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

Chris Lattner sabre at nondot.org
Sun Mar 16 18:19:02 PDT 2008


Author: lattner
Date: Sun Mar 16 20:19:02 2008
New Revision: 48434

URL: http://llvm.org/viewvc/llvm-project?rev=48434&view=rev
Log:
clean up property memory allocation to move it into the ast classes
like the rest of the classes.

Modified:
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Parse/ParseObjc.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=48434&r1=48433&r2=48434&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Sun Mar 16 20:19:02 2008
@@ -311,12 +311,12 @@
         Out << " )";
       }
       
-      ObjCIvarDecl **IDecl = PDecl->getPropertyDecls();
+      ObjCIvarDecl *const *IDecl = PDecl->getPropertyDecls();
       
       Out << ' ' << IDecl[0]->getType().getAsString()
           << ' ' << IDecl[0]->getName();
       
-      for (int j = 1; j < PDecl->getNumPropertyDecls(); j++)
+      for (unsigned j = 1; j < PDecl->getNumPropertyDecls(); j++)
         Out << ", " << IDecl[j]->getName();
 
       Out << ";\n";

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Sun Mar 16 20:19:02 2008
@@ -232,7 +232,7 @@
       NumIvars(0),
       InstanceMethods(0), NumInstanceMethods(-1), 
       ClassMethods(0), NumClassMethods(0),
-      CategoryList(0), PropertyDecl(0), NumPropertyDecl(-1),
+      CategoryList(0), PropertyDecl(0), NumPropertyDecl(0),
       ForwardDecl(FD), InternalInterface(isInternal) {
         AllocIntfRefProtocols(numRefProtos);
       }
@@ -337,7 +337,7 @@
   // We also need to record the @end location.
   SourceLocation getAtEndLoc() const { return AtEndLoc; }
   
-  int getNumPropertyDecl() const { return NumPropertyDecl; }
+  unsigned getNumPropertyDecl() const { return NumPropertyDecl; }
   
   ObjCPropertyDecl * const * getPropertyDecl() const { return PropertyDecl; }
   ObjCPropertyDecl **getPropertyDecl() { return PropertyDecl; }
@@ -908,31 +908,28 @@
   // List of property name declarations
   // FIXME: Property is not an ivar.
   ObjCIvarDecl **PropertyDecls;
-  int NumPropertyDecls;
-
-  // NOTE: VC++ treats enums as signed, avoid using PropertyAttributeKind enum
+  unsigned NumPropertyDecls;
   unsigned PropertyAttributes : 8;
   
   IdentifierInfo *GetterName;    // getter name of NULL if no getter
   IdentifierInfo *SetterName;    // setter name of NULL if no setter
   
   ObjCPropertyDecl(SourceLocation L)
-    : Decl(PropertyDecl, L), PropertyDecls(0), NumPropertyDecls(-1),
+    : Decl(PropertyDecl, L), PropertyDecls(0), NumPropertyDecls(0),
       PropertyAttributes(OBJC_PR_noattr), GetterName(0), SetterName(0) {}
 public:
   static ObjCPropertyDecl *Create(ASTContext &C, SourceLocation L);
   
-  ObjCIvarDecl **const getPropertyDecls() const { return PropertyDecls; }
-  void setPropertyDecls(ObjCIvarDecl **property) { PropertyDecls = property; }
-  
-  const int getNumPropertyDecls() const { return NumPropertyDecls; }
-  void setNumPropertyDecls(int num) { NumPropertyDecls = num; }
+  ObjCIvarDecl *const* getPropertyDecls() const { return PropertyDecls; }
+  unsigned getNumPropertyDecls() const { return NumPropertyDecls; }
+
+  void setPropertyDeclLists(ObjCIvarDecl **Properties, unsigned NumProp);
   
-  const PropertyAttributeKind getPropertyAttributes() const 
-    { return PropertyAttributeKind(PropertyAttributes); }
+  const PropertyAttributeKind getPropertyAttributes() const {
+    return PropertyAttributeKind(PropertyAttributes);
+  }
   void setPropertyAttributes(PropertyAttributeKind PRVal) { 
-    PropertyAttributes = 
-    (PropertyAttributeKind) (PropertyAttributes | PRVal);
+    PropertyAttributes =  (PropertyAttributeKind) (PropertyAttributes | PRVal);
   }
   
   const IdentifierInfo *getGetterName() const { return GetterName; }

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

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Sun Mar 16 20:19:02 2008
@@ -419,3 +419,15 @@
   assert(false && "unknown method context");
   return 0;
 }
+
+void ObjCPropertyDecl::setPropertyDeclLists(ObjCIvarDecl **Properties, 
+                                            unsigned NumProp) {
+  assert(PropertyDecls == 0 && "Properties already set");
+  if (NumProp == 0) return;
+  NumPropertyDecls = NumProp;
+
+  PropertyDecls = new ObjCIvarDecl*[NumProp];
+  memcpy(PropertyDecls, Properties, NumProp*sizeof(ObjCIvarDecl*));
+}
+
+

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

==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Sun Mar 16 20:19:02 2008
@@ -394,8 +394,8 @@
     Diag(Tok, diag::err_expected_semi_decl_list);
     SkipUntil(tok::r_brace, true, true);
   }
-  return Actions.ActOnAddObjCProperties(AtLoc, 
-           &PropertyDecls[0], PropertyDecls.size(), DS);
+  return Actions.ActOnAddObjCProperties(AtLoc,  &PropertyDecls[0],
+                                        PropertyDecls.size(), DS);
 }
 
 ///   objc-method-proto:

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sun Mar 16 20:19:02 2008
@@ -893,43 +893,42 @@
 }
 
 Sema::DeclTy *Sema::ActOnAddObjCProperties(SourceLocation AtLoc, 
-  DeclTy **allProperties, unsigned NumProperties, ObjCDeclSpec &DS) {
+                                           DeclTy **allProperties,
+                                           unsigned NumProperties, 
+                                           ObjCDeclSpec &DS) {
   ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, AtLoc);
   
-  if(DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_readonly)
+  if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_readonly)
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly);
   
-  if(DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_getter) {
+  if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_getter) {
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_getter);
     PDecl->setGetterName(DS.getGetterName());
   }
   
-  if(DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_setter) {
+  if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_setter) {
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_setter);
     PDecl->setSetterName(DS.getSetterName());
   }
   
-  if(DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_assign)
+  if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_assign)
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign);
   
-  if(DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_readwrite)
+  if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_readwrite)
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite);
   
-  if(DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_retain)
+  if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_retain)
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain);
   
-  if(DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_copy)
+  if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_copy)
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy);
   
-  if(DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_nonatomic)
+  if (DS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_nonatomic)
     PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic);
   
-  PDecl->setNumPropertyDecls(NumProperties);
-  if (NumProperties != 0) {
-    ObjCIvarDecl **properties = new ObjCIvarDecl*[NumProperties];
-    memcpy(properties, allProperties, NumProperties*sizeof(ObjCIvarDecl*));
-    PDecl->setPropertyDecls(properties);
-  }
+  if (NumProperties != 0)
+    PDecl->setPropertyDeclLists((ObjCIvarDecl**)allProperties, NumProperties);
+  
   return PDecl;
 }
 





More information about the cfe-commits mailing list