1 //===-- Expression.h --------------------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef liblldb_Expression_h_
10 #define liblldb_Expression_h_
17 #include "lldb/Expression/ExpressionTypeSystemHelper.h"
18 #include "lldb/lldb-forward.h"
19 #include "lldb/lldb-private.h"
21 namespace lldb_private {
23 class RecordingMemoryManager;
25 /// \class Expression Expression.h "lldb/Expression/Expression.h" Encapsulates
26 /// a single expression for use in lldb
28 /// LLDB uses expressions for various purposes, notably to call functions
29 /// and as a backend for the expr command. Expression encapsulates the
30 /// objects needed to parse and interpret or JIT an expression. It uses the
31 /// expression parser appropriate to the language of the expression to produce
32 /// LLVM IR from the expression.
35 /// Discriminator for LLVM-style RTTI (dyn_cast<> et al.)
38 eKindClangFunctionCaller,
40 eKindLLVMUserExpression,
41 eKindClangUserExpression,
43 eKindClangUtilityFunction,
46 enum ResultType { eResultTypeAny, eResultTypeId };
48 Expression(Target &target, ExpressionKind kind);
50 Expression(ExecutionContextScope &exe_scope, ExpressionKind kind);
53 virtual ~Expression() {}
55 /// Return the string that the parser should parse. Must be a full
57 virtual const char *Text() = 0;
59 /// Return the function name that should be used for executing the
60 /// expression. Text() should contain the definition of this function.
61 virtual const char *FunctionName() = 0;
63 /// Return the language that should be used when parsing. To use the
64 /// default, return eLanguageTypeUnknown.
65 virtual lldb::LanguageType Language() { return lldb::eLanguageTypeUnknown; }
67 /// Return the desired result type of the function, or eResultTypeAny if
69 virtual ResultType DesiredResultType() { return eResultTypeAny; }
73 /// Return true if validation code should be inserted into the expression.
74 virtual bool NeedsValidation() = 0;
76 /// Return true if external variables in the expression should be resolved.
77 virtual bool NeedsVariableResolution() = 0;
79 virtual EvaluateExpressionOptions *GetOptions() { return nullptr; };
81 /// Return the address of the function's JIT-compiled code, or
82 /// LLDB_INVALID_ADDRESS if the function is not JIT compiled
83 lldb::addr_t StartAddress() { return m_jit_start_addr; }
85 /// Called to notify the expression that it is about to be executed.
86 virtual void WillStartExecuting() {}
88 /// Called to notify the expression that its execution has finished.
89 virtual void DidFinishExecuting() {}
91 virtual ExpressionTypeSystemHelper *GetTypeSystemHelper() { return nullptr; }
93 /// LLVM-style RTTI support.
94 ExpressionKind getKind() const { return m_kind; }
97 /// LLVM-style RTTI support.
98 const ExpressionKind m_kind;
100 lldb::TargetWP m_target_wp; /// Expression's always have to have a target...
101 lldb::ProcessWP m_jit_process_wp; /// An expression might have a process, but
102 /// it doesn't need to (e.g. calculator
104 lldb::addr_t m_jit_start_addr; ///< The address of the JITted function within
105 ///the JIT allocation. LLDB_INVALID_ADDRESS if
107 lldb::addr_t m_jit_end_addr; ///< The address of the JITted function within
108 ///the JIT allocation. LLDB_INVALID_ADDRESS if
112 } // namespace lldb_private
114 #endif // liblldb_Expression_h_