From: Douglas Gregor Date: Tue, 9 Aug 2011 17:23:49 +0000 (+0000) Subject: Move the creation of the record type for the state of Objective-C fast X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0815b579b31cb3129f732bb7ea36fd6ba6949e98;p=clang Move the creation of the record type for the state of Objective-C fast enumerations from the ASTContext into CodeGen, so that we don't need to serialize it to AST files. This appears to be the last of the low-hanging fruit for SpecialTypes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@137124 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 882e0a6aa8..bf4586a0aa 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -198,8 +198,6 @@ class ASTContext : public llvm::RefCountedBase { QualType ObjCConstantStringType; mutable RecordDecl *CFConstantStringTypeDecl; - mutable RecordDecl *ObjCFastEnumerationStateTypeDecl; - /// \brief The type for the C FILE type. TypeDecl *FILEDecl; @@ -823,19 +821,6 @@ public: return ObjCConstantStringType; } - //// This gets the struct used to keep track of fast enumerations. - QualType getObjCFastEnumerationStateType() const; - - /// Get the ObjCFastEnumerationState type, or NULL if it hasn't yet - /// been built. - QualType getRawObjCFastEnumerationStateType() const { - if (ObjCFastEnumerationStateTypeDecl) - return getTagDeclType(ObjCFastEnumerationStateTypeDecl); - return QualType(); - } - - void setObjCFastEnumerationStateType(QualType T); - /// \brief Set the type for the C FILE type. void setFILEDecl(TypeDecl *FILEDecl) { this->FILEDecl = FILEDecl; } diff --git a/include/clang/Serialization/ASTBitCodes.h b/include/clang/Serialization/ASTBitCodes.h index b6c5a24254..949265461d 100644 --- a/include/clang/Serialization/ASTBitCodes.h +++ b/include/clang/Serialization/ASTBitCodes.h @@ -650,22 +650,20 @@ namespace clang { SPECIAL_TYPE_OBJC_CLASS = 4, /// \brief CFConstantString type SPECIAL_TYPE_CF_CONSTANT_STRING = 5, - /// \brief Objective-C fast enumeration state type - SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE = 6, /// \brief C FILE typedef type - SPECIAL_TYPE_FILE = 7, + SPECIAL_TYPE_FILE = 6, /// \brief C jmp_buf typedef type - SPECIAL_TYPE_jmp_buf = 8, + SPECIAL_TYPE_jmp_buf = 7, /// \brief C sigjmp_buf typedef type - SPECIAL_TYPE_sigjmp_buf = 9, + SPECIAL_TYPE_sigjmp_buf = 8, /// \brief Objective-C "id" redefinition type - SPECIAL_TYPE_OBJC_ID_REDEFINITION = 10, + SPECIAL_TYPE_OBJC_ID_REDEFINITION = 9, /// \brief Objective-C "Class" redefinition type - SPECIAL_TYPE_OBJC_CLASS_REDEFINITION = 11, + SPECIAL_TYPE_OBJC_CLASS_REDEFINITION = 10, /// \brief Objective-C "SEL" redefinition type - SPECIAL_TYPE_OBJC_SEL_REDEFINITION = 12, + SPECIAL_TYPE_OBJC_SEL_REDEFINITION = 11, /// \brief Whether __[u]int128_t identifier is installed. - SPECIAL_TYPE_INT128_INSTALLED = 13 + SPECIAL_TYPE_INT128_INSTALLED = 12 }; /// \brief Predefined declaration IDs. diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index b3fab6f0e3..bbc66d2636 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -223,7 +223,7 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM, SubstTemplateTemplateParmPacks(this_()), GlobalNestedNameSpecifier(0), IsInt128Installed(false), CFConstantStringTypeDecl(0), - ObjCFastEnumerationStateTypeDecl(0), FILEDecl(0), + FILEDecl(0), jmp_bufDecl(0), sigjmp_bufDecl(0), BlockDescriptorType(0), BlockDescriptorExtendedType(0), cudaConfigureCallDecl(0), NullTypeSourceInfo(QualType()), @@ -3639,40 +3639,6 @@ void ASTContext::setCFConstantStringType(QualType T) { CFConstantStringTypeDecl = Rec->getDecl(); } -QualType ASTContext::getObjCFastEnumerationStateType() const { - if (!ObjCFastEnumerationStateTypeDecl) { - ObjCFastEnumerationStateTypeDecl = - CreateRecordDecl(*this, TTK_Struct, TUDecl, - &Idents.get("__objcFastEnumerationState")); - ObjCFastEnumerationStateTypeDecl->startDefinition(); - - QualType FieldTypes[] = { - UnsignedLongTy, - getPointerType(ObjCIdTypedefType), - getPointerType(UnsignedLongTy), - getConstantArrayType(UnsignedLongTy, - llvm::APInt(32, 5), ArrayType::Normal, 0) - }; - - for (size_t i = 0; i < 4; ++i) { - FieldDecl *Field = FieldDecl::Create(*this, - ObjCFastEnumerationStateTypeDecl, - SourceLocation(), - SourceLocation(), 0, - FieldTypes[i], /*TInfo=*/0, - /*BitWidth=*/0, - /*Mutable=*/false, - /*HasInit=*/false); - Field->setAccess(AS_public); - ObjCFastEnumerationStateTypeDecl->addDecl(Field); - } - - ObjCFastEnumerationStateTypeDecl->completeDefinition(); - } - - return getTagDeclType(ObjCFastEnumerationStateTypeDecl); -} - QualType ASTContext::getBlockDescriptorType() const { if (BlockDescriptorType) return getTagDeclType(BlockDescriptorType); @@ -3829,12 +3795,6 @@ ASTContext::BuildByRefType(StringRef DeclName, QualType Ty) const { return getPointerType(getTagDeclType(T)); } -void ASTContext::setObjCFastEnumerationStateType(QualType T) { - const RecordType *Rec = T->getAs(); - assert(Rec && "Invalid ObjCFAstEnumerationStateType"); - ObjCFastEnumerationStateTypeDecl = Rec->getDecl(); -} - // This returns true if a type has been typedefed to BOOL: // typedef BOOL; static bool isTypeTypedefedAsBOOL(QualType T) { diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index 944a0bd2a2..565cf3a5b2 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -997,7 +997,7 @@ void CodeGenFunction::EmitObjCForCollectionStmt(const ObjCForCollectionStmt &S){ JumpDest LoopEnd = getJumpDestInCurrentScope("forcoll.end"); // Fast enumeration state. - QualType StateTy = getContext().getObjCFastEnumerationStateType(); + QualType StateTy = CGM.getObjCFastEnumerationStateType(); llvm::Value *StatePtr = CreateMemTemp(StateTy, "state.ptr"); EmitNullInitialization(StatePtr, StateTy); diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 13c8f6080f..d5d34634db 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -1925,6 +1925,41 @@ CodeGenModule::GetAddrOfConstantString(const StringLiteral *Literal) { return GV; } +QualType CodeGenModule::getObjCFastEnumerationStateType() { + if (ObjCFastEnumerationStateType.isNull()) { + RecordDecl *D = CreateRecordDecl(Context, TTK_Struct, + Context.getTranslationUnitDecl(), + &Context.Idents.get("__objcFastEnumerationState")); + D->startDefinition(); + + QualType FieldTypes[] = { + Context.UnsignedLongTy, + Context.getPointerType(Context.getObjCIdType()), + Context.getPointerType(Context.UnsignedLongTy), + Context.getConstantArrayType(Context.UnsignedLongTy, + llvm::APInt(32, 5), ArrayType::Normal, 0) + }; + + for (size_t i = 0; i < 4; ++i) { + FieldDecl *Field = FieldDecl::Create(Context, + D, + SourceLocation(), + SourceLocation(), 0, + FieldTypes[i], /*TInfo=*/0, + /*BitWidth=*/0, + /*Mutable=*/false, + /*HasInit=*/false); + Field->setAccess(AS_public); + D->addDecl(Field); + } + + D->completeDefinition(); + ObjCFastEnumerationStateType = Context.getTagDeclType(D); + } + + return ObjCFastEnumerationStateType; +} + /// GetStringForStringLiteral - Return the appropriate bytes for a /// string literal, properly padded to match the literal type. std::string CodeGenModule::GetStringForStringLiteral(const StringLiteral *E) { diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 56ff68cc8d..076c29c4de 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -300,6 +300,10 @@ class CodeGenModule : public CodeGenTypeCache { /// \brief The LLVM type corresponding to NSConstantString. llvm::StructType *NSConstantStringType; + /// \brief The type used to describe the state of a fast enumeration in + /// Objective-C's for..in loop. + QualType ObjCFastEnumerationStateType; + /// @} /// Lazily create the Objective-C runtime @@ -566,6 +570,10 @@ public: const char *GlobalName=0, unsigned Alignment=1); + /// \brief Retrieve the record type that describes the state of an + /// Objective-C fast enumeration loop (for..in). + QualType getObjCFastEnumerationStateType(); + /// GetAddrOfCXXConstructor - Return the address of the constructor of the /// given type. llvm::GlobalValue *GetAddrOfCXXConstructor(const CXXConstructorDecl *ctor, diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 9ca5211d9f..b2300e0249 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -2976,9 +2976,6 @@ void ASTReader::InitializeContext(ASTContext &Ctx) { if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) Context->setCFConstantStringType(GetType(String)); - if (unsigned FastEnum - = SpecialTypes[SPECIAL_TYPE_OBJC_FAST_ENUMERATION_STATE]) - Context->setObjCFastEnumerationStateType(GetType(FastEnum)); if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { QualType FileType = GetType(File); if (FileType.isNull()) { diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 1c4a5f63e7..a4cd279112 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -2934,7 +2934,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, AddTypeRef(Context.getObjCProtoType(), SpecialTypes); AddTypeRef(Context.getObjCClassType(), SpecialTypes); AddTypeRef(Context.getRawCFConstantStringType(), SpecialTypes); - AddTypeRef(Context.getRawObjCFastEnumerationStateType(), SpecialTypes); AddTypeRef(Context.getFILEType(), SpecialTypes); AddTypeRef(Context.getjmp_bufType(), SpecialTypes); AddTypeRef(Context.getsigjmp_bufType(), SpecialTypes);