FrontendActions.h revision 263508
11590Srgrimes//===-- FrontendActions.h - Useful Frontend Actions -------------*- C++ -*-===//
21590Srgrimes//
31590Srgrimes//                     The LLVM Compiler Infrastructure
41590Srgrimes//
51590Srgrimes// This file is distributed under the University of Illinois Open Source
61590Srgrimes// License. See LICENSE.TXT for details.
71590Srgrimes//
81590Srgrimes//===----------------------------------------------------------------------===//
91590Srgrimes
101590Srgrimes#ifndef LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H
111590Srgrimes#define LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H
121590Srgrimes
131590Srgrimes#include "clang/Frontend/FrontendAction.h"
141590Srgrimes#include <string>
151590Srgrimes#include <vector>
161590Srgrimes
171590Srgrimesnamespace clang {
181590Srgrimes
191590Srgrimesclass Module;
201590Srgrimes
211590Srgrimes//===----------------------------------------------------------------------===//
221590Srgrimes// Custom Consumer Actions
231590Srgrimes//===----------------------------------------------------------------------===//
241590Srgrimes
251590Srgrimesclass InitOnlyAction : public FrontendAction {
261590Srgrimes  virtual void ExecuteAction();
271590Srgrimes
281590Srgrimes  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
291590Srgrimes                                         StringRef InFile);
301590Srgrimes
3178859Sddpublic:
321590Srgrimes  // Don't claim to only use the preprocessor, we want to follow the AST path,
331590Srgrimes  // but do nothing.
341590Srgrimes  virtual bool usesPreprocessorOnly() const { return false; }
351590Srgrimes};
361590Srgrimes
3727571Scharnier//===----------------------------------------------------------------------===//
381590Srgrimes// AST Consumer Actions
3927571Scharnier//===----------------------------------------------------------------------===//
401590Srgrimes
4199112Sobrienclass ASTPrintAction : public ASTFrontendAction {
4299112Sobrienprotected:
431590Srgrimes  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
441590Srgrimes                                         StringRef InFile);
451590Srgrimes};
461590Srgrimes
471590Srgrimesclass ASTDumpAction : public ASTFrontendAction {
481590Srgrimesprotected:
491590Srgrimes  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
50200462Sdelphij                                         StringRef InFile);
5190878Simp};
521590Srgrimes
531590Srgrimesclass ASTDeclListAction : public ASTFrontendAction {
541590Srgrimesprotected:
55235541Skib  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
561590Srgrimes                                         StringRef InFile);
571590Srgrimes};
581590Srgrimes
59109943Sfennerclass ASTViewAction : public ASTFrontendAction {
60109943Sfennerprotected:
6192920Simp  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
6292920Simp                                         StringRef InFile);
6392920Simp};
64169857Sdds
65169857Sddsclass DeclContextPrintAction : public ASTFrontendAction {
66169857Sddsprotected:
6792920Simp  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
681590Srgrimes                                         StringRef InFile);
6916849Swosch};
7016849Swosch
7116849Swoschclass GeneratePCHAction : public ASTFrontendAction {
7216849Swoschprotected:
7316849Swosch  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
7416849Swosch                                         StringRef InFile);
7516849Swosch
7616849Swosch  virtual TranslationUnitKind getTranslationUnitKind() {
771590Srgrimes    return TU_Prefix;
78102944Sdwmalone  }
791590Srgrimes
80169857Sdds  virtual bool hasASTFileSupport() const { return false; }
8178859Sdd
821590Srgrimespublic:
83169857Sdds  /// \brief Compute the AST consumer arguments that will be used to
841590Srgrimes  /// create the PCHGenerator instance returned by CreateASTConsumer.
85169857Sdds  ///
86235541Skib  /// \returns true if an error occurred, false otherwise.
87235541Skib  static bool ComputeASTConsumerArguments(CompilerInstance &CI,
8878859Sdd                                          StringRef InFile,
891590Srgrimes                                          std::string &Sysroot,
901590Srgrimes                                          std::string &OutputFile,
91235541Skib                                          raw_ostream *&OS);
92169549Sdds};
931590Srgrimes
941590Srgrimesclass GenerateModuleAction : public ASTFrontendAction {
951590Srgrimes  clang::Module *Module;
961590Srgrimes  bool IsSystem;
97169549Sdds
9816849Swoschprotected:
9978859Sdd  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
10016849Swosch                                         StringRef InFile);
10116849Swosch
10278859Sdd  virtual TranslationUnitKind getTranslationUnitKind() {
10316849Swosch    return TU_Module;
10416849Swosch  }
10578859Sdd
10616849Swosch  virtual bool hasASTFileSupport() const { return false; }
10716849Swosch
10878859Sddpublic:
10916849Swosch  explicit GenerateModuleAction(bool IsSystem = false)
11016849Swosch    : ASTFrontendAction(), IsSystem(IsSystem) { }
11116849Swosch
11278859Sdd  virtual bool BeginSourceFileAction(CompilerInstance &CI, StringRef Filename);
11316849Swosch
11416849Swosch  /// \brief Compute the AST consumer arguments that will be used to
11516849Swosch  /// create the PCHGenerator instance returned by CreateASTConsumer.
11678859Sdd  ///
11716849Swosch  /// \returns true if an error occurred, false otherwise.
11816849Swosch  static bool ComputeASTConsumerArguments(CompilerInstance &CI,
1191590Srgrimes                                          StringRef InFile,
1201590Srgrimes                                          std::string &Sysroot,
1211590Srgrimes                                          std::string &OutputFile,
1221590Srgrimes                                          raw_ostream *&OS);
12316849Swosch};
12416849Swosch
125169549Sddsclass SyntaxOnlyAction : public ASTFrontendAction {
12678859Sddprotected:
127169549Sdds  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
12816849Swosch                                         StringRef InFile);
1291590Srgrimes
1301590Srgrimespublic:
1311590Srgrimes  virtual bool hasCodeCompletionSupport() const { return true; }
132235541Skib};
133235541Skib
134235541Skib/// \brief Dump information about the given module file, to be used for
135235541Skib/// basic debugging and discovery.
136235541Skibclass DumpModuleInfoAction : public ASTFrontendAction {
137235541Skibprotected:
138169235Sdwmalone  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
139168367Sdds                                         StringRef InFile);
140169857Sdds  virtual void ExecuteAction();
141169235Sdwmalone
142168367Sddspublic:
143169857Sdds  virtual bool hasPCHSupport() const { return false; }
144168367Sdds  virtual bool hasASTFileSupport() const { return true; }
145169857Sdds  virtual bool hasIRSupport() const { return false; }
146169857Sdds  virtual bool hasCodeCompletionSupport() const { return false; }
147169857Sdds};
148168367Sdds
1491590Srgrimes/**
150169857Sdds * \brief Frontend action adaptor that merges ASTs together.
151169857Sdds *
152169857Sdds * This action takes an existing AST file and "merges" it into the AST
153169857Sdds * context, producing a merged context. This action is an action
154169857Sdds * adaptor, which forwards most of its calls to another action that
1551590Srgrimes * will consume the merged context.
1561590Srgrimes */
1571590Srgrimesclass ASTMergeAction : public FrontendAction {
1581590Srgrimes  /// \brief The action that the merge action adapts.
159202049Sed  FrontendAction *AdaptedAction;
16067443Sphk
161169857Sdds  /// \brief The set of AST files to merge.
162202049Sed  std::vector<std::string> ASTFiles;
163202049Sed
16416849Swoschprotected:
16516849Swosch  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
16616849Swosch                                         StringRef InFile);
16778859Sdd
168169857Sdds  virtual bool BeginSourceFileAction(CompilerInstance &CI,
169169857Sdds                                     StringRef Filename);
17016849Swosch
17116849Swosch  virtual void ExecuteAction();
17216849Swosch  virtual void EndSourceFileAction();
17378859Sdd
174169857Sddspublic:
17516849Swosch  ASTMergeAction(FrontendAction *AdaptedAction, ArrayRef<std::string> ASTFiles);
17616849Swosch  virtual ~ASTMergeAction();
17716849Swosch
17878859Sdd  virtual bool usesPreprocessorOnly() const;
179169857Sdds  virtual TranslationUnitKind getTranslationUnitKind();
18016849Swosch  virtual bool hasPCHSupport() const;
18116849Swosch  virtual bool hasASTFileSupport() const;
18216849Swosch  virtual bool hasCodeCompletionSupport() const;
18378859Sdd};
184169857Sdds
18516849Swoschclass PrintPreambleAction : public FrontendAction {
18616849Swoschprotected:
18716849Swosch  void ExecuteAction();
18878859Sdd  virtual ASTConsumer *CreateASTConsumer(CompilerInstance &, StringRef) {
189235541Skib    return 0;
190235541Skib  }
191235541Skib
192235541Skib  virtual bool usesPreprocessorOnly() const { return true; }
193235541Skib};
194235541Skib
19516849Swosch//===----------------------------------------------------------------------===//
19616849Swosch// Preprocessor Actions
19716849Swosch//===----------------------------------------------------------------------===//
19878859Sdd
19916849Swoschclass DumpRawTokensAction : public PreprocessorFrontendAction {
200169857Sddsprotected:
201235541Skib  void ExecuteAction();
202235541Skib};
203235541Skib
204235541Skibclass DumpTokensAction : public PreprocessorFrontendAction {
205235541Skibprotected:
206235541Skib  void ExecuteAction();
20716849Swosch};
20816849Swosch
209169857Sddsclass GeneratePTHAction : public PreprocessorFrontendAction {
210169857Sddsprotected:
211169857Sdds  void ExecuteAction();
212109943Sfenner};
213168836Sdds
214168836Sddsclass PreprocessOnlyAction : public PreprocessorFrontendAction {
21516849Swoschprotected:
2161590Srgrimes  void ExecuteAction();
2171590Srgrimes};
2181590Srgrimes
219102944Sdwmaloneclass PrintPreprocessedAction : public PreprocessorFrontendAction {
2201590Srgrimesprotected:
2211590Srgrimes  void ExecuteAction();
2221590Srgrimes
2231590Srgrimes  virtual bool hasPCHSupport() const { return true; }
2241590Srgrimes};
2251590Srgrimes
2261590Srgrimes}  // end namespace clang
2271590Srgrimes
2281590Srgrimes#endif
2291590Srgrimes