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" |
Douglas Gregor | f06cdae | 2010-01-03 18:01:57 +0000 | [diff] [blame] | 15 | #include "Lookup.h" |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 16 | #include "clang/Sema/ExternalSemaSource.h" |
Steve Naroff | ca33129 | 2009-03-03 14:49:36 +0000 | [diff] [blame] | 17 | #include "clang/AST/Expr.h" |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
| 19 | #include "clang/AST/DeclObjC.h" |
Daniel Dunbar | 12bc692 | 2008-08-11 03:27:53 +0000 | [diff] [blame] | 20 | #include "clang/Parse/DeclSpec.h" |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | |
Fariborz Jahanian | c001e89 | 2009-05-08 20:20:55 +0000 | [diff] [blame] | 23 | bool Sema::DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *property, |
| 24 | ObjCMethodDecl *GetterMethod, |
| 25 | SourceLocation Loc) { |
| 26 | if (GetterMethod && |
| 27 | GetterMethod->getResultType() != property->getType()) { |
| 28 | AssignConvertType result = Incompatible; |
Steve Naroff | f495456 | 2009-07-16 15:41:00 +0000 | [diff] [blame] | 29 | if (property->getType()->isObjCObjectPointerType()) |
Fariborz Jahanian | 7aaa409 | 2009-05-08 21:10:00 +0000 | [diff] [blame] | 30 | result = CheckAssignmentConstraints(GetterMethod->getResultType(), property->getType()); |
Fariborz Jahanian | c001e89 | 2009-05-08 20:20:55 +0000 | [diff] [blame] | 31 | if (result != Compatible) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 32 | Diag(Loc, diag::warn_accessor_property_type_mismatch) |
Fariborz Jahanian | c001e89 | 2009-05-08 20:20:55 +0000 | [diff] [blame] | 33 | << property->getDeclName() |
| 34 | << GetterMethod->getSelector(); |
| 35 | Diag(GetterMethod->getLocation(), diag::note_declared_at); |
| 36 | return true; |
| 37 | } |
| 38 | } |
| 39 | return false; |
| 40 | } |
| 41 | |
Steve Naroff | ebf6443 | 2009-02-28 16:59:13 +0000 | [diff] [blame] | 42 | /// ActOnStartOfObjCMethodDef - This routine sets up parameters; invisible |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 43 | /// and user declared, in the method definition's AST. |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 44 | void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, DeclPtrTy D) { |
Argyrios Kyrtzidis | 53d0ea5 | 2008-06-28 06:07:14 +0000 | [diff] [blame] | 45 | assert(getCurMethodDecl() == 0 && "Method parsing confused"); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 46 | ObjCMethodDecl *MDecl = dyn_cast_or_null<ObjCMethodDecl>(D.getAs<Decl>()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 47 | |
Steve Naroff | 394f3f4 | 2008-07-25 17:57:26 +0000 | [diff] [blame] | 48 | // If we don't have a valid method decl, simply return. |
| 49 | if (!MDecl) |
| 50 | return; |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 51 | |
Chris Lattner | 38c5ebd | 2009-04-19 05:21:20 +0000 | [diff] [blame] | 52 | CurFunctionNeedsScopeChecking = false; |
Chris Lattner | 6d97e5e | 2010-03-01 20:59:53 +0000 | [diff] [blame^] | 53 | NumErrorsAtStartOfFunction = getDiagnostics().getNumErrors(); |
Chris Lattner | 38c5ebd | 2009-04-19 05:21:20 +0000 | [diff] [blame] | 54 | |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 55 | // Allow the rest of sema to find private method decl implementations. |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 56 | if (MDecl->isInstanceMethod()) |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 57 | AddInstanceMethodToGlobalPool(MDecl); |
| 58 | else |
| 59 | AddFactoryMethodToGlobalPool(MDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 60 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 61 | // 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] | 62 | PushDeclContext(FnBodyScope, MDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 63 | |
| 64 | // Create Decl objects for each parameter, entrring them in the scope for |
| 65 | // binding to their use. |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 66 | |
| 67 | // Insert the invisible arguments, self and _cmd! |
Fariborz Jahanian | fef30b5 | 2008-12-09 20:23:04 +0000 | [diff] [blame] | 68 | MDecl->createImplicitParams(Context, MDecl->getClassInterface()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 69 | |
Daniel Dunbar | 451318c | 2008-08-26 06:07:48 +0000 | [diff] [blame] | 70 | PushOnScopeChains(MDecl->getSelfDecl(), FnBodyScope); |
| 71 | PushOnScopeChains(MDecl->getCmdDecl(), FnBodyScope); |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 72 | |
Chris Lattner | 8123a95 | 2008-04-10 02:22:51 +0000 | [diff] [blame] | 73 | // Introduce all of the other parameters into this scope. |
Chris Lattner | 89951a8 | 2009-02-20 18:43:26 +0000 | [diff] [blame] | 74 | for (ObjCMethodDecl::param_iterator PI = MDecl->param_begin(), |
| 75 | E = MDecl->param_end(); PI != E; ++PI) |
| 76 | if ((*PI)->getIdentifier()) |
| 77 | PushOnScopeChains(*PI, FnBodyScope); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 80 | Sema::DeclPtrTy Sema:: |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 81 | ActOnStartClassInterface(SourceLocation AtInterfaceLoc, |
| 82 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 83 | IdentifierInfo *SuperName, SourceLocation SuperLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 84 | const DeclPtrTy *ProtoRefs, unsigned NumProtoRefs, |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 85 | const SourceLocation *ProtoLocs, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 86 | SourceLocation EndProtoLoc, AttributeList *AttrList) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 87 | assert(ClassName && "Missing class identifier"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 88 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 89 | // Check for another declaration kind with the same name. |
John McCall | f36e02d | 2009-10-09 21:13:30 +0000 | [diff] [blame] | 90 | NamedDecl *PrevDecl = LookupSingleName(TUScope, ClassName, LookupOrdinaryName); |
Douglas Gregor | f57172b | 2008-12-08 18:40:42 +0000 | [diff] [blame] | 91 | if (PrevDecl && PrevDecl->isTemplateParameter()) { |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 92 | // Maybe we will complain about the shadowed template parameter. |
| 93 | DiagnoseTemplateParameterShadow(ClassLoc, PrevDecl); |
| 94 | // Just pretend that we didn't see the previous declaration. |
| 95 | PrevDecl = 0; |
| 96 | } |
| 97 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 98 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 99 | Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName; |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 100 | Diag(PrevDecl->getLocation(), diag::note_previous_definition); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 101 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 102 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 103 | ObjCInterfaceDecl* IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 104 | if (IDecl) { |
| 105 | // Class already seen. Is it a forward declaration? |
Steve Naroff | cfe8bf3 | 2008-11-18 19:15:30 +0000 | [diff] [blame] | 106 | if (!IDecl->isForwardDecl()) { |
Chris Lattner | 1829a6d | 2009-02-23 22:00:08 +0000 | [diff] [blame] | 107 | IDecl->setInvalidDecl(); |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 108 | Diag(AtInterfaceLoc, diag::err_duplicate_class_def)<<IDecl->getDeclName(); |
Chris Lattner | b8b96af | 2008-11-23 22:46:27 +0000 | [diff] [blame] | 109 | Diag(IDecl->getLocation(), diag::note_previous_definition); |
| 110 | |
Steve Naroff | cfe8bf3 | 2008-11-18 19:15:30 +0000 | [diff] [blame] | 111 | // Return the previous class interface. |
| 112 | // FIXME: don't leak the objects passed in! |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 113 | return DeclPtrTy::make(IDecl); |
Steve Naroff | cfe8bf3 | 2008-11-18 19:15:30 +0000 | [diff] [blame] | 114 | } else { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 115 | IDecl->setLocation(AtInterfaceLoc); |
| 116 | IDecl->setForwardDecl(false); |
Steve Naroff | 8b26cbd | 2009-09-11 00:12:01 +0000 | [diff] [blame] | 117 | IDecl->setClassLoc(ClassLoc); |
Ted Kremenek | c32b1d8 | 2009-11-17 22:58:30 +0000 | [diff] [blame] | 118 | |
| 119 | // Since this ObjCInterfaceDecl was created by a forward declaration, |
| 120 | // we now add it to the DeclContext since it wasn't added before |
| 121 | // (see ActOnForwardClassDeclaration). |
| 122 | CurContext->addDecl(IDecl); |
| 123 | |
Fariborz Jahanian | 5f8f857 | 2009-11-17 19:08:08 +0000 | [diff] [blame] | 124 | if (AttrList) |
| 125 | ProcessDeclAttributeList(TUScope, IDecl, AttrList); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 126 | } |
Chris Lattner | b752f28 | 2008-07-21 07:06:49 +0000 | [diff] [blame] | 127 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 128 | IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtInterfaceLoc, |
Steve Naroff | d6a07aa | 2008-04-11 19:35:35 +0000 | [diff] [blame] | 129 | ClassName, ClassLoc); |
Daniel Dunbar | f641492 | 2008-08-20 18:02:42 +0000 | [diff] [blame] | 130 | if (AttrList) |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 131 | ProcessDeclAttributeList(TUScope, IDecl, AttrList); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 132 | |
Steve Naroff | a7503a7 | 2009-04-23 15:15:40 +0000 | [diff] [blame] | 133 | PushOnScopeChains(IDecl, TUScope); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 134 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 135 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 136 | if (SuperName) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 137 | // Check if a different kind of symbol declared in this scope. |
John McCall | f36e02d | 2009-10-09 21:13:30 +0000 | [diff] [blame] | 138 | PrevDecl = LookupSingleName(TUScope, SuperName, LookupOrdinaryName); |
Douglas Gregor | f06cdae | 2010-01-03 18:01:57 +0000 | [diff] [blame] | 139 | |
| 140 | if (!PrevDecl) { |
| 141 | // Try to correct for a typo in the superclass name. |
| 142 | LookupResult R(*this, SuperName, SuperLoc, LookupOrdinaryName); |
| 143 | if (CorrectTypo(R, TUScope, 0) && |
| 144 | (PrevDecl = R.getAsSingle<ObjCInterfaceDecl>())) { |
| 145 | Diag(SuperLoc, diag::err_undef_superclass_suggest) |
| 146 | << SuperName << ClassName << PrevDecl->getDeclName(); |
Douglas Gregor | 67dd1d4 | 2010-01-07 00:17:44 +0000 | [diff] [blame] | 147 | Diag(PrevDecl->getLocation(), diag::note_previous_decl) |
| 148 | << PrevDecl->getDeclName(); |
Douglas Gregor | f06cdae | 2010-01-03 18:01:57 +0000 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
Fariborz Jahanian | fdee089 | 2009-07-09 22:08:26 +0000 | [diff] [blame] | 152 | if (PrevDecl == IDecl) { |
| 153 | Diag(SuperLoc, diag::err_recursive_superclass) |
| 154 | << SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc); |
| 155 | IDecl->setLocEnd(ClassLoc); |
Mike Stump | ac5fc7c | 2009-08-04 21:02:39 +0000 | [diff] [blame] | 156 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 157 | ObjCInterfaceDecl *SuperClassDecl = |
Fariborz Jahanian | fdee089 | 2009-07-09 22:08:26 +0000 | [diff] [blame] | 158 | dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 159 | |
Fariborz Jahanian | fdee089 | 2009-07-09 22:08:26 +0000 | [diff] [blame] | 160 | // Diagnose classes that inherit from deprecated classes. |
| 161 | if (SuperClassDecl) |
| 162 | (void)DiagnoseUseOfDecl(SuperClassDecl, SuperLoc); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 163 | |
Fariborz Jahanian | fdee089 | 2009-07-09 22:08:26 +0000 | [diff] [blame] | 164 | if (PrevDecl && SuperClassDecl == 0) { |
| 165 | // The previous declaration was not a class decl. Check if we have a |
| 166 | // typedef. If we do, get the underlying class type. |
| 167 | if (const TypedefDecl *TDecl = dyn_cast_or_null<TypedefDecl>(PrevDecl)) { |
| 168 | QualType T = TDecl->getUnderlyingType(); |
| 169 | if (T->isObjCInterfaceType()) { |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 170 | if (NamedDecl *IDecl = T->getAs<ObjCInterfaceType>()->getDecl()) |
Fariborz Jahanian | fdee089 | 2009-07-09 22:08:26 +0000 | [diff] [blame] | 171 | SuperClassDecl = dyn_cast<ObjCInterfaceDecl>(IDecl); |
| 172 | } |
| 173 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 174 | |
Fariborz Jahanian | fdee089 | 2009-07-09 22:08:26 +0000 | [diff] [blame] | 175 | // This handles the following case: |
| 176 | // |
| 177 | // typedef int SuperClass; |
| 178 | // @interface MyClass : SuperClass {} @end |
| 179 | // |
| 180 | if (!SuperClassDecl) { |
| 181 | Diag(SuperLoc, diag::err_redefinition_different_kind) << SuperName; |
| 182 | Diag(PrevDecl->getLocation(), diag::note_previous_definition); |
Steve Naroff | 818cb9e | 2009-02-04 17:14:05 +0000 | [diff] [blame] | 183 | } |
| 184 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 185 | |
Fariborz Jahanian | fdee089 | 2009-07-09 22:08:26 +0000 | [diff] [blame] | 186 | if (!dyn_cast_or_null<TypedefDecl>(PrevDecl)) { |
| 187 | if (!SuperClassDecl) |
| 188 | Diag(SuperLoc, diag::err_undef_superclass) |
| 189 | << SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc); |
| 190 | else if (SuperClassDecl->isForwardDecl()) |
| 191 | Diag(SuperLoc, diag::err_undef_superclass) |
| 192 | << SuperClassDecl->getDeclName() << ClassName |
| 193 | << SourceRange(AtInterfaceLoc, ClassLoc); |
Steve Naroff | 818cb9e | 2009-02-04 17:14:05 +0000 | [diff] [blame] | 194 | } |
Fariborz Jahanian | fdee089 | 2009-07-09 22:08:26 +0000 | [diff] [blame] | 195 | IDecl->setSuperClass(SuperClassDecl); |
| 196 | IDecl->setSuperClassLoc(SuperLoc); |
| 197 | IDecl->setLocEnd(SuperLoc); |
Steve Naroff | 818cb9e | 2009-02-04 17:14:05 +0000 | [diff] [blame] | 198 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 199 | } else { // we have a root class. |
| 200 | IDecl->setLocEnd(ClassLoc); |
| 201 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 202 | |
Steve Naroff | cfe8bf3 | 2008-11-18 19:15:30 +0000 | [diff] [blame] | 203 | /// Check then save referenced protocols. |
Chris Lattner | 06036d3 | 2008-07-26 04:13:19 +0000 | [diff] [blame] | 204 | if (NumProtoRefs) { |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 205 | IDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs, |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 206 | ProtoLocs, Context); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 207 | IDecl->setLocEnd(EndProtoLoc); |
| 208 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 209 | |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 210 | CheckObjCDeclScope(IDecl); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 211 | return DeclPtrTy::make(IDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | /// ActOnCompatiblityAlias - this action is called after complete parsing of |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 215 | /// @compatibility_alias declaration. It sets up the alias relationships. |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 216 | Sema::DeclPtrTy Sema::ActOnCompatiblityAlias(SourceLocation AtLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 217 | IdentifierInfo *AliasName, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 218 | SourceLocation AliasLocation, |
| 219 | IdentifierInfo *ClassName, |
| 220 | SourceLocation ClassLocation) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 221 | // Look for previous declaration of alias name |
John McCall | f36e02d | 2009-10-09 21:13:30 +0000 | [diff] [blame] | 222 | NamedDecl *ADecl = LookupSingleName(TUScope, AliasName, LookupOrdinaryName); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 223 | if (ADecl) { |
Chris Lattner | 8b265bd | 2008-11-23 23:20:13 +0000 | [diff] [blame] | 224 | if (isa<ObjCCompatibleAliasDecl>(ADecl)) |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 225 | Diag(AliasLocation, diag::warn_previous_alias_decl); |
Chris Lattner | 8b265bd | 2008-11-23 23:20:13 +0000 | [diff] [blame] | 226 | else |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 227 | Diag(AliasLocation, diag::err_conflicting_aliasing_type) << AliasName; |
Chris Lattner | 8b265bd | 2008-11-23 23:20:13 +0000 | [diff] [blame] | 228 | Diag(ADecl->getLocation(), diag::note_previous_declaration); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 229 | return DeclPtrTy(); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 230 | } |
| 231 | // Check for class declaration |
John McCall | f36e02d | 2009-10-09 21:13:30 +0000 | [diff] [blame] | 232 | NamedDecl *CDeclU = LookupSingleName(TUScope, ClassName, LookupOrdinaryName); |
Fariborz Jahanian | 305c658 | 2009-01-08 01:10:55 +0000 | [diff] [blame] | 233 | if (const TypedefDecl *TDecl = dyn_cast_or_null<TypedefDecl>(CDeclU)) { |
| 234 | QualType T = TDecl->getUnderlyingType(); |
| 235 | if (T->isObjCInterfaceType()) { |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 236 | if (NamedDecl *IDecl = T->getAs<ObjCInterfaceType>()->getDecl()) { |
Fariborz Jahanian | 305c658 | 2009-01-08 01:10:55 +0000 | [diff] [blame] | 237 | ClassName = IDecl->getIdentifier(); |
John McCall | f36e02d | 2009-10-09 21:13:30 +0000 | [diff] [blame] | 238 | CDeclU = LookupSingleName(TUScope, ClassName, LookupOrdinaryName); |
Fariborz Jahanian | 305c658 | 2009-01-08 01:10:55 +0000 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | } |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 242 | ObjCInterfaceDecl *CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDeclU); |
| 243 | if (CDecl == 0) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 244 | Diag(ClassLocation, diag::warn_undef_interface) << ClassName; |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 245 | if (CDeclU) |
Chris Lattner | 8b265bd | 2008-11-23 23:20:13 +0000 | [diff] [blame] | 246 | Diag(CDeclU->getLocation(), diag::note_previous_declaration); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 247 | return DeclPtrTy(); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 248 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 249 | |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 250 | // Everything checked out, instantiate a new alias declaration AST. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 251 | ObjCCompatibleAliasDecl *AliasDecl = |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 252 | ObjCCompatibleAliasDecl::Create(Context, CurContext, AtLoc, AliasName, CDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 253 | |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 254 | if (!CheckObjCDeclScope(AliasDecl)) |
Douglas Gregor | 516ff43 | 2009-04-24 02:57:34 +0000 | [diff] [blame] | 255 | PushOnScopeChains(AliasDecl, TUScope); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 256 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 257 | return DeclPtrTy::make(AliasDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Steve Naroff | 61d6852 | 2009-03-05 15:22:01 +0000 | [diff] [blame] | 260 | void Sema::CheckForwardProtocolDeclarationForCircularDependency( |
| 261 | IdentifierInfo *PName, |
| 262 | SourceLocation &Ploc, SourceLocation PrevLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 263 | const ObjCList<ObjCProtocolDecl> &PList) { |
Steve Naroff | 61d6852 | 2009-03-05 15:22:01 +0000 | [diff] [blame] | 264 | for (ObjCList<ObjCProtocolDecl>::iterator I = PList.begin(), |
| 265 | E = PList.end(); I != E; ++I) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 266 | |
Douglas Gregor | 6e378de | 2009-04-23 23:18:26 +0000 | [diff] [blame] | 267 | if (ObjCProtocolDecl *PDecl = LookupProtocol((*I)->getIdentifier())) { |
Steve Naroff | 61d6852 | 2009-03-05 15:22:01 +0000 | [diff] [blame] | 268 | if (PDecl->getIdentifier() == PName) { |
| 269 | Diag(Ploc, diag::err_protocol_has_circular_dependency); |
| 270 | Diag(PrevLoc, diag::note_previous_definition); |
| 271 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 272 | CheckForwardProtocolDeclarationForCircularDependency(PName, Ploc, |
Steve Naroff | 61d6852 | 2009-03-05 15:22:01 +0000 | [diff] [blame] | 273 | PDecl->getLocation(), PDecl->getReferencedProtocols()); |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 278 | Sema::DeclPtrTy |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 279 | Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc, |
| 280 | IdentifierInfo *ProtocolName, |
| 281 | SourceLocation ProtocolLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 282 | const DeclPtrTy *ProtoRefs, |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 283 | unsigned NumProtoRefs, |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 284 | const SourceLocation *ProtoLocs, |
Daniel Dunbar | 246e70f | 2008-09-26 04:48:09 +0000 | [diff] [blame] | 285 | SourceLocation EndProtoLoc, |
| 286 | AttributeList *AttrList) { |
| 287 | // FIXME: Deal with AttrList. |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 288 | assert(ProtocolName && "Missing protocol identifier"); |
Douglas Gregor | 6e378de | 2009-04-23 23:18:26 +0000 | [diff] [blame] | 289 | ObjCProtocolDecl *PDecl = LookupProtocol(ProtocolName); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 290 | if (PDecl) { |
| 291 | // Protocol already seen. Better be a forward protocol declaration |
Chris Lattner | 439e71f | 2008-03-16 01:25:17 +0000 | [diff] [blame] | 292 | if (!PDecl->isForwardDecl()) { |
Fariborz Jahanian | e2573e5 | 2009-04-06 23:43:32 +0000 | [diff] [blame] | 293 | Diag(ProtocolLoc, diag::warn_duplicate_protocol_def) << ProtocolName; |
Chris Lattner | b8b96af | 2008-11-23 22:46:27 +0000 | [diff] [blame] | 294 | Diag(PDecl->getLocation(), diag::note_previous_definition); |
Chris Lattner | 439e71f | 2008-03-16 01:25:17 +0000 | [diff] [blame] | 295 | // Just return the protocol we already had. |
| 296 | // FIXME: don't leak the objects passed in! |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 297 | return DeclPtrTy::make(PDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 298 | } |
Steve Naroff | 61d6852 | 2009-03-05 15:22:01 +0000 | [diff] [blame] | 299 | ObjCList<ObjCProtocolDecl> PList; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 300 | PList.set((ObjCProtocolDecl *const*)ProtoRefs, NumProtoRefs, Context); |
Steve Naroff | 61d6852 | 2009-03-05 15:22:01 +0000 | [diff] [blame] | 301 | CheckForwardProtocolDeclarationForCircularDependency( |
| 302 | ProtocolName, ProtocolLoc, PDecl->getLocation(), PList); |
| 303 | PList.Destroy(Context); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 304 | |
Steve Naroff | f11b508 | 2008-08-13 16:39:22 +0000 | [diff] [blame] | 305 | // Make sure the cached decl gets a valid start location. |
| 306 | PDecl->setLocation(AtProtoInterfaceLoc); |
Chris Lattner | 439e71f | 2008-03-16 01:25:17 +0000 | [diff] [blame] | 307 | PDecl->setForwardDecl(false); |
Chris Lattner | 439e71f | 2008-03-16 01:25:17 +0000 | [diff] [blame] | 308 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 309 | PDecl = ObjCProtocolDecl::Create(Context, CurContext, |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 310 | AtProtoInterfaceLoc,ProtocolName); |
Douglas Gregor | 6e378de | 2009-04-23 23:18:26 +0000 | [diff] [blame] | 311 | PushOnScopeChains(PDecl, TUScope); |
Chris Lattner | c858105 | 2008-03-16 20:19:15 +0000 | [diff] [blame] | 312 | PDecl->setForwardDecl(false); |
Chris Lattner | cca59d7 | 2008-03-16 01:23:04 +0000 | [diff] [blame] | 313 | } |
Fariborz Jahanian | bc1c877 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 314 | if (AttrList) |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 315 | ProcessDeclAttributeList(TUScope, PDecl, AttrList); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 316 | if (NumProtoRefs) { |
Chris Lattner | c858105 | 2008-03-16 20:19:15 +0000 | [diff] [blame] | 317 | /// Check then save referenced protocols. |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 318 | PDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs, |
| 319 | ProtoLocs, Context); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 320 | PDecl->setLocEnd(EndProtoLoc); |
| 321 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 322 | |
| 323 | CheckObjCDeclScope(PDecl); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 324 | return DeclPtrTy::make(PDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /// FindProtocolDeclaration - This routine looks up protocols and |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 328 | /// issues an error if they are not declared. It returns list of |
| 329 | /// protocol declarations in its 'Protocols' argument. |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 330 | void |
Chris Lattner | e13b959 | 2008-07-26 04:03:38 +0000 | [diff] [blame] | 331 | Sema::FindProtocolDeclaration(bool WarnOnDeclarations, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 332 | const IdentifierLocPair *ProtocolId, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 333 | unsigned NumProtocols, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 334 | llvm::SmallVectorImpl<DeclPtrTy> &Protocols) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 335 | for (unsigned i = 0; i != NumProtocols; ++i) { |
Douglas Gregor | 6e378de | 2009-04-23 23:18:26 +0000 | [diff] [blame] | 336 | ObjCProtocolDecl *PDecl = LookupProtocol(ProtocolId[i].first); |
Chris Lattner | eacc392 | 2008-07-26 03:47:43 +0000 | [diff] [blame] | 337 | if (!PDecl) { |
Douglas Gregor | f06cdae | 2010-01-03 18:01:57 +0000 | [diff] [blame] | 338 | LookupResult R(*this, ProtocolId[i].first, ProtocolId[i].second, |
| 339 | LookupObjCProtocolName); |
| 340 | if (CorrectTypo(R, TUScope, 0) && |
| 341 | (PDecl = R.getAsSingle<ObjCProtocolDecl>())) { |
| 342 | Diag(ProtocolId[i].second, diag::err_undeclared_protocol_suggest) |
| 343 | << ProtocolId[i].first << R.getLookupName(); |
Douglas Gregor | 67dd1d4 | 2010-01-07 00:17:44 +0000 | [diff] [blame] | 344 | Diag(PDecl->getLocation(), diag::note_previous_decl) |
| 345 | << PDecl->getDeclName(); |
Douglas Gregor | f06cdae | 2010-01-03 18:01:57 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
| 349 | if (!PDecl) { |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 350 | Diag(ProtocolId[i].second, diag::err_undeclared_protocol) |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 351 | << ProtocolId[i].first; |
Chris Lattner | eacc392 | 2008-07-26 03:47:43 +0000 | [diff] [blame] | 352 | continue; |
| 353 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 354 | |
Douglas Gregor | 48f3bb9 | 2009-02-18 21:56:37 +0000 | [diff] [blame] | 355 | (void)DiagnoseUseOfDecl(PDecl, ProtocolId[i].second); |
Chris Lattner | eacc392 | 2008-07-26 03:47:43 +0000 | [diff] [blame] | 356 | |
| 357 | // If this is a forward declaration and we are supposed to warn in this |
| 358 | // case, do it. |
| 359 | if (WarnOnDeclarations && PDecl->isForwardDecl()) |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 360 | Diag(ProtocolId[i].second, diag::warn_undef_protocolref) |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 361 | << ProtocolId[i].first; |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 362 | Protocols.push_back(DeclPtrTy::make(PDecl)); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 366 | /// DiagnosePropertyMismatch - Compares two properties for their |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 367 | /// attributes and types and warns on a variety of inconsistencies. |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 368 | /// |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 369 | void |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 370 | Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property, |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 371 | ObjCPropertyDecl *SuperProperty, |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 372 | const IdentifierInfo *inheritedName) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 373 | ObjCPropertyDecl::PropertyAttributeKind CAttr = |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 374 | Property->getPropertyAttributes(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 375 | ObjCPropertyDecl::PropertyAttributeKind SAttr = |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 376 | SuperProperty->getPropertyAttributes(); |
| 377 | if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly) |
| 378 | && (SAttr & ObjCPropertyDecl::OBJC_PR_readwrite)) |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 379 | Diag(Property->getLocation(), diag::warn_readonly_property) |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 380 | << Property->getDeclName() << inheritedName; |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 381 | if ((CAttr & ObjCPropertyDecl::OBJC_PR_copy) |
| 382 | != (SAttr & ObjCPropertyDecl::OBJC_PR_copy)) |
Chris Lattner | c9c7c4e | 2008-11-18 22:52:51 +0000 | [diff] [blame] | 383 | Diag(Property->getLocation(), diag::warn_property_attribute) |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 384 | << Property->getDeclName() << "copy" << inheritedName; |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 385 | else if ((CAttr & ObjCPropertyDecl::OBJC_PR_retain) |
| 386 | != (SAttr & ObjCPropertyDecl::OBJC_PR_retain)) |
Chris Lattner | c9c7c4e | 2008-11-18 22:52:51 +0000 | [diff] [blame] | 387 | Diag(Property->getLocation(), diag::warn_property_attribute) |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 388 | << Property->getDeclName() << "retain" << inheritedName; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 389 | |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 390 | if ((CAttr & ObjCPropertyDecl::OBJC_PR_nonatomic) |
| 391 | != (SAttr & ObjCPropertyDecl::OBJC_PR_nonatomic)) |
Chris Lattner | c9c7c4e | 2008-11-18 22:52:51 +0000 | [diff] [blame] | 392 | Diag(Property->getLocation(), diag::warn_property_attribute) |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 393 | << Property->getDeclName() << "atomic" << inheritedName; |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 394 | if (Property->getSetterName() != SuperProperty->getSetterName()) |
Chris Lattner | c9c7c4e | 2008-11-18 22:52:51 +0000 | [diff] [blame] | 395 | Diag(Property->getLocation(), diag::warn_property_attribute) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 396 | << Property->getDeclName() << "setter" << inheritedName; |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 397 | if (Property->getGetterName() != SuperProperty->getGetterName()) |
Chris Lattner | c9c7c4e | 2008-11-18 22:52:51 +0000 | [diff] [blame] | 398 | Diag(Property->getLocation(), diag::warn_property_attribute) |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 399 | << Property->getDeclName() << "getter" << inheritedName; |
Steve Naroff | 15edf0d | 2009-03-03 15:43:24 +0000 | [diff] [blame] | 400 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | QualType LHSType = |
Steve Naroff | 15edf0d | 2009-03-03 15:43:24 +0000 | [diff] [blame] | 402 | Context.getCanonicalType(SuperProperty->getType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 403 | QualType RHSType = |
Steve Naroff | 15edf0d | 2009-03-03 15:43:24 +0000 | [diff] [blame] | 404 | Context.getCanonicalType(Property->getType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 405 | |
Steve Naroff | 15edf0d | 2009-03-03 15:43:24 +0000 | [diff] [blame] | 406 | if (!Context.typesAreCompatible(LHSType, RHSType)) { |
| 407 | // FIXME: Incorporate this test with typesAreCompatible. |
| 408 | if (LHSType->isObjCQualifiedIdType() && RHSType->isObjCQualifiedIdType()) |
Steve Naroff | 4084c30 | 2009-07-23 01:01:38 +0000 | [diff] [blame] | 409 | if (Context.ObjCQualifiedIdTypesAreCompatible(LHSType, RHSType, false)) |
Steve Naroff | 15edf0d | 2009-03-03 15:43:24 +0000 | [diff] [blame] | 410 | return; |
| 411 | Diag(Property->getLocation(), diag::warn_property_types_are_incompatible) |
| 412 | << Property->getType() << SuperProperty->getType() << inheritedName; |
| 413 | } |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /// ComparePropertiesInBaseAndSuper - This routine compares property |
| 417 | /// declarations in base and its super class, if any, and issues |
| 418 | /// diagnostics in a variety of inconsistant situations. |
| 419 | /// |
Chris Lattner | 70f1954 | 2009-02-16 21:26:43 +0000 | [diff] [blame] | 420 | void Sema::ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl) { |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 421 | ObjCInterfaceDecl *SDecl = IDecl->getSuperClass(); |
| 422 | if (!SDecl) |
| 423 | return; |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 424 | // FIXME: O(N^2) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 425 | for (ObjCInterfaceDecl::prop_iterator S = SDecl->prop_begin(), |
| 426 | E = SDecl->prop_end(); S != E; ++S) { |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 427 | ObjCPropertyDecl *SuperPDecl = (*S); |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 428 | // Does property in super class has declaration in current class? |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 429 | for (ObjCInterfaceDecl::prop_iterator I = IDecl->prop_begin(), |
| 430 | E = IDecl->prop_end(); I != E; ++I) { |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 431 | ObjCPropertyDecl *PDecl = (*I); |
| 432 | if (SuperPDecl->getIdentifier() == PDecl->getIdentifier()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 433 | DiagnosePropertyMismatch(PDecl, SuperPDecl, |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 434 | SDecl->getIdentifier()); |
Fariborz Jahanian | b5e0224 | 2008-04-24 19:58:34 +0000 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | } |
| 438 | |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 439 | /// MatchOneProtocolPropertiesInClass - This routine goes thru the list |
| 440 | /// of properties declared in a protocol and compares their attribute against |
| 441 | /// the same property declared in the class or category. |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 442 | void |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 443 | Sema::MatchOneProtocolPropertiesInClass(Decl *CDecl, |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 444 | ObjCProtocolDecl *PDecl) { |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 445 | ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDecl); |
| 446 | if (!IDecl) { |
| 447 | // Category |
| 448 | ObjCCategoryDecl *CatDecl = static_cast<ObjCCategoryDecl*>(CDecl); |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 449 | assert (CatDecl && "MatchOneProtocolPropertiesInClass"); |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 450 | if (!CatDecl->IsClassExtension()) |
| 451 | for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(), |
| 452 | E = PDecl->prop_end(); P != E; ++P) { |
| 453 | ObjCPropertyDecl *Pr = (*P); |
| 454 | ObjCCategoryDecl::prop_iterator CP, CE; |
| 455 | // Is this property already in category's list of properties? |
| 456 | for (CP = CatDecl->prop_begin(), CE = CatDecl->prop_end(); CP != CE; ++CP) |
| 457 | if ((*CP)->getIdentifier() == Pr->getIdentifier()) |
| 458 | break; |
| 459 | if (CP != CE) |
| 460 | // Property protocol already exist in class. Diagnose any mismatch. |
| 461 | DiagnosePropertyMismatch((*CP), Pr, PDecl->getIdentifier()); |
| 462 | } |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 463 | return; |
| 464 | } |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 465 | for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(), |
| 466 | E = PDecl->prop_end(); P != E; ++P) { |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 467 | ObjCPropertyDecl *Pr = (*P); |
Steve Naroff | 09c4719 | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 468 | ObjCInterfaceDecl::prop_iterator CP, CE; |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 469 | // Is this property already in class's list of properties? |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 470 | for (CP = IDecl->prop_begin(), CE = IDecl->prop_end(); CP != CE; ++CP) |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 471 | if ((*CP)->getIdentifier() == Pr->getIdentifier()) |
| 472 | break; |
Fariborz Jahanian | a66793e | 2009-01-09 21:04:52 +0000 | [diff] [blame] | 473 | if (CP != CE) |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 474 | // Property protocol already exist in class. Diagnose any mismatch. |
Chris Lattner | 8ec03f5 | 2008-11-24 03:54:41 +0000 | [diff] [blame] | 475 | DiagnosePropertyMismatch((*CP), Pr, PDecl->getIdentifier()); |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 476 | } |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 479 | /// CompareProperties - This routine compares properties |
| 480 | /// declared in 'ClassOrProtocol' objects (which can be a class or an |
| 481 | /// inherited protocol with the list of properties for class/category 'CDecl' |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 482 | /// |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 483 | void Sema::CompareProperties(Decl *CDecl, |
| 484 | DeclPtrTy ClassOrProtocol) { |
| 485 | Decl *ClassDecl = ClassOrProtocol.getAs<Decl>(); |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 486 | ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDecl); |
| 487 | |
| 488 | if (!IDecl) { |
| 489 | // Category |
| 490 | ObjCCategoryDecl *CatDecl = static_cast<ObjCCategoryDecl*>(CDecl); |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 491 | assert (CatDecl && "CompareProperties"); |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 492 | if (ObjCCategoryDecl *MDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl)) { |
| 493 | for (ObjCCategoryDecl::protocol_iterator P = MDecl->protocol_begin(), |
| 494 | E = MDecl->protocol_end(); P != E; ++P) |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 495 | // Match properties of category with those of protocol (*P) |
| 496 | MatchOneProtocolPropertiesInClass(CatDecl, *P); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 497 | |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 498 | // Go thru the list of protocols for this category and recursively match |
| 499 | // their properties with those in the category. |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 500 | for (ObjCCategoryDecl::protocol_iterator P = CatDecl->protocol_begin(), |
| 501 | E = CatDecl->protocol_end(); P != E; ++P) |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 502 | CompareProperties(CatDecl, DeclPtrTy::make(*P)); |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 503 | } else { |
| 504 | ObjCProtocolDecl *MD = cast<ObjCProtocolDecl>(ClassDecl); |
| 505 | for (ObjCProtocolDecl::protocol_iterator P = MD->protocol_begin(), |
| 506 | E = MD->protocol_end(); P != E; ++P) |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 507 | MatchOneProtocolPropertiesInClass(CatDecl, *P); |
Fariborz Jahanian | 1ac2bc4 | 2008-12-06 23:03:39 +0000 | [diff] [blame] | 508 | } |
| 509 | return; |
| 510 | } |
| 511 | |
Chris Lattner | b752f28 | 2008-07-21 07:06:49 +0000 | [diff] [blame] | 512 | if (ObjCInterfaceDecl *MDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) { |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 513 | for (ObjCInterfaceDecl::protocol_iterator P = MDecl->protocol_begin(), |
| 514 | E = MDecl->protocol_end(); P != E; ++P) |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 515 | // Match properties of class IDecl with those of protocol (*P). |
| 516 | MatchOneProtocolPropertiesInClass(IDecl, *P); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 517 | |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 518 | // Go thru the list of protocols for this class and recursively match |
| 519 | // their properties with those declared in the class. |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 520 | for (ObjCInterfaceDecl::protocol_iterator P = IDecl->protocol_begin(), |
| 521 | E = IDecl->protocol_end(); P != E; ++P) |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 522 | CompareProperties(IDecl, DeclPtrTy::make(*P)); |
Chris Lattner | b752f28 | 2008-07-21 07:06:49 +0000 | [diff] [blame] | 523 | } else { |
Argyrios Kyrtzidis | e8f0d30 | 2008-07-21 09:18:38 +0000 | [diff] [blame] | 524 | ObjCProtocolDecl *MD = cast<ObjCProtocolDecl>(ClassDecl); |
| 525 | for (ObjCProtocolDecl::protocol_iterator P = MD->protocol_begin(), |
| 526 | E = MD->protocol_end(); P != E; ++P) |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 527 | MatchOneProtocolPropertiesInClass(IDecl, *P); |
Chris Lattner | b752f28 | 2008-07-21 07:06:49 +0000 | [diff] [blame] | 528 | } |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 529 | } |
| 530 | |
Fariborz Jahanian | 78c39c7 | 2009-03-02 19:06:08 +0000 | [diff] [blame] | 531 | /// DiagnoseClassExtensionDupMethods - Check for duplicate declaration of |
Fariborz Jahanian | b7f95f5 | 2009-03-02 19:05:07 +0000 | [diff] [blame] | 532 | /// a class method in its extension. |
| 533 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 534 | void Sema::DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, |
Fariborz Jahanian | b7f95f5 | 2009-03-02 19:05:07 +0000 | [diff] [blame] | 535 | ObjCInterfaceDecl *ID) { |
| 536 | if (!ID) |
| 537 | return; // Possibly due to previous error |
| 538 | |
| 539 | llvm::DenseMap<Selector, const ObjCMethodDecl*> MethodMap; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 540 | for (ObjCInterfaceDecl::method_iterator i = ID->meth_begin(), |
| 541 | e = ID->meth_end(); i != e; ++i) { |
Fariborz Jahanian | b7f95f5 | 2009-03-02 19:05:07 +0000 | [diff] [blame] | 542 | ObjCMethodDecl *MD = *i; |
| 543 | MethodMap[MD->getSelector()] = MD; |
| 544 | } |
| 545 | |
| 546 | if (MethodMap.empty()) |
| 547 | return; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 548 | for (ObjCCategoryDecl::method_iterator i = CAT->meth_begin(), |
| 549 | e = CAT->meth_end(); i != e; ++i) { |
Fariborz Jahanian | b7f95f5 | 2009-03-02 19:05:07 +0000 | [diff] [blame] | 550 | ObjCMethodDecl *Method = *i; |
| 551 | const ObjCMethodDecl *&PrevMethod = MethodMap[Method->getSelector()]; |
| 552 | if (PrevMethod && !MatchTwoMethodDeclarations(Method, PrevMethod)) { |
| 553 | Diag(Method->getLocation(), diag::err_duplicate_method_decl) |
| 554 | << Method->getDeclName(); |
| 555 | Diag(PrevMethod->getLocation(), diag::note_previous_declaration); |
| 556 | } |
| 557 | } |
| 558 | } |
| 559 | |
Chris Lattner | 58fe03b | 2009-04-12 08:43:13 +0000 | [diff] [blame] | 560 | /// ActOnForwardProtocolDeclaration - Handle @protocol foo; |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 561 | Action::DeclPtrTy |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 562 | Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 563 | const IdentifierLocPair *IdentList, |
Fariborz Jahanian | bc1c877 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 564 | unsigned NumElts, |
| 565 | AttributeList *attrList) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 566 | llvm::SmallVector<ObjCProtocolDecl*, 32> Protocols; |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 567 | llvm::SmallVector<SourceLocation, 8> ProtoLocs; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 568 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 569 | for (unsigned i = 0; i != NumElts; ++i) { |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 570 | IdentifierInfo *Ident = IdentList[i].first; |
Douglas Gregor | 6e378de | 2009-04-23 23:18:26 +0000 | [diff] [blame] | 571 | ObjCProtocolDecl *PDecl = LookupProtocol(Ident); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 572 | if (PDecl == 0) { // Not already seen? |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 573 | PDecl = ObjCProtocolDecl::Create(Context, CurContext, |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 574 | IdentList[i].second, Ident); |
Douglas Gregor | 6e378de | 2009-04-23 23:18:26 +0000 | [diff] [blame] | 575 | PushOnScopeChains(PDecl, TUScope); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 576 | } |
Fariborz Jahanian | bc1c877 | 2008-12-17 01:07:27 +0000 | [diff] [blame] | 577 | if (attrList) |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 578 | ProcessDeclAttributeList(TUScope, PDecl, attrList); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 579 | Protocols.push_back(PDecl); |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 580 | ProtoLocs.push_back(IdentList[i].second); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 581 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 582 | |
| 583 | ObjCForwardProtocolDecl *PDecl = |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 584 | ObjCForwardProtocolDecl::Create(Context, CurContext, AtProtocolLoc, |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 585 | Protocols.data(), Protocols.size(), |
| 586 | ProtoLocs.data()); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 587 | CurContext->addDecl(PDecl); |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 588 | CheckObjCDeclScope(PDecl); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 589 | return DeclPtrTy::make(PDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 592 | Sema::DeclPtrTy Sema:: |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 593 | ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc, |
| 594 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 595 | IdentifierInfo *CategoryName, |
| 596 | SourceLocation CategoryLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 597 | const DeclPtrTy *ProtoRefs, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 598 | unsigned NumProtoRefs, |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 599 | const SourceLocation *ProtoLocs, |
Chris Lattner | 7caeabd | 2008-07-21 22:17:28 +0000 | [diff] [blame] | 600 | SourceLocation EndProtoLoc) { |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 601 | ObjCCategoryDecl *CDecl = 0; |
Douglas Gregor | f06cdae | 2010-01-03 18:01:57 +0000 | [diff] [blame] | 602 | ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName, ClassLoc); |
Ted Kremenek | 09b6897 | 2010-02-23 19:39:46 +0000 | [diff] [blame] | 603 | |
| 604 | /// Check that class of this category is already completely declared. |
| 605 | if (!IDecl || IDecl->isForwardDecl()) { |
| 606 | // Create an invalid ObjCCategoryDecl to serve as context for |
| 607 | // the enclosing method declarations. We mark the decl invalid |
| 608 | // to make it clear that this isn't a valid AST. |
| 609 | CDecl = ObjCCategoryDecl::Create(Context, CurContext, AtInterfaceLoc, |
| 610 | ClassLoc, CategoryLoc, CategoryName); |
| 611 | CDecl->setInvalidDecl(); |
| 612 | Diag(ClassLoc, diag::err_undef_interface) << ClassName; |
| 613 | return DeclPtrTy::make(CDecl); |
| 614 | } |
| 615 | |
| 616 | if (!CategoryName) { |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 617 | // Class extensions require a special treatment. Use an existing one. |
Ted Kremenek | 09b6897 | 2010-02-23 19:39:46 +0000 | [diff] [blame] | 618 | // Note that 'getClassExtension()' can return NULL. |
Fariborz Jahanian | 0e5ad25 | 2010-02-23 01:26:30 +0000 | [diff] [blame] | 619 | CDecl = IDecl->getClassExtension(); |
Ted Kremenek | 09b6897 | 2010-02-23 19:39:46 +0000 | [diff] [blame] | 620 | } |
| 621 | |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 622 | if (!CDecl) { |
Ted Kremenek | 09b6897 | 2010-02-23 19:39:46 +0000 | [diff] [blame] | 623 | CDecl = ObjCCategoryDecl::Create(Context, CurContext, AtInterfaceLoc, |
| 624 | ClassLoc, CategoryLoc, CategoryName); |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 625 | // FIXME: PushOnScopeChains? |
| 626 | CurContext->addDecl(CDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 627 | |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 628 | CDecl->setClassInterface(IDecl); |
| 629 | // Insert first use of class extension to the list of class's categories. |
| 630 | if (!CategoryName) |
| 631 | CDecl->insertNextClassCategory(); |
| 632 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 633 | |
Chris Lattner | 16b34b4 | 2009-02-16 21:30:01 +0000 | [diff] [blame] | 634 | // If the interface is deprecated, warn about it. |
Douglas Gregor | 48f3bb9 | 2009-02-18 21:56:37 +0000 | [diff] [blame] | 635 | (void)DiagnoseUseOfDecl(IDecl, ClassLoc); |
Chris Lattner | 70f1954 | 2009-02-16 21:26:43 +0000 | [diff] [blame] | 636 | |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 637 | if (CategoryName) { |
| 638 | /// Check for duplicate interface declaration for this category |
| 639 | ObjCCategoryDecl *CDeclChain; |
| 640 | for (CDeclChain = IDecl->getCategoryList(); CDeclChain; |
| 641 | CDeclChain = CDeclChain->getNextClassCategory()) { |
| 642 | if (CDeclChain->getIdentifier() == CategoryName) { |
| 643 | // Class extensions can be declared multiple times. |
| 644 | Diag(CategoryLoc, diag::warn_dup_category_def) |
| 645 | << ClassName << CategoryName; |
| 646 | Diag(CDeclChain->getLocation(), diag::note_previous_definition); |
| 647 | break; |
| 648 | } |
Chris Lattner | 70f1954 | 2009-02-16 21:26:43 +0000 | [diff] [blame] | 649 | } |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 650 | if (!CDeclChain) |
| 651 | CDecl->insertNextClassCategory(); |
Chris Lattner | 70f1954 | 2009-02-16 21:26:43 +0000 | [diff] [blame] | 652 | } |
Chris Lattner | 70f1954 | 2009-02-16 21:26:43 +0000 | [diff] [blame] | 653 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 654 | if (NumProtoRefs) { |
Fariborz Jahanian | b106fc6 | 2009-10-05 21:32:49 +0000 | [diff] [blame] | 655 | CDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs, |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 656 | ProtoLocs, Context); |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 657 | // Protocols in the class extension belong to the class. |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 658 | if (CDecl->IsClassExtension()) |
Fariborz Jahanian | 339798e | 2009-10-05 20:41:32 +0000 | [diff] [blame] | 659 | IDecl->mergeClassExtensionProtocolList((ObjCProtocolDecl**)ProtoRefs, |
Douglas Gregor | 18df52b | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 660 | NumProtoRefs, ProtoLocs, |
| 661 | Context); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 662 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 663 | |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 664 | CheckObjCDeclScope(CDecl); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 665 | return DeclPtrTy::make(CDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | /// ActOnStartCategoryImplementation - Perform semantic checks on the |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 669 | /// category implementation declaration and build an ObjCCategoryImplDecl |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 670 | /// object. |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 671 | Sema::DeclPtrTy Sema::ActOnStartCategoryImplementation( |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 672 | SourceLocation AtCatImplLoc, |
| 673 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
| 674 | IdentifierInfo *CatName, SourceLocation CatLoc) { |
Douglas Gregor | f06cdae | 2010-01-03 18:01:57 +0000 | [diff] [blame] | 675 | ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName, ClassLoc); |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 676 | ObjCCategoryDecl *CatIDecl = 0; |
| 677 | if (IDecl) { |
| 678 | CatIDecl = IDecl->FindCategoryDeclaration(CatName); |
| 679 | if (!CatIDecl) { |
| 680 | // Category @implementation with no corresponding @interface. |
| 681 | // Create and install one. |
| 682 | CatIDecl = ObjCCategoryDecl::Create(Context, CurContext, SourceLocation(), |
Douglas Gregor | 3db211b | 2010-01-16 16:38:58 +0000 | [diff] [blame] | 683 | SourceLocation(), SourceLocation(), |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 684 | CatName); |
| 685 | CatIDecl->setClassInterface(IDecl); |
| 686 | CatIDecl->insertNextClassCategory(); |
| 687 | } |
| 688 | } |
| 689 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 690 | ObjCCategoryImplDecl *CDecl = |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 691 | ObjCCategoryImplDecl::Create(Context, CurContext, AtCatImplLoc, CatName, |
| 692 | IDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 693 | /// Check that class of this category is already completely declared. |
| 694 | if (!IDecl || IDecl->isForwardDecl()) |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 695 | Diag(ClassLoc, diag::err_undef_interface) << ClassName; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 696 | |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 697 | // FIXME: PushOnScopeChains? |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 698 | CurContext->addDecl(CDecl); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 699 | |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 700 | /// Check that CatName, category name, is not used in another implementation. |
| 701 | if (CatIDecl) { |
| 702 | if (CatIDecl->getImplementation()) { |
| 703 | Diag(ClassLoc, diag::err_dup_implementation_category) << ClassName |
| 704 | << CatName; |
| 705 | Diag(CatIDecl->getImplementation()->getLocation(), |
| 706 | diag::note_previous_definition); |
| 707 | } else |
| 708 | CatIDecl->setImplementation(CDecl); |
| 709 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 710 | |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 711 | CheckObjCDeclScope(CDecl); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 712 | return DeclPtrTy::make(CDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 715 | Sema::DeclPtrTy Sema::ActOnStartClassImplementation( |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 716 | SourceLocation AtClassImplLoc, |
| 717 | IdentifierInfo *ClassName, SourceLocation ClassLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 718 | IdentifierInfo *SuperClassname, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 719 | SourceLocation SuperClassLoc) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 720 | ObjCInterfaceDecl* IDecl = 0; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 721 | // Check for another declaration kind with the same name. |
John McCall | f36e02d | 2009-10-09 21:13:30 +0000 | [diff] [blame] | 722 | NamedDecl *PrevDecl |
| 723 | = LookupSingleName(TUScope, ClassName, LookupOrdinaryName); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 724 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 725 | Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName; |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 726 | Diag(PrevDecl->getLocation(), diag::note_previous_definition); |
Douglas Gregor | 95ff742 | 2010-01-04 17:27:12 +0000 | [diff] [blame] | 727 | } else if ((IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl))) { |
| 728 | // If this is a forward declaration of an interface, warn. |
| 729 | if (IDecl->isForwardDecl()) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 730 | Diag(ClassLoc, diag::warn_undef_interface) << ClassName; |
Fariborz Jahanian | 77a6be4 | 2009-04-23 21:49:04 +0000 | [diff] [blame] | 731 | IDecl = 0; |
| 732 | } |
Douglas Gregor | 95ff742 | 2010-01-04 17:27:12 +0000 | [diff] [blame] | 733 | } else { |
| 734 | // We did not find anything with the name ClassName; try to correct for |
| 735 | // typos in the class name. |
| 736 | LookupResult R(*this, ClassName, ClassLoc, LookupOrdinaryName); |
| 737 | if (CorrectTypo(R, TUScope, 0) && |
| 738 | (IDecl = R.getAsSingle<ObjCInterfaceDecl>())) { |
Douglas Gregor | a6f2638 | 2010-01-06 23:44:25 +0000 | [diff] [blame] | 739 | // Suggest the (potentially) correct interface name. However, put the |
| 740 | // fix-it hint itself in a separate note, since changing the name in |
| 741 | // the warning would make the fix-it change semantics.However, don't |
Douglas Gregor | 95ff742 | 2010-01-04 17:27:12 +0000 | [diff] [blame] | 742 | // provide a code-modification hint or use the typo name for recovery, |
| 743 | // because this is just a warning. The program may actually be correct. |
| 744 | Diag(ClassLoc, diag::warn_undef_interface_suggest) |
| 745 | << ClassName << R.getLookupName(); |
Douglas Gregor | a6f2638 | 2010-01-06 23:44:25 +0000 | [diff] [blame] | 746 | Diag(IDecl->getLocation(), diag::note_previous_decl) |
| 747 | << R.getLookupName() |
| 748 | << CodeModificationHint::CreateReplacement(ClassLoc, |
| 749 | R.getLookupName().getAsString()); |
Douglas Gregor | 95ff742 | 2010-01-04 17:27:12 +0000 | [diff] [blame] | 750 | IDecl = 0; |
| 751 | } else { |
| 752 | Diag(ClassLoc, diag::warn_undef_interface) << ClassName; |
| 753 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 754 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 755 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 756 | // Check that super class name is valid class name |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 757 | ObjCInterfaceDecl* SDecl = 0; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 758 | if (SuperClassname) { |
| 759 | // Check if a different kind of symbol declared in this scope. |
John McCall | f36e02d | 2009-10-09 21:13:30 +0000 | [diff] [blame] | 760 | PrevDecl = LookupSingleName(TUScope, SuperClassname, LookupOrdinaryName); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 761 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 762 | Diag(SuperClassLoc, diag::err_redefinition_different_kind) |
| 763 | << SuperClassname; |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 764 | Diag(PrevDecl->getLocation(), diag::note_previous_definition); |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 765 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 766 | SDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 767 | if (!SDecl) |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 768 | Diag(SuperClassLoc, diag::err_undef_superclass) |
| 769 | << SuperClassname << ClassName; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 770 | else if (IDecl && IDecl->getSuperClass() != SDecl) { |
| 771 | // This implementation and its interface do not have the same |
| 772 | // super class. |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 773 | Diag(SuperClassLoc, diag::err_conflicting_super_class) |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 774 | << SDecl->getDeclName(); |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 775 | Diag(SDecl->getLocation(), diag::note_previous_definition); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 779 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 780 | if (!IDecl) { |
| 781 | // Legacy case of @implementation with no corresponding @interface. |
| 782 | // Build, chain & install the interface decl into the identifier. |
Daniel Dunbar | f641492 | 2008-08-20 18:02:42 +0000 | [diff] [blame] | 783 | |
Mike Stump | 390b4cc | 2009-05-16 07:39:55 +0000 | [diff] [blame] | 784 | // FIXME: Do we support attributes on the @implementation? If so we should |
| 785 | // copy them over. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 786 | IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassImplLoc, |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 787 | ClassName, ClassLoc, false, true); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 788 | IDecl->setSuperClass(SDecl); |
| 789 | IDecl->setLocEnd(ClassLoc); |
Douglas Gregor | 8b9fb30 | 2009-04-24 00:16:12 +0000 | [diff] [blame] | 790 | |
| 791 | PushOnScopeChains(IDecl, TUScope); |
Daniel Dunbar | 24c8991 | 2009-04-21 21:41:56 +0000 | [diff] [blame] | 792 | } else { |
| 793 | // Mark the interface as being completed, even if it was just as |
| 794 | // @class ....; |
| 795 | // declaration; the user cannot reopen it. |
| 796 | IDecl->setForwardDecl(false); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 797 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 798 | |
| 799 | ObjCImplementationDecl* IMPDecl = |
| 800 | ObjCImplementationDecl::Create(Context, CurContext, AtClassImplLoc, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 801 | IDecl, SDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 802 | |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 803 | if (CheckObjCDeclScope(IMPDecl)) |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 804 | return DeclPtrTy::make(IMPDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 805 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 806 | // Check that there is no duplicate implementation of this class. |
Argyrios Kyrtzidis | 8701877 | 2009-07-21 00:06:04 +0000 | [diff] [blame] | 807 | if (IDecl->getImplementation()) { |
Chris Lattner | 75c9cae | 2008-03-16 20:53:07 +0000 | [diff] [blame] | 808 | // FIXME: Don't leak everything! |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 809 | Diag(ClassLoc, diag::err_dup_implementation_class) << ClassName; |
Argyrios Kyrtzidis | 8701877 | 2009-07-21 00:06:04 +0000 | [diff] [blame] | 810 | Diag(IDecl->getImplementation()->getLocation(), |
| 811 | diag::note_previous_definition); |
| 812 | } else { // add it to the list. |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 813 | IDecl->setImplementation(IMPDecl); |
Douglas Gregor | 8fc463a | 2009-04-24 00:11:27 +0000 | [diff] [blame] | 814 | PushOnScopeChains(IMPDecl, TUScope); |
Argyrios Kyrtzidis | 8a1d722 | 2009-07-21 00:05:53 +0000 | [diff] [blame] | 815 | } |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 816 | return DeclPtrTy::make(IMPDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 817 | } |
| 818 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 819 | void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
| 820 | ObjCIvarDecl **ivars, unsigned numIvars, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 821 | SourceLocation RBrace) { |
| 822 | assert(ImpDecl && "missing implementation decl"); |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 823 | ObjCInterfaceDecl* IDecl = ImpDecl->getClassInterface(); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 824 | if (!IDecl) |
| 825 | return; |
| 826 | /// Check case of non-existing @interface decl. |
| 827 | /// (legacy objective-c @implementation decl without an @interface decl). |
| 828 | /// Add implementations's ivar to the synthesize class's ivar list. |
Steve Naroff | 33feeb0 | 2009-04-20 20:09:33 +0000 | [diff] [blame] | 829 | if (IDecl->isImplicitInterfaceDecl()) { |
Chris Lattner | 38af2de | 2009-02-20 21:35:13 +0000 | [diff] [blame] | 830 | IDecl->setLocEnd(RBrace); |
Fariborz Jahanian | 3a21cd9 | 2010-02-17 17:00:07 +0000 | [diff] [blame] | 831 | // Add ivar's to class's DeclContext. |
| 832 | for (unsigned i = 0, e = numIvars; i != e; ++i) { |
Fariborz Jahanian | 2f14c4d | 2010-02-17 18:10:54 +0000 | [diff] [blame] | 833 | ivars[i]->setLexicalDeclContext(ImpDecl); |
| 834 | IDecl->makeDeclVisibleInContext(ivars[i], false); |
Fariborz Jahanian | 11062e1 | 2010-02-19 00:31:17 +0000 | [diff] [blame] | 835 | ImpDecl->addDecl(ivars[i]); |
Fariborz Jahanian | 3a21cd9 | 2010-02-17 17:00:07 +0000 | [diff] [blame] | 836 | } |
| 837 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 838 | return; |
| 839 | } |
| 840 | // If implementation has empty ivar list, just return. |
| 841 | if (numIvars == 0) |
| 842 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 844 | assert(ivars && "missing @implementation ivars"); |
Fariborz Jahanian | bd94d44 | 2010-02-19 20:58:54 +0000 | [diff] [blame] | 845 | if (LangOpts.ObjCNonFragileABI2) { |
| 846 | if (ImpDecl->getSuperClass()) |
| 847 | Diag(ImpDecl->getLocation(), diag::warn_on_superclass_use); |
| 848 | for (unsigned i = 0; i < numIvars; i++) { |
| 849 | ObjCIvarDecl* ImplIvar = ivars[i]; |
| 850 | if (const ObjCIvarDecl *ClsIvar = |
| 851 | IDecl->getIvarDecl(ImplIvar->getIdentifier())) { |
| 852 | Diag(ImplIvar->getLocation(), diag::err_duplicate_ivar_declaration); |
| 853 | Diag(ClsIvar->getLocation(), diag::note_previous_definition); |
| 854 | continue; |
| 855 | } |
| 856 | if (ImplIvar->getAccessControl() != ObjCIvarDecl::Private) |
| 857 | Diag(ImplIvar->getLocation(), diag::err_non_private_ivar_declaration); |
| 858 | // Instance ivar to Implementation's DeclContext. |
| 859 | ImplIvar->setLexicalDeclContext(ImpDecl); |
| 860 | IDecl->makeDeclVisibleInContext(ImplIvar, false); |
| 861 | ImpDecl->addDecl(ImplIvar); |
| 862 | } |
| 863 | return; |
| 864 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 865 | // Check interface's Ivar list against those in the implementation. |
| 866 | // names and types must match. |
| 867 | // |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 868 | unsigned j = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 869 | ObjCInterfaceDecl::ivar_iterator |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 870 | IVI = IDecl->ivar_begin(), IVE = IDecl->ivar_end(); |
| 871 | for (; numIvars > 0 && IVI != IVE; ++IVI) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 872 | ObjCIvarDecl* ImplIvar = ivars[j++]; |
| 873 | ObjCIvarDecl* ClsIvar = *IVI; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 874 | assert (ImplIvar && "missing implementation ivar"); |
| 875 | assert (ClsIvar && "missing class ivar"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 876 | |
Steve Naroff | ca33129 | 2009-03-03 14:49:36 +0000 | [diff] [blame] | 877 | // First, make sure the types match. |
Chris Lattner | 1b63eef | 2008-07-27 00:05:05 +0000 | [diff] [blame] | 878 | if (Context.getCanonicalType(ImplIvar->getType()) != |
| 879 | Context.getCanonicalType(ClsIvar->getType())) { |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 880 | Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_type) |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 881 | << ImplIvar->getIdentifier() |
| 882 | << ImplIvar->getType() << ClsIvar->getType(); |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 883 | Diag(ClsIvar->getLocation(), diag::note_previous_definition); |
Steve Naroff | ca33129 | 2009-03-03 14:49:36 +0000 | [diff] [blame] | 884 | } else if (ImplIvar->isBitField() && ClsIvar->isBitField()) { |
| 885 | Expr *ImplBitWidth = ImplIvar->getBitWidth(); |
| 886 | Expr *ClsBitWidth = ClsIvar->getBitWidth(); |
Eli Friedman | 9a901bb | 2009-04-26 19:19:15 +0000 | [diff] [blame] | 887 | if (ImplBitWidth->EvaluateAsInt(Context).getZExtValue() != |
| 888 | ClsBitWidth->EvaluateAsInt(Context).getZExtValue()) { |
Steve Naroff | ca33129 | 2009-03-03 14:49:36 +0000 | [diff] [blame] | 889 | Diag(ImplBitWidth->getLocStart(), diag::err_conflicting_ivar_bitwidth) |
| 890 | << ImplIvar->getIdentifier(); |
| 891 | Diag(ClsBitWidth->getLocStart(), diag::note_previous_definition); |
| 892 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 893 | } |
Steve Naroff | ca33129 | 2009-03-03 14:49:36 +0000 | [diff] [blame] | 894 | // Make sure the names are identical. |
| 895 | if (ImplIvar->getIdentifier() != ClsIvar->getIdentifier()) { |
Chris Lattner | fa25bbb | 2008-11-19 05:08:23 +0000 | [diff] [blame] | 896 | Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_name) |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 897 | << ImplIvar->getIdentifier() << ClsIvar->getIdentifier(); |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 898 | Diag(ClsIvar->getLocation(), diag::note_previous_definition); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 899 | } |
| 900 | --numIvars; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 901 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 902 | |
Chris Lattner | 609e4c7 | 2007-12-12 18:11:49 +0000 | [diff] [blame] | 903 | if (numIvars > 0) |
Chris Lattner | 0e39105 | 2007-12-12 18:19:52 +0000 | [diff] [blame] | 904 | Diag(ivars[j]->getLocation(), diag::err_inconsistant_ivar_count); |
Chris Lattner | 609e4c7 | 2007-12-12 18:11:49 +0000 | [diff] [blame] | 905 | else if (IVI != IVE) |
Chris Lattner | 0e39105 | 2007-12-12 18:19:52 +0000 | [diff] [blame] | 906 | Diag((*IVI)->getLocation(), diag::err_inconsistant_ivar_count); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 909 | void Sema::WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method, |
| 910 | bool &IncompleteImpl) { |
| 911 | if (!IncompleteImpl) { |
| 912 | Diag(ImpLoc, diag::warn_incomplete_impl); |
| 913 | IncompleteImpl = true; |
| 914 | } |
Chris Lattner | 08631c5 | 2008-11-23 21:45:46 +0000 | [diff] [blame] | 915 | Diag(ImpLoc, diag::warn_undef_method_impl) << method->getDeclName(); |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Fariborz Jahanian | 8daab97 | 2008-12-05 18:18:52 +0000 | [diff] [blame] | 918 | void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl, |
| 919 | ObjCMethodDecl *IntfMethodDecl) { |
Chris Lattner | 5272b7f | 2009-04-11 18:01:59 +0000 | [diff] [blame] | 920 | if (!Context.typesAreCompatible(IntfMethodDecl->getResultType(), |
Fariborz Jahanian | 2574a68 | 2009-05-14 23:52:54 +0000 | [diff] [blame] | 921 | ImpMethodDecl->getResultType()) && |
Steve Naroff | 4084c30 | 2009-07-23 01:01:38 +0000 | [diff] [blame] | 922 | !Context.QualifiedIdConformsQualifiedId(IntfMethodDecl->getResultType(), |
| 923 | ImpMethodDecl->getResultType())) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 924 | Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_ret_types) |
Chris Lattner | 3aff919 | 2009-04-11 19:58:42 +0000 | [diff] [blame] | 925 | << ImpMethodDecl->getDeclName() << IntfMethodDecl->getResultType() |
| 926 | << ImpMethodDecl->getResultType(); |
Fariborz Jahanian | 8daab97 | 2008-12-05 18:18:52 +0000 | [diff] [blame] | 927 | Diag(IntfMethodDecl->getLocation(), diag::note_previous_definition); |
| 928 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 929 | |
Chris Lattner | 3aff919 | 2009-04-11 19:58:42 +0000 | [diff] [blame] | 930 | for (ObjCMethodDecl::param_iterator IM = ImpMethodDecl->param_begin(), |
| 931 | IF = IntfMethodDecl->param_begin(), EM = ImpMethodDecl->param_end(); |
| 932 | IM != EM; ++IM, ++IF) { |
Fariborz Jahanian | 3393f81 | 2009-11-18 18:56:09 +0000 | [diff] [blame] | 933 | QualType ParmDeclTy = (*IF)->getType().getUnqualifiedType(); |
| 934 | QualType ParmImpTy = (*IM)->getType().getUnqualifiedType(); |
| 935 | if (Context.typesAreCompatible(ParmDeclTy, ParmImpTy) || |
| 936 | Context.QualifiedIdConformsQualifiedId(ParmDeclTy, ParmImpTy)) |
Chris Lattner | 3aff919 | 2009-04-11 19:58:42 +0000 | [diff] [blame] | 937 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 938 | |
| 939 | Diag((*IM)->getLocation(), diag::warn_conflicting_param_types) |
Chris Lattner | 3aff919 | 2009-04-11 19:58:42 +0000 | [diff] [blame] | 940 | << ImpMethodDecl->getDeclName() << (*IF)->getType() |
| 941 | << (*IM)->getType(); |
Chris Lattner | d1e0f5a | 2009-04-11 20:14:49 +0000 | [diff] [blame] | 942 | Diag((*IF)->getLocation(), diag::note_previous_definition); |
Chris Lattner | 3aff919 | 2009-04-11 19:58:42 +0000 | [diff] [blame] | 943 | } |
Fariborz Jahanian | 8daab97 | 2008-12-05 18:18:52 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 946 | /// isPropertyReadonly - Return true if property is readonly, by searching |
| 947 | /// for the property in the class and in its categories and implementations |
| 948 | /// |
| 949 | bool Sema::isPropertyReadonly(ObjCPropertyDecl *PDecl, |
Steve Naroff | 22dc0b0 | 2009-02-26 19:11:32 +0000 | [diff] [blame] | 950 | ObjCInterfaceDecl *IDecl) { |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 951 | // by far the most common case. |
| 952 | if (!PDecl->isReadOnly()) |
| 953 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 954 | // Even if property is ready only, if interface has a user defined setter, |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 955 | // it is not considered read only. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 956 | if (IDecl->getInstanceMethod(PDecl->getSetterName())) |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 957 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 958 | |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 959 | // Main class has the property as 'readonly'. Must search |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 960 | // through the category list to see if the property's |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 961 | // attribute has been over-ridden to 'readwrite'. |
| 962 | for (ObjCCategoryDecl *Category = IDecl->getCategoryList(); |
| 963 | Category; Category = Category->getNextClassCategory()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 964 | // Even if property is ready only, if a category has a user defined setter, |
| 965 | // it is not considered read only. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 966 | if (Category->getInstanceMethod(PDecl->getSetterName())) |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 967 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 968 | ObjCPropertyDecl *P = |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 969 | Category->FindPropertyDeclaration(PDecl->getIdentifier()); |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 970 | if (P && !P->isReadOnly()) |
| 971 | return false; |
| 972 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 973 | |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 974 | // Also, check for definition of a setter method in the implementation if |
| 975 | // all else failed. |
| 976 | if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(CurContext)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 977 | if (ObjCImplementationDecl *IMD = |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 978 | dyn_cast<ObjCImplementationDecl>(OMD->getDeclContext())) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 979 | if (IMD->getInstanceMethod(PDecl->getSetterName())) |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 980 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 981 | } else if (ObjCCategoryImplDecl *CIMD = |
Mike Stump | ac5fc7c | 2009-08-04 21:02:39 +0000 | [diff] [blame] | 982 | dyn_cast<ObjCCategoryImplDecl>(OMD->getDeclContext())) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 983 | if (CIMD->getInstanceMethod(PDecl->getSetterName())) |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 984 | return false; |
| 985 | } |
| 986 | } |
Steve Naroff | 22dc0b0 | 2009-02-26 19:11:32 +0000 | [diff] [blame] | 987 | // Lastly, look through the implementation (if one is in scope). |
Argyrios Kyrtzidis | 8701877 | 2009-07-21 00:06:04 +0000 | [diff] [blame] | 988 | if (ObjCImplementationDecl *ImpDecl = IDecl->getImplementation()) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 989 | if (ImpDecl->getInstanceMethod(PDecl->getSetterName())) |
Steve Naroff | 22dc0b0 | 2009-02-26 19:11:32 +0000 | [diff] [blame] | 990 | return false; |
Fariborz Jahanian | 50efe04 | 2009-04-06 16:59:10 +0000 | [diff] [blame] | 991 | // If all fails, look at the super class. |
| 992 | if (ObjCInterfaceDecl *SIDecl = IDecl->getSuperClass()) |
| 993 | return isPropertyReadonly(PDecl, SIDecl); |
Fariborz Jahanian | d1fa644 | 2009-01-12 19:55:42 +0000 | [diff] [blame] | 994 | return true; |
| 995 | } |
| 996 | |
Mike Stump | 390b4cc | 2009-05-16 07:39:55 +0000 | [diff] [blame] | 997 | /// FIXME: Type hierarchies in Objective-C can be deep. We could most likely |
| 998 | /// improve the efficiency of selector lookups and type checking by associating |
| 999 | /// with each protocol / interface / category the flattened instance tables. If |
| 1000 | /// we used an immutable set to keep the table then it wouldn't add significant |
| 1001 | /// memory cost and it would be handy for lookups. |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 1002 | |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 1003 | /// CheckProtocolMethodDefs - This routine checks unimplemented methods |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1004 | /// Declared in protocol, and those referenced by it. |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 1005 | void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc, |
| 1006 | ObjCProtocolDecl *PDecl, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1007 | bool& IncompleteImpl, |
Steve Naroff | efe7f36 | 2008-02-08 22:06:17 +0000 | [diff] [blame] | 1008 | const llvm::DenseSet<Selector> &InsMap, |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 1009 | const llvm::DenseSet<Selector> &ClsMap, |
| 1010 | ObjCInterfaceDecl *IDecl) { |
| 1011 | ObjCInterfaceDecl *Super = IDecl->getSuperClass(); |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 1012 | ObjCInterfaceDecl *NSIDecl = 0; |
| 1013 | if (getLangOptions().NeXTRuntime) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1014 | // check to see if class implements forwardInvocation method and objects |
| 1015 | // of this class are derived from 'NSProxy' so that to forward requests |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 1016 | // from one object to another. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1017 | // Under such conditions, which means that every method possible is |
| 1018 | // implemented in the class, we should not issue "Method definition not |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 1019 | // found" warnings. |
| 1020 | // FIXME: Use a general GetUnarySelector method for this. |
| 1021 | IdentifierInfo* II = &Context.Idents.get("forwardInvocation"); |
| 1022 | Selector fISelector = Context.Selectors.getSelector(1, &II); |
| 1023 | if (InsMap.count(fISelector)) |
| 1024 | // Is IDecl derived from 'NSProxy'? If so, no instance methods |
| 1025 | // need be implemented in the implementation. |
| 1026 | NSIDecl = IDecl->lookupInheritedClass(&Context.Idents.get("NSProxy")); |
| 1027 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1028 | |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 1029 | // If a method lookup fails locally we still need to look and see if |
| 1030 | // the method was implemented by a base class or an inherited |
| 1031 | // protocol. This lookup is slow, but occurs rarely in correct code |
| 1032 | // and otherwise would terminate in a warning. |
| 1033 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1034 | // check unimplemented instance methods. |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 1035 | if (!NSIDecl) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1036 | for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(), |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1037 | E = PDecl->instmeth_end(); I != E; ++I) { |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 1038 | ObjCMethodDecl *method = *I; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1039 | if (method->getImplementationControl() != ObjCMethodDecl::Optional && |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 1040 | !method->isSynthesized() && !InsMap.count(method->getSelector()) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1041 | (!Super || |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1042 | !Super->lookupInstanceMethod(method->getSelector()))) { |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 1043 | // Ugly, but necessary. Method declared in protcol might have |
| 1044 | // have been synthesized due to a property declared in the class which |
| 1045 | // uses the protocol. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1046 | ObjCMethodDecl *MethodInClass = |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1047 | IDecl->lookupInstanceMethod(method->getSelector()); |
Fariborz Jahanian | cd18762 | 2009-05-22 17:12:32 +0000 | [diff] [blame] | 1048 | if (!MethodInClass || !MethodInClass->isSynthesized()) |
| 1049 | WarnUndefinedMethod(ImpLoc, method, IncompleteImpl); |
| 1050 | } |
| 1051 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1052 | // check unimplemented class methods |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1053 | for (ObjCProtocolDecl::classmeth_iterator |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1054 | I = PDecl->classmeth_begin(), E = PDecl->classmeth_end(); |
Douglas Gregor | 6ab3524 | 2009-04-09 21:40:53 +0000 | [diff] [blame] | 1055 | I != E; ++I) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1056 | ObjCMethodDecl *method = *I; |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 1057 | if (method->getImplementationControl() != ObjCMethodDecl::Optional && |
| 1058 | !ClsMap.count(method->getSelector()) && |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1059 | (!Super || !Super->lookupClassMethod(method->getSelector()))) |
Steve Naroff | 3c2eb66 | 2008-02-10 21:38:56 +0000 | [diff] [blame] | 1060 | WarnUndefinedMethod(ImpLoc, method, IncompleteImpl); |
Steve Naroff | 58dbdeb | 2007-12-14 23:37:57 +0000 | [diff] [blame] | 1061 | } |
Chris Lattner | 780f329 | 2008-07-21 21:32:27 +0000 | [diff] [blame] | 1062 | // Check on this protocols's referenced protocols, recursively. |
| 1063 | for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(), |
| 1064 | E = PDecl->protocol_end(); PI != E; ++PI) |
Daniel Dunbar | 7ad1b1f | 2008-09-04 20:01:15 +0000 | [diff] [blame] | 1065 | CheckProtocolMethodDefs(ImpLoc, *PI, IncompleteImpl, InsMap, ClsMap, IDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1068 | /// MatchAllMethodDeclarations - Check methods declaraed in interface or |
| 1069 | /// or protocol against those declared in their implementations. |
| 1070 | /// |
| 1071 | void Sema::MatchAllMethodDeclarations(const llvm::DenseSet<Selector> &InsMap, |
| 1072 | const llvm::DenseSet<Selector> &ClsMap, |
| 1073 | llvm::DenseSet<Selector> &InsMapSeen, |
| 1074 | llvm::DenseSet<Selector> &ClsMapSeen, |
| 1075 | ObjCImplDecl* IMPDecl, |
| 1076 | ObjCContainerDecl* CDecl, |
| 1077 | bool &IncompleteImpl, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1078 | bool ImmediateClass) { |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1079 | // Check and see if instance methods in class interface have been |
| 1080 | // implemented in the implementation class. If so, their types match. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1081 | for (ObjCInterfaceDecl::instmeth_iterator I = CDecl->instmeth_begin(), |
| 1082 | E = CDecl->instmeth_end(); I != E; ++I) { |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1083 | if (InsMapSeen.count((*I)->getSelector())) |
| 1084 | continue; |
| 1085 | InsMapSeen.insert((*I)->getSelector()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1086 | if (!(*I)->isSynthesized() && |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1087 | !InsMap.count((*I)->getSelector())) { |
| 1088 | if (ImmediateClass) |
| 1089 | WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl); |
| 1090 | continue; |
Mike Stump | ac5fc7c | 2009-08-04 21:02:39 +0000 | [diff] [blame] | 1091 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1092 | ObjCMethodDecl *ImpMethodDecl = |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1093 | IMPDecl->getInstanceMethod((*I)->getSelector()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | ObjCMethodDecl *IntfMethodDecl = |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1095 | CDecl->getInstanceMethod((*I)->getSelector()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1096 | assert(IntfMethodDecl && |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1097 | "IntfMethodDecl is null in ImplMethodsVsClassMethods"); |
| 1098 | // ImpMethodDecl may be null as in a @dynamic property. |
| 1099 | if (ImpMethodDecl) |
| 1100 | WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl); |
| 1101 | } |
| 1102 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1103 | |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1104 | // Check and see if class methods in class interface have been |
| 1105 | // implemented in the implementation class. If so, their types match. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | for (ObjCInterfaceDecl::classmeth_iterator |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1107 | I = CDecl->classmeth_begin(), E = CDecl->classmeth_end(); I != E; ++I) { |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1108 | if (ClsMapSeen.count((*I)->getSelector())) |
| 1109 | continue; |
| 1110 | ClsMapSeen.insert((*I)->getSelector()); |
| 1111 | if (!ClsMap.count((*I)->getSelector())) { |
| 1112 | if (ImmediateClass) |
| 1113 | WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl); |
Mike Stump | ac5fc7c | 2009-08-04 21:02:39 +0000 | [diff] [blame] | 1114 | } else { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1115 | ObjCMethodDecl *ImpMethodDecl = |
| 1116 | IMPDecl->getClassMethod((*I)->getSelector()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1117 | ObjCMethodDecl *IntfMethodDecl = |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1118 | CDecl->getClassMethod((*I)->getSelector()); |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1119 | WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl); |
| 1120 | } |
| 1121 | } |
| 1122 | if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl> (CDecl)) { |
| 1123 | // Check for any implementation of a methods declared in protocol. |
| 1124 | for (ObjCInterfaceDecl::protocol_iterator PI = I->protocol_begin(), |
| 1125 | E = I->protocol_end(); PI != E; ++PI) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1126 | MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen, |
| 1127 | IMPDecl, |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1128 | (*PI), IncompleteImpl, false); |
| 1129 | if (I->getSuperClass()) |
| 1130 | MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1131 | IMPDecl, |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1132 | I->getSuperClass(), IncompleteImpl, false); |
| 1133 | } |
| 1134 | } |
| 1135 | |
Fariborz Jahanian | 3ac1eda | 2010-01-20 01:51:55 +0000 | [diff] [blame] | 1136 | /// CollectImmediateProperties - This routine collects all properties in |
| 1137 | /// the class and its conforming protocols; but not those it its super class. |
| 1138 | void Sema::CollectImmediateProperties(ObjCContainerDecl *CDecl, |
| 1139 | llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>& PropMap) { |
| 1140 | if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl)) { |
| 1141 | for (ObjCContainerDecl::prop_iterator P = IDecl->prop_begin(), |
| 1142 | E = IDecl->prop_end(); P != E; ++P) { |
| 1143 | ObjCPropertyDecl *Prop = (*P); |
| 1144 | PropMap[Prop->getIdentifier()] = Prop; |
| 1145 | } |
| 1146 | // scan through class's protocols. |
| 1147 | for (ObjCInterfaceDecl::protocol_iterator PI = IDecl->protocol_begin(), |
| 1148 | E = IDecl->protocol_end(); PI != E; ++PI) |
| 1149 | CollectImmediateProperties((*PI), PropMap); |
| 1150 | } |
Fariborz Jahanian | 3ad230e | 2010-01-20 19:36:21 +0000 | [diff] [blame] | 1151 | if (ObjCCategoryDecl *CATDecl = dyn_cast<ObjCCategoryDecl>(CDecl)) { |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 1152 | if (!CATDecl->IsClassExtension()) |
| 1153 | for (ObjCContainerDecl::prop_iterator P = CATDecl->prop_begin(), |
| 1154 | E = CATDecl->prop_end(); P != E; ++P) { |
| 1155 | ObjCPropertyDecl *Prop = (*P); |
| 1156 | PropMap[Prop->getIdentifier()] = Prop; |
| 1157 | } |
Fariborz Jahanian | 3ad230e | 2010-01-20 19:36:21 +0000 | [diff] [blame] | 1158 | // scan through class's protocols. |
| 1159 | for (ObjCInterfaceDecl::protocol_iterator PI = CATDecl->protocol_begin(), |
| 1160 | E = CATDecl->protocol_end(); PI != E; ++PI) |
| 1161 | CollectImmediateProperties((*PI), PropMap); |
| 1162 | } |
Fariborz Jahanian | 3ac1eda | 2010-01-20 01:51:55 +0000 | [diff] [blame] | 1163 | else if (ObjCProtocolDecl *PDecl = dyn_cast<ObjCProtocolDecl>(CDecl)) { |
| 1164 | for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(), |
| 1165 | E = PDecl->prop_end(); P != E; ++P) { |
| 1166 | ObjCPropertyDecl *Prop = (*P); |
| 1167 | ObjCPropertyDecl *&PropEntry = PropMap[Prop->getIdentifier()]; |
| 1168 | if (!PropEntry) |
| 1169 | PropEntry = Prop; |
| 1170 | } |
| 1171 | // scan through protocol's protocols. |
| 1172 | for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(), |
| 1173 | E = PDecl->protocol_end(); PI != E; ++PI) |
| 1174 | CollectImmediateProperties((*PI), PropMap); |
| 1175 | } |
| 1176 | } |
| 1177 | |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 1178 | /// LookupPropertyDecl - Looks up a property in the current class and all |
| 1179 | /// its protocols. |
| 1180 | ObjCPropertyDecl *Sema::LookupPropertyDecl(const ObjCContainerDecl *CDecl, |
| 1181 | IdentifierInfo *II) { |
| 1182 | if (const ObjCInterfaceDecl *IDecl = |
| 1183 | dyn_cast<ObjCInterfaceDecl>(CDecl)) { |
| 1184 | for (ObjCContainerDecl::prop_iterator P = IDecl->prop_begin(), |
| 1185 | E = IDecl->prop_end(); P != E; ++P) { |
| 1186 | ObjCPropertyDecl *Prop = (*P); |
| 1187 | if (Prop->getIdentifier() == II) |
| 1188 | return Prop; |
| 1189 | } |
| 1190 | // scan through class's protocols. |
| 1191 | for (ObjCInterfaceDecl::protocol_iterator PI = IDecl->protocol_begin(), |
| 1192 | E = IDecl->protocol_end(); PI != E; ++PI) { |
| 1193 | ObjCPropertyDecl *Prop = LookupPropertyDecl((*PI), II); |
| 1194 | if (Prop) |
| 1195 | return Prop; |
| 1196 | } |
| 1197 | } |
| 1198 | else if (const ObjCProtocolDecl *PDecl = |
| 1199 | dyn_cast<ObjCProtocolDecl>(CDecl)) { |
| 1200 | for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(), |
| 1201 | E = PDecl->prop_end(); P != E; ++P) { |
| 1202 | ObjCPropertyDecl *Prop = (*P); |
| 1203 | if (Prop->getIdentifier() == II) |
| 1204 | return Prop; |
| 1205 | } |
| 1206 | // scan through protocol's protocols. |
| 1207 | for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(), |
| 1208 | E = PDecl->protocol_end(); PI != E; ++PI) { |
| 1209 | ObjCPropertyDecl *Prop = LookupPropertyDecl((*PI), II); |
| 1210 | if (Prop) |
| 1211 | return Prop; |
| 1212 | } |
| 1213 | } |
| 1214 | return 0; |
| 1215 | } |
| 1216 | |
| 1217 | |
Fariborz Jahanian | 3ac1eda | 2010-01-20 01:51:55 +0000 | [diff] [blame] | 1218 | void Sema::DiagnoseUnimplementedProperties(ObjCImplDecl* IMPDecl, |
| 1219 | ObjCContainerDecl *CDecl, |
| 1220 | const llvm::DenseSet<Selector>& InsMap) { |
| 1221 | llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*> PropMap; |
| 1222 | CollectImmediateProperties(CDecl, PropMap); |
Fariborz Jahanian | a84f2e4 | 2010-01-20 17:27:59 +0000 | [diff] [blame] | 1223 | if (PropMap.empty()) |
| 1224 | return; |
| 1225 | |
| 1226 | llvm::DenseSet<ObjCPropertyDecl *> PropImplMap; |
| 1227 | for (ObjCImplDecl::propimpl_iterator |
| 1228 | I = IMPDecl->propimpl_begin(), |
| 1229 | EI = IMPDecl->propimpl_end(); I != EI; ++I) |
| 1230 | PropImplMap.insert((*I)->getPropertyDecl()); |
| 1231 | |
Fariborz Jahanian | 3ac1eda | 2010-01-20 01:51:55 +0000 | [diff] [blame] | 1232 | for (llvm::DenseMap<IdentifierInfo *, ObjCPropertyDecl*>::iterator |
| 1233 | P = PropMap.begin(), E = PropMap.end(); P != E; ++P) { |
| 1234 | ObjCPropertyDecl *Prop = P->second; |
Fariborz Jahanian | 3ac1eda | 2010-01-20 01:51:55 +0000 | [diff] [blame] | 1235 | // Is there a matching propery synthesize/dynamic? |
Fariborz Jahanian | a84f2e4 | 2010-01-20 17:27:59 +0000 | [diff] [blame] | 1236 | if (Prop->isInvalidDecl() || |
| 1237 | Prop->getPropertyImplementation() == ObjCPropertyDecl::Optional || |
| 1238 | PropImplMap.count(Prop)) |
Fariborz Jahanian | 3ac1eda | 2010-01-20 01:51:55 +0000 | [diff] [blame] | 1239 | continue; |
Fariborz Jahanian | 412e798 | 2010-02-09 19:31:38 +0000 | [diff] [blame] | 1240 | if (LangOpts.ObjCNonFragileABI2) { |
| 1241 | ActOnPropertyImplDecl(IMPDecl->getLocation(), |
| 1242 | SourceLocation(), |
| 1243 | true, DeclPtrTy::make(IMPDecl), |
| 1244 | Prop->getIdentifier(), |
| 1245 | Prop->getIdentifier()); |
| 1246 | continue; |
| 1247 | } |
Fariborz Jahanian | 3ac1eda | 2010-01-20 01:51:55 +0000 | [diff] [blame] | 1248 | if (!InsMap.count(Prop->getGetterName())) { |
| 1249 | Diag(Prop->getLocation(), |
Fariborz Jahanian | 3ad230e | 2010-01-20 19:36:21 +0000 | [diff] [blame] | 1250 | isa<ObjCCategoryDecl>(CDecl) ? |
| 1251 | diag::warn_setter_getter_impl_required_in_category : |
| 1252 | diag::warn_setter_getter_impl_required) |
Fariborz Jahanian | 3ac1eda | 2010-01-20 01:51:55 +0000 | [diff] [blame] | 1253 | << Prop->getDeclName() << Prop->getGetterName(); |
| 1254 | Diag(IMPDecl->getLocation(), |
| 1255 | diag::note_property_impl_required); |
| 1256 | } |
| 1257 | |
| 1258 | if (!Prop->isReadOnly() && !InsMap.count(Prop->getSetterName())) { |
| 1259 | Diag(Prop->getLocation(), |
Fariborz Jahanian | 3ad230e | 2010-01-20 19:36:21 +0000 | [diff] [blame] | 1260 | isa<ObjCCategoryDecl>(CDecl) ? |
| 1261 | diag::warn_setter_getter_impl_required_in_category : |
Fariborz Jahanian | 3ac1eda | 2010-01-20 01:51:55 +0000 | [diff] [blame] | 1262 | diag::warn_setter_getter_impl_required) |
| 1263 | << Prop->getDeclName() << Prop->getSetterName(); |
| 1264 | Diag(IMPDecl->getLocation(), |
| 1265 | diag::note_property_impl_required); |
| 1266 | } |
| 1267 | } |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1270 | void Sema::ImplMethodsVsClassMethods(ObjCImplDecl* IMPDecl, |
| 1271 | ObjCContainerDecl* CDecl, |
Chris Lattner | cddc888 | 2009-03-01 00:56:52 +0000 | [diff] [blame] | 1272 | bool IncompleteImpl) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1273 | llvm::DenseSet<Selector> InsMap; |
| 1274 | // Check and see if instance methods in class interface have been |
| 1275 | // implemented in the implementation class. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1276 | for (ObjCImplementationDecl::instmeth_iterator |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1277 | I = IMPDecl->instmeth_begin(), E = IMPDecl->instmeth_end(); I!=E; ++I) |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 1278 | InsMap.insert((*I)->getSelector()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1279 | |
Fariborz Jahanian | 12bac25 | 2009-04-14 23:15:21 +0000 | [diff] [blame] | 1280 | // Check and see if properties declared in the interface have either 1) |
| 1281 | // an implementation or 2) there is a @synthesize/@dynamic implementation |
| 1282 | // of the property in the @implementation. |
| 1283 | if (isa<ObjCInterfaceDecl>(CDecl)) |
Fariborz Jahanian | 3ac1eda | 2010-01-20 01:51:55 +0000 | [diff] [blame] | 1284 | DiagnoseUnimplementedProperties(IMPDecl, CDecl, InsMap); |
| 1285 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1286 | llvm::DenseSet<Selector> ClsMap; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1287 | for (ObjCImplementationDecl::classmeth_iterator |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1288 | I = IMPDecl->classmeth_begin(), |
| 1289 | E = IMPDecl->classmeth_end(); I != E; ++I) |
Chris Lattner | 4c52509 | 2007-12-12 17:58:05 +0000 | [diff] [blame] | 1290 | ClsMap.insert((*I)->getSelector()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1291 | |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1292 | // Check for type conflict of methods declared in a class/protocol and |
| 1293 | // its implementation; if any. |
| 1294 | llvm::DenseSet<Selector> InsMapSeen, ClsMapSeen; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1295 | MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen, |
| 1296 | IMPDecl, CDecl, |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1297 | IncompleteImpl, true); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1298 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1299 | // Check the protocol list for unimplemented methods in the @implementation |
| 1300 | // class. |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1301 | // Check and see if class methods in class interface have been |
| 1302 | // implemented in the implementation class. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1303 | |
Chris Lattner | cddc888 | 2009-03-01 00:56:52 +0000 | [diff] [blame] | 1304 | if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl> (CDecl)) { |
Fariborz Jahanian | b33f3ad | 2009-05-01 20:07:12 +0000 | [diff] [blame] | 1305 | for (ObjCInterfaceDecl::protocol_iterator PI = I->protocol_begin(), |
Chris Lattner | cddc888 | 2009-03-01 00:56:52 +0000 | [diff] [blame] | 1306 | E = I->protocol_end(); PI != E; ++PI) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1307 | CheckProtocolMethodDefs(IMPDecl->getLocation(), *PI, IncompleteImpl, |
Chris Lattner | cddc888 | 2009-03-01 00:56:52 +0000 | [diff] [blame] | 1308 | InsMap, ClsMap, I); |
| 1309 | // Check class extensions (unnamed categories) |
| 1310 | for (ObjCCategoryDecl *Categories = I->getCategoryList(); |
| 1311 | Categories; Categories = Categories->getNextClassCategory()) { |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 1312 | if (Categories->IsClassExtension()) { |
Chris Lattner | cddc888 | 2009-03-01 00:56:52 +0000 | [diff] [blame] | 1313 | ImplMethodsVsClassMethods(IMPDecl, Categories, IncompleteImpl); |
| 1314 | break; |
| 1315 | } |
Fariborz Jahanian | 8daab97 | 2008-12-05 18:18:52 +0000 | [diff] [blame] | 1316 | } |
Chris Lattner | cddc888 | 2009-03-01 00:56:52 +0000 | [diff] [blame] | 1317 | } else if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl)) { |
Fariborz Jahanian | b106fc6 | 2009-10-05 21:32:49 +0000 | [diff] [blame] | 1318 | // For extended class, unimplemented methods in its protocols will |
| 1319 | // be reported in the primary class. |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 1320 | if (!C->IsClassExtension()) { |
Fariborz Jahanian | b106fc6 | 2009-10-05 21:32:49 +0000 | [diff] [blame] | 1321 | for (ObjCCategoryDecl::protocol_iterator PI = C->protocol_begin(), |
| 1322 | E = C->protocol_end(); PI != E; ++PI) |
| 1323 | CheckProtocolMethodDefs(IMPDecl->getLocation(), *PI, IncompleteImpl, |
| 1324 | InsMap, ClsMap, C->getClassInterface()); |
Fariborz Jahanian | 3ad230e | 2010-01-20 19:36:21 +0000 | [diff] [blame] | 1325 | // Report unimplemented properties in the category as well. |
| 1326 | // When reporting on missing setter/getters, do not report when |
| 1327 | // setter/getter is implemented in category's primary class |
| 1328 | // implementation. |
| 1329 | if (ObjCInterfaceDecl *ID = C->getClassInterface()) |
| 1330 | if (ObjCImplDecl *IMP = ID->getImplementation()) { |
| 1331 | for (ObjCImplementationDecl::instmeth_iterator |
| 1332 | I = IMP->instmeth_begin(), E = IMP->instmeth_end(); I!=E; ++I) |
| 1333 | InsMap.insert((*I)->getSelector()); |
| 1334 | } |
| 1335 | DiagnoseUnimplementedProperties(IMPDecl, CDecl, InsMap); |
| 1336 | } |
Chris Lattner | cddc888 | 2009-03-01 00:56:52 +0000 | [diff] [blame] | 1337 | } else |
| 1338 | assert(false && "invalid ObjCContainerDecl type."); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Fariborz Jahanian | 7ca8b06 | 2009-11-11 22:40:11 +0000 | [diff] [blame] | 1341 | void |
| 1342 | Sema::AtomicPropertySetterGetterRules (ObjCImplDecl* IMPDecl, |
| 1343 | ObjCContainerDecl* IDecl) { |
| 1344 | // Rules apply in non-GC mode only |
| 1345 | if (getLangOptions().getGCMode() != LangOptions::NonGC) |
| 1346 | return; |
| 1347 | for (ObjCContainerDecl::prop_iterator I = IDecl->prop_begin(), |
| 1348 | E = IDecl->prop_end(); |
| 1349 | I != E; ++I) { |
| 1350 | ObjCPropertyDecl *Property = (*I); |
| 1351 | unsigned Attributes = Property->getPropertyAttributes(); |
| 1352 | // We only care about readwrite atomic property. |
| 1353 | if ((Attributes & ObjCPropertyDecl::OBJC_PR_nonatomic) || |
| 1354 | !(Attributes & ObjCPropertyDecl::OBJC_PR_readwrite)) |
| 1355 | continue; |
| 1356 | if (const ObjCPropertyImplDecl *PIDecl |
| 1357 | = IMPDecl->FindPropertyImplDecl(Property->getIdentifier())) { |
| 1358 | if (PIDecl->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic) |
| 1359 | continue; |
| 1360 | ObjCMethodDecl *GetterMethod = |
| 1361 | IMPDecl->getInstanceMethod(Property->getGetterName()); |
| 1362 | ObjCMethodDecl *SetterMethod = |
| 1363 | IMPDecl->getInstanceMethod(Property->getSetterName()); |
| 1364 | if ((GetterMethod && !SetterMethod) || (!GetterMethod && SetterMethod)) { |
| 1365 | SourceLocation MethodLoc = |
| 1366 | (GetterMethod ? GetterMethod->getLocation() |
| 1367 | : SetterMethod->getLocation()); |
| 1368 | Diag(MethodLoc, diag::warn_atomic_property_rule) |
| 1369 | << Property->getIdentifier(); |
| 1370 | Diag(Property->getLocation(), diag::note_property_declare); |
| 1371 | } |
| 1372 | } |
| 1373 | } |
| 1374 | } |
| 1375 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1376 | /// ActOnForwardClassDeclaration - |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1377 | Action::DeclPtrTy |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1378 | Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc, |
Chris Lattner | bdbde4d | 2009-02-16 19:25:52 +0000 | [diff] [blame] | 1379 | IdentifierInfo **IdentList, |
Ted Kremenek | c09cba6 | 2009-11-17 23:12:20 +0000 | [diff] [blame] | 1380 | SourceLocation *IdentLocs, |
Chris Lattner | bdbde4d | 2009-02-16 19:25:52 +0000 | [diff] [blame] | 1381 | unsigned NumElts) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1382 | llvm::SmallVector<ObjCInterfaceDecl*, 32> Interfaces; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1383 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1384 | for (unsigned i = 0; i != NumElts; ++i) { |
| 1385 | // Check for another declaration kind with the same name. |
John McCall | f36e02d | 2009-10-09 21:13:30 +0000 | [diff] [blame] | 1386 | NamedDecl *PrevDecl |
| 1387 | = LookupSingleName(TUScope, IdentList[i], LookupOrdinaryName); |
Douglas Gregor | f57172b | 2008-12-08 18:40:42 +0000 | [diff] [blame] | 1388 | if (PrevDecl && PrevDecl->isTemplateParameter()) { |
Douglas Gregor | 72c3f31 | 2008-12-05 18:15:24 +0000 | [diff] [blame] | 1389 | // Maybe we will complain about the shadowed template parameter. |
| 1390 | DiagnoseTemplateParameterShadow(AtClassLoc, PrevDecl); |
| 1391 | // Just pretend that we didn't see the previous declaration. |
| 1392 | PrevDecl = 0; |
| 1393 | } |
| 1394 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1395 | if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { |
Steve Naroff | c733388 | 2008-06-05 22:57:10 +0000 | [diff] [blame] | 1396 | // GCC apparently allows the following idiom: |
| 1397 | // |
| 1398 | // typedef NSObject < XCElementTogglerP > XCElementToggler; |
| 1399 | // @class XCElementToggler; |
| 1400 | // |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1401 | // FIXME: Make an extension? |
Steve Naroff | c733388 | 2008-06-05 22:57:10 +0000 | [diff] [blame] | 1402 | TypedefDecl *TDD = dyn_cast<TypedefDecl>(PrevDecl); |
| 1403 | if (!TDD || !isa<ObjCInterfaceType>(TDD->getUnderlyingType())) { |
Chris Lattner | 3c73c41 | 2008-11-19 08:23:25 +0000 | [diff] [blame] | 1404 | Diag(AtClassLoc, diag::err_redefinition_different_kind) << IdentList[i]; |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 1405 | Diag(PrevDecl->getLocation(), diag::note_previous_definition); |
Mike Stump | ac5fc7c | 2009-08-04 21:02:39 +0000 | [diff] [blame] | 1406 | } else if (TDD) { |
| 1407 | // a forward class declaration matching a typedef name of a class refers |
| 1408 | // to the underlying class. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1409 | if (ObjCInterfaceType * OI = |
Fariborz Jahanian | cae27c5 | 2009-05-07 21:49:26 +0000 | [diff] [blame] | 1410 | dyn_cast<ObjCInterfaceType>(TDD->getUnderlyingType())) |
| 1411 | PrevDecl = OI->getDecl(); |
| 1412 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1413 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1414 | ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1415 | if (!IDecl) { // Not already seen? Make a forward decl. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1416 | IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassLoc, |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 1417 | IdentList[i], IdentLocs[i], true); |
Ted Kremenek | c32b1d8 | 2009-11-17 22:58:30 +0000 | [diff] [blame] | 1418 | |
| 1419 | // Push the ObjCInterfaceDecl on the scope chain but do *not* add it to |
| 1420 | // the current DeclContext. This prevents clients that walk DeclContext |
| 1421 | // from seeing the imaginary ObjCInterfaceDecl until it is actually |
| 1422 | // declared later (if at all). We also take care to explicitly make |
| 1423 | // sure this declaration is visible for name lookup. |
| 1424 | PushOnScopeChains(IDecl, TUScope, false); |
| 1425 | CurContext->makeDeclVisibleInContext(IDecl, true); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | Interfaces.push_back(IDecl); |
| 1429 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1430 | |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 1431 | assert(Interfaces.size() == NumElts); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 1432 | ObjCClassDecl *CDecl = ObjCClassDecl::Create(Context, CurContext, AtClassLoc, |
Ted Kremenek | 321c22f | 2009-11-18 00:28:11 +0000 | [diff] [blame] | 1433 | Interfaces.data(), IdentLocs, |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 1434 | Interfaces.size()); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1435 | CurContext->addDecl(CDecl); |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 1436 | CheckObjCDeclScope(CDecl); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1437 | return DeclPtrTy::make(CDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | |
| 1441 | /// MatchTwoMethodDeclarations - Checks that two methods have matching type and |
| 1442 | /// returns true, or false, accordingly. |
| 1443 | /// TODO: Handle protocol list; such as id<p1,p2> in type comparisons |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1444 | bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
Steve Naroff | fe6b0dc | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 1445 | const ObjCMethodDecl *PrevMethod, |
| 1446 | bool matchBasedOnSizeAndAlignment) { |
| 1447 | QualType T1 = Context.getCanonicalType(Method->getResultType()); |
| 1448 | QualType T2 = Context.getCanonicalType(PrevMethod->getResultType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1449 | |
Steve Naroff | fe6b0dc | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 1450 | if (T1 != T2) { |
| 1451 | // The result types are different. |
| 1452 | if (!matchBasedOnSizeAndAlignment) |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1453 | return false; |
Steve Naroff | fe6b0dc | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 1454 | // Incomplete types don't have a size and alignment. |
| 1455 | if (T1->isIncompleteType() || T2->isIncompleteType()) |
| 1456 | return false; |
| 1457 | // Check is based on size and alignment. |
| 1458 | if (Context.getTypeInfo(T1) != Context.getTypeInfo(T2)) |
| 1459 | return false; |
| 1460 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1461 | |
Chris Lattner | 89951a8 | 2009-02-20 18:43:26 +0000 | [diff] [blame] | 1462 | ObjCMethodDecl::param_iterator ParamI = Method->param_begin(), |
| 1463 | E = Method->param_end(); |
| 1464 | ObjCMethodDecl::param_iterator PrevI = PrevMethod->param_begin(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1465 | |
Chris Lattner | 89951a8 | 2009-02-20 18:43:26 +0000 | [diff] [blame] | 1466 | for (; ParamI != E; ++ParamI, ++PrevI) { |
| 1467 | assert(PrevI != PrevMethod->param_end() && "Param mismatch"); |
| 1468 | T1 = Context.getCanonicalType((*ParamI)->getType()); |
| 1469 | T2 = Context.getCanonicalType((*PrevI)->getType()); |
Steve Naroff | fe6b0dc | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 1470 | if (T1 != T2) { |
| 1471 | // The result types are different. |
| 1472 | if (!matchBasedOnSizeAndAlignment) |
| 1473 | return false; |
| 1474 | // Incomplete types don't have a size and alignment. |
| 1475 | if (T1->isIncompleteType() || T2->isIncompleteType()) |
| 1476 | return false; |
| 1477 | // Check is based on size and alignment. |
| 1478 | if (Context.getTypeInfo(T1) != Context.getTypeInfo(T2)) |
| 1479 | return false; |
| 1480 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1481 | } |
| 1482 | return true; |
| 1483 | } |
| 1484 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1485 | /// \brief Read the contents of the instance and factory method pools |
| 1486 | /// for a given selector from external storage. |
| 1487 | /// |
| 1488 | /// This routine should only be called once, when neither the instance |
| 1489 | /// nor the factory method pool has an entry for this selector. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1490 | Sema::MethodPool::iterator Sema::ReadMethodPool(Selector Sel, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1491 | bool isInstance) { |
| 1492 | assert(ExternalSource && "We need an external AST source"); |
| 1493 | assert(InstanceMethodPool.find(Sel) == InstanceMethodPool.end() && |
| 1494 | "Selector data already loaded into the instance method pool"); |
| 1495 | assert(FactoryMethodPool.find(Sel) == FactoryMethodPool.end() && |
| 1496 | "Selector data already loaded into the factory method pool"); |
| 1497 | |
| 1498 | // Read the method list from the external source. |
| 1499 | std::pair<ObjCMethodList, ObjCMethodList> Methods |
| 1500 | = ExternalSource->ReadMethodPool(Sel); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1501 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1502 | if (isInstance) { |
| 1503 | if (Methods.second.Method) |
| 1504 | FactoryMethodPool[Sel] = Methods.second; |
| 1505 | return InstanceMethodPool.insert(std::make_pair(Sel, Methods.first)).first; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1506 | } |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1507 | |
| 1508 | if (Methods.first.Method) |
| 1509 | InstanceMethodPool[Sel] = Methods.first; |
| 1510 | |
| 1511 | return FactoryMethodPool.insert(std::make_pair(Sel, Methods.second)).first; |
| 1512 | } |
| 1513 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1514 | void Sema::AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1515 | llvm::DenseMap<Selector, ObjCMethodList>::iterator Pos |
| 1516 | = InstanceMethodPool.find(Method->getSelector()); |
| 1517 | if (Pos == InstanceMethodPool.end()) { |
| 1518 | if (ExternalSource && !FactoryMethodPool.count(Method->getSelector())) |
| 1519 | Pos = ReadMethodPool(Method->getSelector(), /*isInstance=*/true); |
| 1520 | else |
| 1521 | Pos = InstanceMethodPool.insert(std::make_pair(Method->getSelector(), |
| 1522 | ObjCMethodList())).first; |
| 1523 | } |
| 1524 | |
| 1525 | ObjCMethodList &Entry = Pos->second; |
Chris Lattner | b25df35 | 2009-03-04 05:16:45 +0000 | [diff] [blame] | 1526 | if (Entry.Method == 0) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1527 | // Haven't seen a method with this selector name yet - add it. |
Chris Lattner | b25df35 | 2009-03-04 05:16:45 +0000 | [diff] [blame] | 1528 | Entry.Method = Method; |
| 1529 | Entry.Next = 0; |
| 1530 | return; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1531 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1532 | |
Chris Lattner | b25df35 | 2009-03-04 05:16:45 +0000 | [diff] [blame] | 1533 | // We've seen a method with this name, see if we have already seen this type |
| 1534 | // signature. |
| 1535 | for (ObjCMethodList *List = &Entry; List; List = List->Next) |
| 1536 | if (MatchTwoMethodDeclarations(Method, List->Method)) |
| 1537 | return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1538 | |
Chris Lattner | b25df35 | 2009-03-04 05:16:45 +0000 | [diff] [blame] | 1539 | // We have a new signature for an existing method - add it. |
| 1540 | // This is extremely rare. Only 1% of Cocoa selectors are "overloaded". |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 1541 | ObjCMethodList *Mem = BumpAlloc.Allocate<ObjCMethodList>(); |
| 1542 | Entry.Next = new (Mem) ObjCMethodList(Method, Entry.Next); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
Steve Naroff | 6f5f41c | 2008-10-21 10:50:19 +0000 | [diff] [blame] | 1545 | // FIXME: Finish implementing -Wno-strict-selector-match. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1546 | ObjCMethodDecl *Sema::LookupInstanceMethodInGlobalPool(Selector Sel, |
Fariborz Jahanian | 835ed7f | 2009-08-22 21:13:55 +0000 | [diff] [blame] | 1547 | SourceRange R, |
| 1548 | bool warn) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1549 | llvm::DenseMap<Selector, ObjCMethodList>::iterator Pos |
| 1550 | = InstanceMethodPool.find(Sel); |
Douglas Gregor | 27a4566 | 2009-04-24 22:23:41 +0000 | [diff] [blame] | 1551 | if (Pos == InstanceMethodPool.end()) { |
| 1552 | if (ExternalSource && !FactoryMethodPool.count(Sel)) |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1553 | Pos = ReadMethodPool(Sel, /*isInstance=*/true); |
| 1554 | else |
| 1555 | return 0; |
| 1556 | } |
| 1557 | |
| 1558 | ObjCMethodList &MethList = Pos->second; |
Steve Naroff | fe6b0dc | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 1559 | bool issueWarning = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1560 | |
Steve Naroff | 037cda5 | 2008-09-30 14:38:43 +0000 | [diff] [blame] | 1561 | if (MethList.Method && MethList.Next) { |
Steve Naroff | fe6b0dc | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 1562 | for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next) |
| 1563 | // This checks if the methods differ by size & alignment. |
| 1564 | if (!MatchTwoMethodDeclarations(MethList.Method, Next->Method, true)) |
Fariborz Jahanian | 835ed7f | 2009-08-22 21:13:55 +0000 | [diff] [blame] | 1565 | issueWarning = warn; |
Steve Naroff | fe6b0dc | 2008-10-21 10:37:50 +0000 | [diff] [blame] | 1566 | } |
| 1567 | if (issueWarning && (MethList.Method && MethList.Next)) { |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 1568 | Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel << R; |
John McCall | 41ce66f | 2009-12-10 19:51:03 +0000 | [diff] [blame] | 1569 | Diag(MethList.Method->getLocStart(), diag::note_using) |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 1570 | << MethList.Method->getSourceRange(); |
Steve Naroff | 037cda5 | 2008-09-30 14:38:43 +0000 | [diff] [blame] | 1571 | for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next) |
John McCall | 41ce66f | 2009-12-10 19:51:03 +0000 | [diff] [blame] | 1572 | Diag(Next->Method->getLocStart(), diag::note_also_found) |
Chris Lattner | dcd5ef1 | 2008-11-19 05:27:50 +0000 | [diff] [blame] | 1573 | << Next->Method->getSourceRange(); |
Steve Naroff | 037cda5 | 2008-09-30 14:38:43 +0000 | [diff] [blame] | 1574 | } |
| 1575 | return MethList.Method; |
| 1576 | } |
| 1577 | |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1578 | void Sema::AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method) { |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1579 | llvm::DenseMap<Selector, ObjCMethodList>::iterator Pos |
| 1580 | = FactoryMethodPool.find(Method->getSelector()); |
| 1581 | if (Pos == FactoryMethodPool.end()) { |
| 1582 | if (ExternalSource && !InstanceMethodPool.count(Method->getSelector())) |
| 1583 | Pos = ReadMethodPool(Method->getSelector(), /*isInstance=*/false); |
| 1584 | else |
| 1585 | Pos = FactoryMethodPool.insert(std::make_pair(Method->getSelector(), |
| 1586 | ObjCMethodList())).first; |
| 1587 | } |
| 1588 | |
| 1589 | ObjCMethodList &FirstMethod = Pos->second; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1590 | if (!FirstMethod.Method) { |
| 1591 | // Haven't seen a method with this selector name yet - add it. |
| 1592 | FirstMethod.Method = Method; |
| 1593 | FirstMethod.Next = 0; |
| 1594 | } else { |
| 1595 | // We've seen a method with this name, now check the type signature(s). |
| 1596 | bool match = MatchTwoMethodDeclarations(Method, FirstMethod.Method); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1597 | |
| 1598 | for (ObjCMethodList *Next = FirstMethod.Next; !match && Next; |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1599 | Next = Next->Next) |
| 1600 | match = MatchTwoMethodDeclarations(Method, Next->Method); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1601 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1602 | if (!match) { |
| 1603 | // We have a new signature for an existing method - add it. |
| 1604 | // This is extremely rare. Only 1% of Cocoa selectors are "overloaded". |
Ted Kremenek | 298ed87 | 2010-02-11 00:53:01 +0000 | [diff] [blame] | 1605 | ObjCMethodList *Mem = BumpAlloc.Allocate<ObjCMethodList>(); |
| 1606 | ObjCMethodList *OMI = new (Mem) ObjCMethodList(Method, FirstMethod.Next); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1607 | FirstMethod.Next = OMI; |
| 1608 | } |
| 1609 | } |
| 1610 | } |
| 1611 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1612 | ObjCMethodDecl *Sema::LookupFactoryMethodInGlobalPool(Selector Sel, |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1613 | SourceRange R) { |
| 1614 | llvm::DenseMap<Selector, ObjCMethodList>::iterator Pos |
| 1615 | = FactoryMethodPool.find(Sel); |
| 1616 | if (Pos == FactoryMethodPool.end()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1617 | if (ExternalSource && !InstanceMethodPool.count(Sel)) |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1618 | Pos = ReadMethodPool(Sel, /*isInstance=*/false); |
| 1619 | else |
| 1620 | return 0; |
| 1621 | } |
| 1622 | |
| 1623 | ObjCMethodList &MethList = Pos->second; |
| 1624 | bool issueWarning = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1625 | |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1626 | if (MethList.Method && MethList.Next) { |
| 1627 | for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next) |
| 1628 | // This checks if the methods differ by size & alignment. |
| 1629 | if (!MatchTwoMethodDeclarations(MethList.Method, Next->Method, true)) |
| 1630 | issueWarning = true; |
| 1631 | } |
| 1632 | if (issueWarning && (MethList.Method && MethList.Next)) { |
| 1633 | Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel << R; |
John McCall | 41ce66f | 2009-12-10 19:51:03 +0000 | [diff] [blame] | 1634 | Diag(MethList.Method->getLocStart(), diag::note_using) |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1635 | << MethList.Method->getSourceRange(); |
| 1636 | for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next) |
John McCall | 41ce66f | 2009-12-10 19:51:03 +0000 | [diff] [blame] | 1637 | Diag(Next->Method->getLocStart(), diag::note_also_found) |
Douglas Gregor | f0aaf7a | 2009-04-24 21:10:55 +0000 | [diff] [blame] | 1638 | << Next->Method->getSourceRange(); |
| 1639 | } |
| 1640 | return MethList.Method; |
| 1641 | } |
| 1642 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1643 | /// ProcessPropertyDecl - Make sure that any user-defined setter/getter methods |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 1644 | /// have the property type and issue diagnostics if they don't. |
| 1645 | /// Also synthesize a getter/setter method if none exist (and update the |
| 1646 | /// appropriate lookup tables. FIXME: Should reconsider if adding synthesized |
| 1647 | /// methods is the "right" thing to do. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1648 | void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property, |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 1649 | ObjCContainerDecl *CD) { |
| 1650 | ObjCMethodDecl *GetterMethod, *SetterMethod; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1651 | |
| 1652 | GetterMethod = CD->getInstanceMethod(property->getGetterName()); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1653 | SetterMethod = CD->getInstanceMethod(property->getSetterName()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1654 | DiagnosePropertyAccessorMismatch(property, GetterMethod, |
Fariborz Jahanian | c001e89 | 2009-05-08 20:20:55 +0000 | [diff] [blame] | 1655 | property->getLocation()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1656 | |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1657 | if (SetterMethod) { |
Fariborz Jahanian | 02deae8 | 2010-01-06 00:18:12 +0000 | [diff] [blame] | 1658 | ObjCPropertyDecl::PropertyAttributeKind CAttr = |
| 1659 | property->getPropertyAttributes(); |
| 1660 | if ((!(CAttr & ObjCPropertyDecl::OBJC_PR_readonly)) && |
| 1661 | Context.getCanonicalType(SetterMethod->getResultType()) != |
| 1662 | Context.VoidTy) |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1663 | Diag(SetterMethod->getLocation(), diag::err_setter_type_void); |
Chris Lattner | 89951a8 | 2009-02-20 18:43:26 +0000 | [diff] [blame] | 1664 | if (SetterMethod->param_size() != 1 || |
| 1665 | ((*SetterMethod->param_begin())->getType() != property->getType())) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1666 | Diag(property->getLocation(), |
| 1667 | diag::warn_accessor_property_type_mismatch) |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1668 | << property->getDeclName() |
Ted Kremenek | 8af2c16 | 2009-03-14 00:20:08 +0000 | [diff] [blame] | 1669 | << SetterMethod->getSelector(); |
Fariborz Jahanian | 196d0ed | 2008-12-06 21:48:16 +0000 | [diff] [blame] | 1670 | Diag(SetterMethod->getLocation(), diag::note_declared_at); |
| 1671 | } |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1672 | } |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 1673 | |
| 1674 | // Synthesize getter/setter methods if none exist. |
Steve Naroff | 92f863b | 2009-01-08 20:15:03 +0000 | [diff] [blame] | 1675 | // Find the default getter and if one not found, add one. |
Mike Stump | 390b4cc | 2009-05-16 07:39:55 +0000 | [diff] [blame] | 1676 | // FIXME: The synthesized property we set here is misleading. We almost always |
| 1677 | // synthesize these methods unless the user explicitly provided prototypes |
| 1678 | // (which is odd, but allowed). Sema should be typechecking that the |
| 1679 | // declarations jive in that situation (which it is not currently). |
Steve Naroff | 92f863b | 2009-01-08 20:15:03 +0000 | [diff] [blame] | 1680 | if (!GetterMethod) { |
| 1681 | // No instance method of same name as property getter name was found. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1682 | // Declare a getter method and add it to the list of methods |
Steve Naroff | 92f863b | 2009-01-08 20:15:03 +0000 | [diff] [blame] | 1683 | // for this class. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1684 | GetterMethod = ObjCMethodDecl::Create(Context, property->getLocation(), |
| 1685 | property->getLocation(), property->getGetterName(), |
| 1686 | property->getType(), CD, true, false, true, |
| 1687 | (property->getPropertyImplementation() == |
| 1688 | ObjCPropertyDecl::Optional) ? |
| 1689 | ObjCMethodDecl::Optional : |
Steve Naroff | 92f863b | 2009-01-08 20:15:03 +0000 | [diff] [blame] | 1690 | ObjCMethodDecl::Required); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1691 | CD->addDecl(GetterMethod); |
Steve Naroff | 92f863b | 2009-01-08 20:15:03 +0000 | [diff] [blame] | 1692 | } else |
| 1693 | // A user declared getter will be synthesize when @synthesize of |
| 1694 | // the property with the same name is seen in the @implementation |
Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 1695 | GetterMethod->setSynthesized(true); |
Steve Naroff | 92f863b | 2009-01-08 20:15:03 +0000 | [diff] [blame] | 1696 | property->setGetterMethodDecl(GetterMethod); |
| 1697 | |
| 1698 | // Skip setter if property is read-only. |
| 1699 | if (!property->isReadOnly()) { |
| 1700 | // Find the default setter and if one not found, add one. |
| 1701 | if (!SetterMethod) { |
| 1702 | // No instance method of same name as property setter name was found. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1703 | // Declare a setter method and add it to the list of methods |
Steve Naroff | 92f863b | 2009-01-08 20:15:03 +0000 | [diff] [blame] | 1704 | // for this class. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1705 | SetterMethod = ObjCMethodDecl::Create(Context, property->getLocation(), |
| 1706 | property->getLocation(), |
| 1707 | property->getSetterName(), |
Steve Naroff | 92f863b | 2009-01-08 20:15:03 +0000 | [diff] [blame] | 1708 | Context.VoidTy, CD, true, false, true, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1709 | (property->getPropertyImplementation() == |
| 1710 | ObjCPropertyDecl::Optional) ? |
| 1711 | ObjCMethodDecl::Optional : |
Steve Naroff | 92f863b | 2009-01-08 20:15:03 +0000 | [diff] [blame] | 1712 | ObjCMethodDecl::Required); |
| 1713 | // Invent the arguments for the setter. We don't bother making a |
| 1714 | // nice name for the argument. |
| 1715 | ParmVarDecl *Argument = ParmVarDecl::Create(Context, SetterMethod, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1716 | property->getLocation(), |
Steve Naroff | 92f863b | 2009-01-08 20:15:03 +0000 | [diff] [blame] | 1717 | property->getIdentifier(), |
| 1718 | property->getType(), |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 1719 | /*TInfo=*/0, |
Steve Naroff | 92f863b | 2009-01-08 20:15:03 +0000 | [diff] [blame] | 1720 | VarDecl::None, |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 1721 | 0); |
Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 1722 | SetterMethod->setMethodParams(Context, &Argument, 1); |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1723 | CD->addDecl(SetterMethod); |
Steve Naroff | 92f863b | 2009-01-08 20:15:03 +0000 | [diff] [blame] | 1724 | } else |
| 1725 | // A user declared setter will be synthesize when @synthesize of |
| 1726 | // the property with the same name is seen in the @implementation |
Steve Naroff | 53c9d8a | 2009-04-20 15:06:07 +0000 | [diff] [blame] | 1727 | SetterMethod->setSynthesized(true); |
Steve Naroff | 92f863b | 2009-01-08 20:15:03 +0000 | [diff] [blame] | 1728 | property->setSetterMethodDecl(SetterMethod); |
| 1729 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1730 | // Add any synthesized methods to the global pool. This allows us to |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 1731 | // handle the following, which is supported by GCC (and part of the design). |
| 1732 | // |
| 1733 | // @interface Foo |
| 1734 | // @property double bar; |
| 1735 | // @end |
| 1736 | // |
| 1737 | // void thisIsUnfortunate() { |
| 1738 | // id foo; |
| 1739 | // double bar = [foo bar]; |
| 1740 | // } |
| 1741 | // |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 1742 | if (GetterMethod) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1743 | AddInstanceMethodToGlobalPool(GetterMethod); |
Douglas Gregor | 6037fcb | 2009-01-09 19:42:16 +0000 | [diff] [blame] | 1744 | if (SetterMethod) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1745 | AddInstanceMethodToGlobalPool(SetterMethod); |
Fariborz Jahanian | f3cd3fd | 2008-12-02 18:39:49 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
Fariborz Jahanian | e198f5d | 2009-08-04 17:01:09 +0000 | [diff] [blame] | 1748 | /// CompareMethodParamsInBaseAndSuper - This routine compares methods with |
| 1749 | /// identical selector names in current and its super classes and issues |
| 1750 | /// a warning if any of their argument types are incompatible. |
Fariborz Jahanian | dbdec8b | 2009-08-04 01:07:16 +0000 | [diff] [blame] | 1751 | void Sema::CompareMethodParamsInBaseAndSuper(Decl *ClassDecl, |
| 1752 | ObjCMethodDecl *Method, |
| 1753 | bool IsInstance) { |
Fariborz Jahanian | e198f5d | 2009-08-04 17:01:09 +0000 | [diff] [blame] | 1754 | ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(ClassDecl); |
| 1755 | if (ID == 0) return; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1756 | |
Fariborz Jahanian | e198f5d | 2009-08-04 17:01:09 +0000 | [diff] [blame] | 1757 | while (ObjCInterfaceDecl *SD = ID->getSuperClass()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1758 | ObjCMethodDecl *SuperMethodDecl = |
Fariborz Jahanian | e198f5d | 2009-08-04 17:01:09 +0000 | [diff] [blame] | 1759 | SD->lookupMethod(Method->getSelector(), IsInstance); |
| 1760 | if (SuperMethodDecl == 0) { |
Fariborz Jahanian | dbdec8b | 2009-08-04 01:07:16 +0000 | [diff] [blame] | 1761 | ID = SD; |
Fariborz Jahanian | e198f5d | 2009-08-04 17:01:09 +0000 | [diff] [blame] | 1762 | continue; |
Fariborz Jahanian | dbdec8b | 2009-08-04 01:07:16 +0000 | [diff] [blame] | 1763 | } |
Fariborz Jahanian | e198f5d | 2009-08-04 17:01:09 +0000 | [diff] [blame] | 1764 | ObjCMethodDecl::param_iterator ParamI = Method->param_begin(), |
| 1765 | E = Method->param_end(); |
| 1766 | ObjCMethodDecl::param_iterator PrevI = SuperMethodDecl->param_begin(); |
| 1767 | for (; ParamI != E; ++ParamI, ++PrevI) { |
| 1768 | // Number of parameters are the same and is guaranteed by selector match. |
| 1769 | assert(PrevI != SuperMethodDecl->param_end() && "Param mismatch"); |
| 1770 | QualType T1 = Context.getCanonicalType((*ParamI)->getType()); |
| 1771 | QualType T2 = Context.getCanonicalType((*PrevI)->getType()); |
| 1772 | // If type of arguement of method in this class does not match its |
| 1773 | // respective argument type in the super class method, issue warning; |
| 1774 | if (!Context.typesAreCompatible(T1, T2)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1775 | Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super) |
Fariborz Jahanian | e198f5d | 2009-08-04 17:01:09 +0000 | [diff] [blame] | 1776 | << T1 << T2; |
| 1777 | Diag(SuperMethodDecl->getLocation(), diag::note_previous_declaration); |
| 1778 | return; |
| 1779 | } |
| 1780 | } |
| 1781 | ID = SD; |
| 1782 | } |
Fariborz Jahanian | dbdec8b | 2009-08-04 01:07:16 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
Fariborz Jahanian | f914b97 | 2010-02-23 23:41:11 +0000 | [diff] [blame] | 1785 | /// DiagnoseDuplicateIvars - |
| 1786 | /// Check for duplicate ivars in the entire class at the start of |
| 1787 | /// @implementation. This becomes necesssary because class extension can |
| 1788 | /// add ivars to a class in random order which will not be known until |
| 1789 | /// class's @implementation is seen. |
| 1790 | void Sema::DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, |
| 1791 | ObjCInterfaceDecl *SID) { |
| 1792 | for (ObjCInterfaceDecl::ivar_iterator IVI = ID->ivar_begin(), |
| 1793 | IVE = ID->ivar_end(); IVI != IVE; ++IVI) { |
| 1794 | ObjCIvarDecl* Ivar = (*IVI); |
| 1795 | if (Ivar->isInvalidDecl()) |
| 1796 | continue; |
| 1797 | if (IdentifierInfo *II = Ivar->getIdentifier()) { |
| 1798 | ObjCIvarDecl* prevIvar = SID->lookupInstanceVariable(II); |
| 1799 | if (prevIvar) { |
| 1800 | Diag(Ivar->getLocation(), diag::err_duplicate_member) << II; |
| 1801 | Diag(prevIvar->getLocation(), diag::note_previous_declaration); |
| 1802 | Ivar->setInvalidDecl(); |
| 1803 | } |
| 1804 | } |
| 1805 | } |
| 1806 | } |
| 1807 | |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 1808 | // Note: For class/category implemenations, allMethods/allProperties is |
| 1809 | // always null. |
Ted Kremenek | 782f2f5 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 1810 | void Sema::ActOnAtEnd(SourceRange AtEnd, |
| 1811 | DeclPtrTy classDecl, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1812 | DeclPtrTy *allMethods, unsigned allNum, |
| 1813 | DeclPtrTy *allProperties, unsigned pNum, |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1814 | DeclGroupPtrTy *allTUVars, unsigned tuvNum) { |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1815 | Decl *ClassDecl = classDecl.getAs<Decl>(); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1816 | |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 1817 | // FIXME: If we don't have a ClassDecl, we have an error. We should consider |
| 1818 | // always passing in a decl. If the decl has an error, isInvalidDecl() |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1819 | // should be true. |
| 1820 | if (!ClassDecl) |
| 1821 | return; |
Fariborz Jahanian | 63e963c | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1822 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1823 | bool isInterfaceDeclKind = |
Chris Lattner | f8d17a5 | 2008-03-16 21:17:37 +0000 | [diff] [blame] | 1824 | isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl) |
| 1825 | || isa<ObjCProtocolDecl>(ClassDecl); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1826 | bool checkIdenticalMethods = isa<ObjCImplementationDecl>(ClassDecl); |
Steve Naroff | 09c4719 | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 1827 | |
Ted Kremenek | 782f2f5 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 1828 | if (!isInterfaceDeclKind && AtEnd.isInvalid()) { |
| 1829 | // FIXME: This is wrong. We shouldn't be pretending that there is |
| 1830 | // an '@end' in the declaration. |
| 1831 | SourceLocation L = ClassDecl->getLocation(); |
| 1832 | AtEnd.setBegin(L); |
| 1833 | AtEnd.setEnd(L); |
| 1834 | Diag(L, diag::warn_missing_atend); |
Fariborz Jahanian | 63e963c | 2009-11-16 18:57:01 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 1837 | DeclContext *DC = dyn_cast<DeclContext>(ClassDecl); |
Steve Naroff | 0701bbb | 2009-01-08 17:28:14 +0000 | [diff] [blame] | 1838 | |
| 1839 | // FIXME: Remove these and use the ObjCContainerDecl/DeclContext. |
| 1840 | llvm::DenseMap<Selector, const ObjCMethodDecl*> InsMap; |
| 1841 | llvm::DenseMap<Selector, const ObjCMethodDecl*> ClsMap; |
| 1842 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1843 | for (unsigned i = 0; i < allNum; i++ ) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1844 | ObjCMethodDecl *Method = |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1845 | cast_or_null<ObjCMethodDecl>(allMethods[i].getAs<Decl>()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1846 | |
| 1847 | if (!Method) continue; // Already issued a diagnostic. |
Douglas Gregor | f8d49f6 | 2009-01-09 17:18:27 +0000 | [diff] [blame] | 1848 | if (Method->isInstanceMethod()) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1849 | /// Check for instance method of the same name with incompatible types |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1850 | const ObjCMethodDecl *&PrevMethod = InsMap[Method->getSelector()]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1851 | bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod) |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1852 | : false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1853 | if ((isInterfaceDeclKind && PrevMethod && !match) |
Eli Friedman | 82b4e76 | 2008-12-16 20:15:50 +0000 | [diff] [blame] | 1854 | || (checkIdenticalMethods && match)) { |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 1855 | Diag(Method->getLocation(), diag::err_duplicate_method_decl) |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 1856 | << Method->getDeclName(); |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 1857 | Diag(PrevMethod->getLocation(), diag::note_previous_declaration); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1858 | } else { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1859 | DC->addDecl(Method); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1860 | InsMap[Method->getSelector()] = Method; |
| 1861 | /// The following allows us to typecheck messages to "id". |
| 1862 | AddInstanceMethodToGlobalPool(Method); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1863 | // verify that the instance method conforms to the same definition of |
Fariborz Jahanian | e198f5d | 2009-08-04 17:01:09 +0000 | [diff] [blame] | 1864 | // parent methods if it shadows one. |
Fariborz Jahanian | dbdec8b | 2009-08-04 01:07:16 +0000 | [diff] [blame] | 1865 | CompareMethodParamsInBaseAndSuper(ClassDecl, Method, true); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1866 | } |
Mike Stump | ac5fc7c | 2009-08-04 21:02:39 +0000 | [diff] [blame] | 1867 | } else { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1868 | /// Check for class method of the same name with incompatible types |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1869 | const ObjCMethodDecl *&PrevMethod = ClsMap[Method->getSelector()]; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1870 | bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod) |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1871 | : false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1872 | if ((isInterfaceDeclKind && PrevMethod && !match) |
Eli Friedman | 82b4e76 | 2008-12-16 20:15:50 +0000 | [diff] [blame] | 1873 | || (checkIdenticalMethods && match)) { |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 1874 | Diag(Method->getLocation(), diag::err_duplicate_method_decl) |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 1875 | << Method->getDeclName(); |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 1876 | Diag(PrevMethod->getLocation(), diag::note_previous_declaration); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1877 | } else { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1878 | DC->addDecl(Method); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1879 | ClsMap[Method->getSelector()] = Method; |
Steve Naroff | a56f616 | 2007-12-18 01:30:32 +0000 | [diff] [blame] | 1880 | /// The following allows us to typecheck messages to "Class". |
| 1881 | AddFactoryMethodToGlobalPool(Method); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1882 | // verify that the class method conforms to the same definition of |
Fariborz Jahanian | e198f5d | 2009-08-04 17:01:09 +0000 | [diff] [blame] | 1883 | // parent methods if it shadows one. |
Fariborz Jahanian | dbdec8b | 2009-08-04 01:07:16 +0000 | [diff] [blame] | 1884 | CompareMethodParamsInBaseAndSuper(ClassDecl, Method, false); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1885 | } |
| 1886 | } |
| 1887 | } |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1888 | if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1889 | // Compares properties declared in this class to those of its |
Fariborz Jahanian | 02edb98 | 2008-05-01 00:03:38 +0000 | [diff] [blame] | 1890 | // super class. |
Fariborz Jahanian | aebf0cb | 2008-05-02 19:17:30 +0000 | [diff] [blame] | 1891 | ComparePropertiesInBaseAndSuper(I); |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 1892 | CompareProperties(I, DeclPtrTy::make(I)); |
Steve Naroff | 09c4719 | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 1893 | } else if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(ClassDecl)) { |
Fariborz Jahanian | 77e14bd | 2008-12-06 19:59:02 +0000 | [diff] [blame] | 1894 | // Categories are used to extend the class by declaring new methods. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1895 | // By the same token, they are also used to add new properties. No |
Fariborz Jahanian | 77e14bd | 2008-12-06 19:59:02 +0000 | [diff] [blame] | 1896 | // need to compare the added property to those in the class. |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 1897 | |
Fariborz Jahanian | 107089f | 2010-01-18 18:41:16 +0000 | [diff] [blame] | 1898 | // Compare protocol properties with those in category |
| 1899 | CompareProperties(C, DeclPtrTy::make(C)); |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 1900 | if (C->IsClassExtension()) |
Fariborz Jahanian | b7f95f5 | 2009-03-02 19:05:07 +0000 | [diff] [blame] | 1901 | DiagnoseClassExtensionDupMethods(C, C->getClassInterface()); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1902 | } |
Steve Naroff | 09c4719 | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 1903 | if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(ClassDecl)) { |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 1904 | if (CDecl->getIdentifier()) |
| 1905 | // ProcessPropertyDecl is responsible for diagnosing conflicts with any |
| 1906 | // user-defined setter/getter. It also synthesizes setter/getter methods |
| 1907 | // and adds them to the DeclContext and global method pools. |
| 1908 | for (ObjCContainerDecl::prop_iterator I = CDecl->prop_begin(), |
| 1909 | E = CDecl->prop_end(); |
| 1910 | I != E; ++I) |
| 1911 | ProcessPropertyDecl(*I, CDecl); |
Ted Kremenek | 782f2f5 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 1912 | CDecl->setAtEndRange(AtEnd); |
Steve Naroff | 09c4719 | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 1913 | } |
| 1914 | if (ObjCImplementationDecl *IC=dyn_cast<ObjCImplementationDecl>(ClassDecl)) { |
Ted Kremenek | 782f2f5 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 1915 | IC->setAtEndRange(AtEnd); |
Fariborz Jahanian | 7ca8b06 | 2009-11-11 22:40:11 +0000 | [diff] [blame] | 1916 | if (ObjCInterfaceDecl* IDecl = IC->getClassInterface()) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1917 | ImplMethodsVsClassMethods(IC, IDecl); |
Fariborz Jahanian | 7ca8b06 | 2009-11-11 22:40:11 +0000 | [diff] [blame] | 1918 | AtomicPropertySetterGetterRules(IC, IDecl); |
Fariborz Jahanian | f914b97 | 2010-02-23 23:41:11 +0000 | [diff] [blame] | 1919 | if (LangOpts.ObjCNonFragileABI2) |
| 1920 | while (IDecl->getSuperClass()) { |
| 1921 | DiagnoseDuplicateIvars(IDecl, IDecl->getSuperClass()); |
| 1922 | IDecl = IDecl->getSuperClass(); |
| 1923 | } |
Fariborz Jahanian | 7ca8b06 | 2009-11-11 22:40:11 +0000 | [diff] [blame] | 1924 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1925 | } else if (ObjCCategoryImplDecl* CatImplClass = |
Steve Naroff | 09c4719 | 2009-01-09 15:36:25 +0000 | [diff] [blame] | 1926 | dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) { |
Ted Kremenek | 782f2f5 | 2010-01-07 01:20:12 +0000 | [diff] [blame] | 1927 | CatImplClass->setAtEndRange(AtEnd); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1928 | |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1929 | // Find category interface decl and then check that all methods declared |
Daniel Dunbar | b20ef3e | 2008-08-27 05:40:03 +0000 | [diff] [blame] | 1930 | // in this interface are implemented in the category @implementation. |
Chris Lattner | 97a5887 | 2009-02-16 18:32:47 +0000 | [diff] [blame] | 1931 | if (ObjCInterfaceDecl* IDecl = CatImplClass->getClassInterface()) { |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1932 | for (ObjCCategoryDecl *Categories = IDecl->getCategoryList(); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1933 | Categories; Categories = Categories->getNextClassCategory()) { |
| 1934 | if (Categories->getIdentifier() == CatImplClass->getIdentifier()) { |
Chris Lattner | cddc888 | 2009-03-01 00:56:52 +0000 | [diff] [blame] | 1935 | ImplMethodsVsClassMethods(CatImplClass, Categories); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1936 | break; |
| 1937 | } |
| 1938 | } |
| 1939 | } |
| 1940 | } |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1941 | if (isInterfaceDeclKind) { |
| 1942 | // Reject invalid vardecls. |
| 1943 | for (unsigned i = 0; i != tuvNum; i++) { |
| 1944 | DeclGroupRef DG = allTUVars[i].getAsVal<DeclGroupRef>(); |
| 1945 | for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I) |
| 1946 | if (VarDecl *VDecl = dyn_cast<VarDecl>(*I)) { |
Daniel Dunbar | 5466c7b | 2009-04-14 02:25:56 +0000 | [diff] [blame] | 1947 | if (!VDecl->hasExternalStorage()) |
Steve Naroff | 8745416 | 2009-04-13 17:58:46 +0000 | [diff] [blame] | 1948 | Diag(VDecl->getLocation(), diag::err_objc_var_decl_inclass); |
Fariborz Jahanian | b31cb7f | 2009-03-21 18:06:45 +0000 | [diff] [blame] | 1949 | } |
Chris Lattner | 682bf92 | 2009-03-29 16:50:03 +0000 | [diff] [blame] | 1950 | } |
Fariborz Jahanian | 38e24c7 | 2009-03-18 22:33:24 +0000 | [diff] [blame] | 1951 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | |
| 1955 | /// CvtQTToAstBitMask - utility routine to produce an AST bitmask for |
| 1956 | /// objective-c's type qualifier from the parser version of the same info. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1957 | static Decl::ObjCDeclQualifier |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1958 | CvtQTToAstBitMask(ObjCDeclSpec::ObjCDeclQualifier PQTVal) { |
| 1959 | Decl::ObjCDeclQualifier ret = Decl::OBJC_TQ_None; |
| 1960 | if (PQTVal & ObjCDeclSpec::DQ_In) |
| 1961 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_In); |
| 1962 | if (PQTVal & ObjCDeclSpec::DQ_Inout) |
| 1963 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Inout); |
| 1964 | if (PQTVal & ObjCDeclSpec::DQ_Out) |
| 1965 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Out); |
| 1966 | if (PQTVal & ObjCDeclSpec::DQ_Bycopy) |
| 1967 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Bycopy); |
| 1968 | if (PQTVal & ObjCDeclSpec::DQ_Byref) |
| 1969 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Byref); |
| 1970 | if (PQTVal & ObjCDeclSpec::DQ_Oneway) |
| 1971 | ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Oneway); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1972 | |
| 1973 | return ret; |
| 1974 | } |
| 1975 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1976 | Sema::DeclPtrTy Sema::ActOnMethodDeclaration( |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1977 | SourceLocation MethodLoc, SourceLocation EndLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1978 | tok::TokenKind MethodType, DeclPtrTy classDecl, |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 1979 | ObjCDeclSpec &ReturnQT, TypeTy *ReturnType, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1980 | Selector Sel, |
| 1981 | // optional arguments. The number of types/arguments is obtained |
| 1982 | // from the Sel.getNumArgs(). |
Chris Lattner | e294d3f | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 1983 | ObjCArgInfo *ArgInfo, |
Fariborz Jahanian | 439c658 | 2009-01-09 00:38:19 +0000 | [diff] [blame] | 1984 | llvm::SmallVectorImpl<Declarator> &Cdecls, |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1985 | AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind, |
| 1986 | bool isVariadic) { |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1987 | Decl *ClassDecl = classDecl.getAs<Decl>(); |
Steve Naroff | da323ad | 2008-02-29 21:48:07 +0000 | [diff] [blame] | 1988 | |
| 1989 | // Make sure we can establish a context for the method. |
| 1990 | if (!ClassDecl) { |
| 1991 | Diag(MethodLoc, diag::error_missing_method_context); |
Fariborz Jahanian | 32844b3 | 2009-08-28 17:52:37 +0000 | [diff] [blame] | 1992 | FunctionLabelMap.clear(); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 1993 | return DeclPtrTy(); |
Steve Naroff | da323ad | 2008-02-29 21:48:07 +0000 | [diff] [blame] | 1994 | } |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 1995 | QualType resultDeclType; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1996 | |
Steve Naroff | ccef371 | 2009-02-20 22:59:16 +0000 | [diff] [blame] | 1997 | if (ReturnType) { |
Argyrios Kyrtzidis | e866190 | 2009-08-19 01:28:28 +0000 | [diff] [blame] | 1998 | resultDeclType = GetTypeFromParser(ReturnType); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1999 | |
Steve Naroff | ccef371 | 2009-02-20 22:59:16 +0000 | [diff] [blame] | 2000 | // Methods cannot return interface types. All ObjC objects are |
| 2001 | // passed by reference. |
| 2002 | if (resultDeclType->isObjCInterfaceType()) { |
Chris Lattner | 2dd979f | 2009-04-11 19:08:56 +0000 | [diff] [blame] | 2003 | Diag(MethodLoc, diag::err_object_cannot_be_passed_returned_by_value) |
| 2004 | << 0 << resultDeclType; |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2005 | return DeclPtrTy(); |
Steve Naroff | ccef371 | 2009-02-20 22:59:16 +0000 | [diff] [blame] | 2006 | } |
| 2007 | } else // get the type for "id". |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2008 | resultDeclType = Context.getObjCIdType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2009 | |
| 2010 | ObjCMethodDecl* ObjCMethod = |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 2011 | ObjCMethodDecl::Create(Context, MethodLoc, EndLoc, Sel, resultDeclType, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2012 | cast<DeclContext>(ClassDecl), |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 2013 | MethodType == tok::minus, isVariadic, |
Fariborz Jahanian | 4607034 | 2008-05-07 20:53:44 +0000 | [diff] [blame] | 2014 | false, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2015 | MethodDeclKind == tok::objc_optional ? |
| 2016 | ObjCMethodDecl::Optional : |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 2017 | ObjCMethodDecl::Required); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2018 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 2019 | llvm::SmallVector<ParmVarDecl*, 16> Params; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2020 | |
Chris Lattner | 7db638d | 2009-04-11 19:42:43 +0000 | [diff] [blame] | 2021 | for (unsigned i = 0, e = Sel.getNumArgs(); i != e; ++i) { |
John McCall | 58e4677 | 2009-10-23 21:48:59 +0000 | [diff] [blame] | 2022 | QualType ArgType; |
John McCall | a93c934 | 2009-12-07 02:54:59 +0000 | [diff] [blame] | 2023 | TypeSourceInfo *DI; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2024 | |
Chris Lattner | e294d3f | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 2025 | if (ArgInfo[i].Type == 0) { |
John McCall | 58e4677 | 2009-10-23 21:48:59 +0000 | [diff] [blame] | 2026 | ArgType = Context.getObjCIdType(); |
| 2027 | DI = 0; |
Chris Lattner | e294d3f | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 2028 | } else { |
John McCall | 58e4677 | 2009-10-23 21:48:59 +0000 | [diff] [blame] | 2029 | ArgType = GetTypeFromParser(ArgInfo[i].Type, &DI); |
Steve Naroff | 6082c62 | 2008-12-09 19:36:17 +0000 | [diff] [blame] | 2030 | // Perform the default array/function conversions (C99 6.7.5.3p[7,8]). |
Chris Lattner | f97e8fa | 2009-04-11 19:34:56 +0000 | [diff] [blame] | 2031 | ArgType = adjustParameterType(ArgType); |
Chris Lattner | e294d3f | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 2032 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2033 | |
John McCall | 58e4677 | 2009-10-23 21:48:59 +0000 | [diff] [blame] | 2034 | ParmVarDecl* Param |
| 2035 | = ParmVarDecl::Create(Context, ObjCMethod, ArgInfo[i].NameLoc, |
| 2036 | ArgInfo[i].Name, ArgType, DI, |
| 2037 | VarDecl::None, 0); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2038 | |
Chris Lattner | f97e8fa | 2009-04-11 19:34:56 +0000 | [diff] [blame] | 2039 | if (ArgType->isObjCInterfaceType()) { |
| 2040 | Diag(ArgInfo[i].NameLoc, |
| 2041 | diag::err_object_cannot_be_passed_returned_by_value) |
| 2042 | << 1 << ArgType; |
| 2043 | Param->setInvalidDecl(); |
| 2044 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2045 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 2046 | Param->setObjCDeclQualifier( |
Chris Lattner | e294d3f | 2009-04-11 18:57:04 +0000 | [diff] [blame] | 2047 | CvtQTToAstBitMask(ArgInfo[i].DeclSpec.getObjCDeclQualifier())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2048 | |
Chris Lattner | f97e8fa | 2009-04-11 19:34:56 +0000 | [diff] [blame] | 2049 | // Apply the attributes to the parameter. |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 2050 | ProcessDeclAttributeList(TUScope, Param, ArgInfo[i].ArgAttrs); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2051 | |
Chris Lattner | 0ed844b | 2008-04-04 06:12:32 +0000 | [diff] [blame] | 2052 | Params.push_back(Param); |
| 2053 | } |
| 2054 | |
Jay Foad | beaaccd | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 2055 | ObjCMethod->setMethodParams(Context, Params.data(), Sel.getNumArgs()); |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2056 | ObjCMethod->setObjCDeclQualifier( |
| 2057 | CvtQTToAstBitMask(ReturnQT.getObjCDeclQualifier())); |
| 2058 | const ObjCMethodDecl *PrevMethod = 0; |
Daniel Dunbar | 3568249 | 2008-09-26 04:12:28 +0000 | [diff] [blame] | 2059 | |
| 2060 | if (AttrList) |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 2061 | ProcessDeclAttributeList(TUScope, ObjCMethod, AttrList); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2062 | |
John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 2063 | const ObjCMethodDecl *InterfaceMD = 0; |
| 2064 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2065 | // For implementations (which can be very "coarse grain"), we add the |
| 2066 | // method now. This allows the AST to implement lookup methods that work |
| 2067 | // incrementally (without waiting until we parse the @end). It also allows |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 2068 | // us to flag multiple declaration errors as they occur. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2069 | if (ObjCImplementationDecl *ImpDecl = |
Chris Lattner | 6c4ae5d | 2008-03-16 00:49:28 +0000 | [diff] [blame] | 2070 | dyn_cast<ObjCImplementationDecl>(ClassDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 2071 | if (MethodType == tok::minus) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2072 | PrevMethod = ImpDecl->getInstanceMethod(Sel); |
| 2073 | ImpDecl->addInstanceMethod(ObjCMethod); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 2074 | } else { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2075 | PrevMethod = ImpDecl->getClassMethod(Sel); |
| 2076 | ImpDecl->addClassMethod(ObjCMethod); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 2077 | } |
John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 2078 | InterfaceMD = ImpDecl->getClassInterface()->getMethod(Sel, |
| 2079 | MethodType == tok::minus); |
Fariborz Jahanian | 5d36ac2 | 2009-05-12 21:36:23 +0000 | [diff] [blame] | 2080 | if (AttrList) |
| 2081 | Diag(EndLoc, diag::warn_attribute_method_def); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2082 | } else if (ObjCCategoryImplDecl *CatImpDecl = |
Mike Stump | ac5fc7c | 2009-08-04 21:02:39 +0000 | [diff] [blame] | 2083 | dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) { |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 2084 | if (MethodType == tok::minus) { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2085 | PrevMethod = CatImpDecl->getInstanceMethod(Sel); |
| 2086 | CatImpDecl->addInstanceMethod(ObjCMethod); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 2087 | } else { |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2088 | PrevMethod = CatImpDecl->getClassMethod(Sel); |
| 2089 | CatImpDecl->addClassMethod(ObjCMethod); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 2090 | } |
Fariborz Jahanian | 5d36ac2 | 2009-05-12 21:36:23 +0000 | [diff] [blame] | 2091 | if (AttrList) |
| 2092 | Diag(EndLoc, diag::warn_attribute_method_def); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 2093 | } |
| 2094 | if (PrevMethod) { |
| 2095 | // You can never have two method definitions with the same name. |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 2096 | Diag(ObjCMethod->getLocation(), diag::err_duplicate_method_decl) |
Chris Lattner | 077bf5e | 2008-11-24 03:33:13 +0000 | [diff] [blame] | 2097 | << ObjCMethod->getDeclName(); |
Chris Lattner | 5f4a682 | 2008-11-23 23:12:31 +0000 | [diff] [blame] | 2098 | Diag(PrevMethod->getLocation(), diag::note_previous_declaration); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2099 | } |
John McCall | 54abf7d | 2009-11-04 02:18:39 +0000 | [diff] [blame] | 2100 | |
| 2101 | // If the interface declared this method, and it was deprecated there, |
| 2102 | // mark it deprecated here. |
| 2103 | if (InterfaceMD && InterfaceMD->hasAttr<DeprecatedAttr>()) |
| 2104 | ObjCMethod->addAttr(::new (Context) DeprecatedAttr()); |
| 2105 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2106 | return DeclPtrTy::make(ObjCMethod); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2109 | void Sema::CheckObjCPropertyAttributes(QualType PropertyTy, |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2110 | SourceLocation Loc, |
| 2111 | unsigned &Attributes) { |
| 2112 | // FIXME: Improve the reported location. |
| 2113 | |
Fariborz Jahanian | 567c8df | 2008-12-06 01:12:43 +0000 | [diff] [blame] | 2114 | // readonly and readwrite/assign/retain/copy conflict. |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2115 | if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) && |
Fariborz Jahanian | 567c8df | 2008-12-06 01:12:43 +0000 | [diff] [blame] | 2116 | (Attributes & (ObjCDeclSpec::DQ_PR_readwrite | |
| 2117 | ObjCDeclSpec::DQ_PR_assign | |
| 2118 | ObjCDeclSpec::DQ_PR_copy | |
| 2119 | ObjCDeclSpec::DQ_PR_retain))) { |
| 2120 | const char * which = (Attributes & ObjCDeclSpec::DQ_PR_readwrite) ? |
| 2121 | "readwrite" : |
| 2122 | (Attributes & ObjCDeclSpec::DQ_PR_assign) ? |
| 2123 | "assign" : |
| 2124 | (Attributes & ObjCDeclSpec::DQ_PR_copy) ? |
| 2125 | "copy" : "retain"; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2126 | |
| 2127 | Diag(Loc, (Attributes & (ObjCDeclSpec::DQ_PR_readwrite)) ? |
Chris Lattner | 28372fa | 2009-01-29 18:49:48 +0000 | [diff] [blame] | 2128 | diag::err_objc_property_attr_mutually_exclusive : |
| 2129 | diag::warn_objc_property_attr_mutually_exclusive) |
Fariborz Jahanian | 567c8df | 2008-12-06 01:12:43 +0000 | [diff] [blame] | 2130 | << "readonly" << which; |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | // Check for copy or retain on non-object types. |
| 2134 | if ((Attributes & (ObjCDeclSpec::DQ_PR_copy | ObjCDeclSpec::DQ_PR_retain)) && |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2135 | !PropertyTy->isObjCObjectPointerType() && |
| 2136 | !PropertyTy->isBlockPointerType() && |
Steve Naroff | f495456 | 2009-07-16 15:41:00 +0000 | [diff] [blame] | 2137 | !Context.isObjCNSObjectType(PropertyTy)) { |
Chris Lattner | 5dc266a | 2008-11-20 06:13:02 +0000 | [diff] [blame] | 2138 | Diag(Loc, diag::err_objc_property_requires_object) |
| 2139 | << (Attributes & ObjCDeclSpec::DQ_PR_copy ? "copy" : "retain"); |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2140 | Attributes &= ~(ObjCDeclSpec::DQ_PR_copy | ObjCDeclSpec::DQ_PR_retain); |
| 2141 | } |
| 2142 | |
| 2143 | // Check for more than one of { assign, copy, retain }. |
| 2144 | if (Attributes & ObjCDeclSpec::DQ_PR_assign) { |
| 2145 | if (Attributes & ObjCDeclSpec::DQ_PR_copy) { |
Chris Lattner | 5dc266a | 2008-11-20 06:13:02 +0000 | [diff] [blame] | 2146 | Diag(Loc, diag::err_objc_property_attr_mutually_exclusive) |
| 2147 | << "assign" << "copy"; |
| 2148 | Attributes &= ~ObjCDeclSpec::DQ_PR_copy; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2149 | } |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2150 | if (Attributes & ObjCDeclSpec::DQ_PR_retain) { |
Chris Lattner | 5dc266a | 2008-11-20 06:13:02 +0000 | [diff] [blame] | 2151 | Diag(Loc, diag::err_objc_property_attr_mutually_exclusive) |
| 2152 | << "assign" << "retain"; |
| 2153 | Attributes &= ~ObjCDeclSpec::DQ_PR_retain; |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2154 | } |
| 2155 | } else if (Attributes & ObjCDeclSpec::DQ_PR_copy) { |
| 2156 | if (Attributes & ObjCDeclSpec::DQ_PR_retain) { |
Chris Lattner | 5dc266a | 2008-11-20 06:13:02 +0000 | [diff] [blame] | 2157 | Diag(Loc, diag::err_objc_property_attr_mutually_exclusive) |
| 2158 | << "copy" << "retain"; |
| 2159 | Attributes &= ~ObjCDeclSpec::DQ_PR_retain; |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2160 | } |
| 2161 | } |
| 2162 | |
| 2163 | // Warn if user supplied no assignment attribute, property is |
| 2164 | // readwrite, and this is an object type. |
| 2165 | if (!(Attributes & (ObjCDeclSpec::DQ_PR_assign | ObjCDeclSpec::DQ_PR_copy | |
| 2166 | ObjCDeclSpec::DQ_PR_retain)) && |
| 2167 | !(Attributes & ObjCDeclSpec::DQ_PR_readonly) && |
Steve Naroff | f495456 | 2009-07-16 15:41:00 +0000 | [diff] [blame] | 2168 | PropertyTy->isObjCObjectPointerType()) { |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2169 | // Skip this warning in gc-only mode. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2170 | if (getLangOptions().getGCMode() != LangOptions::GCOnly) |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2171 | Diag(Loc, diag::warn_objc_property_no_assignment_attribute); |
| 2172 | |
| 2173 | // If non-gc code warn that this is likely inappropriate. |
| 2174 | if (getLangOptions().getGCMode() == LangOptions::NonGC) |
| 2175 | Diag(Loc, diag::warn_objc_property_default_assign_on_object); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2176 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2177 | // FIXME: Implement warning dependent on NSCopying being |
| 2178 | // implemented. See also: |
| 2179 | // <rdar://5168496&4855821&5607453&5096644&4947311&5698469&4947014&5168496> |
| 2180 | // (please trim this list while you are at it). |
| 2181 | } |
Mike Stump | 046efd9 | 2009-05-07 23:06:50 +0000 | [diff] [blame] | 2182 | |
| 2183 | if (!(Attributes & ObjCDeclSpec::DQ_PR_copy) |
| 2184 | && getLangOptions().getGCMode() == LangOptions::GCOnly |
| 2185 | && PropertyTy->isBlockPointerType()) |
| 2186 | Diag(Loc, diag::warn_objc_property_copy_missing_on_block); |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2187 | } |
| 2188 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2189 | Sema::DeclPtrTy Sema::ActOnProperty(Scope *S, SourceLocation AtLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2190 | FieldDeclarator &FD, |
| 2191 | ObjCDeclSpec &ODS, |
| 2192 | Selector GetterSel, |
| 2193 | Selector SetterSel, |
| 2194 | DeclPtrTy ClassCategory, |
| 2195 | bool *isOverridingProperty, |
| 2196 | tok::ObjCKeywordKind MethodImplKind) { |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2197 | unsigned Attributes = ODS.getPropertyAttributes(); |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 2198 | bool isReadWrite = ((Attributes & ObjCDeclSpec::DQ_PR_readwrite) || |
| 2199 | // default is readwrite! |
| 2200 | !(Attributes & ObjCDeclSpec::DQ_PR_readonly)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2201 | // property is defaulted to 'assign' if it is readwrite and is |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 2202 | // not retain or copy |
| 2203 | bool isAssign = ((Attributes & ObjCDeclSpec::DQ_PR_assign) || |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2204 | (isReadWrite && |
| 2205 | !(Attributes & ObjCDeclSpec::DQ_PR_retain) && |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 2206 | !(Attributes & ObjCDeclSpec::DQ_PR_copy))); |
| 2207 | QualType T = GetTypeForDeclarator(FD.D, S); |
Fariborz Jahanian | dd69aae | 2009-12-16 18:03:30 +0000 | [diff] [blame] | 2208 | if (T->isReferenceType()) { |
| 2209 | Diag(AtLoc, diag::error_reference_property); |
| 2210 | return DeclPtrTy(); |
| 2211 | } |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2212 | Decl *ClassDecl = ClassCategory.getAs<Decl>(); |
Fariborz Jahanian | d09a456 | 2009-04-02 18:44:20 +0000 | [diff] [blame] | 2213 | ObjCInterfaceDecl *CCPrimary = 0; // continuation class's primary class |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2214 | // May modify Attributes. |
| 2215 | CheckObjCPropertyAttributes(T, AtLoc, Attributes); |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 2216 | if (ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl)) |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 2217 | if (CDecl->IsClassExtension()) { |
| 2218 | // Diagnose if this property is already in continuation class. |
| 2219 | DeclContext *DC = dyn_cast<DeclContext>(ClassDecl); |
| 2220 | assert(DC && "ClassDecl is not a DeclContext"); |
| 2221 | DeclContext::lookup_result Found = DC->lookup(FD.D.getIdentifier()); |
| 2222 | if (Found.first != Found.second && isa<ObjCPropertyDecl>(*Found.first)) { |
| 2223 | Diag(AtLoc, diag::err_duplicate_property); |
| 2224 | Diag((*Found.first)->getLocation(), diag::note_property_declare); |
| 2225 | return DeclPtrTy(); |
| 2226 | } |
| 2227 | ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, DC, |
| 2228 | FD.D.getIdentifierLoc(), |
| 2229 | FD.D.getIdentifier(), |
| 2230 | AtLoc, T); |
| 2231 | DC->addDecl(PDecl); |
| 2232 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2233 | // This is a continuation class. property requires special |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 2234 | // handling. |
Fariborz Jahanian | d09a456 | 2009-04-02 18:44:20 +0000 | [diff] [blame] | 2235 | if ((CCPrimary = CDecl->getClassInterface())) { |
| 2236 | // Find the property in continuation class's primary class only. |
Fariborz Jahanian | d09a456 | 2009-04-02 18:44:20 +0000 | [diff] [blame] | 2237 | IdentifierInfo *PropertyId = FD.D.getIdentifier(); |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 2238 | if (ObjCPropertyDecl *PIDecl = |
| 2239 | CCPrimary->FindPropertyVisibleInPrimaryClass(PropertyId)) { |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 2240 | // property 'PIDecl's readonly attribute will be over-ridden |
Fariborz Jahanian | 22b6e06 | 2009-04-01 23:23:53 +0000 | [diff] [blame] | 2241 | // with continuation class's readwrite property attribute! |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 2242 | unsigned PIkind = PIDecl->getPropertyAttributes(); |
| 2243 | if (isReadWrite && (PIkind & ObjCPropertyDecl::OBJC_PR_readonly)) { |
Fariborz Jahanian | 4770a4a | 2009-11-10 19:31:09 +0000 | [diff] [blame] | 2244 | unsigned retainCopyNonatomic = |
Fariborz Jahanian | d669be5 | 2009-11-06 22:59:12 +0000 | [diff] [blame] | 2245 | (ObjCPropertyDecl::OBJC_PR_retain | |
Fariborz Jahanian | cc667e2 | 2009-11-03 00:01:38 +0000 | [diff] [blame] | 2246 | ObjCPropertyDecl::OBJC_PR_copy | |
| 2247 | ObjCPropertyDecl::OBJC_PR_nonatomic); |
Fariborz Jahanian | 4770a4a | 2009-11-10 19:31:09 +0000 | [diff] [blame] | 2248 | if ((Attributes & retainCopyNonatomic) != |
| 2249 | (PIkind & retainCopyNonatomic)) { |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 2250 | Diag(AtLoc, diag::warn_property_attr_mismatch); |
Fariborz Jahanian | cc667e2 | 2009-11-03 00:01:38 +0000 | [diff] [blame] | 2251 | Diag(PIDecl->getLocation(), diag::note_property_declare); |
| 2252 | } |
Fariborz Jahanian | b73e281 | 2010-01-06 21:38:30 +0000 | [diff] [blame] | 2253 | DeclContext *DC = dyn_cast<DeclContext>(CCPrimary); |
| 2254 | assert(DC && "ClassDecl is not a DeclContext"); |
| 2255 | DeclContext::lookup_result Found = |
| 2256 | DC->lookup(PIDecl->getDeclName()); |
| 2257 | bool PropertyInPrimaryClass = false; |
| 2258 | for (; Found.first != Found.second; ++Found.first) |
| 2259 | if (isa<ObjCPropertyDecl>(*Found.first)) { |
| 2260 | PropertyInPrimaryClass = true; |
| 2261 | break; |
| 2262 | } |
| 2263 | if (!PropertyInPrimaryClass) { |
| 2264 | // Protocol is not in the primary class. Must build one for it. |
| 2265 | ObjCDeclSpec ProtocolPropertyODS; |
| 2266 | // FIXME. Assuming that ObjCDeclSpec::ObjCPropertyAttributeKind and |
| 2267 | // ObjCPropertyDecl::PropertyAttributeKind have identical values. |
| 2268 | // Should consolidate both into one enum type. |
| 2269 | ProtocolPropertyODS.setPropertyAttributes( |
| 2270 | (ObjCDeclSpec::ObjCPropertyAttributeKind)PIkind); |
| 2271 | DeclPtrTy ProtocolPtrTy = |
| 2272 | ActOnProperty(S, AtLoc, FD, ProtocolPropertyODS, |
| 2273 | PIDecl->getGetterName(), |
| 2274 | PIDecl->getSetterName(), |
| 2275 | DeclPtrTy::make(CCPrimary), isOverridingProperty, |
| 2276 | MethodImplKind); |
| 2277 | PIDecl = ProtocolPtrTy.getAs<ObjCPropertyDecl>(); |
| 2278 | } |
Fariborz Jahanian | d09a456 | 2009-04-02 18:44:20 +0000 | [diff] [blame] | 2279 | PIDecl->makeitReadWriteAttribute(); |
| 2280 | if (Attributes & ObjCDeclSpec::DQ_PR_retain) |
| 2281 | PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain); |
| 2282 | if (Attributes & ObjCDeclSpec::DQ_PR_copy) |
| 2283 | PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy); |
| 2284 | PIDecl->setSetterName(SetterSel); |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 2285 | } else { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2286 | Diag(AtLoc, diag::err_use_continuation_class) |
Fariborz Jahanian | d09a456 | 2009-04-02 18:44:20 +0000 | [diff] [blame] | 2287 | << CCPrimary->getDeclName(); |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 2288 | Diag(PIDecl->getLocation(), diag::note_property_declare); |
| 2289 | } |
Fariborz Jahanian | d09a456 | 2009-04-02 18:44:20 +0000 | [diff] [blame] | 2290 | *isOverridingProperty = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2291 | // Make sure setter decl is synthesized, and added to primary |
Fariborz Jahanian | 50c314c | 2009-04-15 19:19:03 +0000 | [diff] [blame] | 2292 | // class's list. |
| 2293 | ProcessPropertyDecl(PIDecl, CCPrimary); |
Fariborz Jahanian | d09a456 | 2009-04-02 18:44:20 +0000 | [diff] [blame] | 2294 | return DeclPtrTy(); |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 2295 | } |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 2296 | |
Fariborz Jahanian | d09a456 | 2009-04-02 18:44:20 +0000 | [diff] [blame] | 2297 | // No matching property found in the primary class. Just fall thru |
| 2298 | // and add property to continuation class's primary class. |
| 2299 | ClassDecl = CCPrimary; |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 2300 | } else { |
Chris Lattner | f25df99 | 2009-02-20 21:38:52 +0000 | [diff] [blame] | 2301 | Diag(CDecl->getLocation(), diag::err_continuation_class); |
| 2302 | *isOverridingProperty = true; |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2303 | return DeclPtrTy(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2304 | } |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 2305 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2306 | |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 2307 | // Issue a warning if property is 'assign' as default and its object, which is |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2308 | // gc'able conforms to NSCopying protocol |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 2309 | if (getLangOptions().getGCMode() != LangOptions::NonGC && |
| 2310 | isAssign && !(Attributes & ObjCDeclSpec::DQ_PR_assign)) |
| 2311 | if (T->isObjCObjectPointerType()) { |
| 2312 | QualType InterfaceTy = T->getPointeeType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2313 | if (const ObjCInterfaceType *OIT = |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 2314 | InterfaceTy->getAs<ObjCInterfaceType>()) { |
Fariborz Jahanian | b11d798 | 2009-08-14 18:06:25 +0000 | [diff] [blame] | 2315 | ObjCInterfaceDecl *IDecl = OIT->getDecl(); |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 2316 | if (IDecl) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2317 | if (ObjCProtocolDecl* PNSCopying = |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 2318 | LookupProtocol(&Context.Idents.get("NSCopying"))) |
| 2319 | if (IDecl->ClassImplementsProtocol(PNSCopying, true)) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2320 | Diag(AtLoc, diag::warn_implements_nscopying) |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 2321 | << FD.D.getIdentifier(); |
Fariborz Jahanian | b11d798 | 2009-08-14 18:06:25 +0000 | [diff] [blame] | 2322 | } |
Fariborz Jahanian | 0fd8904 | 2009-08-11 22:02:25 +0000 | [diff] [blame] | 2323 | } |
Fariborz Jahanian | acf2d13 | 2009-08-12 18:17:53 +0000 | [diff] [blame] | 2324 | if (T->isObjCInterfaceType()) |
| 2325 | Diag(FD.D.getIdentifierLoc(), diag::err_statically_allocated_object); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2326 | |
Steve Naroff | 93983f8 | 2009-01-11 12:47:58 +0000 | [diff] [blame] | 2327 | DeclContext *DC = dyn_cast<DeclContext>(ClassDecl); |
| 2328 | assert(DC && "ClassDecl is not a DeclContext"); |
Chris Lattner | d1e0f5a | 2009-04-11 20:14:49 +0000 | [diff] [blame] | 2329 | ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, DC, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2330 | FD.D.getIdentifierLoc(), |
Fariborz Jahanian | d050240 | 2010-01-21 17:36:00 +0000 | [diff] [blame] | 2331 | FD.D.getIdentifier(), |
| 2332 | AtLoc, T); |
Fariborz Jahanian | 6dd30fc | 2009-12-17 00:49:09 +0000 | [diff] [blame] | 2333 | DeclContext::lookup_result Found = DC->lookup(PDecl->getDeclName()); |
| 2334 | if (Found.first != Found.second && isa<ObjCPropertyDecl>(*Found.first)) { |
| 2335 | Diag(PDecl->getLocation(), diag::err_duplicate_property); |
| 2336 | Diag((*Found.first)->getLocation(), diag::note_property_declare); |
| 2337 | PDecl->setInvalidDecl(); |
| 2338 | } |
| 2339 | else |
| 2340 | DC->addDecl(PDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2341 | |
Chris Lattner | d1e0f5a | 2009-04-11 20:14:49 +0000 | [diff] [blame] | 2342 | if (T->isArrayType() || T->isFunctionType()) { |
| 2343 | Diag(AtLoc, diag::err_property_type) << T; |
| 2344 | PDecl->setInvalidDecl(); |
| 2345 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2346 | |
Douglas Gregor | 9cdda0c | 2009-06-17 21:51:59 +0000 | [diff] [blame] | 2347 | ProcessDeclAttributes(S, PDecl, FD.D); |
Douglas Gregor | d043410 | 2009-01-09 00:49:46 +0000 | [diff] [blame] | 2348 | |
Fariborz Jahanian | 33de3f0 | 2008-05-07 17:43:59 +0000 | [diff] [blame] | 2349 | // Regardless of setter/getter attribute, we save the default getter/setter |
| 2350 | // selector names in anticipation of declaration of setter/getter methods. |
| 2351 | PDecl->setGetterName(GetterSel); |
| 2352 | PDecl->setSetterName(SetterSel); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2353 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2354 | if (Attributes & ObjCDeclSpec::DQ_PR_readonly) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2355 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2356 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2357 | if (Attributes & ObjCDeclSpec::DQ_PR_getter) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2358 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_getter); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2359 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2360 | if (Attributes & ObjCDeclSpec::DQ_PR_setter) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2361 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_setter); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2362 | |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 2363 | if (isReadWrite) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2364 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2365 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2366 | if (Attributes & ObjCDeclSpec::DQ_PR_retain) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2367 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2368 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2369 | if (Attributes & ObjCDeclSpec::DQ_PR_copy) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2370 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2371 | |
Fariborz Jahanian | 8cf0bb3 | 2008-11-26 20:01:34 +0000 | [diff] [blame] | 2372 | if (isAssign) |
| 2373 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2374 | |
Daniel Dunbar | 95e61fb | 2008-09-23 21:53:23 +0000 | [diff] [blame] | 2375 | if (Attributes & ObjCDeclSpec::DQ_PR_nonatomic) |
Ted Kremenek | a526c5c | 2008-01-07 19:49:32 +0000 | [diff] [blame] | 2376 | PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2377 | |
Fariborz Jahanian | 46b55e5 | 2008-05-05 18:51:55 +0000 | [diff] [blame] | 2378 | if (MethodImplKind == tok::objc_required) |
| 2379 | PDecl->setPropertyImplementation(ObjCPropertyDecl::Required); |
| 2380 | else if (MethodImplKind == tok::objc_optional) |
| 2381 | PDecl->setPropertyImplementation(ObjCPropertyDecl::Optional); |
Fariborz Jahanian | d09a456 | 2009-04-02 18:44:20 +0000 | [diff] [blame] | 2382 | // A case of continuation class adding a new property in the class. This |
| 2383 | // is not what it was meant for. However, gcc supports it and so should we. |
| 2384 | // Make sure setter/getters are declared here. |
| 2385 | if (CCPrimary) |
| 2386 | ProcessPropertyDecl(PDecl, CCPrimary); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2387 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2388 | return DeclPtrTy::make(PDecl); |
Chris Lattner | 4d39148 | 2007-12-12 07:09:47 +0000 | [diff] [blame] | 2389 | } |
| 2390 | |
Fariborz Jahanian | 77e2dde | 2010-02-09 21:49:50 +0000 | [diff] [blame] | 2391 | ObjCIvarDecl* |
| 2392 | Sema::SynthesizeNewPropertyIvar(ObjCInterfaceDecl *IDecl, |
| 2393 | IdentifierInfo *NameII) { |
| 2394 | ObjCIvarDecl *Ivar = 0; |
| 2395 | ObjCPropertyDecl *Prop = LookupPropertyDecl(IDecl, NameII); |
| 2396 | if (Prop && !Prop->isInvalidDecl()) { |
| 2397 | DeclContext *EnclosingContext = cast_or_null<DeclContext>(IDecl); |
| 2398 | QualType PropType = Context.getCanonicalType(Prop->getType()); |
| 2399 | assert(EnclosingContext && |
| 2400 | "null DeclContext for synthesized ivar - SynthesizeNewPropertyIvar"); |
| 2401 | Ivar = ObjCIvarDecl::Create(Context, EnclosingContext, |
| 2402 | Prop->getLocation(), |
| 2403 | NameII, PropType, /*Dinfo=*/0, |
| 2404 | ObjCIvarDecl::Public, |
| 2405 | (Expr *)0); |
| 2406 | Ivar->setLexicalDeclContext(IDecl); |
| 2407 | IDecl->addDecl(Ivar); |
| 2408 | Prop->setPropertyIvarDecl(Ivar); |
| 2409 | } |
| 2410 | return Ivar; |
| 2411 | } |
| 2412 | |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 2413 | /// ActOnPropertyImplDecl - This routine performs semantic checks and |
| 2414 | /// builds the AST node for a property implementation declaration; declared |
| 2415 | /// as @synthesize or @dynamic. |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2416 | /// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2417 | Sema::DeclPtrTy Sema::ActOnPropertyImplDecl(SourceLocation AtLoc, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2418 | SourceLocation PropertyLoc, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2419 | bool Synthesize, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2420 | DeclPtrTy ClassCatImpDecl, |
| 2421 | IdentifierInfo *PropertyId, |
| 2422 | IdentifierInfo *PropertyIvar) { |
| 2423 | Decl *ClassImpDecl = ClassCatImpDecl.getAs<Decl>(); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2424 | // Make sure we have a context for the property implementation declaration. |
| 2425 | if (!ClassImpDecl) { |
| 2426 | Diag(AtLoc, diag::error_missing_property_context); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2427 | return DeclPtrTy(); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2428 | } |
| 2429 | ObjCPropertyDecl *property = 0; |
| 2430 | ObjCInterfaceDecl* IDecl = 0; |
| 2431 | // Find the class or category class where this property must have |
| 2432 | // a declaration. |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 2433 | ObjCImplementationDecl *IC = 0; |
| 2434 | ObjCCategoryImplDecl* CatImplClass = 0; |
| 2435 | if ((IC = dyn_cast<ObjCImplementationDecl>(ClassImpDecl))) { |
Douglas Gregor | 4afa39d | 2009-01-20 01:17:11 +0000 | [diff] [blame] | 2436 | IDecl = IC->getClassInterface(); |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 2437 | // We always synthesize an interface for an implementation |
| 2438 | // without an interface decl. So, IDecl is always non-zero. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2439 | assert(IDecl && |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 2440 | "ActOnPropertyImplDecl - @implementation without @interface"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2441 | |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2442 | // Look for this property declaration in the @implementation's @interface |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2443 | property = IDecl->FindPropertyDeclaration(PropertyId); |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 2444 | if (!property) { |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 2445 | Diag(PropertyLoc, diag::error_bad_property_decl) << IDecl->getDeclName(); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2446 | return DeclPtrTy(); |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 2447 | } |
Fariborz Jahanian | 3684bd4 | 2009-11-02 18:45:36 +0000 | [diff] [blame] | 2448 | if (const ObjCCategoryDecl *CD = |
| 2449 | dyn_cast<ObjCCategoryDecl>(property->getDeclContext())) { |
Fariborz Jahanian | 2576061 | 2010-02-15 21:55:26 +0000 | [diff] [blame] | 2450 | if (!CD->IsClassExtension()) { |
Fariborz Jahanian | 3684bd4 | 2009-11-02 18:45:36 +0000 | [diff] [blame] | 2451 | Diag(PropertyLoc, diag::error_category_property) << CD->getDeclName(); |
Fariborz Jahanian | a6f14e1 | 2009-11-02 22:45:15 +0000 | [diff] [blame] | 2452 | Diag(property->getLocation(), diag::note_property_declare); |
Fariborz Jahanian | 3684bd4 | 2009-11-02 18:45:36 +0000 | [diff] [blame] | 2453 | return DeclPtrTy(); |
| 2454 | } |
| 2455 | } |
Mike Stump | ac5fc7c | 2009-08-04 21:02:39 +0000 | [diff] [blame] | 2456 | } else if ((CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl))) { |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 2457 | if (Synthesize) { |
| 2458 | Diag(AtLoc, diag::error_synthesize_category_decl); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2459 | return DeclPtrTy(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2460 | } |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2461 | IDecl = CatImplClass->getClassInterface(); |
| 2462 | if (!IDecl) { |
| 2463 | Diag(AtLoc, diag::error_missing_property_interface); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2464 | return DeclPtrTy(); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2465 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2466 | ObjCCategoryDecl *Category = |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 2467 | IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2468 | |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2469 | // If category for this implementation not found, it is an error which |
| 2470 | // has already been reported eralier. |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 2471 | if (!Category) |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2472 | return DeclPtrTy(); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2473 | // Look for this property declaration in @implementation's category |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2474 | property = Category->FindPropertyDeclaration(PropertyId); |
Fariborz Jahanian | 559c0c4 | 2008-04-21 19:04:53 +0000 | [diff] [blame] | 2475 | if (!property) { |
Chris Lattner | 5dc266a | 2008-11-20 06:13:02 +0000 | [diff] [blame] | 2476 | Diag(PropertyLoc, diag::error_bad_category_property_decl) |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 2477 | << Category->getDeclName(); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2478 | return DeclPtrTy(); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2479 | } |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2480 | } else { |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2481 | Diag(AtLoc, diag::error_bad_property_context); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2482 | return DeclPtrTy(); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2483 | } |
Fariborz Jahanian | 628b96f | 2008-04-23 00:06:01 +0000 | [diff] [blame] | 2484 | ObjCIvarDecl *Ivar = 0; |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2485 | // Check that we have a valid, previously declared ivar for @synthesize |
| 2486 | if (Synthesize) { |
| 2487 | // @synthesize |
Fariborz Jahanian | 6cdf16d | 2008-04-21 21:57:36 +0000 | [diff] [blame] | 2488 | if (!PropertyIvar) |
| 2489 | PropertyIvar = PropertyId; |
Fariborz Jahanian | af3e722 | 2009-03-31 00:06:29 +0000 | [diff] [blame] | 2490 | QualType PropType = Context.getCanonicalType(property->getType()); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2491 | // Check that this is a previously declared 'ivar' in 'IDecl' interface |
Fariborz Jahanian | 29da66e | 2009-04-13 19:30:37 +0000 | [diff] [blame] | 2492 | ObjCInterfaceDecl *ClassDeclared; |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2493 | Ivar = IDecl->lookupInstanceVariable(PropertyIvar, ClassDeclared); |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 2494 | if (!Ivar) { |
Fariborz Jahanian | 8019a7b | 2009-06-06 16:36:41 +0000 | [diff] [blame] | 2495 | DeclContext *EnclosingContext = cast_or_null<DeclContext>(IDecl); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2496 | assert(EnclosingContext && |
Fariborz Jahanian | 8019a7b | 2009-06-06 16:36:41 +0000 | [diff] [blame] | 2497 | "null DeclContext for synthesized ivar - ActOnPropertyImplDecl"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2498 | Ivar = ObjCIvarDecl::Create(Context, EnclosingContext, PropertyLoc, |
| 2499 | PropertyIvar, PropType, /*Dinfo=*/0, |
Fariborz Jahanian | 12bac25 | 2009-04-14 23:15:21 +0000 | [diff] [blame] | 2500 | ObjCIvarDecl::Public, |
| 2501 | (Expr *)0); |
Fariborz Jahanian | 11062e1 | 2010-02-19 00:31:17 +0000 | [diff] [blame] | 2502 | IDecl->makeDeclVisibleInContext(Ivar, false); |
Fariborz Jahanian | 12bac25 | 2009-04-14 23:15:21 +0000 | [diff] [blame] | 2503 | property->setPropertyIvarDecl(Ivar); |
| 2504 | if (!getLangOptions().ObjCNonFragileABI) |
Steve Naroff | f4c00ff | 2009-03-03 22:09:41 +0000 | [diff] [blame] | 2505 | Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2506 | // Note! I deliberately want it to fall thru so, we have a |
Fariborz Jahanian | 12bac25 | 2009-04-14 23:15:21 +0000 | [diff] [blame] | 2507 | // a property implementation and to avoid future warnings. |
Mike Stump | ac5fc7c | 2009-08-04 21:02:39 +0000 | [diff] [blame] | 2508 | } else if (getLangOptions().ObjCNonFragileABI && |
| 2509 | ClassDeclared != IDecl) { |
Fariborz Jahanian | e2f2c16 | 2009-04-30 21:39:24 +0000 | [diff] [blame] | 2510 | Diag(PropertyLoc, diag::error_ivar_in_superclass_use) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2511 | << property->getDeclName() << Ivar->getDeclName() |
Fariborz Jahanian | 29da66e | 2009-04-13 19:30:37 +0000 | [diff] [blame] | 2512 | << ClassDeclared->getDeclName(); |
| 2513 | Diag(Ivar->getLocation(), diag::note_previous_access_declaration) |
| 2514 | << Ivar << Ivar->getNameAsCString(); |
| 2515 | // Note! I deliberately want it to fall thru so more errors are caught. |
| 2516 | } |
Steve Naroff | 3ce52d6 | 2008-09-30 10:07:56 +0000 | [diff] [blame] | 2517 | QualType IvarType = Context.getCanonicalType(Ivar->getType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2518 | |
Steve Naroff | fbbe0ac | 2008-09-30 00:24:17 +0000 | [diff] [blame] | 2519 | // Check that type of property and its ivar are type compatible. |
Steve Naroff | 3ce52d6 | 2008-09-30 10:07:56 +0000 | [diff] [blame] | 2520 | if (PropType != IvarType) { |
Steve Naroff | 4fa4ab6 | 2008-10-16 14:59:30 +0000 | [diff] [blame] | 2521 | if (CheckAssignmentConstraints(PropType, IvarType) != Compatible) { |
Chris Lattner | 5dc266a | 2008-11-20 06:13:02 +0000 | [diff] [blame] | 2522 | Diag(PropertyLoc, diag::error_property_ivar_type) |
Chris Lattner | d9d22dd | 2008-11-24 05:29:24 +0000 | [diff] [blame] | 2523 | << property->getDeclName() << Ivar->getDeclName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2524 | // Note! I deliberately want it to fall thru so, we have a |
Fariborz Jahanian | 12bac25 | 2009-04-14 23:15:21 +0000 | [diff] [blame] | 2525 | // a property implementation and to avoid future warnings. |
Steve Naroff | 3ce52d6 | 2008-09-30 10:07:56 +0000 | [diff] [blame] | 2526 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2527 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2528 | // FIXME! Rules for properties are somewhat different that those |
| 2529 | // for assignments. Use a new routine to consolidate all cases; |
| 2530 | // specifically for property redeclarations as well as for ivars. |
| 2531 | QualType lhsType =Context.getCanonicalType(PropType).getUnqualifiedType(); |
| 2532 | QualType rhsType =Context.getCanonicalType(IvarType).getUnqualifiedType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2533 | if (lhsType != rhsType && |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2534 | lhsType->isArithmeticType()) { |
| 2535 | Diag(PropertyLoc, diag::error_property_ivar_type) |
| 2536 | << property->getDeclName() << Ivar->getDeclName(); |
Fariborz Jahanian | 12bac25 | 2009-04-14 23:15:21 +0000 | [diff] [blame] | 2537 | // Fall thru - see previous comment |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2538 | } |
| 2539 | // __weak is explicit. So it works on Canonical type. |
Fariborz Jahanian | c8bafd7 | 2009-04-07 21:25:06 +0000 | [diff] [blame] | 2540 | if (PropType.isObjCGCWeak() && !IvarType.isObjCGCWeak() && |
| 2541 | getLangOptions().getGCMode() != LangOptions::NonGC) { |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2542 | Diag(PropertyLoc, diag::error_weak_property) |
| 2543 | << property->getDeclName() << Ivar->getDeclName(); |
Fariborz Jahanian | 12bac25 | 2009-04-14 23:15:21 +0000 | [diff] [blame] | 2544 | // Fall thru - see previous comment |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2545 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2546 | if ((property->getType()->isObjCObjectPointerType() || |
Fariborz Jahanian | 0a9217f | 2009-04-10 22:42:54 +0000 | [diff] [blame] | 2547 | PropType.isObjCGCStrong()) && IvarType.isObjCGCWeak() && |
| 2548 | getLangOptions().getGCMode() != LangOptions::NonGC) { |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2549 | Diag(PropertyLoc, diag::error_strong_property) |
| 2550 | << property->getDeclName() << Ivar->getDeclName(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2551 | // Fall thru - see previous comment |
Fariborz Jahanian | acdc33b | 2009-01-19 20:13:47 +0000 | [diff] [blame] | 2552 | } |
Fariborz Jahanian | c35b9e4 | 2008-04-21 21:05:54 +0000 | [diff] [blame] | 2553 | } |
Fariborz Jahanian | 12bac25 | 2009-04-14 23:15:21 +0000 | [diff] [blame] | 2554 | } else if (PropertyIvar) |
| 2555 | // @dynamic |
| 2556 | Diag(PropertyLoc, diag::error_dynamic_property_ivar_decl); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2557 | assert (property && "ActOnPropertyImplDecl - property declaration missing"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2558 | ObjCPropertyImplDecl *PIDecl = |
| 2559 | ObjCPropertyImplDecl::Create(Context, CurContext, AtLoc, PropertyLoc, |
| 2560 | property, |
| 2561 | (Synthesize ? |
| 2562 | ObjCPropertyImplDecl::Synthesize |
Daniel Dunbar | 9f0afd4 | 2008-08-26 04:47:31 +0000 | [diff] [blame] | 2563 | : ObjCPropertyImplDecl::Dynamic), |
| 2564 | Ivar); |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 2565 | if (IC) { |
| 2566 | if (Synthesize) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2567 | if (ObjCPropertyImplDecl *PPIDecl = |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2568 | IC->FindPropertyImplIvarDecl(PropertyIvar)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2569 | Diag(PropertyLoc, diag::error_duplicate_ivar_use) |
| 2570 | << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier() |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 2571 | << PropertyIvar; |
| 2572 | Diag(PPIDecl->getLocation(), diag::note_previous_use); |
| 2573 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2574 | |
| 2575 | if (ObjCPropertyImplDecl *PPIDecl |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2576 | = IC->FindPropertyImplDecl(PropertyId)) { |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 2577 | Diag(PropertyLoc, diag::error_property_implemented) << PropertyId; |
| 2578 | Diag(PPIDecl->getLocation(), diag::note_previous_declaration); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2579 | return DeclPtrTy(); |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 2580 | } |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2581 | IC->addPropertyImplementation(PIDecl); |
Mike Stump | ac5fc7c | 2009-08-04 21:02:39 +0000 | [diff] [blame] | 2582 | } else { |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 2583 | if (Synthesize) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2584 | if (ObjCPropertyImplDecl *PPIDecl = |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2585 | CatImplClass->FindPropertyImplIvarDecl(PropertyIvar)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2586 | Diag(PropertyLoc, diag::error_duplicate_ivar_use) |
| 2587 | << PropertyId << PPIDecl->getPropertyDecl()->getIdentifier() |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 2588 | << PropertyIvar; |
| 2589 | Diag(PPIDecl->getLocation(), diag::note_previous_use); |
| 2590 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2591 | |
| 2592 | if (ObjCPropertyImplDecl *PPIDecl = |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2593 | CatImplClass->FindPropertyImplDecl(PropertyId)) { |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 2594 | Diag(PropertyLoc, diag::error_property_implemented) << PropertyId; |
| 2595 | Diag(PPIDecl->getLocation(), diag::note_previous_declaration); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2596 | return DeclPtrTy(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2597 | } |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2598 | CatImplClass->addPropertyImplementation(PIDecl); |
Fariborz Jahanian | ae6f6fd | 2008-12-05 22:32:48 +0000 | [diff] [blame] | 2599 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2600 | |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2601 | return DeclPtrTy::make(PIDecl); |
Fariborz Jahanian | f624f81 | 2008-04-18 00:19:30 +0000 | [diff] [blame] | 2602 | } |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 2603 | |
Chris Lattner | cc98eac | 2008-12-17 07:13:27 +0000 | [diff] [blame] | 2604 | bool Sema::CheckObjCDeclScope(Decl *D) { |
Douglas Gregor | ce35607 | 2009-01-06 23:51:29 +0000 | [diff] [blame] | 2605 | if (isa<TranslationUnitDecl>(CurContext->getLookupContext())) |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 2606 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2607 | |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 2608 | Diag(D->getLocation(), diag::err_objc_decls_may_only_appear_in_global_scope); |
| 2609 | D->setInvalidDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2610 | |
Anders Carlsson | 1528145 | 2008-11-04 16:57:32 +0000 | [diff] [blame] | 2611 | return true; |
| 2612 | } |
Chris Lattner | cc98eac | 2008-12-17 07:13:27 +0000 | [diff] [blame] | 2613 | |
Chris Lattner | cc98eac | 2008-12-17 07:13:27 +0000 | [diff] [blame] | 2614 | /// Called whenever @defs(ClassName) is encountered in the source. Inserts the |
| 2615 | /// instance variables of ClassName into Decls. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2616 | void Sema::ActOnDefs(Scope *S, DeclPtrTy TagD, SourceLocation DeclStart, |
Chris Lattner | cc98eac | 2008-12-17 07:13:27 +0000 | [diff] [blame] | 2617 | IdentifierInfo *ClassName, |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2618 | llvm::SmallVectorImpl<DeclPtrTy> &Decls) { |
Chris Lattner | cc98eac | 2008-12-17 07:13:27 +0000 | [diff] [blame] | 2619 | // Check that ClassName is a valid class |
| 2620 | ObjCInterfaceDecl *Class = getObjCInterfaceDecl(ClassName); |
| 2621 | if (!Class) { |
| 2622 | Diag(DeclStart, diag::err_undef_interface) << ClassName; |
| 2623 | return; |
| 2624 | } |
Fariborz Jahanian | 0468fb9 | 2009-04-21 20:28:41 +0000 | [diff] [blame] | 2625 | if (LangOpts.ObjCNonFragileABI) { |
| 2626 | Diag(DeclStart, diag::err_atdef_nonfragile_interface); |
| 2627 | return; |
| 2628 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2629 | |
Chris Lattner | cc98eac | 2008-12-17 07:13:27 +0000 | [diff] [blame] | 2630 | // Collect the instance variables |
Fariborz Jahanian | 4183335 | 2009-06-04 17:08:55 +0000 | [diff] [blame] | 2631 | llvm::SmallVector<FieldDecl*, 32> RecFields; |
| 2632 | Context.CollectObjCIvars(Class, RecFields); |
| 2633 | // For each ivar, create a fresh ObjCAtDefsFieldDecl. |
| 2634 | for (unsigned i = 0; i < RecFields.size(); i++) { |
| 2635 | FieldDecl* ID = RecFields[i]; |
| 2636 | RecordDecl *Record = dyn_cast<RecordDecl>(TagD.getAs<Decl>()); |
| 2637 | Decl *FD = ObjCAtDefsFieldDecl::Create(Context, Record, ID->getLocation(), |
| 2638 | ID->getIdentifier(), ID->getType(), |
| 2639 | ID->getBitWidth()); |
| 2640 | Decls.push_back(Sema::DeclPtrTy::make(FD)); |
| 2641 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2642 | |
Chris Lattner | cc98eac | 2008-12-17 07:13:27 +0000 | [diff] [blame] | 2643 | // Introduce all of these fields into the appropriate scope. |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2644 | for (llvm::SmallVectorImpl<DeclPtrTy>::iterator D = Decls.begin(); |
Chris Lattner | cc98eac | 2008-12-17 07:13:27 +0000 | [diff] [blame] | 2645 | D != Decls.end(); ++D) { |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2646 | FieldDecl *FD = cast<FieldDecl>(D->getAs<Decl>()); |
Chris Lattner | cc98eac | 2008-12-17 07:13:27 +0000 | [diff] [blame] | 2647 | if (getLangOptions().CPlusPlus) |
| 2648 | PushOnScopeChains(cast<FieldDecl>(FD), S); |
Chris Lattner | b28317a | 2009-03-28 19:18:32 +0000 | [diff] [blame] | 2649 | else if (RecordDecl *Record = dyn_cast<RecordDecl>(TagD.getAs<Decl>())) |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 2650 | Record->addDecl(FD); |
Chris Lattner | cc98eac | 2008-12-17 07:13:27 +0000 | [diff] [blame] | 2651 | } |
| 2652 | } |
| 2653 | |