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

"lldb/Expression/ASTResultSynthesizer.h" Adds a result variable declaration to the ASTs for an expression. More...

#include <ASTResultSynthesizer.h>

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

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.
 
Targetm_target
 The target, which contains the persistent variable store and the.
 
clang::Sema * m_sema
 The Sema to use.
 
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 36 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 498 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 520 of file ASTResultSynthesizer.cpp.

References m_passthrough_sema, and m_sema.

◆ HandleTagDeclDefinition()

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

Passthrough stub.

Definition at line 493 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 101 of file ASTResultSynthesizer.cpp.

References m_passthrough, and TransformTopLevelDecl().

◆ HandleTranslationUnit()

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

Passthrough stub.

Definition at line 412 of file ASTResultSynthesizer.cpp.

References m_passthrough.

◆ HandleVTable()

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

Passthrough stub.

Definition at line 503 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 49 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 513 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 427 of file ASTResultSynthesizer.cpp.

References lldb_private::Expressions, lldb_private::GetLog(), LLDB_LOG, and m_decls.

Referenced by RecordPersistentTypes().

◆ PrintStats()

void ASTResultSynthesizer::PrintStats ( )
override

Passthrough stub.

Definition at line 508 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 440 of file ASTResultSynthesizer.cpp.

References lldb_private::Expressions, lldb_private::GetLog(), LLDB_LOG, 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 417 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 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().

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

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

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

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: