[cfe-commits] r94923 - in /cfe/trunk: include/clang/Frontend/CompilerInstance.h lib/Frontend/CompilerInstance.cpp

Daniel Dunbar daniel at zuster.org
Sat Jan 30 13:47:07 PST 2010


Author: ddunbar
Date: Sat Jan 30 15:47:07 2010
New Revision: 94923

URL: http://llvm.org/viewvc/llvm-project?rev=94923&view=rev
Log:
CompilerInstance: Change to not contain the CompilerInvocation object.

This allows clients to install their own CompilerInvocation object, which is
important for clients that may wish to create references to things like
LangOptions whose lifetime will extend past that of the CompilerInstance.

Modified:
    cfe/trunk/include/clang/Frontend/CompilerInstance.h
    cfe/trunk/lib/Frontend/CompilerInstance.cpp

Modified: cfe/trunk/include/clang/Frontend/CompilerInstance.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CompilerInstance.h?rev=94923&r1=94922&r2=94923&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/CompilerInstance.h (original)
+++ cfe/trunk/include/clang/Frontend/CompilerInstance.h Sat Jan 30 15:47:07 2010
@@ -62,7 +62,7 @@
   bool OwnsLLVMContext;
 
   /// The options used in this compiler instance.
-  CompilerInvocation Invocation;
+  llvm::OwningPtr<CompilerInvocation> Invocation;
 
   /// The diagnostics engine instance.
   llvm::OwningPtr<Diagnostic> Diagnostics;
@@ -161,82 +161,91 @@
   /// @name Compiler Invocation and Options
   /// {
 
-  CompilerInvocation &getInvocation() { return Invocation; }
-  const CompilerInvocation &getInvocation() const { return Invocation; }
-  void setInvocation(const CompilerInvocation &Value) { Invocation = Value; }
+  bool hasInvocation() const { return Invocation != 0; }
+
+  CompilerInvocation &getInvocation() {
+    assert(Invocation && "Compiler instance has no invocation!");
+    return *Invocation;
+  }
+
+  CompilerInvocation *takeInvocation() { return Invocation.take(); }
+
+  /// setInvocation - Replace the current invocation; the compiler instance
+  /// takes ownership of \arg Value.
+  void setInvocation(CompilerInvocation *Value);
 
   /// }
   /// @name Forwarding Methods
   /// {
 
   AnalyzerOptions &getAnalyzerOpts() {
-    return Invocation.getAnalyzerOpts();
+    return Invocation->getAnalyzerOpts();
   }
   const AnalyzerOptions &getAnalyzerOpts() const {
-    return Invocation.getAnalyzerOpts();
+    return Invocation->getAnalyzerOpts();
   }
 
   CodeGenOptions &getCodeGenOpts() {
-    return Invocation.getCodeGenOpts();
+    return Invocation->getCodeGenOpts();
   }
   const CodeGenOptions &getCodeGenOpts() const {
-    return Invocation.getCodeGenOpts();
+    return Invocation->getCodeGenOpts();
   }
 
   DependencyOutputOptions &getDependencyOutputOpts() {
-    return Invocation.getDependencyOutputOpts();
+    return Invocation->getDependencyOutputOpts();
   }
   const DependencyOutputOptions &getDependencyOutputOpts() const {
-    return Invocation.getDependencyOutputOpts();
+    return Invocation->getDependencyOutputOpts();
   }
 
   DiagnosticOptions &getDiagnosticOpts() {
-    return Invocation.getDiagnosticOpts();
+    return Invocation->getDiagnosticOpts();
   }
   const DiagnosticOptions &getDiagnosticOpts() const {
-    return Invocation.getDiagnosticOpts();
+    return Invocation->getDiagnosticOpts();
   }
 
   FrontendOptions &getFrontendOpts() {
-    return Invocation.getFrontendOpts();
+    return Invocation->getFrontendOpts();
   }
   const FrontendOptions &getFrontendOpts() const {
-    return Invocation.getFrontendOpts();
+    return Invocation->getFrontendOpts();
   }
 
   HeaderSearchOptions &getHeaderSearchOpts() {
-    return Invocation.getHeaderSearchOpts();
+    return Invocation->getHeaderSearchOpts();
   }
   const HeaderSearchOptions &getHeaderSearchOpts() const {
-    return Invocation.getHeaderSearchOpts();
+    return Invocation->getHeaderSearchOpts();
   }
 
   LangOptions &getLangOpts() {
-    return Invocation.getLangOpts();
+    return Invocation->getLangOpts();
   }
   const LangOptions &getLangOpts() const {
-    return Invocation.getLangOpts();
+    return Invocation->getLangOpts();
   }
 
   PreprocessorOptions &getPreprocessorOpts() {
-    return Invocation.getPreprocessorOpts();
+    return Invocation->getPreprocessorOpts();
   }
   const PreprocessorOptions &getPreprocessorOpts() const {
-    return Invocation.getPreprocessorOpts();
+    return Invocation->getPreprocessorOpts();
   }
 
   PreprocessorOutputOptions &getPreprocessorOutputOpts() {
-    return Invocation.getPreprocessorOutputOpts();
+    return Invocation->getPreprocessorOutputOpts();
   }
   const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
-    return Invocation.getPreprocessorOutputOpts();
+    return Invocation->getPreprocessorOutputOpts();
   }
 
   TargetOptions &getTargetOpts() {
-    return Invocation.getTargetOpts();
+    return Invocation->getTargetOpts();
   }
   const TargetOptions &getTargetOpts() const {
-    return Invocation.getTargetOpts();
+    return Invocation->getTargetOpts();
   }
 
   /// }

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=94923&r1=94922&r2=94923&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Sat Jan 30 15:47:07 2010
@@ -38,14 +38,19 @@
 CompilerInstance::CompilerInstance(llvm::LLVMContext *_LLVMContext,
                                    bool _OwnsLLVMContext)
   : LLVMContext(_LLVMContext),
-    OwnsLLVMContext(_OwnsLLVMContext) {
-    }
+    OwnsLLVMContext(_OwnsLLVMContext),
+    Invocation(new CompilerInvocation) {
+}
 
 CompilerInstance::~CompilerInstance() {
   if (OwnsLLVMContext)
     delete LLVMContext;
 }
 
+void CompilerInstance::setInvocation(CompilerInvocation *Value) {
+  Invocation.reset(Value);
+}
+
 void CompilerInstance::setDiagnostics(Diagnostic *Value) {
   Diagnostics.reset(Value);
 }





More information about the cfe-commits mailing list