]> granicus.if.org Git - clang/commitdiff
unique_ptr-ify FrontendAction::takeCurrentASTUnit
authorDavid Blaikie <dblaikie@gmail.com>
Sun, 10 Aug 2014 17:03:42 +0000 (17:03 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Sun, 10 Aug 2014 17:03:42 +0000 (17:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215319 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 9ac9d2828f6a9f620f87d48feb500fe19a02c75e..95e1c09c0ccdad073f3d54ed99970d789bdff641 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Frontend/ASTUnit.h"
 #include "clang/Frontend/FrontendOptions.h"
 #include "llvm/ADT/StringRef.h"
 #include <memory>
@@ -29,7 +30,6 @@
 namespace clang {
 class ASTConsumer;
 class ASTMergeAction;
-class ASTUnit;
 class CompilerInstance;
 
 /// Abstract base class for actions which can be performed by the frontend.
@@ -146,10 +146,12 @@ public:
     return *CurrentASTUnit;
   }
 
-  ASTUnit *takeCurrentASTUnit() { return CurrentASTUnit.release(); }
+  std::unique_ptr<ASTUnit> takeCurrentASTUnit() {
+    return std::move(CurrentASTUnit);
+  }
 
   void setCurrentInput(const FrontendInputFile &CurrentInput,
-                       ASTUnit *AST = nullptr);
+                       std::unique_ptr<ASTUnit> AST = nullptr);
 
   /// @}
   /// @name Supported Modes
index cf13d7b9ba8a9b41d7b919c225b0df7e3cb1701a..8295d6ddfa9ee9f0e00a8bf129d72cb8ce86ba1f 100644 (file)
@@ -129,9 +129,9 @@ FrontendAction::FrontendAction() : Instance(nullptr) {}
 FrontendAction::~FrontendAction() {}
 
 void FrontendAction::setCurrentInput(const FrontendInputFile &CurrentInput,
-                                     ASTUnit *AST) {
+                                     std::unique_ptr<ASTUnit> AST) {
   this->CurrentInput = CurrentInput;
-  CurrentASTUnit.reset(AST);
+  CurrentASTUnit = std::move(AST);
 }
 
 ASTConsumer* FrontendAction::CreateWrappedASTConsumer(CompilerInstance &CI,
@@ -189,13 +189,12 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
 
     IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics());
 
-    ASTUnit *AST = ASTUnit::LoadFromASTFile(InputFile, Diags,
-                                            CI.getFileSystemOpts());
+    std::unique_ptr<ASTUnit> AST(
+        ASTUnit::LoadFromASTFile(InputFile, Diags, CI.getFileSystemOpts()));
+
     if (!AST)
       goto failure;
 
-    setCurrentInput(Input, AST);
-
     // Inform the diagnostic client we are processing a source file.
     CI.getDiagnosticClient().BeginSourceFile(CI.getLangOpts(), nullptr);
     HasBegunSourceFile = true;
@@ -207,6 +206,8 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
     CI.setPreprocessor(&AST->getPreprocessor());
     CI.setASTContext(&AST->getASTContext());
 
+    setCurrentInput(Input, std::move(AST));
+
     // Initialize the action.
     if (!BeginSourceFileAction(CI, InputFile))
       goto failure;