]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Frontend/CompilerInvocation.h
Update clang to trunk r290819 and resolve conflicts.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Frontend / CompilerInvocation.h
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
13 #include "clang/Basic/DiagnosticOptions.h"
14 #include "clang/Basic/FileSystemOptions.h"
15 #include "clang/Basic/LangOptions.h"
16 #include "clang/Frontend/CodeGenOptions.h"
17 #include "clang/Frontend/DependencyOutputOptions.h"
18 #include "clang/Frontend/FrontendOptions.h"
19 #include "clang/Frontend/LangStandard.h"
20 #include "clang/Frontend/MigratorOptions.h"
21 #include "clang/Frontend/PreprocessorOutputOptions.h"
22 #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
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
54 class CompilerInvocationBase : public RefCountedBase<CompilerInvocation> {
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.
65   IntrusiveRefCntPtr<DiagnosticOptions> DiagnosticOpts;
66
67   /// Options controlling the \#include directive.
68   IntrusiveRefCntPtr<HeaderSearchOptions> HeaderSearchOpts;
69
70   /// Options controlling the preprocessor (aside from \#include handling).
71   IntrusiveRefCntPtr<PreprocessorOptions> PreprocessorOpts;
72
73   CompilerInvocationBase();
74   ~CompilerInvocationBase();
75
76   CompilerInvocationBase(const CompilerInvocationBase &X);
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; }
89   const HeaderSearchOptions &getHeaderSearchOpts() const {
90     return *HeaderSearchOpts;
91   }
92
93   PreprocessorOptions &getPreprocessorOpts() { return *PreprocessorOpts; }
94   const PreprocessorOptions &getPreprocessorOpts() const {
95     return *PreprocessorOpts;
96   }
97 };
98   
99 /// \brief Helper class for holding the data necessary to invoke the compiler.
100 ///
101 /// This class is designed to represent an abstract "invocation" of the
102 /// compiler, including data such as the include paths, the code generation
103 /// options, the warning flags, and so on.
104 class CompilerInvocation : public CompilerInvocationBase {
105   /// Options controlling the static analyzer.
106   AnalyzerOptionsRef AnalyzerOpts;
107
108   MigratorOptions MigratorOpts;
109   
110   /// Options controlling IRgen and the backend.
111   CodeGenOptions CodeGenOpts;
112
113   /// Options controlling dependency output.
114   DependencyOutputOptions DependencyOutputOpts;
115
116   /// Options controlling file system operations.
117   FileSystemOptions FileSystemOpts;
118
119   /// Options controlling the frontend itself.
120   FrontendOptions FrontendOpts;
121
122   /// Options controlling preprocessed output.
123   PreprocessorOutputOptions PreprocessorOutputOpts;
124
125 public:
126   CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {}
127
128   /// @name Utility Methods
129   /// @{
130
131   /// \brief Create a compiler invocation from a list of input options.
132   /// \returns true on success.
133   ///
134   /// \param [out] Res - The resulting invocation.
135   /// \param ArgBegin - The first element in the argument vector.
136   /// \param ArgEnd - The last element in the argument vector.
137   /// \param Diags - The diagnostic engine to use for errors.
138   static bool CreateFromArgs(CompilerInvocation &Res,
139                              const char* const *ArgBegin,
140                              const char* const *ArgEnd,
141                              DiagnosticsEngine &Diags);
142
143   /// \brief Get the directory where the compiler headers
144   /// reside, relative to the compiler binary (found by the passed in
145   /// arguments).
146   ///
147   /// \param Argv0 - The program path (from argv[0]), for finding the builtin
148   /// compiler path.
149   /// \param MainAddr - The address of main (or some other function in the main
150   /// executable), for finding the builtin compiler path.
151   static std::string GetResourcesPath(const char *Argv0, void *MainAddr);
152
153   /// \brief Set language defaults for the given input language and
154   /// language standard in the given LangOptions object.
155   ///
156   /// \param Opts - The LangOptions object to set up.
157   /// \param IK - The input language.
158   /// \param T - The target triple.
159   /// \param PPOpts - The PreprocessorOptions affected.
160   /// \param LangStd - The input language standard.
161   static void setLangDefaults(LangOptions &Opts, InputKind IK,
162                    const llvm::Triple &T, PreprocessorOptions &PPOpts,
163                    LangStandard::Kind LangStd = LangStandard::lang_unspecified);
164   
165   /// \brief Retrieve a module hash string that is suitable for uniquely 
166   /// identifying the conditions under which the module was built.
167   std::string getModuleHash() const;
168   
169   /// @}
170   /// @name Option Subgroups
171   /// @{
172
173   AnalyzerOptionsRef getAnalyzerOpts() const {
174     return AnalyzerOpts;
175   }
176
177   MigratorOptions &getMigratorOpts() { return MigratorOpts; }
178   const MigratorOptions &getMigratorOpts() const {
179     return MigratorOpts;
180   }
181   
182   CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; }
183   const CodeGenOptions &getCodeGenOpts() const {
184     return CodeGenOpts;
185   }
186
187   DependencyOutputOptions &getDependencyOutputOpts() {
188     return DependencyOutputOpts;
189   }
190   const DependencyOutputOptions &getDependencyOutputOpts() const {
191     return DependencyOutputOpts;
192   }
193
194   FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }
195   const FileSystemOptions &getFileSystemOpts() const {
196     return FileSystemOpts;
197   }
198
199   FrontendOptions &getFrontendOpts() { return FrontendOpts; }
200   const FrontendOptions &getFrontendOpts() const {
201     return FrontendOpts;
202   }
203
204   PreprocessorOutputOptions &getPreprocessorOutputOpts() {
205     return PreprocessorOutputOpts;
206   }
207   const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
208     return PreprocessorOutputOpts;
209   }
210
211   /// @}
212 };
213
214 namespace vfs {
215   class FileSystem;
216 }
217
218 IntrusiveRefCntPtr<vfs::FileSystem>
219 createVFSFromCompilerInvocation(const CompilerInvocation &CI,
220                                 DiagnosticsEngine &Diags);
221
222 } // end namespace clang
223
224 #endif