Skip to content

Commit 9d11ef9

Browse files
author
akirtzidis
committed
[ARCMigrate] When applying changes from remap files, disable the 'adjustRemovals' functionality of EditedSource
'adjustRemovals' is used to avoid situation when removing a range inadvertently causes 2 separate identifiers to get joined into one. But it is not useful when the edits are character precise, as is the case with the remap files. git-svn-id: http://llvm.org/svn/llvm-project/cfe/trunk@301602 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d9aee8c commit 9d11ef9

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

include/clang/Edit/EditedSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class EditedSource {
6565

6666
bool commit(const Commit &commit);
6767

68-
void applyRewrites(EditsReceiver &receiver);
68+
void applyRewrites(EditsReceiver &receiver, bool adjustRemovals = true);
6969
void clearRewrites();
7070

7171
StringRef copyString(StringRef str) { return str.copy(StrAlloc); }

lib/ARCMigrate/ObjCMT.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,7 @@ static std::string applyEditsToTemp(const FileEntry *FE,
21892189

21902190
Rewriter rewriter(SM, LangOpts);
21912191
RewritesReceiver Rec(rewriter);
2192-
Editor.applyRewrites(Rec);
2192+
Editor.applyRewrites(Rec, /*adjustRemovals=*/false);
21932193

21942194
const RewriteBuffer *Buf = rewriter.getRewriteBufferFor(FID);
21952195
SmallString<512> NewText;

lib/Edit/EditedSource.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,14 @@ static void adjustRemoval(const SourceManager &SM, const LangOptions &LangOpts,
363363

364364
static void applyRewrite(EditsReceiver &receiver,
365365
StringRef text, FileOffset offs, unsigned len,
366-
const SourceManager &SM, const LangOptions &LangOpts) {
366+
const SourceManager &SM, const LangOptions &LangOpts,
367+
bool shouldAdjustRemovals) {
367368
assert(offs.getFID().isValid());
368369
SourceLocation Loc = SM.getLocForStartOfFile(offs.getFID());
369370
Loc = Loc.getLocWithOffset(offs.getOffset());
370371
assert(Loc.isFileID());
371372

372-
if (text.empty())
373+
if (text.empty() && shouldAdjustRemovals)
373374
adjustRemoval(SM, LangOpts, Loc, offs, len, text);
374375

375376
CharSourceRange range = CharSourceRange::getCharRange(Loc,
@@ -387,7 +388,8 @@ static void applyRewrite(EditsReceiver &receiver,
387388
receiver.insert(Loc, text);
388389
}
389390

390-
void EditedSource::applyRewrites(EditsReceiver &receiver) {
391+
void EditedSource::applyRewrites(EditsReceiver &receiver,
392+
bool shouldAdjustRemovals) {
391393
SmallString<128> StrVec;
392394
FileOffset CurOffs, CurEnd;
393395
unsigned CurLen;
@@ -414,14 +416,16 @@ void EditedSource::applyRewrites(EditsReceiver &receiver) {
414416
continue;
415417
}
416418

417-
applyRewrite(receiver, StrVec, CurOffs, CurLen, SourceMgr, LangOpts);
419+
applyRewrite(receiver, StrVec, CurOffs, CurLen, SourceMgr, LangOpts,
420+
shouldAdjustRemovals);
418421
CurOffs = offs;
419422
StrVec = act.Text;
420423
CurLen = act.RemoveLen;
421424
CurEnd = CurOffs.getWithOffset(CurLen);
422425
}
423426

424-
applyRewrite(receiver, StrVec, CurOffs, CurLen, SourceMgr, LangOpts);
427+
applyRewrite(receiver, StrVec, CurOffs, CurLen, SourceMgr, LangOpts,
428+
shouldAdjustRemovals);
425429
}
426430

427431
void EditedSource::clearRewrites() {

test/ARCMT/remap-applying.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a bc
2+
3+
// RUN: echo "[{\"file\": \"%s\", \"offset\": 1, \"remove\": 2, }]" > %t.remap
4+
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result

test/ARCMT/remap-applying.c.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ac
2+
3+
// RUN: echo "[{\"file\": \"%s\", \"offset\": 1, \"remove\": 2, }]" > %t.remap
4+
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result

0 commit comments

Comments
 (0)