To make it possible for replacements made to headers as part of transforming one translation unit to not be visible to the transform of other translation units, Transform now handles replacement application as part of its end-of-source handling. Several things were simplified as a result: - The duplicated code in every transform for applying replacements is now gone and replaced with one location in Transform. - RefactoringTool is no longer used since Transform houses the Replacements structure. - RewriterContainer is now a private implementation detail of Transform (also renamed to RewriterManager since its behaviour is slightly different now with respect to lifetime of objects). - There's now no distinction between input and output file state. Misc notes: - Interface changes reflected in unit tests. - Replacements for files other than the main file are assumed to be for headers and stored as such. llvm-svn: 184194
50 lines
1.6 KiB
C++
50 lines
1.6 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(FileOverrides &InputStates,
|
|
const clang::tooling::CompilationDatabase &Database,
|
|
const std::vector<std::string> &SourcePaths) {
|
|
ClangTool UseAutoTool(Database, SourcePaths);
|
|
|
|
unsigned AcceptedChanges = 0;
|
|
|
|
MatchFinder Finder;
|
|
IteratorReplacer ReplaceIterators(getReplacements(), AcceptedChanges,
|
|
Options().MaxRiskLevel);
|
|
NewReplacer ReplaceNew(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;
|
|
}
|
|
|
|
setAcceptedChanges(AcceptedChanges);
|
|
|
|
return 0;
|
|
}
|