diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-08-12 05:46:01 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-08-12 05:46:01 +0000 |
commit | 3ea7269b54aefd674424cd89be5f17ea8e18d222 (patch) | |
tree | 7c12465cfda3fd11deb868868016a61f9b0d6baf /clang/lib | |
parent | 1ec8114eb82162e8dc25eb3ff020bf0f3bf8b88b (diff) | |
download | bcm5719-llvm-3ea7269b54aefd674424cd89be5f17ea8e18d222.tar.gz bcm5719-llvm-3ea7269b54aefd674424cd89be5f17ea8e18d222.zip |
Move the creation of the predefined typedef for Objective-C's 'id'
type over into the AST context, then make that declaration a
predefined declaration in the AST format. This ensures that different
AST files will at least agree on the (global) declaration ID for 'id',
and eliminates one of the "special" types in the AST file format.
llvm-svn: 137429
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 17 | ||||
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 22 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 9 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 5 |
4 files changed, 30 insertions, 23 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index c4955721e96..cf4535bd90c 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -222,7 +222,7 @@ ASTContext::ASTContext(const LangOptions& LOpts, SourceManager &SM, DependentTemplateSpecializationTypes(this_()), SubstTemplateTemplateParmPacks(this_()), GlobalNestedNameSpecifier(0), IsInt128Installed(false), - CFConstantStringTypeDecl(0), + ObjCIdDecl(0), CFConstantStringTypeDecl(0), FILEDecl(0), jmp_bufDecl(0), sigjmp_bufDecl(0), BlockDescriptorType(0), BlockDescriptorExtendedType(0), cudaConfigureCallDecl(0), @@ -430,7 +430,6 @@ void ASTContext::InitBuiltinTypes() { BuiltinVaListType = QualType(); // "Builtin" typedefs set by Sema::ActOnTranslationUnitScope(). - ObjCIdTypedefType = QualType(); ObjCClassTypedefType = QualType(); ObjCSelTypedefType = QualType(); @@ -4619,8 +4618,18 @@ void ASTContext::setBuiltinVaListType(QualType T) { BuiltinVaListType = T; } -void ASTContext::setObjCIdType(QualType T) { - ObjCIdTypedefType = T; +TypedefDecl *ASTContext::getObjCIdDecl() const { + if (!ObjCIdDecl) { + QualType T = getObjCObjectType(ObjCBuiltinIdTy, 0, 0); + T = getObjCObjectPointerType(T); + TypeSourceInfo *IdInfo = getTrivialTypeSourceInfo(T); + ObjCIdDecl = TypedefDecl::Create(const_cast<ASTContext &>(*this), + getTranslationUnitDecl(), + SourceLocation(), SourceLocation(), + &Idents.get("id"), IdInfo); + } + + return ObjCIdDecl; } void ASTContext::setObjCSelType(QualType T) { diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 7451fa43912..adc749dd704 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -106,18 +106,7 @@ void Sema::ActOnTranslationUnitScope(Scope *S) { Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl)); PushOnScopeChains(ProtocolDecl, TUScope, false); } - // Create the built-in typedef for 'id'. - if (Context.getObjCIdType().isNull()) { - QualType T = Context.getObjCObjectType(Context.ObjCBuiltinIdTy, 0, 0); - T = Context.getObjCObjectPointerType(T); - TypeSourceInfo *IdInfo = Context.getTrivialTypeSourceInfo(T); - TypedefDecl *IdTypedef - = TypedefDecl::Create(Context, CurContext, - SourceLocation(), SourceLocation(), - &Context.Idents.get("id"), IdInfo); - PushOnScopeChains(IdTypedef, TUScope); - Context.setObjCIdType(Context.getTypeDeclType(IdTypedef)); - } + // Create the built-in typedef for 'Class'. if (Context.getObjCClassType().isNull()) { QualType T = Context.getObjCObjectType(Context.ObjCBuiltinClassTy, 0, 0); @@ -178,6 +167,15 @@ void Sema::Initialize() { if (ExternalSemaSource *ExternalSema = dyn_cast_or_null<ExternalSemaSource>(Context.getExternalSource())) ExternalSema->InitializeSema(*this); + + // Initialize predefined Objective-C types: + if (PP.getLangOptions().ObjC1) { + // If 'id' does not yet refer to any declarations, make it refer to the + // predefined 'id'. + DeclarationName Id = &Context.Idents.get("id"); + if (IdentifierResolver::begin(Id) == IdentifierResolver::end()) + PushOnScopeChains(Context.getObjCIdDecl(), TUScope); + } } Sema::~Sema() { diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 43435b6754e..2e9e1bee684 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2987,11 +2987,6 @@ void ASTReader::InitializeContext(ASTContext &Ctx) { GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST])); } - if (unsigned Id = SpecialTypes[SPECIAL_TYPE_OBJC_ID]) { - if (Context->ObjCIdTypedefType.isNull()) - Context->ObjCIdTypedefType = GetType(Id); - } - if (unsigned Sel = SpecialTypes[SPECIAL_TYPE_OBJC_SELECTOR]) { if (Context->ObjCSelTypedefType.isNull()) Context->ObjCSelTypedefType = GetType(Sel); @@ -4225,6 +4220,10 @@ Decl *ASTReader::GetDecl(DeclID ID) { case PREDEF_DECL_TRANSLATION_UNIT_ID: assert(Context && "No context available?"); return Context->getTranslationUnitDecl(); + + case PREDEF_DECL_OBJC_ID_ID: + assert(Context && "No context available?"); + return Context->getObjCIdDecl(); } return 0; diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 2654ae3fdf3..2377369c74f 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2808,7 +2808,9 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, // Set up predefined declaration IDs. DeclIDs[Context.getTranslationUnitDecl()] = PREDEF_DECL_TRANSLATION_UNIT_ID; - + if (Context.ObjCIdDecl) + DeclIDs[Context.ObjCIdDecl] = PREDEF_DECL_OBJC_ID_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 @@ -3015,7 +3017,6 @@ void ASTWriter::WriteASTCore(Sema &SemaRef, MemorizeStatCalls *StatCalls, // Form the record of special types. RecordData SpecialTypes; AddTypeRef(Context.getBuiltinVaListType(), SpecialTypes); - AddTypeRef(Context.ObjCIdTypedefType, SpecialTypes); AddTypeRef(Context.ObjCSelTypedefType, SpecialTypes); AddTypeRef(Context.ObjCProtoType, SpecialTypes); AddTypeRef(Context.ObjCClassTypedefType, SpecialTypes); |