r301602 - [ARCMigrate] When applying changes from remap files, disable the 'adjustRemovals' functionality of EditedSource
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 27 17:25:06 PDT 2017
Author: akirtzidis
Date: Thu Apr 27 19:25:06 2017
New Revision: 301602
URL: http://llvm.org/viewvc/llvm-project?rev=301602&view=rev
Log:
[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.
Added:
cfe/trunk/test/ARCMT/remap-applying.c
cfe/trunk/test/ARCMT/remap-applying.c.result
Modified:
cfe/trunk/include/clang/Edit/EditedSource.h
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/lib/Edit/EditedSource.cpp
Modified: cfe/trunk/include/clang/Edit/EditedSource.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Edit/EditedSource.h?rev=301602&r1=301601&r2=301602&view=diff
==============================================================================
--- cfe/trunk/include/clang/Edit/EditedSource.h (original)
+++ cfe/trunk/include/clang/Edit/EditedSource.h Thu Apr 27 19:25:06 2017
@@ -65,7 +65,7 @@ public:
bool commit(const Commit &commit);
- void applyRewrites(EditsReceiver &receiver);
+ void applyRewrites(EditsReceiver &receiver, bool adjustRemovals = true);
void clearRewrites();
StringRef copyString(StringRef str) { return str.copy(StrAlloc); }
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=301602&r1=301601&r2=301602&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Thu Apr 27 19:25:06 2017
@@ -2189,7 +2189,7 @@ static std::string applyEditsToTemp(cons
Rewriter rewriter(SM, LangOpts);
RewritesReceiver Rec(rewriter);
- Editor.applyRewrites(Rec);
+ Editor.applyRewrites(Rec, /*adjustRemovals=*/false);
const RewriteBuffer *Buf = rewriter.getRewriteBufferFor(FID);
SmallString<512> NewText;
Modified: cfe/trunk/lib/Edit/EditedSource.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Edit/EditedSource.cpp?rev=301602&r1=301601&r2=301602&view=diff
==============================================================================
--- cfe/trunk/lib/Edit/EditedSource.cpp (original)
+++ cfe/trunk/lib/Edit/EditedSource.cpp Thu Apr 27 19:25:06 2017
@@ -363,13 +363,14 @@ static void adjustRemoval(const SourceMa
static void applyRewrite(EditsReceiver &receiver,
StringRef text, FileOffset offs, unsigned len,
- const SourceManager &SM, const LangOptions &LangOpts) {
+ const SourceManager &SM, const LangOptions &LangOpts,
+ bool shouldAdjustRemovals) {
assert(offs.getFID().isValid());
SourceLocation Loc = SM.getLocForStartOfFile(offs.getFID());
Loc = Loc.getLocWithOffset(offs.getOffset());
assert(Loc.isFileID());
- if (text.empty())
+ if (text.empty() && shouldAdjustRemovals)
adjustRemoval(SM, LangOpts, Loc, offs, len, text);
CharSourceRange range = CharSourceRange::getCharRange(Loc,
@@ -387,7 +388,8 @@ static void applyRewrite(EditsReceiver &
receiver.insert(Loc, text);
}
-void EditedSource::applyRewrites(EditsReceiver &receiver) {
+void EditedSource::applyRewrites(EditsReceiver &receiver,
+ bool shouldAdjustRemovals) {
SmallString<128> StrVec;
FileOffset CurOffs, CurEnd;
unsigned CurLen;
@@ -414,14 +416,16 @@ void EditedSource::applyRewrites(EditsRe
continue;
}
- applyRewrite(receiver, StrVec, CurOffs, CurLen, SourceMgr, LangOpts);
+ applyRewrite(receiver, StrVec, CurOffs, CurLen, SourceMgr, LangOpts,
+ shouldAdjustRemovals);
CurOffs = offs;
StrVec = act.Text;
CurLen = act.RemoveLen;
CurEnd = CurOffs.getWithOffset(CurLen);
}
- applyRewrite(receiver, StrVec, CurOffs, CurLen, SourceMgr, LangOpts);
+ applyRewrite(receiver, StrVec, CurOffs, CurLen, SourceMgr, LangOpts,
+ shouldAdjustRemovals);
}
void EditedSource::clearRewrites() {
Added: cfe/trunk/test/ARCMT/remap-applying.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/remap-applying.c?rev=301602&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/remap-applying.c (added)
+++ cfe/trunk/test/ARCMT/remap-applying.c Thu Apr 27 19:25:06 2017
@@ -0,0 +1,4 @@
+a bc
+
+// RUN: echo "[{\"file\": \"%s\", \"offset\": 1, \"remove\": 2, }]" > %t.remap
+// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
Added: cfe/trunk/test/ARCMT/remap-applying.c.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/remap-applying.c.result?rev=301602&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/remap-applying.c.result (added)
+++ cfe/trunk/test/ARCMT/remap-applying.c.result Thu Apr 27 19:25:06 2017
@@ -0,0 +1,4 @@
+ac
+
+// RUN: echo "[{\"file\": \"%s\", \"offset\": 1, \"remove\": 2, }]" > %t.remap
+// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
More information about the cfe-commits
mailing list