FrontendOptions.h revision 69325d5b7cfecf1b3128745efc33612aedf1b8b4
1//===--- FrontendOptions.h --------------------------------------*- 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_FRONTENDOPTIONS_H
11#define LLVM_CLANG_FRONTEND_FRONTENDOPTIONS_H
12
13#include "clang/Frontend/CommandLineSourceLoc.h"
14#include "clang/Frontend/FrontendAction.h"
15#include "llvm/ADT/StringRef.h"
16#include <string>
17#include <vector>
18
19namespace clang {
20
21namespace frontend {
22  enum ActionKind {
23    ASTDump,                ///< Parse ASTs and dump them.
24    ASTDumpXML,             ///< Parse ASTs and dump them in XML.
25    ASTPrint,               ///< Parse ASTs and print them.
26    ASTView,                ///< Parse ASTs and view them in Graphviz.
27    CreateModule,           ///< Create module definition
28    DumpRawTokens,          ///< Dump out raw tokens.
29    DumpTokens,             ///< Dump out preprocessed tokens.
30    EmitAssembly,           ///< Emit a .s file.
31    EmitBC,                 ///< Emit a .bc file.
32    EmitHTML,               ///< Translate input source into HTML.
33    EmitLLVM,               ///< Emit a .ll file.
34    EmitLLVMOnly,           ///< Generate LLVM IR, but do not emit anything.
35    EmitCodeGenOnly,        ///< Generate machine code, but don't emit anything.
36    EmitObj,                ///< Emit a .o file.
37    FixIt,                  ///< Parse and apply any fixits to the source.
38    GeneratePCH,            ///< Generate pre-compiled header.
39    GeneratePTH,            ///< Generate pre-tokenized header.
40    InitOnly,               ///< Only execute frontend initialization.
41    ParseSyntaxOnly,        ///< Parse and perform semantic analysis.
42    PluginAction,           ///< Run a plugin action, \see ActionName.
43    PrintDeclContext,       ///< Print DeclContext and their Decls.
44    PrintPreamble,          ///< Print the "preamble" of the input file
45    PrintPreprocessedInput, ///< -E mode.
46    RewriteMacros,          ///< Expand macros but not #includes.
47    RewriteObjC,            ///< ObjC->C Rewriter.
48    RewriteTest,            ///< Rewriter playground
49    RunAnalysis,            ///< Run one or more source code analyses.
50    RunPreprocessorOnly     ///< Just lex, no output.
51  };
52}
53
54/// FrontendOptions - Options for controlling the behavior of the frontend.
55class FrontendOptions {
56public:
57  unsigned DisableFree : 1;                ///< Disable memory freeing on exit.
58  unsigned RelocatablePCH : 1;             ///< When generating PCH files,
59                                           /// instruct the AST writer to create
60                                           /// relocatable PCH files.
61  unsigned ChainedPCH : 1;                 ///< When generating PCH files,
62                                           /// instruct the AST writer to create
63                                           /// chained PCH files.
64  unsigned ShowHelp : 1;                   ///< Show the -help text.
65  unsigned ShowMacrosInCodeCompletion : 1; ///< Show macros in code completion
66                                           /// results.
67  unsigned ShowCodePatternsInCodeCompletion : 1; ///< Show code patterns in code
68                                                 /// completion results.
69  unsigned ShowGlobalSymbolsInCodeCompletion : 1; ///< Show top-level decls in
70                                                  /// code completion results.
71  unsigned ShowStats : 1;                  ///< Show frontend performance
72                                           /// metrics and statistics.
73  unsigned ShowTimers : 1;                 ///< Show timers for individual
74                                           /// actions.
75  unsigned ShowVersion : 1;                ///< Show the -version text.
76  unsigned FixWhatYouCan : 1;              ///< Apply fixes even if there are
77                                           /// unfixable errors.
78
79  enum {
80    ARCMT_None,
81    ARCMT_Check,
82    ARCMT_Modify,
83    ARCMT_Migrate
84  } ARCMTAction;
85
86  std::string ARCMTMigrateDir;
87
88  /// The input files and their types.
89  std::vector<std::pair<InputKind, std::string> > Inputs;
90
91  /// The output file, if any.
92  std::string OutputFile;
93
94  /// If given, the new suffix for fix-it rewritten files.
95  std::string FixItSuffix;
96
97  /// If given, enable code completion at the provided location.
98  ParsedSourceLocation CodeCompletionAt;
99
100  /// The frontend action to perform.
101  frontend::ActionKind ProgramAction;
102
103  /// The name of the action to run when using a plugin action.
104  std::string ActionName;
105
106  /// Args to pass to the plugin
107  std::vector<std::string> PluginArgs;
108
109  /// The list of plugin actions to run in addition to the normal action.
110  std::vector<std::string> AddPluginActions;
111
112  /// Args to pass to the additional plugins
113  std::vector<std::vector<std::string> > AddPluginArgs;
114
115  /// The list of plugins to load.
116  std::vector<std::string> Plugins;
117
118  /// \brief The list of AST files to merge.
119  std::vector<std::string> ASTMergeFiles;
120
121  /// \brief The list of modules to import.
122  std::vector<std::string> Modules;
123
124  /// \brief A list of arguments to forward to LLVM's option processing; this
125  /// should only be used for debugging and experimental features.
126  std::vector<std::string> LLVMArgs;
127
128public:
129  FrontendOptions() {
130    DisableFree = 0;
131    ProgramAction = frontend::ParseSyntaxOnly;
132    ActionName = "";
133    RelocatablePCH = 0;
134    ChainedPCH = 0;
135    ShowHelp = 0;
136    ShowMacrosInCodeCompletion = 0;
137    ShowCodePatternsInCodeCompletion = 0;
138    ShowGlobalSymbolsInCodeCompletion = 1;
139    ShowStats = 0;
140    ShowTimers = 0;
141    ShowVersion = 0;
142    ARCMTAction = ARCMT_None;
143  }
144
145  /// getInputKindForExtension - Return the appropriate input kind for a file
146  /// extension. For example, "c" would return IK_C.
147  ///
148  /// \return The input kind for the extension, or IK_None if the extension is
149  /// not recognized.
150  static InputKind getInputKindForExtension(llvm::StringRef Extension);
151};
152
153}  // end namespace clang
154
155#endif
156