[cfe-commits] r137431 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/Serialization/ASTBitCodes.h lib/AST/ASTContext.cpp lib/Sema/Sema.cpp lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp

Douglas Gregor dgregor at apple.com
Thu Aug 11 22:59:41 PDT 2011


Author: dgregor
Date: Fri Aug 12 00:59:41 2011
New Revision: 137431

URL: http://llvm.org/viewvc/llvm-project?rev=137431&view=rev
Log:
Switch the Objective-C 'Class' type over to a predefined type in the
AST file format, lazily generating the actual declaration in
ASTContext as needed.

Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/include/clang/Serialization/ASTBitCodes.h
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=137431&r1=137430&r2=137431&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Aug 12 00:59:41 2011
@@ -192,9 +192,9 @@
   QualType ObjCProtoType;
   const RecordType *ProtoStructType;
 
-  /// ObjCClassType - another pseudo built-in typedef type (set by Sema).
-  QualType ObjCClassTypedefType;
-
+  /// \brief The typedef for the predefined 'Class' type.
+  mutable TypedefDecl *ObjCClassDecl;
+  
   // Typedefs which may be provided defining the structure of Objective-C
   // pseudo-builtins
   QualType ObjCIdRedefinitionType;
@@ -968,11 +968,16 @@
   void setObjCProtoType(QualType QT);
   QualType getObjCProtoType() const { return ObjCProtoType; }
 
+  /// \brief Retrieve the typedef declaration corresponding to the predefined
+  /// Objective-C 'Class' type.
+  TypedefDecl *getObjCClassDecl() const;
+  
   /// This setter/getter repreents the ObjC 'Class' type. It is setup lazily, by
   /// Sema.  'Class' is always a (typedef for a) pointer type, a pointer to a
   /// struct.
-  QualType getObjCClassType() const { return ObjCClassTypedefType; }
-  void setObjCClassType(QualType T);
+  QualType getObjCClassType() const { 
+    return getTypeDeclType(getObjCClassDecl());
+  }
 
   void setBuiltinVaListType(QualType T);
   QualType getBuiltinVaListType() const { return BuiltinVaListType; }
@@ -1423,7 +1428,7 @@
     return T == getObjCIdType();
   }
   bool isObjCClassType(QualType T) const {
-    return T == ObjCClassTypedefType;
+    return T == getObjCClassType();
   }
   bool isObjCSelType(QualType T) const {
     return T == ObjCSelTypedefType;

Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=137431&r1=137430&r2=137431&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Fri Aug 12 00:59:41 2011
@@ -644,24 +644,22 @@
       SPECIAL_TYPE_OBJC_SELECTOR               = 1,
       /// \brief Objective-C Protocol type
       SPECIAL_TYPE_OBJC_PROTOCOL               = 2,
-      /// \brief Objective-C Class type
-      SPECIAL_TYPE_OBJC_CLASS                  = 3,
       /// \brief CFConstantString type
-      SPECIAL_TYPE_CF_CONSTANT_STRING          = 4,
+      SPECIAL_TYPE_CF_CONSTANT_STRING          = 3,
       /// \brief C FILE typedef type
-      SPECIAL_TYPE_FILE                        = 5,
+      SPECIAL_TYPE_FILE                        = 4,
       /// \brief C jmp_buf typedef type
-      SPECIAL_TYPE_jmp_buf                     = 6,
+      SPECIAL_TYPE_jmp_buf                     = 5,
       /// \brief C sigjmp_buf typedef type
-      SPECIAL_TYPE_sigjmp_buf                  = 7,
+      SPECIAL_TYPE_sigjmp_buf                  = 6,
       /// \brief Objective-C "id" redefinition type
-      SPECIAL_TYPE_OBJC_ID_REDEFINITION        = 8,
+      SPECIAL_TYPE_OBJC_ID_REDEFINITION        = 7,
       /// \brief Objective-C "Class" redefinition type
-      SPECIAL_TYPE_OBJC_CLASS_REDEFINITION     = 9,
+      SPECIAL_TYPE_OBJC_CLASS_REDEFINITION     = 8,
       /// \brief Objective-C "SEL" redefinition type
-      SPECIAL_TYPE_OBJC_SEL_REDEFINITION       = 10,
+      SPECIAL_TYPE_OBJC_SEL_REDEFINITION       = 9,
       /// \brief Whether __[u]int128_t identifier is installed.
-      SPECIAL_TYPE_INT128_INSTALLED            = 11
+      SPECIAL_TYPE_INT128_INSTALLED            = 10
     };
 
     /// \brief Predefined declaration IDs.
@@ -678,14 +676,17 @@
       PREDEF_DECL_TRANSLATION_UNIT_ID = 1,
       
       /// \brief The Objective-C 'id' type.
-      PREDEF_DECL_OBJC_ID_ID = 2
+      PREDEF_DECL_OBJC_ID_ID = 2,
+      
+      /// \brief The Objective-C 'Class' type.
+      PREDEF_DECL_OBJC_CLASS_ID = 3
     };
 
     /// \brief The number of declaration IDs that are predefined.
     ///
     /// For more information about predefined declarations, see the
     /// \c PredefinedDeclIDs type and the PREDEF_DECL_*_ID constants.
-    const unsigned int NUM_PREDEF_DECL_IDS = 3;
+    const unsigned int NUM_PREDEF_DECL_IDS = 4;
     
     /// \brief Record codes for each kind of declaration.
     ///

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=137431&r1=137430&r2=137431&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Fri Aug 12 00:59:41 2011
@@ -222,7 +222,8 @@
   DependentTemplateSpecializationTypes(this_()),
   SubstTemplateTemplateParmPacks(this_()),
   GlobalNestedNameSpecifier(0), IsInt128Installed(false),
-  ObjCIdDecl(0), CFConstantStringTypeDecl(0),
+  ObjCIdDecl(0), ObjCClassDecl(0),
+  CFConstantStringTypeDecl(0),
   FILEDecl(0), 
   jmp_bufDecl(0), sigjmp_bufDecl(0), BlockDescriptorType(0), 
   BlockDescriptorExtendedType(0), cudaConfigureCallDecl(0),
@@ -430,7 +431,6 @@
   BuiltinVaListType = QualType();
 
   // "Builtin" typedefs set by Sema::ActOnTranslationUnitScope().
-  ObjCClassTypedefType = QualType();
   ObjCSelTypedefType = QualType();
 
   // Builtin types for 'id', 'Class', and 'SEL'.
@@ -4640,8 +4640,18 @@
   ObjCProtoType = QT;
 }
 
-void ASTContext::setObjCClassType(QualType T) {
-  ObjCClassTypedefType = T;
+TypedefDecl *ASTContext::getObjCClassDecl() const {
+  if (!ObjCClassDecl) {
+    QualType T = getObjCObjectType(ObjCBuiltinClassTy, 0, 0);
+    T = getObjCObjectPointerType(T);
+    TypeSourceInfo *ClassInfo = getTrivialTypeSourceInfo(T);
+    ObjCClassDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this),
+                                        getTranslationUnitDecl(),
+                                        SourceLocation(), SourceLocation(),
+                                        &Idents.get("Class"), ClassInfo);
+  }
+  
+  return ObjCClassDecl;
 }
 
 void ASTContext::setObjCConstantStringInterface(ObjCInterfaceDecl *Decl) {

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=137431&r1=137430&r2=137431&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Fri Aug 12 00:59:41 2011
@@ -105,19 +105,6 @@
                                 SourceLocation(), true);
     Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl));
     PushOnScopeChains(ProtocolDecl, TUScope, false);
-  }
-  
-  // Create the built-in typedef for 'Class'.
-  if (Context.getObjCClassType().isNull()) {
-    QualType T = Context.getObjCObjectType(Context.ObjCBuiltinClassTy, 0, 0);
-    T = Context.getObjCObjectPointerType(T);
-    TypeSourceInfo *ClassInfo = Context.getTrivialTypeSourceInfo(T);
-    TypedefDecl *ClassTypedef
-      = TypedefDecl::Create(Context, CurContext,
-                            SourceLocation(), SourceLocation(),
-                            &Context.Idents.get("Class"), ClassInfo);
-    PushOnScopeChains(ClassTypedef, TUScope);
-    Context.setObjCClassType(Context.getTypeDeclType(ClassTypedef));
   }  
 }
 
@@ -175,6 +162,11 @@
     DeclarationName Id = &Context.Idents.get("id");
     if (IdentifierResolver::begin(Id) == IdentifierResolver::end())
       PushOnScopeChains(Context.getObjCIdDecl(), TUScope);
+    
+    // Create the built-in typedef for 'Class'.
+    DeclarationName Class = &Context.Idents.get("Class");
+    if (IdentifierResolver::begin(Class) == IdentifierResolver::end())
+      PushOnScopeChains(Context.getObjCClassDecl(), TUScope);
   }
 }
 

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=137431&r1=137430&r2=137431&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Aug 12 00:59:41 2011
@@ -2997,11 +2997,6 @@
       Context->ObjCProtoType = GetType(Proto);
   }
   
-  if (unsigned Class = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS]) {
-    if (Context->ObjCClassTypedefType.isNull()) 
-      Context->ObjCClassTypedefType = GetType(Class);
-  }
-
   if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) {
     if (!Context->CFConstantStringTypeDecl)
       Context->setCFConstantStringType(GetType(String));
@@ -4224,6 +4219,10 @@
     case PREDEF_DECL_OBJC_ID_ID:
       assert(Context && "No context available?");
       return Context->getObjCIdDecl();
+
+    case PREDEF_DECL_OBJC_CLASS_ID:
+      assert(Context && "No context available?");
+      return Context->getObjCClassDecl();
     }
     
     return 0;

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=137431&r1=137430&r2=137431&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Aug 12 00:59:41 2011
@@ -2810,7 +2810,9 @@
   DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID;
   if (Context.ObjCIdDecl)
     DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_ID;
-          
+  if (Context.ObjCClassDecl)
+    DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID;
+  
   if (!Chain) {
     // Make sure that we emit IdentifierInfos (and any attached
     // declarations) for builtins. We don't need to do this when we're
@@ -3019,7 +3021,6 @@
   AddTypeRef(Context.getBuiltinVaListType(), SpecialTypes);
   AddTypeRef(Context.ObjCSelTypedefType, SpecialTypes);
   AddTypeRef(Context.ObjCProtoType, SpecialTypes);
-  AddTypeRef(Context.ObjCClassTypedefType, SpecialTypes);
   AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes);
   AddTypeRef(Context.getFILEType(), SpecialTypes);
   AddTypeRef(Context.getjmp_bufType(), SpecialTypes);





More information about the cfe-commits mailing list