summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2017-04-28 00:25:06 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2017-04-28 00:25:06 +0000
commit5312b667a86d79afdf683e3040e3c818925368de (patch)
treebce68763ab7877ec585b0b21dff8898255752920
parent064b7fecacdfb49bbdbf736e9779b908a1efe5f7 (diff)
downloadbcm5719-llvm-5312b667a86d79afdf683e3040e3c818925368de.tar.gz
bcm5719-llvm-5312b667a86d79afdf683e3040e3c818925368de.zip
[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. llvm-svn: 301602
-rw-r--r--clang/include/clang/Edit/EditedSource.h2
-rw-r--r--clang/lib/ARCMigrate/ObjCMT.cpp2
-rw-r--r--clang/lib/Edit/EditedSource.cpp14
-rw-r--r--clang/test/ARCMT/remap-applying.c4
-rw-r--r--clang/test/ARCMT/remap-applying.c.result4
5 files changed, 19 insertions, 7 deletions
diff --git a/clang/include/clang/Edit/EditedSource.h b/clang/include/clang/Edit/EditedSource.h
index b6ec8b8f06e..b082e4e0a3d 100644
--- a/clang/include/clang/Edit/EditedSource.h
+++ b/clang/include/clang/Edit/EditedSource.h
@@ -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); }
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp
index 241a7246b62..fcc67da1f77 100644
--- a/clang/lib/ARCMigrate/ObjCMT.cpp
+++ b/clang/lib/ARCMigrate/ObjCMT.cpp
@@ -2189,7 +2189,7 @@ static std::string applyEditsToTemp(const FileEntry *FE,
Rewriter rewriter(SM, LangOpts);
RewritesReceiver Rec(rewriter);
- Editor.applyRewrites(Rec);
+ Editor.applyRewrites(Rec, /*adjustRemovals=*/false);
const RewriteBuffer *Buf = rewriter.getRewriteBufferFor(FID);
SmallString<512> NewText;
diff --git a/clang/lib/Edit/EditedSource.cpp b/clang/lib/Edit/EditedSource.cpp
index 5292a58a9cc..1a7a68cffb6 100644
--- a/clang/lib/Edit/EditedSource.cpp
+++ b/clang/lib/Edit/EditedSource.cpp
@@ -363,13 +363,14 @@ static void adjustRemoval(const SourceManager &SM, const LangOptions &LangOpts,
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,
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(EditsReceiver &receiver) {
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() {
diff --git a/clang/test/ARCMT/remap-applying.c b/clang/test/ARCMT/remap-applying.c
new file mode 100644
index 00000000000..b6280bf9387
--- /dev/null
+++ b/clang/test/ARCMT/remap-applying.c
@@ -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
diff --git a/clang/test/ARCMT/remap-applying.c.result b/clang/test/ARCMT/remap-applying.c.result
new file mode 100644
index 00000000000..975dc9e4312
--- /dev/null
+++ b/clang/test/ARCMT/remap-applying.c.result
@@ -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
OpenPOWER on IntegriCloud