FrontendOptions.h revision d6ac4524cd441808f152f7e10900a8315ea31c08
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    ASTPrint,               ///< Parse ASTs and print them.
25    ASTPrintXML,            ///< Parse ASTs and print them in XML.
26    ASTView,                ///< Parse ASTs and view them in Graphviz.
27    BoostCon,               ///< BoostCon mode.
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    InheritanceView,        ///< View C++ inheritance for a specified class.
41    InitOnly,               ///< Only execute frontend initialization.
42    ParseNoop,              ///< Parse with noop callbacks.
43    ParsePrintCallbacks,    ///< Parse and print each callback.
44    ParseSyntaxOnly,        ///< Parse and perform semantic analysis.
45    PluginAction,           ///< Run a plugin action, \see ActionName.
46    PrintDeclContext,       ///< Print DeclContext and their Decls.
47    PrintPreprocessedInput, ///< -E mode.
48    RewriteMacros,          ///< Expand macros but not #includes.
49    RewriteObjC,            ///< ObjC->C Rewriter.
50    RewriteTest,            ///< Rewriter playground
51    RunAnalysis,            ///< Run one or more source code analyses.
52    RunPreprocessorOnly     ///< Just lex, no output.
53  };
54}
55
56/// FrontendOptions - Options for controlling the behavior of the frontend.
57class FrontendOptions {
58public:
59  unsigned DebugCodeCompletionPrinter : 1; ///< Use the debug printer for code
60                                           /// completion results.
61  unsigned DisableFree : 1;                ///< Disable memory freeing on exit.
62  unsigned RelocatablePCH : 1;             ///< When generating PCH files,
63                                           /// instruct the PCH writer to create
64                                           /// relocatable PCH files.
65  unsigned ChainedPCH : 1;                 ///< When generating PCH files,
66                                           /// instruct the PCH writer to create
67                                           /// chained PCH files.
68  unsigned ShowHelp : 1;                   ///< Show the -help text.
69  unsigned ShowMacrosInCodeCompletion : 1; ///< Show macros in code completion
70                                           /// results.
71  unsigned ShowCodePatternsInCodeCompletion : 1; ///< Show code patterns in code
72                                                 /// completion results.
73  unsigned ShowStats : 1;                  ///< Show frontend performance
74                                           /// metrics and statistics.
75  unsigned ShowTimers : 1;                 ///< Show timers for individual
76                                           /// actions.
77  unsigned ShowVersion : 1;                ///< Show the -version text.
78
79  /// The input files and their types.
80  std::vector<std::pair<InputKind, std::string> > Inputs;
81
82  /// The output file, if any.
83  std::string OutputFile;
84
85  /// If given, the name for a C++ class to view the inheritance of.
86  std::string ViewClassInheritance;
87
88  /// If given, the new suffix for fix-it rewritten files.
89  std::string FixItSuffix;
90
91  /// If given, enable code completion at the provided location.
92  ParsedSourceLocation CodeCompletionAt;
93
94  /// The frontend action to perform.
95  frontend::ActionKind ProgramAction;
96
97  /// The name of the action to run when using a plugin action.
98  std::string ActionName;
99
100  /// Arg to pass to the plugin
101  std::vector<std::string> PluginArgs;
102
103  /// The list of plugins to load.
104  std::vector<std::string> Plugins;
105
106  /// \brief The list of AST files to merge.
107  std::vector<std::string> ASTMergeFiles;
108
109  /// \brief A list of arguments to forward to LLVM's option processing; this
110  /// should only be used for debugging and experimental features.
111  std::vector<std::string> LLVMArgs;
112
113public:
114  FrontendOptions() {
115    DebugCodeCompletionPrinter = 1;
116    DisableFree = 0;
117    ProgramAction = frontend::ParseSyntaxOnly;
118    ActionName = "";
119    RelocatablePCH = 0;
120    ChainedPCH = 0;
121    ShowHelp = 0;
122    ShowMacrosInCodeCompletion = 0;
123    ShowCodePatternsInCodeCompletion = 0;
124    ShowStats = 0;
125    ShowTimers = 0;
126    ShowVersion = 0;
127  }
128
129  /// getInputKindForExtension - Return the appropriate input kind for a file
130  /// extension. For example, "c" would return IK_C.
131  ///
132  /// \return The input kind for the extension, or IK_None if the extension is
133  /// not recognized.
134  static InputKind getInputKindForExtension(llvm::StringRef Extension);
135};
136
137}  // end namespace clang
138
139#endif
140