Coverage Report

Created: 2023-09-30 09:22

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Interpreter/OptionValueString.h
Line
Count
Source (jump to first uncovered line)
1
//===-- OptionValueString.h -------------------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLDB_INTERPRETER_OPTIONVALUESTRING_H
10
#define LLDB_INTERPRETER_OPTIONVALUESTRING_H
11
12
#include <string>
13
14
#include "lldb/Utility/Flags.h"
15
16
#include "lldb/Interpreter/OptionValue.h"
17
18
namespace lldb_private {
19
20
class OptionValueString : public Cloneable<OptionValueString, OptionValue> {
21
public:
22
  typedef Status (*ValidatorCallback)(const char *string, void *baton);
23
24
  enum Options { eOptionEncodeCharacterEscapeSequences = (1u << 0) };
25
26
85.5k
  OptionValueString() = default;
27
28
  OptionValueString(ValidatorCallback validator, void *baton = nullptr)
29
24.3k
      : m_validator(validator), m_validator_baton(baton) {}
30
31
92.5k
  OptionValueString(const char *value) {
32
92.5k
    if (value && value[0]) {
33
67.0k
      m_current_value.assign(value);
34
67.0k
      m_default_value.assign(value);
35
67.0k
    }
36
92.5k
  }
37
38
36.9k
  OptionValueString(const char *current_value, const char *default_value) {
39
36.9k
    if (current_value && 
current_value[0]30.8k
)
40
364
      m_current_value.assign(current_value);
41
36.9k
    if (default_value && 
default_value[0]30.8k
)
42
0
      m_default_value.assign(default_value);
43
36.9k
  }
44
45
  OptionValueString(const char *value, ValidatorCallback validator,
46
                    void *baton = nullptr)
47
0
      : m_validator(validator), m_validator_baton(baton) {
48
0
    if (value && value[0]) {
49
0
      m_current_value.assign(value);
50
0
      m_default_value.assign(value);
51
0
    }
52
0
  }
53
54
  OptionValueString(const char *current_value, const char *default_value,
55
                    ValidatorCallback validator, void *baton = nullptr)
56
0
      : m_validator(validator), m_validator_baton(baton) {
57
0
    if (current_value && current_value[0])
58
0
      m_current_value.assign(current_value);
59
0
    if (default_value && default_value[0])
60
0
      m_default_value.assign(default_value);
61
0
  }
62
63
244k
  ~OptionValueString() override = default;
64
65
  // Virtual subclass pure virtual overrides
66
67
51.3k
  OptionValue::Type GetType() const override { return eTypeString; }
68
69
  void DumpValue(const ExecutionContext *exe_ctx, Stream &strm,
70
                 uint32_t dump_mask) override;
71
72
21
  llvm::json::Value ToJSON(const ExecutionContext *exe_ctx) override {
73
21
    return m_current_value;
74
21
  }
75
76
  Status
77
  SetValueFromString(llvm::StringRef value,
78
                     VarSetOperationType op = eVarSetOperationAssign) override;
79
80
75.2k
  void Clear() override {
81
75.2k
    m_current_value = m_default_value;
82
75.2k
    m_value_was_set = false;
83
75.2k
  }
84
85
  // Subclass specific functions
86
87
6.09k
  Flags &GetOptions() { return m_options; }
88
89
0
  const Flags &GetOptions() const { return m_options; }
90
91
0
  const char *operator=(const char *value) {
92
0
    SetCurrentValue(value);
93
0
    return m_current_value.c_str();
94
0
  }
95
96
2.28k
  const char *GetCurrentValue() const { return m_current_value.c_str(); }
97
33.4k
  llvm::StringRef GetCurrentValueAsRef() const { return m_current_value; }
98
99
0
  const char *GetDefaultValue() const { return m_default_value.c_str(); }
100
0
  llvm::StringRef GetDefaultValueAsRef() const { return m_default_value; }
101
102
  Status SetCurrentValue(llvm::StringRef value);
103
104
  Status AppendToCurrentValue(const char *value);
105
106
0
  void SetDefaultValue(const char *value) {
107
0
    if (value && value[0])
108
0
      m_default_value.assign(value);
109
0
    else
110
0
      m_default_value.clear();
111
0
  }
112
113
7.92k
  bool IsCurrentValueEmpty() const { return m_current_value.empty(); }
114
115
0
  bool IsDefaultValueEmpty() const { return m_default_value.empty(); }
116
117
3.88k
  void SetValidator(ValidatorCallback validator, void *baton = nullptr) {
118
3.88k
    m_validator = validator;
119
3.88k
    m_validator_baton = baton;
120
3.88k
  }
121
122
protected:
123
  std::string m_current_value;
124
  std::string m_default_value;
125
  Flags m_options;
126
  ValidatorCallback m_validator = nullptr;
127
  void *m_validator_baton = nullptr;
128
};
129
130
} // namespace lldb_private
131
132
#endif // LLDB_INTERPRETER_OPTIONVALUESTRING_H