[cfe-commits] r142230 - in /cfe/trunk: 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

Argyrios Kyrtzidis akyrtzi at gmail.com
Mon Oct 17 12:48:06 PDT 2011


Author: akirtzidis
Date: Mon Oct 17 14:48:06 2011
New Revision: 142230

URL: http://llvm.org/viewvc/llvm-project?rev=142230&view=rev
Log:
Keep track when a ObjC interface/protocol was initially created as a forward reference.

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/ASTImporter.cpp
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=142230&r1=142229&r2=142230&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Mon Oct 17 14:48:06 2011
@@ -566,6 +566,11 @@
   /// 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 @@
                                        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 @@
   /// 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 @@
   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 @@
   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:

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=142230&r1=142229&r2=142230&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Oct 17 14:48:06 2011
@@ -3110,7 +3110,8 @@
     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);

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=142230&r1=142229&r2=142230&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Mon Oct 17 14:48:06 2011
@@ -623,8 +623,9 @@
                   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 @@
 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) {

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=142230&r1=142229&r2=142230&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Oct 17 14:48:06 2011
@@ -597,7 +597,8 @@
     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 @@
     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;
     }

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=142230&r1=142229&r2=142230&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Mon Oct 17 14:48:06 2011
@@ -554,6 +554,7 @@
   
   // 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::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 @@
     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(),

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=142230&r1=142229&r2=142230&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Mon Oct 17 14:48:06 2011
@@ -470,6 +470,7 @@
                                      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::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());





More information about the cfe-commits mailing list