Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/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
//                     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 {
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
  std::shared_ptr<HeaderSearchOptions> HeaderSearchOpts;
69
70
  /// Options controlling the preprocessor (aside from \#include handling).
71
  std::shared_ptr<PreprocessorOptions> PreprocessorOpts;
72
73
  CompilerInvocationBase();
74
  ~CompilerInvocationBase();
75
76
  CompilerInvocationBase(const CompilerInvocationBase &X);
77
78
440k
  LangOptions *getLangOpts() { return LangOpts.get(); }
79
4.53k
  const LangOptions *getLangOpts() const { return LangOpts.get(); }
80
81
201k
  TargetOptions &getTargetOpts() { return *TargetOpts.get(); }
82
4.08k
  const TargetOptions &getTargetOpts() const {
83
4.08k
    return *TargetOpts.get();
84
4.08k
  }
85
86
122k
  DiagnosticOptions &getDiagnosticOpts() const { return *DiagnosticOpts; }
87
88
266k
  HeaderSearchOptions &getHeaderSearchOpts() { return *HeaderSearchOpts; }
89
40.9k
  const HeaderSearchOptions &getHeaderSearchOpts() const {
90
40.9k
    return *HeaderSearchOpts;
91
40.9k
  }
92
31.5k
  std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const {
93
31.5k
    return HeaderSearchOpts;
94
31.5k
  }
95
96
31.5k
  std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() {
97
31.5k
    return PreprocessorOpts;
98
31.5k
  }
99
229k
  PreprocessorOptions &getPreprocessorOpts() { return *PreprocessorOpts; }
100
10.1k
  const PreprocessorOptions &getPreprocessorOpts() const {
101
10.1k
    return *PreprocessorOpts;
102
10.1k
  }
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.
110
class CompilerInvocation : public CompilerInvocationBase {
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
43.6k
  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
179
105k
  AnalyzerOptionsRef getAnalyzerOpts() const {
180
105k
    return AnalyzerOpts;
181
105k
  }
182
183
37.5k
  MigratorOptions &getMigratorOpts() { return MigratorOpts; }
184
0
  const MigratorOptions &getMigratorOpts() const {
185
0
    return MigratorOpts;
186
0
  }
187
  
188
235k
  CodeGenOptions &getCodeGenOpts() { return CodeGenOpts; }
189
0
  const CodeGenOptions &getCodeGenOpts() const {
190
0
    return CodeGenOpts;
191
0
  }
192
193
109k
  DependencyOutputOptions &getDependencyOutputOpts() {
194
109k
    return DependencyOutputOpts;
195
109k
  }
196
0
  const DependencyOutputOptions &getDependencyOutputOpts() const {
197
0
    return DependencyOutputOpts;
198
0
  }
199
200
149k
  FileSystemOptions &getFileSystemOpts() { return FileSystemOpts; }
201
0
  const FileSystemOptions &getFileSystemOpts() const {
202
0
    return FileSystemOpts;
203
0
  }
204
205
1.23M
  FrontendOptions &getFrontendOpts() { return FrontendOpts; }
206
2.30k
  const FrontendOptions &getFrontendOpts() const {
207
2.30k
    return FrontendOpts;
208
2.30k
  }
209
210
75.1k
  PreprocessorOutputOptions &getPreprocessorOutputOpts() {
211
75.1k
    return PreprocessorOutputOpts;
212
75.1k
  }
213
0
  const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
214
0
    return PreprocessorOutputOpts;
215
0
  }
216
217
  /// @}
218
};
219
220
namespace vfs {
221
  class FileSystem;
222
}
223
224
IntrusiveRefCntPtr<vfs::FileSystem>
225
createVFSFromCompilerInvocation(const CompilerInvocation &CI,
226
                                DiagnosticsEngine &Diags);
227
228
IntrusiveRefCntPtr<vfs::FileSystem>
229
createVFSFromCompilerInvocation(const CompilerInvocation &CI,
230
                                DiagnosticsEngine &Diags,
231
                                IntrusiveRefCntPtr<vfs::FileSystem> BaseFS);
232
233
} // end namespace clang
234
235
#endif