LLDB mainline
|
"lldb/Expression/ASTResultSynthesizer.h" Adds a result variable declaration to the ASTs for an expression. More...
#include <ASTResultSynthesizer.h>
Public Member Functions | |
ASTResultSynthesizer (clang::ASTConsumer *passthrough, bool top_level, Target &target) | |
Constructor. | |
~ASTResultSynthesizer () override | |
Destructor. | |
void | Initialize (clang::ASTContext &Context) override |
Link this consumer with a particular AST context. | |
bool | HandleTopLevelDecl (clang::DeclGroupRef D) override |
Examine a list of Decls to find the function $__lldb_expr and transform its code. | |
void | HandleTranslationUnit (clang::ASTContext &Ctx) override |
Passthrough stub. | |
void | HandleTagDeclDefinition (clang::TagDecl *D) override |
Passthrough stub. | |
void | CompleteTentativeDefinition (clang::VarDecl *D) override |
Passthrough stub. | |
void | HandleVTable (clang::CXXRecordDecl *RD) override |
Passthrough stub. | |
void | PrintStats () override |
Passthrough stub. | |
void | InitializeSema (clang::Sema &S) override |
Set the Sema object to use when performing transforms, and pass it on. | |
void | ForgetSema () override |
Reset the Sema to NULL now that transformations are done. | |
void | CommitPersistentDecls () |
The parse has succeeded, so record its persistent decls. | |
Private Member Functions | |
void | TransformTopLevelDecl (clang::Decl *D) |
Hunt the given Decl for FunctionDecls named $__lldb_expr, recursing as necessary through LinkageSpecDecls, and calling SynthesizeResult on anything that was found. | |
bool | SynthesizeObjCMethodResult (clang::ObjCMethodDecl *MethodDecl) |
Process an Objective-C method and produce the result variable and initialization. | |
bool | SynthesizeFunctionResult (clang::FunctionDecl *FunDecl) |
Process a function and produce the result variable and initialization. | |
bool | SynthesizeBodyResult (clang::CompoundStmt *Body, clang::DeclContext *DC) |
Process a function body and produce the result variable and initialization. | |
void | RecordPersistentTypes (clang::DeclContext *FunDeclCtx) |
Given a DeclContext for a function or method, find all types declared in the context and record any persistent types found. | |
void | MaybeRecordPersistentType (clang::TypeDecl *D) |
Given a TypeDecl, if it declares a type whose name starts with a dollar sign, register it as a pointer type in the target's scratch AST context. | |
void | RecordPersistentDecl (clang::NamedDecl *D) |
Given a NamedDecl, register it as a pointer type in the target's scratch AST context. | |
Private Attributes | |
clang::ASTContext * | m_ast_context |
The AST context to use for identifiers and types. | |
clang::ASTConsumer * | m_passthrough |
The ASTConsumer down the chain, for passthrough. | |
clang::SemaConsumer * | m_passthrough_sema |
The SemaConsumer down the chain, for passthrough. | |
std::vector< clang::NamedDecl * > | m_decls |
Persistent declarations to register assuming the expression succeeds. | |
Target & | m_target |
The target, which contains the persistent variable store and the. | |
clang::Sema * | m_sema |
The Sema to use. | |
bool | m_top_level |
"lldb/Expression/ASTResultSynthesizer.h" Adds a result variable declaration to the ASTs for an expression.
Users expect the expression "i + 3" to return a result, even if a result variable wasn't specifically declared. To fulfil this requirement, LLDB adds a result variable to the expression, transforming it to "int $__lldb_expr_result = i + 3." The IR transformers ensure that the resulting variable is mapped to the right piece of memory. ASTResultSynthesizer's job is to add the variable and its initialization to the ASTs for the expression, and it does so by acting as a SemaConsumer for Clang.
Definition at line 37 of file ASTResultSynthesizer.h.
ASTResultSynthesizer::ASTResultSynthesizer | ( | clang::ASTConsumer * | passthrough, |
bool | top_level, | ||
Target & | target | ||
) |
Constructor.
[in] | passthrough | Since the ASTs must typically go through to the Clang code generator in order to produce LLVM IR, this SemaConsumer must allow them to pass to the next step in the chain after processing. Passthrough is the next ASTConsumer, or NULL if none is required. |
[in] | top_level | If true, register all top-level Decls and don't try to handle the main function. |
[in] | target | The target, which contains the persistent variable store and the AST importer. |
Definition at line 36 of file ASTResultSynthesizer.cpp.
References m_passthrough, and m_passthrough_sema.
|
overridedefault |
Destructor.
void ASTResultSynthesizer::CommitPersistentDecls | ( | ) |
The parse has succeeded, so record its persistent decls.
Definition at line 455 of file ASTResultSynthesizer.cpp.
References lldb::eLanguageTypeC, lldb_private::Expressions, lldb_private::ScratchTypeSystemClang::GetForTarget(), lldb_private::GetLog(), lldb_private::Target::GetPersistentExpressionStateForLanguage(), LLDB_LOGF, m_ast_context, m_decls, and m_target.
|
override |
Passthrough stub.
Definition at line 498 of file ASTResultSynthesizer.cpp.
References m_passthrough.
|
override |
Reset the Sema to NULL now that transformations are done.
Definition at line 520 of file ASTResultSynthesizer.cpp.
References m_passthrough_sema, and m_sema.
|
override |
Passthrough stub.
Definition at line 493 of file ASTResultSynthesizer.cpp.
References m_passthrough.
|
override |
Examine a list of Decls to find the function $__lldb_expr and transform its code.
[in] | D | The list of Decls to search. These may contain LinkageSpecDecls, which need to be searched recursively. That job falls to TransformTopLevelDecl. |
Definition at line 101 of file ASTResultSynthesizer.cpp.
References m_passthrough, and TransformTopLevelDecl().
|
override |
Passthrough stub.
Definition at line 412 of file ASTResultSynthesizer.cpp.
References m_passthrough.
|
override |
Passthrough stub.
Definition at line 503 of file ASTResultSynthesizer.cpp.
References m_passthrough.
|
override |
Link this consumer with a particular AST context.
[in] | Context | This AST context will be used for types and identifiers, and also forwarded to the passthrough consumer, if one exists. |
Definition at line 49 of file ASTResultSynthesizer.cpp.
References m_ast_context, and m_passthrough.
|
override |
Set the Sema object to use when performing transforms, and pass it on.
[in] | S | The Sema to use. Because Sema isn't externally visible, this class casts it to an Action for actual use. |
Definition at line 513 of file ASTResultSynthesizer.cpp.
References m_passthrough_sema, and m_sema.
|
private |
Given a TypeDecl, if it declares a type whose name starts with a dollar sign, register it as a pointer type in the target's scratch AST context.
Definition at line 427 of file ASTResultSynthesizer.cpp.
References lldb_private::Expressions, lldb_private::GetLog(), LLDB_LOG, and m_decls.
Referenced by RecordPersistentTypes().
|
override |
Passthrough stub.
Definition at line 508 of file ASTResultSynthesizer.cpp.
References m_passthrough.
|
private |
Given a NamedDecl, register it as a pointer type in the target's scratch AST context.
Definition at line 440 of file ASTResultSynthesizer.cpp.
References lldb_private::Expressions, lldb_private::GetLog(), LLDB_LOG, lldbassert, m_decls, and m_top_level.
Referenced by TransformTopLevelDecl().
|
private |
Given a DeclContext for a function or method, find all types declared in the context and record any persistent types found.
[in] | FunDeclCtx | The context for the function to process. |
Definition at line 417 of file ASTResultSynthesizer.cpp.
References MaybeRecordPersistentType().
Referenced by TransformTopLevelDecl().
|
private |
Process a function body and produce the result variable and initialization.
[in] | Body | The body of the function. |
[in] | DC | The DeclContext of the function, into which the result variable is inserted. |
Definition at line 221 of file ASTResultSynthesizer.cpp.
References CanTakeAddressOfLValue(), lldb_private::Expressions, lldb_private::GetLog(), LLDB_LOGF, m_ast_context, and m_sema.
Referenced by SynthesizeFunctionResult(), and SynthesizeObjCMethodResult().
|
private |
Process a function and produce the result variable and initialization.
[in] | FunDecl | The function to process. |
Definition at line 115 of file ASTResultSynthesizer.cpp.
References lldb_private::Expressions, lldb_private::GetLog(), lldb_private::Log::GetVerbose(), LLDB_LOGF, m_sema, and SynthesizeBodyResult().
Referenced by TransformTopLevelDecl().
|
private |
Process an Objective-C method and produce the result variable and initialization.
[in] | MethodDecl | The method to process. |
Definition at line 156 of file ASTResultSynthesizer.cpp.
References lldb_private::Expressions, lldb_private::GetLog(), lldb_private::Log::GetVerbose(), LLDB_LOGF, m_sema, and SynthesizeBodyResult().
Referenced by TransformTopLevelDecl().
|
private |
Hunt the given Decl for FunctionDecls named $__lldb_expr, recursing as necessary through LinkageSpecDecls, and calling SynthesizeResult on anything that was found.
[in] | D | The Decl to hunt. |
Definition at line 56 of file ASTResultSynthesizer.cpp.
References lldb_private::Expressions, lldb_private::GetLog(), lldb_private::Log::GetVerbose(), LLDB_LOGF, m_ast_context, m_top_level, RecordPersistentDecl(), RecordPersistentTypes(), SynthesizeFunctionResult(), SynthesizeObjCMethodResult(), and TransformTopLevelDecl().
Referenced by HandleTopLevelDecl(), and TransformTopLevelDecl().
|
private |
The AST context to use for identifiers and types.
Definition at line 153 of file ASTResultSynthesizer.h.
Referenced by CommitPersistentDecls(), Initialize(), SynthesizeBodyResult(), and TransformTopLevelDecl().
|
private |
Persistent declarations to register assuming the expression succeeds.
Definition at line 161 of file ASTResultSynthesizer.h.
Referenced by CommitPersistentDecls(), MaybeRecordPersistentType(), and RecordPersistentDecl().
|
private |
The ASTConsumer down the chain, for passthrough.
NULL if it's a SemaConsumer.
Definition at line 154 of file ASTResultSynthesizer.h.
Referenced by ASTResultSynthesizer(), CompleteTentativeDefinition(), HandleTagDeclDefinition(), HandleTopLevelDecl(), HandleTranslationUnit(), HandleVTable(), Initialize(), and PrintStats().
|
private |
The SemaConsumer down the chain, for passthrough.
NULL if it's an ASTConsumer.
Definition at line 157 of file ASTResultSynthesizer.h.
Referenced by ASTResultSynthesizer(), ForgetSema(), and InitializeSema().
|
private |
The Sema to use.
Definition at line 167 of file ASTResultSynthesizer.h.
Referenced by ForgetSema(), InitializeSema(), SynthesizeBodyResult(), SynthesizeFunctionResult(), and SynthesizeObjCMethodResult().
|
private |
The target, which contains the persistent variable store and the.
Definition at line 165 of file ASTResultSynthesizer.h.
Referenced by CommitPersistentDecls().
|
private |
Definition at line 168 of file ASTResultSynthesizer.h.
Referenced by RecordPersistentDecl(), and TransformTopLevelDecl().