LLDB mainline
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
lldb_private::ClangExpressionParser Class Reference

"lldb/Expression/ClangExpressionParser.h" Encapsulates an instance of Clang that can parse expressions. More...

#include <ClangExpressionParser.h>

Inheritance diagram for lldb_private::ClangExpressionParser:
Inheritance graph
[legend]

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.
 
LLDBPreprocessorCallbacksm_pp_callbacks
 Called when the preprocessor encounters module imports.
 
std::shared_ptr< TypeSystemClangm_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
Expressionm_expr
 The expression to be parsed.
 
bool m_generate_debug_info
 

Detailed Description

"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.

Constructor & Destructor Documentation

◆ ClangExpressionParser()

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.

Parameters
[in]exe_scopeIf 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]exprThe expression to be parsed.
[in]include_directoriesList of include directories that should be used when parsing the expression.
[in]filenameName 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().

◆ ~ClangExpressionParser()

ClangExpressionParser::~ClangExpressionParser ( )
overridedefault

Destructor.

Member Function Documentation

◆ Complete()

bool ClangExpressionParser::Complete ( CompletionRequest request,
unsigned  line,
unsigned  pos,
unsigned  typed_pos 
)
overridevirtual

Attempts to find possible command line completions for the given expression.

Parameters
[out]requestThe 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]lineThe line with the completion cursor inside the expression as a string. The first line in the expression has the number 0.
[in]posThe 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_posThe 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).
Returns
True if we added any completion results to the output; false otherwise.

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().

◆ DoPrepareForExecution()

lldb_private::Status ClangExpressionParser::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 
)
overridevirtual

Ready an already-parsed expression for execution, possibly evaluating it statically.

Parameters
[out]func_addrThe address to which the function has been written.
[out]func_endThe 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_spAfter parsing, ownership of the execution unit for for the expression is handed to this shared pointer.
[in]exe_ctxThe execution context to write the function into.
[in]execution_policyDetermines whether the expression must be JIT-compiled, must be evaluated statically, or whether this decision may be made opportunistically.
Returns
An error code indicating the success or failure of the operation. Test with Success().

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().

◆ Parse()

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.

Parameters
[in]diagnostic_managerThe diagnostic manager to report errors to.
Returns
The number of errors encountered during parsing. 0 means success.

Definition at line 1109 of file ClangExpressionParser.cpp.

References ParseInternal().

Referenced by lldb_private::ClangUtilityFunction::Install().

◆ ParseInternal()

unsigned ClangExpressionParser::ParseInternal ( DiagnosticManager diagnostic_manager,
clang::CodeCompleteConsumer *  completion = nullptr,
unsigned  completion_line = 0,
unsigned  completion_column = 0 
)
private

Parses the expression.

Parameters
[in]diagnostic_managerThe diagnostic manager that should receive the diagnostics from the parsing process.
[in]completionThe completion consumer that should be used during parsing (or a nullptr if no consumer should be attached).
[in]completion_lineThe line in which the completion marker should be placed. The first line is represented by the value 0.
[in]completion_columnThe column in which the completion marker should be placed. The first column is represented by the value 0.
Returns
The number of parsing errors.

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().

◆ RewriteExpression()

bool ClangExpressionParser::RewriteExpression ( DiagnosticManager diagnostic_manager)
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.

Parameters
[in]diagnostic_managerThe diagnostic manager containing fixit's to apply.
Returns
true if the rewrite was successful, false otherwise.

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().

Member Data Documentation

◆ m_ast_context

std::shared_ptr<TypeSystemClang> lldb_private::ClangExpressionParser::m_ast_context
private

Definition at line 158 of file ClangExpressionParser.h.

Referenced by ClangExpressionParser(), and ParseInternal().

◆ m_code_generator

std::unique_ptr<clang::CodeGenerator> lldb_private::ClangExpressionParser::m_code_generator
private

The Clang object that generates IR.

Definition at line 153 of file ClangExpressionParser.h.

Referenced by ClangExpressionParser(), Complete(), DoPrepareForExecution(), and ParseInternal().

◆ m_compiler

std::unique_ptr<clang::CompilerInstance> lldb_private::ClangExpressionParser::m_compiler
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().

◆ m_filename

std::string lldb_private::ClangExpressionParser::m_filename
private

File name used for the user expression.

Definition at line 162 of file ClangExpressionParser.h.

Referenced by ClangExpressionParser(), and ParseInternal().

◆ m_include_directories

std::vector<std::string> lldb_private::ClangExpressionParser::m_include_directories
private

Definition at line 160 of file ClangExpressionParser.h.

Referenced by ClangExpressionParser().

◆ m_llvm_context

std::unique_ptr<llvm::LLVMContext> lldb_private::ClangExpressionParser::m_llvm_context
private

The LLVM context to generate IR into.

Definition at line 149 of file ClangExpressionParser.h.

Referenced by ClangExpressionParser(), and DoPrepareForExecution().

◆ m_pp_callbacks

LLDBPreprocessorCallbacks* lldb_private::ClangExpressionParser::m_pp_callbacks
private

Called when the preprocessor encounters module imports.

Definition at line 156 of file ClangExpressionParser.h.

Referenced by ClangExpressionParser(), and ParseInternal().


The documentation for this class was generated from the following files: