Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 1 | //===-- ExpressionParser.h --------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 9 | #ifndef LLDB_EXPRESSION_EXPRESSIONPARSER_H |
| 10 | #define LLDB_EXPRESSION_EXPRESSIONPARSER_H |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 11 | |
| 12 | #include "lldb/Utility/CompletionRequest.h" |
| 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 | /// \class ExpressionParser ExpressionParser.h |
| 22 | /// "lldb/Expression/ExpressionParser.h" Encapsulates an instance of a |
| 23 | /// compiler that can parse expressions. |
| 24 | /// |
| 25 | /// ExpressionParser is the base class for llvm based Expression parsers. |
| 26 | class ExpressionParser { |
| 27 | public: |
| 28 | /// Constructor |
| 29 | /// |
| 30 | /// Initializes class variables. |
| 31 | /// |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 32 | /// \param[in] exe_scope |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 33 | /// If non-NULL, an execution context scope that can help to |
| 34 | /// correctly create an expression with a valid process for |
| 35 | /// optional tuning Objective-C runtime support. Can be NULL. |
| 36 | /// |
| 37 | /// \param[in] expr |
| 38 | /// The expression to be parsed. |
| 39 | ExpressionParser(ExecutionContextScope *exe_scope, Expression &expr, |
| 40 | bool generate_debug_info) |
| 41 | : m_expr(expr), m_generate_debug_info(generate_debug_info) {} |
| 42 | |
| 43 | /// Destructor |
| 44 | virtual ~ExpressionParser(){}; |
| 45 | |
| 46 | /// Attempts to find possible command line completions for the given |
| 47 | /// expression. |
| 48 | /// |
| 49 | /// \param[out] request |
| 50 | /// The completion request to fill out. The completion should be a string |
| 51 | /// that would complete the current token at the cursor position. |
| 52 | /// Note that the string in the list replaces the current token |
| 53 | /// in the command line. |
| 54 | /// |
| 55 | /// \param[in] line |
| 56 | /// The line with the completion cursor inside the expression as a string. |
| 57 | /// The first line in the expression has the number 0. |
| 58 | /// |
| 59 | /// \param[in] pos |
| 60 | /// The character position in the line with the completion cursor. |
| 61 | /// If the value is 0, then the cursor is on top of the first character |
| 62 | /// in the line (i.e. the user has requested completion from the start of |
| 63 | /// the expression). |
| 64 | /// |
| 65 | /// \param[in] typed_pos |
| 66 | /// The cursor position in the line as typed by the user. If the user |
| 67 | /// expression has not been transformed in some form (e.g. wrapping it |
| 68 | /// in a function body for C languages), then this is equal to the |
| 69 | /// 'pos' parameter. The semantics of this value are otherwise equal to |
| 70 | /// 'pos' (e.g. a value of 0 means the cursor is at start of the |
| 71 | /// expression). |
| 72 | /// |
| 73 | /// \return |
| 74 | /// True if we added any completion results to the output; |
| 75 | /// false otherwise. |
| 76 | virtual bool Complete(CompletionRequest &request, unsigned line, unsigned pos, |
| 77 | unsigned typed_pos) = 0; |
| 78 | |
Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame] | 79 | /// Try to use the FixIts in the diagnostic_manager to rewrite the |
| 80 | /// expression. If successful, the rewritten expression is stored in the |
| 81 | /// diagnostic_manager, get it out with GetFixedExpression. |
| 82 | /// |
| 83 | /// \param[in] diagnostic_manager |
| 84 | /// The diagnostic manager containing fixit's to apply. |
| 85 | /// |
| 86 | /// \return |
| 87 | /// \b true if the rewrite was successful, \b false otherwise. |
| 88 | virtual bool RewriteExpression(DiagnosticManager &diagnostic_manager) { |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | /// Ready an already-parsed expression for execution, possibly evaluating it |
| 93 | /// statically. |
| 94 | /// |
| 95 | /// \param[out] func_addr |
| 96 | /// The address to which the function has been written. |
| 97 | /// |
| 98 | /// \param[out] func_end |
| 99 | /// The end of the function's allocated memory region. (func_addr |
| 100 | /// and func_end do not delimit an allocated region; the allocated |
| 101 | /// region may begin before func_addr.) |
| 102 | /// |
| 103 | /// \param[in] execution_unit_sp |
| 104 | /// After parsing, ownership of the execution unit for |
| 105 | /// for the expression is handed to this shared pointer. |
| 106 | /// |
| 107 | /// \param[in] exe_ctx |
| 108 | /// The execution context to write the function into. |
| 109 | /// |
| 110 | /// \param[out] can_interpret |
| 111 | /// Set to true if the expression could be interpreted statically; |
| 112 | /// untouched otherwise. |
| 113 | /// |
| 114 | /// \param[in] execution_policy |
| 115 | /// Determines whether the expression must be JIT-compiled, must be |
| 116 | /// evaluated statically, or whether this decision may be made |
| 117 | /// opportunistically. |
| 118 | /// |
| 119 | /// \return |
| 120 | /// An error code indicating the success or failure of the operation. |
| 121 | /// Test with Success(). |
| 122 | virtual Status |
| 123 | PrepareForExecution(lldb::addr_t &func_addr, lldb::addr_t &func_end, |
| 124 | std::shared_ptr<IRExecutionUnit> &execution_unit_sp, |
| 125 | ExecutionContext &exe_ctx, bool &can_interpret, |
| 126 | lldb_private::ExecutionPolicy execution_policy) = 0; |
| 127 | |
| 128 | bool GetGenerateDebugInfo() const { return m_generate_debug_info; } |
| 129 | |
| 130 | protected: |
| 131 | Expression &m_expr; ///< The expression to be parsed |
| 132 | bool m_generate_debug_info; |
| 133 | }; |
| 134 | } |
| 135 | |
Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 136 | #endif // LLDB_EXPRESSION_EXPRESSIONPARSER_H |