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