]> granicus.if.org Git - clang/commitdiff
Add rewriter support for @encode expressions. For example,
authorChris Lattner <sabre@nondot.org>
Wed, 17 Oct 2007 21:28:00 +0000 (21:28 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 17 Oct 2007 21:28:00 +0000 (21:28 +0000)
we currently turn:

    c = @encode(char *)[2] + 4;

into:

    c = "foo"[2] + 4;

Right now the foo string is hard coded, but you can imagine a world
where it wouldn't be :)

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43093 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/RewriteTest.cpp

index 8a6d1df1b4e7da4d8a29048d3cf2ea839d67acc9..6972f35853f4e42dca79d9e6458f34e2922313e8 100644 (file)
@@ -104,18 +104,18 @@ void RewriteTest::RewriteFunctionBody(Stmt *S) {
   // Otherwise, just rewrite all children.
   for (Stmt::child_iterator CI = S->child_begin(), E = S->child_end();
        CI != E; ++CI)
-    RewriteFunctionBody(*CI);
+    if (*CI)
+      RewriteFunctionBody(*CI);
 }
 
 void RewriteTest::RewriteAtEncode(ObjCEncodeExpr *Exp) {
-#if 0
   int Size = Rewrite.getRangeSize(Exp->getSourceRange());
   if (Size == -1) {
     printf("BLAH!");
+    return;
   }
   
-  Rewrite.RemoveText(Exp->getAtLoc(), Size);
-#endif
+  Rewrite.ReplaceText(Exp->getAtLoc(), Size, "\"foo\"", 5);
 }