aboutsummaryrefslogtreecommitdiff
path: root/lib/Frontend/RewriteObjC.cpp
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2009-12-23 17:24:33 +0000
committerSteve Naroff <snaroff@apple.com>2009-12-23 17:24:33 +0000
commitc5143c538783a2834cfdc3d29db0ff76e857818f (patch)
treed231169016df318e3f55595ef964c05d8b1687f8 /lib/Frontend/RewriteObjC.cpp
parent60fd3db910aaae0885a01d39ac5814e8eae2efc6 (diff)
Add support for handling initializers in RewriteObjC::RewriteByRefVar().
As the FIXME indicates, RewriteByRefVar() won't work for multiple declarators (in general). I've discussed this with Fariborz and he is aware of the limitation. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92007 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/RewriteObjC.cpp')
-rw-r--r--lib/Frontend/RewriteObjC.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/Frontend/RewriteObjC.cpp b/lib/Frontend/RewriteObjC.cpp
index 70eb999c58..656d61b133 100644
--- a/lib/Frontend/RewriteObjC.cpp
+++ b/lib/Frontend/RewriteObjC.cpp
@@ -4392,11 +4392,22 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) {
ByrefType += "0, ";
ByrefType += "sizeof(struct __Block_byref_" + Name + "), ";
InsertText(startLoc, ByrefType.c_str(), ByrefType.size());
-#if 0
- ByrefType = "};\n";
- SourceLocation endLoc = ND->getInit()->getLocEnd();
- InsertText(startLoc, ByrefType.c_str(), ByrefType.size());
-#endif
+
+ // Complete the newly synthesized compound expression by inserting a right
+ // curly brace before the end of the declaration.
+ // FIXME: This approach avoids rewriting the initializer expression. It
+ // also assumes there is only one declarator. For example, the following
+ // isn't currently supported by this routine (in general):
+ //
+ // double __block BYREFVAR = 1.34, BYREFVAR2 = 1.37;
+ //
+ const char *startBuf = SM->getCharacterData(startLoc);
+ const char *semiBuf = strchr(startBuf, ';');
+ assert((*semiBuf == ';') && "RewriteByRefVar: can't find ';'");
+ SourceLocation semiLoc =
+ startLoc.getFileLocWithOffset(semiBuf-startBuf);
+
+ InsertText(semiLoc, "}", 1);
}
return;
}