Skip to content

Commit 0d150db

Browse files
authoredAug 18, 2024··
[llvm][clang] Move RewriterBuffer to ADT. (#99770)
These classes are not specific to clang and useful for other rewriter tools (flagged in previous review).
1 parent bcbe9d6 commit 0d150db

26 files changed

+825
-812
lines changed
 

‎clang/include/clang/Rewrite/Core/DeltaTree.h

-50
This file was deleted.

‎clang/include/clang/Rewrite/Core/HTMLRewrite.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
#include "clang/Basic/SourceLocation.h"
1818
#include <string>
1919

20+
namespace llvm {
21+
class RewriteBuffer;
22+
} // namespace llvm
23+
2024
namespace clang {
2125

2226
class Rewriter;
23-
class RewriteBuffer;
2427
class Preprocessor;
2528

2629
namespace html {
@@ -53,9 +56,9 @@ namespace html {
5356

5457
/// HighlightRange - This is the same as the above method, but takes
5558
/// decomposed file locations.
56-
void HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E,
57-
const char *BufferStart,
58-
const char *StartTag, const char *EndTag);
59+
void HighlightRange(llvm::RewriteBuffer &RB, unsigned B, unsigned E,
60+
const char *BufferStart, const char *StartTag,
61+
const char *EndTag);
5962

6063
/// EscapeText - HTMLize a specified file so that special characters are
6164
/// are translated so that they are not interpreted as HTML tags.

‎clang/include/clang/Rewrite/Core/RewriteRope.h

-223
This file was deleted.

‎clang/include/clang/Rewrite/Core/Rewriter.h

+10-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "clang/Basic/LLVM.h"
1818
#include "clang/Basic/SourceLocation.h"
19-
#include "clang/Rewrite/Core/RewriteBuffer.h"
19+
#include "llvm/ADT/RewriteBuffer.h"
2020
#include "llvm/ADT/StringRef.h"
2121
#include <map>
2222
#include <string>
@@ -32,7 +32,7 @@ class SourceManager;
3232
class Rewriter {
3333
SourceManager *SourceMgr = nullptr;
3434
const LangOptions *LangOpts = nullptr;
35-
std::map<FileID, RewriteBuffer> RewriteBuffers;
35+
std::map<FileID, llvm::RewriteBuffer> RewriteBuffers;
3636

3737
public:
3838
struct RewriteOptions {
@@ -49,7 +49,7 @@ class Rewriter {
4949
///
5050
/// FIXME: This sometimes corrupts the file's rewrite buffer due to
5151
/// incorrect indexing in the implementation (see the FIXME in
52-
/// clang::RewriteBuffer::RemoveText). Moreover, it's inefficient because
52+
/// llvm::RewriteBuffer::RemoveText). Moreover, it's inefficient because
5353
/// it must scan the buffer from the beginning to find the start of the
5454
/// line. When feasible, it's better for the caller to check for a blank
5555
/// line and then, if found, expand the removal range to include it.
@@ -62,8 +62,9 @@ class Rewriter {
6262
RewriteOptions() {}
6363
};
6464

65-
using buffer_iterator = std::map<FileID, RewriteBuffer>::iterator;
66-
using const_buffer_iterator = std::map<FileID, RewriteBuffer>::const_iterator;
65+
using buffer_iterator = std::map<FileID, llvm::RewriteBuffer>::iterator;
66+
using const_buffer_iterator =
67+
std::map<FileID, llvm::RewriteBuffer>::const_iterator;
6768

6869
explicit Rewriter() = default;
6970
explicit Rewriter(SourceManager &SM, const LangOptions &LO)
@@ -191,13 +192,13 @@ class Rewriter {
191192
/// buffer, and allows you to write on it directly. This is useful if you
192193
/// want efficient low-level access to apis for scribbling on one specific
193194
/// FileID's buffer.
194-
RewriteBuffer &getEditBuffer(FileID FID);
195+
llvm::RewriteBuffer &getEditBuffer(FileID FID);
195196

196197
/// getRewriteBufferFor - Return the rewrite buffer for the specified FileID.
197198
/// If no modification has been made to it, return null.
198-
const RewriteBuffer *getRewriteBufferFor(FileID FID) const {
199-
std::map<FileID, RewriteBuffer>::const_iterator I =
200-
RewriteBuffers.find(FID);
199+
const llvm::RewriteBuffer *getRewriteBufferFor(FileID FID) const {
200+
std::map<FileID, llvm::RewriteBuffer>::const_iterator I =
201+
RewriteBuffers.find(FID);
201202
return I == RewriteBuffers.end() ? nullptr : &I->second;
202203
}
203204

‎clang/lib/ARCMigrate/ARCMT.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ bool MigrationProcess::applyTransform(TransformFn trans,
596596
for (Rewriter::buffer_iterator
597597
I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
598598
FileID FID = I->first;
599-
RewriteBuffer &buf = I->second;
599+
llvm::RewriteBuffer &buf = I->second;
600600
OptionalFileEntryRef file =
601601
Ctx.getSourceManager().getFileEntryRefForID(FID);
602602
assert(file);

‎clang/lib/ARCMigrate/ObjCMT.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
using namespace clang;
3737
using namespace arcmt;
3838
using namespace ento;
39+
using llvm::RewriteBuffer;
3940

4041
namespace {
4142

‎clang/lib/Frontend/Rewrite/FixItRewriter.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#include "clang/Edit/Commit.h"
2222
#include "clang/Edit/EditsReceiver.h"
2323
#include "clang/Frontend/FrontendDiagnostic.h"
24-
#include "clang/Rewrite/Core/RewriteBuffer.h"
2524
#include "clang/Rewrite/Core/Rewriter.h"
25+
#include "llvm/ADT/RewriteBuffer.h"
2626
#include "llvm/ADT/StringRef.h"
2727
#include "llvm/Support/FileSystem.h"
2828
#include "llvm/Support/raw_ostream.h"
@@ -33,6 +33,7 @@
3333
#include <utility>
3434

3535
using namespace clang;
36+
using llvm::RewriteBuffer;
3637

3738
FixItRewriter::FixItRewriter(DiagnosticsEngine &Diags, SourceManager &SourceMgr,
3839
const LangOptions &LangOpts,

0 commit comments

Comments
 (0)
Please sign in to comment.