@@ -653,8 +653,9 @@ void RewriteObjC::HandleTopLevelSingleDecl(Decl *D) {
653
653
ConstantStringClassReference = FVD;
654
654
return ;
655
655
}
656
- } else if (ObjCInterfaceDecl *MD = dyn_cast<ObjCInterfaceDecl>(D)) {
657
- RewriteInterfaceDecl (MD);
656
+ } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
657
+ if (ID->isThisDeclarationADefinition ())
658
+ RewriteInterfaceDecl (ID);
658
659
} else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(D)) {
659
660
RewriteCategoryDecl (CD);
660
661
} else if (ObjCProtocolDecl *PD = dyn_cast<ObjCProtocolDecl>(D)) {
@@ -673,9 +674,18 @@ void RewriteObjC::HandleTopLevelSingleDecl(Decl *D) {
673
674
SourceLocation Loc = D->getLocation ();
674
675
while (DI != DIEnd &&
675
676
isa<ObjCClassDecl>(D) && D->getLocation () == Loc) {
677
+ ObjCClassDecl *Class = cast<ObjCClassDecl>(D);
676
678
DG.push_back (D);
677
679
++DI;
678
680
D = (*DI);
681
+
682
+ // Following the ObjCClassDecl, we should have the corresponding
683
+ // ObjCInterfaceDecl. Skip over it.
684
+ if (DI != DIEnd && isa<ObjCInterfaceDecl>(D) &&
685
+ Class->getForwardInterfaceDecl () == D) {
686
+ ++DI;
687
+ D = (*DI);
688
+ }
679
689
}
680
690
RewriteForwardClassDecl (DG);
681
691
continue ;
@@ -1179,7 +1189,7 @@ void RewriteObjC::RewriteImplementationDecl(Decl *OID) {
1179
1189
1180
1190
void RewriteObjC::RewriteInterfaceDecl (ObjCInterfaceDecl *ClassDecl) {
1181
1191
std::string ResultStr;
1182
- if (!ObjCForwardDecls.count (ClassDecl)) {
1192
+ if (!ObjCForwardDecls.count (ClassDecl-> getCanonicalDecl () )) {
1183
1193
// we haven't seen a forward decl - generate a typedef.
1184
1194
ResultStr = " #ifndef _REWRITER_typedef_" ;
1185
1195
ResultStr += ClassDecl->getNameAsString ();
@@ -1191,7 +1201,7 @@ void RewriteObjC::RewriteInterfaceDecl(ObjCInterfaceDecl *ClassDecl) {
1191
1201
ResultStr += ClassDecl->getNameAsString ();
1192
1202
ResultStr += " ;\n #endif\n " ;
1193
1203
// Mark this typedef as having been generated.
1194
- ObjCForwardDecls.insert (ClassDecl);
1204
+ ObjCForwardDecls.insert (ClassDecl-> getCanonicalDecl () );
1195
1205
}
1196
1206
RewriteObjCInternalStruct (ClassDecl, ResultStr);
1197
1207
@@ -3130,7 +3140,7 @@ void RewriteObjC::RewriteObjCInternalStruct(ObjCInterfaceDecl *CDecl,
3130
3140
3131
3141
// If no ivars and no root or if its root, directly or indirectly,
3132
3142
// have no ivars (thus not synthesized) then no need to synthesize this class.
3133
- if ((CDecl->isForwardDecl () || NumIvars == 0 ) &&
3143
+ if ((! CDecl->isThisDeclarationADefinition () || NumIvars == 0 ) &&
3134
3144
(!RCDecl || !ObjCSynthesizedStructs.count (RCDecl))) {
3135
3145
endBuf += Lexer::MeasureTokenLength (LocEnd, *SM, LangOpts);
3136
3146
ReplaceText (LocStart, endBuf-startBuf, Result);
@@ -5357,7 +5367,7 @@ void RewriteObjCFragileABI::RewriteObjCClassMetaData(ObjCImplementationDecl *IDe
5357
5367
5358
5368
// Explicitly declared @interface's are already synthesized.
5359
5369
if (CDecl->isImplicitInterfaceDecl ()) {
5360
- // FIXME: Implementation of a class with no @interface (legacy) doese not
5370
+ // FIXME: Implementation of a class with no @interface (legacy) does not
5361
5371
// produce correct synthesis as yet.
5362
5372
RewriteObjCInternalStruct (CDecl, Result);
5363
5373
}
0 commit comments