[cfe-commits] r49817 - in /cfe/trunk: Driver/ASTConsumers.cpp include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Sema/SemaDeclObjC.cpp
Chris Lattner
clattner at apple.com
Wed Apr 16 19:54:48 PDT 2008
On Apr 16, 2008, at 2:08 PM, Fariborz Jahanian wrote:
> 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.
Nice!
> 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 =
What if ClassDecl is neither an ObjCInterfaceDecl or a
ObjCCategoryDecl? Should there be an assert or error here?
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- 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 @@
> 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 {
>
This looks good, but please add an iterarator interface to this, just
like instmeth_begin/end and the iterators in InterfaceDecl.
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- 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];
Please use the iterator interface instead of getNumPropertyDecl/
getPropertyDecl. There is no need to check to see if NumProperties > 0.
>
> + Out << "@property";
Should all this code be split out to a helper function that takes an
ObjCPropertyDecl? This code should be generally shared with interfaces.
-Chris
More information about the cfe-commits
mailing list