17#ifndef LLVM_CLANG_FRONTEND_FRONTENDACTION_H
18#define LLVM_CLANG_FRONTEND_FRONTENDACTION_H
26#include "llvm/ADT/StringRef.h"
27#include "llvm/Support/Error.h"
34class CompilerInstance;
39 std::unique_ptr<ASTUnit> CurrentASTUnit;
72 StringRef InFile) = 0;
127 assert(Instance &&
"Compiler instance not registered!");
138 assert(!CurrentInput.
isEmpty() &&
"No current file!");
139 return (
bool)CurrentASTUnit;
147 assert(!CurrentInput.
isEmpty() &&
"No current file!");
152 assert(!CurrentInput.
isEmpty() &&
"No current file!");
153 return CurrentInput.
isFile()
155 : CurrentInput.
getBuffer().getBufferIdentifier();
159 assert(!CurrentInput.
isEmpty() &&
"No current file!");
164 assert(CurrentASTUnit &&
"No current AST unit!");
165 return *CurrentASTUnit;
171 return std::move(CurrentASTUnit);
175 std::unique_ptr<ASTUnit> AST =
nullptr);
197 if (Instance && Instance->hasASTContext())
198 return Instance->getASTContext().TUKind;
270 virtual void anchor();
273 StringRef InFile)
override = 0;
282 const std::vector<std::string> &arg) = 0;
305 StringRef InFile)
override;
323 StringRef InFile)
override;
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
Abstract base class to use for AST consumer-based frontend actions.
void ExecuteAction() override
Implement the ExecuteAction interface by running Sema on the already-initialized AST consumer.
bool usesPreprocessorOnly() const override
Does this action only use the preprocessor?
Frontend action adaptor that merges ASTs together.
Utility class for loading a ASTContext from an AST file.
CompilerInstance - Helper class for managing a single instance of the Clang compiler.
Preprocessor & getPreprocessor() const
Return the current preprocessor.
Abstract base class for actions which can be performed by the frontend.
const FrontendInputFile & getCurrentInput() const
InputKind getCurrentFileKind() const
virtual bool hasIRSupport() const
Does this action support use with IR files?
virtual void EndSourceFileAction()
Callback at the end of processing a single input.
bool PrepareToExecute(CompilerInstance &CI)
Prepare the action to execute on the given compiler instance.
virtual std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile)=0
Create the AST consumer object for this action, if supported.
virtual bool shouldEraseOutputFiles()
Callback at the end of processing a single input, to determine if the output files should be erased o...
bool BeginSourceFile(CompilerInstance &CI, const FrontendInputFile &Input)
Prepare the action for processing the input file Input.
ASTUnit & getCurrentASTUnit() const
CompilerInstance & getCompilerInstance() const
virtual bool PrepareToExecuteAction(CompilerInstance &CI)
Prepare to execute the action on the given CompilerInstance.
virtual bool hasASTFileSupport() const
Does this action support use with AST files?
StringRef getCurrentFile() const
std::unique_ptr< ASTUnit > takeCurrentASTUnit()
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.
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...
void setCompilerInstance(CompilerInstance *Value)
virtual TranslationUnitKind getTranslationUnitKind()
For AST-based actions, the kind of translation unit we're handling.
virtual bool hasCodeCompletionSupport() const
Does this action support use with code completion?
StringRef getCurrentFileOrBufferName() const
virtual bool isModelParsingAction() const
Is this action invoked on a model file?
bool isCurrentFileAST() const
virtual bool usesPreprocessorOnly() const =0
Does this action only use the preprocessor?
void setCurrentInput(const FrontendInputFile &CurrentInput, std::unique_ptr< ASTUnit > AST=nullptr)
virtual ~FrontendAction()
virtual bool BeginInvocation(CompilerInstance &CI)
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
virtual bool hasPCHSupport() const
Does this action support use with PCH?
Module * getCurrentModule() const
Describes a module or submodule.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override=0
Create the AST consumer object for this action, if supported.
virtual bool ParseArgs(const CompilerInstance &CI, const std::vector< std::string > &arg)=0
Parse the given plugin command line arguments.
@ AddAfterMainAction
Execute the action after the main action.
@ ReplaceAction
Replace the main action.
@ AddBeforeMainAction
Execute the action before the main action.
@ CmdlineBeforeMainAction
Execute the action before the main action if on the command line.
@ CmdlineAfterMainAction
Execute the action after the main action if on the command line.
virtual ActionType getActionType()
Get the action type for this plugin.
Abstract base class to use for preprocessor-based frontend actions.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Provide a default implementation which returns aborts; this method should never be called by Frontend...
bool usesPreprocessorOnly() const override
Does this action only use the preprocessor?
void SetMacroExpansionOnlyInDirectives()
Disables macro expansion everywhere except for preprocessor directives.
void SetEnableMacroExpansion()
A frontend action which simply wraps some other runtime-specified frontend action.
std::unique_ptr< ASTConsumer > CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override
Create the AST consumer object for this action, if supported.
bool hasPCHSupport() const override
Does this action support use with PCH?
TranslationUnitKind getTranslationUnitKind() override
For AST-based actions, the kind of translation unit we're handling.
void ExecuteAction() override
Callback to run the program action, using the initialized compiler instance.
bool BeginSourceFileAction(CompilerInstance &CI) override
Callback at the start of processing a single input.
bool hasCodeCompletionSupport() const override
Does this action support use with code completion?
bool hasIRSupport() const override
Does this action support use with IR files?
bool BeginInvocation(CompilerInstance &CI) override
Callback before starting processing a single input, giving the opportunity to modify the CompilerInvo...
WrapperFrontendAction(std::unique_ptr< FrontendAction > WrappedAction)
Construct a WrapperFrontendAction from an existing action, taking ownership of it.
bool PrepareToExecuteAction(CompilerInstance &CI) override
Prepare to execute the action on the given CompilerInstance.
void EndSourceFileAction() override
Callback at the end of processing a single input.
bool hasASTFileSupport() const override
Does this action support use with AST files?
std::unique_ptr< FrontendAction > WrappedAction
bool usesPreprocessorOnly() const override
Does this action only use the preprocessor?
bool shouldEraseOutputFiles() override
Callback at the end of processing a single input, to determine if the output files should be erased o...
void EndSourceFile() override
Perform any per-file post processing, deallocate per-file objects, and run statistics and output file...
The JSON file list parser is used to communicate input to InstallAPI.
TranslationUnitKind
Describes the kind of translation unit being processed.
@ TU_Complete
The translation unit is a complete translation unit.