1061da546Spatrick //===-- ExpressionParser.h --------------------------------------*- C++ -*-===// 2061da546Spatrick // 3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6061da546Spatrick // 7061da546Spatrick //===----------------------------------------------------------------------===// 8061da546Spatrick 9dda28197Spatrick #ifndef LLDB_EXPRESSION_EXPRESSIONPARSER_H 10dda28197Spatrick #define LLDB_EXPRESSION_EXPRESSIONPARSER_H 11061da546Spatrick 12061da546Spatrick #include "lldb/Utility/CompletionRequest.h" 13061da546Spatrick #include "lldb/Utility/Status.h" 14061da546Spatrick #include "lldb/lldb-private-enumerations.h" 15061da546Spatrick #include "lldb/lldb-public.h" 16061da546Spatrick 17061da546Spatrick namespace lldb_private { 18061da546Spatrick 19061da546Spatrick class IRExecutionUnit; 20061da546Spatrick 21061da546Spatrick /// \class ExpressionParser ExpressionParser.h 22061da546Spatrick /// "lldb/Expression/ExpressionParser.h" Encapsulates an instance of a 23061da546Spatrick /// compiler that can parse expressions. 24061da546Spatrick /// 25061da546Spatrick /// ExpressionParser is the base class for llvm based Expression parsers. 26061da546Spatrick class ExpressionParser { 27061da546Spatrick public: 28061da546Spatrick /// Constructor 29061da546Spatrick /// 30061da546Spatrick /// Initializes class variables. 31061da546Spatrick /// 32061da546Spatrick /// \param[in] exe_scope 33061da546Spatrick /// If non-NULL, an execution context scope that can help to 34061da546Spatrick /// correctly create an expression with a valid process for 35061da546Spatrick /// optional tuning Objective-C runtime support. Can be NULL. 36061da546Spatrick /// 37061da546Spatrick /// \param[in] expr 38061da546Spatrick /// The expression to be parsed. ExpressionParser(ExecutionContextScope * exe_scope,Expression & expr,bool generate_debug_info)39061da546Spatrick ExpressionParser(ExecutionContextScope *exe_scope, Expression &expr, 40061da546Spatrick bool generate_debug_info) 41061da546Spatrick : m_expr(expr), m_generate_debug_info(generate_debug_info) {} 42061da546Spatrick 43061da546Spatrick /// Destructor 44*be691f3bSpatrick virtual ~ExpressionParser() = default; 45061da546Spatrick 46061da546Spatrick /// Attempts to find possible command line completions for the given 47061da546Spatrick /// expression. 48061da546Spatrick /// 49061da546Spatrick /// \param[out] request 50061da546Spatrick /// The completion request to fill out. The completion should be a string 51061da546Spatrick /// that would complete the current token at the cursor position. 52061da546Spatrick /// Note that the string in the list replaces the current token 53061da546Spatrick /// in the command line. 54061da546Spatrick /// 55061da546Spatrick /// \param[in] line 56061da546Spatrick /// The line with the completion cursor inside the expression as a string. 57061da546Spatrick /// The first line in the expression has the number 0. 58061da546Spatrick /// 59061da546Spatrick /// \param[in] pos 60061da546Spatrick /// The character position in the line with the completion cursor. 61061da546Spatrick /// If the value is 0, then the cursor is on top of the first character 62061da546Spatrick /// in the line (i.e. the user has requested completion from the start of 63061da546Spatrick /// the expression). 64061da546Spatrick /// 65061da546Spatrick /// \param[in] typed_pos 66061da546Spatrick /// The cursor position in the line as typed by the user. If the user 67061da546Spatrick /// expression has not been transformed in some form (e.g. wrapping it 68061da546Spatrick /// in a function body for C languages), then this is equal to the 69061da546Spatrick /// 'pos' parameter. The semantics of this value are otherwise equal to 70061da546Spatrick /// 'pos' (e.g. a value of 0 means the cursor is at start of the 71061da546Spatrick /// expression). 72061da546Spatrick /// 73061da546Spatrick /// \return 74061da546Spatrick /// True if we added any completion results to the output; 75061da546Spatrick /// false otherwise. 76061da546Spatrick virtual bool Complete(CompletionRequest &request, unsigned line, unsigned pos, 77061da546Spatrick unsigned typed_pos) = 0; 78061da546Spatrick 79061da546Spatrick /// Try to use the FixIts in the diagnostic_manager to rewrite the 80061da546Spatrick /// expression. If successful, the rewritten expression is stored in the 81061da546Spatrick /// diagnostic_manager, get it out with GetFixedExpression. 82061da546Spatrick /// 83061da546Spatrick /// \param[in] diagnostic_manager 84061da546Spatrick /// The diagnostic manager containing fixit's to apply. 85061da546Spatrick /// 86061da546Spatrick /// \return 87061da546Spatrick /// \b true if the rewrite was successful, \b false otherwise. RewriteExpression(DiagnosticManager & diagnostic_manager)88061da546Spatrick virtual bool RewriteExpression(DiagnosticManager &diagnostic_manager) { 89061da546Spatrick return false; 90061da546Spatrick } 91061da546Spatrick 92061da546Spatrick /// Ready an already-parsed expression for execution, possibly evaluating it 93061da546Spatrick /// statically. 94061da546Spatrick /// 95061da546Spatrick /// \param[out] func_addr 96061da546Spatrick /// The address to which the function has been written. 97061da546Spatrick /// 98061da546Spatrick /// \param[out] func_end 99061da546Spatrick /// The end of the function's allocated memory region. (func_addr 100061da546Spatrick /// and func_end do not delimit an allocated region; the allocated 101061da546Spatrick /// region may begin before func_addr.) 102061da546Spatrick /// 103061da546Spatrick /// \param[in] execution_unit_sp 104061da546Spatrick /// After parsing, ownership of the execution unit for 105061da546Spatrick /// for the expression is handed to this shared pointer. 106061da546Spatrick /// 107061da546Spatrick /// \param[in] exe_ctx 108061da546Spatrick /// The execution context to write the function into. 109061da546Spatrick /// 110061da546Spatrick /// \param[out] can_interpret 111061da546Spatrick /// Set to true if the expression could be interpreted statically; 112061da546Spatrick /// untouched otherwise. 113061da546Spatrick /// 114061da546Spatrick /// \param[in] execution_policy 115061da546Spatrick /// Determines whether the expression must be JIT-compiled, must be 116061da546Spatrick /// evaluated statically, or whether this decision may be made 117061da546Spatrick /// opportunistically. 118061da546Spatrick /// 119061da546Spatrick /// \return 120061da546Spatrick /// An error code indicating the success or failure of the operation. 121061da546Spatrick /// Test with Success(). 122061da546Spatrick virtual Status 123061da546Spatrick PrepareForExecution(lldb::addr_t &func_addr, lldb::addr_t &func_end, 124061da546Spatrick std::shared_ptr<IRExecutionUnit> &execution_unit_sp, 125061da546Spatrick ExecutionContext &exe_ctx, bool &can_interpret, 126061da546Spatrick lldb_private::ExecutionPolicy execution_policy) = 0; 127061da546Spatrick GetGenerateDebugInfo()128061da546Spatrick bool GetGenerateDebugInfo() const { return m_generate_debug_info; } 129061da546Spatrick 130061da546Spatrick protected: 131061da546Spatrick Expression &m_expr; ///< The expression to be parsed 132061da546Spatrick bool m_generate_debug_info; 133061da546Spatrick }; 134061da546Spatrick } 135061da546Spatrick 136dda28197Spatrick #endif // LLDB_EXPRESSION_EXPRESSIONPARSER_H 137