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/Utility/Status.h"
14 #include "lldb/lldb-private-enumerations.h"
15 #include "lldb/lldb-public.h"
17 namespace lldb_private {
19 class IRExecutionUnit;
21 //----------------------------------------------------------------------
22 /// @class ExpressionParser ExpressionParser.h
23 /// "lldb/Expression/ExpressionParser.h"
24 /// @brief Encapsulates an instance of a compiler that can parse expressions.
26 /// ExpressionParser is the base class for llvm based Expression parsers.
27 //----------------------------------------------------------------------
28 class ExpressionParser {
30 //------------------------------------------------------------------
33 /// Initializes class variables.
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.
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) {}
47 //------------------------------------------------------------------
49 //------------------------------------------------------------------
50 virtual ~ExpressionParser(){};
52 //------------------------------------------------------------------
53 /// Parse a single expression and convert it to IR using Clang. Don't
54 /// wrap the expression in anything at all.
56 /// @param[in] diagnostic_manager
57 /// The diagnostic manager in which to store the errors and warnings.
60 /// The number of errors encountered during parsing. 0 means
62 //------------------------------------------------------------------
63 virtual unsigned Parse(DiagnosticManager &diagnostic_manager) = 0;
65 //------------------------------------------------------------------
66 /// Try to use the FixIts in the diagnostic_manager to rewrite the
67 /// expression. If successful, the rewritten expression is stored
68 /// in the diagnostic_manager, get it out with GetFixedExpression.
70 /// @param[in] diagnostic_manager
71 /// The diagnostic manager containing fixit's to apply.
74 /// \b true if the rewrite was successful, \b false otherwise.
75 //------------------------------------------------------------------
76 virtual bool RewriteExpression(DiagnosticManager &diagnostic_manager) {
80 //------------------------------------------------------------------
81 /// Ready an already-parsed expression for execution, possibly
82 /// evaluating it statically.
84 /// @param[out] func_addr
85 /// The address to which the function has been written.
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.)
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.
96 /// @param[in] exe_ctx
97 /// The execution context to write the function into.
99 /// @param[out] can_interpret
100 /// Set to true if the expression could be interpreted statically;
101 /// untouched otherwise.
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.
109 /// An error code indicating the success or failure of the operation.
110 /// Test with Success().
111 //------------------------------------------------------------------
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;
118 bool GetGenerateDebugInfo() const { return m_generate_debug_info; }
121 Expression &m_expr; ///< The expression to be parsed
122 bool m_generate_debug_info;
126 #endif // liblldb_ExpressionParser_h_