@@ -207,9 +207,11 @@ Interpreter::Interpreter(lldb::TargetSP target, llvm::StringRef expr,
207207 m_exe_ctx_scope (frame_sp) {}
208208
209209llvm::Expected<lldb::ValueObjectSP> Interpreter::Evaluate (const ASTNode *node) {
210-
211- // Traverse an AST pointed by the `node`.
212- return node->Accept (this );
210+ // Evaluate an AST.
211+ auto value_or_error = node->Accept (this );
212+ // Return the computed value-or-error. The caller is responsible for
213+ // checking if an error occured during the evaluation.
214+ return value_or_error;
213215}
214216
215217llvm::Expected<lldb::ValueObjectSP>
@@ -232,4 +234,42 @@ Interpreter::Visit(const IdentifierNode *node) {
232234 return identifier;
233235}
234236
237+ llvm::Expected<lldb::ValueObjectSP>
238+ Interpreter::Visit (const UnaryOpNode *node) {
239+ Status error;
240+ auto rhs_or_err = Evaluate (node->operand ());
241+ if (!rhs_or_err)
242+ return rhs_or_err;
243+
244+ lldb::ValueObjectSP rhs = *rhs_or_err;
245+
246+ switch (node->kind ()) {
247+ case UnaryOpKind::Deref: {
248+ lldb::ValueObjectSP dynamic_rhs = rhs->GetDynamicValue (m_default_dynamic);
249+ if (dynamic_rhs)
250+ rhs = dynamic_rhs;
251+
252+ lldb::ValueObjectSP child_sp = rhs->Dereference (error);
253+ if (error.Fail ())
254+ return llvm::make_error<DILDiagnosticError>(m_expr, error.AsCString (),
255+ node->GetLocation ());
256+
257+ return child_sp;
258+ }
259+ case UnaryOpKind::AddrOf: {
260+ Status error;
261+ lldb::ValueObjectSP value = rhs->AddressOf (error);
262+ if (error.Fail ())
263+ return llvm::make_error<DILDiagnosticError>(m_expr, error.AsCString (),
264+ node->GetLocation ());
265+
266+ return value;
267+ }
268+ }
269+
270+ // Unsupported/invalid operation.
271+ return llvm::make_error<DILDiagnosticError>(
272+ m_expr, " invalid ast: unexpected binary operator" , node->GetLocation ());
273+ }
274+
235275} // namespace lldb_private::dil
0 commit comments