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

#include <ASTResultSynthesizer.h>

Inheritance diagram for lldb_private::ASTResultSynthesizer:
Inheritance graph
[legend]
Collaboration diagram for lldb_private::ASTResultSynthesizer:
Collaboration graph
[legend]

Public Member Functions

 ASTResultSynthesizer (clang::ASTConsumer *passthrough, bool top_level, Target &target)
 Constructor. More...
 
 ~ASTResultSynthesizer () override
 Destructor. More...
 
void Initialize (clang::ASTContext &Context) override
 Link this consumer with a particular AST context. More...
 
bool HandleTopLevelDecl (clang::DeclGroupRef D) override
 Examine a list of Decls to find the function $__lldb_expr and transform its code. More...
 
void HandleTranslationUnit (clang::ASTContext &Ctx) override
 Passthrough stub. More...
 
void HandleTagDeclDefinition (clang::TagDecl *D) override
 Passthrough stub. More...
 
void CompleteTentativeDefinition (clang::VarDecl *D) override
 Passthrough stub. More...
 
void HandleVTable (clang::CXXRecordDecl *RD) override
 Passthrough stub. More...
 
void PrintStats () override
 Passthrough stub. More...
 
void InitializeSema (clang::Sema &S) override
 Set the Sema object to use when performing transforms, and pass it on. More...
 
void ForgetSema () override
 Reset the Sema to NULL now that transformations are done. More...
 
void CommitPersistentDecls ()
 The parse has succeeded, so record its persistent decls. More...
 

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. More...
 
bool SynthesizeObjCMethodResult (clang::ObjCMethodDecl *MethodDecl)
 Process an Objective-C method and produce the result variable and initialization. More...
 
bool SynthesizeFunctionResult (clang::FunctionDecl *FunDecl)
 Process a function and produce the result variable and initialization. More...
 
bool SynthesizeBodyResult (clang::CompoundStmt *Body, clang::DeclContext *DC)
 Process a function body and produce the result variable and initialization. More...
 
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. More...
 
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. More...
 
void RecordPersistentDecl (clang::NamedDecl *D)
 Given a NamedDecl, register it as a pointer type in the target's scratch AST context. More...
 

Private Attributes

clang::ASTContext * m_ast_context
 The AST context to use for identifiers and types. More...
 
clang::ASTConsumer * m_passthrough
 The ASTConsumer down the chain, for passthrough. More...
 
clang::SemaConsumer * m_passthrough_sema
 The SemaConsumer down the chain, for passthrough. More...
 
std::vector< clang::NamedDecl * > m_decls
 Persistent declarations to register assuming the expression succeeds. More...
 
Targetm_target
 The target, which contains the persistent variable store and the. More...
 
clang::Sema * m_sema
 The Sema to use. More...
 
bool m_top_level
 

Detailed Description

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

Constructor & Destructor Documentation

◆ ASTResultSynthesizer()

ASTResultSynthesizer::ASTResultSynthesizer ( clang::ASTConsumer *  passthrough,
bool  top_level,
Target target 
)

Constructor.

Parameters
[in]passthroughSince 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_levelIf true, register all top-level Decls and don't try to handle the main function.
[in]targetThe target, which contains the persistent variable store and the AST importer.

Definition at line 35 of file ASTResultSynthesizer.cpp.

References m_passthrough, and m_passthrough_sema.

◆ ~ASTResultSynthesizer()

ASTResultSynthesizer::~ASTResultSynthesizer ( )
overridedefault

Destructor.

Member Function Documentation

◆ CommitPersistentDecls()

void ASTResultSynthesizer::CommitPersistentDecls ( )

◆ CompleteTentativeDefinition()

void ASTResultSynthesizer::CompleteTentativeDefinition ( clang::VarDecl *  D)
override

Passthrough stub.

Definition at line 483 of file ASTResultSynthesizer.cpp.

References m_passthrough.

◆ ForgetSema()

void ASTResultSynthesizer::ForgetSema ( )
override

Reset the Sema to NULL now that transformations are done.

Definition at line 505 of file ASTResultSynthesizer.cpp.

References m_passthrough_sema, and m_sema.

◆ HandleTagDeclDefinition()

void ASTResultSynthesizer::HandleTagDeclDefinition ( clang::TagDecl *  D)
override

Passthrough stub.

Definition at line 478 of file ASTResultSynthesizer.cpp.

References m_passthrough.

◆ HandleTopLevelDecl()

bool ASTResultSynthesizer::HandleTopLevelDecl ( clang::DeclGroupRef  D)
override

Examine a list of Decls to find the function $__lldb_expr and transform its code.

Parameters
[in]DThe list of Decls to search. These may contain LinkageSpecDecls, which need to be searched recursively. That job falls to TransformTopLevelDecl.

Definition at line 100 of file ASTResultSynthesizer.cpp.

References m_passthrough, and TransformTopLevelDecl().

◆ HandleTranslationUnit()

void ASTResultSynthesizer::HandleTranslationUnit ( clang::ASTContext &  Ctx)
override

Passthrough stub.

Definition at line 386 of file ASTResultSynthesizer.cpp.

References m_passthrough.

◆ HandleVTable()

void ASTResultSynthesizer::HandleVTable ( clang::CXXRecordDecl *  RD)
override

Passthrough stub.

Definition at line 488 of file ASTResultSynthesizer.cpp.

References m_passthrough.

◆ Initialize()

void ASTResultSynthesizer::Initialize ( clang::ASTContext &  Context)
override

Link this consumer with a particular AST context.

Parameters
[in]ContextThis AST context will be used for types and identifiers, and also forwarded to the passthrough consumer, if one exists.

Definition at line 48 of file ASTResultSynthesizer.cpp.

References m_ast_context, and m_passthrough.

◆ InitializeSema()

void ASTResultSynthesizer::InitializeSema ( clang::Sema &  S)
override

Set the Sema object to use when performing transforms, and pass it on.

Parameters
[in]SThe Sema to use. Because Sema isn't externally visible, this class casts it to an Action for actual use.

Definition at line 498 of file ASTResultSynthesizer.cpp.

References m_passthrough_sema, and m_sema.

◆ MaybeRecordPersistentType()

void ASTResultSynthesizer::MaybeRecordPersistentType ( clang::TypeDecl *  D)
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 401 of file ASTResultSynthesizer.cpp.

References lldb_private::ConstString::GetCString(), lldb_private::GetLogIfAllCategoriesSet(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOGF, and m_decls.

Referenced by RecordPersistentTypes().

◆ PrintStats()

void ASTResultSynthesizer::PrintStats ( )
override

Passthrough stub.

Definition at line 493 of file ASTResultSynthesizer.cpp.

References m_passthrough.

◆ RecordPersistentDecl()

void ASTResultSynthesizer::RecordPersistentDecl ( clang::NamedDecl *  D)
private

Given a NamedDecl, register it as a pointer type in the target's scratch AST context.

Definition at line 419 of file ASTResultSynthesizer.cpp.

References lldb_private::ConstString::GetCString(), lldb_private::GetLogIfAllCategoriesSet(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOGF, lldbassert, m_decls, and m_top_level.

Referenced by TransformTopLevelDecl().

◆ RecordPersistentTypes()

void ASTResultSynthesizer::RecordPersistentTypes ( clang::DeclContext *  FunDeclCtx)
private

Given a DeclContext for a function or method, find all types declared in the context and record any persistent types found.

Parameters
[in]FunDeclCtxThe context for the function to process.

Definition at line 391 of file ASTResultSynthesizer.cpp.

References MaybeRecordPersistentType().

Referenced by TransformTopLevelDecl().

◆ SynthesizeBodyResult()

bool ASTResultSynthesizer::SynthesizeBodyResult ( clang::CompoundStmt *  Body,
clang::DeclContext *  DC 
)
private

Process a function body and produce the result variable and initialization.

Parameters
[in]BodyThe body of the function.
[in]DCThe DeclContext of the function, into which the result variable is inserted.

Definition at line 199 of file ASTResultSynthesizer.cpp.

References lldb_private::GetLogIfAllCategoriesSet(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOGF, m_ast_context, m_sema, and string().

Referenced by SynthesizeFunctionResult(), and SynthesizeObjCMethodResult().

◆ SynthesizeFunctionResult()

bool ASTResultSynthesizer::SynthesizeFunctionResult ( clang::FunctionDecl *  FunDecl)
private

Process a function and produce the result variable and initialization.

Parameters
[in]FunDeclThe function to process.

Definition at line 114 of file ASTResultSynthesizer.cpp.

References lldb_private::GetLogIfAllCategoriesSet(), lldb_private::Log::GetVerbose(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOGF, m_sema, string(), and SynthesizeBodyResult().

Referenced by TransformTopLevelDecl().

◆ SynthesizeObjCMethodResult()

bool ASTResultSynthesizer::SynthesizeObjCMethodResult ( clang::ObjCMethodDecl *  MethodDecl)
private

Process an Objective-C method and produce the result variable and initialization.

Parameters
[in]MethodDeclThe method to process.

Definition at line 155 of file ASTResultSynthesizer.cpp.

References lldb_private::GetLogIfAllCategoriesSet(), lldb_private::Log::GetVerbose(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOGF, m_sema, string(), and SynthesizeBodyResult().

Referenced by TransformTopLevelDecl().

◆ TransformTopLevelDecl()

void ASTResultSynthesizer::TransformTopLevelDecl ( clang::Decl *  D)
private

Hunt the given Decl for FunctionDecls named $__lldb_expr, recursing as necessary through LinkageSpecDecls, and calling SynthesizeResult on anything that was found.

Parameters
[in]DThe Decl to hunt.

Definition at line 55 of file ASTResultSynthesizer.cpp.

References lldb_private::GetLogIfAllCategoriesSet(), lldb_private::Log::GetVerbose(), LIBLLDB_LOG_EXPRESSIONS, LLDB_LOGF, m_ast_context, m_top_level, RecordPersistentDecl(), RecordPersistentTypes(), SynthesizeFunctionResult(), and SynthesizeObjCMethodResult().

Referenced by HandleTopLevelDecl().

Member Data Documentation

◆ m_ast_context

clang::ASTContext* lldb_private::ASTResultSynthesizer::m_ast_context
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().

◆ m_decls

std::vector<clang::NamedDecl *> lldb_private::ASTResultSynthesizer::m_decls
private

Persistent declarations to register assuming the expression succeeds.

Definition at line 161 of file ASTResultSynthesizer.h.

Referenced by CommitPersistentDecls(), MaybeRecordPersistentType(), and RecordPersistentDecl().

◆ m_passthrough

clang::ASTConsumer* lldb_private::ASTResultSynthesizer::m_passthrough
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().

◆ m_passthrough_sema

clang::SemaConsumer* lldb_private::ASTResultSynthesizer::m_passthrough_sema
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().

◆ m_sema

clang::Sema* lldb_private::ASTResultSynthesizer::m_sema
private

◆ m_target

Target& lldb_private::ASTResultSynthesizer::m_target
private

The target, which contains the persistent variable store and the.

Definition at line 165 of file ASTResultSynthesizer.h.

Referenced by CommitPersistentDecls().

◆ m_top_level

bool lldb_private::ASTResultSynthesizer::m_top_level
private

Definition at line 168 of file ASTResultSynthesizer.h.

Referenced by RecordPersistentDecl(), and TransformTopLevelDecl().


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