From: Steve Naroff Date: Wed, 31 Oct 2007 22:11:35 +0000 (+0000) Subject: Fix two rewriter bugs: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8749be53f53384e7846502791ceda6c657228d07;p=clang Fix two rewriter bugs: - For @class, don't generate multiple typedefs. - Handle the following edge case interface... @interface NSMiddleSpecifier : NSObject {} @end ...which was incorrectly being rewritten to... struct _interface_NSMiddleSpecifier { struct _interface_NSObject _NSObject; }; {} git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43582 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index d3bbb1b48a..55fb4d7565 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -33,6 +33,7 @@ namespace { llvm::SmallVector ClassImplementation; llvm::SmallVector CategoryImplementation; llvm::SmallPtrSet ObjcSynthesizedStructs; + llvm::SmallPtrSet ObjcForwardDecls; FunctionDecl *MsgSendFunctionDecl; FunctionDecl *GetClassFunctionDecl; @@ -260,11 +261,17 @@ void RewriteTest::RewriteForwardClassDecl(ObjcClassDecl *ClassDecl) { typedefString += "\n"; for (int i = 0; i < numDecls; i++) { ObjcInterfaceDecl *ForwardDecl = ForwardDecls[i]; + if (ObjcForwardDecls.count(ForwardDecl)) + continue; typedefString += "typedef struct "; typedefString += ForwardDecl->getName(); typedefString += " "; typedefString += ForwardDecl->getName(); typedefString += ";\n"; + + // Mark this typedef as having been generated. + if (!ObjcForwardDecls.insert(ForwardDecl)) + assert(true && "typedef already output"); } // Replace the @class with typedefs corresponding to the classes. @@ -437,7 +444,6 @@ void RewriteTest::RewriteFunctionDecl(FunctionDecl *FD) { SelGetUidFunctionDecl = FD; return; } - return; // FIXME: remove when the code below is ready. // Check for ObjC 'id' and class types that have been adorned with protocol // information (id

, C

*). The protocol references need to be rewritten! const FunctionType *funcType = FD->getType()->getAsFunctionType(); @@ -560,6 +566,7 @@ void RewriteTest::SynthesizeObjcInternalStruct(ObjcInterfaceDecl *CDecl, } else Result += " {"; + if (NumIvars > 0) { SourceLocation LocStart = CDecl->getLocStart(); SourceLocation LocEnd = CDecl->getLocEnd(); @@ -595,7 +602,7 @@ void RewriteTest::SynthesizeObjcInternalStruct(ObjcInterfaceDecl *CDecl, Result += "};\n"; // Mark this struct as having been generated. if (!ObjcSynthesizedStructs.insert(CDecl)) - assert(true && "struct already synthesize- SynthesizeObjcInternalStruct"); + assert(true && "struct already synthesize- SynthesizeObjcInternalStruct"); } // RewriteObjcMethodsMetaData - Rewrite methods metadata for instance or diff --git a/Parse/ParseObjc.cpp b/Parse/ParseObjc.cpp index 579c48cf45..301b04148a 100644 --- a/Parse/ParseObjc.cpp +++ b/Parse/ParseObjc.cpp @@ -740,11 +740,11 @@ void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl, } } SourceLocation RBraceLoc = MatchRHSPunctuation(tok::r_brace, LBraceLoc); - if (AllIvarDecls.size()) { // Check for {} - no ivars in braces - Actions.ActOnFields(CurScope, atLoc, interfaceDecl, - &AllIvarDecls[0], AllIvarDecls.size(), - LBraceLoc, RBraceLoc, &AllVisibilities[0]); - } + // Call ActOnFields() even if we don't have any decls. This is useful + // for code rewriting tools that need to be aware of the empty list. + Actions.ActOnFields(CurScope, atLoc, interfaceDecl, + &AllIvarDecls[0], AllIvarDecls.size(), + LBraceLoc, RBraceLoc, &AllVisibilities[0]); return; }