brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.0 KiB · 734ad51 Raw
168 lines · c
1//===-- ClangExpressionParser.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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXPRESSIONPARSER_H10#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXPRESSIONPARSER_H11 12#include "lldb/Expression/DiagnosticManager.h"13#include "lldb/Expression/ExpressionParser.h"14#include "lldb/Utility/ArchSpec.h"15#include "lldb/Utility/Status.h"16#include "lldb/lldb-public.h"17 18#include <string>19#include <vector>20 21namespace llvm {22class LLVMContext;23}24 25namespace clang {26class CodeGenerator;27class CodeCompleteConsumer;28class CompilerInstance;29} // namespace clang30 31namespace lldb_private {32 33class IRExecutionUnit;34class TypeSystemClang;35 36/// \class ClangExpressionParser ClangExpressionParser.h37/// "lldb/Expression/ClangExpressionParser.h" Encapsulates an instance of38/// Clang that can parse expressions.39///40/// ClangExpressionParser is responsible for preparing an instance of41/// ClangExpression for execution.  ClangExpressionParser uses ClangExpression42/// as a glorified parameter list, performing the required parsing and43/// conversion to formats (DWARF bytecode, or JIT compiled machine code) that44/// can be executed.45class ClangExpressionParser : public ExpressionParser {46public:47  /// Constructor48  ///49  /// Initializes class variables.50  ///51  /// \param[in] exe_scope52  ///     If non-NULL, an execution context scope that can help to53  ///     correctly create an expression with a valid process for54  ///     optional tuning Objective-C runtime support. Can be NULL.55  ///56  /// \param[in] expr57  ///     The expression to be parsed.58  ///59  /// @param[in] include_directories60  ///     List of include directories that should be used when parsing the61  ///     expression.62  ///63  /// @param[in] filename64  ///     Name of the source file that should be used when rendering65  ///     diagnostics (i.e. errors, warnings or notes from Clang).66  ClangExpressionParser(ExecutionContextScope *exe_scope, Expression &expr,67                        bool generate_debug_info,68                        DiagnosticManager &diagnostic_manager,69                        std::vector<std::string> include_directories = {},70                        std::string filename = "<clang expression>");71 72  /// Destructor73  ~ClangExpressionParser() override;74 75  bool Complete(CompletionRequest &request, unsigned line, unsigned pos,76                unsigned typed_pos) override;77 78  /// Parse a single expression and convert it to IR using Clang.  Don't wrap79  /// the expression in anything at all.80  ///81  /// \param[in] diagnostic_manager82  ///     The diagnostic manager to report errors to.83  ///84  /// \return85  ///     The number of errors encountered during parsing.  0 means86  ///     success.87  unsigned Parse(DiagnosticManager &diagnostic_manager);88 89  bool RewriteExpression(DiagnosticManager &diagnostic_manager) override;90 91  /// Ready an already-parsed expression for execution, possibly evaluating it92  /// statically.93  ///94  /// \param[out] func_addr95  ///     The address to which the function has been written.96  ///97  /// \param[out] func_end98  ///     The end of the function's allocated memory region.  (func_addr99  ///     and func_end do not delimit an allocated region; the allocated100  ///     region may begin before func_addr.)101  ///102  /// \param[in] execution_unit_sp103  ///     After parsing, ownership of the execution unit for104  ///     for the expression is handed to this shared pointer.105  ///106  /// \param[in] exe_ctx107  ///     The execution context to write the function into.108  ///109  /// \param[in] execution_policy110  ///     Determines whether the expression must be JIT-compiled, must be111  ///     evaluated statically, or whether this decision may be made112  ///     opportunistically.113  ///114  /// \return115  ///     An error code indicating the success or failure of the operation.116  ///     Test with Success().117  Status DoPrepareForExecution(118      lldb::addr_t &func_addr, lldb::addr_t &func_end,119      lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx,120      bool &can_interpret,121      lldb_private::ExecutionPolicy execution_policy) override;122 123private:124  /// Parses the expression.125  ///126  /// \param[in] diagnostic_manager127  ///     The diagnostic manager that should receive the diagnostics128  ///     from the parsing process.129  ///130  /// \param[in] completion131  ///     The completion consumer that should be used during parsing132  ///     (or a nullptr if no consumer should be attached).133  ///134  /// \param[in] completion_line135  ///     The line in which the completion marker should be placed.136  ///     The first line is represented by the value 0.137  ///138  /// \param[in] completion_column139  ///     The column in which the completion marker should be placed.140  ///     The first column is represented by the value 0.141  ///142  /// \return143  ///    The number of parsing errors.144  unsigned ParseInternal(DiagnosticManager &diagnostic_manager,145                         clang::CodeCompleteConsumer *completion = nullptr,146                         unsigned completion_line = 0,147                         unsigned completion_column = 0);148 149  std::unique_ptr<llvm::LLVMContext>150      m_llvm_context; ///< The LLVM context to generate IR into151  std::unique_ptr<clang::CompilerInstance>152      m_compiler; ///< The Clang compiler used to parse expressions into IR153  std::unique_ptr<clang::CodeGenerator>154      m_code_generator; ///< The Clang object that generates IR155 156  class LLDBPreprocessorCallbacks;157  LLDBPreprocessorCallbacks *m_pp_callbacks; ///< Called when the preprocessor158                                             ///encounters module imports159  std::shared_ptr<TypeSystemClang> m_ast_context;160 161  std::vector<std::string> m_include_directories;162  /// File name used for the user expression.163  std::string m_filename;164};165}166 167#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXPRESSIONPARSER_H168