Skip to content

Commit 42c52f3

Browse files
committed
Address/fix remaining reviewer comments:
- Rename 'NewFormatDiagnostics' to 'FormatDiagnostics', keeping the code that uses DiagnosticDetail; remove 'OldFormatDiagnostics'. - Remove the code that automatically dereferences reference variables before returning them. - Remove IdentifierInfo class, replacing it directly with lldb::ValueObjectSP values.
1 parent 07d0d15 commit 42c52f3

File tree

5 files changed

+37
-100
lines changed

5 files changed

+37
-100
lines changed

lldb/include/lldb/ValueObject/DILEval.h

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -16,54 +16,25 @@
1616

1717
namespace lldb_private::dil {
1818

19-
/// Class used to store & manipulate information about identifiers.
20-
class IdentifierInfo {
21-
public:
22-
enum class Kind {
23-
eValue,
24-
eContextArg,
25-
};
26-
27-
static std::unique_ptr<IdentifierInfo> FromValue(ValueObject &valobj) {
28-
CompilerType type;
29-
type = valobj.GetCompilerType();
30-
return std::unique_ptr<IdentifierInfo>(
31-
new IdentifierInfo(Kind::eValue, type, valobj.GetSP(), {}));
32-
}
33-
34-
Kind GetKind() const { return m_kind; }
35-
lldb::ValueObjectSP GetValue() const { return m_value; }
36-
37-
bool IsValid() const { return m_type.IsValid(); }
38-
39-
IdentifierInfo(Kind kind, CompilerType type, lldb::ValueObjectSP value,
40-
std::vector<uint32_t> path)
41-
: m_kind(kind), m_type(type), m_value(std::move(value)) {}
42-
43-
private:
44-
Kind m_kind;
45-
CompilerType m_type;
46-
lldb::ValueObjectSP m_value;
47-
};
48-
4919
/// Given the name of an identifier (variable name, member name, type name,
5020
/// etc.), find the ValueObject for that name (if it exists), excluding global
5121
/// variables, and create and return an IdentifierInfo object containing all
5222
/// the relevant information about that object (for DIL parsing and
5323
/// evaluating).
54-
std::unique_ptr<IdentifierInfo>
55-
LookupIdentifier(llvm::StringRef name_ref, std::shared_ptr<StackFrame> frame_sp,
56-
lldb::DynamicValueType use_dynamic,
57-
CompilerType *scope_ptr = nullptr);
24+
lldb::ValueObjectSP LookupIdentifier(llvm::StringRef name_ref,
25+
std::shared_ptr<StackFrame> frame_sp,
26+
lldb::DynamicValueType use_dynamic,
27+
CompilerType *scope_ptr = nullptr);
5828

5929
/// Given the name of an identifier, check to see if it matches the name of a
6030
/// global variable. If so, find the ValueObject for that global variable, and
6131
/// create and return an IdentifierInfo object containing all the relevant
6232
/// informatin about it.
63-
std::unique_ptr<IdentifierInfo> LookupGlobalIdentifier(
64-
llvm::StringRef name_ref, std::shared_ptr<StackFrame> frame_sp,
65-
lldb::TargetSP target_sp, lldb::DynamicValueType use_dynamic,
66-
CompilerType *scope_ptr = nullptr);
33+
lldb::ValueObjectSP LookupGlobalIdentifier(llvm::StringRef name_ref,
34+
std::shared_ptr<StackFrame> frame_sp,
35+
lldb::TargetSP target_sp,
36+
lldb::DynamicValueType use_dynamic,
37+
CompilerType *scope_ptr = nullptr);
6738

6839
class Interpreter : Visitor {
6940
public:
@@ -77,16 +48,11 @@ class Interpreter : Visitor {
7748
llvm::Expected<lldb::ValueObjectSP>
7849
Visit(const IdentifierNode *node) override;
7950

80-
private:
8151
// Used by the interpreter to create objects, perform casts, etc.
8252
lldb::TargetSP m_target;
83-
8453
llvm::StringRef m_expr;
85-
8654
lldb::ValueObjectSP m_scope;
87-
8855
lldb::DynamicValueType m_default_dynamic;
89-
9056
std::shared_ptr<StackFrame> m_exe_ctx_scope;
9157
};
9258

lldb/include/lldb/ValueObject/DILParser.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,9 @@ enum class ErrorCode : unsigned char {
2828
kUnknown,
2929
};
3030

31-
std::string NewFormatDiagnostics(llvm::StringRef input_expr,
32-
const std::string &message, uint32_t loc,
33-
uint16_t err_len);
34-
35-
std::string OldFormatDiagnostics(llvm::StringRef input_expr,
36-
const std::string &message, uint32_t loc);
31+
std::string FormatDiagnostics(llvm::StringRef input_expr,
32+
const std::string &message, uint32_t loc,
33+
uint16_t err_len);
3734

3835
/// Pure recursive descent parser for C++ like expressions.
3936
/// EBNF grammar for the parser is described in lldb/docs/dil-expr-lang.ebnf

lldb/source/ValueObject/DILEval.cpp

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static lldb::VariableSP DILFindVariable(ConstString name,
8787
return nullptr;
8888
}
8989

90-
std::unique_ptr<IdentifierInfo> LookupGlobalIdentifier(
90+
lldb::ValueObjectSP LookupGlobalIdentifier(
9191
llvm::StringRef name_ref, std::shared_ptr<StackFrame> stack_frame,
9292
lldb::TargetSP target_sp, lldb::DynamicValueType use_dynamic,
9393
CompilerType *scope_ptr) {
@@ -105,7 +105,7 @@ std::unique_ptr<IdentifierInfo> LookupGlobalIdentifier(
105105
}
106106

107107
if (value_sp)
108-
return IdentifierInfo::FromValue(*value_sp);
108+
return value_sp;
109109

110110
// Also check for static global vars.
111111
if (variable_list) {
@@ -122,7 +122,7 @@ std::unique_ptr<IdentifierInfo> LookupGlobalIdentifier(
122122
}
123123

124124
if (value_sp)
125-
return IdentifierInfo::FromValue(*value_sp);
125+
return value_sp;
126126

127127
// Check for match in modules global variables.
128128
VariableList modules_var_list;
@@ -142,15 +142,15 @@ std::unique_ptr<IdentifierInfo> LookupGlobalIdentifier(
142142
}
143143

144144
if (value_sp)
145-
return IdentifierInfo::FromValue(*value_sp);
145+
return value_sp;
146146

147147
return nullptr;
148148
}
149149

150-
std::unique_ptr<IdentifierInfo>
151-
LookupIdentifier(llvm::StringRef name_ref,
152-
std::shared_ptr<StackFrame> stack_frame,
153-
lldb::DynamicValueType use_dynamic, CompilerType *scope_ptr) {
150+
lldb::ValueObjectSP LookupIdentifier(llvm::StringRef name_ref,
151+
std::shared_ptr<StackFrame> stack_frame,
152+
lldb::DynamicValueType use_dynamic,
153+
CompilerType *scope_ptr) {
154154
// Support $rax as a special syntax for accessing registers.
155155
// Will return an invalid value in case the requested register doesn't exist.
156156
if (name_ref.consume_front("$")) {
@@ -165,7 +165,7 @@ LookupIdentifier(llvm::StringRef name_ref,
165165
ValueObjectRegister::Create(stack_frame.get(), reg_ctx, reg_info);
166166

167167
if (value_sp)
168-
return IdentifierInfo::FromValue(*value_sp);
168+
return value_sp;
169169

170170
return nullptr;
171171
}
@@ -189,7 +189,7 @@ LookupIdentifier(llvm::StringRef name_ref,
189189
value_sp = stack_frame->FindVariable(ConstString(name_ref));
190190

191191
if (value_sp)
192-
return IdentifierInfo::FromValue(*value_sp);
192+
return value_sp;
193193

194194
// Try looking for an instance variable (class member).
195195
SymbolContext sc = stack_frame->GetSymbolContext(
@@ -200,7 +200,7 @@ LookupIdentifier(llvm::StringRef name_ref,
200200
value_sp = value_sp->GetChildMemberWithName(name_ref);
201201

202202
if (value_sp)
203-
return IdentifierInfo::FromValue(*(value_sp));
203+
return value_sp;
204204
}
205205
}
206206
return nullptr;
@@ -226,7 +226,7 @@ llvm::Expected<lldb::ValueObjectSP>
226226
Interpreter::Visit(const IdentifierNode *node) {
227227
lldb::DynamicValueType use_dynamic = node->GetUseDynamic();
228228

229-
std::unique_ptr<IdentifierInfo> identifier =
229+
lldb::ValueObjectSP identifier =
230230
LookupIdentifier(node->GetName(), m_exe_ctx_scope, use_dynamic);
231231

232232
if (!identifier)
@@ -235,28 +235,14 @@ Interpreter::Visit(const IdentifierNode *node) {
235235
if (!identifier) {
236236
std::string errMsg =
237237
llvm::formatv("use of undeclared identifier '{0}'", node->GetName());
238-
Status error = Status(
239-
(uint32_t)ErrorCode::kUndeclaredIdentifier, lldb::eErrorTypeGeneric,
240-
NewFormatDiagnostics(m_expr, errMsg, node->GetLocation(),
241-
node->GetName().size()));
238+
Status error = Status((uint32_t)ErrorCode::kUndeclaredIdentifier,
239+
lldb::eErrorTypeGeneric,
240+
FormatDiagnostics(m_expr, errMsg, node->GetLocation(),
241+
node->GetName().size()));
242242
return error.ToError();
243243
}
244-
lldb::ValueObjectSP val;
245-
lldb::TargetSP target_sp;
246244

247-
assert(identifier->GetKind() == IdentifierInfo::Kind::eValue &&
248-
"Unrecognized identifier kind");
249-
250-
val = identifier->GetValue();
251-
252-
if (val->GetCompilerType().IsReferenceType()) {
253-
Status error;
254-
val = val->Dereference(error);
255-
if (error.Fail())
256-
return error.ToError();
257-
}
258-
259-
return val;
245+
return identifier;
260246
}
261247

262248
} // namespace lldb_private::dil

lldb/source/ValueObject/DILParser.cpp

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626

2727
namespace lldb_private::dil {
2828

29-
std::string NewFormatDiagnostics(llvm::StringRef text,
30-
const std::string &message, uint32_t loc,
31-
uint16_t err_len) {
29+
std::string FormatDiagnostics(llvm::StringRef text, const std::string &message,
30+
uint32_t loc, uint16_t err_len) {
3231
DiagnosticDetail::SourceLocation sloc = {
3332
FileSpec{}, /*line=*/1, loc + 1, err_len, false, /*in_user_input=*/true};
3433
std::string arrow_str = "^";
@@ -48,18 +47,6 @@ std::string NewFormatDiagnostics(llvm::StringRef text,
4847
return ret_str;
4948
}
5049

51-
std::string OldFormatDiagnostics(llvm::StringRef text,
52-
const std::string &message, uint32_t loc) {
53-
// Get the position, in the current line of text, of the diagnostics pointer.
54-
// ('loc' is the location of the start of the current token/error within the
55-
// overall text line).
56-
int32_t arrow = loc + 1; // Column offset starts at 1, not 0.
57-
58-
return llvm::formatv("<expr:1:{0}>: {1}\n{2}\n{3}", loc + 1, message,
59-
llvm::fmt_pad(text, 0, 0),
60-
llvm::fmt_pad("^", arrow - 1, 0));
61-
}
62-
6350
llvm::Expected<ASTNodeUP>
6451
DILParser::Parse(llvm::StringRef dil_input_expr, DILLexer lexer,
6552
std::shared_ptr<StackFrame> frame_sp,
@@ -257,8 +244,8 @@ void DILParser::BailOut(ErrorCode code, const std::string &error,
257244
}
258245

259246
m_error = Status((uint32_t)code, lldb::eErrorTypeGeneric,
260-
NewFormatDiagnostics(m_input_expr, error, loc,
261-
CurToken().GetSpelling().length()));
247+
FormatDiagnostics(m_input_expr, error, loc,
248+
CurToken().GetSpelling().length()));
262249
// Advance the lexer token index to the end of the lexed tokens vector.
263250
m_dil_lexer.ResetTokenIdx(m_dil_lexer.NumLexedTokens() - 1);
264251
}

lldb/test/API/commands/frame/var-dil/basics/GlobalVariableLookup/TestFrameVarDILGlobalVariableLookup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ def test_frame_var(self):
2626
self.expect("settings set target.experimental.use-DIL true", substrs=[""])
2727
self.expect_var_path("globalVar", type="int", value="-559038737") # 0xDEADBEEF
2828
self.expect_var_path("globalPtr", type="int *")
29-
self.expect_var_path("globalRef", value="-559038737")
29+
self.expect_var_path("globalRef", type="int &")
3030
self.expect_var_path("::globalVar", value="-559038737")
3131
self.expect_var_path("::globalPtr", type="int *")
32-
self.expect_var_path("::globalRef", value="-559038737")
32+
self.expect_var_path("::globalRef", type="int &")
3333

3434
self.expect(
3535
"frame variable 'externGlobalVar'",
@@ -44,6 +44,7 @@ def test_frame_var(self):
4444

4545
self.expect_var_path("ns::globalVar", value="13")
4646
self.expect_var_path("ns::globalPtr", type="int *")
47-
self.expect_var_path("ns::globalRef", value="13")
47+
self.expect_var_path("ns::globalRef", type="int &")
4848
self.expect_var_path("::ns::globalVar", value="13")
4949
self.expect_var_path("::ns::globalPtr", type="int *")
50+
self.expect_var_path("::ns::globalRef", type="int &")

0 commit comments

Comments
 (0)