[cfe-commits] r52593 - in /cfe/trunk: lib/Sema/Sema.cpp test/CodeGen/empty-union-init.c test/Sema/objc-string.m

Chris Lattner sabre at nondot.org
Sat Jun 21 13:20:40 PDT 2008


Author: lattner
Date: Sat Jun 21 15:20:39 2008
New Revision: 52593

URL: http://llvm.org/viewvc/llvm-project?rev=52593&view=rev
Log:
"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!


Modified:
    cfe/trunk/lib/Sema/Sema.cpp
    cfe/trunk/test/CodeGen/empty-union-init.c
    cfe/trunk/test/Sema/objc-string.m

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=52593&r1=52592&r2=52593&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sat Jun 21 15:20:39 2008
@@ -45,17 +45,6 @@
   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 @@
                                                 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 @@
   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;
 }
 

Modified: cfe/trunk/test/CodeGen/empty-union-init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/empty-union-init.c?rev=52593&r1=52592&r2=52593&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/empty-union-init.c (original)
+++ cfe/trunk/test/CodeGen/empty-union-init.c Sat Jun 21 15:20:39 2008
@@ -1,4 +1,5 @@
 // RUN: clang -emit-llvm < %s -o -
+// PR2419
 
 struct Mem {
         union {

Modified: cfe/trunk/test/Sema/objc-string.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/objc-string.m?rev=52593&r1=52592&r2=52593&view=diff

==============================================================================
--- cfe/trunk/test/Sema/objc-string.m (original)
+++ cfe/trunk/test/Sema/objc-string.m Sat Jun 21 15:20:39 2008
@@ -1,11 +1,15 @@
 // RUN: clang %s -verify -fsyntax-only
+// RUN: clang %s -verify -fsyntax-only -DDECLAREIT
 
+// a declaration of NSConstantString is not required.
+#ifdef DECLAREIT
 @interface NSConstantString;
 @end
+#endif
 
 
 
-NSConstantString *s = @"123"; // simple
-NSConstantString *t = @"123" @"456"; // concat
-NSConstantString *u = @"123" @ blah; // expected-error: {{unexpected token}}
+id s = @"123"; // simple
+id t = @"123" @"456"; // concat
+id u = @"123" @ blah; // expected-error: {{unexpected token}}
 





More information about the cfe-commits mailing list