[cfe-commits] r46644 - in /cfe/trunk: Driver/RewriteTest.cpp test/Rewriter/rewrite-try-catch.m
Steve Naroff
snaroff at apple.com
Fri Feb 1 14:09:39 PST 2008
On Feb 1, 2008, at 12:31 PM, Fariborz Jahanian wrote:
> Later on we want to preserve "..." in the AST and check for it in
> the rewriter/ast-print etc. This is instead of assuming null
> catchStmt to mean "..."
>
"..." is preserved (i.e. the code isn't making an assumption). The API
is just a little indirect.
I just committed a change (r46649) that will likely address your
concern.
Thanks,
snaroff
> - Fariborz
>
> On Feb 1, 2008, at 12:02 PM, Steve Naroff wrote:
>
>> Author: snaroff
>> Date: Fri Feb 1 14:02:07 2008
>> New Revision: 46644
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=46644&view=rev
>> Log:
>>
>> Fix two rewriter bugs with @catch.
>>
>> - Support @catch(...), rather than crash:-)
>> - Make sure all catch bodies get rewritten. This "fix" is really a
>> workaround until the iterator for the "try" AST is fixed. Will fix
>> this in a separate commit.
>>
>>
>> Modified:
>> cfe/trunk/Driver/RewriteTest.cpp
>> cfe/trunk/test/Rewriter/rewrite-try-catch.m
>>
>> Modified: cfe/trunk/Driver/RewriteTest.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=46644&r1=46643&r2=46644&view=diff
>>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> --- cfe/trunk/Driver/RewriteTest.cpp (original)
>> +++ cfe/trunk/Driver/RewriteTest.cpp Fri Feb 1 14:02:07 2008
>> @@ -1203,7 +1203,20 @@
>>
>> const char *lParenLoc = strchr(startBuf, '(');
>>
>> - if (DeclStmt *declStmt = dyn_cast<DeclStmt>(catchStmt)) {
>> + if (!catchStmt) { // handle "..."
>> + // Now rewrite the body...
>> + lastCatchBody = catchList->getCatchBody();
>> + SourceLocation rParenLoc = catchList->getRParenLoc();
>> + SourceLocation bodyLoc = lastCatchBody->getLocStart();
>> + const char *bodyBuf = SM->getCharacterData(bodyLoc);
>> + const char *rParenBuf = SM->getCharacterData(rParenLoc);
>> + assert((*rParenBuf == ')') && "bogus @catch paren location");
>> + assert((*bodyBuf == '{') && "bogus @catch body location");
>> +
>> + buf += "1) { id _tmp = _caught;";
>> + Rewrite.ReplaceText(startLoc, bodyBuf-startBuf+1,
>> + buf.c_str(), buf.size());
>> + } else if (DeclStmt *declStmt = dyn_cast<DeclStmt>(catchStmt)) {
>> QualType t = dyn_cast<ValueDecl>(declStmt->getDecl())-
>> >getType();
>> if (t == Context->getObjCIdType()) {
>> buf += "1) { ";
>> @@ -1236,6 +1249,10 @@
>> } else if (!isa<NullStmt>(catchStmt)) {
>> assert(false && "@catch rewrite bug");
>> }
>> + // make sure all the catch bodies get rewritten!
>> + // FIXME: this call should be removed when the iterator for
>> ObjCAtTryStmt
>> + // is fixed. Currently, it only returns the first catch
>> statement!
>> + RewriteFunctionBodyOrGlobalInitializer(lastCatchBody);
>> catchList = catchList->getNextCatchStmt();
>> }
>> // Complete the catch list...
>>
>> Modified: cfe/trunk/test/Rewriter/rewrite-try-catch.m
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-try-catch.m?rev=46644&r1=46643&r2=46644&view=diff
>>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> --- cfe/trunk/test/Rewriter/rewrite-try-catch.m (original)
>> +++ cfe/trunk/test/Rewriter/rewrite-try-catch.m Fri Feb 1 14:02:07
>> 2008
>> @@ -1,8 +1,13 @@
>> // RUN: clang -rewrite-test %s | clang
>>
>> - at interface foo @end
>> + at interface Foo @end
>> @interface GARF @end
>>
>> +void foo() {
>> + @try { TRY(); }
>> + @catch (...) { SPLATCH(); @throw; }
>> +}
>> +
>> int main()
>> {
>>
>> @@ -10,7 +15,7 @@
>> MYTRY();
>> }
>>
>> - at catch (foo* localException) {
>> + at catch (Foo* localException) {
>> MYCATCH();
>> @throw;
>> }
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
More information about the cfe-commits
mailing list