forked from OSchip/llvm-project
66 lines
2.2 KiB
C++
66 lines
2.2 KiB
C++
//===-- ReplaceAutoPtr.cpp ---------- std::auto_ptr replacement -----------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// \brief This file provides the implementation of the ReplaceAutoPtrTransform
|
|
/// class.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "ReplaceAutoPtr.h"
|
|
#include "ReplaceAutoPtrActions.h"
|
|
#include "ReplaceAutoPtrMatchers.h"
|
|
|
|
using namespace clang;
|
|
using namespace clang::tooling;
|
|
using namespace clang::ast_matchers;
|
|
|
|
int
|
|
ReplaceAutoPtrTransform::apply(FileOverrides &InputStates,
|
|
const CompilationDatabase &Database,
|
|
const std::vector<std::string> &SourcePaths) {
|
|
ClangTool Tool(Database, SourcePaths);
|
|
unsigned AcceptedChanges = 0;
|
|
MatchFinder Finder;
|
|
AutoPtrReplacer Replacer(getReplacements(), AcceptedChanges,
|
|
/*Owner=*/*this);
|
|
OwnershipTransferFixer Fixer(getReplacements(), AcceptedChanges,
|
|
/*Owner=*/*this);
|
|
|
|
Finder.addMatcher(makeAutoPtrTypeLocMatcher(), &Replacer);
|
|
Finder.addMatcher(makeAutoPtrUsingDeclMatcher(), &Replacer);
|
|
Finder.addMatcher(makeTransferOwnershipExprMatcher(), &Fixer);
|
|
|
|
setOverrides(InputStates);
|
|
|
|
if (Tool.run(createActionFactory(Finder))) {
|
|
llvm::errs() << "Error encountered during translation.\n";
|
|
return 1;
|
|
}
|
|
|
|
setAcceptedChanges(AcceptedChanges);
|
|
|
|
return 0;
|
|
}
|
|
|
|
struct ReplaceAutoPtrFactory : TransformFactory {
|
|
Transform *createTransform(const TransformOptions &Opts) LLVM_OVERRIDE {
|
|
return new ReplaceAutoPtrTransform(Opts);
|
|
}
|
|
};
|
|
|
|
// Register the factory using this statically initialized variable.
|
|
static TransformFactoryRegistry::Add<ReplaceAutoPtrFactory>
|
|
X("replace-auto_ptr", "Replace std::auto_ptr (deprecated) by std::unique_ptr"
|
|
" (EXPERIMENTAL)");
|
|
|
|
// This anchor is used to force the linker to link in the generated object file
|
|
// and thus register the factory.
|
|
volatile int ReplaceAutoPtrTransformAnchorSource = 0;
|