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> |
17 |
18namespace llvm { 19 class raw_ostream; 20} 21 |
22namespace clang { |
23class ASTConsumer; |
24class ASTMergeAction; |
25class ASTUnit; 26class CompilerInstance; |
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 |
45/// FrontendAction - Abstract base class for actions which can be performed by 46/// the frontend. 47class FrontendAction { 48 std::string CurrentFile; |
49 InputKind CurrentFileKind; |
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 |
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 |
141 void setCurrentFile(llvm::StringRef Value, InputKind Kind, ASTUnit *AST = 0); |
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 |
159 /// hasASTFileSupport - Does this action support use with AST files? 160 virtual bool hasASTFileSupport() const { return !usesPreprocessorOnly(); } |
161 |
162 /// hasIRSupport - Does this action support use with IR files? 163 virtual bool hasIRSupport() const { return false; } 164 |
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 /// |
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(). |
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, |
195 InputKind Kind); |
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: |
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 |
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 |