diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-08-12 06:17:30 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-08-12 06:17:30 +0000 |
commit | 7a27ea52b7bd635c89bec5a9c521a3bf7d204238 (patch) | |
tree | e89f1ae41b586aebd3ce40519a07f055d8b670e4 /lib | |
parent | 79d6726921897811232554ed94c5d77b5b7b3fc0 (diff) |
Switch the Objective-C 'SEL' type over to a predefined type in the
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/ASTContext.cpp | 17 | ||||
-rw-r--r-- | lib/Sema/Sema.cpp | 19 | ||||
-rw-r--r-- | lib/Serialization/ASTReader.cpp | 9 | ||||
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 3 |
4 files changed, 23 insertions, 25 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 5951fcfe0e..8a4c9d3338 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -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) { diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp index 2377d186ef..a4abae42ac 100644 --- a/lib/Sema/Sema.cpp +++ b/lib/Sema/Sema.cpp @@ -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"); diff --git a/lib/Serialization/ASTReader.cpp b/lib/Serialization/ASTReader.cpp index 2d4cde05a9..c048f58fdb 100644 --- a/lib/Serialization/ASTReader.cpp +++ b/lib/Serialization/ASTReader.cpp @@ -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(); diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index b92b760863..47bcd6fdee 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -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); |