]> granicus.if.org Git - clang/commitdiff
Keep track when a ObjC interface/protocol was initially created as a forward reference.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 17 Oct 2011 19:48:06 +0000 (19:48 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 17 Oct 2011 19:48:06 +0000 (19:48 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142230 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclObjC.h
lib/AST/ASTImporter.cpp
lib/AST/DeclObjC.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriterDecl.cpp

index 425c89d290a6c02f22973c6cf76c2bc0f7470d5f..136acf377f96aa97f4bd53be1093d5dffda74dae 100644 (file)
@@ -566,6 +566,11 @@ class ObjCInterfaceDecl : public ObjCContainerDecl {
   /// extensions and implementation. This list is built lazily.
   ObjCIvarDecl *IvarList;
 
+  /// \brief True if it was initially declared with @class.
+  /// Differs with \see ForwardDecl in that \see ForwardDecl will change to
+  /// false when we see the @interface, but InitiallyForwardDecl will remain
+  /// true.
+  bool InitiallyForwardDecl : 1;
   bool ForwardDecl:1; // declared with @class.
   bool InternalInterface:1; // true - no @interface for @implementation
   
@@ -693,6 +698,11 @@ public:
                                        unsigned Num,
                                        ASTContext &C);
 
+  /// \brief True if it was initially declared with @class.
+  /// Differs with \see isForwardDecl in that \see isForwardDecl will change to
+  /// false when we see the @interface, but this will remain true.
+  bool isInitiallyForwardDecl() const { return InitiallyForwardDecl; }
+
   bool isForwardDecl() const { return ForwardDecl; }
   void setForwardDecl(bool val) { ForwardDecl = val; }
 
@@ -924,21 +934,25 @@ class ObjCProtocolDecl : public ObjCContainerDecl {
   /// Referenced protocols
   ObjCProtocolList ReferencedProtocols;
 
-  bool isForwardProtoDecl; // declared with @protocol.
+  bool InitiallyForwardDecl : 1;
+  bool isForwardProtoDecl : 1; // declared with @protocol.
 
   SourceLocation EndLoc; // marks the '>' or identifier.
 
   ObjCProtocolDecl(DeclContext *DC, IdentifierInfo *Id,
-                   SourceLocation nameLoc, SourceLocation atStartLoc)
+                   SourceLocation nameLoc, SourceLocation atStartLoc,
+                   bool isForwardDecl)
     : ObjCContainerDecl(ObjCProtocol, DC, Id, nameLoc, atStartLoc),
-      isForwardProtoDecl(true) {
+      InitiallyForwardDecl(isForwardDecl),
+      isForwardProtoDecl(isForwardDecl) {
   }
 
 public:
   static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
                                   IdentifierInfo *Id,
                                   SourceLocation nameLoc,
-                                  SourceLocation atStartLoc);
+                                  SourceLocation atStartLoc,
+                                  bool isForwardDecl);
 
   const ObjCProtocolList &getReferencedProtocols() const {
     return ReferencedProtocols;
@@ -973,6 +987,11 @@ public:
   ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
     return lookupMethod(Sel, false/*isInstance*/);
   }
+
+  /// \brief True if it was initially a forward reference.
+  /// Differs with \see isForwardDecl in that \see isForwardDecl will change to
+  /// false when we see the definition, but this will remain true.
+  bool isInitiallyForwardDecl() const { return InitiallyForwardDecl; }
   
   bool isForwardDecl() const { return isForwardProtoDecl; }
   void setForwardDecl(bool val) { isForwardProtoDecl = val; }
@@ -985,6 +1004,9 @@ public:
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const ObjCProtocolDecl *D) { return true; }
   static bool classofKind(Kind K) { return K == ObjCProtocol; }
+
+  friend class ASTDeclReader;
+  friend class ASTDeclWriter;
 };
 
 /// ObjCClassDecl - Specifies a list of forward class declarations. For example:
index ae2b8903f24e00437d87d759830c6149d9b1e2bd..7e252d1d163e310a61dce50ec9851169418fa51a 100644 (file)
@@ -3110,7 +3110,8 @@ Decl *ASTNodeImporter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
     if (!ToProto) {
       ToProto = ObjCProtocolDecl::Create(Importer.getToContext(), DC,
                                          Name.getAsIdentifierInfo(), Loc,
-                                         Importer.Import(D->getAtStartLoc()));
+                                         Importer.Import(D->getAtStartLoc()),
+                                         D->isInitiallyForwardDecl());
       ToProto->setForwardDecl(D->isForwardDecl());
       ToProto->setLexicalDeclContext(LexicalDC);
       LexicalDC->addDecl(ToProto);
index a589b7f9d3e95dc798064db8b2494a8f1768b826..5af3cf599061f84ccd14c05f18ae3e756b20afd0 100644 (file)
@@ -623,8 +623,9 @@ ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
                   SourceLocation CLoc, bool FD, bool isInternal)
   : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, atLoc),
     TypeForDecl(0), SuperClass(0),
-    CategoryList(0), IvarList(0), 
-    ForwardDecl(FD), InternalInterface(isInternal), ExternallyCompleted(false) {
+    CategoryList(0), IvarList(0),
+    InitiallyForwardDecl(FD), ForwardDecl(FD),
+    InternalInterface(isInternal), ExternallyCompleted(false) {
 }
 
 void ObjCInterfaceDecl::LoadExternalDefinition() const {
@@ -866,8 +867,9 @@ ObjCAtDefsFieldDecl
 ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
                                            IdentifierInfo *Id,
                                            SourceLocation nameLoc,
-                                           SourceLocation atStartLoc) {
-  return new (C) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc);
+                                           SourceLocation atStartLoc,
+                                           bool isForwardDecl) {
+  return new (C) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc, isForwardDecl);
 }
 
 ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
index 62b4a7c0cc7730a7cf3b4581b2d1f7f5359fa6c5..1de17d2131816ac4c70c4bb6070689aa3e5132f7 100644 (file)
@@ -597,7 +597,8 @@ Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc,
     PDecl->setChangedSinceDeserialization(true);
   } else {
     PDecl = ObjCProtocolDecl::Create(Context, CurContext, ProtocolName,
-                                     ProtocolLoc, AtProtoInterfaceLoc);
+                                     ProtocolLoc, AtProtoInterfaceLoc,
+                                     /*isForwardDecl=*/false);
     PushOnScopeChains(PDecl, TUScope);
     PDecl->setForwardDecl(false);
   }
@@ -698,7 +699,8 @@ Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
     bool isNew = false;
     if (PDecl == 0) { // Not already seen?
       PDecl = ObjCProtocolDecl::Create(Context, CurContext, Ident,
-                                       IdentList[i].second, AtProtocolLoc);
+                                       IdentList[i].second, AtProtocolLoc,
+                                       /*isForwardDecl=*/true);
       PushOnScopeChains(PDecl, TUScope, false);
       isNew = true;
     }
index 6cc3f0a70bc198e0789f134c3fef0f25e3088188..a15dc424e793096710c0eb97a702566746a1adfa 100644 (file)
@@ -554,6 +554,7 @@ void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
   
   // We will rebuild this list lazily.
   ID->setIvarList(0);
+  ID->InitiallyForwardDecl = Record[Idx++];
   ID->setForwardDecl(Record[Idx++]);
   ID->setImplicitInterfaceDecl(Record[Idx++]);
   ID->setSuperClassLoc(ReadSourceLocation(Record, Idx));
@@ -571,6 +572,7 @@ void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
 
 void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
   VisitObjCContainerDecl(PD);
+  PD->InitiallyForwardDecl = Record[Idx++];
   PD->setForwardDecl(Record[Idx++]);
   PD->setLocEnd(ReadSourceLocation(Record, Idx));
   unsigned NumProtoRefs = Record[Idx++];
@@ -1637,7 +1639,7 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) {
     break;
   case DECL_OBJC_PROTOCOL:
     D = ObjCProtocolDecl::Create(Context, 0, 0, SourceLocation(),
-                                 SourceLocation());
+                                 SourceLocation(), 0);
     break;
   case DECL_OBJC_AT_DEFS_FIELD:
     D = ObjCAtDefsFieldDecl::Create(Context, 0, SourceLocation(),
index a8243e502e30865b2f12d7bdd1282d0363b5d04a..2925f49292e7e1eac6e32d111794d1800e5b7153 100644 (file)
@@ -470,6 +470,7 @@ void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
                                      IEnd = D->ivar_end(); I != IEnd; ++I)
     Writer.AddDeclRef(*I, Record);
   Writer.AddDeclRef(D->getCategoryList(), Record);
+  Record.push_back(D->isInitiallyForwardDecl());
   Record.push_back(D->isForwardDecl());
   Record.push_back(D->isImplicitInterfaceDecl());
   Writer.AddSourceLocation(D->getSuperClassLoc(), Record);
@@ -499,6 +500,7 @@ void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
 
 void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
   VisitObjCContainerDecl(D);
+  Record.push_back(D->isInitiallyForwardDecl());
   Record.push_back(D->isForwardDecl());
   Writer.AddSourceLocation(D->getLocEnd(), Record);
   Record.push_back(D->protocol_size());