LLDB mainline
|
"lldb/Expression/ClangExpressionParser.h" Encapsulates an instance of Clang that can parse expressions. More...
#include <ClangExpressionParser.h>
Classes | |
class | LLDBPreprocessorCallbacks |
Public Member Functions | |
ClangExpressionParser (ExecutionContextScope *exe_scope, Expression &expr, bool generate_debug_info, std::vector< std::string > include_directories={}, std::string filename="<clang expression>") | |
Constructor. | |
~ClangExpressionParser () override | |
Destructor. | |
bool | Complete (CompletionRequest &request, unsigned line, unsigned pos, unsigned typed_pos) override |
Attempts to find possible command line completions for the given expression. | |
unsigned | Parse (DiagnosticManager &diagnostic_manager) |
Parse a single expression and convert it to IR using Clang. | |
bool | RewriteExpression (DiagnosticManager &diagnostic_manager) override |
Try to use the FixIts in the diagnostic_manager to rewrite the expression. | |
Status | DoPrepareForExecution (lldb::addr_t &func_addr, lldb::addr_t &func_end, lldb::IRExecutionUnitSP &execution_unit_sp, ExecutionContext &exe_ctx, bool &can_interpret, lldb_private::ExecutionPolicy execution_policy) override |
Ready an already-parsed expression for execution, possibly evaluating it statically. | |
Public Member Functions inherited from lldb_private::ExpressionParser | |
ExpressionParser (ExecutionContextScope *exe_scope, Expression &expr, bool generate_debug_info) | |
Constructor. | |
virtual | ~ExpressionParser ()=default |
Destructor. | |
virtual bool | Complete (CompletionRequest &request, unsigned line, unsigned pos, unsigned typed_pos)=0 |
Attempts to find possible command line completions for the given expression. | |
virtual bool | RewriteExpression (DiagnosticManager &diagnostic_manager) |
Try to use the FixIts in the diagnostic_manager to rewrite the expression. | |
Status | PrepareForExecution (lldb::addr_t &func_addr, lldb::addr_t &func_end, std::shared_ptr< IRExecutionUnit > &execution_unit_sp, ExecutionContext &exe_ctx, bool &can_interpret, lldb_private::ExecutionPolicy execution_policy) |
Ready an already-parsed expression for execution, possibly evaluating it statically. | |
bool | GetGenerateDebugInfo () const |
Private Member Functions | |
unsigned | ParseInternal (DiagnosticManager &diagnostic_manager, clang::CodeCompleteConsumer *completion=nullptr, unsigned completion_line=0, unsigned completion_column=0) |
Parses the expression. | |
Private Attributes | |
std::unique_ptr< llvm::LLVMContext > | m_llvm_context |
The LLVM context to generate IR into. | |
std::unique_ptr< clang::CompilerInstance > | m_compiler |
The Clang compiler used to parse expressions into IR. | |
std::unique_ptr< clang::CodeGenerator > | m_code_generator |
The Clang object that generates IR. | |
LLDBPreprocessorCallbacks * | m_pp_callbacks |
Called when the preprocessor encounters module imports. | |
std::shared_ptr< TypeSystemClang > | m_ast_context |
std::vector< std::string > | m_include_directories |
std::string | m_filename |
File name used for the user expression. | |
Additional Inherited Members | |
virtual Status | DoPrepareForExecution (lldb::addr_t &func_addr, lldb::addr_t &func_end, std::shared_ptr< IRExecutionUnit > &execution_unit_sp, ExecutionContext &exe_ctx, bool &can_interpret, lldb_private::ExecutionPolicy execution_policy)=0 |
Protected Attributes inherited from lldb_private::ExpressionParser | |
Expression & | m_expr |
The expression to be parsed. | |
bool | m_generate_debug_info |
"lldb/Expression/ClangExpressionParser.h" Encapsulates an instance of Clang that can parse expressions.
ClangExpressionParser is responsible for preparing an instance of ClangExpression for execution. ClangExpressionParser uses ClangExpression as a glorified parameter list, performing the required parsing and conversion to formats (DWARF bytecode, or JIT compiled machine code) that can be executed.
Definition at line 45 of file ClangExpressionParser.h.
ClangExpressionParser::ClangExpressionParser | ( | ExecutionContextScope * | exe_scope, |
Expression & | expr, | ||
bool | generate_debug_info, | ||
std::vector< std::string > | include_directories = {} , |
||
std::string | filename = "<clang expression>" |
||
) |
Constructor.
Initializes class variables.
[in] | exe_scope | If non-NULL, an execution context scope that can help to correctly create an expression with a valid process for optional tuning Objective-C runtime support. Can be NULL. |
[in] | expr | The expression to be parsed. |
[in] | include_directories | List of include directories that should be used when parsing the expression. |
[in] | filename | Name of the source file that should be used when rendering diagnostics (i.e. errors, warnings or notes from Clang). |
Definition at line 646 of file ClangExpressionParser.cpp.
References lldb_private::SourceLanguage::AsLanguageType(), lldb_private::ExecutionContextScope::CalculateTarget(), lldb::eLanguageTypeC, lldb::eLanguageTypeC11, lldb::eLanguageTypeC89, lldb::eLanguageTypeC99, lldb::eLanguageTypeObjC, lldb_private::Expressions, lldb_private::GetLog(), lldb_private::FileSystem::Instance(), lldb_private::Expression::Language(), LLDB_LOG, LLDB_LOGF, lldbassert, m_ast_context, m_code_generator, m_compiler, lldb_private::ExpressionParser::m_expr, m_filename, m_include_directories, m_llvm_context, m_pp_callbacks, RemoveAllCppKeywords(), SetupDefaultClangDiagnostics(), SetupImportStdModuleLangOpts(), SetupLangOpts(), SetupModuleHeaderPaths(), and SetupTargetOpts().
|
overridedefault |
Destructor.
|
overridevirtual |
Attempts to find possible command line completions for the given expression.
[out] | request | The completion request to fill out. The completion should be a string that would complete the current token at the cursor position. Note that the string in the list replaces the current token in the command line. |
[in] | line | The line with the completion cursor inside the expression as a string. The first line in the expression has the number 0. |
[in] | pos | The character position in the line with the completion cursor. If the value is 0, then the cursor is on top of the first character in the line (i.e. the user has requested completion from the start of the expression). |
[in] | typed_pos | The cursor position in the line as typed by the user. If the user expression has not been transformed in some form (e.g. wrapping it in a function body for C languages), then this is equal to the 'pos' parameter. The semantics of this value are otherwise equal to 'pos' (e.g. a value of 0 means the cursor is at start of the expression). |
Implements lldb_private::ExpressionParser.
Definition at line 1089 of file ClangExpressionParser.cpp.
References lldb_private::UserExpression::GetUserText(), m_code_generator, m_compiler, lldb_private::ExpressionParser::m_expr, and ParseInternal().
Referenced by lldb_private::ClangUserExpression::Complete().
|
overridevirtual |
Ready an already-parsed expression for execution, possibly evaluating it statically.
[out] | func_addr | The address to which the function has been written. |
[out] | func_end | The end of the function's allocated memory region. (func_addr and func_end do not delimit an allocated region; the allocated region may begin before func_addr.) |
[in] | execution_unit_sp | After parsing, ownership of the execution unit for for the expression is handed to this shared pointer. |
[in] | exe_ctx | The execution context to write the function into. |
[in] | execution_policy | Determines whether the expression must be JIT-compiled, must be evaluated statically, or whether this decision may be made opportunistically. |
Implements lldb_private::ExpressionParser.
Definition at line 1382 of file ClangExpressionParser.cpp.
References lldb_private::Status::AsCString(), lldb_private::ConstString::AsCString(), IRInterpreter::CanInterpret(), lldb_private::Process::CanInterpretFunctionCalls(), lldb_private::ClangExpressionHelper::DeclMap(), lldb_private::DiagnosticManager::Diagnostics(), lldb_private::LLVMUserExpression::IRPasses::EarlyPasses, lldb_private::eExecutionPolicyAlways, lldb_private::eExecutionPolicyNever, lldb_private::eExecutionPolicyTopLevel, lldb::eLanguageTypeUnknown, lldb_private::Expressions, FindFunctionInModule(), lldb_private::Expression::FunctionName(), lldb_private::Process::GetDynamicCheckers(), lldb_private::ExecutionContext::GetFrameSP(), lldb_private::GetLog(), lldb_private::ExecutionContext::GetProcessPtr(), lldb_private::ExecutionContext::GetProcessSP(), lldb_private::StreamString::GetString(), lldb_private::DiagnosticManager::GetString(), lldb_private::ExecutionContext::GetTargetSP(), lldb_private::Expression::GetTypeSystemHelper(), lldb_private::ClangDynamicCheckerFunctions::Install(), lldb_private::Expression::Language(), lldb_private::LLVMUserExpression::IRPasses::LatePasses, LLDB_INVALID_ADDRESS, LLDB_LOGF, m_code_generator, m_compiler, lldb_private::ExpressionParser::m_expr, m_llvm_context, lldb_private::Expression::NeedsValidation(), lldb_private::Expression::NeedsVariableResolution(), IRForTarget::runOnModule(), lldb_private::IRDynamicChecks::runOnModule(), lldb_private::Process::SetDynamicCheckers(), lldb_private::Status::SetErrorString(), lldb_private::Status::SetErrorStringWithFormat(), lldb_private::Status::SetErrorToGenericError(), lldb_private::SymbolContext::target_sp, and lldb_private::toString().
unsigned ClangExpressionParser::Parse | ( | DiagnosticManager & | diagnostic_manager | ) |
Parse a single expression and convert it to IR using Clang.
Don't wrap the expression in anything at all.
[in] | diagnostic_manager | The diagnostic manager to report errors to. |
Definition at line 1109 of file ClangExpressionParser.cpp.
References ParseInternal().
Referenced by lldb_private::ClangUtilityFunction::Install().
|
private |
Parses the expression.
[in] | diagnostic_manager | The diagnostic manager that should receive the diagnostics from the parsing process. |
[in] | completion | The completion consumer that should be used during parsing (or a nullptr if no consumer should be attached). |
[in] | completion_line | The line in which the completion marker should be placed. The first line is represented by the value 0. |
[in] | completion_column | The column in which the completion marker should be placed. The first column is represented by the value 0. |
Definition at line 1114 of file ClangExpressionParser.cpp.
References lldb_private::DiagnosticManager::AppendMessageToDiagnostic(), lldb_private::ClangExpressionHelper::ASTTransformer(), ClangDiagnosticManagerAdapter::BeginSourceFile(), lldb_private::NativeFile::Close(), lldb_private::ClangExpressionHelper::CommitPersistentDecls(), lldb_private::ClangASTSource::CreateProxy(), lldb_private::ClangExpressionHelper::DeclMap(), ClangDiagnosticManagerAdapter::EndSourceFile(), lldb_private::File::eOpenOptionWriteOnly, lldb::eSeverityError, lldb_private::ClangExpressionParser::LLDBPreprocessorCallbacks::getErrorString(), lldb_private::Expression::GetTypeSystemHelper(), lldb_private::ClangExpressionParser::LLDBPreprocessorCallbacks::hasErrors(), lldb_private::ClangASTSource::InstallASTContext(), lldb_private::ClangExpressionDeclMap::InstallCodeGenerator(), lldb_private::ClangExpressionDeclMap::InstallDiagnosticManager(), m_ast_context, m_code_generator, m_compiler, lldb_private::ExpressionParser::m_expr, m_filename, m_pp_callbacks, lldb_private::DiagnosticManager::PutString(), ClangDiagnosticManagerAdapter::ResetManager(), lldb_private::Status::Success(), lldb_private::Expression::Text(), and lldb_private::NativeFile::Write().
Referenced by Complete(), and Parse().
|
overridevirtual |
Try to use the FixIts in the diagnostic_manager to rewrite the expression.
If successful, the rewritten expression is stored in the diagnostic_manager, get it out with GetFixedExpression.
[in] | diagnostic_manager | The diagnostic manager containing fixit's to apply. |
Reimplemented from lldb_private::ExpressionParser.
Definition at line 1309 of file ClangExpressionParser.cpp.
References ApplyFixIt(), lldb_private::DiagnosticManager::Diagnostics(), m_compiler, and lldb_private::DiagnosticManager::SetFixedExpression().
|
private |
Definition at line 158 of file ClangExpressionParser.h.
Referenced by ClangExpressionParser(), and ParseInternal().
|
private |
The Clang object that generates IR.
Definition at line 153 of file ClangExpressionParser.h.
Referenced by ClangExpressionParser(), Complete(), DoPrepareForExecution(), and ParseInternal().
|
private |
The Clang compiler used to parse expressions into IR.
Definition at line 151 of file ClangExpressionParser.h.
Referenced by ClangExpressionParser(), Complete(), DoPrepareForExecution(), ParseInternal(), and RewriteExpression().
|
private |
File name used for the user expression.
Definition at line 162 of file ClangExpressionParser.h.
Referenced by ClangExpressionParser(), and ParseInternal().
|
private |
Definition at line 160 of file ClangExpressionParser.h.
Referenced by ClangExpressionParser().
|
private |
The LLVM context to generate IR into.
Definition at line 149 of file ClangExpressionParser.h.
Referenced by ClangExpressionParser(), and DoPrepareForExecution().
|
private |
Called when the preprocessor encounters module imports.
Definition at line 156 of file ClangExpressionParser.h.
Referenced by ClangExpressionParser(), and ParseInternal().