@@ -61,7 +61,15 @@ bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args,
6161 DiagnosticsEngine *Diags = nullptr ,
6262 bool DefaultDiagColor = true );
6363
64- class CompilerInvocationBase {
64+ // / The base class of CompilerInvocation with reference semantics.
65+ // /
66+ // / This class stores option objects behind reference-counted pointers. This is
67+ // / useful for clients that want to keep some option object around even after
68+ // / CompilerInvocation gets destroyed, without making a copy.
69+ // /
70+ // / This is a separate class so that we can implement the copy constructor and
71+ // / assignment here and leave them defaulted in the rest of CompilerInvocation.
72+ class CompilerInvocationRefBase {
6573public:
6674 // / Options controlling the language variant.
6775 std::shared_ptr<LangOptions> LangOpts;
@@ -81,10 +89,12 @@ class CompilerInvocationBase {
8189 // / Options controlling the static analyzer.
8290 AnalyzerOptionsRef AnalyzerOpts;
8391
84- CompilerInvocationBase ();
85- CompilerInvocationBase (const CompilerInvocationBase &X);
86- CompilerInvocationBase &operator =(const CompilerInvocationBase &) = delete ;
87- ~CompilerInvocationBase ();
92+ CompilerInvocationRefBase ();
93+ CompilerInvocationRefBase (const CompilerInvocationRefBase &X);
94+ CompilerInvocationRefBase (CompilerInvocationRefBase &&X);
95+ CompilerInvocationRefBase &operator =(CompilerInvocationRefBase X);
96+ CompilerInvocationRefBase &operator =(CompilerInvocationRefBase &&X);
97+ ~CompilerInvocationRefBase ();
8898
8999 LangOptions *getLangOpts () { return LangOpts.get (); }
90100 const LangOptions *getLangOpts () const { return LangOpts.get (); }
@@ -117,12 +127,9 @@ class CompilerInvocationBase {
117127 AnalyzerOptionsRef getAnalyzerOpts () const { return AnalyzerOpts; }
118128};
119129
120- // / Helper class for holding the data necessary to invoke the compiler.
121- // /
122- // / This class is designed to represent an abstract "invocation" of the
123- // / compiler, including data such as the include paths, the code generation
124- // / options, the warning flags, and so on.
125- class CompilerInvocation : public CompilerInvocationBase {
130+ // / The base class of CompilerInvocation with value semantics.
131+ class CompilerInvocationValueBase {
132+ protected:
126133 MigratorOptions MigratorOpts;
127134
128135 // / Options controlling IRgen and the backend.
@@ -141,9 +148,46 @@ class CompilerInvocation : public CompilerInvocationBase {
141148 PreprocessorOutputOptions PreprocessorOutputOpts;
142149
143150public:
144- // / @name Utility Methods
145- // / @{
151+ MigratorOptions &getMigratorOpts () { return MigratorOpts; }
152+ const MigratorOptions &getMigratorOpts () const { return MigratorOpts; }
153+
154+ CodeGenOptions &getCodeGenOpts () { return CodeGenOpts; }
155+ const CodeGenOptions &getCodeGenOpts () const { return CodeGenOpts; }
156+
157+ DependencyOutputOptions &getDependencyOutputOpts () {
158+ return DependencyOutputOpts;
159+ }
160+
161+ const DependencyOutputOptions &getDependencyOutputOpts () const {
162+ return DependencyOutputOpts;
163+ }
146164
165+ FileSystemOptions &getFileSystemOpts () { return FileSystemOpts; }
166+
167+ const FileSystemOptions &getFileSystemOpts () const {
168+ return FileSystemOpts;
169+ }
170+
171+ FrontendOptions &getFrontendOpts () { return FrontendOpts; }
172+ const FrontendOptions &getFrontendOpts () const { return FrontendOpts; }
173+
174+ PreprocessorOutputOptions &getPreprocessorOutputOpts () {
175+ return PreprocessorOutputOpts;
176+ }
177+
178+ const PreprocessorOutputOptions &getPreprocessorOutputOpts () const {
179+ return PreprocessorOutputOpts;
180+ }
181+ };
182+
183+ // / Helper class for holding the data necessary to invoke the compiler.
184+ // /
185+ // / This class is designed to represent an abstract "invocation" of the
186+ // / compiler, including data such as the include paths, the code generation
187+ // / options, the warning flags, and so on.
188+ class CompilerInvocation : public CompilerInvocationRefBase ,
189+ public CompilerInvocationValueBase {
190+ public:
147191 // / Create a compiler invocation from a list of input options.
148192 // / \returns true on success.
149193 // /
@@ -199,43 +243,6 @@ class CompilerInvocation : public CompilerInvocationBase {
199243 void generateCC1CommandLine (llvm::SmallVectorImpl<const char *> &Args,
200244 StringAllocator SA) const ;
201245
202- // / @}
203- // / @name Option Subgroups
204- // / @{
205-
206- MigratorOptions &getMigratorOpts () { return MigratorOpts; }
207- const MigratorOptions &getMigratorOpts () const { return MigratorOpts; }
208-
209- CodeGenOptions &getCodeGenOpts () { return CodeGenOpts; }
210- const CodeGenOptions &getCodeGenOpts () const { return CodeGenOpts; }
211-
212- DependencyOutputOptions &getDependencyOutputOpts () {
213- return DependencyOutputOpts;
214- }
215-
216- const DependencyOutputOptions &getDependencyOutputOpts () const {
217- return DependencyOutputOpts;
218- }
219-
220- FileSystemOptions &getFileSystemOpts () { return FileSystemOpts; }
221-
222- const FileSystemOptions &getFileSystemOpts () const {
223- return FileSystemOpts;
224- }
225-
226- FrontendOptions &getFrontendOpts () { return FrontendOpts; }
227- const FrontendOptions &getFrontendOpts () const { return FrontendOpts; }
228-
229- PreprocessorOutputOptions &getPreprocessorOutputOpts () {
230- return PreprocessorOutputOpts;
231- }
232-
233- const PreprocessorOutputOptions &getPreprocessorOutputOpts () const {
234- return PreprocessorOutputOpts;
235- }
236-
237- // / @}
238-
239246private:
240247 static bool CreateFromArgsImpl (CompilerInvocation &Res,
241248 ArrayRef<const char *> CommandLineArgs,
0 commit comments