[clang] [clang] Introduce copy-on-write `CompilerInvocation` (PR #65412)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 7 08:40:34 PDT 2023


================
@@ -94,47 +96,37 @@ class CompilerInvocationRefBase {
   /// Options controlling the static analyzer.
   AnalyzerOptionsRef AnalyzerOpts;
 
-  CompilerInvocationRefBase();
-  CompilerInvocationRefBase(const CompilerInvocationRefBase &X);
-  CompilerInvocationRefBase(CompilerInvocationRefBase &&X);
-  CompilerInvocationRefBase &operator=(CompilerInvocationRefBase X);
-  CompilerInvocationRefBase &operator=(CompilerInvocationRefBase &&X);
-  ~CompilerInvocationRefBase();
+  struct ShallowCopy {};
+  struct DeepCopy {};
 
-  LangOptions &getLangOpts() { return *LangOpts; }
-  const LangOptions &getLangOpts() const { return *LangOpts; }
+  RefBase();
 
-  TargetOptions &getTargetOpts() { return *TargetOpts.get(); }
-  const TargetOptions &getTargetOpts() const { return *TargetOpts.get(); }
+  RefBase(const RefBase &X, DeepCopy);
+  RefBase(const RefBase &X, ShallowCopy);
+  RefBase(const RefBase &) = delete;
 
-  DiagnosticOptions &getDiagnosticOpts() const { return *DiagnosticOpts; }
+  RefBase &assign(const RefBase &X, DeepCopy);
+  RefBase &assign(const RefBase &X, ShallowCopy);
+  RefBase &operator=(const RefBase &) = delete;
 
-  HeaderSearchOptions &getHeaderSearchOpts() { return *HeaderSearchOpts; }
+  RefBase(RefBase &&);
+  RefBase &operator=(RefBase &&);
 
-  const HeaderSearchOptions &getHeaderSearchOpts() const {
-    return *HeaderSearchOpts;
-  }
+  ~RefBase();
 
-  std::shared_ptr<HeaderSearchOptions> getHeaderSearchOptsPtr() const {
-    return HeaderSearchOpts;
-  }
-
-  std::shared_ptr<PreprocessorOptions> getPreprocessorOptsPtr() {
-    return PreprocessorOpts;
-  }
-
-  PreprocessorOptions &getPreprocessorOpts() { return *PreprocessorOpts; }
-
-  const PreprocessorOptions &getPreprocessorOpts() const {
-    return *PreprocessorOpts;
-  }
-
-  AnalyzerOptions &getAnalyzerOpts() { return *AnalyzerOpts; }
+public:
+  // clang-format off
----------------
jansvoboda11 wrote:

Yes, I find this hard to read when some of these simple getters fit on one line while others are spread out over three lines.

https://github.com/llvm/llvm-project/pull/65412


More information about the cfe-commits mailing list