[Lldb-commits] [lldb] [LLDB] Add DIL code for handling plain variable names. (PR #120971)
via lldb-commits
lldb-commits at lists.llvm.org
Wed Jan 8 16:43:59 PST 2025
================
@@ -0,0 +1,117 @@
+//===-- DILEval.cpp -------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/ValueObject/DILEval.h"
+
+#include <memory>
+
+#include "lldb/ValueObject/DILAST.h"
+#include "lldb/ValueObject/ValueObject.h"
+#include "llvm/Support/FormatAdapters.h"
+
+namespace lldb_private {
+
+namespace dil {
+
+DILInterpreter::DILInterpreter(lldb::TargetSP target,
+ std::shared_ptr<std::string> sm)
+ : m_target(std::move(target)), m_sm(std::move(sm)) {
+ m_default_dynamic = lldb::eNoDynamicValues;
+}
+
+DILInterpreter::DILInterpreter(lldb::TargetSP target,
+ std::shared_ptr<std::string> sm,
+ lldb::DynamicValueType use_dynamic)
+ : m_target(std::move(target)), m_sm(std::move(sm)),
+ m_default_dynamic(use_dynamic) {}
+
+DILInterpreter::DILInterpreter(lldb::TargetSP target,
+ std::shared_ptr<std::string> sm,
+ lldb::ValueObjectSP scope)
+ : m_target(std::move(target)), m_sm(std::move(sm)),
+ m_scope(std::move(scope)) {
+ m_default_dynamic = lldb::eNoDynamicValues;
+ // If `m_scope` is a reference, dereference it. All operations on a reference
+ // should be operations on the referent.
+ if (m_scope->GetCompilerType().IsValid() &&
+ m_scope->GetCompilerType().IsReferenceType()) {
+ Status error;
+ m_scope = m_scope->Dereference(error);
+ }
+}
+
+lldb::ValueObjectSP DILInterpreter::DILEval(const DILASTNode *tree,
+ lldb::TargetSP target_sp,
+ Status &error) {
+ m_error.Clear();
+ // Evaluate an AST.
+ DILEvalNode(tree);
+ // Set the error.
+ error = std::move(m_error);
+ // Return the computed result. If there was an error, it will be invalid.
+ return m_result;
+}
+
+lldb::ValueObjectSP DILInterpreter::DILEvalNode(const DILASTNode *node) {
+
+ // Traverse an AST pointed by the `node`.
+ node->Accept(this);
+
+ // Return the computed value for convenience. The caller is responsible for
+ // checking if an error occured during the evaluation.
+ return m_result;
+}
----------------
cmtice wrote:
As we add functionality, some of the "Visit" functions call DILEvalNode to evaluate subtrees within the AST. SO..this function isn't really needed immediately (in this version), but it will definitely be needed later. Do you want me to remove it in this version?
https://github.com/llvm/llvm-project/pull/120971
More information about the lldb-commits
mailing list