The rewriter was previously reading the content buffer from the file itself. Since we are now keeping the content in memory and writing to the file only once, the rewriter's buffer (from the file) was not in sync with the RefactoringTool's buffer. Adding an overrideFileContents call (similar to how Clang-format handles for this) will resolve this issue. Author: Jack Yang <jack.yang@intel.com> Reviewers: gribozavr, klimek llvm-svn: 174643
69 lines
2.2 KiB
C++
69 lines
2.2 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 UseNullptrTransform
|
|
/// class.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "UseNullptr.h"
|
|
#include "NullptrActions.h"
|
|
#include "NullptrMatchers.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 UseNullptrTransform::apply(const FileContentsByPath &InputStates,
|
|
RiskLevel MaxRisk,
|
|
const CompilationDatabase &Database,
|
|
const std::vector<std::string> &SourcePaths,
|
|
FileContentsByPath &ResultStates) {
|
|
RefactoringTool UseNullptrTool(Database, SourcePaths);
|
|
|
|
for (FileContentsByPath::const_iterator I = InputStates.begin(),
|
|
E = InputStates.end();
|
|
I != E; ++I) {
|
|
UseNullptrTool.mapVirtualFile(I->first, I->second);
|
|
}
|
|
|
|
unsigned AcceptedChanges = 0;
|
|
|
|
MatchFinder Finder;
|
|
NullptrFixer Fixer(UseNullptrTool.getReplacements(),
|
|
AcceptedChanges,
|
|
MaxRisk);
|
|
|
|
Finder.addMatcher(makeImplicitCastMatcher(), &Fixer);
|
|
Finder.addMatcher(makeCastSequenceMatcher(), &Fixer);
|
|
|
|
if (int result = UseNullptrTool.run(newFrontendActionFactory(&Finder))) {
|
|
llvm::errs() << "Error encountered during translation.\n";
|
|
return result;
|
|
}
|
|
|
|
RewriterContainer Rewrite(UseNullptrTool.getFiles(), InputStates);
|
|
|
|
// FIXME: Do something if some replacements didn't get applied?
|
|
UseNullptrTool.applyAllReplacements(Rewrite.getRewriter());
|
|
|
|
collectResults(Rewrite.getRewriter(), ResultStates);
|
|
|
|
if (AcceptedChanges > 0) {
|
|
setChangesMade();
|
|
}
|
|
|
|
return 0;
|
|
}
|