clang  3.7.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 
52 class CompilerInvocationBase : public RefCountedBase<CompilerInvocation> {
53  void operator=(const CompilerInvocationBase &) = delete;
54 
55 public:
56  /// Options controlling the language variant.
57  std::shared_ptr<LangOptions> LangOpts;
58 
59  /// Options controlling the target.
60  std::shared_ptr<TargetOptions> TargetOpts;
61 
62  /// Options controlling the diagnostic engine.
64 
65  /// Options controlling the \#include directive.
67 
68  /// Options controlling the preprocessor (aside from \#include handling).
70 
73 
75 
76  LangOptions *getLangOpts() { return LangOpts.get(); }
77  const LangOptions *getLangOpts() const { return LangOpts.get(); }
78 
79  TargetOptions &getTargetOpts() { return *TargetOpts.get(); }
80  const TargetOptions &getTargetOpts() const {
81  return *TargetOpts.get();
82  }
83 
85 
88  return *HeaderSearchOpts;
89  }
90 
93  return *PreprocessorOpts;
94  }
95 };
96 
97 /// \brief Helper class for holding the data necessary to invoke the compiler.
98 ///
99 /// This class is designed to represent an abstract "invocation" of the
100 /// compiler, including data such as the include paths, the code generation
101 /// options, the warning flags, and so on.
103  /// Options controlling the static analyzer.
104  AnalyzerOptionsRef AnalyzerOpts;
105 
106  MigratorOptions MigratorOpts;
107 
108  /// Options controlling IRgen and the backend.
109  CodeGenOptions CodeGenOpts;
110 
111  /// Options controlling dependency output.
112  DependencyOutputOptions DependencyOutputOpts;
113 
114  /// Options controlling file system operations.
115  FileSystemOptions FileSystemOpts;
116 
117  /// Options controlling the frontend itself.
118  FrontendOptions FrontendOpts;
119 
120  /// Options controlling preprocessed output.
121  PreprocessorOutputOptions PreprocessorOutputOpts;
122 
123 public:
124  CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {}
125 
126  /// @name Utility Methods
127  /// @{
128 
129  /// \brief Create a compiler invocation from a list of input options.
130  /// \returns true on success.
131  ///
132  /// \param [out] Res - The resulting invocation.
133  /// \param ArgBegin - The first element in the argument vector.
134  /// \param ArgEnd - The last element in the argument vector.
135  /// \param Diags - The diagnostic engine to use for errors.
136  static bool CreateFromArgs(CompilerInvocation &Res,
137  const char* const *ArgBegin,
138  const char* const *ArgEnd,
139  DiagnosticsEngine &Diags);
140 
141  /// \brief Get the directory where the compiler headers
142  /// reside, relative to the compiler binary (found by the passed in
143  /// arguments).
144  ///
145  /// \param Argv0 - The program path (from argv[0]), for finding the builtin
146  /// compiler path.
147  /// \param MainAddr - The address of main (or some other function in the main
148  /// executable), for finding the builtin compiler path.
149  static std::string GetResourcesPath(const char *Argv0, void *MainAddr);
150 
151  /// \brief Set language defaults for the given input language and
152  /// language standard in the given LangOptions object.
153  ///
154  /// \param Opts - The LangOptions object to set up.
155  /// \param IK - The input language.
156  /// \param LangStd - The input language standard.
157  static void setLangDefaults(LangOptions &Opts, InputKind IK,
159 
160  /// \brief Retrieve a module hash string that is suitable for uniquely
161  /// identifying the conditions under which the module was built.
162  std::string getModuleHash() const;
163 
164  /// @}
165  /// @name Option Subgroups
166  /// @{
167 
169  return AnalyzerOpts;
170  }
171 
172  MigratorOptions &getMigratorOpts() { return MigratorOpts; }
174  return MigratorOpts;
175  }
176 
177  CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; }
179  return CodeGenOpts;
180  }
181 
183  return DependencyOutputOpts;
184  }
186  return DependencyOutputOpts;
187  }
188 
189  FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }
191  return FileSystemOpts;
192  }
193 
194  FrontendOptions &getFrontendOpts() { return FrontendOpts; }
196  return FrontendOpts;
197  }
198 
200  return PreprocessorOutputOpts;
201  }
203  return PreprocessorOutputOpts;
204  }
205 
206  /// @}
207 };
208 
209 namespace vfs {
210  class FileSystem;
211 }
212 
213 IntrusiveRefCntPtr<vfs::FileSystem>
214 createVFSFromCompilerInvocation(const CompilerInvocation &CI,
215  DiagnosticsEngine &Diags);
216 
217 } // end namespace clang
218 
219 #endif
HeaderSearchOptions & getHeaderSearchOpts()
DependencyOutputOptions & getDependencyOutputOpts()
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.
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:24
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()
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)
bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args, DiagnosticsEngine *Diags=nullptr)
Fill out Opts based on the options given in Args.
Options for controlling the compiler diagnostics engine.
AnalyzerOptionsRef getAnalyzerOpts() const
Defines the clang::TargetOptions class.
std::shared_ptr< TargetOptions > TargetOpts
Options controlling the target.
static void setLangDefaults(LangOptions &Opts, InputKind IK, LangStandard::Kind LangStd=LangStandard::lang_unspecified)
Set language defaults for the given input language and language standard in the given LangOptions obj...
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
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
Definition: SemaDecl.cpp:11429
FileSystemOptions & getFileSystemOpts()
const HeaderSearchOptions & getHeaderSearchOpts() const