]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/lldb/Expression/ExpressionParser.h
Vendor import of lldb trunk r338150:
[FreeBSD/FreeBSD.git] / include / lldb / Expression / ExpressionParser.h
1 //===-- ExpressionParser.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_ExpressionParser_h_
11 #define liblldb_ExpressionParser_h_
12
13 #include "lldb/Utility/Status.h"
14 #include "lldb/lldb-private-enumerations.h"
15 #include "lldb/lldb-public.h"
16
17 namespace lldb_private {
18
19 class IRExecutionUnit;
20
21 //----------------------------------------------------------------------
22 /// @class ExpressionParser ExpressionParser.h
23 /// "lldb/Expression/ExpressionParser.h" Encapsulates an instance of a
24 /// compiler that can parse expressions.
25 ///
26 /// ExpressionParser is the base class for llvm based Expression parsers.
27 //----------------------------------------------------------------------
28 class ExpressionParser {
29 public:
30   //------------------------------------------------------------------
31   /// Constructor
32   ///
33   /// Initializes class variables.
34   ///
35   /// @param[in] exe_scope,
36   ///     If non-NULL, an execution context scope that can help to
37   ///     correctly create an expression with a valid process for
38   ///     optional tuning Objective-C runtime support. Can be NULL.
39   ///
40   /// @param[in] expr
41   ///     The expression to be parsed.
42   //------------------------------------------------------------------
43   ExpressionParser(ExecutionContextScope *exe_scope, Expression &expr,
44                    bool generate_debug_info)
45       : m_expr(expr), m_generate_debug_info(generate_debug_info) {}
46
47   //------------------------------------------------------------------
48   /// Destructor
49   //------------------------------------------------------------------
50   virtual ~ExpressionParser(){};
51
52   //------------------------------------------------------------------
53   /// Parse a single expression and convert it to IR using Clang.  Don't wrap
54   /// the expression in anything at all.
55   ///
56   /// @param[in] diagnostic_manager
57   ///     The diagnostic manager in which to store the errors and warnings.
58   ///
59   /// @return
60   ///     The number of errors encountered during parsing.  0 means
61   ///     success.
62   //------------------------------------------------------------------
63   virtual unsigned Parse(DiagnosticManager &diagnostic_manager) = 0;
64
65   //------------------------------------------------------------------
66   /// Try to use the FixIts in the diagnostic_manager to rewrite the
67   /// expression.  If successful, the rewritten expression is stored in the
68   /// diagnostic_manager, get it out with GetFixedExpression.
69   ///
70   /// @param[in] diagnostic_manager
71   ///     The diagnostic manager containing fixit's to apply.
72   ///
73   /// @return
74   ///     \b true if the rewrite was successful, \b false otherwise.
75   //------------------------------------------------------------------
76   virtual bool RewriteExpression(DiagnosticManager &diagnostic_manager) {
77     return false;
78   }
79
80   //------------------------------------------------------------------
81   /// Ready an already-parsed expression for execution, possibly evaluating it
82   /// statically.
83   ///
84   /// @param[out] func_addr
85   ///     The address to which the function has been written.
86   ///
87   /// @param[out] func_end
88   ///     The end of the function's allocated memory region.  (func_addr
89   ///     and func_end do not delimit an allocated region; the allocated
90   ///     region may begin before func_addr.)
91   ///
92   /// @param[in] execution_unit_sp
93   ///     After parsing, ownership of the execution unit for
94   ///     for the expression is handed to this shared pointer.
95   ///
96   /// @param[in] exe_ctx
97   ///     The execution context to write the function into.
98   ///
99   /// @param[out] can_interpret
100   ///     Set to true if the expression could be interpreted statically;
101   ///     untouched otherwise.
102   ///
103   /// @param[in] execution_policy
104   ///     Determines whether the expression must be JIT-compiled, must be
105   ///     evaluated statically, or whether this decision may be made
106   ///     opportunistically.
107   ///
108   /// @return
109   ///     An error code indicating the success or failure of the operation.
110   ///     Test with Success().
111   //------------------------------------------------------------------
112   virtual Status
113   PrepareForExecution(lldb::addr_t &func_addr, lldb::addr_t &func_end,
114                       std::shared_ptr<IRExecutionUnit> &execution_unit_sp,
115                       ExecutionContext &exe_ctx, bool &can_interpret,
116                       lldb_private::ExecutionPolicy execution_policy) = 0;
117
118   bool GetGenerateDebugInfo() const { return m_generate_debug_info; }
119
120 protected:
121   Expression &m_expr; ///< The expression to be parsed
122   bool m_generate_debug_info;
123 };
124 }
125
126 #endif // liblldb_ExpressionParser_h_