blob: 91c86d893bc6d305e121602311812dbc6dbcb033 [file] [log] [blame]
//===--- RewriteBufferEditsReceiver.h ---------------------------*- C++ -*-===//
// This source file is part of the open source project
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
// See for license information
// See for the list of Swift project authors
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Edit/EditsReceiver.h"
#include "clang/Rewrite/Core/RewriteBuffer.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"
using llvm::StringRef;
namespace swift {
namespace migrator {
/// An EditsReceiver that collects edits from an EditedSource and directly
/// applies it to a clang::RewriteBuffer.
class RewriteBufferEditsReceiver final : public clang::edit::EditsReceiver {
const clang::SourceManager &ClangSourceManager;
const clang::FileID InputFileID;
const StringRef InputText;
clang::RewriteBuffer RewriteBuf;
RewriteBufferEditsReceiver(const clang::SourceManager &ClangSourceManager,
const clang::FileID InputFileID,
const StringRef InputText)
: ClangSourceManager(ClangSourceManager),
InputText(InputText) {
virtual void insert(clang::SourceLocation Loc, StringRef Text) override;
virtual void replace(clang::CharSourceRange Range, StringRef Text) override;
/// Print the result of all of the edits to the given output stream.
void printResult(llvm::raw_ostream &OS) const;
} // end namespace migrator
} // end namespace swift