diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2008-04-16 21:08:45 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2008-04-16 21:08:45 +0000 |
commit | 7e7e3872b584bc5e7de7a34c8b9c092032303b72 (patch) | |
tree | dcb84f600af86a0976de97cb47f320b6fc605ebb | |
parent | 678c6358c8d4e368c78629099142397c63c1ee35 (diff) |
This patch adds support for declaraing properties in categories,
just as they are declared in objc classes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49817 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | Driver/ASTConsumers.cpp | 63 | ||||
-rw-r--r-- | include/clang/AST/DeclObjC.h | 11 | ||||
-rw-r--r-- | lib/AST/DeclObjC.cpp | 16 | ||||
-rw-r--r-- | lib/Sema/SemaDeclObjC.cpp | 3 |
4 files changed, 90 insertions, 3 deletions
diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index 16299c46c4..596fefc8e5 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -345,6 +345,69 @@ void DeclPrinter::PrintObjCCategoryDecl(ObjCCategoryDecl *PID) { 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... } diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index bed6ac5812..89261d9f53 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -672,6 +672,10 @@ class ObjCCategoryDecl : public NamedDecl { /// 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 @@ class ObjCCategoryDecl : public NamedDecl { 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 @@ public: 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 { diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 7a99f0f549..c9c5132e29 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -185,8 +185,8 @@ void ObjCInterfaceDecl::addMethods(ObjCMethodDecl **insMethods, 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 @@ void ObjCInterfaceDecl::addProperties(ObjCPropertyDecl **Properties, 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. /// diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index bf9af85a6c..3b6f8eccdb 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -699,6 +699,9 @@ void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, 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 = |