[cfe-commits] r55261 - /cfe/trunk/lib/Sema/Sema.cpp

Anders Carlsson andersca at mac.com
Sat Aug 23 15:20:38 PDT 2008


Author: andersca
Date: Sat Aug 23 17:20:38 2008
New Revision: 55261

URL: http://llvm.org/viewvc/llvm-project?rev=55261&view=rev
Log:
Make sure to create CXX record decls for the implicit Obj-C type declarations. This lets us compile Cocoa.h as Objective-C++

Modified:
    cfe/trunk/lib/Sema/Sema.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Sat Aug 23 17:20:38 2008
@@ -27,17 +27,25 @@
          strcmp(typeName, "SEL") == 0 || strcmp(typeName, "Protocol") == 0;
 }
 
+static inline RecordDecl *CreateStructDecl(ASTContext &C, const char *Name)
+{
+  if (C.getLangOptions().CPlusPlus)
+    return CXXRecordDecl::Create(C, TagDecl::TK_struct, 
+                                 C.getTranslationUnitDecl(),
+                                 SourceLocation(), &C.Idents.get(Name), 0);
+  else
+    return RecordDecl::Create(C, TagDecl::TK_struct, 
+                              C.getTranslationUnitDecl(),
+                              SourceLocation(), &C.Idents.get(Name), 0);
+}
+
 void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
   TUScope = S;
   CurContext = Context.getTranslationUnitDecl();
   if (!PP.getLangOptions().ObjC1) return;
   
   // Synthesize "typedef struct objc_selector *SEL;"
-  RecordDecl *SelTag = RecordDecl::Create(Context, TagDecl::TK_struct,
-                                          CurContext,
-                                          SourceLocation(), 
-                                          &Context.Idents.get("objc_selector"),
-                                          0);
+  RecordDecl *SelTag = CreateStructDecl(Context, "objc_selector");
   PushOnScopeChains(SelTag, TUScope);
   
   QualType SelT = Context.getPointerType(Context.getTagDeclType(SelTag));
@@ -49,11 +57,7 @@
   Context.setObjCSelType(SelTypedef);
 
   // FIXME: Make sure these don't leak!
-  RecordDecl *ClassTag = RecordDecl::Create(Context, TagDecl::TK_struct,
-                                            CurContext,
-                                            SourceLocation(),
-                                            &Context.Idents.get("objc_class"),
-                                            0);
+  RecordDecl *ClassTag = CreateStructDecl(Context, "objc_class");
   QualType ClassT = Context.getPointerType(Context.getTagDeclType(ClassTag));
   TypedefDecl *ClassTypedef = 
     TypedefDecl::Create(Context, CurContext, SourceLocation(),
@@ -70,10 +74,8 @@
   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);
+  RecordDecl *ObjectTag = CreateStructDecl(Context, "objc_object");
+
   QualType ObjT = Context.getPointerType(Context.getTagDeclType(ObjectTag));
   PushOnScopeChains(ObjectTag, TUScope);
   TypedefDecl *IdTypedef = TypedefDecl::Create(Context, CurContext,





More information about the cfe-commits mailing list