clang 22.0.0git
clang::FrontendAction Class Referenceabstract

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

#include "clang/Frontend/FrontendAction.h"

Inheritance diagram for clang::FrontendAction:
[legend]

Public Member Functions

 FrontendAction ()
virtual ~FrontendAction ()
Compiler Instance Access
CompilerInstancegetCompilerInstance () const
void setCompilerInstance (CompilerInstance *Value)
Current File Information
bool isCurrentFileAST () const
const FrontendInputFilegetCurrentInput () const
StringRef getCurrentFile () const
StringRef getCurrentFileOrBufferName () const
InputKind getCurrentFileKind () const
ASTUnitgetCurrentASTUnit () const
ModulegetCurrentModule () const
std::unique_ptr< ASTUnittakeCurrentASTUnit ()
void setCurrentInput (const FrontendInputFile &CurrentInput, std::unique_ptr< ASTUnit > AST=nullptr)
Supported Modes
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?
Public Action Interface
bool PrepareToExecute (CompilerInstance &CI)
 Prepare the action to execute on the given compiler instance.
bool BeginSourceFile (CompilerInstance &CI, const FrontendInputFile &Input)
 Prepare the action for processing the input file Input.
llvm::Error Execute ()
 Set the source manager's main input file, and run the action.
virtual void EndSourceFile ()
 Perform any per-file post processing, deallocate per-file objects, and run statistics and output file cleanup code.

Protected Member Functions

Implementation Action Interface
virtual bool PrepareToExecuteAction (CompilerInstance &CI)
 Prepare to execute the action on the given CompilerInstance.
virtual std::unique_ptr< ASTConsumerCreateASTConsumer (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)
 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 37 of file FrontendAction.h.

Constructor & Destructor Documentation

◆ FrontendAction()

FrontendAction::FrontendAction ( )

Definition at line 368 of file FrontendAction.cpp.

References clang::nullptr.

◆ ~FrontendAction()

FrontendAction::~FrontendAction ( )
virtual

Definition at line 370 of file FrontendAction.cpp.

Member Function Documentation

◆ BeginInvocation()

virtual bool clang::FrontendAction::BeginInvocation ( CompilerInstance & CI)
inlineprotectedvirtual

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::DumpModuleInfoAction, clang::FixItRecompile, and clang::WrapperFrontendAction.

Definition at line 80 of file FrontendAction.h.

Referenced by BeginSourceFile().

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

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 825 of file FrontendAction.cpp.

References clang::PreprocessorOptions::AllowPCHWithCompilerErrors, BeginInvocation(), clang::DiagnosticConsumer::BeginSourceFile(), BeginSourceFileAction(), clang::SrcMgr::C_System, clang::SrcMgr::C_User, clang::PreprocessorOptions::ChainedIncludes, clang::CompilerInstance::clearOutputFiles(), clang::LangOptionsBase::CMK_ModuleMap, clang::LangOptionsBase::CMK_None, clang::CompilerInstance::createASTContext(), clang::CompilerInstance::createASTReader(), clang::createChainedIncludesSource(), clang::SourceManager::createFileID(), clang::CompilerInstance::createFileManager(), clang::CompilerInstance::createPCHExternalASTSource(), clang::CompilerInstance::createPreprocessor(), clang::CompilerInstance::createSourceManager(), clang::LangOptions::CurrentModule, clang::PreprocessorOptions::DeserializedPCHDeclsToErrorOn, clang::PreprocessorOptions::DisablePCHOrModuleValidation, clang::PreprocessorOptions::DumpDeserializedPCHDecls, clang::DiagnosticConsumer::EndSourceFile(), clang::File, clang::FileName, clang::ModuleMap::finishModuleDeclarationScope(), clang::Found, clang::CompilerInstance::getASTContext(), clang::CompilerInstance::getASTReader(), clang::Preprocessor::getBuiltinInfo(), clang::CompilerInstance::getCodeGenOpts(), getCurrentFileOrBufferName(), clang::Preprocessor::getCurrentModuleImplementation(), clang::CompilerInstance::getDiagnosticClient(), clang::CompilerInstance::getDiagnosticOpts(), clang::CompilerInstance::getDiagnostics(), clang::CompilerInstance::getDiagnosticsPtr(), clang::ASTContext::getExternalSource(), clang::ASTContext::getExternalSourcePtr(), clang::FrontendInputFile::getFile(), clang::CompilerInstance::getFileManager(), clang::CompilerInstance::getFileSystemOpts(), clang::InputKind::getFormat(), clang::CompilerInstance::getFrontendOpts(), clang::Preprocessor::getHeaderSearchInfo(), clang::CompilerInstance::getHeaderSearchOpts(), clang::InputKind::getHeaderUnitKind(), clang::Preprocessor::getIdentifierTable(), getInputBufferForModule(), clang::FrontendInputFile::getKind(), clang::CompilerInstance::getLangOpts(), clang::Preprocessor::getLangOpts(), clang::InputKind::getLanguage(), clang::CompilerInstance::getModuleCache(), clang::ASTReader::getModuleManager(), clang::HeaderSearch::getModuleMap(), clang::FileEntryRef::getName(), clang::FileManager::getOptionalDirectoryRef(), clang::FileManager::getOptionalFileRef(), clang::CompilerInstance::getPCHContainerReader(), clang::CompilerInstance::getPreprocessor(), clang::CompilerInstance::getPreprocessorOpts(), clang::serialization::ModuleManager::getPrimaryModule(), clang::CompilerInstance::getSourceManager(), clang::CompilerInstance::getSpecificModuleCachePath(), clang::CompilerInstance::getTargetOpts(), getTranslationUnitKind(), clang::CompilerInstance::hasASTConsumer(), clang::CompilerInstance::hasASTContext(), hasASTFileSupport(), clang::CompilerInstance::hasFileManager(), hasIRSupport(), hasPCHSupport(), clang::CompilerInstance::hasPreprocessor(), clang::CompilerInstance::hasSourceManager(), clang::InputKind::HeaderUnit_Abs, clang::InputKind::HeaderUnit_System, clang::PreprocessorOptions::ImplicitPCHInclude, clang::Builtin::Context::initializeBuiltins(), clang::SourceManager::initializeForReplay(), clang::CompilerInstance::InitializeSourceManager(), clang::ASTReader::isAcceptableASTFile(), clang::FrontendInputFile::isEmpty(), clang::InputKind::isHeaderUnit(), isModelParsingAction(), clang::FrontendInputFile::isPreprocessed(), clang::InputKind::isPreprocessed(), clang::FrontendInputFile::isSystem(), clang::LLVM_IR, clang::ASTUnit::LoadEverything, clang::ASTUnit::LoadFromASTFile(), clang::CompilerInstance::loadModuleFile(), loadModuleMapForModuleBuild(), clang::ASTUnit::LoadPreprocessorOnly, clang::HeaderSearch::LookupFile(), clang::FrontendOptions::ModuleFiles, clang::InputKind::ModuleMap, clang::FrontendOptions::ModuleMapFiles, clang::LangOptions::ModuleName, clang::FrontendOptions::ModulesEmbedAllFiles, clang::FrontendOptions::ModulesEmbedFiles, clang::Override, clang::FrontendOptions::OverrideRecordLayoutsFile, clang::HeaderSearch::parseAndLoadModuleMapFile(), clang::InputKind::Precompiled, prepareToBuildModule(), clang::Module::PresumedModuleMapFile, ReadOriginalFileName(), clang::DiagnosticsEngine::Report(), clang::DiagnosticOptions::SARIF, clang::SourceManager::setAllFilesAreTransient(), clang::CompilerInstance::setASTConsumer(), clang::CompilerInstance::setASTContext(), clang::ASTContext::setASTMutationListener(), clang::CompilerInstance::setASTReader(), setCompilerInstance(), setCurrentInput(), clang::ASTContext::setExternalSource(), clang::SourceManager::setFileIsTransient(), clang::CompilerInstance::setFileManager(), clang::CompilerInstance::setPreprocessor(), clang::SARIFDiagnosticPrinter::setSarifWriter(), clang::Preprocessor::setSkipMainFilePreamble(), clang::CompilerInstance::setSourceManager(), clang::serialization::ModuleFile::StandardCXXModule, usesPreprocessorOnly(), clang::ASTReader::visitTopLevelModuleMaps(), and clang::InputKind::withHeaderUnit().

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

◆ BeginSourceFileAction()

◆ CreateASTConsumer()

virtual std::unique_ptr< ASTConsumer > clang::FrontendAction::CreateASTConsumer ( CompilerInstance & CI,
StringRef InFile )
protectedpure virtual

◆ EndSourceFile()

void FrontendAction::EndSourceFile ( )
virtual

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

Reimplemented in clang::IncrementalAction, and clang::WrapperFrontendAction.

Definition at line 1332 of file FrontendAction.cpp.

References clang::CompilerInstance::clearOutputFiles(), clang::LangOptionsBase::CMK_None, clang::FrontendOptions::DisableFree, clang::DiagnosticConsumer::EndSourceFile(), clang::Preprocessor::EndSourceFile(), EndSourceFileAction(), getCompilerInstance(), getCurrentFileOrBufferName(), clang::CompilerInstance::getDiagnosticClient(), clang::CompilerInstance::getFrontendOpts(), clang::Preprocessor::getHeaderSearchInfo(), clang::Preprocessor::getIdentifierTable(), clang::CompilerInstance::getLangOpts(), clang::CompilerInstance::getPreprocessor(), clang::CompilerInstance::getSourceManager(), clang::CompilerInstance::hasPreprocessor(), clang::CompilerInstance::hasSourceManager(), isCurrentFileAST(), clang::HeaderSearch::PrintStats(), clang::IdentifierTable::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::setFileManager(), clang::CompilerInstance::setPreprocessor(), clang::CompilerInstance::setSema(), clang::CompilerInstance::setSourceManager(), shouldEraseOutputFiles(), clang::FrontendOptions::ShowStats, and clang::CompilerInstance::takeASTConsumer().

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

◆ EndSourceFileAction()

virtual void clang::FrontendAction::EndSourceFileAction ( )
inlineprotectedvirtual

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::ASTMergeAction, clang::CodeGenAction, clang::FixItAction, and clang::WrapperFrontendAction.

Definition at line 103 of file FrontendAction.h.

References getCompilerInstance(), clang::CompilerInstance::getPreprocessor(), and clang::Preprocessor::SetEnableMacroExpansion().

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

◆ Execute()

◆ ExecuteAction()

◆ getCompilerInstance()

◆ getCurrentASTUnit()

ASTUnit & clang::FrontendAction::getCurrentASTUnit ( ) const
inline

Definition at line 163 of file FrontendAction.h.

Referenced by clang::DumpModuleInfoAction::ExecuteAction().

◆ getCurrentFile()

StringRef clang::FrontendAction::getCurrentFile ( ) const
inline

◆ getCurrentFileKind()

InputKind clang::FrontendAction::getCurrentFileKind ( ) const
inline

◆ getCurrentFileOrBufferName()

◆ getCurrentInput()

◆ getCurrentModule()

◆ getTranslationUnitKind()

virtual TranslationUnitKind clang::FrontendAction::getTranslationUnitKind ( )
inlinevirtual

◆ hasASTFileSupport()

virtual bool clang::FrontendAction::hasASTFileSupport ( ) const
inlinevirtual

◆ hasCodeCompletionSupport()

virtual bool clang::FrontendAction::hasCodeCompletionSupport ( ) const
inlinevirtual

Does this action support use with code completion?

Reimplemented in clang::ASTMergeAction, clang::DumpModuleInfoAction, clang::SyntaxOnlyAction, clang::VerifyPCHAction, and clang::WrapperFrontendAction.

Definition at line 212 of file FrontendAction.h.

Referenced by clang::ASTFrontendAction::ExecuteAction().

◆ hasIRSupport()

virtual bool clang::FrontendAction::hasIRSupport ( ) const
inlinevirtual

Does this action support use with IR files?

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

Definition at line 209 of file FrontendAction.h.

Referenced by BeginSourceFile(), and clang::IncrementalAction::getCodeGen().

◆ hasPCHSupport()

virtual bool clang::FrontendAction::hasPCHSupport ( ) const
inlinevirtual

Does this action support use with PCH?

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

Definition at line 203 of file FrontendAction.h.

Referenced by BeginSourceFile().

◆ isCurrentFileAST()

bool clang::FrontendAction::isCurrentFileAST ( ) const
inline

Definition at line 137 of file FrontendAction.h.

Referenced by EndSourceFile(), and clang::DumpModuleInfoAction::ExecuteAction().

◆ isModelParsingAction()

virtual bool clang::FrontendAction::isModelParsingAction ( ) const
inlinevirtual

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 186 of file FrontendAction.h.

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

◆ PrepareToExecute()

bool clang::FrontendAction::PrepareToExecute ( CompilerInstance & CI)
inline

Prepare the action to execute on the given compiler instance.

Definition at line 219 of file FrontendAction.h.

References PrepareToExecuteAction().

Referenced by clang::CompilerInstance::ExecuteAction().

◆ PrepareToExecuteAction()

virtual bool clang::FrontendAction::PrepareToExecuteAction ( CompilerInstance & CI)
inlineprotectedvirtual

Prepare to execute the action on the given CompilerInstance.

This is called before executing the action on any inputs, and can modify the configuration as needed (including adjusting the input list).

Reimplemented in clang::GenerateModuleInterfaceAction, and clang::WrapperFrontendAction.

Definition at line 56 of file FrontendAction.h.

Referenced by PrepareToExecute(), and clang::GenerateModuleInterfaceAction::PrepareToExecuteAction().

◆ setCompilerInstance()

void clang::FrontendAction::setCompilerInstance ( CompilerInstance * Value)
inline

Definition at line 131 of file FrontendAction.h.

Referenced by BeginSourceFile(), and EndSourceFile().

◆ setCurrentInput()

void FrontendAction::setCurrentInput ( const FrontendInputFile & CurrentInput,
std::unique_ptr< ASTUnit > AST = nullptr )

◆ shouldEraseOutputFiles()

bool FrontendAction::shouldEraseOutputFiles ( )
protectedvirtual

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

Reimplemented in clang::GenerateModuleAction, clang::GeneratePCHAction, and clang::WrapperFrontendAction.

Definition at line 1399 of file FrontendAction.cpp.

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

Referenced by EndSourceFile(), clang::GenerateModuleAction::shouldEraseOutputFiles(), and clang::GeneratePCHAction::shouldEraseOutputFiles().

◆ takeCurrentASTUnit()

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

Definition at line 170 of file FrontendAction.h.

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

◆ usesPreprocessorOnly()

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

◆ ASTMergeAction

friend class ASTMergeAction
friend

Definition at line 41 of file FrontendAction.h.

References ASTMergeAction.

Referenced by ASTMergeAction.

◆ WrapperFrontendAction

friend class WrapperFrontendAction
friend

Definition at line 42 of file FrontendAction.h.

References WrapperFrontendAction.

Referenced by WrapperFrontendAction.


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