1 //===-- FrontendActions.h - Useful Frontend Actions -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H
11 #define LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H
13 #include "clang/Frontend/FrontendAction.h"
19 //===----------------------------------------------------------------------===//
20 // Custom Consumer Actions
21 //===----------------------------------------------------------------------===//
23 class InitOnlyAction : public FrontendAction {
24 virtual void ExecuteAction();
26 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
27 llvm::StringRef InFile);
30 // Don't claim to only use the preprocessor, we want to follow the AST path,
32 virtual bool usesPreprocessorOnly() const { return false; }
35 //===----------------------------------------------------------------------===//
36 // AST Consumer Actions
37 //===----------------------------------------------------------------------===//
39 class ASTPrintAction : public ASTFrontendAction {
41 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
42 llvm::StringRef InFile);
45 class ASTDumpAction : public ASTFrontendAction {
47 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
48 llvm::StringRef InFile);
51 class ASTDumpXMLAction : public ASTFrontendAction {
53 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
54 llvm::StringRef InFile);
57 class ASTViewAction : public ASTFrontendAction {
59 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
60 llvm::StringRef InFile);
63 class DeclContextPrintAction : public ASTFrontendAction {
65 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
66 llvm::StringRef InFile);
69 class GeneratePCHAction : public ASTFrontendAction {
71 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
72 llvm::StringRef InFile);
74 virtual bool usesCompleteTranslationUnit() { return false; }
76 virtual bool hasASTFileSupport() const { return false; }
79 /// \brief Compute the AST consumer arguments that will be used to
80 /// create the PCHGenerator instance returned by CreateASTConsumer.
82 /// \returns true if an error occurred, false otherwise.
83 static bool ComputeASTConsumerArguments(CompilerInstance &CI,
84 llvm::StringRef InFile,
86 std::string &OutputFile,
87 llvm::raw_ostream *&OS,
91 class SyntaxOnlyAction : public ASTFrontendAction {
93 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
94 llvm::StringRef InFile);
97 virtual bool hasCodeCompletionSupport() const { return true; }
101 * \brief Frontend action adaptor that merges ASTs together.
103 * This action takes an existing AST file and "merges" it into the AST
104 * context, producing a merged context. This action is an action
105 * adaptor, which forwards most of its calls to another action that
106 * will consume the merged context.
108 class ASTMergeAction : public FrontendAction {
109 /// \brief The action that the merge action adapts.
110 FrontendAction *AdaptedAction;
112 /// \brief The set of AST files to merge.
113 std::vector<std::string> ASTFiles;
116 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
117 llvm::StringRef InFile);
119 virtual bool BeginSourceFileAction(CompilerInstance &CI,
120 llvm::StringRef Filename);
122 virtual void ExecuteAction();
123 virtual void EndSourceFileAction();
126 ASTMergeAction(FrontendAction *AdaptedAction,
127 std::string *ASTFiles, unsigned NumASTFiles);
128 virtual ~ASTMergeAction();
130 virtual bool usesPreprocessorOnly() const;
131 virtual bool usesCompleteTranslationUnit();
132 virtual bool hasPCHSupport() const;
133 virtual bool hasASTFileSupport() const;
134 virtual bool hasCodeCompletionSupport() const;
137 class PrintPreambleAction : public FrontendAction {
139 void ExecuteAction();
140 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &, llvm::StringRef) {
144 virtual bool usesPreprocessorOnly() const { return true; }
147 //===----------------------------------------------------------------------===//
148 // Preprocessor Actions
149 //===----------------------------------------------------------------------===//
151 class DumpRawTokensAction : public PreprocessorFrontendAction {
153 void ExecuteAction();
156 class DumpTokensAction : public PreprocessorFrontendAction {
158 void ExecuteAction();
161 class GeneratePTHAction : public PreprocessorFrontendAction {
163 void ExecuteAction();
166 class PreprocessOnlyAction : public PreprocessorFrontendAction {
168 void ExecuteAction();
171 class PrintPreprocessedAction : public PreprocessorFrontendAction {
173 void ExecuteAction();
175 virtual bool hasPCHSupport() const { return true; }
178 } // end namespace clang