[cfe-commits] r49817 - in /cfe/trunk: Driver/ASTConsumers.cpp include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Sema/SemaDeclObjC.cpp

Fariborz Jahanian fjahanian at apple.com
Wed Apr 16 14:08:45 PDT 2008


Author: fjahanian
Date: Wed Apr 16 16:08:45 2008
New Revision: 49817

URL: http://llvm.org/viewvc/llvm-project?rev=49817&view=rev
Log:
This patch adds support for declaraing properties in categories,
just as they are declared in objc classes.

Modified:
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=49817&r1=49816&r2=49817&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Wed Apr 16 16:08:45 2008
@@ -345,6 +345,69 @@
   Out << "@interface " 
       << PID->getClassInterface()->getName()
       << '(' << PID->getName() << ");\n";
+  // Output property declarations.
+  int NumProperties = PID->getNumPropertyDecl();
+  if (NumProperties > 0) {
+    for (int i = 0; i < NumProperties; i++) {
+      ObjCPropertyDecl *PDecl = PID->getPropertyDecl()[i];
+      Out << "@property";
+      if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) {
+        bool first = true;
+        Out << " (";
+        if (PDecl->getPropertyAttributes() & 
+            ObjCPropertyDecl::OBJC_PR_readonly) {
+          Out << (first ? ' ' : ',') << "readonly";
+          first = false;
+        }
+        
+        if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) {
+          Out << (first ? ' ' : ',') << "getter = "
+          << PDecl->getGetterName()->getName();
+          first = false;
+        }
+        if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) {
+          Out << (first ? ' ' : ',') << "setter = "
+          << PDecl->getSetterName()->getName();
+          first = false;
+        }
+        
+        if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) {
+          Out << (first ? ' ' : ',') << "assign";
+          first = false;
+        }
+        
+        if (PDecl->getPropertyAttributes() &
+            ObjCPropertyDecl::OBJC_PR_readwrite) {
+          Out << (first ? ' ' : ',') << "readwrite";
+          first = false;
+        }
+        
+        if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) {
+          Out << (first ? ' ' : ',') << "retain";
+          first = false;
+        }
+        
+        if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) {
+          Out << (first ? ' ' : ',') << "copy";
+          first = false;
+        }
+        
+        if (PDecl->getPropertyAttributes() & 
+            ObjCPropertyDecl::OBJC_PR_nonatomic) {
+          Out << (first ? ' ' : ',') << "nonatomic";
+          first = false;
+        }
+        Out << " )";
+      }
+      Out << ' ' << PDecl->getType().getAsString()
+      << ' ' << PDecl->getName();
+      
+      Out << ";\n";
+    }
+  }
+  
+  Out << "@end\n";
+  
   // FIXME: implement the rest...
 }
 

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Wed Apr 16 16:08:45 2008
@@ -672,6 +672,10 @@
   /// Next category belonging to this class
   ObjCCategoryDecl *NextClassCategory;
   
+  /// category properties
+  ObjCPropertyDecl **PropertyDecl;  // Null if no property
+  unsigned NumPropertyDecl;  // 0 if none  
+  
   SourceLocation EndLoc; // marks the '>' or identifier.
   SourceLocation AtEndLoc; // marks the end of the entire interface.
   
@@ -680,7 +684,7 @@
       ClassInterface(0), ReferencedProtocols(0), NumReferencedProtocols(0),
       InstanceMethods(0), NumInstanceMethods(0),
       ClassMethods(0), NumClassMethods(0),
-      NextClassCategory(0) {
+      NextClassCategory(0), PropertyDecl(0),  NumPropertyDecl(0) {
   }
 public:
   
@@ -705,6 +709,11 @@
   unsigned getNumInstanceMethods() const { return NumInstanceMethods; }
   unsigned getNumClassMethods() const { return NumClassMethods; }
 
+  void addProperties(ObjCPropertyDecl **Properties, unsigned NumProperties);
+  unsigned getNumPropertyDecl() const { return NumPropertyDecl; }
+  
+  ObjCPropertyDecl * const * getPropertyDecl() const { return PropertyDecl; }
+  
   typedef ObjCMethodDecl * const * instmeth_iterator;
   instmeth_iterator instmeth_begin() const { return InstanceMethods; }
   instmeth_iterator instmeth_end() const {

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

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Wed Apr 16 16:08:45 2008
@@ -185,8 +185,8 @@
   AtEndLoc = endLoc;
 }
 
-/// addMethods - Insert instance and methods declarations into
-/// ObjCInterfaceDecl's InsMethods and ClsMethods fields.
+/// addProperties - Insert property declaration AST nodes into
+/// ObjCInterfaceDecl's PropertyDecl field.
 ///
 void ObjCInterfaceDecl::addProperties(ObjCPropertyDecl **Properties, 
                                       unsigned NumProperties) {
@@ -197,6 +197,18 @@
   memcpy(PropertyDecl, Properties, NumProperties*sizeof(ObjCPropertyDecl*));
 }                                   
 
+/// addProperties - Insert property declaration AST nodes into
+/// ObjCProtocolDecl's PropertyDecl field.
+///
+void ObjCCategoryDecl::addProperties(ObjCPropertyDecl **Properties, 
+                                     unsigned NumProperties) {
+  if (NumProperties == 0) return;
+  
+  NumPropertyDecl = NumProperties;
+  PropertyDecl = new ObjCPropertyDecl*[NumProperties];
+  memcpy(PropertyDecl, Properties, NumProperties*sizeof(ObjCPropertyDecl*));
+}
+
 /// addMethods - Insert instance and methods declarations into
 /// ObjCProtocolDecl's ProtoInsMethods and ProtoClsMethods fields.
 ///

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Wed Apr 16 16:08:45 2008
@@ -699,6 +699,9 @@
   if (pNum != 0)
     if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl))
       IDecl->addProperties((ObjCPropertyDecl**)allProperties, pNum);
+    else
+      if (ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl))
+        CDecl->addProperties((ObjCPropertyDecl**)allProperties, pNum);
   
   for (unsigned i = 0; i < allNum; i++ ) {
     ObjCMethodDecl *Method =





More information about the cfe-commits mailing list