diff options
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 80 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 6 |
2 files changed, 47 insertions, 39 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index a5b30cc72ac..3702c89cf60 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -110,46 +110,54 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { PushDeclContext(S, Context.getTranslationUnitDecl()); if (!PP.getLangOptions().ObjC1) return; - // Synthesize "typedef struct objc_selector *SEL;" - RecordDecl *SelTag = CreateStructDecl(Context, "objc_selector"); - PushOnScopeChains(SelTag, TUScope); + if (Context.getObjCSelType().isNull()) { + // Synthesize "typedef struct objc_selector *SEL;" + RecordDecl *SelTag = CreateStructDecl(Context, "objc_selector"); + PushOnScopeChains(SelTag, TUScope); - QualType SelT = Context.getPointerType(Context.getTagDeclType(SelTag)); - TypedefDecl *SelTypedef = TypedefDecl::Create(Context, CurContext, - SourceLocation(), - &Context.Idents.get("SEL"), - SelT); - PushOnScopeChains(SelTypedef, TUScope); - Context.setObjCSelType(SelTypedef); + QualType SelT = Context.getPointerType(Context.getTagDeclType(SelTag)); + TypedefDecl *SelTypedef = TypedefDecl::Create(Context, CurContext, + SourceLocation(), + &Context.Idents.get("SEL"), + SelT); + PushOnScopeChains(SelTypedef, TUScope); + Context.setObjCSelType(Context.getTypeDeclType(SelTypedef)); + } + + if (Context.getObjCClassType().isNull()) { + RecordDecl *ClassTag = CreateStructDecl(Context, "objc_class"); + QualType ClassT = Context.getPointerType(Context.getTagDeclType(ClassTag)); + TypedefDecl *ClassTypedef = + TypedefDecl::Create(Context, CurContext, SourceLocation(), + &Context.Idents.get("Class"), ClassT); + PushOnScopeChains(ClassTag, TUScope); + PushOnScopeChains(ClassTypedef, TUScope); + Context.setObjCClassType(Context.getTypeDeclType(ClassTypedef)); + } - // FIXME: Make sure these don't leak! - RecordDecl *ClassTag = CreateStructDecl(Context, "objc_class"); - QualType ClassT = Context.getPointerType(Context.getTagDeclType(ClassTag)); - TypedefDecl *ClassTypedef = - TypedefDecl::Create(Context, CurContext, SourceLocation(), - &Context.Idents.get("Class"), ClassT); - PushOnScopeChains(ClassTag, TUScope); - PushOnScopeChains(ClassTypedef, TUScope); - Context.setObjCClassType(ClassTypedef); // Synthesize "@class Protocol; - ObjCInterfaceDecl *ProtocolDecl = - ObjCInterfaceDecl::Create(Context, CurContext, SourceLocation(), - &Context.Idents.get("Protocol"), - SourceLocation(), true); - Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl)); - PushOnScopeChains(ProtocolDecl, TUScope); - - // Synthesize "typedef struct objc_object { Class isa; } *id;" - RecordDecl *ObjectTag = CreateStructDecl(Context, "objc_object"); + if (Context.getObjCProtoType().isNull()) { + ObjCInterfaceDecl *ProtocolDecl = + ObjCInterfaceDecl::Create(Context, CurContext, SourceLocation(), + &Context.Idents.get("Protocol"), + SourceLocation(), true); + Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl)); + PushOnScopeChains(ProtocolDecl, TUScope); + } - QualType ObjT = Context.getPointerType(Context.getTagDeclType(ObjectTag)); - PushOnScopeChains(ObjectTag, TUScope); - TypedefDecl *IdTypedef = TypedefDecl::Create(Context, CurContext, - SourceLocation(), - &Context.Idents.get("id"), - ObjT); - PushOnScopeChains(IdTypedef, TUScope); - Context.setObjCIdType(IdTypedef); + // Synthesize "typedef struct objc_object { Class isa; } *id;" + if (Context.getObjCIdType().isNull()) { + RecordDecl *ObjectTag = CreateStructDecl(Context, "objc_object"); + + QualType ObjT = Context.getPointerType(Context.getTagDeclType(ObjectTag)); + PushOnScopeChains(ObjectTag, TUScope); + TypedefDecl *IdTypedef = TypedefDecl::Create(Context, CurContext, + SourceLocation(), + &Context.Idents.get("id"), + ObjT); + PushOnScopeChains(IdTypedef, TUScope); + Context.setObjCIdType(Context.getTypeDeclType(IdTypedef)); + } } Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index b3592086ddd..e81e8832724 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -473,19 +473,19 @@ bool Sema::MergeTypeDefDecl(TypedefDecl *New, Decl *OldD) { case 2: if (!TypeID->isStr("id")) break; - Context.setObjCIdType(New); + Context.setObjCIdType(Context.getTypeDeclType(New)); objc_types = true; break; case 5: if (!TypeID->isStr("Class")) break; - Context.setObjCClassType(New); + Context.setObjCClassType(Context.getTypeDeclType(New)); objc_types = true; return false; case 3: if (!TypeID->isStr("SEL")) break; - Context.setObjCSelType(New); + Context.setObjCSelType(Context.getTypeDeclType(New)); objc_types = true; return false; case 8: |