#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>
namespace clang {
class ASTConsumer;
class ASTMergeAction;
-class ASTUnit;
class CompilerInstance;
/// Abstract base class for actions which can be performed by the frontend.
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
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,
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;
CI.setPreprocessor(&AST->getPreprocessor());
CI.setASTContext(&AST->getASTContext());
+ setCurrentInput(Input, std::move(AST));
+
// Initialize the action.
if (!BeginSourceFileAction(CI, InputFile))
goto failure;