2013-07-08 20:17:37 +08:00
|
|
|
//===-- UseNullptr/UseNullptr.cpp - C++11 nullptr migration ---------------===//
|
2013-01-23 02:31:49 +08:00
|
|
|
//
|
|
|
|
// 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 UseNullptrTransform
|
|
|
|
/// class.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "UseNullptr.h"
|
|
|
|
#include "NullptrActions.h"
|
|
|
|
#include "NullptrMatchers.h"
|
|
|
|
#include "clang/Frontend/FrontendActions.h"
|
|
|
|
#include "clang/Tooling/Refactoring.h"
|
|
|
|
#include "clang/Tooling/Tooling.h"
|
|
|
|
|
|
|
|
using clang::ast_matchers::MatchFinder;
|
|
|
|
using namespace clang::tooling;
|
|
|
|
using namespace clang;
|
|
|
|
|
2013-10-05 20:15:58 +08:00
|
|
|
int UseNullptrTransform::apply(const CompilationDatabase &Database,
|
2013-06-18 23:31:01 +08:00
|
|
|
const std::vector<std::string> &SourcePaths) {
|
|
|
|
ClangTool UseNullptrTool(Database, SourcePaths);
|
2013-01-23 02:31:49 +08:00
|
|
|
|
|
|
|
unsigned AcceptedChanges = 0;
|
|
|
|
|
|
|
|
MatchFinder Finder;
|
2013-09-03 21:16:02 +08:00
|
|
|
NullptrFixer Fixer(AcceptedChanges, Options().MaxRiskLevel, /*Owner=*/ *this);
|
2013-06-18 23:44:58 +08:00
|
|
|
|
2013-01-23 02:31:49 +08:00
|
|
|
Finder.addMatcher(makeCastSequenceMatcher(), &Fixer);
|
|
|
|
|
2013-06-18 02:18:15 +08:00
|
|
|
if (int result = UseNullptrTool.run(createActionFactory(Finder))) {
|
2013-01-23 02:31:49 +08:00
|
|
|
llvm::errs() << "Error encountered during translation.\n";
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-05 08:12:33 +08:00
|
|
|
setAcceptedChanges(AcceptedChanges);
|
2013-01-23 02:31:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-24 22:24:33 +08:00
|
|
|
|
|
|
|
struct UseNullptrFactory : TransformFactory {
|
2013-07-29 23:58:47 +08:00
|
|
|
UseNullptrFactory() {
|
|
|
|
Since.Clang = Version(3, 0);
|
|
|
|
Since.Gcc = Version(4, 6);
|
|
|
|
Since.Icc = Version(12, 1);
|
|
|
|
Since.Msvc = Version(10);
|
|
|
|
}
|
|
|
|
|
2013-07-24 22:24:33 +08:00
|
|
|
Transform *createTransform(const TransformOptions &Opts) LLVM_OVERRIDE {
|
|
|
|
return new UseNullptrTransform(Opts);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Register the factory using this statically initialized variable.
|
|
|
|
static TransformFactoryRegistry::Add<UseNullptrFactory>
|
|
|
|
X("use-nullptr", "Make use of nullptr keyword where possible");
|
|
|
|
|
|
|
|
// This anchor is used to force the linker to link in the generated object file
|
|
|
|
// and thus register the factory.
|
|
|
|
volatile int UseNullptrTransformAnchorSource = 0;
|