Home | History | Annotate | Download | only in Frontend
      1 //===-- FrontendActions.h - Useful Frontend Actions -------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #ifndef LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H
     11 #define LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H
     12 
     13 #include "clang/Frontend/FrontendAction.h"
     14 #include <string>
     15 #include <vector>
     16 
     17 namespace clang {
     18 
     19 //===----------------------------------------------------------------------===//
     20 // Custom Consumer Actions
     21 //===----------------------------------------------------------------------===//
     22 
     23 class InitOnlyAction : public FrontendAction {
     24   virtual void ExecuteAction();
     25 
     26   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
     27                                          StringRef InFile);
     28 
     29 public:
     30   // Don't claim to only use the preprocessor, we want to follow the AST path,
     31   // but do nothing.
     32   virtual bool usesPreprocessorOnly() const { return false; }
     33 };
     34 
     35 //===----------------------------------------------------------------------===//
     36 // AST Consumer Actions
     37 //===----------------------------------------------------------------------===//
     38 
     39 class ASTPrintAction : public ASTFrontendAction {
     40 protected:
     41   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
     42                                          StringRef InFile);
     43 };
     44 
     45 class ASTDumpAction : public ASTFrontendAction {
     46 protected:
     47   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
     48                                          StringRef InFile);
     49 };
     50 
     51 class ASTDumpXMLAction : public ASTFrontendAction {
     52 protected:
     53   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
     54                                          StringRef InFile);
     55 };
     56 
     57 class ASTViewAction : public ASTFrontendAction {
     58 protected:
     59   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
     60                                          StringRef InFile);
     61 };
     62 
     63 class DeclContextPrintAction : public ASTFrontendAction {
     64 protected:
     65   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
     66                                          StringRef InFile);
     67 };
     68 
     69 class GeneratePCHAction : public ASTFrontendAction {
     70   bool MakeModule;
     71 
     72 protected:
     73   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
     74                                          StringRef InFile);
     75 
     76   virtual TranslationUnitKind getTranslationUnitKind() {
     77     return MakeModule? TU_Module : TU_Prefix;
     78   }
     79 
     80   virtual bool hasASTFileSupport() const { return false; }
     81 
     82 public:
     83   /// \brief Create a new action
     84   explicit GeneratePCHAction(bool MakeModule) : MakeModule(MakeModule) { }
     85 
     86   /// \brief Compute the AST consumer arguments that will be used to
     87   /// create the PCHGenerator instance returned by CreateASTConsumer.
     88   ///
     89   /// \returns true if an error occurred, false otherwise.
     90   static bool ComputeASTConsumerArguments(CompilerInstance &CI,
     91                                           StringRef InFile,
     92                                           std::string &Sysroot,
     93                                           std::string &OutputFile,
     94                                           raw_ostream *&OS);
     95 };
     96 
     97 class SyntaxOnlyAction : public ASTFrontendAction {
     98 protected:
     99   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
    100                                          StringRef InFile);
    101 
    102 public:
    103   virtual bool hasCodeCompletionSupport() const { return true; }
    104 };
    105 
    106 /**
    107  * \brief Frontend action adaptor that merges ASTs together.
    108  *
    109  * This action takes an existing AST file and "merges" it into the AST
    110  * context, producing a merged context. This action is an action
    111  * adaptor, which forwards most of its calls to another action that
    112  * will consume the merged context.
    113  */
    114 class ASTMergeAction : public FrontendAction {
    115   /// \brief The action that the merge action adapts.
    116   FrontendAction *AdaptedAction;
    117 
    118   /// \brief The set of AST files to merge.
    119   std::vector<std::string> ASTFiles;
    120 
    121 protected:
    122   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
    123                                          StringRef InFile);
    124 
    125   virtual bool BeginSourceFileAction(CompilerInstance &CI,
    126                                      StringRef Filename);
    127 
    128   virtual void ExecuteAction();
    129   virtual void EndSourceFileAction();
    130 
    131 public:
    132   ASTMergeAction(FrontendAction *AdaptedAction,
    133                  std::string *ASTFiles, unsigned NumASTFiles);
    134   virtual ~ASTMergeAction();
    135 
    136   virtual bool usesPreprocessorOnly() const;
    137   virtual TranslationUnitKind getTranslationUnitKind();
    138   virtual bool hasPCHSupport() const;
    139   virtual bool hasASTFileSupport() const;
    140   virtual bool hasCodeCompletionSupport() const;
    141 };
    142 
    143 class PrintPreambleAction : public FrontendAction {
    144 protected:
    145   void ExecuteAction();
    146   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &, StringRef) {
    147     return 0;
    148   }
    149 
    150   virtual bool usesPreprocessorOnly() const { return true; }
    151 };
    152 
    153 //===----------------------------------------------------------------------===//
    154 // Preprocessor Actions
    155 //===----------------------------------------------------------------------===//
    156 
    157 class DumpRawTokensAction : public PreprocessorFrontendAction {
    158 protected:
    159   void ExecuteAction();
    160 };
    161 
    162 class DumpTokensAction : public PreprocessorFrontendAction {
    163 protected:
    164   void ExecuteAction();
    165 };
    166 
    167 class GeneratePTHAction : public PreprocessorFrontendAction {
    168 protected:
    169   void ExecuteAction();
    170 };
    171 
    172 class PreprocessOnlyAction : public PreprocessorFrontendAction {
    173 protected:
    174   void ExecuteAction();
    175 };
    176 
    177 class PrintPreprocessedAction : public PreprocessorFrontendAction {
    178 protected:
    179   void ExecuteAction();
    180 
    181   virtual bool hasPCHSupport() const { return true; }
    182 };
    183 
    184 }  // end namespace clang
    185 
    186 #endif
    187