]> granicus.if.org Git - clang/commitdiff
[ARCMigrate] When applying changes from remap files, disable the 'adjustRemovals...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 28 Apr 2017 00:25:06 +0000 (00:25 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 28 Apr 2017 00:25:06 +0000 (00:25 +0000)
'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: https://llvm.org/svn/llvm-project/cfe/trunk@301602 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Edit/EditedSource.h
lib/ARCMigrate/ObjCMT.cpp
lib/Edit/EditedSource.cpp
test/ARCMT/remap-applying.c [new file with mode: 0644]
test/ARCMT/remap-applying.c.result [new file with mode: 0644]

index b6ec8b8f06e2446fdaa4e69b645e8769ace6d6ba..b082e4e0a3dfbcb855819a7331ae09d1daf880ce 100644 (file)
@@ -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); }
index 241a7246b6219dfd5e9d804ed9f9151a8af9ed79..fcc67da1f77411b4d1c94cf31166980b01524e3b 100644 (file)
@@ -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;
index 5292a58a9ccd4dcbb2165c7d1765704a6150a8f9..1a7a68cffb625907265af30c2f107a5c9ec3f703 100644 (file)
@@ -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/test/ARCMT/remap-applying.c b/test/ARCMT/remap-applying.c
new file mode 100644 (file)
index 0000000..b6280bf
--- /dev/null
@@ -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/test/ARCMT/remap-applying.c.result b/test/ARCMT/remap-applying.c.result
new file mode 100644 (file)
index 0000000..975dc9e
--- /dev/null
@@ -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