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

Chris Lattner sabre at nondot.org
Sun Mar 16 14:23:50 PDT 2008


Author: lattner
Date: Sun Mar 16 16:23:50 2008
New Revision: 48433

URL: http://llvm.org/viewvc/llvm-project?rev=48433&view=rev
Log:
make property addition work list all other "add" methods.  Do 
the allocation in the class, not in sema.

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

Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=48433&r1=48432&r2=48433&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Sun Mar 16 16:23:50 2008
@@ -146,7 +146,7 @@
     void RewriteProtocolDecl(ObjCProtocolDecl *Dcl);
     void RewriteForwardProtocolDecl(ObjCForwardProtocolDecl *Dcl);
     void RewriteMethodDeclaration(ObjCMethodDecl *Method);
-    void RewriteProperties(int nProperties, ObjCPropertyDecl **Properties);
+    void RewriteProperties(unsigned nProperties, ObjCPropertyDecl **Properties);
     void RewriteFunctionDecl(FunctionDecl *FD);
     void RewriteObjCQualifiedInterfaceTypes(Decl *Dcl);
     bool needToScanForQualifiers(QualType T);
@@ -549,9 +549,9 @@
   }
 }
 
-void RewriteTest::RewriteProperties(int nProperties, ObjCPropertyDecl **Properties) 
+void RewriteTest::RewriteProperties(unsigned nProperties, ObjCPropertyDecl **Properties) 
 {
-  for (int i = 0; i < nProperties; i++) {
+  for (unsigned i = 0; i < nProperties; i++) {
     ObjCPropertyDecl *Property = Properties[i];
     SourceLocation Loc = Property->getLocation();
     

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Sun Mar 16 16:23:50 2008
@@ -217,7 +217,7 @@
     
   /// class properties
   ObjCPropertyDecl **PropertyDecl;  // Null if no property
-  int NumPropertyDecl;  // -1 if no property
+  unsigned NumPropertyDecl;  // 0 if none.
   
   bool ForwardDecl:1; // declared with @class.
   bool InternalInterface:1; // true - no @interface for @implementation
@@ -285,6 +285,9 @@
                   ObjCMethodDecl **clsMethods, unsigned numClsMembers,
                   SourceLocation AtEnd);
   
+  void addProperties(ObjCPropertyDecl **Properties, unsigned NumProperties);
+  
+  
   bool isForwardDecl() const { return ForwardDecl; }
   void setForwardDecl(bool val) { ForwardDecl = val; }
   
@@ -335,13 +338,9 @@
   SourceLocation getAtEndLoc() const { return AtEndLoc; }
   
   int getNumPropertyDecl() const { return NumPropertyDecl; }
-  void setNumPropertyDecl(int num) { NumPropertyDecl = num; }
   
-  ObjCPropertyDecl **const getPropertyDecl() const { return PropertyDecl; }
+  ObjCPropertyDecl * const * getPropertyDecl() const { return PropertyDecl; }
   ObjCPropertyDecl **getPropertyDecl() { return PropertyDecl; }
-  void setPropertyDecls(ObjCPropertyDecl **properties) { 
-    PropertyDecl = properties; 
-  }
 
   /// ImplicitInterfaceDecl - check that this is an implicitely declared
   /// ObjCInterfaceDecl node. This is for legacy objective-c @implementation

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

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Sun Mar 16 16:23:50 2008
@@ -171,6 +171,18 @@
 }
 
 /// addMethods - Insert instance and methods declarations into
+/// ObjCInterfaceDecl's InsMethods and ClsMethods fields.
+///
+void ObjCInterfaceDecl::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.
 ///
 void ObjCProtocolDecl::addMethods(ObjCMethodDecl **insMethods, 

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sun Mar 16 16:23:50 2008
@@ -705,13 +705,8 @@
   
   // TODO: property declaration in category and protocols.
   if (pNum != 0)
-    if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
-      // FIXME: Move the memory allocation into setPropertyDecls!
-      ObjCPropertyDecl **properties = new ObjCPropertyDecl*[pNum];
-      memcpy(properties, allProperties, pNum*sizeof(ObjCPropertyDecl*));
-      IDecl->setPropertyDecls(properties);
-      IDecl->setNumPropertyDecl(pNum);
-    }
+    if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl))
+      IDecl->addProperties((ObjCPropertyDecl**)allProperties, pNum);
   
   for (unsigned i = 0; i < allNum; i++ ) {
     ObjCMethodDecl *Method =





More information about the cfe-commits mailing list