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
69 lines
2.5 KiB
C++
69 lines
2.5 KiB
C++
//===-- LoopConvert/LoopConvert.cpp - C++11 for-loop migration --*- C++ -*-===//
|
|
//
|
|
// 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 LoopConvertTransform
|
|
/// class.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "LoopConvert.h"
|
|
#include "LoopActions.h"
|
|
#include "LoopMatchers.h"
|
|
#include "clang/Frontend/FrontendActions.h"
|
|
#include "clang/Rewrite/Core/Rewriter.h"
|
|
#include "clang/Tooling/Refactoring.h"
|
|
#include "clang/Tooling/Tooling.h"
|
|
|
|
using clang::ast_matchers::MatchFinder;
|
|
using namespace clang::tooling;
|
|
using namespace clang;
|
|
|
|
int LoopConvertTransform::apply(FileOverrides &InputStates,
|
|
const CompilationDatabase &Database,
|
|
const std::vector<std::string> &SourcePaths) {
|
|
ClangTool LoopTool(Database, SourcePaths);
|
|
|
|
StmtAncestorASTVisitor ParentFinder;
|
|
StmtGeneratedVarNameMap GeneratedDecls;
|
|
ReplacedVarsMap ReplacedVars;
|
|
unsigned AcceptedChanges = 0;
|
|
unsigned DeferredChanges = 0;
|
|
unsigned RejectedChanges = 0;
|
|
|
|
MatchFinder Finder;
|
|
LoopFixer ArrayLoopFixer(&ParentFinder, &getReplacements(), &GeneratedDecls,
|
|
&ReplacedVars, &AcceptedChanges, &DeferredChanges,
|
|
&RejectedChanges, Options().MaxRiskLevel, LFK_Array);
|
|
Finder.addMatcher(makeArrayLoopMatcher(), &ArrayLoopFixer);
|
|
LoopFixer IteratorLoopFixer(&ParentFinder, &getReplacements(),
|
|
&GeneratedDecls, &ReplacedVars, &AcceptedChanges,
|
|
&DeferredChanges, &RejectedChanges,
|
|
Options().MaxRiskLevel, LFK_Iterator);
|
|
Finder.addMatcher(makeIteratorLoopMatcher(), &IteratorLoopFixer);
|
|
LoopFixer PseudoarrrayLoopFixer(
|
|
&ParentFinder, &getReplacements(), &GeneratedDecls, &ReplacedVars,
|
|
&AcceptedChanges, &DeferredChanges, &RejectedChanges,
|
|
Options().MaxRiskLevel, LFK_PseudoArray);
|
|
Finder.addMatcher(makePseudoArrayLoopMatcher(), &PseudoarrrayLoopFixer);
|
|
|
|
setOverrides(InputStates);
|
|
|
|
if (int result = LoopTool.run(createActionFactory(Finder))) {
|
|
llvm::errs() << "Error encountered during translation.\n";
|
|
return result;
|
|
}
|
|
|
|
setAcceptedChanges(AcceptedChanges);
|
|
setRejectedChanges(RejectedChanges);
|
|
setDeferredChanges(DeferredChanges);
|
|
|
|
return 0;
|
|
}
|