diff options
author | Chris Lattner <sabre@nondot.org> | 2008-06-21 20:20:39 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-06-21 20:20:39 +0000 |
commit | 5a92bab4f0e59be836f307f3a7d3b22f46663e7f (patch) | |
tree | 8661c7f7ae4f37c6b59d2205b1e4cea47c1bd928 /clang/lib/Sema | |
parent | 1cf5af9e428e6d18d8782d67c73dc7d113a0b44f (diff) | |
download | bcm5719-llvm-5a92bab4f0e59be836f307f3a7d3b22f46663e7f.tar.gz bcm5719-llvm-5a92bab4f0e59be836f307f3a7d3b22f46663e7f.zip |
"This moves built-in Objective-C types up the scope chains to where they can be replaced by versions included from the runtime library's headers."
This makes it ok to use @"foo" without a declaration for NSConstantString.
Patch by David Chisnall!
llvm-svn: 52593
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/Sema.cpp | 85 |
1 files changed, 34 insertions, 51 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index 78cc5d85af5..3296bf3550a 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -45,17 +45,6 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { CurContext = Context.getTranslationUnitDecl(); if (!PP.getLangOptions().ObjC1) return; - TypedefType *t; - - // Add the built-in ObjC types. - t = cast<TypedefType>(Context.getObjCIdType().getTypePtr()); - PushOnScopeChains(t->getDecl(), TUScope); - t = cast<TypedefType>(Context.getObjCClassType().getTypePtr()); - PushOnScopeChains(t->getDecl(), TUScope); - ObjCInterfaceType *it = cast<ObjCInterfaceType>(Context.getObjCProtoType()); - ObjCInterfaceDecl *IDecl = it->getDecl(); - PushOnScopeChains(IDecl, TUScope); - // Synthesize "typedef struct objc_selector *SEL;" RecordDecl *SelTag = RecordDecl::Create(Context, TagDecl::TK_struct, CurContext, SourceLocation(), @@ -70,6 +59,40 @@ void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) { SelT, 0); PushOnScopeChains(SelTypedef, TUScope); Context.setObjCSelType(SelTypedef); + + RecordDecl *ClassTag = RecordDecl::Create(Context, TagDecl::TK_struct, + CurContext, + SourceLocation(), + &Context.Idents.get("objc_class"), + 0); + QualType ClassT = Context.getPointerType(Context.getTagDeclType(ClassTag)); + TypedefDecl *ClassTypedef = + TypedefDecl::Create(Context, CurContext, SourceLocation(), + &Context.Idents.get("Class"), ClassT, 0); + PushOnScopeChains(ClassTag, TUScope); + PushOnScopeChains(ClassTypedef, TUScope); + Context.setObjCClassType(ClassTypedef); + // Synthesize "@class Protocol; + ObjCInterfaceDecl *ProtocolDecl = + ObjCInterfaceDecl::Create(Context, SourceLocation(), 0, + &Context.Idents.get("Protocol"), + SourceLocation(), true); + Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl)); + PushOnScopeChains(ProtocolDecl, TUScope); + + // Synthesize "typedef struct objc_object { Class isa; } *id;" + RecordDecl *ObjectTag = + RecordDecl::Create(Context, TagDecl::TK_struct, CurContext, + SourceLocation(), + &Context.Idents.get("objc_object"), 0); + QualType ObjT = Context.getPointerType(Context.getTagDeclType(ObjectTag)); + PushOnScopeChains(ObjectTag, TUScope); + TypedefDecl *IdTypedef = TypedefDecl::Create(Context, CurContext, + SourceLocation(), + &Context.Idents.get("id"), + ObjT, 0); + PushOnScopeChains(IdTypedef, TUScope); + Context.setObjCIdType(IdTypedef); } Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer) @@ -92,46 +115,6 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer) KnownFunctionIDs[id_vsprintf] = &IT.get("vsprintf"); KnownFunctionIDs[id_vprintf] = &IT.get("vprintf"); - // FIXME: Move this initialization up to Sema::ActOnTranslationUnitScope() - // and make sure the decls get inserted into TUScope! - // FIXME: And make sure they don't leak! - if (PP.getLangOptions().ObjC1) { - TranslationUnitDecl *TUDecl = Context.getTranslationUnitDecl(); - - // Synthesize "typedef struct objc_class *Class;" - RecordDecl *ClassTag = RecordDecl::Create(Context, TagDecl::TK_struct, - TUDecl, - SourceLocation(), - &IT.get("objc_class"), 0); - QualType ClassT = Context.getPointerType(Context.getTagDeclType(ClassTag)); - TypedefDecl *ClassTypedef = - TypedefDecl::Create(Context, TUDecl, SourceLocation(), - &Context.Idents.get("Class"), ClassT, 0); - Context.setObjCClassType(ClassTypedef); - - // Synthesize "@class Protocol; - ObjCInterfaceDecl *ProtocolDecl = - ObjCInterfaceDecl::Create(Context, SourceLocation(), 0, - &Context.Idents.get("Protocol"), - SourceLocation(), true); - Context.setObjCProtoType(Context.getObjCInterfaceType(ProtocolDecl)); - - // Synthesize "typedef struct objc_object { Class isa; } *id;" - RecordDecl *ObjectTag = - RecordDecl::Create(Context, TagDecl::TK_struct, TUDecl, - SourceLocation(), - &IT.get("objc_object"), 0); - FieldDecl *IsaDecl = FieldDecl::Create(Context, SourceLocation(), - &Context.Idents.get("isa"), - Context.getObjCClassType()); - ObjectTag->defineBody(&IsaDecl, 1); - QualType ObjT = Context.getPointerType(Context.getTagDeclType(ObjectTag)); - TypedefDecl *IdTypedef = TypedefDecl::Create(Context, TUDecl, - SourceLocation(), - &Context.Idents.get("id"), - ObjT, 0); - Context.setObjCIdType(IdTypedef); - } TUScope = 0; } |