1 //===-- ExpressionParser.h --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_ExpressionParser_h_
11 #define liblldb_ExpressionParser_h_
13 #include "lldb/Core/Error.h"
14 #include "lldb/lldb-public.h"
16 namespace lldb_private {
18 class IRExecutionUnit;
20 //----------------------------------------------------------------------
21 /// @class ExpressionParser ExpressionParser.h
22 /// "lldb/Expression/ExpressionParser.h"
23 /// @brief Encapsulates an instance of a compiler that can parse expressions.
25 /// ExpressionParser is the base class for llvm based Expression parsers.
26 //----------------------------------------------------------------------
27 class ExpressionParser {
29 //------------------------------------------------------------------
32 /// Initializes class variables.
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.
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) {}
46 //------------------------------------------------------------------
48 //------------------------------------------------------------------
49 virtual ~ExpressionParser(){};
51 //------------------------------------------------------------------
52 /// Parse a single expression and convert it to IR using Clang. Don't
53 /// wrap the expression in anything at all.
55 /// @param[in] diagnostic_manager
56 /// The diagnostic manager in which to store the errors and warnings.
59 /// The number of errors encountered during parsing. 0 means
61 //------------------------------------------------------------------
62 virtual unsigned Parse(DiagnosticManager &diagnostic_manager) = 0;
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.
69 /// @param[in] diagnostic_manager
70 /// The diagnostic manager containing fixit's to apply.
73 /// \b true if the rewrite was successful, \b false otherwise.
74 //------------------------------------------------------------------
75 virtual bool RewriteExpression(DiagnosticManager &diagnostic_manager) {
79 //------------------------------------------------------------------
80 /// Ready an already-parsed expression for execution, possibly
81 /// evaluating it statically.
83 /// @param[out] func_addr
84 /// The address to which the function has been written.
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.)
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.
95 /// @param[in] exe_ctx
96 /// The execution context to write the function into.
98 /// @param[out] can_interpret
99 /// Set to true if the expression could be interpreted statically;
100 /// untouched otherwise.
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.
108 /// An error code indicating the success or failure of the operation.
109 /// Test with Success().
110 //------------------------------------------------------------------
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;
117 bool GetGenerateDebugInfo() const { return m_generate_debug_info; }
120 Expression &m_expr; ///< The expression to be parsed
121 bool m_generate_debug_info;
125 #endif // liblldb_ExpressionParser_h_