clang API Documentation

Public Member Functions | Friends
clang::FrontendAction Class Reference

Abstract base class for actions which can be performed by the frontend. More...

#include <FrontendAction.h>

Inheritance diagram for clang::FrontendAction:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 FrontendAction ()
virtual ~FrontendAction ()
bool isCurrentFileAST () const
const FrontendInputFilegetCurrentInput () const
const StringRef getCurrentFile () const
InputKind getCurrentFileKind () const
ASTUnitgetCurrentASTUnit () const
std::unique_ptr< ASTUnittakeCurrentASTUnit ()
void setCurrentInput (const FrontendInputFile &CurrentInput, std::unique_ptr< ASTUnit > AST=nullptr)
virtual bool isModelParsingAction () const
 Is this action invoked on a model file?
virtual bool usesPreprocessorOnly () const =0
 Does this action only use the preprocessor?
virtual TranslationUnitKind getTranslationUnitKind ()
 For AST-based actions, the kind of translation unit we're handling.
virtual bool hasPCHSupport () const
 Does this action support use with PCH?
virtual bool hasASTFileSupport () const
 Does this action support use with AST files?
virtual bool hasIRSupport () const
 Does this action support use with IR files?
virtual bool hasCodeCompletionSupport () const
 Does this action support use with code completion?
bool BeginSourceFile (CompilerInstance &CI, const FrontendInputFile &Input)
 Prepare the action for processing the input file Input.
bool Execute ()
 Set the source manager's main input file, and run the action.
void EndSourceFile ()
 Perform any per-file post processing, deallocate per-file objects, and run statistics and output file cleanup code.
Compiler Instance Access
CompilerInstancegetCompilerInstance () const
void setCompilerInstance (CompilerInstance *Value)

Protected Member Functions

Implementation Action Interface
virtual std::unique_ptr
< ASTConsumer
CreateASTConsumer (CompilerInstance &CI, StringRef InFile)=0
 Create the AST consumer object for this action, if supported.
virtual bool BeginInvocation (CompilerInstance &CI)
 Callback before starting processing a single input, giving the opportunity to modify the CompilerInvocation or do some other action before BeginSourceFileAction is called.
virtual bool BeginSourceFileAction (CompilerInstance &CI, StringRef Filename)
 Callback at the start of processing a single input.
virtual void ExecuteAction ()=0
 Callback to run the program action, using the initialized compiler instance.
virtual void EndSourceFileAction ()
 Callback at the end of processing a single input.
virtual bool shouldEraseOutputFiles ()
 Callback at the end of processing a single input, to determine if the output files should be erased or not.

Friends

class ASTMergeAction
class WrapperFrontendAction

Detailed Description

Abstract base class for actions which can be performed by the frontend.

Definition at line 36 of file FrontendAction.h.


Constructor & Destructor Documentation

Definition at line 127 of file FrontendAction.cpp.

Definition at line 129 of file FrontendAction.cpp.


Member Function Documentation

virtual bool clang::FrontendAction::BeginInvocation ( CompilerInstance CI) [inline, protected, virtual]

Callback before starting processing a single input, giving the opportunity to modify the CompilerInvocation or do some other action before BeginSourceFileAction is called.

Returns:
True on success; on failure BeginSourceFileAction(), ExecuteAction() and EndSourceFileAction() will not be called.

Reimplemented in clang::WrapperFrontendAction, clang::arcmt::ObjCMigrateAction, clang::FixItRecompile, clang::arcmt::MigrateAction, clang::arcmt::MigrateSourceAction, clang::arcmt::ModifyAction, and clang::arcmt::CheckAction.

Definition at line 73 of file FrontendAction.h.

Referenced by BeginSourceFile().

Prepare the action for processing the input file Input.

This is run after the options and frontend have been initialized, but prior to executing any per-file processing.

Parameters:
CI- The compiler instance this action is being run from. The action may store and use this object up until the matching EndSourceFile action.
Input- The input filename and kind. Some input kinds are handled specially, for example AST inputs, since the AST file itself contains several objects which would normally be owned by the CompilerInstance. When processing AST input files, these objects should generally not be initialized in the CompilerInstance -- they will automatically be shared with the AST file in between BeginSourceFile() and EndSourceFile().
Returns:
True on success; on failure the compilation of this file should be aborted and neither Execute() nor EndSourceFile() should be called.

Definition at line 171 of file FrontendAction.cpp.

References clang::PreprocessorOptions::AllowPCHWithCompilerErrors, BeginInvocation(), clang::DiagnosticConsumer::BeginSourceFile(), BeginSourceFileAction(), clang::PreprocessorOptions::ChainedIncludes, clang::CompilerInstance::clearOutputFiles(), clang::CompilerInstance::createASTContext(), clang::createChainedIncludesSource(), clang::CompilerInstance::createFileManager(), clang::CompilerInstance::createModuleManager(), clang::CompilerInstance::createPCHExternalASTSource(), clang::CompilerInstance::createPreprocessor(), clang::CompilerInstance::createSourceManager(), clang::createVFSFromCompilerInvocation(), clang::PreprocessorOptions::DeserializedPCHDeclsToErrorOn, clang::PreprocessorOptions::DisablePCHValidation, clang::PreprocessorOptions::DumpDeserializedPCHDecls, clang::DiagnosticConsumer::EndSourceFile(), clang::CompilerInstance::getASTContext(), clang::Preprocessor::getBuiltinInfo(), clang::CompilerInstance::getDiagnosticClient(), clang::CompilerInstance::getDiagnostics(), clang::FileManager::getDirectory(), clang::ASTContext::getExternalSource(), clang::FrontendInputFile::getFile(), clang::CompilerInstance::getFileManager(), clang::CompilerInstance::getFileSystemOpts(), clang::CompilerInstance::getFrontendOpts(), clang::Preprocessor::getIdentifierTable(), clang::CompilerInstance::getInvocation(), clang::FrontendInputFile::getKind(), clang::CompilerInstance::getLangOpts(), clang::Preprocessor::getLangOpts(), clang::CompilerInstance::getModuleManager(), clang::CompilerInstance::getPreprocessor(), clang::CompilerInstance::getPreprocessorOpts(), clang::CompilerInstance::getTargetOpts(), getTranslationUnitKind(), clang::CompilerInstance::hasASTConsumer(), clang::CompilerInstance::hasASTContext(), hasASTFileSupport(), clang::CompilerInstance::hasFileManager(), hasIRSupport(), hasPCHSupport(), clang::CompilerInstance::hasSourceManager(), clang::CompilerInstance::hasVirtualFileSystem(), clang::IK_AST, clang::IK_LLVM_IR, clang::PreprocessorOptions::ImplicitPCHInclude, clang::Builtin::Context::InitializeBuiltins(), clang::CompilerInstance::InitializeSourceManager(), clang::ASTReader::isAcceptableASTFile(), isCurrentFileAST(), clang::FrontendInputFile::isEmpty(), isModelParsingAction(), clang::ASTUnit::LoadFromASTFile(), clang::CompilerInstance::loadModuleFile(), clang::FrontendOptions::ModuleFiles, clang::FrontendOptions::OverrideRecordLayoutsFile, clang::DiagnosticsEngine::Report(), clang::CompilerInstance::setASTConsumer(), clang::CompilerInstance::setASTContext(), clang::ASTContext::setASTMutationListener(), setCompilerInstance(), setCurrentInput(), clang::ASTContext::setExternalSource(), clang::CompilerInstance::setFileManager(), clang::CompilerInstance::setModuleManager(), clang::CompilerInstance::setPreprocessor(), clang::CompilerInstance::setSourceManager(), clang::CompilerInstance::setVirtualFileSystem(), and usesPreprocessorOnly().

Referenced by clang::CompilerInstance::ExecuteAction(), and clang::ASTUnit::LoadFromCompilerInvocationAction().

virtual bool clang::FrontendAction::BeginSourceFileAction ( CompilerInstance CI,
StringRef  Filename 
) [inline, protected, virtual]

Callback at the start of processing a single input.

Returns:
True on success; on failure ExecutionAction() and EndSourceFileAction() will not be called.

Reimplemented in clang::WrapperFrontendAction, clang::ASTMergeAction, clang::GenerateModuleAction, and clang::FixItAction.

Definition at line 79 of file FrontendAction.h.

Referenced by BeginSourceFile(), clang::ASTMergeAction::BeginSourceFileAction(), and clang::tooling::newFrontendActionFactory().

virtual std::unique_ptr<ASTConsumer> clang::FrontendAction::CreateASTConsumer ( CompilerInstance CI,
StringRef  InFile 
) [protected, pure virtual]

Create the AST consumer object for this action, if supported.

This routine is called as part of BeginSourceFile(), which will fail if the AST consumer cannot be created. This will not be called if the action has indicated that it only uses the preprocessor.

Parameters:
CI- The current compiler instance, provided as a convenience, see getCompilerInstance().
InFile- The current input file, provided as a convenience, see getCurrentFile().
Returns:
The new AST consumer, or null on failure.

Implemented in clang::WrapperFrontendAction, clang::PreprocessorFrontendAction, clang::PluginASTAction, clang::PrintPreambleAction, clang::ASTMergeAction, clang::VerifyPCHAction, clang::DumpModuleInfoAction, clang::SyntaxOnlyAction, clang::GenerateModuleAction, clang::GeneratePCHAction, clang::arcmt::ObjCMigrateAction, clang::DeclContextPrintAction, clang::ASTViewAction, clang::RewriteObjCAction, clang::ASTDeclListAction, clang::ASTDumpAction, clang::ento::ParseModelFileAction, clang::ASTPrintAction, clang::arcmt::MigrateSourceAction, clang::CodeGenAction, clang::FixItAction, clang::ento::AnalysisAction, and clang::HTMLPrintAction.

Referenced by clang::ASTMergeAction::CreateASTConsumer().

Perform any per-file post processing, deallocate per-file objects, and run statistics and output file cleanup code.

Definition at line 442 of file FrontendAction.cpp.

References clang::BuryPointer(), clang::CompilerInstance::clearOutputFiles(), clang::FrontendOptions::DisableFree, clang::Preprocessor::EndSourceFile(), clang::DiagnosticConsumer::EndSourceFile(), EndSourceFileAction(), getCompilerInstance(), getCurrentFile(), clang::CompilerInstance::getDiagnosticClient(), clang::CompilerInstance::getFrontendOpts(), clang::Preprocessor::getHeaderSearchInfo(), clang::Preprocessor::getIdentifierTable(), clang::CompilerInstance::getPreprocessor(), clang::CompilerInstance::getSourceManager(), clang::CompilerInstance::hasPreprocessor(), isCurrentFileAST(), clang::IdentifierTable::PrintStats(), clang::HeaderSearch::PrintStats(), clang::Preprocessor::PrintStats(), clang::SourceManager::PrintStats(), clang::CompilerInstance::resetAndLeakASTContext(), clang::CompilerInstance::resetAndLeakFileManager(), clang::CompilerInstance::resetAndLeakPreprocessor(), clang::CompilerInstance::resetAndLeakSema(), clang::CompilerInstance::resetAndLeakSourceManager(), clang::CompilerInstance::setASTConsumer(), clang::CompilerInstance::setASTContext(), setCompilerInstance(), setCurrentInput(), clang::CompilerInstance::setSema(), shouldEraseOutputFiles(), clang::FrontendOptions::ShowStats, and clang::CompilerInstance::takeASTConsumer().

Referenced by clang::CompilerInstance::ExecuteAction(), and clang::ASTUnit::LoadFromCompilerInvocationAction().

virtual void clang::FrontendAction::EndSourceFileAction ( ) [inline, protected, virtual]

Callback at the end of processing a single input.

This is guaranteed to only be called following a successful call to BeginSourceFileAction (and BeginSourceFile).

Reimplemented in clang::WrapperFrontendAction, clang::ASTMergeAction, clang::CodeGenAction, and clang::FixItAction.

Definition at line 95 of file FrontendAction.h.

Referenced by EndSourceFile(), clang::ASTMergeAction::EndSourceFileAction(), and clang::tooling::newFrontendActionFactory().

virtual void clang::FrontendAction::ExecuteAction ( ) [protected, pure virtual]

Definition at line 142 of file FrontendAction.h.

const StringRef clang::FrontendAction::getCurrentFile ( ) const [inline]
virtual bool clang::FrontendAction::hasASTFileSupport ( ) const [inline, virtual]
virtual bool clang::FrontendAction::hasCodeCompletionSupport ( ) const [inline, virtual]
virtual bool clang::FrontendAction::hasIRSupport ( ) const [inline, virtual]

Does this action support use with IR files?

Reimplemented in clang::WrapperFrontendAction, clang::DumpModuleInfoAction, and clang::CodeGenAction.

Definition at line 179 of file FrontendAction.h.

References usesPreprocessorOnly().

Referenced by BeginSourceFile().

virtual bool clang::FrontendAction::hasPCHSupport ( ) const [inline, virtual]

Does this action support use with PCH?

Reimplemented in clang::WrapperFrontendAction, clang::PrintPreprocessedAction, clang::ASTMergeAction, and clang::DumpModuleInfoAction.

Definition at line 173 of file FrontendAction.h.

References clang::TU_Complete.

Referenced by BeginSourceFile(), and clang::ASTMergeAction::hasPCHSupport().

Definition at line 123 of file FrontendAction.h.

References clang::FrontendInputFile::isEmpty().

Referenced by BeginSourceFile(), and EndSourceFile().

virtual bool clang::FrontendAction::isModelParsingAction ( ) const [inline, virtual]

Is this action invoked on a model file?

Model files are incomplete translation units that relies on type information from another translation unit. Check ParseModelFileAction for details.

Reimplemented in clang::ento::ParseModelFileAction.

Definition at line 161 of file FrontendAction.h.

Referenced by BeginSourceFile(), and clang::CompilerInstance::ExecuteAction().

void FrontendAction::setCurrentInput ( const FrontendInputFile CurrentInput,
std::unique_ptr< ASTUnit AST = nullptr 
)
bool FrontendAction::shouldEraseOutputFiles ( ) [protected, virtual]

Callback at the end of processing a single input, to determine if the output files should be erased or not.

By default it returns true if a compiler error occurred. This is guaranteed to only be called following a successful call to BeginSourceFileAction (and BeginSourceFile).

Definition at line 499 of file FrontendAction.cpp.

References getCompilerInstance(), clang::CompilerInstance::getDiagnostics(), and clang::DiagnosticsEngine::hasErrorOccurred().

Referenced by EndSourceFile().

std::unique_ptr<ASTUnit> clang::FrontendAction::takeCurrentASTUnit ( ) [inline]

Definition at line 147 of file FrontendAction.h.

Referenced by clang::ASTMergeAction::BeginSourceFileAction().

virtual bool clang::FrontendAction::usesPreprocessorOnly ( ) const [pure virtual]

Does this action only use the preprocessor?

If so no AST context will be created and this action will be invalid with AST file inputs.

Implemented in clang::WrapperFrontendAction, clang::PreprocessorFrontendAction, clang::ASTFrontendAction, clang::PrintPreambleAction, clang::ASTMergeAction, and clang::InitOnlyAction.

Referenced by BeginSourceFile(), hasASTFileSupport(), hasIRSupport(), and clang::ASTMergeAction::usesPreprocessorOnly().


Friends And Related Function Documentation

friend class ASTMergeAction [friend]

Definition at line 40 of file FrontendAction.h.

friend class WrapperFrontendAction [friend]

Definition at line 41 of file FrontendAction.h.


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