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" |
Daniel Dunbar | 12bc692 | 2008-08-11 03:27:53 +0000 | [diff] [blame] | 17 | #include "clang/Basic/Diagnostic.h" |
| 18 | #include "clang/Parse/DeclSpec.h" |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace clang; |
| 21 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 22 | /// ObjCActOnStartOfMethodDef - This routine sets up parameters; invisible |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 23 | /// and user declared, in the method definition's AST. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 24 | void Sema::ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) { |
Argyrios Kyrtzidis | 53d0ea5 | 2008-06-28 06:07:14 +0000 | [diff] [blame] | 25 | assert(getCurMethodDecl() == 0 && "Method parsing confused"); |
Steve Naroff | 394f3f4 | 2008-07-25 17:57:26 +0000 | [diff] [blame] | 26 | ObjCMethodDecl *MDecl = dyn_cast_or_null<ObjCMethodDecl>((Decl *)D); |
| 27 | |
| 28 | // If we don't have a valid method decl, simply return. |
| 29 | if (!MDecl) |
| 30 | return; |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 31 | |
| 32 | // Allow the rest of sema to find private method decl implementations. |
| 33 | if (MDecl->isInstance()) |
| 34 | AddInstanceMethodToGlobalPool(MDecl); |
| 35 | else |
| 36 | AddFactoryMethodToGlobalPool(MDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 37 | |
| 38 | // Allow all of Sema to see that we are entering a method definition. |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 39 | PushDeclContext(FnBodyScope, MDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 40 | |
| 41 | // Create Decl objects for each parameter, entrring them in the scope for |
| 42 | // binding to their use. |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 43 | |
| 44 | // Insert the invisible arguments, self and _cmd! |
Fariborz Jahanian | fef30b5 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 45 | MDecl->createImplicitParams(Context, MDecl->getClassInterface()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 46 | |
Daniel Dunbar | 451318c | 2008-08-26 06:07:48 +0000 | [diff] [blame] | 47 | PushOnScopeChains(MDecl->getSelfDecl(), FnBodyScope); |
| 48 | PushOnScopeChains(MDecl->getCmdDecl(), FnBodyScope); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 49 | |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 50 | // Introduce all of the other parameters into this scope. |
Chris Lattner | 58cce3b | 2008-03-16 01:07:14 +0000 | [diff] [blame] | 51 | for (unsigned i = 0, e = MDecl->getNumParams(); i != e; ++i) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 52 | ParmVarDecl *PDecl = MDecl->getParamDecl(i); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 53 | IdentifierInfo *II = PDecl->getIdentifier(); |
Argyrios Kyrtzidis | 642e38b | 2008-04-27 13:30:35 +0000 | [diff] [blame] | 54 | if (II) |
| 55 | PushOnScopeChains(PDecl, FnBodyScope); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 56 | } |
| 57 | } |
| 58 | |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 59 | Sema::DeclTy *Sema:: |
| 60 | ActOnStartClassInterface(SourceLocation AtInterfaceLoc, |
| 61 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 62 | IdentifierInfo *SuperName, SourceLocation SuperLoc, |
Chris Lattner | 06036d3 | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 63 | DeclTy * const *ProtoRefs, unsigned NumProtoRefs, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 64 | SourceLocation EndProtoLoc, AttributeList *AttrList) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 65 | assert(ClassName && "Missing class identifier"); |
| 66 | |
| 67 | // Check for another declaration kind with the same name. |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 68 | Decl *PrevDecl = LookupDecl(ClassName, Decl::IDNS_Ordinary, TUScope); |
Douglas Gregor | f57172b | 2008-12-08 18:40:42 +0000 | [diff] [blame] | 69 | if (PrevDecl && PrevDecl->isTemplateParameter()) { |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 70 | // Maybe we will complain about the shadowed template parameter. |
| 71 | DiagnoseTemplateParameterShadow(ClassLoc, PrevDecl); |
| 72 | // Just pretend that we didn't see the previous declaration. |
| 73 | PrevDecl = 0; |
| 74 | } |
| 75 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 76 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 77 | Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName; |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 78 | Diag(PrevDecl->getLocation(), diag::note_previous_definition); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 81 | ObjCInterfaceDecl* IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 82 | if (IDecl) { |
| 83 | // Class already seen. Is it a forward declaration? |
Steve Naroff | cfe8bf3 | 2008-11-18 19:15:30 +0000 | [diff] [blame] | 84 | if (!IDecl->isForwardDecl()) { |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 85 | Diag(AtInterfaceLoc, diag::err_duplicate_class_def)<<IDecl->getDeclName(); |
Chris Lattner | b8b96af | 2008-11-23 22:46:27 +0000 | [diff] [blame] | 86 | Diag(IDecl->getLocation(), diag::note_previous_definition); |
| 87 | |
Steve Naroff | cfe8bf3 | 2008-11-18 19:15:30 +0000 | [diff] [blame] | 88 | // Return the previous class interface. |
| 89 | // FIXME: don't leak the objects passed in! |
| 90 | return IDecl; |
| 91 | } else { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 92 | IDecl->setLocation(AtInterfaceLoc); |
| 93 | IDecl->setForwardDecl(false); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 94 | } |
Chris Lattner | b752f28 | 2008-07-21 07:06:49 +0000 | [diff] [blame] | 95 | } else { |
Daniel Dunbar | f641492 | 2008-08-20 18:02:42 +0000 | [diff] [blame] | 96 | IDecl = ObjCInterfaceDecl::Create(Context, AtInterfaceLoc, |
Steve Naroff | d6a07aa | 2008-04-11 19:35:35 +0000 | [diff] [blame] | 97 | ClassName, ClassLoc); |
Daniel Dunbar | f641492 | 2008-08-20 18:02:42 +0000 | [diff] [blame] | 98 | if (AttrList) |
| 99 | ProcessDeclAttributeList(IDecl, AttrList); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 100 | |
Steve Naroff | 3110251 | 2008-04-02 18:30:49 +0000 | [diff] [blame] | 101 | ObjCInterfaceDecls[ClassName] = IDecl; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 102 | // Remember that this needs to be removed when the scope is popped. |
| 103 | TUScope->AddDecl(IDecl); |
| 104 | } |
| 105 | |
| 106 | if (SuperName) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 107 | ObjCInterfaceDecl* SuperClassEntry = 0; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 108 | // Check if a different kind of symbol declared in this scope. |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 109 | PrevDecl = LookupDecl(SuperName, Decl::IDNS_Ordinary, TUScope); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 110 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 111 | Diag(SuperLoc, diag::err_redefinition_different_kind) << SuperName; |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 112 | Diag(PrevDecl->getLocation(), diag::note_previous_definition); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 113 | } |
| 114 | else { |
| 115 | // Check that super class is previously defined |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 116 | SuperClassEntry = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 117 | |
| 118 | if (!SuperClassEntry) |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 119 | Diag(SuperLoc, diag::err_undef_superclass) |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 120 | << SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc); |
| 121 | else if (SuperClassEntry->isForwardDecl()) |
| 122 | Diag(SuperLoc, diag::err_undef_superclass) |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 123 | << SuperClassEntry->getDeclName() << ClassName |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 124 | << SourceRange(AtInterfaceLoc, ClassLoc); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 125 | } |
| 126 | IDecl->setSuperClass(SuperClassEntry); |
Steve Naroff | d6a07aa | 2008-04-11 19:35:35 +0000 | [diff] [blame] | 127 | IDecl->setSuperClassLoc(SuperLoc); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 128 | IDecl->setLocEnd(SuperLoc); |
| 129 | } else { // we have a root class. |
| 130 | IDecl->setLocEnd(ClassLoc); |
| 131 | } |
| 132 | |
Steve Naroff | cfe8bf3 | 2008-11-18 19:15:30 +0000 | [diff] [blame] | 133 | /// Check then save referenced protocols. |
Chris Lattner | 06036d3 | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 134 | if (NumProtoRefs) { |
| 135 | IDecl->addReferencedProtocols((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 136 | IDecl->setLocEnd(EndProtoLoc); |
| 137 | } |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 138 | |
| 139 | CheckObjCDeclScope(IDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 140 | return IDecl; |
| 141 | } |
| 142 | |
| 143 | /// ActOnCompatiblityAlias - this action is called after complete parsing of |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 144 | /// @compatibility_alias declaration. It sets up the alias relationships. |
Steve Naroff | e8043c3 | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 145 | Sema::DeclTy *Sema::ActOnCompatiblityAlias(SourceLocation AtLoc, |
| 146 | IdentifierInfo *AliasName, |
| 147 | SourceLocation AliasLocation, |
| 148 | IdentifierInfo *ClassName, |
| 149 | SourceLocation ClassLocation) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 150 | // Look for previous declaration of alias name |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 151 | Decl *ADecl = LookupDecl(AliasName, Decl::IDNS_Ordinary, TUScope); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 152 | if (ADecl) { |
Chris Lattner | 8b265bd | 2008-11-23 23:20:13 +0000 | [diff] [blame] | 153 | if (isa<ObjCCompatibleAliasDecl>(ADecl)) |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 154 | Diag(AliasLocation, diag::warn_previous_alias_decl); |
Chris Lattner | 8b265bd | 2008-11-23 23:20:13 +0000 | [diff] [blame] | 155 | else |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 156 | Diag(AliasLocation, diag::err_conflicting_aliasing_type) << AliasName; |
Chris Lattner | 8b265bd | 2008-11-23 23:20:13 +0000 | [diff] [blame] | 157 | Diag(ADecl->getLocation(), diag::note_previous_declaration); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 158 | return 0; |
| 159 | } |
| 160 | // Check for class declaration |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 161 | Decl *CDeclU = LookupDecl(ClassName, Decl::IDNS_Ordinary, TUScope); |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 162 | ObjCInterfaceDecl *CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDeclU); |
| 163 | if (CDecl == 0) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 164 | Diag(ClassLocation, diag::warn_undef_interface) << ClassName; |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 165 | if (CDeclU) |
Chris Lattner | 8b265bd | 2008-11-23 23:20:13 +0000 | [diff] [blame] | 166 | Diag(CDeclU->getLocation(), diag::note_previous_declaration); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 167 | return 0; |
| 168 | } |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 169 | |
| 170 | // Everything checked out, instantiate a new alias declaration AST. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 171 | ObjCCompatibleAliasDecl *AliasDecl = |
Steve Naroff | e8043c3 | 2008-04-01 23:04:06 +0000 | [diff] [blame] | 172 | ObjCCompatibleAliasDecl::Create(Context, AtLoc, AliasName, CDecl); |
| 173 | |
| 174 | ObjCAliasDecls[AliasName] = AliasDecl; |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 175 | |
| 176 | if (!CheckObjCDeclScope(AliasDecl)) |
| 177 | TUScope->AddDecl(AliasDecl); |
| 178 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 179 | return AliasDecl; |
| 180 | } |
| 181 | |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 182 | Sema::DeclTy * |
| 183 | Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc, |
| 184 | IdentifierInfo *ProtocolName, |
| 185 | SourceLocation ProtocolLoc, |
| 186 | DeclTy * const *ProtoRefs, |
| 187 | unsigned NumProtoRefs, |
Daniel Dunbar | 246e70f | 2008-09-26 04:48:09 +0000 | [diff] [blame] | 188 | SourceLocation EndProtoLoc, |
| 189 | AttributeList *AttrList) { |
| 190 | // FIXME: Deal with AttrList. |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 191 | assert(ProtocolName && "Missing protocol identifier"); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 192 | ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolName]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 193 | if (PDecl) { |
| 194 | // Protocol already seen. Better be a forward protocol declaration |
Chris Lattner | 439e71f | 2008-03-16 01:25:17 +0000 | [diff] [blame] | 195 | if (!PDecl->isForwardDecl()) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 196 | Diag(ProtocolLoc, diag::err_duplicate_protocol_def) << ProtocolName; |
Chris Lattner | b8b96af | 2008-11-23 22:46:27 +0000 | [diff] [blame] | 197 | Diag(PDecl->getLocation(), diag::note_previous_definition); |
Chris Lattner | 439e71f | 2008-03-16 01:25:17 +0000 | [diff] [blame] | 198 | // Just return the protocol we already had. |
| 199 | // FIXME: don't leak the objects passed in! |
| 200 | return PDecl; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 201 | } |
Steve Naroff | f11b508 | 2008-08-13 16:39:22 +0000 | [diff] [blame] | 202 | // Make sure the cached decl gets a valid start location. |
| 203 | PDecl->setLocation(AtProtoInterfaceLoc); |
Chris Lattner | 439e71f | 2008-03-16 01:25:17 +0000 | [diff] [blame] | 204 | PDecl->setForwardDecl(false); |
Chris Lattner | 439e71f | 2008-03-16 01:25:17 +0000 | [diff] [blame] | 205 | } else { |
Chris Lattner | 780f329 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 206 | PDecl = ObjCProtocolDecl::Create(Context, AtProtoInterfaceLoc,ProtocolName); |
Chris Lattner | c858105 | 2008-03-16 20:19:15 +0000 | [diff] [blame] | 207 | PDecl->setForwardDecl(false); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 208 | ObjCProtocols[ProtocolName] = PDecl; |
Chris Lattner | cca59d7 | 2008-03-16 01:23:04 +0000 | [diff] [blame] | 209 | } |
Fariborz Jahanian | bc1c877 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 210 | if (AttrList) |
| 211 | ProcessDeclAttributeList(PDecl, AttrList); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 212 | if (NumProtoRefs) { |
Chris Lattner | c858105 | 2008-03-16 20:19:15 +0000 | [diff] [blame] | 213 | /// Check then save referenced protocols. |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 214 | PDecl->addReferencedProtocols((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 215 | PDecl->setLocEnd(EndProtoLoc); |
| 216 | } |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 217 | |
| 218 | CheckObjCDeclScope(PDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 219 | return PDecl; |
| 220 | } |
| 221 | |
| 222 | /// FindProtocolDeclaration - This routine looks up protocols and |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 223 | /// issues an error if they are not declared. It returns list of |
| 224 | /// protocol declarations in its 'Protocols' argument. |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 225 | void |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 226 | Sema::FindProtocolDeclaration(bool WarnOnDeclarations, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 227 | const IdentifierLocPair *ProtocolId, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 228 | unsigned NumProtocols, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 229 | llvm::SmallVectorImpl<DeclTy*> &Protocols) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 230 | for (unsigned i = 0; i != NumProtocols; ++i) { |
Chris Lattner | eacc392 | 2008-07-26 03:47:43 +0000 | [diff] [blame] | 231 | ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolId[i].first]; |
| 232 | if (!PDecl) { |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 233 | Diag(ProtocolId[i].second, diag::err_undeclared_protocol) |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 234 | << ProtocolId[i].first; |
Chris Lattner | eacc392 | 2008-07-26 03:47:43 +0000 | [diff] [blame] | 235 | continue; |
| 236 | } |
Fariborz Jahanian | bc1c877 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 237 | for (const Attr *attr = PDecl->getAttrs(); attr; attr = attr->getNext()) { |
| 238 | if (attr->hasKind(Attr::Unavailable)) |
| 239 | Diag(ProtocolId[i].second, diag::warn_unavailable) << |
| 240 | PDecl->getDeclName(); |
| 241 | if (attr->hasKind(Attr::Deprecated)) |
| 242 | Diag(ProtocolId[i].second, diag::warn_deprecated) << |
| 243 | PDecl->getDeclName(); |
| 244 | } |
Chris Lattner | eacc392 | 2008-07-26 03:47:43 +0000 | [diff] [blame] | 245 | |
| 246 | // If this is a forward declaration and we are supposed to warn in this |
| 247 | // case, do it. |
| 248 | if (WarnOnDeclarations && PDecl->isForwardDecl()) |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 249 | Diag(ProtocolId[i].second, diag::warn_undef_protocolref) |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 250 | << ProtocolId[i].first; |
Chris Lattner | eacc392 | 2008-07-26 03:47:43 +0000 | [diff] [blame] | 251 | Protocols.push_back(PDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 255 | /// DiagnosePropertyMismatch - Compares two properties for their |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 256 | /// attributes and types and warns on a variety of inconsistencies. |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 257 | /// |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 258 | void |
| 259 | Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property, |
| 260 | ObjCPropertyDecl *SuperProperty, |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 261 | const IdentifierInfo *inheritedName) { |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 262 | ObjCPropertyDecl::PropertyAttributeKind CAttr = |
| 263 | Property->getPropertyAttributes(); |
| 264 | ObjCPropertyDecl::PropertyAttributeKind SAttr = |
| 265 | SuperProperty->getPropertyAttributes(); |
| 266 | if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly) |
| 267 | && (SAttr & ObjCPropertyDecl::OBJC_PR_readwrite)) |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 268 | Diag(Property->getLocation(), diag::warn_readonly_property) |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 269 | << Property->getDeclName() << inheritedName; |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 270 | if ((CAttr & ObjCPropertyDecl::OBJC_PR_copy) |
| 271 | != (SAttr & ObjCPropertyDecl::OBJC_PR_copy)) |
Chris Lattner | c9c7c4e | 2008-11-18 22:52:51 +0000 | [diff] [blame] | 272 | Diag(Property->getLocation(), diag::warn_property_attribute) |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 273 | << Property->getDeclName() << "copy" << inheritedName; |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 274 | else if ((CAttr & ObjCPropertyDecl::OBJC_PR_retain) |
| 275 | != (SAttr & ObjCPropertyDecl::OBJC_PR_retain)) |
Chris Lattner | c9c7c4e | 2008-11-18 22:52:51 +0000 | [diff] [blame] | 276 | Diag(Property->getLocation(), diag::warn_property_attribute) |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 277 | << Property->getDeclName() << "retain" << inheritedName; |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 278 | |
| 279 | if ((CAttr & ObjCPropertyDecl::OBJC_PR_nonatomic) |
| 280 | != (SAttr & ObjCPropertyDecl::OBJC_PR_nonatomic)) |
Chris Lattner | c9c7c4e | 2008-11-18 22:52:51 +0000 | [diff] [blame] | 281 | Diag(Property->getLocation(), diag::warn_property_attribute) |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 282 | << Property->getDeclName() << "atomic" << inheritedName; |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 283 | if (Property->getSetterName() != SuperProperty->getSetterName()) |
Chris Lattner | c9c7c4e | 2008-11-18 22:52:51 +0000 | [diff] [blame] | 284 | Diag(Property->getLocation(), diag::warn_property_attribute) |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 285 | << Property->getDeclName() << "setter" << inheritedName; |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 286 | if (Property->getGetterName() != SuperProperty->getGetterName()) |
Chris Lattner | c9c7c4e | 2008-11-18 22:52:51 +0000 | [diff] [blame] | 287 | Diag(Property->getLocation(), diag::warn_property_attribute) |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 288 | << Property->getDeclName() << "getter" << inheritedName; |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 289 | |
Chris Lattner | 717250a | 2008-07-26 20:50:02 +0000 | [diff] [blame] | 290 | if (Context.getCanonicalType(Property->getType()) != |
| 291 | Context.getCanonicalType(SuperProperty->getType())) |
Chris Lattner | c9c7c4e | 2008-11-18 22:52:51 +0000 | [diff] [blame] | 292 | Diag(Property->getLocation(), diag::warn_property_type) |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 293 | << Property->getType() << inheritedName; |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 294 | |
| 295 | } |
| 296 | |
| 297 | /// ComparePropertiesInBaseAndSuper - This routine compares property |
| 298 | /// declarations in base and its super class, if any, and issues |
| 299 | /// diagnostics in a variety of inconsistant situations. |
| 300 | /// |
| 301 | void |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 302 | Sema::ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl) { |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 303 | ObjCInterfaceDecl *SDecl = IDecl->getSuperClass(); |
| 304 | if (!SDecl) |
| 305 | return; |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 306 | // FIXME: O(N^2) |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 307 | for (ObjCInterfaceDecl::classprop_iterator S = SDecl->classprop_begin(), |
| 308 | E = SDecl->classprop_end(); S != E; ++S) { |
| 309 | ObjCPropertyDecl *SuperPDecl = (*S); |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 310 | // Does property in super class has declaration in current class? |
| 311 | for (ObjCInterfaceDecl::classprop_iterator I = IDecl->classprop_begin(), |
| 312 | E = IDecl->classprop_end(); I != E; ++I) { |
| 313 | ObjCPropertyDecl *PDecl = (*I); |
| 314 | if (SuperPDecl->getIdentifier() == PDecl->getIdentifier()) |
Douglas Gregor | 2e1cd42 | 2008-11-17 14:58:09 +0000 | [diff] [blame] | 315 | DiagnosePropertyMismatch(PDecl, SuperPDecl, |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 316 | SDecl->getIdentifier()); |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | } |
| 320 | |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 321 | /// MergeOneProtocolPropertiesIntoClass - This routine goes thru the list |
| 322 | /// of properties declared in a protocol and adds them to the list |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 323 | /// of properties for current class/category if it is not there already. |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 324 | void |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 325 | Sema::MergeOneProtocolPropertiesIntoClass(Decl *CDecl, |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 326 | ObjCProtocolDecl *PDecl) { |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 327 | llvm::SmallVector<ObjCPropertyDecl*, 16> mergeProperties; |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 328 | ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDecl); |
| 329 | if (!IDecl) { |
| 330 | // Category |
| 331 | ObjCCategoryDecl *CatDecl = static_cast<ObjCCategoryDecl*>(CDecl); |
| 332 | assert (CatDecl && "MergeOneProtocolPropertiesIntoClass"); |
| 333 | for (ObjCProtocolDecl::classprop_iterator P = PDecl->classprop_begin(), |
| 334 | E = PDecl->classprop_end(); P != E; ++P) { |
| 335 | ObjCPropertyDecl *Pr = (*P); |
| 336 | ObjCCategoryDecl::classprop_iterator CP, CE; |
| 337 | // Is this property already in category's list of properties? |
| 338 | for (CP = CatDecl->classprop_begin(), CE = CatDecl->classprop_end(); |
| 339 | CP != CE; ++CP) |
| 340 | if ((*CP)->getIdentifier() == Pr->getIdentifier()) |
| 341 | break; |
| 342 | if (CP == CE) |
| 343 | // Add this property to list of properties for thie class. |
| 344 | mergeProperties.push_back(Pr); |
| 345 | else |
| 346 | // Property protocol already exist in class. Diagnose any mismatch. |
| 347 | DiagnosePropertyMismatch((*CP), Pr, PDecl->getIdentifier()); |
| 348 | } |
| 349 | CatDecl->mergeProperties(&mergeProperties[0], mergeProperties.size()); |
| 350 | return; |
| 351 | } |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 352 | for (ObjCProtocolDecl::classprop_iterator P = PDecl->classprop_begin(), |
| 353 | E = PDecl->classprop_end(); P != E; ++P) { |
| 354 | ObjCPropertyDecl *Pr = (*P); |
| 355 | ObjCInterfaceDecl::classprop_iterator CP, CE; |
| 356 | // Is this property already in class's list of properties? |
| 357 | for (CP = IDecl->classprop_begin(), CE = IDecl->classprop_end(); |
| 358 | CP != CE; ++CP) |
| 359 | if ((*CP)->getIdentifier() == Pr->getIdentifier()) |
| 360 | break; |
| 361 | if (CP == CE) |
| 362 | // Add this property to list of properties for thie class. |
| 363 | mergeProperties.push_back(Pr); |
| 364 | else |
| 365 | // Property protocol already exist in class. Diagnose any mismatch. |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 366 | DiagnosePropertyMismatch((*CP), Pr, PDecl->getIdentifier()); |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 367 | } |
| 368 | IDecl->mergeProperties(&mergeProperties[0], mergeProperties.size()); |
| 369 | } |
| 370 | |
| 371 | /// MergeProtocolPropertiesIntoClass - This routine merges properties |
| 372 | /// declared in 'MergeItsProtocols' objects (which can be a class or an |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 373 | /// inherited protocol into the list of properties for class/category 'CDecl' |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 374 | /// |
| 375 | |
| 376 | void |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 377 | Sema::MergeProtocolPropertiesIntoClass(Decl *CDecl, |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 378 | DeclTy *MergeItsProtocols) { |
| 379 | Decl *ClassDecl = static_cast<Decl *>(MergeItsProtocols); |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 380 | ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDecl); |
| 381 | |
| 382 | if (!IDecl) { |
| 383 | // Category |
| 384 | ObjCCategoryDecl *CatDecl = static_cast<ObjCCategoryDecl*>(CDecl); |
| 385 | assert (CatDecl && "MergeProtocolPropertiesIntoClass"); |
| 386 | if (ObjCCategoryDecl *MDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl)) { |
| 387 | for (ObjCCategoryDecl::protocol_iterator P = MDecl->protocol_begin(), |
| 388 | E = MDecl->protocol_end(); P != E; ++P) |
| 389 | // Merge properties of category (*P) into IDECL's |
| 390 | MergeOneProtocolPropertiesIntoClass(CatDecl, *P); |
| 391 | |
| 392 | // Go thru the list of protocols for this category and recursively merge |
| 393 | // their properties into this class as well. |
| 394 | for (ObjCCategoryDecl::protocol_iterator P = CatDecl->protocol_begin(), |
| 395 | E = CatDecl->protocol_end(); P != E; ++P) |
| 396 | MergeProtocolPropertiesIntoClass(CatDecl, *P); |
| 397 | } else { |
| 398 | ObjCProtocolDecl *MD = cast<ObjCProtocolDecl>(ClassDecl); |
| 399 | for (ObjCProtocolDecl::protocol_iterator P = MD->protocol_begin(), |
| 400 | E = MD->protocol_end(); P != E; ++P) |
| 401 | MergeOneProtocolPropertiesIntoClass(CatDecl, (*P)); |
| 402 | } |
| 403 | return; |
| 404 | } |
| 405 | |
Chris Lattner | b752f28 | 2008-07-21 07:06:49 +0000 | [diff] [blame] | 406 | if (ObjCInterfaceDecl *MDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) { |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 407 | for (ObjCInterfaceDecl::protocol_iterator P = MDecl->protocol_begin(), |
| 408 | E = MDecl->protocol_end(); P != E; ++P) |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 409 | // Merge properties of class (*P) into IDECL's |
Chris Lattner | b752f28 | 2008-07-21 07:06:49 +0000 | [diff] [blame] | 410 | MergeOneProtocolPropertiesIntoClass(IDecl, *P); |
| 411 | |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 412 | // Go thru the list of protocols for this class and recursively merge |
| 413 | // their properties into this class as well. |
| 414 | for (ObjCInterfaceDecl::protocol_iterator P = IDecl->protocol_begin(), |
| 415 | E = IDecl->protocol_end(); P != E; ++P) |
Chris Lattner | b752f28 | 2008-07-21 07:06:49 +0000 | [diff] [blame] | 416 | MergeProtocolPropertiesIntoClass(IDecl, *P); |
| 417 | } else { |
Argyrios Kyrtzidis | e8f0d30 | 2008-07-21 09:18:38 +0000 | [diff] [blame] | 418 | ObjCProtocolDecl *MD = cast<ObjCProtocolDecl>(ClassDecl); |
| 419 | for (ObjCProtocolDecl::protocol_iterator P = MD->protocol_begin(), |
| 420 | E = MD->protocol_end(); P != E; ++P) |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 421 | MergeOneProtocolPropertiesIntoClass(IDecl, (*P)); |
Chris Lattner | b752f28 | 2008-07-21 07:06:49 +0000 | [diff] [blame] | 422 | } |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 425 | /// ActOnForwardProtocolDeclaration - |
| 426 | Action::DeclTy * |
| 427 | Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 428 | const IdentifierLocPair *IdentList, |
Fariborz Jahanian | bc1c877 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 429 | unsigned NumElts, |
| 430 | AttributeList *attrList) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 431 | llvm::SmallVector<ObjCProtocolDecl*, 32> Protocols; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 432 | |
| 433 | for (unsigned i = 0; i != NumElts; ++i) { |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 434 | IdentifierInfo *Ident = IdentList[i].first; |
Chris Lattner | c858105 | 2008-03-16 20:19:15 +0000 | [diff] [blame] | 435 | ObjCProtocolDecl *&PDecl = ObjCProtocols[Ident]; |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 436 | if (PDecl == 0) // Not already seen? |
| 437 | PDecl = ObjCProtocolDecl::Create(Context, IdentList[i].second, Ident); |
Fariborz Jahanian | bc1c877 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 438 | if (attrList) |
| 439 | ProcessDeclAttributeList(PDecl, attrList); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 440 | Protocols.push_back(PDecl); |
| 441 | } |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 442 | |
| 443 | ObjCForwardProtocolDecl *PDecl = |
| 444 | ObjCForwardProtocolDecl::Create(Context, AtProtocolLoc, |
| 445 | &Protocols[0], Protocols.size()); |
| 446 | |
| 447 | CheckObjCDeclScope(PDecl); |
| 448 | return PDecl; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 451 | Sema::DeclTy *Sema:: |
| 452 | ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, |
| 453 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 454 | IdentifierInfo *CategoryName, |
| 455 | SourceLocation CategoryLoc, |
Chris Lattner | 6bd6d0b | 2008-07-26 04:07:02 +0000 | [diff] [blame] | 456 | DeclTy * const *ProtoRefs, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 457 | unsigned NumProtoRefs, |
| 458 | SourceLocation EndProtoLoc) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 459 | ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 460 | |
Chris Lattner | 61f9d41 | 2008-03-16 20:34:23 +0000 | [diff] [blame] | 461 | ObjCCategoryDecl *CDecl = |
Chris Lattner | 68c82cf | 2008-03-16 20:47:45 +0000 | [diff] [blame] | 462 | ObjCCategoryDecl::Create(Context, AtInterfaceLoc, CategoryName); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 463 | CDecl->setClassInterface(IDecl); |
Fariborz Jahanian | 7c453b3 | 2008-01-17 20:33:24 +0000 | [diff] [blame] | 464 | |
| 465 | /// Check that class of this category is already completely declared. |
| 466 | if (!IDecl || IDecl->isForwardDecl()) |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 467 | Diag(ClassLoc, diag::err_undef_interface) << ClassName; |
Steve Naroff | d100c80 | 2008-06-05 15:03:27 +0000 | [diff] [blame] | 468 | else { |
Fariborz Jahanian | 7c453b3 | 2008-01-17 20:33:24 +0000 | [diff] [blame] | 469 | /// Check for duplicate interface declaration for this category |
| 470 | ObjCCategoryDecl *CDeclChain; |
| 471 | for (CDeclChain = IDecl->getCategoryList(); CDeclChain; |
| 472 | CDeclChain = CDeclChain->getNextClassCategory()) { |
Steve Naroff | d100c80 | 2008-06-05 15:03:27 +0000 | [diff] [blame] | 473 | if (CategoryName && CDeclChain->getIdentifier() == CategoryName) { |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 474 | Diag(CategoryLoc, diag::warn_dup_category_def) |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 475 | << ClassName << CategoryName; |
Chris Lattner | 6ff0fc3 | 2008-11-23 22:38:38 +0000 | [diff] [blame] | 476 | Diag(CDeclChain->getLocation(), diag::note_previous_definition); |
Fariborz Jahanian | 7c453b3 | 2008-01-17 20:33:24 +0000 | [diff] [blame] | 477 | break; |
| 478 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 479 | } |
Steve Naroff | d100c80 | 2008-06-05 15:03:27 +0000 | [diff] [blame] | 480 | if (!CDeclChain) |
| 481 | CDecl->insertNextClassCategory(); |
Fariborz Jahanian | 7c453b3 | 2008-01-17 20:33:24 +0000 | [diff] [blame] | 482 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 483 | |
| 484 | if (NumProtoRefs) { |
Chris Lattner | 6bd6d0b | 2008-07-26 04:07:02 +0000 | [diff] [blame] | 485 | CDecl->addReferencedProtocols((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs); |
| 486 | CDecl->setLocEnd(EndProtoLoc); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 487 | } |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 488 | |
| 489 | CheckObjCDeclScope(CDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 490 | return CDecl; |
| 491 | } |
| 492 | |
| 493 | /// ActOnStartCategoryImplementation - Perform semantic checks on the |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 494 | /// category implementation declaration and build an ObjCCategoryImplDecl |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 495 | /// object. |
| 496 | Sema::DeclTy *Sema::ActOnStartCategoryImplementation( |
| 497 | SourceLocation AtCatImplLoc, |
| 498 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 499 | IdentifierInfo *CatName, SourceLocation CatLoc) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 500 | ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName); |
Chris Lattner | 75c9cae | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 501 | ObjCCategoryImplDecl *CDecl = |
| 502 | ObjCCategoryImplDecl::Create(Context, AtCatImplLoc, CatName, IDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 503 | /// Check that class of this category is already completely declared. |
| 504 | if (!IDecl || IDecl->isForwardDecl()) |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 505 | Diag(ClassLoc, diag::err_undef_interface) << ClassName; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 506 | |
| 507 | /// TODO: Check that CatName, category name, is not used in another |
| 508 | // implementation. |
Steve Naroff | e84a864 | 2008-09-28 14:55:53 +0000 | [diff] [blame] | 509 | ObjCCategoryImpls.push_back(CDecl); |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 510 | |
| 511 | CheckObjCDeclScope(CDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 512 | return CDecl; |
| 513 | } |
| 514 | |
| 515 | Sema::DeclTy *Sema::ActOnStartClassImplementation( |
| 516 | SourceLocation AtClassImplLoc, |
| 517 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 518 | IdentifierInfo *SuperClassname, |
| 519 | SourceLocation SuperClassLoc) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 520 | ObjCInterfaceDecl* IDecl = 0; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 521 | // Check for another declaration kind with the same name. |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 522 | Decl *PrevDecl = LookupDecl(ClassName, Decl::IDNS_Ordinary, TUScope); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 523 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 524 | Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName; |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 525 | Diag(PrevDecl->getLocation(), diag::note_previous_definition); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 526 | } |
| 527 | else { |
| 528 | // Is there an interface declaration of this class; if not, warn! |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 529 | IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 530 | if (!IDecl) |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 531 | Diag(ClassLoc, diag::warn_undef_interface) << ClassName; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | // Check that super class name is valid class name |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 535 | ObjCInterfaceDecl* SDecl = 0; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 536 | if (SuperClassname) { |
| 537 | // Check if a different kind of symbol declared in this scope. |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 538 | PrevDecl = LookupDecl(SuperClassname, Decl::IDNS_Ordinary, TUScope); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 539 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 540 | Diag(SuperClassLoc, diag::err_redefinition_different_kind) |
| 541 | << SuperClassname; |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 542 | Diag(PrevDecl->getLocation(), diag::note_previous_definition); |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 543 | } else { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 544 | SDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 545 | if (!SDecl) |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 546 | Diag(SuperClassLoc, diag::err_undef_superclass) |
| 547 | << SuperClassname << ClassName; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 548 | else if (IDecl && IDecl->getSuperClass() != SDecl) { |
| 549 | // This implementation and its interface do not have the same |
| 550 | // super class. |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 551 | Diag(SuperClassLoc, diag::err_conflicting_super_class) |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 552 | << SDecl->getDeclName(); |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 553 | Diag(SDecl->getLocation(), diag::note_previous_definition); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | if (!IDecl) { |
| 559 | // Legacy case of @implementation with no corresponding @interface. |
| 560 | // Build, chain & install the interface decl into the identifier. |
Daniel Dunbar | f641492 | 2008-08-20 18:02:42 +0000 | [diff] [blame] | 561 | |
| 562 | // FIXME: Do we support attributes on the @implementation? If so |
| 563 | // we should copy them over. |
Chris Lattner | b752f28 | 2008-07-21 07:06:49 +0000 | [diff] [blame] | 564 | IDecl = ObjCInterfaceDecl::Create(Context, AtClassImplLoc, ClassName, |
Steve Naroff | d6a07aa | 2008-04-11 19:35:35 +0000 | [diff] [blame] | 565 | ClassLoc, false, true); |
Steve Naroff | 3110251 | 2008-04-02 18:30:49 +0000 | [diff] [blame] | 566 | ObjCInterfaceDecls[ClassName] = IDecl; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 567 | IDecl->setSuperClass(SDecl); |
| 568 | IDecl->setLocEnd(ClassLoc); |
| 569 | |
| 570 | // Remember that this needs to be removed when the scope is popped. |
| 571 | TUScope->AddDecl(IDecl); |
| 572 | } |
| 573 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 574 | ObjCImplementationDecl* IMPDecl = |
Chris Lattner | 75c9cae | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 575 | ObjCImplementationDecl::Create(Context, AtClassImplLoc, ClassName, |
| 576 | IDecl, SDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 577 | |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 578 | if (CheckObjCDeclScope(IMPDecl)) |
| 579 | return IMPDecl; |
| 580 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 581 | // Check that there is no duplicate implementation of this class. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 582 | if (ObjCImplementations[ClassName]) |
Chris Lattner | 75c9cae | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 583 | // FIXME: Don't leak everything! |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 584 | Diag(ClassLoc, diag::err_dup_implementation_class) << ClassName; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 585 | else // add it to the list. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 586 | ObjCImplementations[ClassName] = IMPDecl; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 587 | return IMPDecl; |
| 588 | } |
| 589 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 590 | void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
| 591 | ObjCIvarDecl **ivars, unsigned numIvars, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 592 | SourceLocation RBrace) { |
| 593 | assert(ImpDecl && "missing implementation decl"); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 594 | ObjCInterfaceDecl* IDecl = getObjCInterfaceDecl(ImpDecl->getIdentifier()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 595 | if (!IDecl) |
| 596 | return; |
| 597 | /// Check case of non-existing @interface decl. |
| 598 | /// (legacy objective-c @implementation decl without an @interface decl). |
| 599 | /// Add implementations's ivar to the synthesize class's ivar list. |
| 600 | if (IDecl->ImplicitInterfaceDecl()) { |
| 601 | IDecl->addInstanceVariablesToClass(ivars, numIvars, RBrace); |
| 602 | return; |
| 603 | } |
| 604 | // If implementation has empty ivar list, just return. |
| 605 | if (numIvars == 0) |
| 606 | return; |
| 607 | |
| 608 | assert(ivars && "missing @implementation ivars"); |
| 609 | |
| 610 | // Check interface's Ivar list against those in the implementation. |
| 611 | // names and types must match. |
| 612 | // |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 613 | unsigned j = 0; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 614 | ObjCInterfaceDecl::ivar_iterator |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 615 | IVI = IDecl->ivar_begin(), IVE = IDecl->ivar_end(); |
| 616 | for (; numIvars > 0 && IVI != IVE; ++IVI) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 617 | ObjCIvarDecl* ImplIvar = ivars[j++]; |
| 618 | ObjCIvarDecl* ClsIvar = *IVI; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 619 | assert (ImplIvar && "missing implementation ivar"); |
| 620 | assert (ClsIvar && "missing class ivar"); |
Chris Lattner | 1b63eef | 2008-07-27 00:05:05 +0000 | [diff] [blame] | 621 | if (Context.getCanonicalType(ImplIvar->getType()) != |
| 622 | Context.getCanonicalType(ClsIvar->getType())) { |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 623 | Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_type) |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 624 | << ImplIvar->getIdentifier() |
| 625 | << ImplIvar->getType() << ClsIvar->getType(); |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 626 | Diag(ClsIvar->getLocation(), diag::note_previous_definition); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 627 | } |
| 628 | // TODO: Two mismatched (unequal width) Ivar bitfields should be diagnosed |
| 629 | // as error. |
| 630 | else if (ImplIvar->getIdentifier() != ClsIvar->getIdentifier()) { |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 631 | Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_name) |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 632 | << ImplIvar->getIdentifier() << ClsIvar->getIdentifier(); |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 633 | Diag(ClsIvar->getLocation(), diag::note_previous_definition); |
Chris Lattner | 609e4c7 | 2007-12-12 18:11:49 +0000 | [diff] [blame] | 634 | return; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 635 | } |
| 636 | --numIvars; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 637 | } |
Chris Lattner | 609e4c7 | 2007-12-12 18:11:49 +0000 | [diff] [blame] | 638 | |
| 639 | if (numIvars > 0) |
Chris Lattner | 0e39105 | 2007-12-12 18:19:52 +0000 | [diff] [blame] | 640 | Diag(ivars[j]->getLocation(), diag::err_inconsistant_ivar_count); |
Chris Lattner | 609e4c7 | 2007-12-12 18:11:49 +0000 | [diff] [blame] | 641 | else if (IVI != IVE) |
Chris Lattner | 0e39105 | 2007-12-12 18:19:52 +0000 | [diff] [blame] | 642 | Diag((*IVI)->getLocation(), diag::err_inconsistant_ivar_count); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 643 | } |
| 644 | |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 645 | void Sema::WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, |
| 646 | bool &IncompleteImpl) { |
| 647 | if (!IncompleteImpl) { |
| 648 | Diag(ImpLoc, diag::warn_incomplete_impl); |
| 649 | IncompleteImpl = true; |
| 650 | } |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 651 | Diag(ImpLoc, diag::warn_undef_method_impl) << method->getDeclName(); |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Fariborz Jahanian | 8daab97 | 2008-12-05 18:18:52 +0000 | [diff] [blame] | 654 | void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl, |
| 655 | ObjCMethodDecl *IntfMethodDecl) { |
| 656 | bool err = false; |
| 657 | QualType ImpMethodQType = |
| 658 | Context.getCanonicalType(ImpMethodDecl->getResultType()); |
| 659 | QualType IntfMethodQType = |
| 660 | Context.getCanonicalType(IntfMethodDecl->getResultType()); |
| 661 | if (!Context.typesAreCompatible(IntfMethodQType, ImpMethodQType)) |
| 662 | err = true; |
| 663 | else for (ObjCMethodDecl::param_iterator IM=ImpMethodDecl->param_begin(), |
| 664 | IF=IntfMethodDecl->param_begin(), |
| 665 | EM=ImpMethodDecl->param_end(); IM!=EM; ++IM, IF++) { |
| 666 | ImpMethodQType = Context.getCanonicalType((*IM)->getType()); |
| 667 | IntfMethodQType = Context.getCanonicalType((*IF)->getType()); |
| 668 | if (!Context.typesAreCompatible(IntfMethodQType, ImpMethodQType)) { |
| 669 | err = true; |
| 670 | break; |
| 671 | } |
| 672 | } |
| 673 | if (err) { |
| 674 | Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_types) |
| 675 | << ImpMethodDecl->getDeclName(); |
| 676 | Diag(IntfMethodDecl->getLocation(), diag::note_previous_definition); |
| 677 | } |
| 678 | } |
| 679 | |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 680 | /// FIXME: Type hierarchies in Objective-C can be deep. We could most |
| 681 | /// likely improve the efficiency of selector lookups and type |
| 682 | /// checking by associating with each protocol / interface / category |
| 683 | /// the flattened instance tables. If we used an immutable set to keep |
| 684 | /// the table then it wouldn't add significant memory cost and it |
| 685 | /// would be handy for lookups. |
| 686 | |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 687 | /// CheckProtocolMethodDefs - This routine checks unimplemented methods |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 688 | /// Declared in protocol, and those referenced by it. |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 689 | void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc, |
| 690 | ObjCProtocolDecl *PDecl, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 691 | bool& IncompleteImpl, |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 692 | const llvm::DenseSet<Selector> &InsMap, |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 693 | const llvm::DenseSet<Selector> &ClsMap, |
| 694 | ObjCInterfaceDecl *IDecl) { |
| 695 | ObjCInterfaceDecl *Super = IDecl->getSuperClass(); |
| 696 | |
| 697 | // If a method lookup fails locally we still need to look and see if |
| 698 | // the method was implemented by a base class or an inherited |
| 699 | // protocol. This lookup is slow, but occurs rarely in correct code |
| 700 | // and otherwise would terminate in a warning. |
| 701 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 702 | // check unimplemented instance methods. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 703 | for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(), |
Steve Naroff | 58dbdeb | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 704 | E = PDecl->instmeth_end(); I != E; ++I) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 705 | ObjCMethodDecl *method = *I; |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 706 | if (method->getImplementationControl() != ObjCMethodDecl::Optional && |
Fariborz Jahanian | e793a6e | 2008-11-24 22:16:00 +0000 | [diff] [blame] | 707 | !method->isSynthesized() && !InsMap.count(method->getSelector()) && |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 708 | (!Super || !Super->lookupInstanceMethod(method->getSelector()))) |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 709 | WarnUndefinedMethod(ImpLoc, method, IncompleteImpl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 710 | } |
| 711 | // check unimplemented class methods |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 712 | for (ObjCProtocolDecl::classmeth_iterator I = PDecl->classmeth_begin(), |
Steve Naroff | 58dbdeb | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 713 | E = PDecl->classmeth_end(); I != E; ++I) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 714 | ObjCMethodDecl *method = *I; |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 715 | if (method->getImplementationControl() != ObjCMethodDecl::Optional && |
| 716 | !ClsMap.count(method->getSelector()) && |
| 717 | (!Super || !Super->lookupClassMethod(method->getSelector()))) |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 718 | WarnUndefinedMethod(ImpLoc, method, IncompleteImpl); |
Steve Naroff | 58dbdeb | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 719 | } |
Chris Lattner | 780f329 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 720 | // Check on this protocols's referenced protocols, recursively. |
| 721 | for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(), |
| 722 | E = PDecl->protocol_end(); PI != E; ++PI) |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 723 | CheckProtocolMethodDefs(ImpLoc, *PI, IncompleteImpl, InsMap, ClsMap, IDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 726 | void Sema::ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl, |
| 727 | ObjCInterfaceDecl* IDecl) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 728 | llvm::DenseSet<Selector> InsMap; |
| 729 | // Check and see if instance methods in class interface have been |
| 730 | // implemented in the implementation class. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 731 | for (ObjCImplementationDecl::instmeth_iterator I = IMPDecl->instmeth_begin(), |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 732 | E = IMPDecl->instmeth_end(); I != E; ++I) |
| 733 | InsMap.insert((*I)->getSelector()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 734 | |
| 735 | bool IncompleteImpl = false; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 736 | for (ObjCInterfaceDecl::instmeth_iterator I = IDecl->instmeth_begin(), |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 737 | E = IDecl->instmeth_end(); I != E; ++I) |
Fariborz Jahanian | 4607034 | 2008-05-07 20:53:44 +0000 | [diff] [blame] | 738 | if (!(*I)->isSynthesized() && !InsMap.count((*I)->getSelector())) |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 739 | WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl); |
Fariborz Jahanian | 804058e | 2008-12-22 19:05:31 +0000 | [diff] [blame] | 740 | else { |
Fariborz Jahanian | de73941 | 2008-12-05 01:35:25 +0000 | [diff] [blame] | 741 | ObjCMethodDecl *ImpMethodDecl = |
| 742 | IMPDecl->getInstanceMethod((*I)->getSelector()); |
| 743 | ObjCMethodDecl *IntfMethodDecl = |
| 744 | IDecl->getInstanceMethod((*I)->getSelector()); |
Fariborz Jahanian | 804058e | 2008-12-22 19:05:31 +0000 | [diff] [blame] | 745 | assert(IntfMethodDecl && |
| 746 | "IntfMethodDecl is null in ImplMethodsVsClassMethods"); |
| 747 | // ImpMethodDecl may be null as in a @dynamic property. |
| 748 | if (ImpMethodDecl) |
| 749 | WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl); |
Fariborz Jahanian | de73941 | 2008-12-05 01:35:25 +0000 | [diff] [blame] | 750 | } |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 751 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 752 | llvm::DenseSet<Selector> ClsMap; |
| 753 | // Check and see if class methods in class interface have been |
| 754 | // implemented in the implementation class. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 755 | for (ObjCImplementationDecl::classmeth_iterator I =IMPDecl->classmeth_begin(), |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 756 | E = IMPDecl->classmeth_end(); I != E; ++I) |
| 757 | ClsMap.insert((*I)->getSelector()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 758 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 759 | for (ObjCInterfaceDecl::classmeth_iterator I = IDecl->classmeth_begin(), |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 760 | E = IDecl->classmeth_end(); I != E; ++I) |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 761 | if (!ClsMap.count((*I)->getSelector())) |
| 762 | WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl); |
Fariborz Jahanian | 8daab97 | 2008-12-05 18:18:52 +0000 | [diff] [blame] | 763 | else { |
| 764 | ObjCMethodDecl *ImpMethodDecl = |
| 765 | IMPDecl->getClassMethod((*I)->getSelector()); |
| 766 | ObjCMethodDecl *IntfMethodDecl = |
| 767 | IDecl->getClassMethod((*I)->getSelector()); |
| 768 | WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl); |
| 769 | } |
| 770 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 771 | |
| 772 | // Check the protocol list for unimplemented methods in the @implementation |
| 773 | // class. |
Chris Lattner | 3db6cae | 2008-07-21 18:19:38 +0000 | [diff] [blame] | 774 | const ObjCList<ObjCProtocolDecl> &Protocols = |
| 775 | IDecl->getReferencedProtocols(); |
| 776 | for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(), |
| 777 | E = Protocols.end(); I != E; ++I) |
| 778 | CheckProtocolMethodDefs(IMPDecl->getLocation(), *I, |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 779 | IncompleteImpl, InsMap, ClsMap, IDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | /// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 783 | /// category interface are implemented in the category @implementation. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 784 | void Sema::ImplCategoryMethodsVsIntfMethods(ObjCCategoryImplDecl *CatImplDecl, |
| 785 | ObjCCategoryDecl *CatClassDecl) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 786 | llvm::DenseSet<Selector> InsMap; |
| 787 | // Check and see if instance methods in category interface have been |
| 788 | // implemented in its implementation class. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 789 | for (ObjCCategoryImplDecl::instmeth_iterator I =CatImplDecl->instmeth_begin(), |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 790 | E = CatImplDecl->instmeth_end(); I != E; ++I) |
| 791 | InsMap.insert((*I)->getSelector()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 792 | |
| 793 | bool IncompleteImpl = false; |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 794 | for (ObjCCategoryDecl::instmeth_iterator I = CatClassDecl->instmeth_begin(), |
Steve Naroff | 58dbdeb | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 795 | E = CatClassDecl->instmeth_end(); I != E; ++I) |
Fariborz Jahanian | 804058e | 2008-12-22 19:05:31 +0000 | [diff] [blame] | 796 | if (!(*I)->isSynthesized() && !InsMap.count((*I)->getSelector())) |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 797 | WarnUndefinedMethod(CatImplDecl->getLocation(), *I, IncompleteImpl); |
Fariborz Jahanian | 8daab97 | 2008-12-05 18:18:52 +0000 | [diff] [blame] | 798 | else { |
| 799 | ObjCMethodDecl *ImpMethodDecl = |
| 800 | CatImplDecl->getInstanceMethod((*I)->getSelector()); |
| 801 | ObjCMethodDecl *IntfMethodDecl = |
| 802 | CatClassDecl->getInstanceMethod((*I)->getSelector()); |
Fariborz Jahanian | 804058e | 2008-12-22 19:05:31 +0000 | [diff] [blame] | 803 | assert(IntfMethodDecl && |
| 804 | "IntfMethodDecl is null in ImplCategoryMethodsVsIntfMethods"); |
| 805 | // ImpMethodDecl may be null as in a @dynamic property. |
| 806 | if (ImpMethodDecl) |
| 807 | WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl); |
Fariborz Jahanian | 8daab97 | 2008-12-05 18:18:52 +0000 | [diff] [blame] | 808 | } |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 809 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 810 | llvm::DenseSet<Selector> ClsMap; |
| 811 | // Check and see if class methods in category interface have been |
| 812 | // implemented in its implementation class. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 813 | for (ObjCCategoryImplDecl::classmeth_iterator |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 814 | I = CatImplDecl->classmeth_begin(), E = CatImplDecl->classmeth_end(); |
| 815 | I != E; ++I) |
| 816 | ClsMap.insert((*I)->getSelector()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 817 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 818 | for (ObjCCategoryDecl::classmeth_iterator I = CatClassDecl->classmeth_begin(), |
Steve Naroff | 58dbdeb | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 819 | E = CatClassDecl->classmeth_end(); I != E; ++I) |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 820 | if (!ClsMap.count((*I)->getSelector())) |
| 821 | WarnUndefinedMethod(CatImplDecl->getLocation(), *I, IncompleteImpl); |
Fariborz Jahanian | 8daab97 | 2008-12-05 18:18:52 +0000 | [diff] [blame] | 822 | else { |
| 823 | ObjCMethodDecl *ImpMethodDecl = |
| 824 | CatImplDecl->getClassMethod((*I)->getSelector()); |
| 825 | ObjCMethodDecl *IntfMethodDecl = |
| 826 | CatClassDecl->getClassMethod((*I)->getSelector()); |
| 827 | WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl); |
| 828 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 829 | // Check the protocol list for unimplemented methods in the @implementation |
| 830 | // class. |
Chris Lattner | 780f329 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 831 | for (ObjCCategoryDecl::protocol_iterator PI = CatClassDecl->protocol_begin(), |
| 832 | E = CatClassDecl->protocol_end(); PI != E; ++PI) |
| 833 | CheckProtocolMethodDefs(CatImplDecl->getLocation(), *PI, IncompleteImpl, |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 834 | InsMap, ClsMap, CatClassDecl->getClassInterface()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /// ActOnForwardClassDeclaration - |
| 838 | Action::DeclTy * |
| 839 | Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, |
| 840 | IdentifierInfo **IdentList, unsigned NumElts) |
| 841 | { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 842 | llvm::SmallVector<ObjCInterfaceDecl*, 32> Interfaces; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 843 | |
| 844 | for (unsigned i = 0; i != NumElts; ++i) { |
| 845 | // Check for another declaration kind with the same name. |
Steve Naroff | b327ce0 | 2008-04-02 14:35:35 +0000 | [diff] [blame] | 846 | Decl *PrevDecl = LookupDecl(IdentList[i], Decl::IDNS_Ordinary, TUScope); |
Douglas Gregor | f57172b | 2008-12-08 18:40:42 +0000 | [diff] [blame] | 847 | if (PrevDecl && PrevDecl->isTemplateParameter()) { |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 848 | // Maybe we will complain about the shadowed template parameter. |
| 849 | DiagnoseTemplateParameterShadow(AtClassLoc, PrevDecl); |
| 850 | // Just pretend that we didn't see the previous declaration. |
| 851 | PrevDecl = 0; |
| 852 | } |
| 853 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 854 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Steve Naroff | c733388 | 2008-06-05 22:57:10 +0000 | [diff] [blame] | 855 | // GCC apparently allows the following idiom: |
| 856 | // |
| 857 | // typedef NSObject < XCElementTogglerP > XCElementToggler; |
| 858 | // @class XCElementToggler; |
| 859 | // |
| 860 | // FIXME: Make an extension? |
| 861 | TypedefDecl *TDD = dyn_cast<TypedefDecl>(PrevDecl); |
| 862 | if (!TDD || !isa<ObjCInterfaceType>(TDD->getUnderlyingType())) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 863 | Diag(AtClassLoc, diag::err_redefinition_different_kind) << IdentList[i]; |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 864 | Diag(PrevDecl->getLocation(), diag::note_previous_definition); |
Steve Naroff | c733388 | 2008-06-05 22:57:10 +0000 | [diff] [blame] | 865 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 866 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 867 | ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 868 | if (!IDecl) { // Not already seen? Make a forward decl. |
Chris Lattner | b752f28 | 2008-07-21 07:06:49 +0000 | [diff] [blame] | 869 | IDecl = ObjCInterfaceDecl::Create(Context, AtClassLoc, IdentList[i], |
Steve Naroff | d6a07aa | 2008-04-11 19:35:35 +0000 | [diff] [blame] | 870 | SourceLocation(), true); |
Steve Naroff | 3110251 | 2008-04-02 18:30:49 +0000 | [diff] [blame] | 871 | ObjCInterfaceDecls[IdentList[i]] = IDecl; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 872 | |
| 873 | // Remember that this needs to be removed when the scope is popped. |
| 874 | TUScope->AddDecl(IDecl); |
| 875 | } |
| 876 | |
| 877 | Interfaces.push_back(IDecl); |
| 878 | } |
| 879 | |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 880 | ObjCClassDecl *CDecl = ObjCClassDecl::Create(Context, AtClassLoc, |
| 881 | &Interfaces[0], |
| 882 | Interfaces.size()); |
| 883 | |
| 884 | CheckObjCDeclScope(CDecl); |
| 885 | return CDecl; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | |
| 889 | /// MatchTwoMethodDeclarations - Checks that two methods have matching type and |
| 890 | /// returns true, or false, accordingly. |
| 891 | /// TODO: Handle protocol list; such as id<p1,p2> in type comparisons |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 892 | bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
Steve Naroff | fe6b0dc | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 893 | const ObjCMethodDecl *PrevMethod, |
| 894 | bool matchBasedOnSizeAndAlignment) { |
| 895 | QualType T1 = Context.getCanonicalType(Method->getResultType()); |
| 896 | QualType T2 = Context.getCanonicalType(PrevMethod->getResultType()); |
| 897 | |
| 898 | if (T1 != T2) { |
| 899 | // The result types are different. |
| 900 | if (!matchBasedOnSizeAndAlignment) |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 901 | return false; |
Steve Naroff | fe6b0dc | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 902 | // Incomplete types don't have a size and alignment. |
| 903 | if (T1->isIncompleteType() || T2->isIncompleteType()) |
| 904 | return false; |
| 905 | // Check is based on size and alignment. |
| 906 | if (Context.getTypeInfo(T1) != Context.getTypeInfo(T2)) |
| 907 | return false; |
| 908 | } |
| 909 | for (unsigned i = 0, e = Method->getNumParams(); i != e; ++i) { |
| 910 | T1 = Context.getCanonicalType(Method->getParamDecl(i)->getType()); |
| 911 | T2 = Context.getCanonicalType(PrevMethod->getParamDecl(i)->getType()); |
| 912 | if (T1 != T2) { |
| 913 | // The result types are different. |
| 914 | if (!matchBasedOnSizeAndAlignment) |
| 915 | return false; |
| 916 | // Incomplete types don't have a size and alignment. |
| 917 | if (T1->isIncompleteType() || T2->isIncompleteType()) |
| 918 | return false; |
| 919 | // Check is based on size and alignment. |
| 920 | if (Context.getTypeInfo(T1) != Context.getTypeInfo(T2)) |
| 921 | return false; |
| 922 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 923 | } |
| 924 | return true; |
| 925 | } |
| 926 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 927 | void Sema::AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method) { |
| 928 | ObjCMethodList &FirstMethod = InstanceMethodPool[Method->getSelector()]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 929 | if (!FirstMethod.Method) { |
| 930 | // Haven't seen a method with this selector name yet - add it. |
| 931 | FirstMethod.Method = Method; |
| 932 | FirstMethod.Next = 0; |
| 933 | } else { |
| 934 | // We've seen a method with this name, now check the type signature(s). |
| 935 | bool match = MatchTwoMethodDeclarations(Method, FirstMethod.Method); |
| 936 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 937 | for (ObjCMethodList *Next = FirstMethod.Next; !match && Next; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 938 | Next = Next->Next) |
| 939 | match = MatchTwoMethodDeclarations(Method, Next->Method); |
| 940 | |
| 941 | if (!match) { |
| 942 | // We have a new signature for an existing method - add it. |
| 943 | // This is extremely rare. Only 1% of Cocoa selectors are "overloaded". |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 944 | FirstMethod.Next = new ObjCMethodList(Method, FirstMethod.Next);; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | } |
| 948 | |
Steve Naroff | 6f5f41c | 2008-10-21 10:50:19 +0000 | [diff] [blame] | 949 | // FIXME: Finish implementing -Wno-strict-selector-match. |
Steve Naroff | 037cda5 | 2008-09-30 14:38:43 +0000 | [diff] [blame] | 950 | ObjCMethodDecl *Sema::LookupInstanceMethodInGlobalPool(Selector Sel, |
| 951 | SourceRange R) { |
| 952 | ObjCMethodList &MethList = InstanceMethodPool[Sel]; |
Steve Naroff | fe6b0dc | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 953 | bool issueWarning = false; |
Steve Naroff | 037cda5 | 2008-09-30 14:38:43 +0000 | [diff] [blame] | 954 | |
| 955 | if (MethList.Method && MethList.Next) { |
Steve Naroff | fe6b0dc | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 956 | for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next) |
| 957 | // This checks if the methods differ by size & alignment. |
| 958 | if (!MatchTwoMethodDeclarations(MethList.Method, Next->Method, true)) |
| 959 | issueWarning = true; |
| 960 | } |
| 961 | if (issueWarning && (MethList.Method && MethList.Next)) { |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 962 | Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel << R; |
Chris Lattner | 1326a3d | 2008-11-23 23:26:13 +0000 | [diff] [blame] | 963 | Diag(MethList.Method->getLocStart(), diag::note_using_decl) |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 964 | << MethList.Method->getSourceRange(); |
Steve Naroff | 037cda5 | 2008-09-30 14:38:43 +0000 | [diff] [blame] | 965 | for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next) |
Chris Lattner | 1326a3d | 2008-11-23 23:26:13 +0000 | [diff] [blame] | 966 | Diag(Next->Method->getLocStart(), diag::note_also_found_decl) |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 967 | << Next->Method->getSourceRange(); |
Steve Naroff | 037cda5 | 2008-09-30 14:38:43 +0000 | [diff] [blame] | 968 | } |
| 969 | return MethList.Method; |
| 970 | } |
| 971 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 972 | void Sema::AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method) { |
| 973 | ObjCMethodList &FirstMethod = FactoryMethodPool[Method->getSelector()]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 974 | if (!FirstMethod.Method) { |
| 975 | // Haven't seen a method with this selector name yet - add it. |
| 976 | FirstMethod.Method = Method; |
| 977 | FirstMethod.Next = 0; |
| 978 | } else { |
| 979 | // We've seen a method with this name, now check the type signature(s). |
| 980 | bool match = MatchTwoMethodDeclarations(Method, FirstMethod.Method); |
| 981 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 982 | for (ObjCMethodList *Next = FirstMethod.Next; !match && Next; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 983 | Next = Next->Next) |
| 984 | match = MatchTwoMethodDeclarations(Method, Next->Method); |
| 985 | |
| 986 | if (!match) { |
| 987 | // We have a new signature for an existing method - add it. |
| 988 | // This is extremely rare. Only 1% of Cocoa selectors are "overloaded". |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 989 | struct ObjCMethodList *OMI = new ObjCMethodList(Method, FirstMethod.Next); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 990 | FirstMethod.Next = OMI; |
| 991 | } |
| 992 | } |
| 993 | } |
| 994 | |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 995 | /// diagnosePropertySetterGetterMismatch - Make sure that use-defined |
| 996 | /// setter/getter methods have the property type and issue diagnostics |
| 997 | /// if they don't. |
| 998 | /// |
| 999 | void |
| 1000 | Sema::diagnosePropertySetterGetterMismatch(ObjCPropertyDecl *property, |
| 1001 | const ObjCMethodDecl *GetterMethod, |
| 1002 | const ObjCMethodDecl *SetterMethod) { |
| 1003 | if (GetterMethod && |
Fariborz Jahanian | 196d0ed | 2008-12-06 21:48:16 +0000 | [diff] [blame] | 1004 | GetterMethod->getResultType() != property->getType()) { |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1005 | Diag(property->getLocation(), |
| 1006 | diag::err_accessor_property_type_mismatch) |
| 1007 | << property->getDeclName() |
| 1008 | << GetterMethod->getSelector().getAsIdentifierInfo(); |
Fariborz Jahanian | 196d0ed | 2008-12-06 21:48:16 +0000 | [diff] [blame] | 1009 | Diag(GetterMethod->getLocation(), diag::note_declared_at); |
| 1010 | } |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1011 | |
| 1012 | if (SetterMethod) { |
Fariborz Jahanian | 5dd4129 | 2008-12-06 23:12:49 +0000 | [diff] [blame] | 1013 | if (Context.getCanonicalType(SetterMethod->getResultType()) |
| 1014 | != Context.VoidTy) |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1015 | Diag(SetterMethod->getLocation(), diag::err_setter_type_void); |
| 1016 | if (SetterMethod->getNumParams() != 1 || |
Fariborz Jahanian | 196d0ed | 2008-12-06 21:48:16 +0000 | [diff] [blame] | 1017 | (SetterMethod->getParamDecl(0)->getType() != property->getType())) { |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1018 | Diag(property->getLocation(), |
| 1019 | diag::err_accessor_property_type_mismatch) |
| 1020 | << property->getDeclName() |
| 1021 | << SetterMethod->getSelector().getAsIdentifierInfo(); |
Fariborz Jahanian | 196d0ed | 2008-12-06 21:48:16 +0000 | [diff] [blame] | 1022 | Diag(SetterMethod->getLocation(), diag::note_declared_at); |
| 1023 | } |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1024 | } |
| 1025 | } |
| 1026 | |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 1027 | // Note: For class/category implemenations, allMethods/allProperties is |
| 1028 | // always null. |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1029 | void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl, |
| 1030 | DeclTy **allMethods, unsigned allNum, |
| 1031 | DeclTy **allProperties, unsigned pNum) { |
| 1032 | Decl *ClassDecl = static_cast<Decl *>(classDecl); |
| 1033 | |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 1034 | // FIXME: If we don't have a ClassDecl, we have an error. We should consider |
| 1035 | // always passing in a decl. If the decl has an error, isInvalidDecl() |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1036 | // should be true. |
| 1037 | if (!ClassDecl) |
| 1038 | return; |
| 1039 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1040 | llvm::SmallVector<ObjCMethodDecl*, 32> insMethods; |
| 1041 | llvm::SmallVector<ObjCMethodDecl*, 16> clsMethods; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1042 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1043 | llvm::DenseMap<Selector, const ObjCMethodDecl*> InsMap; |
| 1044 | llvm::DenseMap<Selector, const ObjCMethodDecl*> ClsMap; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1045 | |
| 1046 | bool isInterfaceDeclKind = |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 1047 | isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl) |
| 1048 | || isa<ObjCProtocolDecl>(ClassDecl); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1049 | bool checkIdenticalMethods = isa<ObjCImplementationDecl>(ClassDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1050 | |
Seo Sanghyeon | fe5042e | 2008-07-05 02:01:25 +0000 | [diff] [blame] | 1051 | if (pNum != 0) { |
Chris Lattner | 55d13b4 | 2008-03-16 21:23:50 +0000 | [diff] [blame] | 1052 | if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) |
| 1053 | IDecl->addProperties((ObjCPropertyDecl**)allProperties, pNum); |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 1054 | else if (ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl)) |
| 1055 | CDecl->addProperties((ObjCPropertyDecl**)allProperties, pNum); |
| 1056 | else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(ClassDecl)) |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 1057 | PDecl->addProperties((ObjCPropertyDecl**)allProperties, pNum); |
Fariborz Jahanian | 7e7e387 | 2008-04-16 21:08:45 +0000 | [diff] [blame] | 1058 | else |
Fariborz Jahanian | 3dd4ba4 | 2008-04-17 18:25:18 +0000 | [diff] [blame] | 1059 | assert(false && "ActOnAtEnd - property declaration misplaced"); |
Seo Sanghyeon | fe5042e | 2008-07-05 02:01:25 +0000 | [diff] [blame] | 1060 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1061 | |
| 1062 | for (unsigned i = 0; i < allNum; i++ ) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1063 | ObjCMethodDecl *Method = |
| 1064 | cast_or_null<ObjCMethodDecl>(static_cast<Decl*>(allMethods[i])); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1065 | |
| 1066 | if (!Method) continue; // Already issued a diagnostic. |
| 1067 | if (Method->isInstance()) { |
| 1068 | /// Check for instance method of the same name with incompatible types |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1069 | const ObjCMethodDecl *&PrevMethod = InsMap[Method->getSelector()]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1070 | bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod) |
| 1071 | : false; |
Eli Friedman | 82b4e76 | 2008-12-16 20:15:50 +0000 | [diff] [blame] | 1072 | if ((isInterfaceDeclKind && PrevMethod && !match) |
| 1073 | || (checkIdenticalMethods && match)) { |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 1074 | Diag(Method->getLocation(), diag::err_duplicate_method_decl) |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 1075 | << Method->getDeclName(); |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 1076 | Diag(PrevMethod->getLocation(), diag::note_previous_declaration); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1077 | } else { |
| 1078 | insMethods.push_back(Method); |
| 1079 | InsMap[Method->getSelector()] = Method; |
| 1080 | /// The following allows us to typecheck messages to "id". |
| 1081 | AddInstanceMethodToGlobalPool(Method); |
| 1082 | } |
| 1083 | } |
| 1084 | else { |
| 1085 | /// Check for class method of the same name with incompatible types |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1086 | const ObjCMethodDecl *&PrevMethod = ClsMap[Method->getSelector()]; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1087 | bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod) |
| 1088 | : false; |
Eli Friedman | 82b4e76 | 2008-12-16 20:15:50 +0000 | [diff] [blame] | 1089 | if ((isInterfaceDeclKind && PrevMethod && !match) |
| 1090 | || (checkIdenticalMethods && match)) { |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 1091 | Diag(Method->getLocation(), diag::err_duplicate_method_decl) |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 1092 | << Method->getDeclName(); |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 1093 | Diag(PrevMethod->getLocation(), diag::note_previous_declaration); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1094 | } else { |
| 1095 | clsMethods.push_back(Method); |
| 1096 | ClsMap[Method->getSelector()] = Method; |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 1097 | /// The following allows us to typecheck messages to "Class". |
| 1098 | AddFactoryMethodToGlobalPool(Method); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1099 | } |
| 1100 | } |
| 1101 | } |
Steve Naroff | 5e0a74f | 2008-09-29 14:20:56 +0000 | [diff] [blame] | 1102 | // Save the size so we can detect if we've added any property methods. |
| 1103 | unsigned int insMethodsSizePriorToPropAdds = insMethods.size(); |
| 1104 | unsigned int clsMethodsSizePriorToPropAdds = clsMethods.size(); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1105 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1106 | if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) { |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 1107 | // Compares properties declared in this class to those of its |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 1108 | // super class. |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 1109 | ComparePropertiesInBaseAndSuper(I); |
| 1110 | MergeProtocolPropertiesIntoClass(I, I); |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 1111 | for (ObjCInterfaceDecl::classprop_iterator i = I->classprop_begin(), |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1112 | e = I->classprop_end(); i != e; ++i) { |
| 1113 | diagnosePropertySetterGetterMismatch((*i), InsMap[(*i)->getGetterName()], |
| 1114 | InsMap[(*i)->getSetterName()]); |
Fariborz Jahanian | b85cce6 | 2008-12-02 00:19:12 +0000 | [diff] [blame] | 1115 | I->addPropertyMethods(Context, *i, insMethods, InsMap); |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1116 | } |
Fariborz Jahanian | 33de3f0 | 2008-05-07 17:43:59 +0000 | [diff] [blame] | 1117 | I->addMethods(&insMethods[0], insMethods.size(), |
| 1118 | &clsMethods[0], clsMethods.size(), AtEndLoc); |
| 1119 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1120 | } else if (ObjCProtocolDecl *P = dyn_cast<ObjCProtocolDecl>(ClassDecl)) { |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 1121 | for (ObjCProtocolDecl::classprop_iterator i = P->classprop_begin(), |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1122 | e = P->classprop_end(); i != e; ++i) { |
| 1123 | diagnosePropertySetterGetterMismatch((*i), InsMap[(*i)->getGetterName()], |
| 1124 | InsMap[(*i)->getSetterName()]); |
Fariborz Jahanian | b85cce6 | 2008-12-02 00:19:12 +0000 | [diff] [blame] | 1125 | P->addPropertyMethods(Context, *i, insMethods, InsMap); |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1126 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1127 | P->addMethods(&insMethods[0], insMethods.size(), |
| 1128 | &clsMethods[0], clsMethods.size(), AtEndLoc); |
| 1129 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1130 | else if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(ClassDecl)) { |
Fariborz Jahanian | 77e14bd | 2008-12-06 19:59:02 +0000 | [diff] [blame] | 1131 | // Categories are used to extend the class by declaring new methods. |
| 1132 | // By the same token, they are also used to add new properties. No |
| 1133 | // need to compare the added property to those in the class. |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 1134 | |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 1135 | // Merge protocol properties into category |
| 1136 | MergeProtocolPropertiesIntoClass(C, C); |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 1137 | for (ObjCCategoryDecl::classprop_iterator i = C->classprop_begin(), |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1138 | e = C->classprop_end(); i != e; ++i) { |
| 1139 | diagnosePropertySetterGetterMismatch((*i), InsMap[(*i)->getGetterName()], |
| 1140 | InsMap[(*i)->getSetterName()]); |
Fariborz Jahanian | b85cce6 | 2008-12-02 00:19:12 +0000 | [diff] [blame] | 1141 | C->addPropertyMethods(Context, *i, insMethods, InsMap); |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1142 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1143 | C->addMethods(&insMethods[0], insMethods.size(), |
| 1144 | &clsMethods[0], clsMethods.size(), AtEndLoc); |
| 1145 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1146 | else if (ObjCImplementationDecl *IC = |
| 1147 | dyn_cast<ObjCImplementationDecl>(ClassDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1148 | IC->setLocEnd(AtEndLoc); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1149 | if (ObjCInterfaceDecl* IDecl = getObjCInterfaceDecl(IC->getIdentifier())) |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1150 | ImplMethodsVsClassMethods(IC, IDecl); |
| 1151 | } else { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1152 | ObjCCategoryImplDecl* CatImplClass = cast<ObjCCategoryImplDecl>(ClassDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1153 | CatImplClass->setLocEnd(AtEndLoc); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1154 | ObjCInterfaceDecl* IDecl = CatImplClass->getClassInterface(); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1155 | // Find category interface decl and then check that all methods declared |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 1156 | // in this interface are implemented in the category @implementation. |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1157 | if (IDecl) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1158 | for (ObjCCategoryDecl *Categories = IDecl->getCategoryList(); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1159 | Categories; Categories = Categories->getNextClassCategory()) { |
| 1160 | if (Categories->getIdentifier() == CatImplClass->getIdentifier()) { |
| 1161 | ImplCategoryMethodsVsIntfMethods(CatImplClass, Categories); |
| 1162 | break; |
| 1163 | } |
| 1164 | } |
| 1165 | } |
| 1166 | } |
Steve Naroff | 5e0a74f | 2008-09-29 14:20:56 +0000 | [diff] [blame] | 1167 | // Add any synthesized methods to the global pool. This allows us to |
| 1168 | // handle the following, which is supported by GCC (and part of the design). |
| 1169 | // |
| 1170 | // @interface Foo |
| 1171 | // @property double bar; |
| 1172 | // @end |
| 1173 | // |
| 1174 | // void thisIsUnfortunate() { |
| 1175 | // id foo; |
| 1176 | // double bar = [foo bar]; |
| 1177 | // } |
| 1178 | // |
| 1179 | if (insMethodsSizePriorToPropAdds < insMethods.size()) |
| 1180 | for (unsigned i = insMethodsSizePriorToPropAdds; i < insMethods.size(); i++) |
| 1181 | AddInstanceMethodToGlobalPool(insMethods[i]); |
| 1182 | if (clsMethodsSizePriorToPropAdds < clsMethods.size()) |
| 1183 | for (unsigned i = clsMethodsSizePriorToPropAdds; i < clsMethods.size(); i++) |
| 1184 | AddFactoryMethodToGlobalPool(clsMethods[i]); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | |
| 1188 | /// CvtQTToAstBitMask - utility routine to produce an AST bitmask for |
| 1189 | /// 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] | 1190 | static Decl::ObjCDeclQualifier |
| 1191 | CvtQTToAstBitMask(ObjCDeclSpec::ObjCDeclQualifier PQTVal) { |
| 1192 | Decl::ObjCDeclQualifier ret = Decl::OBJC_TQ_None; |
| 1193 | if (PQTVal & ObjCDeclSpec::DQ_In) |
| 1194 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_In); |
| 1195 | if (PQTVal & ObjCDeclSpec::DQ_Inout) |
| 1196 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Inout); |
| 1197 | if (PQTVal & ObjCDeclSpec::DQ_Out) |
| 1198 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Out); |
| 1199 | if (PQTVal & ObjCDeclSpec::DQ_Bycopy) |
| 1200 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Bycopy); |
| 1201 | if (PQTVal & ObjCDeclSpec::DQ_Byref) |
| 1202 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Byref); |
| 1203 | if (PQTVal & ObjCDeclSpec::DQ_Oneway) |
| 1204 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Oneway); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1205 | |
| 1206 | return ret; |
| 1207 | } |
| 1208 | |
| 1209 | Sema::DeclTy *Sema::ActOnMethodDeclaration( |
| 1210 | SourceLocation MethodLoc, SourceLocation EndLoc, |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 1211 | tok::TokenKind MethodType, DeclTy *classDecl, |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1212 | ObjCDeclSpec &ReturnQT, TypeTy *ReturnType, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1213 | Selector Sel, |
| 1214 | // optional arguments. The number of types/arguments is obtained |
| 1215 | // from the Sel.getNumArgs(). |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1216 | ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1217 | AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind, |
| 1218 | bool isVariadic) { |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 1219 | Decl *ClassDecl = static_cast<Decl*>(classDecl); |
Steve Naroff | da323ad | 2008-02-29 21:48:07 +0000 | [diff] [blame] | 1220 | |
| 1221 | // Make sure we can establish a context for the method. |
| 1222 | if (!ClassDecl) { |
| 1223 | Diag(MethodLoc, diag::error_missing_method_context); |
| 1224 | return 0; |
| 1225 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1226 | QualType resultDeclType; |
| 1227 | |
| 1228 | if (ReturnType) |
| 1229 | resultDeclType = QualType::getFromOpaquePtr(ReturnType); |
| 1230 | else // get the type for "id". |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1231 | resultDeclType = Context.getObjCIdType(); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1232 | |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 1233 | ObjCMethodDecl* ObjCMethod = |
| 1234 | ObjCMethodDecl::Create(Context, MethodLoc, EndLoc, Sel, resultDeclType, |
Daniel Dunbar | f641492 | 2008-08-20 18:02:42 +0000 | [diff] [blame] | 1235 | ClassDecl, |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 1236 | MethodType == tok::minus, isVariadic, |
Fariborz Jahanian | 4607034 | 2008-05-07 20:53:44 +0000 | [diff] [blame] | 1237 | false, |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 1238 | MethodDeclKind == tok::objc_optional ? |
| 1239 | ObjCMethodDecl::Optional : |
| 1240 | ObjCMethodDecl::Required); |
| 1241 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1242 | llvm::SmallVector<ParmVarDecl*, 16> Params; |
| 1243 | |
| 1244 | for (unsigned i = 0; i < Sel.getNumArgs(); i++) { |
| 1245 | // FIXME: arg->AttrList must be stored too! |
Fariborz Jahanian | 4306d3c | 2008-12-20 23:29:59 +0000 | [diff] [blame] | 1246 | QualType argType, originalArgType; |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1247 | |
Steve Naroff | 6082c62 | 2008-12-09 19:36:17 +0000 | [diff] [blame] | 1248 | if (ArgTypes[i]) { |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1249 | argType = QualType::getFromOpaquePtr(ArgTypes[i]); |
Steve Naroff | 6082c62 | 2008-12-09 19:36:17 +0000 | [diff] [blame] | 1250 | // Perform the default array/function conversions (C99 6.7.5.3p[7,8]). |
Fariborz Jahanian | 4306d3c | 2008-12-20 23:29:59 +0000 | [diff] [blame] | 1251 | if (argType->isArrayType()) { // (char *[]) -> (char **) |
| 1252 | originalArgType = argType; |
Steve Naroff | 6082c62 | 2008-12-09 19:36:17 +0000 | [diff] [blame] | 1253 | argType = Context.getArrayDecayedType(argType); |
Fariborz Jahanian | 4306d3c | 2008-12-20 23:29:59 +0000 | [diff] [blame] | 1254 | } |
Steve Naroff | 6082c62 | 2008-12-09 19:36:17 +0000 | [diff] [blame] | 1255 | else if (argType->isFunctionType()) |
| 1256 | argType = Context.getPointerType(argType); |
| 1257 | } else |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1258 | argType = Context.getObjCIdType(); |
Fariborz Jahanian | 4306d3c | 2008-12-20 23:29:59 +0000 | [diff] [blame] | 1259 | ParmVarDecl* Param; |
| 1260 | if (originalArgType.isNull()) |
| 1261 | Param = ParmVarDecl::Create(Context, ObjCMethod, |
| 1262 | SourceLocation(/*FIXME*/), |
| 1263 | ArgNames[i], argType, |
| 1264 | VarDecl::None, 0, 0); |
| 1265 | else |
| 1266 | Param = ParmVarWithOriginalTypeDecl::Create(Context, ObjCMethod, |
| 1267 | SourceLocation(/*FIXME*/), |
| 1268 | ArgNames[i], argType, originalArgType, |
| 1269 | VarDecl::None, 0, 0); |
| 1270 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 1271 | Param->setObjCDeclQualifier( |
| 1272 | CvtQTToAstBitMask(ArgQT[i].getObjCDeclQualifier())); |
| 1273 | Params.push_back(Param); |
| 1274 | } |
| 1275 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1276 | ObjCMethod->setMethodParams(&Params[0], Sel.getNumArgs()); |
| 1277 | ObjCMethod->setObjCDeclQualifier( |
| 1278 | CvtQTToAstBitMask(ReturnQT.getObjCDeclQualifier())); |
| 1279 | const ObjCMethodDecl *PrevMethod = 0; |
Daniel Dunbar | 3568249 | 2008-09-26 04:12:28 +0000 | [diff] [blame] | 1280 | |
| 1281 | if (AttrList) |
| 1282 | ProcessDeclAttributeList(ObjCMethod, AttrList); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1283 | |
| 1284 | // For implementations (which can be very "coarse grain"), we add the |
| 1285 | // method now. This allows the AST to implement lookup methods that work |
| 1286 | // incrementally (without waiting until we parse the @end). It also allows |
| 1287 | // us to flag multiple declaration errors as they occur. |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1288 | if (ObjCImplementationDecl *ImpDecl = |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 1289 | dyn_cast<ObjCImplementationDecl>(ClassDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1290 | if (MethodType == tok::minus) { |
Steve Naroff | 94a5c33 | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 1291 | PrevMethod = ImpDecl->getInstanceMethod(Sel); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1292 | ImpDecl->addInstanceMethod(ObjCMethod); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1293 | } else { |
Steve Naroff | 94a5c33 | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 1294 | PrevMethod = ImpDecl->getClassMethod(Sel); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1295 | ImpDecl->addClassMethod(ObjCMethod); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1296 | } |
| 1297 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1298 | else if (ObjCCategoryImplDecl *CatImpDecl = |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 1299 | dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1300 | if (MethodType == tok::minus) { |
Steve Naroff | 94a5c33 | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 1301 | PrevMethod = CatImpDecl->getInstanceMethod(Sel); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1302 | CatImpDecl->addInstanceMethod(ObjCMethod); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1303 | } else { |
Steve Naroff | 94a5c33 | 2007-12-19 22:27:04 +0000 | [diff] [blame] | 1304 | PrevMethod = CatImpDecl->getClassMethod(Sel); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1305 | CatImpDecl->addClassMethod(ObjCMethod); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1306 | } |
| 1307 | } |
| 1308 | if (PrevMethod) { |
| 1309 | // You can never have two method definitions with the same name. |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 1310 | Diag(ObjCMethod->getLocation(), diag::err_duplicate_method_decl) |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 1311 | << ObjCMethod->getDeclName(); |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 1312 | Diag(PrevMethod->getLocation(), diag::note_previous_declaration); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1313 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1314 | return ObjCMethod; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1317 | void Sema::CheckObjCPropertyAttributes(QualType PropertyTy, |
| 1318 | SourceLocation Loc, |
| 1319 | unsigned &Attributes) { |
| 1320 | // FIXME: Improve the reported location. |
| 1321 | |
Fariborz Jahanian | 567c8df | 2008-12-06 01:12:43 +0000 | [diff] [blame] | 1322 | // readonly and readwrite/assign/retain/copy conflict. |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1323 | if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) && |
Fariborz Jahanian | 567c8df | 2008-12-06 01:12:43 +0000 | [diff] [blame] | 1324 | (Attributes & (ObjCDeclSpec::DQ_PR_readwrite | |
| 1325 | ObjCDeclSpec::DQ_PR_assign | |
| 1326 | ObjCDeclSpec::DQ_PR_copy | |
| 1327 | ObjCDeclSpec::DQ_PR_retain))) { |
| 1328 | const char * which = (Attributes & ObjCDeclSpec::DQ_PR_readwrite) ? |
| 1329 | "readwrite" : |
| 1330 | (Attributes & ObjCDeclSpec::DQ_PR_assign) ? |
| 1331 | "assign" : |
| 1332 | (Attributes & ObjCDeclSpec::DQ_PR_copy) ? |
| 1333 | "copy" : "retain"; |
| 1334 | |
Fariborz Jahanian | ba45da8 | 2008-12-08 19:28:10 +0000 | [diff] [blame] | 1335 | Diag(Loc, (Attributes & (ObjCDeclSpec::DQ_PR_readwrite)) ? |
| 1336 | diag::err_objc_property_attr_mutually_exclusive : |
| 1337 | diag::warn_objc_property_attr_mutually_exclusive) |
Fariborz Jahanian | 567c8df | 2008-12-06 01:12:43 +0000 | [diff] [blame] | 1338 | << "readonly" << which; |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | // Check for copy or retain on non-object types. |
| 1342 | if ((Attributes & (ObjCDeclSpec::DQ_PR_copy | ObjCDeclSpec::DQ_PR_retain)) && |
| 1343 | !Context.isObjCObjectPointerType(PropertyTy)) { |
Chris Lattner | 5dc266a | 2008-11-20 06:13:02 +0000 | [diff] [blame] | 1344 | Diag(Loc, diag::err_objc_property_requires_object) |
| 1345 | << (Attributes & ObjCDeclSpec::DQ_PR_copy ? "copy" : "retain"); |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1346 | Attributes &= ~(ObjCDeclSpec::DQ_PR_copy | ObjCDeclSpec::DQ_PR_retain); |
| 1347 | } |
| 1348 | |
| 1349 | // Check for more than one of { assign, copy, retain }. |
| 1350 | if (Attributes & ObjCDeclSpec::DQ_PR_assign) { |
| 1351 | if (Attributes & ObjCDeclSpec::DQ_PR_copy) { |
Chris Lattner | 5dc266a | 2008-11-20 06:13:02 +0000 | [diff] [blame] | 1352 | Diag(Loc, diag::err_objc_property_attr_mutually_exclusive) |
| 1353 | << "assign" << "copy"; |
| 1354 | Attributes &= ~ObjCDeclSpec::DQ_PR_copy; |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1355 | } |
| 1356 | if (Attributes & ObjCDeclSpec::DQ_PR_retain) { |
Chris Lattner | 5dc266a | 2008-11-20 06:13:02 +0000 | [diff] [blame] | 1357 | Diag(Loc, diag::err_objc_property_attr_mutually_exclusive) |
| 1358 | << "assign" << "retain"; |
| 1359 | Attributes &= ~ObjCDeclSpec::DQ_PR_retain; |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1360 | } |
| 1361 | } else if (Attributes & ObjCDeclSpec::DQ_PR_copy) { |
| 1362 | if (Attributes & ObjCDeclSpec::DQ_PR_retain) { |
Chris Lattner | 5dc266a | 2008-11-20 06:13:02 +0000 | [diff] [blame] | 1363 | Diag(Loc, diag::err_objc_property_attr_mutually_exclusive) |
| 1364 | << "copy" << "retain"; |
| 1365 | Attributes &= ~ObjCDeclSpec::DQ_PR_retain; |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | // Warn if user supplied no assignment attribute, property is |
| 1370 | // readwrite, and this is an object type. |
| 1371 | if (!(Attributes & (ObjCDeclSpec::DQ_PR_assign | ObjCDeclSpec::DQ_PR_copy | |
| 1372 | ObjCDeclSpec::DQ_PR_retain)) && |
| 1373 | !(Attributes & ObjCDeclSpec::DQ_PR_readonly) && |
| 1374 | Context.isObjCObjectPointerType(PropertyTy)) { |
| 1375 | // Skip this warning in gc-only mode. |
| 1376 | if (getLangOptions().getGCMode() != LangOptions::GCOnly) |
| 1377 | Diag(Loc, diag::warn_objc_property_no_assignment_attribute); |
| 1378 | |
| 1379 | // If non-gc code warn that this is likely inappropriate. |
| 1380 | if (getLangOptions().getGCMode() == LangOptions::NonGC) |
| 1381 | Diag(Loc, diag::warn_objc_property_default_assign_on_object); |
| 1382 | |
| 1383 | // FIXME: Implement warning dependent on NSCopying being |
| 1384 | // implemented. See also: |
| 1385 | // <rdar://5168496&4855821&5607453&5096644&4947311&5698469&4947014&5168496> |
| 1386 | // (please trim this list while you are at it). |
| 1387 | } |
| 1388 | } |
| 1389 | |
Fariborz Jahanian | 1de1e74 | 2008-04-14 23:36:35 +0000 | [diff] [blame] | 1390 | Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, |
| 1391 | FieldDeclarator &FD, |
Fariborz Jahanian | 46b55e5 | 2008-05-05 18:51:55 +0000 | [diff] [blame] | 1392 | ObjCDeclSpec &ODS, |
Fariborz Jahanian | 5251e13 | 2008-05-06 18:09:04 +0000 | [diff] [blame] | 1393 | Selector GetterSel, |
| 1394 | Selector SetterSel, |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 1395 | DeclTy *ClassCategory, |
| 1396 | bool *isOverridingProperty, |
Fariborz Jahanian | 46b55e5 | 2008-05-05 18:51:55 +0000 | [diff] [blame] | 1397 | tok::ObjCKeywordKind MethodImplKind) { |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1398 | unsigned Attributes = ODS.getPropertyAttributes(); |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 1399 | bool isReadWrite = ((Attributes & ObjCDeclSpec::DQ_PR_readwrite) || |
| 1400 | // default is readwrite! |
| 1401 | !(Attributes & ObjCDeclSpec::DQ_PR_readonly)); |
| 1402 | // property is defaulted to 'assign' if it is readwrite and is |
| 1403 | // not retain or copy |
| 1404 | bool isAssign = ((Attributes & ObjCDeclSpec::DQ_PR_assign) || |
| 1405 | (isReadWrite && |
| 1406 | !(Attributes & ObjCDeclSpec::DQ_PR_retain) && |
| 1407 | !(Attributes & ObjCDeclSpec::DQ_PR_copy))); |
| 1408 | QualType T = GetTypeForDeclarator(FD.D, S); |
| 1409 | Decl *ClassDecl = static_cast<Decl *>(ClassCategory); |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1410 | |
| 1411 | // May modify Attributes. |
| 1412 | CheckObjCPropertyAttributes(T, AtLoc, Attributes); |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 1413 | |
| 1414 | if (ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl)) |
| 1415 | if (!CDecl->getIdentifier()) { |
| 1416 | // This is an anonymous category. property requires special |
| 1417 | // handling. |
| 1418 | if (ObjCInterfaceDecl *ICDecl = CDecl->getClassInterface()) { |
| 1419 | if (ObjCPropertyDecl *PIDecl = |
| 1420 | ICDecl->FindPropertyDeclaration(FD.D.getIdentifier())) { |
| 1421 | // property 'PIDecl's readonly attribute will be over-ridden |
| 1422 | // with anonymous category's readwrite property attribute! |
| 1423 | unsigned PIkind = PIDecl->getPropertyAttributes(); |
| 1424 | if (isReadWrite && (PIkind & ObjCPropertyDecl::OBJC_PR_readonly)) { |
Fariborz Jahanian | 9bfb2a2 | 2008-12-08 18:47:29 +0000 | [diff] [blame] | 1425 | if ((Attributes & ObjCPropertyDecl::OBJC_PR_nonatomic) != |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 1426 | (PIkind & ObjCPropertyDecl::OBJC_PR_nonatomic)) |
| 1427 | Diag(AtLoc, diag::warn_property_attr_mismatch); |
| 1428 | PIDecl->makeitReadWriteAttribute(); |
| 1429 | if (Attributes & ObjCDeclSpec::DQ_PR_retain) |
| 1430 | PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain); |
| 1431 | if (Attributes & ObjCDeclSpec::DQ_PR_copy) |
| 1432 | PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy); |
| 1433 | PIDecl->setSetterName(SetterSel); |
| 1434 | // FIXME: use a common routine with addPropertyMethods. |
| 1435 | ObjCMethodDecl *SetterDecl = |
| 1436 | ObjCMethodDecl::Create(Context, AtLoc, AtLoc, SetterSel, |
| 1437 | Context.VoidTy, |
| 1438 | ICDecl, |
| 1439 | true, false, true, |
| 1440 | ObjCMethodDecl::Required); |
| 1441 | ParmVarDecl *Argument = ParmVarDecl::Create(Context, |
| 1442 | SetterDecl, |
| 1443 | SourceLocation(), |
| 1444 | FD.D.getIdentifier(), |
| 1445 | T, |
| 1446 | VarDecl::None, |
| 1447 | 0, 0); |
| 1448 | SetterDecl->setMethodParams(&Argument, 1); |
| 1449 | PIDecl->setSetterMethodDecl(SetterDecl); |
| 1450 | } |
| 1451 | else |
Fariborz Jahanian | 06de37b | 2008-12-04 22:56:16 +0000 | [diff] [blame] | 1452 | Diag(AtLoc, diag::err_use_continuation_class) << ICDecl->getDeclName(); |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 1453 | *isOverridingProperty = true; |
| 1454 | return 0; |
| 1455 | } |
Fariborz Jahanian | b16308f | 2008-11-26 20:33:54 +0000 | [diff] [blame] | 1456 | // No matching property found in the main class. Just fall thru |
| 1457 | // and add property to the anonymous category. It looks like |
| 1458 | // it works as is. This category becomes just like a category |
| 1459 | // for its primary class. |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 1460 | } else { |
| 1461 | Diag(CDecl->getLocation(), diag::err_continuation_class); |
| 1462 | *isOverridingProperty = true; |
| 1463 | return 0; |
| 1464 | } |
| 1465 | } |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1466 | |
Fariborz Jahanian | 105ec4b | 2008-12-16 17:51:01 +0000 | [diff] [blame] | 1467 | Type *t = T.getTypePtr(); |
| 1468 | if (t->isArrayType() || t->isFunctionType()) |
| 1469 | Diag(AtLoc, diag::err_property_type) << T; |
| 1470 | |
Fariborz Jahanian | 1de1e74 | 2008-04-14 23:36:35 +0000 | [diff] [blame] | 1471 | ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, AtLoc, |
| 1472 | FD.D.getIdentifier(), T); |
Fariborz Jahanian | 33de3f0 | 2008-05-07 17:43:59 +0000 | [diff] [blame] | 1473 | // Regardless of setter/getter attribute, we save the default getter/setter |
| 1474 | // selector names in anticipation of declaration of setter/getter methods. |
| 1475 | PDecl->setGetterName(GetterSel); |
| 1476 | PDecl->setSetterName(SetterSel); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1477 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1478 | if (Attributes & ObjCDeclSpec::DQ_PR_readonly) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1479 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1480 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1481 | if (Attributes & ObjCDeclSpec::DQ_PR_getter) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1482 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_getter); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1483 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1484 | if (Attributes & ObjCDeclSpec::DQ_PR_setter) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1485 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_setter); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1486 | |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 1487 | if (isReadWrite) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1488 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1489 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1490 | if (Attributes & ObjCDeclSpec::DQ_PR_retain) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1491 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1492 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1493 | if (Attributes & ObjCDeclSpec::DQ_PR_copy) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1494 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1495 | |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 1496 | if (isAssign) |
| 1497 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign); |
| 1498 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 1499 | if (Attributes & ObjCDeclSpec::DQ_PR_nonatomic) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1500 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1501 | |
Fariborz Jahanian | 46b55e5 | 2008-05-05 18:51:55 +0000 | [diff] [blame] | 1502 | if (MethodImplKind == tok::objc_required) |
| 1503 | PDecl->setPropertyImplementation(ObjCPropertyDecl::Required); |
| 1504 | else if (MethodImplKind == tok::objc_optional) |
| 1505 | PDecl->setPropertyImplementation(ObjCPropertyDecl::Optional); |
| 1506 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1507 | return PDecl; |
| 1508 | } |
| 1509 | |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 1510 | /// ActOnPropertyImplDecl - This routine performs semantic checks and |
| 1511 | /// builds the AST node for a property implementation declaration; declared |
| 1512 | /// as @synthesize or @dynamic. |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1513 | /// |
| 1514 | Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, |
| 1515 | SourceLocation PropertyLoc, |
| 1516 | bool Synthesize, |
| 1517 | DeclTy *ClassCatImpDecl, |
| 1518 | IdentifierInfo *PropertyId, |
| 1519 | IdentifierInfo *PropertyIvar) { |
| 1520 | Decl *ClassImpDecl = static_cast<Decl*>(ClassCatImpDecl); |
| 1521 | // Make sure we have a context for the property implementation declaration. |
| 1522 | if (!ClassImpDecl) { |
| 1523 | Diag(AtLoc, diag::error_missing_property_context); |
| 1524 | return 0; |
| 1525 | } |
| 1526 | ObjCPropertyDecl *property = 0; |
| 1527 | ObjCInterfaceDecl* IDecl = 0; |
| 1528 | // Find the class or category class where this property must have |
| 1529 | // a declaration. |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1530 | ObjCImplementationDecl *IC = 0; |
| 1531 | ObjCCategoryImplDecl* CatImplClass = 0; |
| 1532 | if ((IC = dyn_cast<ObjCImplementationDecl>(ClassImpDecl))) { |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1533 | IDecl = getObjCInterfaceDecl(IC->getIdentifier()); |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1534 | // We always synthesize an interface for an implementation |
| 1535 | // without an interface decl. So, IDecl is always non-zero. |
| 1536 | assert(IDecl && |
| 1537 | "ActOnPropertyImplDecl - @implementation without @interface"); |
| 1538 | |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1539 | // Look for this property declaration in the @implementation's @interface |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 1540 | property = IDecl->FindPropertyDeclaration(PropertyId); |
| 1541 | if (!property) { |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 1542 | Diag(PropertyLoc, diag::error_bad_property_decl) << IDecl->getDeclName(); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1543 | return 0; |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 1544 | } |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1545 | } |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1546 | else if ((CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl))) { |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1547 | if (Synthesize) { |
| 1548 | Diag(AtLoc, diag::error_synthesize_category_decl); |
| 1549 | return 0; |
| 1550 | } |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1551 | IDecl = CatImplClass->getClassInterface(); |
| 1552 | if (!IDecl) { |
| 1553 | Diag(AtLoc, diag::error_missing_property_interface); |
| 1554 | return 0; |
| 1555 | } |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 1556 | ObjCCategoryDecl *Category = |
| 1557 | IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier()); |
| 1558 | |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1559 | // If category for this implementation not found, it is an error which |
| 1560 | // has already been reported eralier. |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 1561 | if (!Category) |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1562 | return 0; |
| 1563 | // Look for this property declaration in @implementation's category |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 1564 | property = Category->FindPropertyDeclaration(PropertyId); |
| 1565 | if (!property) { |
Chris Lattner | 5dc266a | 2008-11-20 06:13:02 +0000 | [diff] [blame] | 1566 | Diag(PropertyLoc, diag::error_bad_category_property_decl) |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 1567 | << Category->getDeclName(); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1568 | return 0; |
| 1569 | } |
| 1570 | } |
| 1571 | else { |
| 1572 | Diag(AtLoc, diag::error_bad_property_context); |
| 1573 | return 0; |
| 1574 | } |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1575 | ObjCIvarDecl *Ivar = 0; |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1576 | // Check that we have a valid, previously declared ivar for @synthesize |
| 1577 | if (Synthesize) { |
| 1578 | // @synthesize |
Fariborz Jahanian | 6cdf16d | 2008-04-21 21:57:36 +0000 | [diff] [blame] | 1579 | if (!PropertyIvar) |
| 1580 | PropertyIvar = PropertyId; |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1581 | // Check that this is a previously declared 'ivar' in 'IDecl' interface |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1582 | Ivar = IDecl->FindIvarDeclaration(PropertyIvar); |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1583 | if (!Ivar) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 1584 | Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId; |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1585 | return 0; |
| 1586 | } |
Steve Naroff | 3ce52d6 | 2008-09-30 10:07:56 +0000 | [diff] [blame] | 1587 | QualType PropType = Context.getCanonicalType(property->getType()); |
| 1588 | QualType IvarType = Context.getCanonicalType(Ivar->getType()); |
| 1589 | |
Steve Naroff | fbbe0ac | 2008-09-30 00:24:17 +0000 | [diff] [blame] | 1590 | // Check that type of property and its ivar are type compatible. |
Steve Naroff | 3ce52d6 | 2008-09-30 10:07:56 +0000 | [diff] [blame] | 1591 | if (PropType != IvarType) { |
Steve Naroff | 4fa4ab6 | 2008-10-16 14:59:30 +0000 | [diff] [blame] | 1592 | if (CheckAssignmentConstraints(PropType, IvarType) != Compatible) { |
Chris Lattner | 5dc266a | 2008-11-20 06:13:02 +0000 | [diff] [blame] | 1593 | Diag(PropertyLoc, diag::error_property_ivar_type) |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 1594 | << property->getDeclName() << Ivar->getDeclName(); |
Steve Naroff | 3ce52d6 | 2008-09-30 10:07:56 +0000 | [diff] [blame] | 1595 | return 0; |
| 1596 | } |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 1597 | } |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1598 | } else if (PropertyIvar) { |
| 1599 | // @dynamic |
| 1600 | Diag(PropertyLoc, diag::error_dynamic_property_ivar_decl); |
| 1601 | return 0; |
| 1602 | } |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1603 | assert (property && "ActOnPropertyImplDecl - property declaration missing"); |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1604 | ObjCPropertyImplDecl *PIDecl = |
| 1605 | ObjCPropertyImplDecl::Create(Context, AtLoc, PropertyLoc, property, |
| 1606 | (Synthesize ? |
Daniel Dunbar | 9f0afd4 | 2008-08-26 04:47:31 +0000 | [diff] [blame] | 1607 | ObjCPropertyImplDecl::Synthesize |
| 1608 | : ObjCPropertyImplDecl::Dynamic), |
| 1609 | Ivar); |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1610 | if (IC) { |
| 1611 | if (Synthesize) |
| 1612 | if (ObjCPropertyImplDecl *PPIDecl = |
| 1613 | IC->FindPropertyImplIvarDecl(PropertyIvar)) { |
| 1614 | Diag(PropertyLoc, diag::error_duplicate_ivar_use) |
| 1615 | << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier() |
| 1616 | << PropertyIvar; |
| 1617 | Diag(PPIDecl->getLocation(), diag::note_previous_use); |
| 1618 | } |
| 1619 | |
| 1620 | if (ObjCPropertyImplDecl *PPIDecl = IC->FindPropertyImplDecl(PropertyId)) { |
| 1621 | Diag(PropertyLoc, diag::error_property_implemented) << PropertyId; |
| 1622 | Diag(PPIDecl->getLocation(), diag::note_previous_declaration); |
| 1623 | return 0; |
| 1624 | } |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1625 | IC->addPropertyImplementation(PIDecl); |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1626 | } |
| 1627 | else { |
| 1628 | if (Synthesize) |
| 1629 | if (ObjCPropertyImplDecl *PPIDecl = |
| 1630 | CatImplClass->FindPropertyImplIvarDecl(PropertyIvar)) { |
| 1631 | Diag(PropertyLoc, diag::error_duplicate_ivar_use) |
| 1632 | << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier() |
| 1633 | << PropertyIvar; |
| 1634 | Diag(PPIDecl->getLocation(), diag::note_previous_use); |
| 1635 | } |
| 1636 | |
| 1637 | if (ObjCPropertyImplDecl *PPIDecl = |
| 1638 | CatImplClass->FindPropertyImplDecl(PropertyId)) { |
| 1639 | Diag(PropertyLoc, diag::error_property_implemented) << PropertyId; |
| 1640 | Diag(PPIDecl->getLocation(), diag::note_previous_declaration); |
| 1641 | return 0; |
| 1642 | } |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1643 | CatImplClass->addPropertyImplementation(PIDecl); |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 1644 | } |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 1645 | |
| 1646 | return PIDecl; |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 1647 | } |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 1648 | |
Chris Lattner | cc98eac | 2008-12-17 07:13:27 +0000 | [diff] [blame] | 1649 | bool Sema::CheckObjCDeclScope(Decl *D) { |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 1650 | if (isa<TranslationUnitDecl>(CurContext)) |
| 1651 | return false; |
| 1652 | |
| 1653 | Diag(D->getLocation(), diag::err_objc_decls_may_only_appear_in_global_scope); |
| 1654 | D->setInvalidDecl(); |
| 1655 | |
| 1656 | return true; |
| 1657 | } |
Chris Lattner | cc98eac | 2008-12-17 07:13:27 +0000 | [diff] [blame] | 1658 | |
| 1659 | /// Collect the instance variables declared in an Objective-C object. Used in |
| 1660 | /// the creation of structures from objects using the @defs directive. |
| 1661 | /// FIXME: This should be consolidated with CollectObjCIvars as it is also |
| 1662 | /// part of the AST generation logic of @defs. |
| 1663 | static void CollectIvars(ObjCInterfaceDecl *Class, RecordDecl *Record, |
| 1664 | ASTContext& Ctx, |
| 1665 | llvm::SmallVectorImpl<Sema::DeclTy*> &ivars) { |
| 1666 | if (Class->getSuperClass()) |
| 1667 | CollectIvars(Class->getSuperClass(), Record, Ctx, ivars); |
| 1668 | |
| 1669 | // For each ivar, create a fresh ObjCAtDefsFieldDecl. |
| 1670 | for (ObjCInterfaceDecl::ivar_iterator |
| 1671 | I=Class->ivar_begin(), E=Class->ivar_end(); I!=E; ++I) { |
| 1672 | |
| 1673 | ObjCIvarDecl* ID = *I; |
| 1674 | ivars.push_back(ObjCAtDefsFieldDecl::Create(Ctx, Record, |
| 1675 | ID->getLocation(), |
| 1676 | ID->getIdentifier(), |
| 1677 | ID->getType(), |
| 1678 | ID->getBitWidth())); |
| 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | /// Called whenever @defs(ClassName) is encountered in the source. Inserts the |
| 1683 | /// instance variables of ClassName into Decls. |
| 1684 | void Sema::ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart, |
| 1685 | IdentifierInfo *ClassName, |
| 1686 | llvm::SmallVectorImpl<DeclTy*> &Decls) { |
| 1687 | // Check that ClassName is a valid class |
| 1688 | ObjCInterfaceDecl *Class = getObjCInterfaceDecl(ClassName); |
| 1689 | if (!Class) { |
| 1690 | Diag(DeclStart, diag::err_undef_interface) << ClassName; |
| 1691 | return; |
| 1692 | } |
| 1693 | // Collect the instance variables |
| 1694 | CollectIvars(Class, dyn_cast<RecordDecl>((Decl*)TagD), Context, Decls); |
| 1695 | |
| 1696 | // Introduce all of these fields into the appropriate scope. |
| 1697 | for (llvm::SmallVectorImpl<DeclTy*>::iterator D = Decls.begin(); |
| 1698 | D != Decls.end(); ++D) { |
| 1699 | FieldDecl *FD = cast<FieldDecl>((Decl*)*D); |
| 1700 | if (getLangOptions().CPlusPlus) |
| 1701 | PushOnScopeChains(cast<FieldDecl>(FD), S); |
| 1702 | else if (RecordDecl *Record = dyn_cast<RecordDecl>((Decl*)TagD)) |
| 1703 | Record->addDecl(Context, FD); |
| 1704 | } |
| 1705 | } |
| 1706 | |