clang API Documentation

Frontend/FrontendActions.h
Go to the documentation of this file.
00001 //===-- FrontendActions.h - Useful Frontend Actions -------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #ifndef LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H
00011 #define LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H
00012 
00013 #include "clang/Frontend/FrontendAction.h"
00014 #include <string>
00015 #include <vector>
00016 
00017 namespace clang {
00018 
00019 class Module;
00020   
00021 //===----------------------------------------------------------------------===//
00022 // Custom Consumer Actions
00023 //===----------------------------------------------------------------------===//
00024 
00025 class InitOnlyAction : public FrontendAction {
00026   virtual void ExecuteAction();
00027 
00028   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
00029                                          StringRef InFile);
00030 
00031 public:
00032   // Don't claim to only use the preprocessor, we want to follow the AST path,
00033   // but do nothing.
00034   virtual bool usesPreprocessorOnly() const { return false; }
00035 };
00036 
00037 //===----------------------------------------------------------------------===//
00038 // AST Consumer Actions
00039 //===----------------------------------------------------------------------===//
00040 
00041 class ASTPrintAction : public ASTFrontendAction {
00042 protected:
00043   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
00044                                          StringRef InFile);
00045 };
00046 
00047 class ASTDumpAction : public ASTFrontendAction {
00048 protected:
00049   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
00050                                          StringRef InFile);
00051 };
00052 
00053 class ASTDumpXMLAction : public ASTFrontendAction {
00054 protected:
00055   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
00056                                          StringRef InFile);
00057 };
00058 
00059 class ASTViewAction : public ASTFrontendAction {
00060 protected:
00061   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
00062                                          StringRef InFile);
00063 };
00064 
00065 class DeclContextPrintAction : public ASTFrontendAction {
00066 protected:
00067   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
00068                                          StringRef InFile);
00069 };
00070 
00071 class GeneratePCHAction : public ASTFrontendAction {
00072 protected:
00073   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
00074                                          StringRef InFile);
00075 
00076   virtual TranslationUnitKind getTranslationUnitKind() {
00077     return TU_Prefix;
00078   }
00079 
00080   virtual bool hasASTFileSupport() const { return false; }
00081 
00082 public:
00083   /// \brief Compute the AST consumer arguments that will be used to
00084   /// create the PCHGenerator instance returned by CreateASTConsumer.
00085   ///
00086   /// \returns true if an error occurred, false otherwise.
00087   static bool ComputeASTConsumerArguments(CompilerInstance &CI,
00088                                           StringRef InFile,
00089                                           std::string &Sysroot,
00090                                           std::string &OutputFile,
00091                                           raw_ostream *&OS);
00092 };
00093 
00094 class GenerateModuleAction : public ASTFrontendAction {
00095   clang::Module *Module;
00096   
00097 protected:
00098   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
00099                                          StringRef InFile);
00100   
00101   virtual TranslationUnitKind getTranslationUnitKind() { 
00102     return TU_Module;
00103   }
00104   
00105   virtual bool hasASTFileSupport() const { return false; }
00106   
00107 public:
00108   virtual bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename);
00109   
00110   /// \brief Compute the AST consumer arguments that will be used to
00111   /// create the PCHGenerator instance returned by CreateASTConsumer.
00112   ///
00113   /// \returns true if an error occurred, false otherwise.
00114   static bool ComputeASTConsumerArguments(CompilerInstance &CI,
00115                                           StringRef InFile,
00116                                           std::string &Sysroot,
00117                                           std::string &OutputFile,
00118                                           raw_ostream *&OS);
00119 };
00120   
00121 class SyntaxOnlyAction : public ASTFrontendAction {
00122 protected:
00123   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
00124                                          StringRef InFile);
00125 
00126 public:
00127   virtual bool hasCodeCompletionSupport() const { return true; }
00128 };
00129 
00130 /**
00131  * \brief Frontend action adaptor that merges ASTs together.
00132  *
00133  * This action takes an existing AST file and "merges" it into the AST
00134  * context, producing a merged context. This action is an action
00135  * adaptor, which forwards most of its calls to another action that
00136  * will consume the merged context.
00137  */
00138 class ASTMergeAction : public FrontendAction {
00139   /// \brief The action that the merge action adapts.
00140   FrontendAction *AdaptedAction;
00141   
00142   /// \brief The set of AST files to merge.
00143   std::vector<std::string> ASTFiles;
00144 
00145 protected:
00146   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
00147                                          StringRef InFile);
00148 
00149   virtual bool BeginSourceFileAction(CompilerInstance &CI,
00150                                      StringRef Filename);
00151 
00152   virtual void ExecuteAction();
00153   virtual void EndSourceFileAction();
00154 
00155 public:
00156   ASTMergeAction(FrontendAction *AdaptedAction, ArrayRef<std::string> ASTFiles);
00157   virtual ~ASTMergeAction();
00158 
00159   virtual bool usesPreprocessorOnly() const;
00160   virtual TranslationUnitKind getTranslationUnitKind();
00161   virtual bool hasPCHSupport() const;
00162   virtual bool hasASTFileSupport() const;
00163   virtual bool hasCodeCompletionSupport() const;
00164 };
00165 
00166 class PrintPreambleAction : public FrontendAction {
00167 protected:
00168   void ExecuteAction();
00169   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &, StringRef) { 
00170     return 0; 
00171   }
00172   
00173   virtual bool usesPreprocessorOnly() const { return true; }
00174 };
00175   
00176 //===----------------------------------------------------------------------===//
00177 // Preprocessor Actions
00178 //===----------------------------------------------------------------------===//
00179 
00180 class DumpRawTokensAction : public PreprocessorFrontendAction {
00181 protected:
00182   void ExecuteAction();
00183 };
00184 
00185 class DumpTokensAction : public PreprocessorFrontendAction {
00186 protected:
00187   void ExecuteAction();
00188 };
00189 
00190 class GeneratePTHAction : public PreprocessorFrontendAction {
00191 protected:
00192   void ExecuteAction();
00193 };
00194 
00195 class PreprocessOnlyAction : public PreprocessorFrontendAction {
00196 protected:
00197   void ExecuteAction();
00198 };
00199 
00200 class PrintPreprocessedAction : public PreprocessorFrontendAction {
00201 protected:
00202   void ExecuteAction();
00203 
00204   virtual bool hasPCHSupport() const { return true; }
00205 };
00206   
00207 }  // end namespace clang
00208 
00209 #endif