]> granicus.if.org Git - clang/commitdiff
CompilerInstance: Change to not contain the CompilerInvocation object.
authorDaniel Dunbar <daniel@zuster.org>
Sat, 30 Jan 2010 21:47:07 +0000 (21:47 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 30 Jan 2010 21:47:07 +0000 (21:47 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94923 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/CompilerInstance.h
lib/Frontend/CompilerInstance.cpp

index edafe623a4f6c14d45d28d4ed418979f647abaf2..8f12b54be95e8029aca7b930133544ed4c701aad 100644 (file)
@@ -62,7 +62,7 @@ class CompilerInstance {
   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 @@ public:
   /// @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();
   }
 
   /// }
index 6b0fdb8a343039bf219e878a3d71aacf627104fb..a630486688e401e074ae71b06a4e29d4f8b65742 100644 (file)
@@ -38,14 +38,19 @@ using namespace clang;
 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);
 }