| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | #ifndef LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H |
| 10 | #define LLVM_CLANG_FRONTEND_FRONTENDACTIONS_H |
| 11 | |
| 12 | #include "clang/Frontend/FrontendAction.h" |
| 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
| 16 | namespace clang { |
| 17 | |
| 18 | class Module; |
| 19 | class FileEntry; |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | class InitOnlyAction : public FrontendAction { |
| 26 | void ExecuteAction() override; |
| 27 | |
| 28 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 29 | StringRef InFile) override; |
| 30 | |
| 31 | public: |
| 32 | |
| 33 | |
| 34 | bool usesPreprocessorOnly() const override { return false; } |
| 35 | }; |
| 36 | |
| 37 | class DumpCompilerOptionsAction : public FrontendAction { |
| 38 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 39 | StringRef InFile) override { |
| 40 | return nullptr; |
| 41 | } |
| 42 | |
| 43 | void ExecuteAction() override; |
| 44 | |
| 45 | public: |
| 46 | bool usesPreprocessorOnly() const override { return true; } |
| 47 | }; |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | class ASTPrintAction : public ASTFrontendAction { |
| 54 | protected: |
| 55 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 56 | StringRef InFile) override; |
| 57 | }; |
| 58 | |
| 59 | class ASTDumpAction : public ASTFrontendAction { |
| 60 | protected: |
| 61 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 62 | StringRef InFile) override; |
| 63 | }; |
| 64 | |
| 65 | class ASTDeclListAction : public ASTFrontendAction { |
| 66 | protected: |
| 67 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 68 | StringRef InFile) override; |
| 69 | }; |
| 70 | |
| 71 | class ASTViewAction : public ASTFrontendAction { |
| 72 | protected: |
| 73 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 74 | StringRef InFile) override; |
| 75 | }; |
| 76 | |
| 77 | class GeneratePCHAction : public ASTFrontendAction { |
| 78 | protected: |
| 79 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 80 | StringRef InFile) override; |
| 81 | |
| 82 | TranslationUnitKind getTranslationUnitKind() override { |
| 83 | return TU_Prefix; |
| 84 | } |
| 85 | |
| 86 | bool hasASTFileSupport() const override { return false; } |
| 87 | |
| 88 | bool shouldEraseOutputFiles() override; |
| 89 | |
| 90 | public: |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | static bool ComputeASTConsumerArguments(CompilerInstance &CI, |
| 96 | std::string &Sysroot); |
| 97 | |
| 98 | |
| 99 | |
| 100 | static std::unique_ptr<llvm::raw_pwrite_stream> |
| 101 | CreateOutputFile(CompilerInstance &CI, StringRef InFile, |
| 102 | std::string &OutputFile); |
| 103 | |
| 104 | bool BeginSourceFileAction(CompilerInstance &CI) override; |
| 105 | }; |
| 106 | |
| 107 | class GenerateModuleAction : public ASTFrontendAction { |
| 108 | virtual std::unique_ptr<raw_pwrite_stream> |
| 109 | CreateOutputFile(CompilerInstance &CI, StringRef InFile) = 0; |
| 110 | |
| 111 | protected: |
| 112 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 113 | StringRef InFile) override; |
| 114 | |
| 115 | TranslationUnitKind getTranslationUnitKind() override { |
| 116 | return TU_Module; |
| 117 | } |
| 118 | |
| 119 | bool hasASTFileSupport() const override { return false; } |
| 120 | }; |
| 121 | |
| 122 | class GenerateModuleFromModuleMapAction : public GenerateModuleAction { |
| 123 | private: |
| 124 | bool BeginSourceFileAction(CompilerInstance &CI) override; |
| 125 | |
| 126 | std::unique_ptr<raw_pwrite_stream> |
| 127 | CreateOutputFile(CompilerInstance &CI, StringRef InFile) override; |
| 128 | }; |
| 129 | |
| 130 | class GenerateModuleInterfaceAction : public GenerateModuleAction { |
| 131 | private: |
| 132 | bool BeginSourceFileAction(CompilerInstance &CI) override; |
| 133 | |
| 134 | std::unique_ptr<raw_pwrite_stream> |
| 135 | CreateOutputFile(CompilerInstance &CI, StringRef InFile) override; |
| 136 | }; |
| 137 | |
| 138 | class : public GenerateModuleAction { |
| 139 | |
| 140 | std::unique_ptr<llvm::MemoryBuffer> ; |
| 141 | std::vector<std::string> ; |
| 142 | |
| 143 | private: |
| 144 | bool (CompilerInstance &CI) override; |
| 145 | bool (CompilerInstance &CI) override; |
| 146 | |
| 147 | std::unique_ptr<raw_pwrite_stream> |
| 148 | (CompilerInstance &CI, StringRef InFile) override; |
| 149 | }; |
| 150 | |
| 151 | class SyntaxOnlyAction : public ASTFrontendAction { |
| 152 | protected: |
| 153 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 154 | StringRef InFile) override; |
| 155 | |
| 156 | public: |
| 157 | ~SyntaxOnlyAction() override; |
| 158 | bool hasCodeCompletionSupport() const override { return true; } |
| 159 | }; |
| 160 | |
| 161 | |
| 162 | |
| 163 | class DumpModuleInfoAction : public ASTFrontendAction { |
| 164 | protected: |
| 165 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 166 | StringRef InFile) override; |
| 167 | bool BeginInvocation(CompilerInstance &CI) override; |
| 168 | void ExecuteAction() override; |
| 169 | |
| 170 | public: |
| 171 | bool hasPCHSupport() const override { return false; } |
| 172 | bool hasASTFileSupport() const override { return true; } |
| 173 | bool hasIRSupport() const override { return false; } |
| 174 | bool hasCodeCompletionSupport() const override { return false; } |
| 175 | }; |
| 176 | |
| 177 | class VerifyPCHAction : public ASTFrontendAction { |
| 178 | protected: |
| 179 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 180 | StringRef InFile) override; |
| 181 | |
| 182 | void ExecuteAction() override; |
| 183 | |
| 184 | public: |
| 185 | bool hasCodeCompletionSupport() const override { return false; } |
| 186 | }; |
| 187 | |
| 188 | class TemplightDumpAction : public ASTFrontendAction { |
| 189 | protected: |
| 190 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 191 | StringRef InFile) override; |
| 192 | |
| 193 | void ExecuteAction() override; |
| 194 | }; |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | class ASTMergeAction : public FrontendAction { |
| 205 | |
| 206 | std::unique_ptr<FrontendAction> AdaptedAction; |
| 207 | |
| 208 | |
| 209 | std::vector<std::string> ASTFiles; |
| 210 | |
| 211 | protected: |
| 212 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, |
| 213 | StringRef InFile) override; |
| 214 | |
| 215 | bool BeginSourceFileAction(CompilerInstance &CI) override; |
| 216 | |
| 217 | void ExecuteAction() override; |
| 218 | void EndSourceFileAction() override; |
| 219 | |
| 220 | public: |
| 221 | ASTMergeAction(std::unique_ptr<FrontendAction> AdaptedAction, |
| 222 | ArrayRef<std::string> ASTFiles); |
| 223 | ~ASTMergeAction() override; |
| 224 | |
| 225 | bool usesPreprocessorOnly() const override; |
| 226 | TranslationUnitKind getTranslationUnitKind() override; |
| 227 | bool hasPCHSupport() const override; |
| 228 | bool hasASTFileSupport() const override; |
| 229 | bool hasCodeCompletionSupport() const override; |
| 230 | }; |
| 231 | |
| 232 | class PrintPreambleAction : public FrontendAction { |
| 233 | protected: |
| 234 | void ExecuteAction() override; |
| 235 | std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &, |
| 236 | StringRef) override { |
| 237 | return nullptr; |
| 238 | } |
| 239 | |
| 240 | bool usesPreprocessorOnly() const override { return true; } |
| 241 | }; |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | class DumpRawTokensAction : public PreprocessorFrontendAction { |
| 248 | protected: |
| 249 | void ExecuteAction() override; |
| 250 | }; |
| 251 | |
| 252 | class DumpTokensAction : public PreprocessorFrontendAction { |
| 253 | protected: |
| 254 | void ExecuteAction() override; |
| 255 | }; |
| 256 | |
| 257 | class PreprocessOnlyAction : public PreprocessorFrontendAction { |
| 258 | protected: |
| 259 | void ExecuteAction() override; |
| 260 | }; |
| 261 | |
| 262 | class PrintPreprocessedAction : public PreprocessorFrontendAction { |
| 263 | protected: |
| 264 | void ExecuteAction() override; |
| 265 | |
| 266 | bool hasPCHSupport() const override { return true; } |
| 267 | }; |
| 268 | |
| 269 | } |
| 270 | |
| 271 | #endif |
| 272 | |