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