Path: blob/main/contrib/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.h
39654 views
//===-- ClangExpressionParser.h ---------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXPRESSIONPARSER_H9#define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXPRESSIONPARSER_H1011#include "lldb/Expression/DiagnosticManager.h"12#include "lldb/Expression/ExpressionParser.h"13#include "lldb/Utility/ArchSpec.h"14#include "lldb/Utility/Status.h"15#include "lldb/lldb-public.h"1617#include <string>18#include <vector>1920namespace llvm {21class LLVMContext;22}2324namespace clang {25class CodeGenerator;26class CodeCompleteConsumer;27class CompilerInstance;28} // namespace clang2930namespace lldb_private {3132class IRExecutionUnit;33class TypeSystemClang;3435/// \class ClangExpressionParser ClangExpressionParser.h36/// "lldb/Expression/ClangExpressionParser.h" Encapsulates an instance of37/// Clang that can parse expressions.38///39/// ClangExpressionParser is responsible for preparing an instance of40/// ClangExpression for execution. ClangExpressionParser uses ClangExpression41/// as a glorified parameter list, performing the required parsing and42/// conversion to formats (DWARF bytecode, or JIT compiled machine code) that43/// can be executed.44class ClangExpressionParser : public ExpressionParser {45public:46/// Constructor47///48/// Initializes class variables.49///50/// \param[in] exe_scope51/// If non-NULL, an execution context scope that can help to52/// correctly create an expression with a valid process for53/// optional tuning Objective-C runtime support. Can be NULL.54///55/// \param[in] expr56/// The expression to be parsed.57///58/// @param[in] include_directories59/// List of include directories that should be used when parsing the60/// expression.61///62/// @param[in] filename63/// Name of the source file that should be used when rendering64/// diagnostics (i.e. errors, warnings or notes from Clang).65ClangExpressionParser(ExecutionContextScope *exe_scope, Expression &expr,66bool generate_debug_info,67std::vector<std::string> include_directories = {},68std::string filename = "<clang expression>");6970/// Destructor71~ClangExpressionParser() override;7273bool Complete(CompletionRequest &request, unsigned line, unsigned pos,74unsigned typed_pos) override;7576/// Parse a single expression and convert it to IR using Clang. Don't wrap77/// the expression in anything at all.78///79/// \param[in] diagnostic_manager80/// The diagnostic manager to report errors to.81///82/// \return83/// The number of errors encountered during parsing. 0 means84/// success.85unsigned Parse(DiagnosticManager &diagnostic_manager);8687bool RewriteExpression(DiagnosticManager &diagnostic_manager) override;8889/// Ready an already-parsed expression for execution, possibly evaluating it90/// statically.91///92/// \param[out] func_addr93/// The address to which the function has been written.94///95/// \param[out] func_end96/// The end of the function's allocated memory region. (func_addr97/// and func_end do not delimit an allocated region; the allocated98/// region may begin before func_addr.)99///100/// \param[in] execution_unit_sp101/// After parsing, ownership of the execution unit for102/// for the expression is handed to this shared pointer.103///104/// \param[in] exe_ctx105/// The execution context to write the function into.106///107/// \param[in] execution_policy108/// Determines whether the expression must be JIT-compiled, must be109/// evaluated statically, or whether this decision may be made110/// opportunistically.111///112/// \return113/// An error code indicating the success or failure of the operation.114/// Test with Success().115Status DoPrepareForExecution(116lldb::addr_t &func_addr, lldb::addr_t &func_end,117lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx,118bool &can_interpret,119lldb_private::ExecutionPolicy execution_policy) override;120121/// Returns a string representing current ABI.122///123/// \param[in] target_arch124/// The target architecture.125///126/// \return127/// A string representing target ABI for the current architecture.128std::string GetClangTargetABI(const ArchSpec &target_arch);129130private:131/// Parses the expression.132///133/// \param[in] diagnostic_manager134/// The diagnostic manager that should receive the diagnostics135/// from the parsing process.136///137/// \param[in] completion138/// The completion consumer that should be used during parsing139/// (or a nullptr if no consumer should be attached).140///141/// \param[in] completion_line142/// The line in which the completion marker should be placed.143/// The first line is represented by the value 0.144///145/// \param[in] completion_column146/// The column in which the completion marker should be placed.147/// The first column is represented by the value 0.148///149/// \return150/// The number of parsing errors.151unsigned ParseInternal(DiagnosticManager &diagnostic_manager,152clang::CodeCompleteConsumer *completion = nullptr,153unsigned completion_line = 0,154unsigned completion_column = 0);155156std::unique_ptr<llvm::LLVMContext>157m_llvm_context; ///< The LLVM context to generate IR into158std::unique_ptr<clang::CompilerInstance>159m_compiler; ///< The Clang compiler used to parse expressions into IR160std::unique_ptr<clang::CodeGenerator>161m_code_generator; ///< The Clang object that generates IR162163class LLDBPreprocessorCallbacks;164LLDBPreprocessorCallbacks *m_pp_callbacks; ///< Called when the preprocessor165///encounters module imports166std::shared_ptr<TypeSystemClang> m_ast_context;167168std::vector<std::string> m_include_directories;169/// File name used for the user expression.170std::string m_filename;171};172}173174#endif // LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXPRESSIONPARSER_H175176177