clang  10.0.0svn
CompilerInvocation.h
Go to the documentation of this file.
1 //===- CompilerInvocation.h - Compiler Invocation Helper Data ---*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
10 #define LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H
11 
15 #include "clang/Basic/LLVM.h"
23 #include "llvm/ADT/IntrusiveRefCntPtr.h"
24 #include "llvm/ADT/ArrayRef.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 vfs {
39 
40 class FileSystem;
41 
42 } // namespace vfs
43 
44 } // namespace llvm
45 
46 namespace clang {
47 
48 class DiagnosticsEngine;
49 class HeaderSearchOptions;
50 class PreprocessorOptions;
51 class TargetOptions;
52 
53 /// Fill out Opts based on the options given in Args.
54 ///
55 /// Args must have been created from the OptTable returned by
56 /// createCC1OptTable().
57 ///
58 /// When errors are encountered, return false and, if Diags is non-null,
59 /// report the error(s).
60 bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args,
61  DiagnosticsEngine *Diags = nullptr,
62  bool DefaultDiagColor = true,
63  bool DefaultShowOpt = true);
64 
66 public:
67  /// Options controlling the language variant.
68  std::shared_ptr<LangOptions> LangOpts;
69 
70  /// Options controlling the target.
71  std::shared_ptr<TargetOptions> TargetOpts;
72 
73  /// Options controlling the diagnostic engine.
75 
76  /// Options controlling the \#include directive.
77  std::shared_ptr<HeaderSearchOptions> HeaderSearchOpts;
78 
79  /// Options controlling the preprocessor (aside from \#include handling).
80  std::shared_ptr<PreprocessorOptions> PreprocessorOpts;
81 
84  CompilerInvocationBase &operator=(const CompilerInvocationBase &) = delete;
86 
87  LangOptions *getLangOpts() { return LangOpts.get(); }
88  const LangOptions *getLangOpts() const { return LangOpts.get(); }
89 
90  TargetOptions &getTargetOpts() { return *TargetOpts.get(); }
91  const TargetOptions &getTargetOpts() const { return *TargetOpts.get(); }
92 
93  DiagnosticOptions &getDiagnosticOpts() const { return *DiagnosticOpts; }
94 
95  HeaderSearchOptions &getHeaderSearchOpts() { return *HeaderSearchOpts; }
96 
98  return *HeaderSearchOpts;
99  }
100 
101  std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const {
102  return HeaderSearchOpts;
103  }
104 
105  std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() {
106  return PreprocessorOpts;
107  }
108 
109  PreprocessorOptions &getPreprocessorOpts() { return *PreprocessorOpts; }
110 
112  return *PreprocessorOpts;
113  }
114 };
115 
116 /// Helper class for holding the data necessary to invoke the compiler.
117 ///
118 /// This class is designed to represent an abstract "invocation" of the
119 /// compiler, including data such as the include paths, the code generation
120 /// options, the warning flags, and so on.
122  /// Options controlling the static analyzer.
123  AnalyzerOptionsRef AnalyzerOpts;
124 
125  MigratorOptions MigratorOpts;
126 
127  /// Options controlling IRgen and the backend.
128  CodeGenOptions CodeGenOpts;
129 
130  /// Options controlling dependency output.
131  DependencyOutputOptions DependencyOutputOpts;
132 
133  /// Options controlling file system operations.
134  FileSystemOptions FileSystemOpts;
135 
136  /// Options controlling the frontend itself.
137  FrontendOptions FrontendOpts;
138 
139  /// Options controlling preprocessed output.
140  PreprocessorOutputOptions PreprocessorOutputOpts;
141 
142 public:
143  CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {}
144 
145  /// @name Utility Methods
146  /// @{
147 
148  /// Create a compiler invocation from a list of input options.
149  /// \returns true on success.
150  ///
151  /// \returns false if an error was encountered while parsing the arguments
152  /// and attempts to recover and continue parsing the rest of the arguments.
153  /// The recovery is best-effort and only guarantees that \p Res will end up in
154  /// one of the vaild-to-access (albeit arbitrary) states.
155  ///
156  /// \param [out] Res - The resulting invocation.
157  static bool CreateFromArgs(CompilerInvocation &Res,
158  ArrayRef<const char *> CommandLineArgs,
159  DiagnosticsEngine &Diags);
160 
161  /// Get the directory where the compiler headers
162  /// reside, relative to the compiler binary (found by the passed in
163  /// arguments).
164  ///
165  /// \param Argv0 - The program path (from argv[0]), for finding the builtin
166  /// compiler path.
167  /// \param MainAddr - The address of main (or some other function in the main
168  /// executable), for finding the builtin compiler path.
169  static std::string GetResourcesPath(const char *Argv0, void *MainAddr);
170 
171  /// Set language defaults for the given input language and
172  /// language standard in the given LangOptions object.
173  ///
174  /// \param Opts - The LangOptions object to set up.
175  /// \param IK - The input language.
176  /// \param T - The target triple.
177  /// \param PPOpts - The PreprocessorOptions affected.
178  /// \param LangStd - The input language standard.
179  static void setLangDefaults(LangOptions &Opts, InputKind IK,
180  const llvm::Triple &T, PreprocessorOptions &PPOpts,
181  LangStandard::Kind LangStd = LangStandard::lang_unspecified);
182 
183  /// Retrieve a module hash string that is suitable for uniquely
184  /// identifying the conditions under which the module was built.
185  std::string getModuleHash() const;
186 
187  /// @}
188  /// @name Option Subgroups
189  /// @{
190 
191  AnalyzerOptionsRef getAnalyzerOpts() const { return AnalyzerOpts; }
192 
193  MigratorOptions &getMigratorOpts() { return MigratorOpts; }
194  const MigratorOptions &getMigratorOpts() const { return MigratorOpts; }
195 
196  CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; }
197  const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
198 
200  return DependencyOutputOpts;
201  }
202 
204  return DependencyOutputOpts;
205  }
206 
207  FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }
208 
210  return FileSystemOpts;
211  }
212 
213  FrontendOptions &getFrontendOpts() { return FrontendOpts; }
214  const FrontendOptions &getFrontendOpts() const { return FrontendOpts; }
215 
217  return PreprocessorOutputOpts;
218  }
219 
221  return PreprocessorOutputOpts;
222  }
223 
224  /// @}
225 };
226 
229  DiagnosticsEngine &Diags);
230 
232  const CompilerInvocation &CI, 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.
IntrusiveRefCntPtr< llvm::vfs::FileSystem > createVFSFromCompilerInvocation(const CompilerInvocation &CI, DiagnosticsEngine &Diags, IntrusiveRefCntPtr< llvm::vfs::FileSystem > BaseFS)
const HeaderSearchOptions & getHeaderSearchOpts() const
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
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:49
const PreprocessorOptions & getPreprocessorOpts() const
std::shared_ptr< PreprocessorOptions > PreprocessorOpts
Options controlling the preprocessor (aside from #include handling).
CodeGenOptions & getCodeGenOpts()
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.
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.
Stores options for the analyzer from the command line.
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:14579
FileSystemOptions & getFileSystemOpts()
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
const TargetOptions & getTargetOpts() const
const DependencyOutputOptions & getDependencyOutputOpts() const