Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Frontend/CompilerInvocation.h
Line
Count
Source (jump to first uncovered line)
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
12
#include "clang/Basic/CodeGenOptions.h"
13
#include "clang/Basic/DiagnosticOptions.h"
14
#include "clang/Basic/FileSystemOptions.h"
15
#include "clang/Basic/LLVM.h"
16
#include "clang/Basic/LangOptions.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 <memory>
25
#include <string>
26
27
namespace llvm {
28
29
class Triple;
30
31
namespace opt {
32
33
class ArgList;
34
35
} // namespace opt
36
37
namespace vfs {
38
39
class FileSystem;
40
41
} // namespace vfs
42
43
} // namespace llvm
44
45
namespace clang {
46
47
class DiagnosticsEngine;
48
class HeaderSearchOptions;
49
class PreprocessorOptions;
50
class TargetOptions;
51
52
/// Fill out Opts based on the options given in Args.
53
///
54
/// Args must have been created from the OptTable returned by
55
/// createCC1OptTable().
56
///
57
/// When errors are encountered, return false and, if Diags is non-null,
58
/// report the error(s).
59
bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args,
60
                         DiagnosticsEngine *Diags = nullptr,
61
                         bool DefaultDiagColor = true,
62
                         bool DefaultShowOpt = true);
63
64
class CompilerInvocationBase {
65
public:
66
  /// Options controlling the language variant.
67
  std::shared_ptr<LangOptions> LangOpts;
68
69
  /// Options controlling the target.
70
  std::shared_ptr<TargetOptions> TargetOpts;
71
72
  /// Options controlling the diagnostic engine.
73
  IntrusiveRefCntPtr<DiagnosticOptions> DiagnosticOpts;
74
75
  /// Options controlling the \#include directive.
76
  std::shared_ptr<HeaderSearchOptions> HeaderSearchOpts;
77
78
  /// Options controlling the preprocessor (aside from \#include handling).
79
  std::shared_ptr<PreprocessorOptions> PreprocessorOpts;
80
81
  CompilerInvocationBase();
82
  CompilerInvocationBase(const CompilerInvocationBase &X);
83
  CompilerInvocationBase &operator=(const CompilerInvocationBase &) = delete;
84
  ~CompilerInvocationBase();
85
86
594k
  LangOptions *getLangOpts() { return LangOpts.get(); }
87
7.81k
  const LangOptions *getLangOpts() const { return LangOpts.get(); }
88
89
242k
  TargetOptions &getTargetOpts() { return *TargetOpts.get(); }
90
7.81k
  const TargetOptions &getTargetOpts() const { return *TargetOpts.get(); }
91
92
150k
  DiagnosticOptions &getDiagnosticOpts() const { return *DiagnosticOpts; }
93
94
331k
  HeaderSearchOptions &getHeaderSearchOpts() { return *HeaderSearchOpts; }
95
96
48.3k
  const HeaderSearchOptions &getHeaderSearchOpts() const {
97
48.3k
    return *HeaderSearchOpts;
98
48.3k
  }
99
100
44.0k
  std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const {
101
44.0k
    return HeaderSearchOpts;
102
44.0k
  }
103
104
44.0k
  std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() {
105
44.0k
    return PreprocessorOpts;
106
44.0k
  }
107
108
324k
  PreprocessorOptions &getPreprocessorOpts() { return *PreprocessorOpts; }
109
110
12.4k
  const PreprocessorOptions &getPreprocessorOpts() const {
111
12.4k
    return *PreprocessorOpts;
112
12.4k
  }
113
};
114
115
/// Helper class for holding the data necessary to invoke the compiler.
116
///
117
/// This class is designed to represent an abstract "invocation" of the
118
/// compiler, including data such as the include paths, the code generation
119
/// options, the warning flags, and so on.
120
class CompilerInvocation : public CompilerInvocationBase {
121
  /// Options controlling the static analyzer.
122
  AnalyzerOptionsRef AnalyzerOpts;
123
124
  MigratorOptions MigratorOpts;
125
126
  /// Options controlling IRgen and the backend.
127
  CodeGenOptions CodeGenOpts;
128
129
  /// Options controlling dependency output.
130
  DependencyOutputOptions DependencyOutputOpts;
131
132
  /// Options controlling file system operations.
133
  FileSystemOptions FileSystemOpts;
134
135
  /// Options controlling the frontend itself.
136
  FrontendOptions FrontendOpts;
137
138
  /// Options controlling preprocessed output.
139
  PreprocessorOutputOptions PreprocessorOutputOpts;
140
141
public:
142
56.7k
  CompilerInvocation() : AnalyzerOpts(new AnalyzerOptions()) {}
143
144
  /// @name Utility Methods
145
  /// @{
146
147
  /// Create a compiler invocation from a list of input options.
148
  /// \returns true on success.
149
  ///
150
  /// \param [out] Res - The resulting invocation.
151
  /// \param ArgBegin - The first element in the argument vector.
152
  /// \param ArgEnd - The last element in the argument vector.
153
  /// \param Diags - The diagnostic engine to use for errors.
154
  static bool CreateFromArgs(CompilerInvocation &Res,
155
                             const char* const *ArgBegin,
156
                             const char* const *ArgEnd,
157
                             DiagnosticsEngine &Diags);
158
159
  /// Get the directory where the compiler headers
160
  /// reside, relative to the compiler binary (found by the passed in
161
  /// arguments).
162
  ///
163
  /// \param Argv0 - The program path (from argv[0]), for finding the builtin
164
  /// compiler path.
165
  /// \param MainAddr - The address of main (or some other function in the main
166
  /// executable), for finding the builtin compiler path.
167
  static std::string GetResourcesPath(const char *Argv0, void *MainAddr);
168
169
  /// Set language defaults for the given input language and
170
  /// language standard in the given LangOptions object.
171
  ///
172
  /// \param Opts - The LangOptions object to set up.
173
  /// \param IK - The input language.
174
  /// \param T - The target triple.
175
  /// \param PPOpts - The PreprocessorOptions affected.
176
  /// \param LangStd - The input language standard.
177
  static void setLangDefaults(LangOptions &Opts, InputKind IK,
178
                   const llvm::Triple &T, PreprocessorOptions &PPOpts,
179
                   LangStandard::Kind LangStd = LangStandard::lang_unspecified);
180
181
  /// Retrieve a module hash string that is suitable for uniquely
182
  /// identifying the conditions under which the module was built.
183
  std::string getModuleHash() const;
184
185
  /// @}
186
  /// @name Option Subgroups
187
  /// @{
188
189
97.5k
  AnalyzerOptionsRef getAnalyzerOpts() const { return AnalyzerOpts; }
190
191
45.5k
  MigratorOptions &getMigratorOpts() { return MigratorOpts; }
192
0
  const MigratorOptions &getMigratorOpts() const { return MigratorOpts; }
193
194
313k
  CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; }
195
2.07k
  const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
196
197
138k
  DependencyOutputOptions &getDependencyOutputOpts() {
198
138k
    return DependencyOutputOpts;
199
138k
  }
200
201
0
  const DependencyOutputOptions &getDependencyOutputOpts() const {
202
0
    return DependencyOutputOpts;
203
0
  }
204
205
135k
  FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }
206
207
0
  const FileSystemOptions &getFileSystemOpts() const {
208
0
    return FileSystemOpts;
209
0
  }
210
211
1.65M
  FrontendOptions &getFrontendOpts() { return FrontendOpts; }
212
2.04k
  const FrontendOptions &getFrontendOpts() const { return FrontendOpts; }
213
214
97.0k
  PreprocessorOutputOptions &getPreprocessorOutputOpts() {
215
97.0k
    return PreprocessorOutputOpts;
216
97.0k
  }
217
218
0
  const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
219
0
    return PreprocessorOutputOpts;
220
0
  }
221
222
  /// @}
223
};
224
225
IntrusiveRefCntPtr<llvm::vfs::FileSystem>
226
createVFSFromCompilerInvocation(const CompilerInvocation &CI,
227
                                DiagnosticsEngine &Diags);
228
229
IntrusiveRefCntPtr<llvm::vfs::FileSystem> createVFSFromCompilerInvocation(
230
    const CompilerInvocation &CI, DiagnosticsEngine &Diags,
231
    IntrusiveRefCntPtr<llvm::vfs::FileSystem> BaseFS);
232
233
} // namespace clang
234
235
#endif // LLVM_CLANG_FRONTEND_COMPILERINVOCATION_H