clang  7.0.0svn
CompilerInvocation.h
Go to the documentation of this file.
1 //===- CompilerInvocation.h - Compiler Invocation Helper Data ---*- 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_COMPILERINVOCATION_H
11 #define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
12 
15 #include "clang/Basic/LLVM.h"
24 #include "llvm/ADT/IntrusiveRefCntPtr.h"
25 #include <memory>
26 #include <string>
27 
28 namespace llvm {
29 
30 class Triple;
31 
32 namespace opt {
33 
34 class ArgList;
35 
36 } // namespace opt
37 
38 } // namespace llvm
39 
40 namespace clang {
41 
42 class DiagnosticsEngine;
43 class HeaderSearchOptions;
44 class PreprocessorOptions;
45 class TargetOptions;
46 
47 /// Fill out Opts based on the options given in Args.
48 ///
49 /// Args must have been created from the OptTable returned by
50 /// createCC1OptTable().
51 ///
52 /// When errors are encountered, return false and, if Diags is non-null,
53 /// report the error(s).
54 bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args,
55  DiagnosticsEngine *Diags = nullptr,
56  bool DefaultDiagColor = true,
57  bool DefaultShowOpt = true);
58 
60 public:
61  /// Options controlling the language variant.
62  std::shared_ptr<LangOptions> LangOpts;
63 
64  /// Options controlling the target.
65  std::shared_ptr<TargetOptions> TargetOpts;
66 
67  /// Options controlling the diagnostic engine.
69 
70  /// Options controlling the \#include directive.
71  std::shared_ptr<HeaderSearchOptions> HeaderSearchOpts;
72 
73  /// Options controlling the preprocessor (aside from \#include handling).
74  std::shared_ptr<PreprocessorOptions> PreprocessorOpts;
75 
78  CompilerInvocationBase &operator=(const CompilerInvocationBase &) = delete;
80 
81  LangOptions *getLangOpts() { return LangOpts.get(); }
82  const LangOptions *getLangOpts() const { return LangOpts.get(); }
83 
84  TargetOptions &getTargetOpts() { return *TargetOpts.get(); }
85  const TargetOptions &getTargetOpts() const { return *TargetOpts.get(); }
86 
87  DiagnosticOptions &getDiagnosticOpts() const { return *DiagnosticOpts; }
88 
89  HeaderSearchOptions &getHeaderSearchOpts() { return *HeaderSearchOpts; }
90 
92  return *HeaderSearchOpts;
93  }
94 
95  std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const {
96  return HeaderSearchOpts;
97  }
98 
99  std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() {
100  return PreprocessorOpts;
101  }
102 
103  PreprocessorOptions &getPreprocessorOpts() { return *PreprocessorOpts; }
104 
106  return *PreprocessorOpts;
107  }
108 };
109 
110 /// Helper class for holding the data necessary to invoke the compiler.
111 ///
112 /// This class is designed to represent an abstract "invocation" of the
113 /// compiler, including data such as the include paths, the code generation
114 /// options, the warning flags, and so on.
116  /// Options controlling the static analyzer.
117  AnalyzerOptionsRef AnalyzerOpts;
118 
119  MigratorOptions MigratorOpts;
120 
121  /// Options controlling IRgen and the backend.
122  CodeGenOptions CodeGenOpts;
123 
124  /// Options controlling dependency output.
125  DependencyOutputOptions DependencyOutputOpts;
126 
127  /// Options controlling file system operations.
128  FileSystemOptions FileSystemOpts;
129 
130  /// Options controlling the frontend itself.
131  FrontendOptions FrontendOpts;
132 
133  /// Options controlling preprocessed output.
134  PreprocessorOutputOptions PreprocessorOutputOpts;
135 
136 public:
137  CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {}
138 
139  /// @name Utility Methods
140  /// @{
141 
142  /// Create a compiler invocation from a list of input options.
143  /// \returns true on success.
144  ///
145  /// \param [out] Res - The resulting invocation.
146  /// \param ArgBegin - The first element in the argument vector.
147  /// \param ArgEnd - The last element in the argument vector.
148  /// \param Diags - The diagnostic engine to use for errors.
149  static bool CreateFromArgs(CompilerInvocation &Res,
150  const char* const *ArgBegin,
151  const char* const *ArgEnd,
152  DiagnosticsEngine &Diags);
153 
154  /// Get the directory where the compiler headers
155  /// reside, relative to the compiler binary (found by the passed in
156  /// arguments).
157  ///
158  /// \param Argv0 - The program path (from argv[0]), for finding the builtin
159  /// compiler path.
160  /// \param MainAddr - The address of main (or some other function in the main
161  /// executable), for finding the builtin compiler path.
162  static std::string GetResourcesPath(const char *Argv0, void *MainAddr);
163 
164  /// Set language defaults for the given input language and
165  /// language standard in the given LangOptions object.
166  ///
167  /// \param Opts - The LangOptions object to set up.
168  /// \param IK - The input language.
169  /// \param T - The target triple.
170  /// \param PPOpts - The PreprocessorOptions affected.
171  /// \param LangStd - The input language standard.
172  static void setLangDefaults(LangOptions &Opts, InputKind IK,
173  const llvm::Triple &T, PreprocessorOptions &PPOpts,
174  LangStandard::Kind LangStd = LangStandard::lang_unspecified);
175 
176  /// Retrieve a module hash string that is suitable for uniquely
177  /// identifying the conditions under which the module was built.
178  std::string getModuleHash() const;
179 
180  /// @}
181  /// @name Option Subgroups
182  /// @{
183 
184  AnalyzerOptionsRef getAnalyzerOpts() const { return AnalyzerOpts; }
185 
186  MigratorOptions &getMigratorOpts() { return MigratorOpts; }
187  const MigratorOptions &getMigratorOpts() const { return MigratorOpts; }
188 
189  CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; }
190  const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
191 
193  return DependencyOutputOpts;
194  }
195 
197  return DependencyOutputOpts;
198  }
199 
200  FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }
201 
203  return FileSystemOpts;
204  }
205 
206  FrontendOptions &getFrontendOpts() { return FrontendOpts; }
207  const FrontendOptions &getFrontendOpts() const { return FrontendOpts; }
208 
210  return PreprocessorOutputOpts;
211  }
212 
214  return PreprocessorOutputOpts;
215  }
216 
217  /// @}
218 };
219 
220 namespace vfs {
221 
222 class FileSystem;
223 
224 } // namespace vfs
225 
228  DiagnosticsEngine &Diags);
229 
232  DiagnosticsEngine &Diags,
234 
235 } // namespace clang
236 
237 #endif // LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
HeaderSearchOptions & getHeaderSearchOpts()
bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args, DiagnosticsEngine *Diags=nullptr, bool DefaultDiagColor=true, bool DefaultShowOpt=true)
Fill out Opts based on the options given in Args.
const HeaderSearchOptions & getHeaderSearchOpts() const
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Definition: Dominators.h:30
DependencyOutputOptions & getDependencyOutputOpts()
std::shared_ptr< HeaderSearchOptions > HeaderSearchOpts
Options controlling the #include directive.
std::shared_ptr< LangOptions > LangOpts
Options controlling the language variant.
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
const MigratorOptions & getMigratorOpts() const
Options for controlling the target.
Definition: TargetOptions.h:26
const PreprocessorOutputOptions & getPreprocessorOutputOpts() const
const LangOptions * getLangOpts() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
const PreprocessorOptions & getPreprocessorOpts() const
std::shared_ptr< PreprocessorOptions > PreprocessorOpts
Options controlling the preprocessor (aside from #include handling).
CodeGenOptions & getCodeGenOpts()
IntrusiveRefCntPtr< vfs::FileSystem > createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags, IntrusiveRefCntPtr< vfs::FileSystem > BaseFS)
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
std::shared_ptr< PreprocessorOptions > getPreprocessorOptsPtr()
PreprocessorOutputOptions & getPreprocessorOutputOpts()
FrontendOptions & getFrontendOpts()
MigratorOptions & getMigratorOpts()
PreprocessorOutputOptions - Options for controlling the C preprocessor output (e.g., -E).
Defines the clang::LangOptions interface.
const FunctionProtoType * T
AnalyzerOptionsRef getAnalyzerOpts() const
Options for controlling the compiler diagnostics engine.
The kind of a file that we&#39;ve been handed as an input.
const FrontendOptions & getFrontendOpts() const
const CodeGenOptions & getCodeGenOpts() const
DiagnosticOptions & getDiagnosticOpts() const
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
std::shared_ptr< TargetOptions > TargetOpts
Options controlling the target.
std::shared_ptr< HeaderSearchOptions > getHeaderSearchOptsPtr() const
const FileSystemOptions & getFileSystemOpts() const
Dataflow Directional Tag Classes.
PreprocessorOptions & getPreprocessorOpts()
Helper class for holding the data necessary to invoke the compiler.
FrontendOptions - Options for controlling the behavior of the frontend.
Defines the clang::FileSystemOptions interface.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
IntrusiveRefCntPtr< DiagnosticOptions > DiagnosticOpts
Options controlling the diagnostic engine.
Keeps track of options that affect how file operations are performed.
X
Add a minimal nested name specifier fixit hint to allow lookup of a tag name from an outer enclosing ...
Definition: SemaDecl.cpp:13462
FileSystemOptions & getFileSystemOpts()
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
const TargetOptions & getTargetOpts() const
const DependencyOutputOptions & getDependencyOutputOpts() const