From b5500b9ca0102f1ccaf32f0e77e96d0739aded9b Mon Sep 17 00:00:00 2001 From: pascal Date: Sat, 3 Sep 2016 22:46:54 +0000 Subject: Use the space freed up by sparc and zaurus to import LLVM. ok hackroom@ --- gnu/llvm/tools/clang/lib/Tooling/Refactoring.cpp | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 gnu/llvm/tools/clang/lib/Tooling/Refactoring.cpp (limited to 'gnu/llvm/tools/clang/lib/Tooling/Refactoring.cpp') diff --git a/gnu/llvm/tools/clang/lib/Tooling/Refactoring.cpp b/gnu/llvm/tools/clang/lib/Tooling/Refactoring.cpp new file mode 100644 index 00000000000..d32452f6f29 --- /dev/null +++ b/gnu/llvm/tools/clang/lib/Tooling/Refactoring.cpp @@ -0,0 +1,65 @@ +//===--- Refactoring.cpp - Framework for clang refactoring tools ----------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Implements tools to support refactorings. +// +//===----------------------------------------------------------------------===// + +#include "clang/Basic/DiagnosticOptions.h" +#include "clang/Basic/FileManager.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Frontend/TextDiagnosticPrinter.h" +#include "clang/Lex/Lexer.h" +#include "clang/Rewrite/Core/Rewriter.h" +#include "clang/Tooling/Refactoring.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/raw_os_ostream.h" + +namespace clang { +namespace tooling { + +RefactoringTool::RefactoringTool( + const CompilationDatabase &Compilations, ArrayRef SourcePaths, + std::shared_ptr PCHContainerOps) + : ClangTool(Compilations, SourcePaths, PCHContainerOps) {} + +Replacements &RefactoringTool::getReplacements() { return Replace; } + +int RefactoringTool::runAndSave(FrontendActionFactory *ActionFactory) { + if (int Result = run(ActionFactory)) { + return Result; + } + + LangOptions DefaultLangOptions; + IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); + TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), &*DiagOpts); + DiagnosticsEngine Diagnostics( + IntrusiveRefCntPtr(new DiagnosticIDs()), + &*DiagOpts, &DiagnosticPrinter, false); + SourceManager Sources(Diagnostics, getFiles()); + Rewriter Rewrite(Sources, DefaultLangOptions); + + if (!applyAllReplacements(Rewrite)) { + llvm::errs() << "Skipped some replacements.\n"; + } + + return saveRewrittenFiles(Rewrite); +} + +bool RefactoringTool::applyAllReplacements(Rewriter &Rewrite) { + return tooling::applyAllReplacements(Replace, Rewrite); +} + +int RefactoringTool::saveRewrittenFiles(Rewriter &Rewrite) { + return Rewrite.overwriteChangedFiles() ? 1 : 0; +} + +} // end namespace tooling +} // end namespace clang -- cgit v1.2.3-59-g8ed1b