Skip to content

Commit 057efa9

Browse files
committed
Make the error condition in Value::ValueType explicit (NFC)
The comment for ValueType claims that all values <1 are errors, but not all switch statements take this into account. This patch introduces an explicit Error case and deletes all default: cases, so we get warned about incomplete switch coverage. https://reviews.llvm.org/D96537
1 parent 532d4bf commit 057efa9

35 files changed

+312
-262
lines changed

lldb/include/lldb/Core/Value.h

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,32 @@ namespace lldb_private {
3737

3838
class Value {
3939
public:
40-
// Values Less than zero are an error, greater than or equal to zero returns
41-
// what the Scalar result is.
42-
enum ValueType {
43-
// m_value contains...
44-
// ============================
45-
eValueTypeScalar, // raw scalar value
46-
eValueTypeFileAddress, // file address value
47-
eValueTypeLoadAddress, // load address value
48-
eValueTypeHostAddress // host address value (for memory in the process that
49-
// is using liblldb)
40+
/// Type that describes Value::m_value.
41+
enum class ValueType {
42+
Invalid = -1,
43+
// m_value contains:
44+
/// A raw scalar value.
45+
Scalar = 0,
46+
/// A file address value.
47+
FileAddress,
48+
/// A load address value.
49+
LoadAddress,
50+
/// A host address value (for memory in the process that < A is
51+
/// using liblldb).
52+
HostAddress
5053
};
5154

52-
enum ContextType // Type that describes Value::m_context
53-
{
54-
// m_context contains...
55-
// ====================
56-
eContextTypeInvalid, // undefined
57-
eContextTypeRegisterInfo, // RegisterInfo * (can be a scalar or a vector
58-
// register)
59-
eContextTypeLLDBType, // lldb_private::Type *
60-
eContextTypeVariable // lldb_private::Variable *
55+
/// Type that describes Value::m_context.
56+
enum class ContextType {
57+
// m_context contains:
58+
/// Undefined.
59+
Invalid = -1,
60+
/// RegisterInfo * (can be a scalar or a vector register).
61+
RegisterInfo = 0,
62+
/// lldb_private::Type *.
63+
LLDBType,
64+
/// lldb_private::Variable *.
65+
Variable
6166
};
6267

6368
Value();
@@ -85,16 +90,16 @@ class Value {
8590

8691
void ClearContext() {
8792
m_context = nullptr;
88-
m_context_type = eContextTypeInvalid;
93+
m_context_type = ContextType::Invalid;
8994
}
9095

9196
void SetContext(ContextType context_type, void *p) {
9297
m_context_type = context_type;
9398
m_context = p;
94-
if (m_context_type == eContextTypeRegisterInfo) {
99+
if (m_context_type == ContextType::RegisterInfo) {
95100
RegisterInfo *reg_info = GetRegisterInfo();
96101
if (reg_info->encoding == lldb::eEncodingVector)
97-
SetValueType(eValueTypeScalar);
102+
SetValueType(ValueType::Scalar);
98103
}
99104
}
100105

lldb/include/lldb/Expression/ExpressionVariable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ExpressionVariable
4848

4949
void SetRegisterInfo(const RegisterInfo *reg_info) {
5050
return m_frozen_sp->GetValue().SetContext(
51-
Value::eContextTypeRegisterInfo, const_cast<RegisterInfo *>(reg_info));
51+
Value::ContextType::RegisterInfo, const_cast<RegisterInfo *>(reg_info));
5252
}
5353

5454
CompilerType GetCompilerType() { return m_frozen_sp->GetCompilerType(); }

0 commit comments

Comments
 (0)