FrontendAction.h (208954) | FrontendAction.h (210299) |
---|---|
1//===-- FrontendAction.h - Generic Frontend Action Interface ----*- 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_FRONTENDACTION_H 11#define LLVM_CLANG_FRONTEND_FRONTENDACTION_H 12 13#include "llvm/ADT/StringRef.h" 14#include "llvm/ADT/OwningPtr.h" 15#include <string> | 1//===-- FrontendAction.h - Generic Frontend Action Interface ----*- 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_FRONTENDACTION_H 11#define LLVM_CLANG_FRONTEND_FRONTENDACTION_H 12 13#include "llvm/ADT/StringRef.h" 14#include "llvm/ADT/OwningPtr.h" 15#include <string> |
16#include <vector> |
|
16 | 17 |
18namespace llvm { 19 class raw_ostream; 20} 21 |
|
17namespace clang { | 22namespace clang { |
18class ASTUnit; | |
19class ASTConsumer; | 23class ASTConsumer; |
20class CompilerInstance; | |
21class ASTMergeAction; | 24class ASTMergeAction; |
25class ASTUnit; 26class CompilerInstance; |
|
22 | 27 |
28enum InputKind { 29 IK_None, 30 IK_Asm, 31 IK_C, 32 IK_CXX, 33 IK_ObjC, 34 IK_ObjCXX, 35 IK_PreprocessedC, 36 IK_PreprocessedCXX, 37 IK_PreprocessedObjC, 38 IK_PreprocessedObjCXX, 39 IK_OpenCL, 40 IK_AST, 41 IK_LLVM_IR 42}; 43 44 |
|
23/// FrontendAction - Abstract base class for actions which can be performed by 24/// the frontend. 25class FrontendAction { 26 std::string CurrentFile; | 45/// FrontendAction - Abstract base class for actions which can be performed by 46/// the frontend. 47class FrontendAction { 48 std::string CurrentFile; |
49 InputKind CurrentFileKind; |
|
27 llvm::OwningPtr<ASTUnit> CurrentASTUnit; 28 CompilerInstance *Instance; 29 friend class ASTMergeAction; 30 31protected: 32 /// @name Implementation Action Interface 33 /// @{ 34 --- 61 unchanged lines hidden (view full) --- 96 return CurrentASTUnit != 0; 97 } 98 99 const std::string &getCurrentFile() const { 100 assert(!CurrentFile.empty() && "No current file!"); 101 return CurrentFile; 102 } 103 | 50 llvm::OwningPtr<ASTUnit> CurrentASTUnit; 51 CompilerInstance *Instance; 52 friend class ASTMergeAction; 53 54protected: 55 /// @name Implementation Action Interface 56 /// @{ 57 --- 61 unchanged lines hidden (view full) --- 119 return CurrentASTUnit != 0; 120 } 121 122 const std::string &getCurrentFile() const { 123 assert(!CurrentFile.empty() && "No current file!"); 124 return CurrentFile; 125 } 126 |
127 InputKind getCurrentFileKind() const { 128 assert(!CurrentFile.empty() && "No current file!"); 129 return CurrentFileKind; 130 } 131 |
|
104 ASTUnit &getCurrentASTUnit() const { 105 assert(!CurrentASTUnit && "No current AST unit!"); 106 return *CurrentASTUnit; 107 } 108 109 ASTUnit *takeCurrentASTUnit() { 110 return CurrentASTUnit.take(); 111 } 112 | 132 ASTUnit &getCurrentASTUnit() const { 133 assert(!CurrentASTUnit && "No current AST unit!"); 134 return *CurrentASTUnit; 135 } 136 137 ASTUnit *takeCurrentASTUnit() { 138 return CurrentASTUnit.take(); 139 } 140 |
113 void setCurrentFile(llvm::StringRef Value, ASTUnit *AST = 0); | 141 void setCurrentFile(llvm::StringRef Value, InputKind Kind, ASTUnit *AST = 0); |
114 115 /// @} 116 /// @name Supported Modes 117 /// @{ 118 119 /// usesPreprocessorOnly - Does this action only use the preprocessor? If so 120 /// no AST context will be created and this action will be invalid with PCH 121 /// inputs. 122 virtual bool usesPreprocessorOnly() const = 0; 123 124 /// usesCompleteTranslationUnit - For AST based actions, should the 125 /// translation unit be completed? 126 virtual bool usesCompleteTranslationUnit() { return true; } 127 128 /// hasPCHSupport - Does this action support use with PCH? 129 virtual bool hasPCHSupport() const { return !usesPreprocessorOnly(); } 130 | 142 143 /// @} 144 /// @name Supported Modes 145 /// @{ 146 147 /// usesPreprocessorOnly - Does this action only use the preprocessor? If so 148 /// no AST context will be created and this action will be invalid with PCH 149 /// inputs. 150 virtual bool usesPreprocessorOnly() const = 0; 151 152 /// usesCompleteTranslationUnit - For AST based actions, should the 153 /// translation unit be completed? 154 virtual bool usesCompleteTranslationUnit() { return true; } 155 156 /// hasPCHSupport - Does this action support use with PCH? 157 virtual bool hasPCHSupport() const { return !usesPreprocessorOnly(); } 158 |
131 /// hasASTSupport - Does this action support use with AST files? 132 virtual bool hasASTSupport() const { return !usesPreprocessorOnly(); } | 159 /// hasASTFileSupport - Does this action support use with AST files? 160 virtual bool hasASTFileSupport() const { return !usesPreprocessorOnly(); } |
133 | 161 |
162 /// hasIRSupport - Does this action support use with IR files? 163 virtual bool hasIRSupport() const { return false; } 164 |
|
134 /// hasCodeCompletionSupport - Does this action support use with code 135 /// completion? 136 virtual bool hasCodeCompletionSupport() const { return false; } 137 138 /// @} 139 /// @name Public Action Interface 140 /// @{ 141 142 /// BeginSourceFile - Prepare the action for processing the input file \arg 143 /// Filename; this is run after the options and frontend have been 144 /// initialized, but prior to executing any per-file processing. 145 /// 146 /// \param CI - The compiler instance this action is being run from. The 147 /// action may store and use this object up until the matching EndSourceFile 148 /// action. 149 /// 150 /// \param Filename - The input filename, which will be made available to 151 /// clients via \see getCurrentFile(). 152 /// | 165 /// hasCodeCompletionSupport - Does this action support use with code 166 /// completion? 167 virtual bool hasCodeCompletionSupport() const { return false; } 168 169 /// @} 170 /// @name Public Action Interface 171 /// @{ 172 173 /// BeginSourceFile - Prepare the action for processing the input file \arg 174 /// Filename; this is run after the options and frontend have been 175 /// initialized, but prior to executing any per-file processing. 176 /// 177 /// \param CI - The compiler instance this action is being run from. The 178 /// action may store and use this object up until the matching EndSourceFile 179 /// action. 180 /// 181 /// \param Filename - The input filename, which will be made available to 182 /// clients via \see getCurrentFile(). 183 /// |
153 /// \param IsAST - Indicates whether this is an AST input. AST inputs require 154 /// special handling, since the AST file itself contains several objects which 155 /// would normally be owned by the CompilerInstance. When processing AST input 156 /// files, these objects should generally not be initialized in the 157 /// CompilerInstance -- they will automatically be shared with the AST file in 158 /// between \see BeginSourceFile() and \see EndSourceFile(). | 184 /// \param InputKind - The type of input. Some input kinds are handled 185 /// specially, for example AST inputs, since the AST file itself contains 186 /// several objects which would normally be owned by the 187 /// CompilerInstance. When processing AST input files, these objects should 188 /// generally not be initialized in the CompilerInstance -- they will 189 /// automatically be shared with the AST file in between \see 190 /// BeginSourceFile() and \see EndSourceFile(). |
159 /// 160 /// \return True on success; the compilation of this file should be aborted 161 /// and neither Execute nor EndSourceFile should be called. 162 bool BeginSourceFile(CompilerInstance &CI, llvm::StringRef Filename, | 191 /// 192 /// \return True on success; the compilation of this file should be aborted 193 /// and neither Execute nor EndSourceFile should be called. 194 bool BeginSourceFile(CompilerInstance &CI, llvm::StringRef Filename, |
163 bool IsAST = false); | 195 InputKind Kind); |
164 165 /// Execute - Set the source managers main input file, and run the action. 166 void Execute(); 167 168 /// EndSourceFile - Perform any per-file post processing, deallocate per-file 169 /// objects, and run statistics and output file cleanup code. 170 void EndSourceFile(); 171 172 /// @} 173}; 174 175/// ASTFrontendAction - Abstract base class to use for AST consumer based 176/// frontend actions. 177class ASTFrontendAction : public FrontendAction { | 196 197 /// Execute - Set the source managers main input file, and run the action. 198 void Execute(); 199 200 /// EndSourceFile - Perform any per-file post processing, deallocate per-file 201 /// objects, and run statistics and output file cleanup code. 202 void EndSourceFile(); 203 204 /// @} 205}; 206 207/// ASTFrontendAction - Abstract base class to use for AST consumer based 208/// frontend actions. 209class ASTFrontendAction : public FrontendAction { |
210protected: |
|
178 /// ExecuteAction - Implement the ExecuteAction interface by running Sema on 179 /// the already initialized AST consumer. 180 /// 181 /// This will also take care of instantiating a code completion consumer if 182 /// the user requested it and the action supports it. 183 virtual void ExecuteAction(); 184 185public: 186 virtual bool usesPreprocessorOnly() const { return false; } 187}; 188 | 211 /// ExecuteAction - Implement the ExecuteAction interface by running Sema on 212 /// the already initialized AST consumer. 213 /// 214 /// This will also take care of instantiating a code completion consumer if 215 /// the user requested it and the action supports it. 216 virtual void ExecuteAction(); 217 218public: 219 virtual bool usesPreprocessorOnly() const { return false; } 220}; 221 |
222class PluginASTAction : public ASTFrontendAction { 223protected: 224 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, 225 llvm::StringRef InFile) = 0; 226 227public: 228 virtual bool ParseArgs(const std::vector<std::string>& arg) = 0; 229 virtual void PrintHelp(llvm::raw_ostream&) = 0; 230}; 231 |
|
189/// PreprocessorFrontendAction - Abstract base class to use for preprocessor 190/// based frontend actions. 191class PreprocessorFrontendAction : public FrontendAction { 192protected: 193 /// CreateASTConsumer - Provide a default implementation which returns aborts, 194 /// this method should never be called by FrontendAction clients. 195 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, 196 llvm::StringRef InFile); 197 198public: 199 virtual bool usesPreprocessorOnly() const { return true; } 200}; 201 202} // end namespace clang 203 204#endif | 232/// PreprocessorFrontendAction - Abstract base class to use for preprocessor 233/// based frontend actions. 234class PreprocessorFrontendAction : public FrontendAction { 235protected: 236 /// CreateASTConsumer - Provide a default implementation which returns aborts, 237 /// this method should never be called by FrontendAction clients. 238 virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI, 239 llvm::StringRef InFile); 240 241public: 242 virtual bool usesPreprocessorOnly() const { return true; } 243}; 244 245} // end namespace clang 246 247#endif |