clang API Documentation
Abstract base class for actions which can be performed by the frontend. More...
#include <FrontendAction.h>
Public Member Functions | |
FrontendAction () | |
virtual | ~FrontendAction () |
bool | isCurrentFileAST () const |
const FrontendInputFile & | getCurrentInput () const |
const StringRef | getCurrentFile () const |
InputKind | getCurrentFileKind () const |
ASTUnit & | getCurrentASTUnit () const |
std::unique_ptr< ASTUnit > | takeCurrentASTUnit () |
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 | |
CompilerInstance & | getCompilerInstance () 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 |
Abstract base class for actions which can be performed by the frontend.
Definition at line 36 of file FrontendAction.h.
Definition at line 127 of file FrontendAction.cpp.
FrontendAction::~FrontendAction | ( | ) | [virtual] |
Definition at line 129 of file FrontendAction.cpp.
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.
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().
bool FrontendAction::BeginSourceFile | ( | CompilerInstance & | CI, |
const FrontendInputFile & | Input | ||
) |
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.
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(). |
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.
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.
CI | - The current compiler instance, provided as a convenience, see getCompilerInstance(). |
InFile | - The current input file, provided as a convenience, see getCurrentFile(). |
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().
void FrontendAction::EndSourceFile | ( | ) |
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().
Set the source manager's main input file, and run the action.
Definition at line 421 of file FrontendAction.cpp.
References ExecuteAction(), getCompilerInstance(), clang::CompilerInstance::getFileManager(), clang::CompilerInstance::getFrontendTimer(), clang::Preprocessor::getHeaderSearchInfo(), clang::HeaderSearch::getModuleCachePath(), clang::CompilerInstance::getPreprocessor(), clang::CompilerInstance::hasFileManager(), clang::CompilerInstance::hasFrontendTimer(), clang::CompilerInstance::hasPreprocessor(), clang::CompilerInstance::shouldBuildGlobalModuleIndex(), and clang::GlobalModuleIndex::writeIndex().
Referenced by clang::CompilerInstance::ExecuteAction(), and clang::ASTUnit::LoadFromCompilerInvocationAction().
virtual void clang::FrontendAction::ExecuteAction | ( | ) | [protected, pure virtual] |
Callback to run the program action, using the initialized compiler instance.
This is guaranteed to only be called between BeginSourceFileAction() and EndSourceFileAction().
Implemented in clang::WrapperFrontendAction, clang::PrintPreprocessedAction, clang::PreprocessOnlyAction, clang::ASTFrontendAction, clang::GeneratePTHAction, clang::DumpTokensAction, clang::DumpRawTokensAction, clang::PrintPreambleAction, clang::ASTMergeAction, clang::VerifyPCHAction, clang::DumpModuleInfoAction, clang::RewriteIncludesAction, clang::RewriteTestAction, clang::RewriteMacrosAction, and clang::CodeGenAction.
Referenced by Execute(), and clang::ASTMergeAction::ExecuteAction().
CompilerInstance& clang::FrontendAction::getCompilerInstance | ( | ) | const [inline] |
Definition at line 114 of file FrontendAction.h.
Referenced by clang::FixItAction::BeginSourceFileAction(), EndSourceFile(), clang::CodeGenAction::EndSourceFileAction(), Execute(), clang::CodeGenAction::ExecuteAction(), clang::RewriteMacrosAction::ExecuteAction(), clang::RewriteTestAction::ExecuteAction(), clang::RewriteIncludesAction::ExecuteAction(), clang::DumpModuleInfoAction::ExecuteAction(), clang::VerifyPCHAction::ExecuteAction(), clang::ASTMergeAction::ExecuteAction(), clang::PrintPreambleAction::ExecuteAction(), clang::DumpRawTokensAction::ExecuteAction(), clang::DumpTokensAction::ExecuteAction(), clang::GeneratePTHAction::ExecuteAction(), clang::ASTFrontendAction::ExecuteAction(), clang::PreprocessOnlyAction::ExecuteAction(), clang::PrintPreprocessedAction::ExecuteAction(), and shouldEraseOutputFiles().
ASTUnit& clang::FrontendAction::getCurrentASTUnit | ( | ) | const [inline] |
Definition at line 142 of file FrontendAction.h.
const StringRef clang::FrontendAction::getCurrentFile | ( | ) | const [inline] |
Definition at line 132 of file FrontendAction.h.
Referenced by EndSourceFile(), clang::CodeGenAction::ExecuteAction(), clang::RewriteMacrosAction::ExecuteAction(), clang::RewriteTestAction::ExecuteAction(), clang::RewriteIncludesAction::ExecuteAction(), clang::DumpModuleInfoAction::ExecuteAction(), clang::VerifyPCHAction::ExecuteAction(), clang::PrintPreambleAction::ExecuteAction(), clang::GeneratePTHAction::ExecuteAction(), and clang::PrintPreprocessedAction::ExecuteAction().
InputKind clang::FrontendAction::getCurrentFileKind | ( | ) | const [inline] |
Definition at line 137 of file FrontendAction.h.
Referenced by clang::GenerateModuleAction::BeginSourceFileAction(), clang::CodeGenAction::ExecuteAction(), and clang::PrintPreambleAction::ExecuteAction().
const FrontendInputFile& clang::FrontendAction::getCurrentInput | ( | ) | const [inline] |
Definition at line 128 of file FrontendAction.h.
Referenced by clang::arcmt::CheckAction::BeginInvocation(), clang::arcmt::ModifyAction::BeginInvocation(), clang::arcmt::MigrateAction::BeginInvocation(), clang::ASTMergeAction::BeginSourceFileAction(), and clang::WrapperFrontendAction::BeginSourceFileAction().
virtual TranslationUnitKind clang::FrontendAction::getTranslationUnitKind | ( | ) | [inline, virtual] |
For AST-based actions, the kind of translation unit we're handling.
Reimplemented in clang::WrapperFrontendAction, clang::ASTMergeAction, clang::GenerateModuleAction, and clang::GeneratePCHAction.
Definition at line 170 of file FrontendAction.h.
Referenced by BeginSourceFile(), clang::ASTFrontendAction::ExecuteAction(), clang::ASTMergeAction::getTranslationUnitKind(), and clang::ASTUnit::LoadFromCompilerInvocationAction().
virtual bool clang::FrontendAction::hasASTFileSupport | ( | ) | const [inline, virtual] |
Does this action support use with AST files?
Reimplemented in clang::WrapperFrontendAction, clang::ASTMergeAction, clang::DumpModuleInfoAction, clang::GenerateModuleAction, clang::GeneratePCHAction, and clang::FixItAction.
Definition at line 176 of file FrontendAction.h.
References usesPreprocessorOnly().
Referenced by BeginSourceFile(), and clang::ASTMergeAction::hasASTFileSupport().
virtual bool clang::FrontendAction::hasCodeCompletionSupport | ( | ) | const [inline, virtual] |
Does this action support use with code completion?
Reimplemented in clang::WrapperFrontendAction, clang::ASTMergeAction, clang::VerifyPCHAction, clang::DumpModuleInfoAction, and clang::SyntaxOnlyAction.
Definition at line 182 of file FrontendAction.h.
Referenced by clang::ASTFrontendAction::ExecuteAction(), and clang::ASTMergeAction::hasCodeCompletionSupport().
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().
bool clang::FrontendAction::isCurrentFileAST | ( | ) | const [inline] |
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 clang::FrontendAction::setCompilerInstance | ( | CompilerInstance * | Value | ) | [inline] |
Definition at line 119 of file FrontendAction.h.
Referenced by BeginSourceFile(), clang::ASTMergeAction::BeginSourceFileAction(), and EndSourceFile().
void FrontendAction::setCurrentInput | ( | const FrontendInputFile & | CurrentInput, |
std::unique_ptr< ASTUnit > | AST = nullptr |
||
) |
Definition at line 131 of file FrontendAction.cpp.
Referenced by BeginSourceFile(), clang::GenerateModuleAction::BeginSourceFileAction(), clang::ASTMergeAction::BeginSourceFileAction(), and EndSourceFile().
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().
friend class ASTMergeAction [friend] |
Definition at line 40 of file FrontendAction.h.
friend class WrapperFrontendAction [friend] |
Definition at line 41 of file FrontendAction.h.