[cfe-commits] r146669 - in /cfe/trunk: include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Serialization/ASTReaderDecl.cpp

Douglas Gregor dgregor at apple.com
Thu Dec 15 10:17:27 PST 2011


Author: dgregor
Date: Thu Dec 15 12:17:27 2011
New Revision: 146669

URL: http://llvm.org/viewvc/llvm-project?rev=146669&view=rev
Log:
Extend ObjCInterfaceDecl::DefinitionData to contain a pointer to the
definition, and implement ObjCInterfaceDecl::getDefinition()
efficiently based on that.

Modified:
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=146669&r1=146668&r2=146669&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Thu Dec 15 12:17:27 2011
@@ -548,6 +548,10 @@
   friend class ASTContext;
   
   struct DefinitionData {
+    /// \brief The definition of this class, for quick access from any 
+    /// declaration.
+    ObjCInterfaceDecl *Definition;
+    
     /// Class's super class.
     ObjCInterfaceDecl *SuperClass;
 
@@ -574,7 +578,7 @@
 
     SourceLocation SuperClassLoc; // location of the super class identifier.
     
-    DefinitionData() : SuperClass(), CategoryList(), IvarList(), 
+    DefinitionData() : Definition(), SuperClass(), CategoryList(), IvarList(), 
                        ExternallyCompleted() { }
   };
 
@@ -585,10 +589,7 @@
 
   /// \brief Contains a pointer to the data associated with this class,
   /// which will be NULL if this class has not yet been defined.
-  ///
-  /// The boolean value indicates whether this particular declaration is 
-  /// also the definition.
-  llvm::PointerIntPair<DefinitionData *, 1, bool> Definition;
+  DefinitionData *Data;
 
   /// \brief The location of the last location in this declaration, e.g.,
   /// the '>', '}', or identifier.
@@ -602,8 +603,8 @@
   bool InitiallyForwardDecl : 1;
 
   DefinitionData &data() const {
-    assert(Definition.getPointer() != 0 && "Declaration is not a definition!");
-    return *Definition.getPointer();
+    assert(Data != 0 && "Declaration has no definition!");
+    return *Data;
   }
 
   /// \brief Allocate the definition data for this class.
@@ -778,29 +779,30 @@
     return InitiallyForwardDecl; 
   }
 
-  /// \brief Determine whether this declaration is a forward declaration of
-  /// the class.
-  bool isForwardDecl() const { return !Definition.getInt(); }
-
+  /// \brief Determine whether this class has only ever been forward-declared.
+  bool isForwardDecl() const { return Data == 0; }
+                          
   /// \brief Determine whether this particular declaration of this class is
   /// actually also a definition.
-  bool isThisDeclarationADefinition() const { return Definition.getInt(); }
+  bool isThisDeclarationADefinition() const { 
+    return Data == 0 || Data->Definition != this;
+  }
                           
   /// \brief Determine whether this class has been defined.
-  bool hasDefinition() const { return Definition.getPointer() != 0; }
+  bool hasDefinition() const { return Data; }
                         
   /// \brief Retrieve the definition of this class, or NULL if this class 
   /// has been forward-declared (with @class) but not yet defined (with 
   /// @interface).
   ObjCInterfaceDecl *getDefinition() {
-    return hasDefinition()? this : 0;
+    return hasDefinition()? Data->Definition : 0;
   }
 
   /// \brief Retrieve the definition of this class, or NULL if this class 
   /// has been forward-declared (with @class) but not yet defined (with 
   /// @interface).
   const ObjCInterfaceDecl *getDefinition() const {
-    return hasDefinition()? this : 0;
+    return hasDefinition()? Data->Definition : 0;
   }
 
   /// \brief Starts the definition of this Objective-C class, taking it from

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=146669&r1=146668&r2=146669&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Thu Dec 15 12:17:27 2011
@@ -224,14 +224,14 @@
 
 void ObjCInterfaceDecl::allocateDefinitionData() {
   assert(!hasDefinition() && "ObjC class already has a definition");
-  Definition.setPointer(new (getASTContext()) DefinitionData());
-  Definition.setInt(true);
+  Data = new (getASTContext()) DefinitionData();
+  Data->Definition = this;
   
   // Update all of the declarations with a pointer to the definition.
   for (redecl_iterator RD = redecls_begin(), RDEnd = redecls_end();
        RD != RDEnd; ++RD) {
     if (*RD != this)
-      RD->Definition.setPointer(Definition.getPointer());
+      RD->Data = Data;
   }
 }
 
@@ -684,7 +684,7 @@
 ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
                   SourceLocation CLoc, bool FD, bool isInternal)
   : ObjCContainerDecl(ObjCInterface, DC, Id, CLoc, atLoc),
-    TypeForDecl(0), Definition(), InitiallyForwardDecl(FD) 
+    TypeForDecl(0), Data(), InitiallyForwardDecl(FD) 
 {
   setImplicit(isInternal);
 }

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=146669&r1=146668&r2=146669&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Thu Dec 15 12:17:27 2011
@@ -613,15 +613,15 @@
       for (ASTReader::ForwardRefs::iterator I = Refs.begin(), 
                                             E = Refs.end(); 
            I != E; ++I)
-        cast<ObjCInterfaceDecl>(*I)->Definition = ID->Definition;
+        cast<ObjCInterfaceDecl>(*I)->Data = ID->Data;
 #ifndef NDEBUG
       // We later check whether PendingForwardRefs is empty to make sure all
       // pending references were linked.
       Reader.PendingForwardRefs.erase(ID);
 #endif
     } else if (Def) {
-      if (Def->Definition.getPointer()) {
-        ID->Definition.setPointer(Def->Definition.getPointer());
+      if (Def->Data) {
+        ID->Data = Def->Data;
       } else {
         // The definition is still initializing.
         Reader.PendingForwardRefs[Def].push_back(ID);
@@ -2072,8 +2072,8 @@
       ObjCInterfaceDecl *ID = cast<ObjCInterfaceDecl>(D);
       ObjCInterfaceDecl *Def
         = Reader.ReadDeclAs<ObjCInterfaceDecl>(ModuleFile, Record, Idx);
-      if (Def->Definition.getPointer()) {
-        ID->Definition.setPointer(Def->Definition.getPointer());
+      if (Def->Data) {
+        ID->Data = Def->Data;
       } else {
         // The definition is still initializing.
         Reader.PendingForwardRefs[Def].push_back(ID);





More information about the cfe-commits mailing list