From: Chris Lattner Date: Mon, 17 Mar 2008 01:19:02 +0000 (+0000) Subject: clean up property memory allocation to move it into the ast classes X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f4af5154571e0c5eadb19df10e65464766ef6683;p=clang clean up property memory allocation to move it into the ast classes like the rest of the classes. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48434 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index 0dc6692945..da20557b1d 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -311,12 +311,12 @@ void DeclPrinter::PrintObjCInterfaceDecl(ObjCInterfaceDecl *OID) { 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"; diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 0e49101e3c..e74d5b4676 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -232,7 +232,7 @@ class ObjCInterfaceDecl : public TypeDecl { 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 @@ public: // 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 @@ private: // 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; } diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index afc3aa1959..2e3a06a956 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -419,3 +419,15 @@ ObjCInterfaceDecl *const ObjCMethodDecl::getClassInterface() const { 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*)); +} + + diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 7345abed99..dfd00ec420 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -394,8 +394,8 @@ Parser::DeclTy *Parser::ParseObjCPropertyDecl(DeclTy *interfaceDecl, 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: diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 335122ebfa..1270653499 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -893,43 +893,42 @@ Sema::DeclTy *Sema::ActOnMethodDeclaration( } 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; }