]> granicus.if.org Git - clang/commitdiff
Switch the Objective-C 'SEL' type over to a predefined type in the
authorDouglas Gregor <dgregor@apple.com>
Fri, 12 Aug 2011 06:17:30 +0000 (06:17 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 12 Aug 2011 06:17:30 +0000 (06:17 +0000)
AST file format, lazily generating the actual declaration in
ASTContext as needed.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137434 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 4d5ba677a683aae7e42234d246067b833e0bca07..2625f81eb757e4d7aa1600b6784ac8ead663d323 100644 (file)
@@ -185,10 +185,9 @@ class ASTContext : public llvm::RefCountedBase<ASTContext> {
   /// \brief The typedef for the predefined 'id' type.
   mutable TypedefDecl *ObjCIdDecl;
   
-  /// ObjCSelType - another pseudo built-in typedef type (set by Sema).
-  QualType ObjCSelTypedefType;
+  /// \brief The typedef for the predefined 'SEL' type.
+  mutable TypedefDecl *ObjCSelDecl;
 
-  /// ObjCProtoType - another pseudo built-in typedef type (set by Sema).
   QualType ObjCProtoType;
   const RecordType *ProtoStructType;
 
@@ -961,9 +960,16 @@ public:
   QualType getObjCIdType() const {
     return getTypeDeclType(getObjCIdDecl());
   }
+
+  /// \brief Retrieve the typedef corresponding to the predefined 'SEL' type
+  /// in Objective-C.
+  TypedefDecl *getObjCSelDecl() const;
   
-  void setObjCSelType(QualType T);
-  QualType getObjCSelType() const { return ObjCSelTypedefType; }
+  /// \brief Retrieve the type that corresponds to the predefined Objective-C
+  /// 'SEL' type.
+  QualType getObjCSelType() const { 
+    return getTypeDeclType(getObjCSelDecl());
+  }
 
   void setObjCProtoType(QualType QT);
   QualType getObjCProtoType() const { return ObjCProtoType; }
@@ -1431,7 +1437,7 @@ public:
     return T == getObjCClassType();
   }
   bool isObjCSelType(QualType T) const {
-    return T == ObjCSelTypedefType;
+    return T == getObjCSelType();
   }
   bool QualifiedIdConformsQualifiedId(QualType LHS, QualType RHS);
   bool ObjCQualifiedIdTypesAreCompatible(QualType LHS, QualType RHS,
index c4a7f86622f72dc5939777924dca24a2a29f9ef7..56a0f52920c20775573ced8525666b9b33852f70 100644 (file)
@@ -640,26 +640,24 @@ namespace clang {
     enum SpecialTypeIDs {
       /// \brief __builtin_va_list
       SPECIAL_TYPE_BUILTIN_VA_LIST             = 0,
-      /// \brief Objective-C selector type
-      SPECIAL_TYPE_OBJC_SELECTOR               = 1,
       /// \brief Objective-C Protocol type
-      SPECIAL_TYPE_OBJC_PROTOCOL               = 2,
+      SPECIAL_TYPE_OBJC_PROTOCOL               = 1,
       /// \brief CFConstantString type
-      SPECIAL_TYPE_CF_CONSTANT_STRING          = 3,
+      SPECIAL_TYPE_CF_CONSTANT_STRING          = 2,
       /// \brief C FILE typedef type
-      SPECIAL_TYPE_FILE                        = 4,
+      SPECIAL_TYPE_FILE                        = 3,
       /// \brief C jmp_buf typedef type
-      SPECIAL_TYPE_jmp_buf                     = 5,
+      SPECIAL_TYPE_jmp_buf                     = 4,
       /// \brief C sigjmp_buf typedef type
-      SPECIAL_TYPE_sigjmp_buf                  = 6,
+      SPECIAL_TYPE_sigjmp_buf                  = 5,
       /// \brief Objective-C "id" redefinition type
-      SPECIAL_TYPE_OBJC_ID_REDEFINITION        = 7,
+      SPECIAL_TYPE_OBJC_ID_REDEFINITION        = 6,
       /// \brief Objective-C "Class" redefinition type
-      SPECIAL_TYPE_OBJC_CLASS_REDEFINITION     = 8,
+      SPECIAL_TYPE_OBJC_CLASS_REDEFINITION     = 7,
       /// \brief Objective-C "SEL" redefinition type
-      SPECIAL_TYPE_OBJC_SEL_REDEFINITION       = 9,
+      SPECIAL_TYPE_OBJC_SEL_REDEFINITION       = 8,
       /// \brief Whether __[u]int128_t identifier is installed.
-      SPECIAL_TYPE_INT128_INSTALLED            = 10
+      SPECIAL_TYPE_INT128_INSTALLED            = 9
     };
 
     /// \brief Predefined declaration IDs.
@@ -678,15 +676,18 @@ namespace clang {
       /// \brief The Objective-C 'id' type.
       PREDEF_DECL_OBJC_ID_ID = 2,
       
+      /// \brief The Objective-C 'SEL' type.
+      PREDEF_DECL_OBJC_SEL_ID = 3,
+      
       /// \brief The Objective-C 'Class' type.
-      PREDEF_DECL_OBJC_CLASS_ID = 3
+      PREDEF_DECL_OBJC_CLASS_ID = 4
     };
 
     /// \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 = 4;
+    const unsigned int NUM_PREDEF_DECL_IDS = 5;
     
     /// \brief Record codes for each kind of declaration.
     ///
index 5951fcfe0e0f5482e050742516c8e4d151345d74..8a4c9d333823b8b6c85486ec92405268195772a5 100644 (file)
@@ -222,7 +222,7 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM,
   DependentTemplateSpecializationTypes(this_()),
   SubstTemplateTemplateParmPacks(this_()),
   GlobalNestedNameSpecifier(0), IsInt128Installed(false),
-  ObjCIdDecl(0), ObjCClassDecl(0),
+  ObjCIdDecl(0), ObjCSelDecl(0), ObjCClassDecl(0),
   CFConstantStringTypeDecl(0),
   FILEDecl(0), 
   jmp_bufDecl(0), sigjmp_bufDecl(0), BlockDescriptorType(0), 
@@ -430,9 +430,6 @@ void ASTContext::InitBuiltinTypes() {
 
   BuiltinVaListType = QualType();
 
-  // "Builtin" typedefs set by Sema::ActOnTranslationUnitScope().
-  ObjCSelTypedefType = QualType();
-
   // Builtin types for 'id', 'Class', and 'SEL'.
   InitBuiltinType(ObjCBuiltinIdTy, BuiltinType::ObjCId);
   InitBuiltinType(ObjCBuiltinClassTy, BuiltinType::ObjCClass);
@@ -4632,8 +4629,16 @@ TypedefDecl *ASTContext::getObjCIdDecl() const {
   return ObjCIdDecl;
 }
 
-void ASTContext::setObjCSelType(QualType T) {
-  ObjCSelTypedefType = T;
+TypedefDecl *ASTContext::getObjCSelDecl() const {
+  if (!ObjCSelDecl) {
+    QualType SelT = getPointerType(ObjCBuiltinSelTy);
+    TypeSourceInfo *SelInfo = getTrivialTypeSourceInfo(SelT);
+    ObjCSelDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this),
+                                      getTranslationUnitDecl(),
+                                      SourceLocation(), SourceLocation(),
+                                      &Idents.get("SEL"), SelInfo);
+  }
+  return ObjCSelDecl;
 }
 
 void ASTContext::setObjCProtoType(QualType QT) {
index 2377d186ef529371fb7a1fda828514a4564bfe8f..a4abae42ac8fc07dca346fe53c3a762edb83638d 100644 (file)
@@ -84,19 +84,6 @@ void Sema::ActOnTranslationUnitScope(Scope *S) {
 
   if (!PP.getLangOptions().ObjC1) return;
 
-  // Built-in ObjC types may already be set by ASTReader (hence isNull checks).
-  if (Context.getObjCSelType().isNull()) {
-    // Create the built-in typedef for 'SEL'.
-    QualType SelT = Context.getPointerType(Context.ObjCBuiltinSelTy);
-    TypeSourceInfo *SelInfo = Context.getTrivialTypeSourceInfo(SelT);
-    TypedefDecl *SelTypedef
-      = TypedefDecl::Create(Context, CurContext,
-                            SourceLocation(), SourceLocation(),
-                            &Context.Idents.get("SEL"), SelInfo);
-    PushOnScopeChains(SelTypedef, TUScope);
-    Context.setObjCSelType(Context.getTypeDeclType(SelTypedef));
-  }
-
   // Synthesize "@class Protocol;
   if (Context.getObjCProtoType().isNull()) {
     ObjCInterfaceDecl *ProtocolDecl =
@@ -157,6 +144,12 @@ void Sema::Initialize() {
 
   // Initialize predefined Objective-C types:
   if (PP.getLangOptions().ObjC1) {
+    // If 'SEL' does not yet refer to any declarations, make it refer to the
+    // predefined 'SEL'.
+    DeclarationName SEL = &Context.Idents.get("SEL");
+    if (IdentifierResolver::begin(SEL) == IdentifierResolver::end())
+      PushOnScopeChains(Context.getObjCSelDecl(), TUScope);
+
     // If 'id' does not yet refer to any declarations, make it refer to the
     // predefined 'id'.
     DeclarationName Id = &Context.Idents.get("id");
index 2d4cde05a9d53f151d1b6ed0aa771b18ca0f43f4..c048f58fdba1c09afa6bf177d148a8a3bd95bc48 100644 (file)
@@ -2987,11 +2987,6 @@ void ASTReader::InitializeContext(ASTContext &Ctx) {
       GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST]));
   }
   
-  if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) {
-    if (Context->ObjCSelTypedefType.isNull())
-      Context->ObjCSelTypedefType = GetType(Sel);
-  }
-  
   if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) {
     if (Context->ObjCProtoType.isNull())
       Context->ObjCProtoType = GetType(Proto);
@@ -4220,6 +4215,10 @@ Decl *ASTReader::GetDecl(DeclID ID) {
       assert(Context && "No context available?");
       return Context->getObjCIdDecl();
 
+    case PREDEF_DECL_OBJC_SEL_ID:
+      assert(Context && "No context available?");
+      return Context->getObjCSelDecl();
+
     case PREDEF_DECL_OBJC_CLASS_ID:
       assert(Context && "No context available?");
       return Context->getObjCClassDecl();
index b92b76086398e711a831e44824b6438db09339ca..47bcd6fdeecee54f2874932249f1672ab86eaeff 100644 (file)
@@ -2810,6 +2810,8 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
   DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID;
   if (Context.ObjCIdDecl)
     DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_ID;
+  if (Context.ObjCSelDecl)
+    DeclIDs[Context.ObjCSelDecl] = PREDEF_DECL_OBJC_SEL_ID;
   if (Context.ObjCClassDecl)
     DeclIDs[Context.ObjCClassDecl] = PREDEF_DECL_OBJC_CLASS_ID;
   
@@ -3019,7 +3021,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls,
   // Form the record of special types.
   RecordData SpecialTypes;
   AddTypeRef(Context.getBuiltinVaListType(), SpecialTypes);
-  AddTypeRef(Context.ObjCSelTypedefType, SpecialTypes);
   AddTypeRef(Context.ObjCProtoType, SpecialTypes);
   AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes);
   AddTypeRef(Context.getFILEType(), SpecialTypes);