clang  6.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 
23 #include "llvm/ADT/IntrusiveRefCntPtr.h"
24 #include <string>
25 
26 namespace llvm {
27 class Triple;
28 
29 namespace opt {
30 class ArgList;
31 }
32 }
33 
34 namespace clang {
35 class PreprocessorOptions;
36 class HeaderSearchOptions;
37 class TargetOptions;
38 class LangOptions;
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  bool DefaultShowOpt = true);
53 
55  void operator=(const CompilerInvocationBase &) = delete;
56 
57 public:
58  /// Options controlling the language variant.
59  std::shared_ptr<LangOptions> LangOpts;
60 
61  /// Options controlling the target.
62  std::shared_ptr<TargetOptions> TargetOpts;
63 
64  /// Options controlling the diagnostic engine.
66 
67  /// Options controlling the \#include directive.
68  std::shared_ptr<HeaderSearchOptions> HeaderSearchOpts;
69 
70  /// Options controlling the preprocessor (aside from \#include handling).
71  std::shared_ptr<PreprocessorOptions> PreprocessorOpts;
72 
75 
77 
78  LangOptions *getLangOpts() { return LangOpts.get(); }
79  const LangOptions *getLangOpts() const { return LangOpts.get(); }
80 
81  TargetOptions &getTargetOpts() { return *TargetOpts.get(); }
82  const TargetOptions &getTargetOpts() const {
83  return *TargetOpts.get();
84  }
85 
86  DiagnosticOptions &getDiagnosticOpts() const { return *DiagnosticOpts; }
87 
88  HeaderSearchOptions &getHeaderSearchOpts() { return *HeaderSearchOpts; }
90  return *HeaderSearchOpts;
91  }
92  std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const {
93  return HeaderSearchOpts;
94  }
95 
96  std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() {
97  return PreprocessorOpts;
98  }
99  PreprocessorOptions &getPreprocessorOpts() { return *PreprocessorOpts; }
101  return *PreprocessorOpts;
102  }
103 };
104 
105 /// \brief Helper class for holding the data necessary to invoke the compiler.
106 ///
107 /// This class is designed to represent an abstract "invocation" of the
108 /// compiler, including data such as the include paths, the code generation
109 /// options, the warning flags, and so on.
111  /// Options controlling the static analyzer.
112  AnalyzerOptionsRef AnalyzerOpts;
113 
114  MigratorOptions MigratorOpts;
115 
116  /// Options controlling IRgen and the backend.
117  CodeGenOptions CodeGenOpts;
118 
119  /// Options controlling dependency output.
120  DependencyOutputOptions DependencyOutputOpts;
121 
122  /// Options controlling file system operations.
123  FileSystemOptions FileSystemOpts;
124 
125  /// Options controlling the frontend itself.
126  FrontendOptions FrontendOpts;
127 
128  /// Options controlling preprocessed output.
129  PreprocessorOutputOptions PreprocessorOutputOpts;
130 
131 public:
132  CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {}
133 
134  /// @name Utility Methods
135  /// @{
136 
137  /// \brief Create a compiler invocation from a list of input options.
138  /// \returns true on success.
139  ///
140  /// \param [out] Res - The resulting invocation.
141  /// \param ArgBegin - The first element in the argument vector.
142  /// \param ArgEnd - The last element in the argument vector.
143  /// \param Diags - The diagnostic engine to use for errors.
144  static bool CreateFromArgs(CompilerInvocation &Res,
145  const char* const *ArgBegin,
146  const char* const *ArgEnd,
147  DiagnosticsEngine &Diags);
148 
149  /// \brief Get the directory where the compiler headers
150  /// reside, relative to the compiler binary (found by the passed in
151  /// arguments).
152  ///
153  /// \param Argv0 - The program path (from argv[0]), for finding the builtin
154  /// compiler path.
155  /// \param MainAddr - The address of main (or some other function in the main
156  /// executable), for finding the builtin compiler path.
157  static std::string GetResourcesPath(const char *Argv0, void *MainAddr);
158 
159  /// \brief Set language defaults for the given input language and
160  /// language standard in the given LangOptions object.
161  ///
162  /// \param Opts - The LangOptions object to set up.
163  /// \param IK - The input language.
164  /// \param T - The target triple.
165  /// \param PPOpts - The PreprocessorOptions affected.
166  /// \param LangStd - The input language standard.
167  static void setLangDefaults(LangOptions &Opts, InputKind IK,
168  const llvm::Triple &T, PreprocessorOptions &PPOpts,
169  LangStandard::Kind LangStd = LangStandard::lang_unspecified);
170 
171  /// \brief Retrieve a module hash string that is suitable for uniquely
172  /// identifying the conditions under which the module was built.
173  std::string getModuleHash() const;
174 
175  /// @}
176  /// @name Option Subgroups
177  /// @{
178 
180  return AnalyzerOpts;
181  }
182 
183  MigratorOptions &getMigratorOpts() { return MigratorOpts; }
185  return MigratorOpts;
186  }
187 
188  CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; }
190  return CodeGenOpts;
191  }
192 
194  return DependencyOutputOpts;
195  }
197  return DependencyOutputOpts;
198  }
199 
200  FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }
202  return FileSystemOpts;
203  }
204 
205  FrontendOptions &getFrontendOpts() { return FrontendOpts; }
207  return FrontendOpts;
208  }
209 
211  return PreprocessorOutputOpts;
212  }
214  return PreprocessorOutputOpts;
215  }
216 
217  /// @}
218 };
219 
220 namespace vfs {
221  class FileSystem;
222 }
223 
226  DiagnosticsEngine &Diags);
227 
230  DiagnosticsEngine &Diags,
232 
233 } // end namespace clang
234 
235 #endif
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:26
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:48
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)
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
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:13010
FileSystemOptions & getFileSystemOpts()
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
const TargetOptions & getTargetOpts() const
const DependencyOutputOptions & getDependencyOutputOpts() const