1818
1919namespace lldb_private ::dil {
2020
21- static lldb::ValueObjectSP
22- ArrayToPointerConversion (lldb::ValueObjectSP valobj,
23- std::shared_ptr<ExecutionContextScope> ctx) {
24- assert (valobj->IsArrayType () &&
25- " an argument to array-to-pointer conversion must be an array" );
26-
27- uint64_t addr = valobj->GetLoadAddress ();
28- llvm::StringRef name = " result" ;
29- ExecutionContext exe_ctx;
30- ctx->CalculateExecutionContext (exe_ctx);
31- return ValueObject::CreateValueObjectFromAddress (
32- name, addr, exe_ctx,
33- valobj->GetCompilerType ().GetArrayElementType (ctx.get ()).GetPointerType (),
34- /* do_deref */ false );
35- }
36-
3721static lldb::ValueObjectSP LookupStaticIdentifier (
3822 VariableList &variable_list, std::shared_ptr<StackFrame> exe_scope,
3923 llvm::StringRef name_ref, llvm::StringRef unqualified_name) {
@@ -222,22 +206,9 @@ Interpreter::Interpreter(lldb::TargetSP target, llvm::StringRef expr,
222206 : m_target(std::move(target)), m_expr(expr), m_default_dynamic(use_dynamic),
223207 m_exe_ctx_scope (frame_sp) {}
224208
225- llvm::Expected<lldb::ValueObjectSP> Interpreter::Evaluate (const ASTNode *tree ) {
209+ llvm::Expected<lldb::ValueObjectSP> Interpreter::Evaluate (const ASTNode *node ) {
226210 // Evaluate an AST.
227- auto value_or_error = EvaluateNode (tree);
228-
229- // Return the computed result-or-error.
230- return value_or_error;
231- }
232-
233- llvm::Expected<lldb::ValueObjectSP>
234- Interpreter::EvaluateNode (const ASTNode *node, FlowAnalysis *flow) {
235- // Set up the evaluation context for the current node.
236- m_flow_analysis_chain.push_back (flow);
237- // Traverse an AST pointed by the `node`.
238211 auto value_or_error = node->Accept (this );
239- // Cleanup the context.
240- m_flow_analysis_chain.pop_back ();
241212 // Return the computed value-or-error. The caller is responsible for
242213 // checking if an error occured during the evaluation.
243214 return value_or_error;
@@ -265,33 +236,29 @@ Interpreter::Visit(const IdentifierNode *node) {
265236
266237llvm::Expected<lldb::ValueObjectSP>
267238Interpreter::Visit (const UnaryOpNode *node) {
268- FlowAnalysis rhs_flow (
269- /* address_of_is_pending */ node->kind () == UnaryOpKind::AddrOf);
270-
271239 Status error;
272- auto rhs_or_err = EvaluateNode (node->rhs (), &rhs_flow );
240+ auto rhs_or_err = Evaluate (node->rhs ());
273241 if (!rhs_or_err) {
274242 return rhs_or_err;
275243 }
276244 lldb::ValueObjectSP rhs = *rhs_or_err;
277245
278- CompilerType rhs_type = rhs->GetCompilerType ();
279246 switch (node->kind ()) {
280247 case UnaryOpKind::Deref: {
281- if (rhs_type.IsArrayType ())
282- rhs = ArrayToPointerConversion (rhs, m_exe_ctx_scope);
283-
284248 lldb::ValueObjectSP dynamic_rhs = rhs->GetDynamicValue (m_default_dynamic);
285249 if (dynamic_rhs)
286250 rhs = dynamic_rhs;
287251
288- if (rhs->GetCompilerType ().IsPointerType ()) {
289- if (rhs->GetCompilerType ().IsPointerToVoid ()) {
290- return llvm::make_error<DILDiagnosticError>(
291- m_expr, " indirection not permitted on operand of type 'void *'" ,
292- node->GetLocation (), 1 );
293- }
294- return EvaluateDereference (rhs);
252+ CompilerType rhs_type = rhs->GetCompilerType ();
253+ if (!rhs_type.IsReferenceType () && !rhs_type.IsPointerType ())
254+ return llvm::make_error<DILDiagnosticError>(
255+ m_expr, " not a pointer or reference type" ,
256+ node->rhs ()->GetLocation ());
257+
258+ if (rhs_type.IsPointerToVoid ()) {
259+ return llvm::make_error<DILDiagnosticError>(
260+ m_expr, " indirection not permitted on operand of type 'void *'" ,
261+ node->GetLocation ());
295262 }
296263 lldb::ValueObjectSP child_sp = rhs->Dereference (error);
297264 if (error.Success ())
@@ -300,68 +267,19 @@ Interpreter::Visit(const UnaryOpNode *node) {
300267 return rhs;
301268 }
302269 case UnaryOpKind::AddrOf: {
303- if (node->rhs ()->is_rvalue ()) {
304- std::string errMsg =
305- llvm::formatv (" cannot take the address of an rvalue of type {0}" ,
306- rhs_type.TypeDescription ());
307- return llvm::make_error<DILDiagnosticError>(m_expr, errMsg,
270+ Status error;
271+ lldb::ValueObjectSP value = rhs->AddressOf (error);
272+ if (error.Fail ()) {
273+ return llvm::make_error<DILDiagnosticError>(m_expr, error.AsCString (),
308274 node->GetLocation ());
309275 }
310- if (rhs->IsBitfield ()) {
311- return llvm::make_error<DILDiagnosticError>(
312- m_expr, " address of bit-field requested" , node->GetLocation ());
313- }
314- // If the address-of operation wasn't cancelled during the evaluation of
315- // RHS (e.g. because of the address-of-a-dereference elision), apply it
316- // here.
317- if (rhs_flow.AddressOfIsPending ()) {
318- Status error;
319- lldb::ValueObjectSP value = rhs->AddressOf (error);
320- if (error.Fail ()) {
321- return llvm::make_error<DILDiagnosticError>(m_expr, error.AsCString (),
322- node->GetLocation ());
323- }
324- return value;
325- }
326- return rhs;
276+ return value;
327277 }
328278 }
329279
330280 // Unsupported/invalid operation.
331281 return llvm::make_error<DILDiagnosticError>(
332- m_expr, " invalid ast: unexpected binary operator" , node->GetLocation (),
333- 1 );
334- }
335-
336- lldb::ValueObjectSP Interpreter::EvaluateDereference (lldb::ValueObjectSP rhs) {
337- // If rhs is a reference, dereference it first.
338- Status error;
339- if (rhs->GetCompilerType ().IsReferenceType ())
340- rhs = rhs->Dereference (error);
341-
342- assert (rhs->GetCompilerType ().IsPointerType () &&
343- " invalid ast: must be a pointer type" );
344-
345- if (rhs->GetDerefValobj ())
346- return rhs->GetDerefValobj ()->GetSP ();
347-
348- CompilerType pointer_type = rhs->GetCompilerType ();
349- lldb::addr_t base_addr = rhs->GetValueAsUnsigned (0 );
350-
351- llvm::StringRef name = " result" ;
352- ExecutionContext exe_ctx (m_target.get (), false );
353- lldb::ValueObjectSP value = ValueObject::CreateValueObjectFromAddress (
354- name, base_addr, exe_ctx, pointer_type,
355- /* do_deref */ false );
356-
357- // If we're in the address-of context, skip the dereference and cancel the
358- // pending address-of operation as well.
359- if (flow_analysis () && flow_analysis ()->AddressOfIsPending ()) {
360- flow_analysis ()->DiscardAddressOf ();
361- return value;
362- }
363-
364- return value->Dereference (error);
282+ m_expr, " invalid ast: unexpected binary operator" , node->GetLocation ());
365283}
366284
367285} // namespace lldb_private::dil
0 commit comments