@@ -120,14 +120,23 @@ class CompilerInvocationBase {
120
120
// / Options controlling preprocessed output.
121
121
std::shared_ptr<PreprocessorOutputOptions> PreprocessorOutputOpts;
122
122
123
- public:
123
+ // / Dummy tag type whose instance can be passed into the constructor to
124
+ // / prevent creation of the reference-counted option objects.
125
+ struct EmptyConstructor {};
126
+
124
127
CompilerInvocationBase ();
125
- CompilerInvocationBase (const CompilerInvocationBase &X) { operator =(X); }
128
+ CompilerInvocationBase (EmptyConstructor) {}
129
+ CompilerInvocationBase (const CompilerInvocationBase &X) = delete ;
126
130
CompilerInvocationBase (CompilerInvocationBase &&X) = default ;
127
- CompilerInvocationBase &operator =(const CompilerInvocationBase &X);
131
+ CompilerInvocationBase &operator =(const CompilerInvocationBase &X) = delete ;
132
+ CompilerInvocationBase &deep_copy_assign (const CompilerInvocationBase &X);
133
+ CompilerInvocationBase &shallow_copy_assign (const CompilerInvocationBase &X);
128
134
CompilerInvocationBase &operator =(CompilerInvocationBase &&X) = default ;
129
135
~CompilerInvocationBase () = default ;
130
136
137
+ public:
138
+ // / Const getters.
139
+ // / @{
131
140
const LangOptions &getLangOpts () const { return *LangOpts; }
132
141
const TargetOptions &getTargetOpts () const { return *TargetOpts; }
133
142
const DiagnosticOptions &getDiagnosticOpts () const { return *DiagnosticOpts; }
@@ -146,7 +155,118 @@ class CompilerInvocationBase {
146
155
const PreprocessorOutputOptions &getPreprocessorOutputOpts () const {
147
156
return *PreprocessorOutputOpts;
148
157
}
158
+ // / @}
159
+
160
+ // / Command line generation.
161
+ // / @{
162
+ using StringAllocator = llvm::function_ref<const char *(const Twine &)>;
163
+ // / Generate cc1-compatible command line arguments from this instance.
164
+ // /
165
+ // / \param [out] Args - The generated arguments. Note that the caller is
166
+ // / responsible for inserting the path to the clang executable and "-cc1" if
167
+ // / desired.
168
+ // / \param SA - A function that given a Twine can allocate storage for a given
169
+ // / command line argument and return a pointer to the newly allocated string.
170
+ // / The returned pointer is what gets appended to Args.
171
+ void generateCC1CommandLine (llvm::SmallVectorImpl<const char *> &Args,
172
+ StringAllocator SA) const {
173
+ generateCC1CommandLine ([&](const Twine &Arg) {
174
+ // No need to allocate static string literals.
175
+ Args.push_back (Arg.isSingleStringLiteral ()
176
+ ? Arg.getSingleStringRef ().data ()
177
+ : SA (Arg));
178
+ });
179
+ }
180
+
181
+ using ArgumentConsumer = llvm::function_ref<void (const Twine &)>;
182
+ // / Generate cc1-compatible command line arguments from this instance.
183
+ // /
184
+ // / \param Consumer - Callback that gets invoked for every single generated
185
+ // / command line argument.
186
+ void generateCC1CommandLine (ArgumentConsumer Consumer) const ;
187
+
188
+ // / Generate cc1-compatible command line arguments from this instance,
189
+ // / wrapping the result as a std::vector<std::string>.
190
+ // /
191
+ // / This is a (less-efficient) wrapper over generateCC1CommandLine().
192
+ std::vector<std::string> getCC1CommandLine () const ;
193
+
194
+ private:
195
+ // / Generate command line options from DiagnosticOptions.
196
+ static void GenerateDiagnosticArgs (const DiagnosticOptions &Opts,
197
+ ArgumentConsumer Consumer,
198
+ bool DefaultDiagColor);
199
+
200
+ // / Generate command line options from LangOptions.
201
+ static void GenerateLangArgs (const LangOptions &Opts,
202
+ ArgumentConsumer Consumer, const llvm::Triple &T,
203
+ InputKind IK);
204
+
205
+ // Generate command line options from CodeGenOptions.
206
+ static void GenerateCodeGenArgs (const CodeGenOptions &Opts,
207
+ ArgumentConsumer Consumer,
208
+ const llvm::Triple &T,
209
+ const std::string &OutputFile,
210
+ const LangOptions *LangOpts);
211
+ // / @}
212
+
213
+ public:
214
+ // / Generate command line options from CASOptions.
215
+ static void GenerateCASArgs (const CASOptions &Opts,
216
+ ArgumentConsumer Consumer);
217
+ static void GenerateCASArgs (const CASOptions &Opts,
218
+ SmallVectorImpl<const char *> &Args,
219
+ StringAllocator SA) {
220
+ GenerateCASArgs (Opts, [&](const Twine &Arg) {
221
+ // No need to allocate static string literals.
222
+ Args.push_back (Arg.isSingleStringLiteral ()
223
+ ? Arg.getSingleStringRef ().data ()
224
+ : SA (Arg));
225
+ });
226
+ }
227
+ };
228
+
229
+ // / Helper class for holding the data necessary to invoke the compiler.
230
+ // /
231
+ // / This class is designed to represent an abstract "invocation" of the
232
+ // / compiler, including data such as the include paths, the code generation
233
+ // / options, the warning flags, and so on.
234
+ class CompilerInvocation : public CompilerInvocationBase {
235
+ public:
236
+ CompilerInvocation () = default ;
237
+ CompilerInvocation (const CompilerInvocation &X)
238
+ : CompilerInvocationBase(EmptyConstructor{}) {
239
+ deep_copy_assign (X);
240
+ }
241
+ CompilerInvocation (CompilerInvocation &&) = default ;
242
+ CompilerInvocation &operator =(const CompilerInvocation &X) {
243
+ deep_copy_assign (X);
244
+ return *this ;
245
+ }
246
+ ~CompilerInvocation () = default ;
149
247
248
+ // / Const getters.
249
+ // / @{
250
+ // Note: These need to be pulled in manually. Otherwise, they get hidden by
251
+ // the mutable getters with the same names.
252
+ using CompilerInvocationBase::getLangOpts;
253
+ using CompilerInvocationBase::getTargetOpts;
254
+ using CompilerInvocationBase::getDiagnosticOpts;
255
+ using CompilerInvocationBase::getHeaderSearchOpts;
256
+ using CompilerInvocationBase::getPreprocessorOpts;
257
+ using CompilerInvocationBase::getAnalyzerOpts;
258
+ using CompilerInvocationBase::getMigratorOpts;
259
+ using CompilerInvocationBase::getAPINotesOpts;
260
+ using CompilerInvocationBase::getCASOpts;
261
+ using CompilerInvocationBase::getCodeGenOpts;
262
+ using CompilerInvocationBase::getFileSystemOpts;
263
+ using CompilerInvocationBase::getFrontendOpts;
264
+ using CompilerInvocationBase::getDependencyOutputOpts;
265
+ using CompilerInvocationBase::getPreprocessorOutputOpts;
266
+ // / @}
267
+
268
+ // / Mutable getters.
269
+ // / @{
150
270
LangOptions &getLangOpts () { return *LangOpts; }
151
271
TargetOptions &getTargetOpts () { return *TargetOpts; }
152
272
DiagnosticOptions &getDiagnosticOpts () { return *DiagnosticOpts; }
@@ -165,15 +285,8 @@ class CompilerInvocationBase {
165
285
PreprocessorOutputOptions &getPreprocessorOutputOpts () {
166
286
return *PreprocessorOutputOpts;
167
287
}
168
- };
288
+ // / @}
169
289
170
- // / Helper class for holding the data necessary to invoke the compiler.
171
- // /
172
- // / This class is designed to represent an abstract "invocation" of the
173
- // / compiler, including data such as the include paths, the code generation
174
- // / options, the warning flags, and so on.
175
- class CompilerInvocation : public CompilerInvocationBase {
176
- public:
177
290
// / Base class internals.
178
291
// / @{
179
292
using CompilerInvocationBase::LangOpts;
@@ -217,38 +330,6 @@ class CompilerInvocation : public CompilerInvocationBase {
217
330
// / identifying the conditions under which the module was built.
218
331
std::string getModuleHash (DiagnosticsEngine &Diags) const ;
219
332
220
- using StringAllocator = llvm::function_ref<const char *(const Twine &)>;
221
- // / Generate cc1-compatible command line arguments from this instance.
222
- // /
223
- // / \param [out] Args - The generated arguments. Note that the caller is
224
- // / responsible for inserting the path to the clang executable and "-cc1" if
225
- // / desired.
226
- // / \param SA - A function that given a Twine can allocate storage for a given
227
- // / command line argument and return a pointer to the newly allocated string.
228
- // / The returned pointer is what gets appended to Args.
229
- void generateCC1CommandLine (llvm::SmallVectorImpl<const char *> &Args,
230
- StringAllocator SA) const {
231
- generateCC1CommandLine ([&](const Twine &Arg) {
232
- // No need to allocate static string literals.
233
- Args.push_back (Arg.isSingleStringLiteral ()
234
- ? Arg.getSingleStringRef ().data ()
235
- : SA (Arg));
236
- });
237
- }
238
-
239
- using ArgumentConsumer = llvm::function_ref<void (const Twine &)>;
240
- // / Generate cc1-compatible command line arguments from this instance.
241
- // /
242
- // / \param Consumer - Callback that gets invoked for every single generated
243
- // / command line argument.
244
- void generateCC1CommandLine (ArgumentConsumer Consumer) const ;
245
-
246
- // / Generate cc1-compatible command line arguments from this instance,
247
- // / wrapping the result as a std::vector<std::string>.
248
- // /
249
- // / This is a (less-efficient) wrapper over generateCC1CommandLine().
250
- std::vector<std::string> getCC1CommandLine () const ;
251
-
252
333
// / Check that \p Args can be parsed and re-serialized without change,
253
334
// / emiting diagnostics for any differences.
254
335
// /
@@ -272,38 +353,17 @@ class CompilerInvocation : public CompilerInvocationBase {
272
353
static bool ParseCASArgs (CASOptions &Opts, const llvm::opt::ArgList &Args,
273
354
DiagnosticsEngine &Diags);
274
355
275
- // / Generate command line options from CASOptions.
276
- static void GenerateCASArgs (const CASOptions &Opts,
277
- ArgumentConsumer);
278
- static void GenerateCASArgs (const CASOptions &Opts,
279
- SmallVectorImpl<const char *> &Args,
280
- CompilerInvocation::StringAllocator SA) {
281
- GenerateCASArgs (Opts, [&](const Twine &Arg) { Args.push_back (SA (Arg)); });
282
- }
283
-
284
356
private:
285
357
static bool CreateFromArgsImpl (CompilerInvocation &Res,
286
358
ArrayRef<const char *> CommandLineArgs,
287
359
DiagnosticsEngine &Diags, const char *Argv0);
288
360
289
- // / Generate command line options from DiagnosticOptions.
290
- static void GenerateDiagnosticArgs (const DiagnosticOptions &Opts,
291
- ArgumentConsumer Consumer,
292
- bool DefaultDiagColor);
293
-
294
361
// / Parse command line options that map to LangOptions.
295
362
static bool ParseLangArgs (LangOptions &Opts, llvm::opt::ArgList &Args,
296
363
InputKind IK, const llvm::Triple &T,
297
364
std::vector<std::string> &Includes,
298
365
DiagnosticsEngine &Diags);
299
366
300
- public:
301
- // / Generate command line options from LangOptions.
302
- static void GenerateLangArgs (const LangOptions &Opts,
303
- ArgumentConsumer Consumer, const llvm::Triple &T,
304
- InputKind IK);
305
-
306
- private:
307
367
// / Parse command line options that map to CodeGenOptions.
308
368
static bool ParseCodeGenArgs (CodeGenOptions &Opts, llvm::opt::ArgList &Args,
309
369
InputKind IK, DiagnosticsEngine &Diags,
@@ -313,13 +373,47 @@ class CompilerInvocation : public CompilerInvocationBase {
313
373
const FileSystemOptions &FSOpts,
314
374
const FrontendOptions &FEOpts,
315
375
const CASOptions &CASOpts);
376
+ };
316
377
317
- // Generate command line options from CodeGenOptions.
318
- static void GenerateCodeGenArgs (const CodeGenOptions &Opts,
319
- ArgumentConsumer Consumer,
320
- const llvm::Triple &T,
321
- const std::string &OutputFile,
322
- const LangOptions *LangOpts);
378
+ // / Same as \c CompilerInvocation, but with copy-on-write optimization.
379
+ class CowCompilerInvocation : public CompilerInvocationBase {
380
+ public:
381
+ CowCompilerInvocation () = default ;
382
+ CowCompilerInvocation (const CowCompilerInvocation &X)
383
+ : CompilerInvocationBase(EmptyConstructor{}) {
384
+ shallow_copy_assign (X);
385
+ }
386
+ CowCompilerInvocation (CowCompilerInvocation &&) = default ;
387
+ CowCompilerInvocation &operator =(const CowCompilerInvocation &X) {
388
+ shallow_copy_assign (X);
389
+ return *this ;
390
+ }
391
+ ~CowCompilerInvocation () = default ;
392
+
393
+ CowCompilerInvocation (const CompilerInvocation &X)
394
+ : CompilerInvocationBase(EmptyConstructor{}) {
395
+ deep_copy_assign (X);
396
+ }
397
+
398
+ // Const getters are inherited from the base class.
399
+
400
+ // / Mutable getters.
401
+ // / @{
402
+ LangOptions &getMutLangOpts ();
403
+ TargetOptions &getMutTargetOpts ();
404
+ DiagnosticOptions &getMutDiagnosticOpts ();
405
+ HeaderSearchOptions &getMutHeaderSearchOpts ();
406
+ PreprocessorOptions &getMutPreprocessorOpts ();
407
+ AnalyzerOptions &getMutAnalyzerOpts ();
408
+ MigratorOptions &getMutMigratorOpts ();
409
+ APINotesOptions &getMutAPINotesOpts ();
410
+ CASOptions &getMutCASOpts ();
411
+ CodeGenOptions &getMutCodeGenOpts ();
412
+ FileSystemOptions &getMutFileSystemOpts ();
413
+ FrontendOptions &getMutFrontendOpts ();
414
+ DependencyOutputOptions &getMutDependencyOutputOpts ();
415
+ PreprocessorOutputOptions &getMutPreprocessorOutputOpts ();
416
+ // / @}
323
417
};
324
418
325
419
IntrusiveRefCntPtr<llvm::vfs::FileSystem> createVFSFromCompilerInvocation (
0 commit comments