]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Expression/LLVMUserExpression.h
Upgrade our copies of clang, llvm, lldb and compiler-rt to 3.8.0
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Expression / LLVMUserExpression.h
1 //===-- LLVMUserExpression.h ------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_LLVMUserExpression_h
11 #define liblldb_LLVMUserExpression_h
12
13 // C Includes
14 // C++ Includes
15 #include <string>
16 #include <map>
17 #include <vector>
18
19 // Project includes
20 #include "lldb/Expression/UserExpression.h"
21
22 namespace lldb_private
23 {
24
25 //----------------------------------------------------------------------
26 /// @class LLVMUserExpression LLVMUserExpression.h "lldb/Expression/LLVMUserExpression.h"
27 /// @brief Encapsulates a one-time expression for use in lldb.
28 ///
29 /// LLDB uses expressions for various purposes, notably to call functions
30 /// and as a backend for the expr command.  LLVMUserExpression is a virtual base
31 /// class that encapsulates the objects needed to parse and JIT an expression.
32 /// The actual parsing part will be provided by the specific implementations
33 /// of LLVMUserExpression - which will be vended through the appropriate TypeSystem.
34 //----------------------------------------------------------------------
35 class LLVMUserExpression : public UserExpression
36 {
37   public:
38     LLVMUserExpression(ExecutionContextScope &exe_scope,
39                        const char *expr,
40                        const char *expr_prefix,
41                        lldb::LanguageType language,
42                        ResultType desired_type,
43                        const EvaluateExpressionOptions &options);
44     ~LLVMUserExpression() override;
45
46     lldb::ExpressionResults Execute(Stream &error_stream,
47                                     ExecutionContext &exe_ctx,
48                                     const EvaluateExpressionOptions &options,
49                                     lldb::UserExpressionSP &shared_ptr_to_me,
50                                     lldb::ExpressionVariableSP &result) override;
51
52     bool FinalizeJITExecution(Stream &error_stream,
53                               ExecutionContext &exe_ctx,
54                               lldb::ExpressionVariableSP &result,
55                               lldb::addr_t function_stack_bottom = LLDB_INVALID_ADDRESS,
56                               lldb::addr_t function_stack_top = LLDB_INVALID_ADDRESS) override;
57
58     bool
59     CanInterpret() override
60     {
61         return m_can_interpret;
62     }
63
64     //------------------------------------------------------------------
65     /// Return the string that the parser should parse.  Must be a full
66     /// translation unit.
67     //------------------------------------------------------------------
68     const char *
69     Text() override
70     {
71         return m_transformed_text.c_str();
72     }
73
74     lldb::ModuleSP GetJITModule() override;
75
76   protected:
77     virtual void ScanContext(ExecutionContext &exe_ctx, lldb_private::Error &err) = 0;
78
79     bool PrepareToExecuteJITExpression(Stream &error_stream, ExecutionContext &exe_ctx, lldb::addr_t &struct_address);
80
81     virtual bool
82     AddArguments (ExecutionContext &exe_ctx,
83                   std::vector<lldb::addr_t> &args,
84                   lldb::addr_t struct_address,
85                   Stream &error_stream) = 0;
86
87
88     lldb::addr_t m_stack_frame_bottom; ///< The bottom of the allocated stack frame.
89     lldb::addr_t m_stack_frame_top;    ///< The top of the allocated stack frame.
90
91     bool m_allow_cxx;               ///< True if the language allows C++.
92     bool m_allow_objc;              ///< True if the language allows Objective-C.
93     std::string m_transformed_text; ///< The text of the expression, as send to the parser
94
95     std::shared_ptr<IRExecutionUnit> m_execution_unit_sp; ///< The execution unit the expression is stored in.
96     std::unique_ptr<Materializer> m_materializer_ap;      ///< The materializer to use when running the expression.
97     lldb::ModuleWP m_jit_module_wp;
98     bool m_enforce_valid_object; ///< True if the expression parser should enforce the presence of a valid class pointer
99                                  ///in order to generate the expression as a method.
100     bool m_in_cplusplus_method;  ///< True if the expression is compiled as a C++ member function (true if it was parsed
101                                  ///when exe_ctx was in a C++ method).
102     bool m_in_objectivec_method; ///< True if the expression is compiled as an Objective-C method (true if it was parsed
103                                  ///when exe_ctx was in an Objective-C method).
104     bool m_in_static_method; ///< True if the expression is compiled as a static (or class) method (currently true if it
105                              ///was parsed when exe_ctx was in an Objective-C class method).
106     bool m_needs_object_ptr; ///< True if "this" or "self" must be looked up and passed in.  False if the expression
107                              ///doesn't really use them and they can be NULL.
108     bool m_const_object;     ///< True if "this" is const.
109     Target *m_target;        ///< The target for storing persistent data like types and variables.
110
111     bool m_can_interpret; ///< True if the expression could be evaluated statically; false otherwise.
112     lldb::addr_t
113         m_materialized_address; ///< The address at which the arguments to the expression have been materialized.
114     Materializer::DematerializerSP m_dematerializer_sp; ///< The dematerializer.
115 };
116
117 } // namespace lldb_private
118 #endif