Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1 | //===--- SemaDeclObjC.cpp - Semantic Analysis for ObjC Declarations -------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements semantic analysis for Objective C declarations. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "Sema.h" |
| 15 | #include "clang/AST/ASTContext.h" |
| 16 | #include "clang/AST/DeclObjC.h" |
| 17 | #include "clang/Parse/Scope.h" |
| 18 | |
| 19 | using namespace clang; |
| 20 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 21 | /// ObjCActOnStartOfMethodDef - This routine sets up parameters; invisible |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 22 | /// and user declared, in the method definition's AST. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 23 | void Sema::ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 24 | assert(CurFunctionDecl == 0 && "Method parsing confused"); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 25 | ObjCMethodDecl *MDecl = dyn_cast<ObjCMethodDecl>(static_cast<Decl *>(D)); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 26 | assert(MDecl != 0 && "Not a method declarator!"); |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 27 | |
| 28 | // Allow the rest of sema to find private method decl implementations. |
| 29 | if (MDecl->isInstance()) |
| 30 | AddInstanceMethodToGlobalPool(MDecl); |
| 31 | else |
| 32 | AddFactoryMethodToGlobalPool(MDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 33 | |
| 34 | // Allow all of Sema to see that we are entering a method definition. |
| 35 | CurMethodDecl = MDecl; |
Chris Lattner | b048c98 | 2008-04-06 04:47:34 +0000 | [diff] [blame] | 36 | PushDeclContext(MDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 37 | |
| 38 | // Create Decl objects for each parameter, entrring them in the scope for |
| 39 | // binding to their use. |
| 40 | struct DeclaratorChunk::ParamInfo PI; |
| 41 | |
| 42 | // Insert the invisible arguments, self and _cmd! |
| 43 | PI.Ident = &Context.Idents.get("self"); |
| 44 | PI.IdentLoc = SourceLocation(); // synthesized vars have a null location. |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 45 | QualType selfTy = Context.getObjCIdType(); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 46 | if (MDecl->isInstance()) { |
Gabor Greif | 3003753 | 2008-02-29 20:35:55 +0000 | [diff] [blame] | 47 | if (ObjCInterfaceDecl *OID = MDecl->getClassInterface()) { |
| 48 | // There may be no interface context due to error in declaration of the |
| 49 | // interface (which has been reported). Recover gracefully |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 50 | selfTy = Context.getObjCInterfaceType(OID); |
Fariborz Jahanian | 20552d2 | 2008-01-10 20:33:58 +0000 | [diff] [blame] | 51 | selfTy = Context.getPointerType(selfTy); |
Fariborz Jahanian | 20552d2 | 2008-01-10 20:33:58 +0000 | [diff] [blame] | 52 | } |
Gabor Greif | 3003753 | 2008-02-29 20:35:55 +0000 | [diff] [blame] | 53 | } |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 54 | CurMethodDecl->setSelfDecl(CreateImplicitParameter(FnBodyScope, PI.Ident, |
| 55 | PI.IdentLoc, selfTy)); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 56 | |
| 57 | PI.Ident = &Context.Idents.get("_cmd"); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 58 | CreateImplicitParameter(FnBodyScope, PI.Ident, PI.IdentLoc, |
| 59 | Context.getObjCSelType()); |
| 60 | |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 61 | // Introduce all of the other parameters into this scope. |
Chris Lattner | 58cce3b | 2008-03-16 01:07:14 +0000 | [diff] [blame] | 62 | for (unsigned i = 0, e = MDecl->getNumParams(); i != e; ++i) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 63 | ParmVarDecl *PDecl = MDecl->getParamDecl(i); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 64 | IdentifierInfo *II = PDecl->getIdentifier(); |
| 65 | if (II) { |
Chris Lattner | 7f925cc | 2008-04-11 07:00:53 +0000 | [diff] [blame] | 66 | IdResolver.AddDecl(PDecl, FnBodyScope); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 67 | FnBodyScope->AddDecl(PDecl); |
| 68 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | Sema::DeclTy *Sema::ActOnStartClassInterface( |
| 73 | SourceLocation AtInterfaceLoc, |
| 74 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 75 | IdentifierInfo *SuperName, SourceLocation SuperLoc, |
| 76 | IdentifierInfo **ProtocolNames, unsigned NumProtocols, |
| 77 | SourceLocation EndProtoLoc, AttributeList *AttrList) { |
| 78 | assert(ClassName && "Missing class identifier"); |
| 79 | |
| 80 | // Check for another declaration kind with the same name. |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 81 | Decl *PrevDecl = LookupDecl(ClassName, Decl::IDNS_Ordinary, TUScope); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 82 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 83 | Diag(ClassLoc, diag::err_redefinition_different_kind, |
| 84 | ClassName->getName()); |
| 85 | Diag(PrevDecl->getLocation(), diag::err_previous_definition); |
| 86 | } |
| 87 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 88 | ObjCInterfaceDecl* IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 89 | if (IDecl) { |
| 90 | // Class already seen. Is it a forward declaration? |
| 91 | if (!IDecl->isForwardDecl()) |
| 92 | Diag(AtInterfaceLoc, diag::err_duplicate_class_def, IDecl->getName()); |
| 93 | else { |
| 94 | IDecl->setLocation(AtInterfaceLoc); |
| 95 | IDecl->setForwardDecl(false); |
| 96 | IDecl->AllocIntfRefProtocols(NumProtocols); |
| 97 | } |
| 98 | } |
| 99 | else { |
Chris Lattner | 0e77ba0 | 2008-03-16 01:15:50 +0000 | [diff] [blame] | 100 | IDecl = ObjCInterfaceDecl::Create(Context, AtInterfaceLoc, NumProtocols, |
Steve Naroff | d6a07aa | 2008-04-11 19:35:35 +0000 | [diff] [blame] | 101 | ClassName, ClassLoc); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 102 | |
Steve Naroff | 3110251 | 2008-04-02 18:30:49 +0000 | [diff] [blame] | 103 | ObjCInterfaceDecls[ClassName] = IDecl; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 104 | // Remember that this needs to be removed when the scope is popped. |
| 105 | TUScope->AddDecl(IDecl); |
| 106 | } |
| 107 | |
| 108 | if (SuperName) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 109 | ObjCInterfaceDecl* SuperClassEntry = 0; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 110 | // Check if a different kind of symbol declared in this scope. |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 111 | PrevDecl = LookupDecl(SuperName, Decl::IDNS_Ordinary, TUScope); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 112 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 113 | Diag(SuperLoc, diag::err_redefinition_different_kind, |
| 114 | SuperName->getName()); |
| 115 | Diag(PrevDecl->getLocation(), diag::err_previous_definition); |
| 116 | } |
| 117 | else { |
| 118 | // Check that super class is previously defined |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 119 | SuperClassEntry = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 120 | |
| 121 | if (!SuperClassEntry || SuperClassEntry->isForwardDecl()) { |
| 122 | Diag(AtInterfaceLoc, diag::err_undef_superclass, |
| 123 | SuperClassEntry ? SuperClassEntry->getName() |
| 124 | : SuperName->getName(), |
| 125 | ClassName->getName()); |
| 126 | } |
| 127 | } |
| 128 | IDecl->setSuperClass(SuperClassEntry); |
Steve Naroff | d6a07aa | 2008-04-11 19:35:35 +0000 | [diff] [blame] | 129 | IDecl->setSuperClassLoc(SuperLoc); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 130 | IDecl->setLocEnd(SuperLoc); |
| 131 | } else { // we have a root class. |
| 132 | IDecl->setLocEnd(ClassLoc); |
| 133 | } |
| 134 | |
| 135 | /// Check then save referenced protocols |
| 136 | if (NumProtocols) { |
| 137 | for (unsigned int i = 0; i != NumProtocols; i++) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 138 | ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtocolNames[i]]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 139 | if (!RefPDecl || RefPDecl->isForwardDecl()) |
| 140 | Diag(ClassLoc, diag::warn_undef_protocolref, |
| 141 | ProtocolNames[i]->getName(), |
| 142 | ClassName->getName()); |
Fariborz Jahanian | c395bda | 2007-12-20 19:24:10 +0000 | [diff] [blame] | 143 | IDecl->setIntfRefProtocols(i, RefPDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 144 | } |
| 145 | IDecl->setLocEnd(EndProtoLoc); |
| 146 | } |
| 147 | return IDecl; |
| 148 | } |
| 149 | |
| 150 | /// ActOnCompatiblityAlias - this action is called after complete parsing of |
| 151 | /// @compaatibility_alias declaration. It sets up the alias relationships. |
Steve Naroff | e8043c3 | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 152 | Sema::DeclTy *Sema::ActOnCompatiblityAlias(SourceLocation AtLoc, |
| 153 | IdentifierInfo *AliasName, |
| 154 | SourceLocation AliasLocation, |
| 155 | IdentifierInfo *ClassName, |
| 156 | SourceLocation ClassLocation) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 157 | // Look for previous declaration of alias name |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 158 | Decl *ADecl = LookupDecl(AliasName, Decl::IDNS_Ordinary, TUScope); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 159 | if (ADecl) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 160 | if (isa<ObjCCompatibleAliasDecl>(ADecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 161 | Diag(AliasLocation, diag::warn_previous_alias_decl); |
| 162 | Diag(ADecl->getLocation(), diag::warn_previous_declaration); |
| 163 | } |
| 164 | else { |
| 165 | Diag(AliasLocation, diag::err_conflicting_aliasing_type, |
| 166 | AliasName->getName()); |
| 167 | Diag(ADecl->getLocation(), diag::err_previous_declaration); |
| 168 | } |
| 169 | return 0; |
| 170 | } |
| 171 | // Check for class declaration |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 172 | Decl *CDeclU = LookupDecl(ClassName, Decl::IDNS_Ordinary, TUScope); |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 173 | ObjCInterfaceDecl *CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDeclU); |
| 174 | if (CDecl == 0) { |
| 175 | Diag(ClassLocation, diag::warn_undef_interface, ClassName->getName()); |
| 176 | if (CDeclU) |
| 177 | Diag(CDeclU->getLocation(), diag::warn_previous_declaration); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 178 | return 0; |
| 179 | } |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 180 | |
| 181 | // Everything checked out, instantiate a new alias declaration AST. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 182 | ObjCCompatibleAliasDecl *AliasDecl = |
Steve Naroff | e8043c3 | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 183 | ObjCCompatibleAliasDecl::Create(Context, AtLoc, AliasName, CDecl); |
| 184 | |
| 185 | ObjCAliasDecls[AliasName] = AliasDecl; |
| 186 | TUScope->AddDecl(AliasDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 187 | return AliasDecl; |
| 188 | } |
| 189 | |
| 190 | Sema::DeclTy *Sema::ActOnStartProtocolInterface( |
| 191 | SourceLocation AtProtoInterfaceLoc, |
| 192 | IdentifierInfo *ProtocolName, SourceLocation ProtocolLoc, |
| 193 | IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs, |
| 194 | SourceLocation EndProtoLoc) { |
| 195 | assert(ProtocolName && "Missing protocol identifier"); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 196 | ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolName]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 197 | if (PDecl) { |
| 198 | // Protocol already seen. Better be a forward protocol declaration |
Chris Lattner | 439e71f | 2008-03-16 01:25:17 +0000 | [diff] [blame] | 199 | if (!PDecl->isForwardDecl()) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 200 | Diag(ProtocolLoc, diag::err_duplicate_protocol_def, |
| 201 | ProtocolName->getName()); |
Chris Lattner | 439e71f | 2008-03-16 01:25:17 +0000 | [diff] [blame] | 202 | // Just return the protocol we already had. |
| 203 | // FIXME: don't leak the objects passed in! |
| 204 | return PDecl; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 205 | } |
Chris Lattner | 439e71f | 2008-03-16 01:25:17 +0000 | [diff] [blame] | 206 | |
| 207 | PDecl->setForwardDecl(false); |
| 208 | PDecl->AllocReferencedProtocols(NumProtoRefs); |
| 209 | } else { |
Chris Lattner | cca59d7 | 2008-03-16 01:23:04 +0000 | [diff] [blame] | 210 | PDecl = ObjCProtocolDecl::Create(Context, AtProtoInterfaceLoc, NumProtoRefs, |
Chris Lattner | c858105 | 2008-03-16 20:19:15 +0000 | [diff] [blame] | 211 | ProtocolName); |
| 212 | PDecl->setForwardDecl(false); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 213 | ObjCProtocols[ProtocolName] = PDecl; |
Chris Lattner | cca59d7 | 2008-03-16 01:23:04 +0000 | [diff] [blame] | 214 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 215 | |
| 216 | if (NumProtoRefs) { |
Chris Lattner | c858105 | 2008-03-16 20:19:15 +0000 | [diff] [blame] | 217 | /// Check then save referenced protocols. |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 218 | for (unsigned int i = 0; i != NumProtoRefs; i++) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 219 | ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtoRefNames[i]]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 220 | if (!RefPDecl || RefPDecl->isForwardDecl()) |
| 221 | Diag(ProtocolLoc, diag::warn_undef_protocolref, |
| 222 | ProtoRefNames[i]->getName(), |
| 223 | ProtocolName->getName()); |
Fariborz Jahanian | c395bda | 2007-12-20 19:24:10 +0000 | [diff] [blame] | 224 | PDecl->setReferencedProtocols(i, RefPDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 225 | } |
| 226 | PDecl->setLocEnd(EndProtoLoc); |
| 227 | } |
| 228 | return PDecl; |
| 229 | } |
| 230 | |
| 231 | /// FindProtocolDeclaration - This routine looks up protocols and |
| 232 | /// issuer error if they are not declared. It returns list of protocol |
| 233 | /// declarations in its 'Protocols' argument. |
| 234 | void |
| 235 | Sema::FindProtocolDeclaration(SourceLocation TypeLoc, |
| 236 | IdentifierInfo **ProtocolId, |
| 237 | unsigned NumProtocols, |
| 238 | llvm::SmallVector<DeclTy *,8> &Protocols) { |
| 239 | for (unsigned i = 0; i != NumProtocols; ++i) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 240 | ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolId[i]]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 241 | if (!PDecl) |
| 242 | Diag(TypeLoc, diag::err_undeclared_protocol, |
| 243 | ProtocolId[i]->getName()); |
| 244 | else |
| 245 | Protocols.push_back(PDecl); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /// ActOnForwardProtocolDeclaration - |
| 250 | Action::DeclTy * |
| 251 | Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, |
| 252 | IdentifierInfo **IdentList, unsigned NumElts) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 253 | llvm::SmallVector<ObjCProtocolDecl*, 32> Protocols; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 254 | |
| 255 | for (unsigned i = 0; i != NumElts; ++i) { |
Chris Lattner | c858105 | 2008-03-16 20:19:15 +0000 | [diff] [blame] | 256 | IdentifierInfo *Ident = IdentList[i]; |
| 257 | ObjCProtocolDecl *&PDecl = ObjCProtocols[Ident]; |
| 258 | if (PDecl == 0) { // Not already seen? |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 259 | // FIXME: Pass in the location of the identifier! |
Chris Lattner | c858105 | 2008-03-16 20:19:15 +0000 | [diff] [blame] | 260 | PDecl = ObjCProtocolDecl::Create(Context, AtProtocolLoc, 0, Ident); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | Protocols.push_back(PDecl); |
| 264 | } |
Chris Lattner | 61f9d41 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 265 | return ObjCForwardProtocolDecl::Create(Context, AtProtocolLoc, |
| 266 | &Protocols[0], Protocols.size()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | Sema::DeclTy *Sema::ActOnStartCategoryInterface( |
| 270 | SourceLocation AtInterfaceLoc, |
| 271 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 272 | IdentifierInfo *CategoryName, SourceLocation CategoryLoc, |
| 273 | IdentifierInfo **ProtoRefNames, unsigned NumProtoRefs, |
| 274 | SourceLocation EndProtoLoc) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 275 | ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 276 | |
Chris Lattner | 61f9d41 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 277 | ObjCCategoryDecl *CDecl = |
Chris Lattner | 68c82cf | 2008-03-16 20:47:45 +0000 | [diff] [blame] | 278 | ObjCCategoryDecl::Create(Context, AtInterfaceLoc, CategoryName); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 279 | CDecl->setClassInterface(IDecl); |
Fariborz Jahanian | 7c453b3 | 2008-01-17 20:33:24 +0000 | [diff] [blame] | 280 | |
| 281 | /// Check that class of this category is already completely declared. |
| 282 | if (!IDecl || IDecl->isForwardDecl()) |
| 283 | Diag(ClassLoc, diag::err_undef_interface, ClassName->getName()); |
| 284 | else { |
| 285 | /// Check for duplicate interface declaration for this category |
| 286 | ObjCCategoryDecl *CDeclChain; |
| 287 | for (CDeclChain = IDecl->getCategoryList(); CDeclChain; |
| 288 | CDeclChain = CDeclChain->getNextClassCategory()) { |
| 289 | if (CDeclChain->getIdentifier() == CategoryName) { |
| 290 | Diag(CategoryLoc, diag::err_dup_category_def, ClassName->getName(), |
| 291 | CategoryName->getName()); |
| 292 | break; |
| 293 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 294 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 295 | if (!CDeclChain) |
| 296 | CDecl->insertNextClassCategory(); |
Fariborz Jahanian | 7c453b3 | 2008-01-17 20:33:24 +0000 | [diff] [blame] | 297 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 298 | |
| 299 | if (NumProtoRefs) { |
Chris Lattner | 68c82cf | 2008-03-16 20:47:45 +0000 | [diff] [blame] | 300 | llvm::SmallVector<ObjCProtocolDecl*, 32> RefProtocols; |
| 301 | /// Check and then save the referenced protocols. |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 302 | for (unsigned int i = 0; i != NumProtoRefs; i++) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 303 | ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtoRefNames[i]]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 304 | if (!RefPDecl || RefPDecl->isForwardDecl()) { |
| 305 | Diag(CategoryLoc, diag::warn_undef_protocolref, |
| 306 | ProtoRefNames[i]->getName(), |
| 307 | CategoryName->getName()); |
| 308 | } |
Chris Lattner | 68c82cf | 2008-03-16 20:47:45 +0000 | [diff] [blame] | 309 | if (RefPDecl) |
| 310 | RefProtocols.push_back(RefPDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 311 | } |
Chris Lattner | 68c82cf | 2008-03-16 20:47:45 +0000 | [diff] [blame] | 312 | if (!RefProtocols.empty()) |
| 313 | CDecl->setReferencedProtocolList(&RefProtocols[0], RefProtocols.size()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 314 | } |
Chris Lattner | 68c82cf | 2008-03-16 20:47:45 +0000 | [diff] [blame] | 315 | CDecl->setLocEnd(EndProtoLoc); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 316 | return CDecl; |
| 317 | } |
| 318 | |
| 319 | /// ActOnStartCategoryImplementation - Perform semantic checks on the |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 320 | /// category implementation declaration and build an ObjCCategoryImplDecl |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 321 | /// object. |
| 322 | Sema::DeclTy *Sema::ActOnStartCategoryImplementation( |
| 323 | SourceLocation AtCatImplLoc, |
| 324 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 325 | IdentifierInfo *CatName, SourceLocation CatLoc) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 326 | ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName); |
Chris Lattner | 75c9cae | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 327 | ObjCCategoryImplDecl *CDecl = |
| 328 | ObjCCategoryImplDecl::Create(Context, AtCatImplLoc, CatName, IDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 329 | /// Check that class of this category is already completely declared. |
| 330 | if (!IDecl || IDecl->isForwardDecl()) |
| 331 | Diag(ClassLoc, diag::err_undef_interface, ClassName->getName()); |
| 332 | |
| 333 | /// TODO: Check that CatName, category name, is not used in another |
| 334 | // implementation. |
| 335 | return CDecl; |
| 336 | } |
| 337 | |
| 338 | Sema::DeclTy *Sema::ActOnStartClassImplementation( |
| 339 | SourceLocation AtClassImplLoc, |
| 340 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 341 | IdentifierInfo *SuperClassname, |
| 342 | SourceLocation SuperClassLoc) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 343 | ObjCInterfaceDecl* IDecl = 0; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 344 | // Check for another declaration kind with the same name. |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 345 | Decl *PrevDecl = LookupDecl(ClassName, Decl::IDNS_Ordinary, TUScope); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 346 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 347 | Diag(ClassLoc, diag::err_redefinition_different_kind, |
| 348 | ClassName->getName()); |
| 349 | Diag(PrevDecl->getLocation(), diag::err_previous_definition); |
| 350 | } |
| 351 | else { |
| 352 | // Is there an interface declaration of this class; if not, warn! |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 353 | IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 354 | if (!IDecl) |
| 355 | Diag(ClassLoc, diag::warn_undef_interface, ClassName->getName()); |
| 356 | } |
| 357 | |
| 358 | // Check that super class name is valid class name |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 359 | ObjCInterfaceDecl* SDecl = 0; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 360 | if (SuperClassname) { |
| 361 | // Check if a different kind of symbol declared in this scope. |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 362 | PrevDecl = LookupDecl(SuperClassname, Decl::IDNS_Ordinary, TUScope); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 363 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 364 | Diag(SuperClassLoc, diag::err_redefinition_different_kind, |
| 365 | SuperClassname->getName()); |
| 366 | Diag(PrevDecl->getLocation(), diag::err_previous_definition); |
| 367 | } |
| 368 | else { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 369 | SDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 370 | if (!SDecl) |
| 371 | Diag(SuperClassLoc, diag::err_undef_superclass, |
| 372 | SuperClassname->getName(), ClassName->getName()); |
| 373 | else if (IDecl && IDecl->getSuperClass() != SDecl) { |
| 374 | // This implementation and its interface do not have the same |
| 375 | // super class. |
| 376 | Diag(SuperClassLoc, diag::err_conflicting_super_class, |
| 377 | SDecl->getName()); |
| 378 | Diag(SDecl->getLocation(), diag::err_previous_definition); |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | if (!IDecl) { |
| 384 | // Legacy case of @implementation with no corresponding @interface. |
| 385 | // Build, chain & install the interface decl into the identifier. |
Chris Lattner | 0e77ba0 | 2008-03-16 01:15:50 +0000 | [diff] [blame] | 386 | IDecl = ObjCInterfaceDecl::Create(Context, AtClassImplLoc, 0, ClassName, |
Steve Naroff | d6a07aa | 2008-04-11 19:35:35 +0000 | [diff] [blame] | 387 | ClassLoc, false, true); |
Steve Naroff | 3110251 | 2008-04-02 18:30:49 +0000 | [diff] [blame] | 388 | ObjCInterfaceDecls[ClassName] = IDecl; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 389 | IDecl->setSuperClass(SDecl); |
| 390 | IDecl->setLocEnd(ClassLoc); |
| 391 | |
| 392 | // Remember that this needs to be removed when the scope is popped. |
| 393 | TUScope->AddDecl(IDecl); |
| 394 | } |
| 395 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 396 | ObjCImplementationDecl* IMPDecl = |
Chris Lattner | 75c9cae | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 397 | ObjCImplementationDecl::Create(Context, AtClassImplLoc, ClassName, |
| 398 | IDecl, SDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 399 | |
| 400 | // Check that there is no duplicate implementation of this class. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 401 | if (ObjCImplementations[ClassName]) |
Chris Lattner | 75c9cae | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 402 | // FIXME: Don't leak everything! |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 403 | Diag(ClassLoc, diag::err_dup_implementation_class, ClassName->getName()); |
| 404 | else // add it to the list. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 405 | ObjCImplementations[ClassName] = IMPDecl; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 406 | return IMPDecl; |
| 407 | } |
| 408 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 409 | void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
| 410 | ObjCIvarDecl **ivars, unsigned numIvars, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 411 | SourceLocation RBrace) { |
| 412 | assert(ImpDecl && "missing implementation decl"); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 413 | ObjCInterfaceDecl* IDecl = getObjCInterfaceDecl(ImpDecl->getIdentifier()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 414 | if (!IDecl) |
| 415 | return; |
| 416 | /// Check case of non-existing @interface decl. |
| 417 | /// (legacy objective-c @implementation decl without an @interface decl). |
| 418 | /// Add implementations's ivar to the synthesize class's ivar list. |
| 419 | if (IDecl->ImplicitInterfaceDecl()) { |
| 420 | IDecl->addInstanceVariablesToClass(ivars, numIvars, RBrace); |
| 421 | return; |
| 422 | } |
| 423 | // If implementation has empty ivar list, just return. |
| 424 | if (numIvars == 0) |
| 425 | return; |
| 426 | |
| 427 | assert(ivars && "missing @implementation ivars"); |
| 428 | |
| 429 | // Check interface's Ivar list against those in the implementation. |
| 430 | // names and types must match. |
| 431 | // |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 432 | unsigned j = 0; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 433 | ObjCInterfaceDecl::ivar_iterator |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 434 | IVI = IDecl->ivar_begin(), IVE = IDecl->ivar_end(); |
| 435 | for (; numIvars > 0 && IVI != IVE; ++IVI) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 436 | ObjCIvarDecl* ImplIvar = ivars[j++]; |
| 437 | ObjCIvarDecl* ClsIvar = *IVI; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 438 | assert (ImplIvar && "missing implementation ivar"); |
| 439 | assert (ClsIvar && "missing class ivar"); |
| 440 | if (ImplIvar->getCanonicalType() != ClsIvar->getCanonicalType()) { |
| 441 | Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_type, |
| 442 | ImplIvar->getIdentifier()->getName()); |
| 443 | Diag(ClsIvar->getLocation(), diag::err_previous_definition, |
| 444 | ClsIvar->getIdentifier()->getName()); |
| 445 | } |
| 446 | // TODO: Two mismatched (unequal width) Ivar bitfields should be diagnosed |
| 447 | // as error. |
| 448 | else if (ImplIvar->getIdentifier() != ClsIvar->getIdentifier()) { |
| 449 | Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_name, |
| 450 | ImplIvar->getIdentifier()->getName()); |
| 451 | Diag(ClsIvar->getLocation(), diag::err_previous_definition, |
| 452 | ClsIvar->getIdentifier()->getName()); |
Chris Lattner | 609e4c7 | 2007-12-12 18:11:49 +0000 | [diff] [blame] | 453 | return; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 454 | } |
| 455 | --numIvars; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 456 | } |
Chris Lattner | 609e4c7 | 2007-12-12 18:11:49 +0000 | [diff] [blame] | 457 | |
| 458 | if (numIvars > 0) |
Chris Lattner | 0e39105 | 2007-12-12 18:19:52 +0000 | [diff] [blame] | 459 | Diag(ivars[j]->getLocation(), diag::err_inconsistant_ivar_count); |
Chris Lattner | 609e4c7 | 2007-12-12 18:11:49 +0000 | [diff] [blame] | 460 | else if (IVI != IVE) |
Chris Lattner | 0e39105 | 2007-12-12 18:19:52 +0000 | [diff] [blame] | 461 | Diag((*IVI)->getLocation(), diag::err_inconsistant_ivar_count); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 464 | void Sema::WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, |
| 465 | bool &IncompleteImpl) { |
| 466 | if (!IncompleteImpl) { |
| 467 | Diag(ImpLoc, diag::warn_incomplete_impl); |
| 468 | IncompleteImpl = true; |
| 469 | } |
| 470 | Diag(ImpLoc, diag::warn_undef_method_impl, method->getSelector().getName()); |
| 471 | } |
| 472 | |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 473 | /// CheckProtocolMethodDefs - This routine checks unimplemented methods |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 474 | /// Declared in protocol, and those referenced by it. |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 475 | void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc, |
| 476 | ObjCProtocolDecl *PDecl, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 477 | bool& IncompleteImpl, |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 478 | const llvm::DenseSet<Selector> &InsMap, |
| 479 | const llvm::DenseSet<Selector> &ClsMap) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 480 | // check unimplemented instance methods. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 481 | for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(), |
Steve Naroff | 58dbdeb | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 482 | E = PDecl->instmeth_end(); I != E; ++I) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 483 | ObjCMethodDecl *method = *I; |
Steve Naroff | 58dbdeb | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 484 | if (!InsMap.count(method->getSelector()) && |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 485 | method->getImplementationControl() != ObjCMethodDecl::Optional) |
| 486 | WarnUndefinedMethod(ImpLoc, method, IncompleteImpl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 487 | } |
| 488 | // check unimplemented class methods |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 489 | for (ObjCProtocolDecl::classmeth_iterator I = PDecl->classmeth_begin(), |
Steve Naroff | 58dbdeb | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 490 | E = PDecl->classmeth_end(); I != E; ++I) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 491 | ObjCMethodDecl *method = *I; |
Steve Naroff | 58dbdeb | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 492 | if (!ClsMap.count(method->getSelector()) && |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 493 | method->getImplementationControl() != ObjCMethodDecl::Optional) |
| 494 | WarnUndefinedMethod(ImpLoc, method, IncompleteImpl); |
Steve Naroff | 58dbdeb | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 495 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 496 | // Check on this protocols's referenced protocols, recursively |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 497 | ObjCProtocolDecl** RefPDecl = PDecl->getReferencedProtocols(); |
Fariborz Jahanian | c395bda | 2007-12-20 19:24:10 +0000 | [diff] [blame] | 498 | for (unsigned i = 0; i < PDecl->getNumReferencedProtocols(); i++) |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 499 | CheckProtocolMethodDefs(ImpLoc, RefPDecl[i], IncompleteImpl, InsMap, ClsMap); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 502 | void Sema::ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl, |
| 503 | ObjCInterfaceDecl* IDecl) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 504 | llvm::DenseSet<Selector> InsMap; |
| 505 | // Check and see if instance methods in class interface have been |
| 506 | // implemented in the implementation class. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 507 | for (ObjCImplementationDecl::instmeth_iterator I = IMPDecl->instmeth_begin(), |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 508 | E = IMPDecl->instmeth_end(); I != E; ++I) |
| 509 | InsMap.insert((*I)->getSelector()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 510 | |
| 511 | bool IncompleteImpl = false; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 512 | for (ObjCInterfaceDecl::instmeth_iterator I = IDecl->instmeth_begin(), |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 513 | E = IDecl->instmeth_end(); I != E; ++I) |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 514 | if (!InsMap.count((*I)->getSelector())) |
| 515 | WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl); |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 516 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 517 | llvm::DenseSet<Selector> ClsMap; |
| 518 | // Check and see if class methods in class interface have been |
| 519 | // implemented in the implementation class. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 520 | for (ObjCImplementationDecl::classmeth_iterator I =IMPDecl->classmeth_begin(), |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 521 | E = IMPDecl->classmeth_end(); I != E; ++I) |
| 522 | ClsMap.insert((*I)->getSelector()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 523 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 524 | for (ObjCInterfaceDecl::classmeth_iterator I = IDecl->classmeth_begin(), |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 525 | E = IDecl->classmeth_end(); I != E; ++I) |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 526 | if (!ClsMap.count((*I)->getSelector())) |
| 527 | WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 528 | |
| 529 | // Check the protocol list for unimplemented methods in the @implementation |
| 530 | // class. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 531 | ObjCProtocolDecl** protocols = IDecl->getReferencedProtocols(); |
Fariborz Jahanian | c395bda | 2007-12-20 19:24:10 +0000 | [diff] [blame] | 532 | for (unsigned i = 0; i < IDecl->getNumIntfRefProtocols(); i++) |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 533 | CheckProtocolMethodDefs(IMPDecl->getLocation(), protocols[i], |
| 534 | IncompleteImpl, InsMap, ClsMap); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | /// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the |
| 538 | /// category interface is implemented in the category @implementation. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 539 | void Sema::ImplCategoryMethodsVsIntfMethods(ObjCCategoryImplDecl *CatImplDecl, |
| 540 | ObjCCategoryDecl *CatClassDecl) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 541 | llvm::DenseSet<Selector> InsMap; |
| 542 | // Check and see if instance methods in category interface have been |
| 543 | // implemented in its implementation class. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 544 | for (ObjCCategoryImplDecl::instmeth_iterator I =CatImplDecl->instmeth_begin(), |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 545 | E = CatImplDecl->instmeth_end(); I != E; ++I) |
| 546 | InsMap.insert((*I)->getSelector()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 547 | |
| 548 | bool IncompleteImpl = false; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 549 | for (ObjCCategoryDecl::instmeth_iterator I = CatClassDecl->instmeth_begin(), |
Steve Naroff | 58dbdeb | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 550 | E = CatClassDecl->instmeth_end(); I != E; ++I) |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 551 | if (!InsMap.count((*I)->getSelector())) |
| 552 | WarnUndefinedMethod(CatImplDecl->getLocation(), *I, IncompleteImpl); |
| 553 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 554 | llvm::DenseSet<Selector> ClsMap; |
| 555 | // Check and see if class methods in category interface have been |
| 556 | // implemented in its implementation class. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 557 | for (ObjCCategoryImplDecl::classmeth_iterator |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 558 | I = CatImplDecl->classmeth_begin(), E = CatImplDecl->classmeth_end(); |
| 559 | I != E; ++I) |
| 560 | ClsMap.insert((*I)->getSelector()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 561 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 562 | for (ObjCCategoryDecl::classmeth_iterator I = CatClassDecl->classmeth_begin(), |
Steve Naroff | 58dbdeb | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 563 | E = CatClassDecl->classmeth_end(); I != E; ++I) |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 564 | if (!ClsMap.count((*I)->getSelector())) |
| 565 | WarnUndefinedMethod(CatImplDecl->getLocation(), *I, IncompleteImpl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 566 | |
| 567 | // Check the protocol list for unimplemented methods in the @implementation |
| 568 | // class. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 569 | ObjCProtocolDecl** protocols = CatClassDecl->getReferencedProtocols(); |
Fariborz Jahanian | c395bda | 2007-12-20 19:24:10 +0000 | [diff] [blame] | 570 | for (unsigned i = 0; i < CatClassDecl->getNumReferencedProtocols(); i++) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 571 | ObjCProtocolDecl* PDecl = protocols[i]; |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 572 | CheckProtocolMethodDefs(CatImplDecl->getLocation(), PDecl, IncompleteImpl, |
| 573 | InsMap, ClsMap); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 574 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | /// ActOnForwardClassDeclaration - |
| 578 | Action::DeclTy * |
| 579 | Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, |
| 580 | IdentifierInfo **IdentList, unsigned NumElts) |
| 581 | { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 582 | llvm::SmallVector<ObjCInterfaceDecl*, 32> Interfaces; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 583 | |
| 584 | for (unsigned i = 0; i != NumElts; ++i) { |
| 585 | // Check for another declaration kind with the same name. |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 586 | Decl *PrevDecl = LookupDecl(IdentList[i], Decl::IDNS_Ordinary, TUScope); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 587 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 588 | Diag(AtClassLoc, diag::err_redefinition_different_kind, |
| 589 | IdentList[i]->getName()); |
| 590 | Diag(PrevDecl->getLocation(), diag::err_previous_definition); |
| 591 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 592 | ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 593 | if (!IDecl) { // Not already seen? Make a forward decl. |
Chris Lattner | 0e77ba0 | 2008-03-16 01:15:50 +0000 | [diff] [blame] | 594 | IDecl = ObjCInterfaceDecl::Create(Context, AtClassLoc, 0, IdentList[i], |
Steve Naroff | d6a07aa | 2008-04-11 19:35:35 +0000 | [diff] [blame] | 595 | SourceLocation(), true); |
Steve Naroff | 3110251 | 2008-04-02 18:30:49 +0000 | [diff] [blame] | 596 | ObjCInterfaceDecls[IdentList[i]] = IDecl; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 597 | |
| 598 | // Remember that this needs to be removed when the scope is popped. |
| 599 | TUScope->AddDecl(IDecl); |
| 600 | } |
| 601 | |
| 602 | Interfaces.push_back(IDecl); |
| 603 | } |
| 604 | |
Chris Lattner | 61f9d41 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 605 | return ObjCClassDecl::Create(Context, AtClassLoc, |
| 606 | &Interfaces[0], Interfaces.size()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | |
| 610 | /// MatchTwoMethodDeclarations - Checks that two methods have matching type and |
| 611 | /// returns true, or false, accordingly. |
| 612 | /// TODO: Handle protocol list; such as id<p1,p2> in type comparisons |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 613 | bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
| 614 | const ObjCMethodDecl *PrevMethod) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 615 | if (Method->getResultType().getCanonicalType() != |
| 616 | PrevMethod->getResultType().getCanonicalType()) |
| 617 | return false; |
Chris Lattner | 58cce3b | 2008-03-16 01:07:14 +0000 | [diff] [blame] | 618 | for (unsigned i = 0, e = Method->getNumParams(); i != e; ++i) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 619 | ParmVarDecl *ParamDecl = Method->getParamDecl(i); |
| 620 | ParmVarDecl *PrevParamDecl = PrevMethod->getParamDecl(i); |
Chris Lattner | 8bcfc5b | 2008-04-06 23:10:54 +0000 | [diff] [blame] | 621 | if (Context.getCanonicalType(ParamDecl->getType()) != |
| 622 | Context.getCanonicalType(PrevParamDecl->getType())) |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 623 | return false; |
| 624 | } |
| 625 | return true; |
| 626 | } |
| 627 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 628 | void Sema::AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method) { |
| 629 | ObjCMethodList &FirstMethod = InstanceMethodPool[Method->getSelector()]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 630 | if (!FirstMethod.Method) { |
| 631 | // Haven't seen a method with this selector name yet - add it. |
| 632 | FirstMethod.Method = Method; |
| 633 | FirstMethod.Next = 0; |
| 634 | } else { |
| 635 | // We've seen a method with this name, now check the type signature(s). |
| 636 | bool match = MatchTwoMethodDeclarations(Method, FirstMethod.Method); |
| 637 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 638 | for (ObjCMethodList *Next = FirstMethod.Next; !match && Next; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 639 | Next = Next->Next) |
| 640 | match = MatchTwoMethodDeclarations(Method, Next->Method); |
| 641 | |
| 642 | if (!match) { |
| 643 | // We have a new signature for an existing method - add it. |
| 644 | // This is extremely rare. Only 1% of Cocoa selectors are "overloaded". |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 645 | struct ObjCMethodList *OMI = new ObjCMethodList(Method, FirstMethod.Next); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 646 | FirstMethod.Next = OMI; |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 651 | void Sema::AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method) { |
| 652 | ObjCMethodList &FirstMethod = FactoryMethodPool[Method->getSelector()]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 653 | if (!FirstMethod.Method) { |
| 654 | // Haven't seen a method with this selector name yet - add it. |
| 655 | FirstMethod.Method = Method; |
| 656 | FirstMethod.Next = 0; |
| 657 | } else { |
| 658 | // We've seen a method with this name, now check the type signature(s). |
| 659 | bool match = MatchTwoMethodDeclarations(Method, FirstMethod.Method); |
| 660 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 661 | for (ObjCMethodList *Next = FirstMethod.Next; !match && Next; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 662 | Next = Next->Next) |
| 663 | match = MatchTwoMethodDeclarations(Method, Next->Method); |
| 664 | |
| 665 | if (!match) { |
| 666 | // We have a new signature for an existing method - add it. |
| 667 | // This is extremely rare. Only 1% of Cocoa selectors are "overloaded". |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 668 | struct ObjCMethodList *OMI = new ObjCMethodList(Method, FirstMethod.Next); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 669 | FirstMethod.Next = OMI; |
| 670 | } |
| 671 | } |
| 672 | } |
| 673 | |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 674 | // Note: For class/category implemenations, allMethods/allProperties is |
| 675 | // always null. |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 676 | void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, |
| 677 | DeclTy **allMethods, unsigned allNum, |
| 678 | DeclTy **allProperties, unsigned pNum) { |
| 679 | Decl *ClassDecl = static_cast<Decl *>(classDecl); |
| 680 | |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 681 | // FIXME: If we don't have a ClassDecl, we have an error. We should consider |
| 682 | // always passing in a decl. If the decl has an error, isInvalidDecl() |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 683 | // should be true. |
| 684 | if (!ClassDecl) |
| 685 | return; |
| 686 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 687 | llvm::SmallVector<ObjCMethodDecl*, 32> insMethods; |
| 688 | llvm::SmallVector<ObjCMethodDecl*, 16> clsMethods; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 689 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 690 | llvm::DenseMap<Selector, const ObjCMethodDecl*> InsMap; |
| 691 | llvm::DenseMap<Selector, const ObjCMethodDecl*> ClsMap; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 692 | |
| 693 | bool isInterfaceDeclKind = |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 694 | isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl) |
| 695 | || isa<ObjCProtocolDecl>(ClassDecl); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 696 | bool checkIdenticalMethods = isa<ObjCImplementationDecl>(ClassDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 697 | |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 698 | if (pNum != 0) |
Chris Lattner | 55d13b4 | 2008-03-16 21:23:50 +0000 | [diff] [blame] | 699 | if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) |
| 700 | IDecl->addProperties((ObjCPropertyDecl**)allProperties, pNum); |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 701 | else if (ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl)) |
| 702 | CDecl->addProperties((ObjCPropertyDecl**)allProperties, pNum); |
| 703 | else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(ClassDecl)) |
| 704 | PDecl->addProperties((ObjCPropertyDecl**)allProperties, pNum); |
Fariborz Jahanian | 7e7e387 | 2008-04-16 21:08:45 +0000 | [diff] [blame] | 705 | else |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 706 | assert(false && "ActOnAtEnd - property declaration misplaced"); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 707 | |
| 708 | for (unsigned i = 0; i < allNum; i++ ) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 709 | ObjCMethodDecl *Method = |
| 710 | cast_or_null<ObjCMethodDecl>(static_cast<Decl*>(allMethods[i])); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 711 | |
| 712 | if (!Method) continue; // Already issued a diagnostic. |
| 713 | if (Method->isInstance()) { |
| 714 | /// Check for instance method of the same name with incompatible types |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 715 | const ObjCMethodDecl *&PrevMethod = InsMap[Method->getSelector()]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 716 | bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod) |
| 717 | : false; |
| 718 | if (isInterfaceDeclKind && PrevMethod && !match |
| 719 | || checkIdenticalMethods && match) { |
| 720 | Diag(Method->getLocation(), diag::error_duplicate_method_decl, |
| 721 | Method->getSelector().getName()); |
| 722 | Diag(PrevMethod->getLocation(), diag::err_previous_declaration); |
| 723 | } else { |
| 724 | insMethods.push_back(Method); |
| 725 | InsMap[Method->getSelector()] = Method; |
| 726 | /// The following allows us to typecheck messages to "id". |
| 727 | AddInstanceMethodToGlobalPool(Method); |
| 728 | } |
| 729 | } |
| 730 | else { |
| 731 | /// Check for class method of the same name with incompatible types |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 732 | const ObjCMethodDecl *&PrevMethod = ClsMap[Method->getSelector()]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 733 | bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod) |
| 734 | : false; |
| 735 | if (isInterfaceDeclKind && PrevMethod && !match |
| 736 | || checkIdenticalMethods && match) { |
| 737 | Diag(Method->getLocation(), diag::error_duplicate_method_decl, |
| 738 | Method->getSelector().getName()); |
| 739 | Diag(PrevMethod->getLocation(), diag::err_previous_declaration); |
| 740 | } else { |
| 741 | clsMethods.push_back(Method); |
| 742 | ClsMap[Method->getSelector()] = Method; |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 743 | /// The following allows us to typecheck messages to "Class". |
| 744 | AddFactoryMethodToGlobalPool(Method); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | } |
| 748 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 749 | if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 750 | I->addMethods(&insMethods[0], insMethods.size(), |
| 751 | &clsMethods[0], clsMethods.size(), AtEndLoc); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 752 | } else if (ObjCProtocolDecl *P = dyn_cast<ObjCProtocolDecl>(ClassDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 753 | P->addMethods(&insMethods[0], insMethods.size(), |
| 754 | &clsMethods[0], clsMethods.size(), AtEndLoc); |
| 755 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 756 | else if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(ClassDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 757 | C->addMethods(&insMethods[0], insMethods.size(), |
| 758 | &clsMethods[0], clsMethods.size(), AtEndLoc); |
| 759 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 760 | else if (ObjCImplementationDecl *IC = |
| 761 | dyn_cast<ObjCImplementationDecl>(ClassDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 762 | IC->setLocEnd(AtEndLoc); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 763 | if (ObjCInterfaceDecl* IDecl = getObjCInterfaceDecl(IC->getIdentifier())) |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 764 | ImplMethodsVsClassMethods(IC, IDecl); |
| 765 | } else { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 766 | ObjCCategoryImplDecl* CatImplClass = cast<ObjCCategoryImplDecl>(ClassDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 767 | CatImplClass->setLocEnd(AtEndLoc); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 768 | ObjCInterfaceDecl* IDecl = CatImplClass->getClassInterface(); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 769 | // Find category interface decl and then check that all methods declared |
| 770 | // in this interface is implemented in the category @implementation. |
| 771 | if (IDecl) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 772 | for (ObjCCategoryDecl *Categories = IDecl->getCategoryList(); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 773 | Categories; Categories = Categories->getNextClassCategory()) { |
| 774 | if (Categories->getIdentifier() == CatImplClass->getIdentifier()) { |
| 775 | ImplCategoryMethodsVsIntfMethods(CatImplClass, Categories); |
| 776 | break; |
| 777 | } |
| 778 | } |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | |
| 784 | /// CvtQTToAstBitMask - utility routine to produce an AST bitmask for |
| 785 | /// objective-c's type qualifier from the parser version of the same info. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 786 | static Decl::ObjCDeclQualifier |
| 787 | CvtQTToAstBitMask(ObjCDeclSpec::ObjCDeclQualifier PQTVal) { |
| 788 | Decl::ObjCDeclQualifier ret = Decl::OBJC_TQ_None; |
| 789 | if (PQTVal & ObjCDeclSpec::DQ_In) |
| 790 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_In); |
| 791 | if (PQTVal & ObjCDeclSpec::DQ_Inout) |
| 792 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Inout); |
| 793 | if (PQTVal & ObjCDeclSpec::DQ_Out) |
| 794 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Out); |
| 795 | if (PQTVal & ObjCDeclSpec::DQ_Bycopy) |
| 796 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Bycopy); |
| 797 | if (PQTVal & ObjCDeclSpec::DQ_Byref) |
| 798 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Byref); |
| 799 | if (PQTVal & ObjCDeclSpec::DQ_Oneway) |
| 800 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Oneway); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 801 | |
| 802 | return ret; |
| 803 | } |
| 804 | |
| 805 | Sema::DeclTy *Sema::ActOnMethodDeclaration( |
| 806 | SourceLocation MethodLoc, SourceLocation EndLoc, |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 807 | tok::TokenKind MethodType, DeclTy *classDecl, |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 808 | ObjCDeclSpec &ReturnQT, TypeTy *ReturnType, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 809 | Selector Sel, |
| 810 | // optional arguments. The number of types/arguments is obtained |
| 811 | // from the Sel.getNumArgs(). |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 812 | ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 813 | AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind, |
| 814 | bool isVariadic) { |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 815 | Decl *ClassDecl = static_cast<Decl*>(classDecl); |
Steve Naroff | da323ad | 2008-02-29 21:48:07 +0000 | [diff] [blame] | 816 | |
| 817 | // Make sure we can establish a context for the method. |
| 818 | if (!ClassDecl) { |
| 819 | Diag(MethodLoc, diag::error_missing_method_context); |
| 820 | return 0; |
| 821 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 822 | QualType resultDeclType; |
| 823 | |
| 824 | if (ReturnType) |
| 825 | resultDeclType = QualType::getFromOpaquePtr(ReturnType); |
| 826 | else // get the type for "id". |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 827 | resultDeclType = Context.getObjCIdType(); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 828 | |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 829 | ObjCMethodDecl* ObjCMethod = |
| 830 | ObjCMethodDecl::Create(Context, MethodLoc, EndLoc, Sel, resultDeclType, |
Chris Lattner | b06fa3b | 2008-03-16 00:58:16 +0000 | [diff] [blame] | 831 | ClassDecl, AttrList, |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 832 | MethodType == tok::minus, isVariadic, |
| 833 | MethodDeclKind == tok::objc_optional ? |
| 834 | ObjCMethodDecl::Optional : |
| 835 | ObjCMethodDecl::Required); |
| 836 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 837 | llvm::SmallVector<ParmVarDecl*, 16> Params; |
| 838 | |
| 839 | for (unsigned i = 0; i < Sel.getNumArgs(); i++) { |
| 840 | // FIXME: arg->AttrList must be stored too! |
| 841 | QualType argType; |
| 842 | |
| 843 | if (ArgTypes[i]) |
| 844 | argType = QualType::getFromOpaquePtr(ArgTypes[i]); |
| 845 | else |
| 846 | argType = Context.getObjCIdType(); |
| 847 | ParmVarDecl* Param = ParmVarDecl::Create(Context, ObjCMethod, |
| 848 | SourceLocation(/*FIXME*/), |
| 849 | ArgNames[i], argType, |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 850 | VarDecl::None, 0, 0); |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 851 | Param->setObjCDeclQualifier( |
| 852 | CvtQTToAstBitMask(ArgQT[i].getObjCDeclQualifier())); |
| 853 | Params.push_back(Param); |
| 854 | } |
| 855 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 856 | ObjCMethod->setMethodParams(&Params[0], Sel.getNumArgs()); |
| 857 | ObjCMethod->setObjCDeclQualifier( |
| 858 | CvtQTToAstBitMask(ReturnQT.getObjCDeclQualifier())); |
| 859 | const ObjCMethodDecl *PrevMethod = 0; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 860 | |
| 861 | // For implementations (which can be very "coarse grain"), we add the |
| 862 | // method now. This allows the AST to implement lookup methods that work |
| 863 | // incrementally (without waiting until we parse the @end). It also allows |
| 864 | // us to flag multiple declaration errors as they occur. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 865 | if (ObjCImplementationDecl *ImpDecl = |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 866 | dyn_cast<ObjCImplementationDecl>(ClassDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 867 | if (MethodType == tok::minus) { |
Steve Naroff | 94a5c33 | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 868 | PrevMethod = ImpDecl->getInstanceMethod(Sel); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 869 | ImpDecl->addInstanceMethod(ObjCMethod); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 870 | } else { |
Steve Naroff | 94a5c33 | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 871 | PrevMethod = ImpDecl->getClassMethod(Sel); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 872 | ImpDecl->addClassMethod(ObjCMethod); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 873 | } |
| 874 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 875 | else if (ObjCCategoryImplDecl *CatImpDecl = |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 876 | dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 877 | if (MethodType == tok::minus) { |
Steve Naroff | 94a5c33 | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 878 | PrevMethod = CatImpDecl->getInstanceMethod(Sel); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 879 | CatImpDecl->addInstanceMethod(ObjCMethod); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 880 | } else { |
Steve Naroff | 94a5c33 | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 881 | PrevMethod = CatImpDecl->getClassMethod(Sel); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 882 | CatImpDecl->addClassMethod(ObjCMethod); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 883 | } |
| 884 | } |
| 885 | if (PrevMethod) { |
| 886 | // You can never have two method definitions with the same name. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 887 | Diag(ObjCMethod->getLocation(), diag::error_duplicate_method_decl, |
| 888 | ObjCMethod->getSelector().getName()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 889 | Diag(PrevMethod->getLocation(), diag::err_previous_declaration); |
| 890 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 891 | return ObjCMethod; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 892 | } |
| 893 | |
Fariborz Jahanian | 1de1e74 | 2008-04-14 23:36:35 +0000 | [diff] [blame] | 894 | Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, |
| 895 | FieldDeclarator &FD, |
| 896 | ObjCDeclSpec &ODS) { |
Fariborz Jahanian | dae1a1a | 2008-04-11 23:40:25 +0000 | [diff] [blame] | 897 | QualType T = GetTypeForDeclarator(FD.D, S); |
Fariborz Jahanian | 1de1e74 | 2008-04-14 23:36:35 +0000 | [diff] [blame] | 898 | ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, AtLoc, |
| 899 | FD.D.getIdentifier(), T); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 900 | |
Fariborz Jahanian | dae1a1a | 2008-04-11 23:40:25 +0000 | [diff] [blame] | 901 | if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_readonly) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 902 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 903 | |
Fariborz Jahanian | dae1a1a | 2008-04-11 23:40:25 +0000 | [diff] [blame] | 904 | if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_getter) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 905 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_getter); |
Fariborz Jahanian | dae1a1a | 2008-04-11 23:40:25 +0000 | [diff] [blame] | 906 | PDecl->setGetterName(ODS.getGetterName()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Fariborz Jahanian | dae1a1a | 2008-04-11 23:40:25 +0000 | [diff] [blame] | 909 | if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_setter) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 910 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_setter); |
Fariborz Jahanian | dae1a1a | 2008-04-11 23:40:25 +0000 | [diff] [blame] | 911 | PDecl->setSetterName(ODS.getSetterName()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Fariborz Jahanian | dae1a1a | 2008-04-11 23:40:25 +0000 | [diff] [blame] | 914 | if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_assign) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 915 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 916 | |
Fariborz Jahanian | dae1a1a | 2008-04-11 23:40:25 +0000 | [diff] [blame] | 917 | if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_readwrite) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 918 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 919 | |
Fariborz Jahanian | dae1a1a | 2008-04-11 23:40:25 +0000 | [diff] [blame] | 920 | if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_retain) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 921 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 922 | |
Fariborz Jahanian | dae1a1a | 2008-04-11 23:40:25 +0000 | [diff] [blame] | 923 | if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_copy) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 924 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 925 | |
Fariborz Jahanian | dae1a1a | 2008-04-11 23:40:25 +0000 | [diff] [blame] | 926 | if (ODS.getPropertyAttributes() & ObjCDeclSpec::DQ_PR_nonatomic) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 927 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 928 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 929 | return PDecl; |
| 930 | } |
| 931 | |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 932 | /// ActOnPropertyImplDecl - This routine performs semantic checks and |
| 933 | /// builds the AST node for a property implementation declaration; declared |
| 934 | /// as @synthesize or @dynamic. |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 935 | /// |
| 936 | Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, |
| 937 | SourceLocation PropertyLoc, |
| 938 | bool Synthesize, |
| 939 | DeclTy *ClassCatImpDecl, |
| 940 | IdentifierInfo *PropertyId, |
| 941 | IdentifierInfo *PropertyIvar) { |
| 942 | Decl *ClassImpDecl = static_cast<Decl*>(ClassCatImpDecl); |
| 943 | // Make sure we have a context for the property implementation declaration. |
| 944 | if (!ClassImpDecl) { |
| 945 | Diag(AtLoc, diag::error_missing_property_context); |
| 946 | return 0; |
| 947 | } |
| 948 | ObjCPropertyDecl *property = 0; |
| 949 | ObjCInterfaceDecl* IDecl = 0; |
| 950 | // Find the class or category class where this property must have |
| 951 | // a declaration. |
| 952 | if (ObjCImplementationDecl *IC = |
| 953 | dyn_cast<ObjCImplementationDecl>(ClassImpDecl)) { |
| 954 | IDecl = getObjCInterfaceDecl(IC->getIdentifier()); |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame^] | 955 | // We always synthesize an interface for an implementation |
| 956 | // without an interface decl. So, IDecl is always non-zero. |
| 957 | assert(IDecl && |
| 958 | "ActOnPropertyImplDecl - @implementation without @interface"); |
| 959 | |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 960 | // Look for this property declaration in the @implementation's @interface |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 961 | property = IDecl->FindPropertyDeclaration(PropertyId); |
| 962 | if (!property) { |
| 963 | Diag(PropertyLoc, diag::error_bad_property_decl, IDecl->getName()); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 964 | return 0; |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 965 | } |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 966 | } |
| 967 | else if (ObjCCategoryImplDecl* CatImplClass = |
| 968 | dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl)) { |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame^] | 969 | if (Synthesize) { |
| 970 | Diag(AtLoc, diag::error_synthesize_category_decl); |
| 971 | return 0; |
| 972 | } |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 973 | IDecl = CatImplClass->getClassInterface(); |
| 974 | if (!IDecl) { |
| 975 | Diag(AtLoc, diag::error_missing_property_interface); |
| 976 | return 0; |
| 977 | } |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 978 | ObjCCategoryDecl *Category = |
| 979 | IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier()); |
| 980 | |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 981 | // If category for this implementation not found, it is an error which |
| 982 | // has already been reported eralier. |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 983 | if (!Category) |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 984 | return 0; |
| 985 | // Look for this property declaration in @implementation's category |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 986 | property = Category->FindPropertyDeclaration(PropertyId); |
| 987 | if (!property) { |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame^] | 988 | Diag(PropertyLoc, diag::error_bad_category_property_decl, |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 989 | Category->getName()); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 990 | return 0; |
| 991 | } |
| 992 | } |
| 993 | else { |
| 994 | Diag(AtLoc, diag::error_bad_property_context); |
| 995 | return 0; |
| 996 | } |
| 997 | |
| 998 | // Check that we have a valid, previously declared ivar for @synthesize |
| 999 | if (Synthesize) { |
| 1000 | // @synthesize |
| 1001 | if (!PropertyIvar) { |
| 1002 | Diag(PropertyLoc, diag::error_property_ivar_decl); |
| 1003 | return 0; |
| 1004 | } |
| 1005 | // Check that this is a previously declared 'ivar' in 'IDecl' interface |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame^] | 1006 | ObjCIvarDecl *Ivar = IDecl->FindIvarDeclaration(PropertyIvar); |
| 1007 | if (!Ivar) { |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1008 | Diag(PropertyLoc, diag::error_missing_property_ivar_decl); |
| 1009 | return 0; |
| 1010 | } |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame^] | 1011 | // Check that type of property and its ivar match. |
| 1012 | if (Ivar->getCanonicalType() != property->getCanonicalType()) { |
| 1013 | Diag(PropertyLoc, diag::error_property_ivar_type, property->getName(), |
| 1014 | Ivar->getName()); |
| 1015 | return 0; |
| 1016 | } |
| 1017 | |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1018 | } else if (PropertyIvar) { |
| 1019 | // @dynamic |
| 1020 | Diag(PropertyLoc, diag::error_dynamic_property_ivar_decl); |
| 1021 | return 0; |
| 1022 | } |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1023 | assert (property && "ActOnPropertyImplDecl - property declaration missing"); |
| 1024 | // TODO: Build the property implementation AST, pushes it into its |
| 1025 | // class/cateogory implementation's vector of property implementations |
| 1026 | #if 0 |
| 1027 | ObjCCategoryImplDecl *PIDecl = |
| 1028 | ObjCCategoryImplDecl::Create(AtLoc, PropertyLoc, property, |
| 1029 | Synthesize ? ObjCPropertyImplDecl::OBJC_PR_IMPL_SYNTHSIZE |
| 1030 | : ObjCPropertyImplDecl::OBJC_PR_IMPL_DYNAMIC, |
| 1031 | PropertyId, PropertyIvar); |
| 1032 | #endif |
| 1033 | return 0; |
| 1034 | } |
Chris Lattner | 7f925cc | 2008-04-11 07:00:53 +0000 | [diff] [blame] | 1035 | |