clang  3.9.0
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 
26 #include "llvm/ADT/IntrusiveRefCntPtr.h"
27 #include "llvm/ADT/StringMap.h"
28 #include "llvm/ADT/StringRef.h"
29 #include <string>
30 #include <vector>
31 
32 namespace llvm {
33 namespace opt {
34 class ArgList;
35 }
36 }
37 
38 namespace clang {
39 class CompilerInvocation;
40 class DiagnosticsEngine;
41 
42 /// \brief Fill out Opts based on the options given in Args.
43 ///
44 /// Args must have been created from the OptTable returned by
45 /// createCC1OptTable().
46 ///
47 /// When errors are encountered, return false and, if Diags is non-null,
48 /// report the error(s).
49 bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args,
50  DiagnosticsEngine *Diags = nullptr,
51  bool DefaultDiagColor = true);
52 
53 class CompilerInvocationBase : public RefCountedBase<CompilerInvocation> {
54  void operator=(const CompilerInvocationBase &) = delete;
55 
56 public:
57  /// Options controlling the language variant.
58  std::shared_ptr<LangOptions> LangOpts;
59 
60  /// Options controlling the target.
61  std::shared_ptr<TargetOptions> TargetOpts;
62 
63  /// Options controlling the diagnostic engine.
65 
66  /// Options controlling the \#include directive.
68 
69  /// Options controlling the preprocessor (aside from \#include handling).
71 
74 
76 
77  LangOptions *getLangOpts() { return LangOpts.get(); }
78  const LangOptions *getLangOpts() const { return LangOpts.get(); }
79 
80  TargetOptions &getTargetOpts() { return *TargetOpts.get(); }
81  const TargetOptions &getTargetOpts() const {
82  return *TargetOpts.get();
83  }
84 
86 
89  return *HeaderSearchOpts;
90  }
91 
94  return *PreprocessorOpts;
95  }
96 };
97 
98 /// \brief Helper class for holding the data necessary to invoke the compiler.
99 ///
100 /// This class is designed to represent an abstract "invocation" of the
101 /// compiler, including data such as the include paths, the code generation
102 /// options, the warning flags, and so on.
104  /// Options controlling the static analyzer.
105  AnalyzerOptionsRef AnalyzerOpts;
106 
107  MigratorOptions MigratorOpts;
108 
109  /// Options controlling IRgen and the backend.
110  CodeGenOptions CodeGenOpts;
111 
112  /// Options controlling dependency output.
113  DependencyOutputOptions DependencyOutputOpts;
114 
115  /// Options controlling file system operations.
116  FileSystemOptions FileSystemOpts;
117 
118  /// Options controlling the frontend itself.
119  FrontendOptions FrontendOpts;
120 
121  /// Options controlling preprocessed output.
122  PreprocessorOutputOptions PreprocessorOutputOpts;
123 
124 public:
125  CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {}
126 
127  /// @name Utility Methods
128  /// @{
129 
130  /// \brief Create a compiler invocation from a list of input options.
131  /// \returns true on success.
132  ///
133  /// \param [out] Res - The resulting invocation.
134  /// \param ArgBegin - The first element in the argument vector.
135  /// \param ArgEnd - The last element in the argument vector.
136  /// \param Diags - The diagnostic engine to use for errors.
137  static bool CreateFromArgs(CompilerInvocation &Res,
138  const char* const *ArgBegin,
139  const char* const *ArgEnd,
140  DiagnosticsEngine &Diags);
141 
142  /// \brief Get the directory where the compiler headers
143  /// reside, relative to the compiler binary (found by the passed in
144  /// arguments).
145  ///
146  /// \param Argv0 - The program path (from argv[0]), for finding the builtin
147  /// compiler path.
148  /// \param MainAddr - The address of main (or some other function in the main
149  /// executable), for finding the builtin compiler path.
150  static std::string GetResourcesPath(const char *Argv0, void *MainAddr);
151 
152  /// \brief Set language defaults for the given input language and
153  /// language standard in the given LangOptions object.
154  ///
155  /// \param Opts - The LangOptions object to set up.
156  /// \param IK - The input language.
157  /// \param T - The target triple.
158  /// \param PPOpts - The PreprocessorOptions affected.
159  /// \param LangStd - The input language standard.
160  static void setLangDefaults(LangOptions &Opts, InputKind IK,
161  const llvm::Triple &T, PreprocessorOptions &PPOpts,
163 
164  /// \brief Retrieve a module hash string that is suitable for uniquely
165  /// identifying the conditions under which the module was built.
166  std::string getModuleHash() const;
167 
168  /// @}
169  /// @name Option Subgroups
170  /// @{
171 
173  return AnalyzerOpts;
174  }
175 
176  MigratorOptions &getMigratorOpts() { return MigratorOpts; }
178  return MigratorOpts;
179  }
180 
181  CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; }
183  return CodeGenOpts;
184  }
185 
187  return DependencyOutputOpts;
188  }
190  return DependencyOutputOpts;
191  }
192 
193  FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }
195  return FileSystemOpts;
196  }
197 
198  FrontendOptions &getFrontendOpts() { return FrontendOpts; }
200  return FrontendOpts;
201  }
202 
204  return PreprocessorOutputOpts;
205  }
207  return PreprocessorOutputOpts;
208  }
209 
210  /// @}
211 };
212 
213 namespace vfs {
214  class FileSystem;
215 }
216 
217 IntrusiveRefCntPtr<vfs::FileSystem>
218 createVFSFromCompilerInvocation(const CompilerInvocation &CI,
219  DiagnosticsEngine &Diags);
220 
221 } // end namespace clang
222 
223 #endif
HeaderSearchOptions & getHeaderSearchOpts()
DependencyOutputOptions & getDependencyOutputOpts()
bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args, DiagnosticsEngine *Diags=nullptr, bool DefaultDiagColor=true)
Fill out Opts based on the options given in Args.
static bool CreateFromArgs(CompilerInvocation &Res, const char *const *ArgBegin, const char *const *ArgEnd, DiagnosticsEngine &Diags)
Create a compiler invocation from a list of input options.
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 PreprocessorOptions & getPreprocessorOpts() const
std::string getModuleHash() const
Retrieve a module hash string that is suitable for uniquely identifying the conditions under which th...
Options for controlling the target.
Definition: TargetOptions.h:25
IntrusiveRefCntPtr< PreprocessorOptions > PreprocessorOpts
Options controlling the preprocessor (aside from #include handling).
const PreprocessorOutputOptions & getPreprocessorOutputOpts() const
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:48
CodeGenOptions & getCodeGenOpts()
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:135
const FrontendOptions & getFrontendOpts() const
PreprocessorOutputOptions & getPreprocessorOutputOpts()
FrontendOptions & getFrontendOpts()
MigratorOptions & getMigratorOpts()
PreprocessorOutputOptions - Options for controlling the C preprocessor output (e.g., -E).
static void setLangDefaults(LangOptions &Opts, InputKind IK, const llvm::Triple &T, PreprocessorOptions &PPOpts, LangStandard::Kind LangStd=LangStandard::lang_unspecified)
Set language defaults for the given input language and language standard in the given LangOptions obj...
static std::string GetResourcesPath(const char *Argv0, void *MainAddr)
Get the directory where the compiler headers reside, relative to the compiler binary (found by the pa...
Defines the clang::LangOptions interface.
const LangOptions * getLangOpts() const
IntrusiveRefCntPtr< vfs::FileSystem > createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags)
Options for controlling the compiler diagnostics engine.
AnalyzerOptionsRef getAnalyzerOpts() const
Defines the clang::TargetOptions class.
DependencyOutputOptions - Options for controlling the compiler dependency file generation.
std::shared_ptr< TargetOptions > TargetOpts
Options controlling the target.
const TargetOptions & getTargetOpts() const
const FileSystemOptions & getFileSystemOpts() const
const MigratorOptions & getMigratorOpts() const
PreprocessorOptions & getPreprocessorOpts()
Helper class for holding the data necessary to invoke the compiler.
DiagnosticOptions & getDiagnosticOpts() const
const CodeGenOptions & getCodeGenOpts() const
FrontendOptions - Options for controlling the behavior of the frontend.
Defines the clang::FileSystemOptions interface.
const DependencyOutputOptions & getDependencyOutputOpts() const
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
IntrusiveRefCntPtr< DiagnosticOptions > DiagnosticOpts
Options controlling the diagnostic engine.
IntrusiveRefCntPtr< HeaderSearchOptions > HeaderSearchOpts
Options controlling the #include directive.
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:12171
FileSystemOptions & getFileSystemOpts()
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
const HeaderSearchOptions & getHeaderSearchOpts() const