[cfe-commits] r62601 - in /cfe/trunk: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp test/CodeGenObjC/encode-test-2.m

Fariborz Jahanian fjahanian at apple.com
Tue Jan 20 11:14:18 PST 2009


Author: fjahanian
Date: Tue Jan 20 13:14:18 2009
New Revision: 62601

URL: http://llvm.org/viewvc/llvm-project?rev=62601&view=rev
Log:
Improving on encoding of objective-c's property types. More to come.

Added:
    cfe/trunk/test/CodeGenObjC/encode-test-2.m
Modified:
    cfe/trunk/include/clang/AST/ASTContext.h
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=62601&r1=62600&r2=62601&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Jan 20 13:14:18 2009
@@ -548,7 +548,8 @@
                                   bool ExpandPointedToStructures,
                                   bool ExpandStructures,
                                   FieldDecl *Field,
-                                  bool OutermostType = false) const;
+                                  bool OutermostType = false,
+                                  bool EncodingProperty = false) const;
   
 };
   

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=62601&r1=62600&r2=62601&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Jan 20 13:14:18 2009
@@ -1744,9 +1744,11 @@
   S = "T";
 
   // Encode result type.
-  // FIXME: GCC uses a generating_property_type_encoding mode during
-  // this part. Investigate.
-  getObjCEncodingForType(PD->getType(), S);
+  // GCC has some special rules regarding encoding of properties which
+  // closely resembles encoding of ivars.
+  getObjCEncodingForTypeImpl(PD->getType(), S, true, true, NULL, 
+                             true /* outermost type */,
+                             true /* encoding for property */);
 
   if (PD->isReadOnly()) {
     S += ",R";
@@ -1763,6 +1765,9 @@
   if (Dynamic)
     S += ",D";
 
+  if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic)
+    S += ",N";
+  
   if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) {
     S += ",G";
     S += PD->getGetterName().getAsString();
@@ -1822,7 +1827,8 @@
                                             bool ExpandPointedToStructures,
                                             bool ExpandStructures,
                                             FieldDecl *FD,
-                                            bool OutermostType) const {
+                                            bool OutermostType,
+                                            bool EncodingProperty) const {
   if (const BuiltinType *BT = T->getAsBuiltinType()) {
     if (FD && FD->isBitField()) {
       EncodeBitField(this, S, FD);
@@ -1854,10 +1860,23 @@
     }
   }
   else if (T->isObjCQualifiedIdType()) {
-    // Treat id<P...> same as 'id' for encoding purposes.
-    return getObjCEncodingForTypeImpl(getObjCIdType(), S, 
-                                      ExpandPointedToStructures,
-                                      ExpandStructures, FD);    
+    getObjCEncodingForTypeImpl(getObjCIdType(), S, 
+                               ExpandPointedToStructures,
+                               ExpandStructures, FD);
+    if (FD || EncodingProperty) {
+      // Note that we do extended encoding of protocol qualifer list
+      // Only when doing ivar or property encoding.
+      const ObjCQualifiedIdType *QIDT = T->getAsObjCQualifiedIdType();
+      S += '"';
+      for (unsigned i =0; i < QIDT->getNumProtocols(); i++) {
+        ObjCProtocolDecl *Proto = QIDT->getProtocols(i);
+        S += '<';
+        S += Proto->getNameAsString();
+        S += '>';
+      }
+      S += '"';
+    }
+    return;
   }
   else if (const PointerType *PT = T->getAsPointerType()) {
     QualType PointeeTy = PT->getPointeeType();
@@ -1908,10 +1927,17 @@
         return;
       }
       S += '@';
-      if (FD) {
-        ObjCInterfaceDecl *OI = PointeeTy->getAsObjCInterfaceType()->getDecl();
+      if (FD || EncodingProperty) {
+        const ObjCInterfaceType *OIT = PointeeTy->getAsObjCInterfaceType();
+        ObjCInterfaceDecl *OI = OIT->getDecl();
         S += '"';
         S += OI->getNameAsCString();
+        for (unsigned i =0; i < OIT->getNumProtocols(); i++) {
+          ObjCProtocolDecl *Proto = OIT->getProtocol(i);
+          S += '<';
+          S += Proto->getNameAsString();
+          S += '>';
+        } 
         S += '"';
       }
       return;

Added: cfe/trunk/test/CodeGenObjC/encode-test-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/encode-test-2.m?rev=62601&view=auto

==============================================================================
--- cfe/trunk/test/CodeGenObjC/encode-test-2.m (added)
+++ cfe/trunk/test/CodeGenObjC/encode-test-2.m Tue Jan 20 13:14:18 2009
@@ -0,0 +1,29 @@
+// RUN: clang -triple=i686-apple-darwin9 -fnext-runtime -emit-llvm -o %t %s &&
+// RUN: grep -e "@\\\22<X>\\\22" %t  &&
+// RUN: grep -e "@\\\22<X><Y>\\\22" %t  &&
+// RUN: grep -e "@\\\22<X><Y><Z>\\\22" %t  &&
+// RUN: grep -e "@\\\22Foo<X><Y><Z>\\\22" %t  &&
+// RUN: grep -e "{Intf=@@@@}" %t  
+
+ at protocol X, Y, Z;
+ at class Foo;
+
+ at protocol Proto
+ at end
+
+ at interface Intf <Proto>
+{
+id <X> IVAR_x;
+id <X, Y> IVAR_xy;
+id <X, Y, Z> IVAR_xyz;
+Foo <X, Y, Z> *IVAR_Fooxyz;
+}
+ at end
+
+ at implementation Intf 
+ at end
+
+int main()
+{
+	const char * en = @encode(Intf);
+}





More information about the cfe-commits mailing list