2013-03-01 00:29:24 +08:00
|
|
|
//===-- UseAuto/UseAuto.cpp - Use auto type specifier ---------------------===//
|
|
|
|
//
|
|
|
|
// 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 UseAutoTransform class.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "UseAuto.h"
|
|
|
|
#include "UseAutoActions.h"
|
|
|
|
#include "UseAutoMatchers.h"
|
|
|
|
|
|
|
|
using clang::ast_matchers::MatchFinder;
|
|
|
|
using namespace clang;
|
|
|
|
using namespace clang::tooling;
|
|
|
|
|
2013-10-05 20:15:58 +08:00
|
|
|
int UseAutoTransform::apply(const clang::tooling::CompilationDatabase &Database,
|
2013-06-18 23:31:01 +08:00
|
|
|
const std::vector<std::string> &SourcePaths) {
|
|
|
|
ClangTool UseAutoTool(Database, SourcePaths);
|
2013-03-01 00:29:24 +08:00
|
|
|
|
|
|
|
unsigned AcceptedChanges = 0;
|
|
|
|
|
|
|
|
MatchFinder Finder;
|
2013-09-03 21:16:02 +08:00
|
|
|
ReplacementsVec Replaces;
|
|
|
|
IteratorReplacer ReplaceIterators(AcceptedChanges, Options().MaxRiskLevel,
|
|
|
|
/*Owner=*/ *this);
|
|
|
|
NewReplacer ReplaceNew(AcceptedChanges, Options().MaxRiskLevel,
|
|
|
|
/*Owner=*/ *this);
|
2013-03-01 00:29:24 +08:00
|
|
|
|
2013-04-03 04:43:57 +08:00
|
|
|
Finder.addMatcher(makeIteratorDeclMatcher(), &ReplaceIterators);
|
|
|
|
Finder.addMatcher(makeDeclWithNewMatcher(), &ReplaceNew);
|
2013-03-01 00:29:24 +08:00
|
|
|
|
2014-08-09 00:06:07 +08:00
|
|
|
if (int Result = UseAutoTool.run(createActionFactory(Finder).get())) {
|
2013-03-01 00:29:24 +08:00
|
|
|
llvm::errs() << "Error encountered during translation.\n";
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2013-03-05 08:12:33 +08:00
|
|
|
setAcceptedChanges(AcceptedChanges);
|
2013-03-01 00:29:24 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-24 22:24:33 +08:00
|
|
|
|
|
|
|
struct UseAutoFactory : TransformFactory {
|
2013-07-29 23:58:47 +08:00
|
|
|
UseAutoFactory() {
|
|
|
|
Since.Clang = Version(2, 9);
|
|
|
|
Since.Gcc = Version(4, 4);
|
|
|
|
Since.Icc = Version(12);
|
|
|
|
Since.Msvc = Version(10);
|
|
|
|
}
|
|
|
|
|
2014-03-02 18:20:11 +08:00
|
|
|
Transform *createTransform(const TransformOptions &Opts) override {
|
2013-07-24 22:24:33 +08:00
|
|
|
return new UseAutoTransform(Opts);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Register the factory using this statically initialized variable.
|
|
|
|
static TransformFactoryRegistry::Add<UseAutoFactory>
|
|
|
|
X("use-auto", "Use of 'auto' type specifier");
|
|
|
|
|
|
|
|
// This anchor is used to force the linker to link in the generated object file
|
|
|
|
// and thus register the factory.
|
|
|
|
volatile int UseAutoTransformAnchorSource = 0;
|