To better support per-translation unit replacements, any real work is being moved out of ActionFactory and into Transform. In this revision, that means file override application. For simplification, Transform no longer inherits from SourceFileCallbacks. TransformTest required updating as a result. llvm-svn: 184098
58 lines
1.9 KiB
C++
58 lines
1.9 KiB
C++
//===-- 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;
|
|
|
|
int UseAutoTransform::apply(const FileOverrides &InputStates,
|
|
const clang::tooling::CompilationDatabase &Database,
|
|
const std::vector<std::string> &SourcePaths,
|
|
FileOverrides &ResultStates) {
|
|
RefactoringTool UseAutoTool(Database, SourcePaths);
|
|
|
|
unsigned AcceptedChanges = 0;
|
|
|
|
MatchFinder Finder;
|
|
IteratorReplacer ReplaceIterators(UseAutoTool.getReplacements(),
|
|
AcceptedChanges, Options().MaxRiskLevel);
|
|
NewReplacer ReplaceNew(UseAutoTool.getReplacements(), AcceptedChanges,
|
|
Options().MaxRiskLevel);
|
|
|
|
Finder.addMatcher(makeIteratorDeclMatcher(), &ReplaceIterators);
|
|
Finder.addMatcher(makeDeclWithNewMatcher(), &ReplaceNew);
|
|
|
|
setOverrides(InputStates);
|
|
|
|
if (int Result = UseAutoTool.run(createActionFactory(Finder))) {
|
|
llvm::errs() << "Error encountered during translation.\n";
|
|
return Result;
|
|
}
|
|
|
|
RewriterContainer Rewrite(UseAutoTool.getFiles(), InputStates);
|
|
|
|
// FIXME: Do something if some replacements didn't get applied?
|
|
UseAutoTool.applyAllReplacements(Rewrite.getRewriter());
|
|
|
|
collectResults(Rewrite.getRewriter(), InputStates, ResultStates);
|
|
|
|
setAcceptedChanges(AcceptedChanges);
|
|
|
|
return 0;
|
|
}
|