blob: a6902a3e391c8a15246525aec9d8751b1e4caee5 [file] [log] [blame]
Chris Lattner4d391482007-12-12 07:09:47 +00001//===--- SemaDeclObjC.cpp - Semantic Analysis for ObjC Declarations -------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner4d391482007-12-12 07:09:47 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements semantic analysis for Objective C declarations.
11//
12//===----------------------------------------------------------------------===//
13
John McCall2d887082010-08-25 22:03:47 +000014#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000015#include "clang/Sema/Lookup.h"
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +000016#include "clang/Sema/ExternalSemaSource.h"
John McCall5f1e0942010-08-24 08:50:51 +000017#include "clang/Sema/Scope.h"
John McCall781472f2010-08-25 08:40:02 +000018#include "clang/Sema/ScopeInfo.h"
Steve Naroffca331292009-03-03 14:49:36 +000019#include "clang/AST/Expr.h"
Chris Lattner4d391482007-12-12 07:09:47 +000020#include "clang/AST/ASTContext.h"
21#include "clang/AST/DeclObjC.h"
John McCall19510852010-08-20 18:27:03 +000022#include "clang/Sema/DeclSpec.h"
John McCall50df6ae2010-08-25 07:03:20 +000023#include "llvm/ADT/DenseSet.h"
24
Chris Lattner4d391482007-12-12 07:09:47 +000025using namespace clang;
26
Steve Naroffebf64432009-02-28 16:59:13 +000027/// ActOnStartOfObjCMethodDef - This routine sets up parameters; invisible
Chris Lattner4d391482007-12-12 07:09:47 +000028/// and user declared, in the method definition's AST.
John McCalld226f652010-08-21 09:40:31 +000029void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
Argyrios Kyrtzidis53d0ea52008-06-28 06:07:14 +000030 assert(getCurMethodDecl() == 0 && "Method parsing confused");
John McCalld226f652010-08-21 09:40:31 +000031 ObjCMethodDecl *MDecl = dyn_cast_or_null<ObjCMethodDecl>(D);
Mike Stump1eb44332009-09-09 15:08:12 +000032
Steve Naroff394f3f42008-07-25 17:57:26 +000033 // If we don't have a valid method decl, simply return.
34 if (!MDecl)
35 return;
Steve Naroffa56f6162007-12-18 01:30:32 +000036
37 // Allow the rest of sema to find private method decl implementations.
Douglas Gregorf8d49f62009-01-09 17:18:27 +000038 if (MDecl->isInstanceMethod())
Fariborz Jahanian3fe10412010-07-22 18:24:20 +000039 AddInstanceMethodToGlobalPool(MDecl, true);
Steve Naroffa56f6162007-12-18 01:30:32 +000040 else
Fariborz Jahanian3fe10412010-07-22 18:24:20 +000041 AddFactoryMethodToGlobalPool(MDecl, true);
42
Chris Lattner4d391482007-12-12 07:09:47 +000043 // Allow all of Sema to see that we are entering a method definition.
Douglas Gregor44b43212008-12-11 16:49:14 +000044 PushDeclContext(FnBodyScope, MDecl);
Douglas Gregor9ea9bdb2010-03-01 23:15:13 +000045 PushFunctionScope();
46
Chris Lattner4d391482007-12-12 07:09:47 +000047 // Create Decl objects for each parameter, entrring them in the scope for
48 // binding to their use.
Chris Lattner4d391482007-12-12 07:09:47 +000049
50 // Insert the invisible arguments, self and _cmd!
Fariborz Jahanianfef30b52008-12-09 20:23:04 +000051 MDecl->createImplicitParams(Context, MDecl->getClassInterface());
Mike Stump1eb44332009-09-09 15:08:12 +000052
Daniel Dunbar451318c2008-08-26 06:07:48 +000053 PushOnScopeChains(MDecl->getSelfDecl(), FnBodyScope);
54 PushOnScopeChains(MDecl->getCmdDecl(), FnBodyScope);
Chris Lattner04421082008-04-08 04:40:51 +000055
Chris Lattner8123a952008-04-10 02:22:51 +000056 // Introduce all of the other parameters into this scope.
Chris Lattner89951a82009-02-20 18:43:26 +000057 for (ObjCMethodDecl::param_iterator PI = MDecl->param_begin(),
58 E = MDecl->param_end(); PI != E; ++PI)
59 if ((*PI)->getIdentifier())
60 PushOnScopeChains(*PI, FnBodyScope);
Chris Lattner4d391482007-12-12 07:09:47 +000061}
62
John McCalld226f652010-08-21 09:40:31 +000063Decl *Sema::
Chris Lattner7caeabd2008-07-21 22:17:28 +000064ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
65 IdentifierInfo *ClassName, SourceLocation ClassLoc,
66 IdentifierInfo *SuperName, SourceLocation SuperLoc,
John McCalld226f652010-08-21 09:40:31 +000067 Decl * const *ProtoRefs, unsigned NumProtoRefs,
Douglas Gregor18df52b2010-01-16 15:02:53 +000068 const SourceLocation *ProtoLocs,
Chris Lattner7caeabd2008-07-21 22:17:28 +000069 SourceLocation EndProtoLoc, AttributeList *AttrList) {
Chris Lattner4d391482007-12-12 07:09:47 +000070 assert(ClassName && "Missing class identifier");
Mike Stump1eb44332009-09-09 15:08:12 +000071
Chris Lattner4d391482007-12-12 07:09:47 +000072 // Check for another declaration kind with the same name.
Douglas Gregorc83c6872010-04-15 22:33:43 +000073 NamedDecl *PrevDecl = LookupSingleName(TUScope, ClassName, ClassLoc,
Douglas Gregorc0b39642010-04-15 23:40:53 +000074 LookupOrdinaryName, ForRedeclaration);
Douglas Gregor72c3f312008-12-05 18:15:24 +000075
Ted Kremeneka526c5c2008-01-07 19:49:32 +000076 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
Chris Lattner3c73c412008-11-19 08:23:25 +000077 Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
Chris Lattner5f4a6822008-11-23 23:12:31 +000078 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
Chris Lattner4d391482007-12-12 07:09:47 +000079 }
Mike Stump1eb44332009-09-09 15:08:12 +000080
Douglas Gregordeacbdc2010-08-11 12:19:30 +000081 ObjCInterfaceDecl* IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
82 if (IDecl) {
Chris Lattner4d391482007-12-12 07:09:47 +000083 // Class already seen. Is it a forward declaration?
Douglas Gregordeacbdc2010-08-11 12:19:30 +000084 if (!IDecl->isForwardDecl()) {
85 IDecl->setInvalidDecl();
86 Diag(AtInterfaceLoc, diag::err_duplicate_class_def)<<IDecl->getDeclName();
87 Diag(IDecl->getLocation(), diag::note_previous_definition);
Chris Lattnerb8b96af2008-11-23 22:46:27 +000088
Douglas Gregordeacbdc2010-08-11 12:19:30 +000089 // Return the previous class interface.
90 // FIXME: don't leak the objects passed in!
John McCalld226f652010-08-21 09:40:31 +000091 return IDecl;
Douglas Gregordeacbdc2010-08-11 12:19:30 +000092 } else {
93 IDecl->setLocation(AtInterfaceLoc);
94 IDecl->setForwardDecl(false);
95 IDecl->setClassLoc(ClassLoc);
Sebastian Redl0b17c612010-08-13 00:28:03 +000096 // If the forward decl was in a PCH, we need to write it again in a
Sebastian Redl3c7f4132010-08-18 23:57:06 +000097 // dependent AST file.
Sebastian Redl0b17c612010-08-13 00:28:03 +000098 IDecl->setChangedSinceDeserialization(true);
Douglas Gregordeacbdc2010-08-11 12:19:30 +000099
100 // Since this ObjCInterfaceDecl was created by a forward declaration,
101 // we now add it to the DeclContext since it wasn't added before
102 // (see ActOnForwardClassDeclaration).
103 IDecl->setLexicalDeclContext(CurContext);
104 CurContext->addDecl(IDecl);
105
106 if (AttrList)
107 ProcessDeclAttributeList(TUScope, IDecl, AttrList);
Chris Lattner4d391482007-12-12 07:09:47 +0000108 }
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000109 } else {
110 IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtInterfaceLoc,
111 ClassName, ClassLoc);
112 if (AttrList)
113 ProcessDeclAttributeList(TUScope, IDecl, AttrList);
114
115 PushOnScopeChains(IDecl, TUScope);
Chris Lattner4d391482007-12-12 07:09:47 +0000116 }
Mike Stump1eb44332009-09-09 15:08:12 +0000117
Chris Lattner4d391482007-12-12 07:09:47 +0000118 if (SuperName) {
Chris Lattner4d391482007-12-12 07:09:47 +0000119 // Check if a different kind of symbol declared in this scope.
Douglas Gregorc83c6872010-04-15 22:33:43 +0000120 PrevDecl = LookupSingleName(TUScope, SuperName, SuperLoc,
121 LookupOrdinaryName);
Douglas Gregorf06cdae2010-01-03 18:01:57 +0000122
123 if (!PrevDecl) {
124 // Try to correct for a typo in the superclass name.
125 LookupResult R(*this, SuperName, SuperLoc, LookupOrdinaryName);
Douglas Gregoraaf87162010-04-14 20:04:41 +0000126 if (CorrectTypo(R, TUScope, 0, 0, false, CTC_NoKeywords) &&
Douglas Gregorf06cdae2010-01-03 18:01:57 +0000127 (PrevDecl = R.getAsSingle<ObjCInterfaceDecl>())) {
128 Diag(SuperLoc, diag::err_undef_superclass_suggest)
129 << SuperName << ClassName << PrevDecl->getDeclName();
Douglas Gregor67dd1d42010-01-07 00:17:44 +0000130 Diag(PrevDecl->getLocation(), diag::note_previous_decl)
131 << PrevDecl->getDeclName();
Douglas Gregorf06cdae2010-01-03 18:01:57 +0000132 }
133 }
134
Fariborz Jahanianfdee0892009-07-09 22:08:26 +0000135 if (PrevDecl == IDecl) {
136 Diag(SuperLoc, diag::err_recursive_superclass)
137 << SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc);
138 IDecl->setLocEnd(ClassLoc);
Mike Stumpac5fc7c2009-08-04 21:02:39 +0000139 } else {
Mike Stump1eb44332009-09-09 15:08:12 +0000140 ObjCInterfaceDecl *SuperClassDecl =
Fariborz Jahanianfdee0892009-07-09 22:08:26 +0000141 dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
Chris Lattner3c73c412008-11-19 08:23:25 +0000142
Fariborz Jahanianfdee0892009-07-09 22:08:26 +0000143 // Diagnose classes that inherit from deprecated classes.
144 if (SuperClassDecl)
145 (void)DiagnoseUseOfDecl(SuperClassDecl, SuperLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000146
Fariborz Jahanianfdee0892009-07-09 22:08:26 +0000147 if (PrevDecl && SuperClassDecl == 0) {
148 // The previous declaration was not a class decl. Check if we have a
149 // typedef. If we do, get the underlying class type.
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000150 if (const TypedefDecl *TDecl = dyn_cast_or_null<TypedefDecl>(PrevDecl)) {
Fariborz Jahanianfdee0892009-07-09 22:08:26 +0000151 QualType T = TDecl->getUnderlyingType();
John McCallc12c5bb2010-05-15 11:32:37 +0000152 if (T->isObjCObjectType()) {
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000153 if (NamedDecl *IDecl = T->getAs<ObjCObjectType>()->getInterface())
154 SuperClassDecl = dyn_cast<ObjCInterfaceDecl>(IDecl);
Fariborz Jahanianfdee0892009-07-09 22:08:26 +0000155 }
156 }
Mike Stump1eb44332009-09-09 15:08:12 +0000157
Fariborz Jahanianfdee0892009-07-09 22:08:26 +0000158 // This handles the following case:
159 //
160 // typedef int SuperClass;
161 // @interface MyClass : SuperClass {} @end
162 //
163 if (!SuperClassDecl) {
164 Diag(SuperLoc, diag::err_redefinition_different_kind) << SuperName;
165 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
Steve Naroff818cb9e2009-02-04 17:14:05 +0000166 }
167 }
Mike Stump1eb44332009-09-09 15:08:12 +0000168
Fariborz Jahanianfdee0892009-07-09 22:08:26 +0000169 if (!dyn_cast_or_null<TypedefDecl>(PrevDecl)) {
170 if (!SuperClassDecl)
171 Diag(SuperLoc, diag::err_undef_superclass)
172 << SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc);
173 else if (SuperClassDecl->isForwardDecl())
174 Diag(SuperLoc, diag::err_undef_superclass)
175 << SuperClassDecl->getDeclName() << ClassName
176 << SourceRange(AtInterfaceLoc, ClassLoc);
Steve Naroff818cb9e2009-02-04 17:14:05 +0000177 }
Fariborz Jahanianfdee0892009-07-09 22:08:26 +0000178 IDecl->setSuperClass(SuperClassDecl);
179 IDecl->setSuperClassLoc(SuperLoc);
180 IDecl->setLocEnd(SuperLoc);
Steve Naroff818cb9e2009-02-04 17:14:05 +0000181 }
Chris Lattner4d391482007-12-12 07:09:47 +0000182 } else { // we have a root class.
183 IDecl->setLocEnd(ClassLoc);
184 }
Mike Stump1eb44332009-09-09 15:08:12 +0000185
Sebastian Redl0b17c612010-08-13 00:28:03 +0000186 // Check then save referenced protocols.
Chris Lattner06036d32008-07-26 04:13:19 +0000187 if (NumProtoRefs) {
Chris Lattner38af2de2009-02-20 21:35:13 +0000188 IDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs,
Douglas Gregor18df52b2010-01-16 15:02:53 +0000189 ProtoLocs, Context);
Chris Lattner4d391482007-12-12 07:09:47 +0000190 IDecl->setLocEnd(EndProtoLoc);
191 }
Mike Stump1eb44332009-09-09 15:08:12 +0000192
Anders Carlsson15281452008-11-04 16:57:32 +0000193 CheckObjCDeclScope(IDecl);
John McCalld226f652010-08-21 09:40:31 +0000194 return IDecl;
Chris Lattner4d391482007-12-12 07:09:47 +0000195}
196
197/// ActOnCompatiblityAlias - this action is called after complete parsing of
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000198/// @compatibility_alias declaration. It sets up the alias relationships.
John McCalld226f652010-08-21 09:40:31 +0000199Decl *Sema::ActOnCompatiblityAlias(SourceLocation AtLoc,
200 IdentifierInfo *AliasName,
201 SourceLocation AliasLocation,
202 IdentifierInfo *ClassName,
203 SourceLocation ClassLocation) {
Chris Lattner4d391482007-12-12 07:09:47 +0000204 // Look for previous declaration of alias name
Douglas Gregorc83c6872010-04-15 22:33:43 +0000205 NamedDecl *ADecl = LookupSingleName(TUScope, AliasName, AliasLocation,
Douglas Gregorc0b39642010-04-15 23:40:53 +0000206 LookupOrdinaryName, ForRedeclaration);
Chris Lattner4d391482007-12-12 07:09:47 +0000207 if (ADecl) {
Chris Lattner8b265bd2008-11-23 23:20:13 +0000208 if (isa<ObjCCompatibleAliasDecl>(ADecl))
Chris Lattner4d391482007-12-12 07:09:47 +0000209 Diag(AliasLocation, diag::warn_previous_alias_decl);
Chris Lattner8b265bd2008-11-23 23:20:13 +0000210 else
Chris Lattner3c73c412008-11-19 08:23:25 +0000211 Diag(AliasLocation, diag::err_conflicting_aliasing_type) << AliasName;
Chris Lattner8b265bd2008-11-23 23:20:13 +0000212 Diag(ADecl->getLocation(), diag::note_previous_declaration);
John McCalld226f652010-08-21 09:40:31 +0000213 return 0;
Chris Lattner4d391482007-12-12 07:09:47 +0000214 }
215 // Check for class declaration
Douglas Gregorc83c6872010-04-15 22:33:43 +0000216 NamedDecl *CDeclU = LookupSingleName(TUScope, ClassName, ClassLocation,
Douglas Gregorc0b39642010-04-15 23:40:53 +0000217 LookupOrdinaryName, ForRedeclaration);
Fariborz Jahanian305c6582009-01-08 01:10:55 +0000218 if (const TypedefDecl *TDecl = dyn_cast_or_null<TypedefDecl>(CDeclU)) {
219 QualType T = TDecl->getUnderlyingType();
John McCallc12c5bb2010-05-15 11:32:37 +0000220 if (T->isObjCObjectType()) {
221 if (NamedDecl *IDecl = T->getAs<ObjCObjectType>()->getInterface()) {
Fariborz Jahanian305c6582009-01-08 01:10:55 +0000222 ClassName = IDecl->getIdentifier();
Douglas Gregorc83c6872010-04-15 22:33:43 +0000223 CDeclU = LookupSingleName(TUScope, ClassName, ClassLocation,
Douglas Gregorc0b39642010-04-15 23:40:53 +0000224 LookupOrdinaryName, ForRedeclaration);
Fariborz Jahanian305c6582009-01-08 01:10:55 +0000225 }
226 }
227 }
Chris Lattnerf8d17a52008-03-16 21:17:37 +0000228 ObjCInterfaceDecl *CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDeclU);
229 if (CDecl == 0) {
Chris Lattner3c73c412008-11-19 08:23:25 +0000230 Diag(ClassLocation, diag::warn_undef_interface) << ClassName;
Chris Lattnerf8d17a52008-03-16 21:17:37 +0000231 if (CDeclU)
Chris Lattner8b265bd2008-11-23 23:20:13 +0000232 Diag(CDeclU->getLocation(), diag::note_previous_declaration);
John McCalld226f652010-08-21 09:40:31 +0000233 return 0;
Chris Lattner4d391482007-12-12 07:09:47 +0000234 }
Mike Stump1eb44332009-09-09 15:08:12 +0000235
Chris Lattnerf8d17a52008-03-16 21:17:37 +0000236 // Everything checked out, instantiate a new alias declaration AST.
Mike Stump1eb44332009-09-09 15:08:12 +0000237 ObjCCompatibleAliasDecl *AliasDecl =
Douglas Gregord0434102009-01-09 00:49:46 +0000238 ObjCCompatibleAliasDecl::Create(Context, CurContext, AtLoc, AliasName, CDecl);
Mike Stump1eb44332009-09-09 15:08:12 +0000239
Anders Carlsson15281452008-11-04 16:57:32 +0000240 if (!CheckObjCDeclScope(AliasDecl))
Douglas Gregor516ff432009-04-24 02:57:34 +0000241 PushOnScopeChains(AliasDecl, TUScope);
Douglas Gregord0434102009-01-09 00:49:46 +0000242
John McCalld226f652010-08-21 09:40:31 +0000243 return AliasDecl;
Chris Lattner4d391482007-12-12 07:09:47 +0000244}
245
Steve Naroff61d68522009-03-05 15:22:01 +0000246void Sema::CheckForwardProtocolDeclarationForCircularDependency(
247 IdentifierInfo *PName,
248 SourceLocation &Ploc, SourceLocation PrevLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000249 const ObjCList<ObjCProtocolDecl> &PList) {
Steve Naroff61d68522009-03-05 15:22:01 +0000250 for (ObjCList<ObjCProtocolDecl>::iterator I = PList.begin(),
251 E = PList.end(); I != E; ++I) {
Mike Stump1eb44332009-09-09 15:08:12 +0000252
Douglas Gregorc83c6872010-04-15 22:33:43 +0000253 if (ObjCProtocolDecl *PDecl = LookupProtocol((*I)->getIdentifier(),
254 Ploc)) {
Steve Naroff61d68522009-03-05 15:22:01 +0000255 if (PDecl->getIdentifier() == PName) {
256 Diag(Ploc, diag::err_protocol_has_circular_dependency);
257 Diag(PrevLoc, diag::note_previous_definition);
258 }
Mike Stump1eb44332009-09-09 15:08:12 +0000259 CheckForwardProtocolDeclarationForCircularDependency(PName, Ploc,
Steve Naroff61d68522009-03-05 15:22:01 +0000260 PDecl->getLocation(), PDecl->getReferencedProtocols());
261 }
262 }
263}
264
John McCalld226f652010-08-21 09:40:31 +0000265Decl *
Chris Lattnere13b9592008-07-26 04:03:38 +0000266Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc,
267 IdentifierInfo *ProtocolName,
268 SourceLocation ProtocolLoc,
John McCalld226f652010-08-21 09:40:31 +0000269 Decl * const *ProtoRefs,
Chris Lattnere13b9592008-07-26 04:03:38 +0000270 unsigned NumProtoRefs,
Douglas Gregor18df52b2010-01-16 15:02:53 +0000271 const SourceLocation *ProtoLocs,
Daniel Dunbar246e70f2008-09-26 04:48:09 +0000272 SourceLocation EndProtoLoc,
273 AttributeList *AttrList) {
274 // FIXME: Deal with AttrList.
Chris Lattner4d391482007-12-12 07:09:47 +0000275 assert(ProtocolName && "Missing protocol identifier");
Douglas Gregorc83c6872010-04-15 22:33:43 +0000276 ObjCProtocolDecl *PDecl = LookupProtocol(ProtocolName, ProtocolLoc);
Chris Lattner4d391482007-12-12 07:09:47 +0000277 if (PDecl) {
278 // Protocol already seen. Better be a forward protocol declaration
Chris Lattner439e71f2008-03-16 01:25:17 +0000279 if (!PDecl->isForwardDecl()) {
Fariborz Jahaniane2573e52009-04-06 23:43:32 +0000280 Diag(ProtocolLoc, diag::warn_duplicate_protocol_def) << ProtocolName;
Chris Lattnerb8b96af2008-11-23 22:46:27 +0000281 Diag(PDecl->getLocation(), diag::note_previous_definition);
Chris Lattner439e71f2008-03-16 01:25:17 +0000282 // Just return the protocol we already had.
283 // FIXME: don't leak the objects passed in!
John McCalld226f652010-08-21 09:40:31 +0000284 return PDecl;
Chris Lattner4d391482007-12-12 07:09:47 +0000285 }
Steve Naroff61d68522009-03-05 15:22:01 +0000286 ObjCList<ObjCProtocolDecl> PList;
Mike Stump1eb44332009-09-09 15:08:12 +0000287 PList.set((ObjCProtocolDecl *const*)ProtoRefs, NumProtoRefs, Context);
Steve Naroff61d68522009-03-05 15:22:01 +0000288 CheckForwardProtocolDeclarationForCircularDependency(
289 ProtocolName, ProtocolLoc, PDecl->getLocation(), PList);
Mike Stump1eb44332009-09-09 15:08:12 +0000290
Steve Narofff11b5082008-08-13 16:39:22 +0000291 // Make sure the cached decl gets a valid start location.
292 PDecl->setLocation(AtProtoInterfaceLoc);
Chris Lattner439e71f2008-03-16 01:25:17 +0000293 PDecl->setForwardDecl(false);
Sebastian Redl0b17c612010-08-13 00:28:03 +0000294 CurContext->addDecl(PDecl);
Sebastian Redl3c7f4132010-08-18 23:57:06 +0000295 // Repeat in dependent AST files.
Sebastian Redl0b17c612010-08-13 00:28:03 +0000296 PDecl->setChangedSinceDeserialization(true);
Chris Lattner439e71f2008-03-16 01:25:17 +0000297 } else {
Mike Stump1eb44332009-09-09 15:08:12 +0000298 PDecl = ObjCProtocolDecl::Create(Context, CurContext,
Douglas Gregord0434102009-01-09 00:49:46 +0000299 AtProtoInterfaceLoc,ProtocolName);
Douglas Gregor6e378de2009-04-23 23:18:26 +0000300 PushOnScopeChains(PDecl, TUScope);
Chris Lattnerc8581052008-03-16 20:19:15 +0000301 PDecl->setForwardDecl(false);
Chris Lattnercca59d72008-03-16 01:23:04 +0000302 }
Fariborz Jahanianbc1c8772008-12-17 01:07:27 +0000303 if (AttrList)
Douglas Gregor9cdda0c2009-06-17 21:51:59 +0000304 ProcessDeclAttributeList(TUScope, PDecl, AttrList);
Chris Lattner4d391482007-12-12 07:09:47 +0000305 if (NumProtoRefs) {
Chris Lattnerc8581052008-03-16 20:19:15 +0000306 /// Check then save referenced protocols.
Douglas Gregor18df52b2010-01-16 15:02:53 +0000307 PDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs,
308 ProtoLocs, Context);
Chris Lattner4d391482007-12-12 07:09:47 +0000309 PDecl->setLocEnd(EndProtoLoc);
310 }
Mike Stump1eb44332009-09-09 15:08:12 +0000311
312 CheckObjCDeclScope(PDecl);
John McCalld226f652010-08-21 09:40:31 +0000313 return PDecl;
Chris Lattner4d391482007-12-12 07:09:47 +0000314}
315
316/// FindProtocolDeclaration - This routine looks up protocols and
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000317/// issues an error if they are not declared. It returns list of
318/// protocol declarations in its 'Protocols' argument.
Chris Lattner4d391482007-12-12 07:09:47 +0000319void
Chris Lattnere13b9592008-07-26 04:03:38 +0000320Sema::FindProtocolDeclaration(bool WarnOnDeclarations,
Chris Lattner7caeabd2008-07-21 22:17:28 +0000321 const IdentifierLocPair *ProtocolId,
Chris Lattner4d391482007-12-12 07:09:47 +0000322 unsigned NumProtocols,
John McCalld226f652010-08-21 09:40:31 +0000323 llvm::SmallVectorImpl<Decl *> &Protocols) {
Chris Lattner4d391482007-12-12 07:09:47 +0000324 for (unsigned i = 0; i != NumProtocols; ++i) {
Douglas Gregorc83c6872010-04-15 22:33:43 +0000325 ObjCProtocolDecl *PDecl = LookupProtocol(ProtocolId[i].first,
326 ProtocolId[i].second);
Chris Lattnereacc3922008-07-26 03:47:43 +0000327 if (!PDecl) {
Douglas Gregorf06cdae2010-01-03 18:01:57 +0000328 LookupResult R(*this, ProtocolId[i].first, ProtocolId[i].second,
329 LookupObjCProtocolName);
Douglas Gregoraaf87162010-04-14 20:04:41 +0000330 if (CorrectTypo(R, TUScope, 0, 0, false, CTC_NoKeywords) &&
Douglas Gregorf06cdae2010-01-03 18:01:57 +0000331 (PDecl = R.getAsSingle<ObjCProtocolDecl>())) {
332 Diag(ProtocolId[i].second, diag::err_undeclared_protocol_suggest)
333 << ProtocolId[i].first << R.getLookupName();
Douglas Gregor67dd1d42010-01-07 00:17:44 +0000334 Diag(PDecl->getLocation(), diag::note_previous_decl)
335 << PDecl->getDeclName();
Douglas Gregorf06cdae2010-01-03 18:01:57 +0000336 }
337 }
338
339 if (!PDecl) {
Chris Lattnerfa25bbb2008-11-19 05:08:23 +0000340 Diag(ProtocolId[i].second, diag::err_undeclared_protocol)
Chris Lattner3c73c412008-11-19 08:23:25 +0000341 << ProtocolId[i].first;
Chris Lattnereacc3922008-07-26 03:47:43 +0000342 continue;
343 }
Mike Stump1eb44332009-09-09 15:08:12 +0000344
Douglas Gregor48f3bb92009-02-18 21:56:37 +0000345 (void)DiagnoseUseOfDecl(PDecl, ProtocolId[i].second);
Chris Lattnereacc3922008-07-26 03:47:43 +0000346
347 // If this is a forward declaration and we are supposed to warn in this
348 // case, do it.
349 if (WarnOnDeclarations && PDecl->isForwardDecl())
Chris Lattnerfa25bbb2008-11-19 05:08:23 +0000350 Diag(ProtocolId[i].second, diag::warn_undef_protocolref)
Chris Lattner3c73c412008-11-19 08:23:25 +0000351 << ProtocolId[i].first;
John McCalld226f652010-08-21 09:40:31 +0000352 Protocols.push_back(PDecl);
Chris Lattner4d391482007-12-12 07:09:47 +0000353 }
354}
355
Fariborz Jahanian78c39c72009-03-02 19:06:08 +0000356/// DiagnoseClassExtensionDupMethods - Check for duplicate declaration of
Fariborz Jahanianb7f95f52009-03-02 19:05:07 +0000357/// a class method in its extension.
358///
Mike Stump1eb44332009-09-09 15:08:12 +0000359void Sema::DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT,
Fariborz Jahanianb7f95f52009-03-02 19:05:07 +0000360 ObjCInterfaceDecl *ID) {
361 if (!ID)
362 return; // Possibly due to previous error
363
364 llvm::DenseMap<Selector, const ObjCMethodDecl*> MethodMap;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000365 for (ObjCInterfaceDecl::method_iterator i = ID->meth_begin(),
366 e = ID->meth_end(); i != e; ++i) {
Fariborz Jahanianb7f95f52009-03-02 19:05:07 +0000367 ObjCMethodDecl *MD = *i;
368 MethodMap[MD->getSelector()] = MD;
369 }
370
371 if (MethodMap.empty())
372 return;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000373 for (ObjCCategoryDecl::method_iterator i = CAT->meth_begin(),
374 e = CAT->meth_end(); i != e; ++i) {
Fariborz Jahanianb7f95f52009-03-02 19:05:07 +0000375 ObjCMethodDecl *Method = *i;
376 const ObjCMethodDecl *&PrevMethod = MethodMap[Method->getSelector()];
377 if (PrevMethod && !MatchTwoMethodDeclarations(Method, PrevMethod)) {
378 Diag(Method->getLocation(), diag::err_duplicate_method_decl)
379 << Method->getDeclName();
380 Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
381 }
382 }
383}
384
Chris Lattner58fe03b2009-04-12 08:43:13 +0000385/// ActOnForwardProtocolDeclaration - Handle @protocol foo;
John McCalld226f652010-08-21 09:40:31 +0000386Decl *
Chris Lattner4d391482007-12-12 07:09:47 +0000387Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
Chris Lattner7caeabd2008-07-21 22:17:28 +0000388 const IdentifierLocPair *IdentList,
Fariborz Jahanianbc1c8772008-12-17 01:07:27 +0000389 unsigned NumElts,
390 AttributeList *attrList) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000391 llvm::SmallVector<ObjCProtocolDecl*, 32> Protocols;
Douglas Gregor18df52b2010-01-16 15:02:53 +0000392 llvm::SmallVector<SourceLocation, 8> ProtoLocs;
Mike Stump1eb44332009-09-09 15:08:12 +0000393
Chris Lattner4d391482007-12-12 07:09:47 +0000394 for (unsigned i = 0; i != NumElts; ++i) {
Chris Lattner7caeabd2008-07-21 22:17:28 +0000395 IdentifierInfo *Ident = IdentList[i].first;
Douglas Gregorc83c6872010-04-15 22:33:43 +0000396 ObjCProtocolDecl *PDecl = LookupProtocol(Ident, IdentList[i].second);
Sebastian Redl0b17c612010-08-13 00:28:03 +0000397 bool isNew = false;
Douglas Gregord0434102009-01-09 00:49:46 +0000398 if (PDecl == 0) { // Not already seen?
Mike Stump1eb44332009-09-09 15:08:12 +0000399 PDecl = ObjCProtocolDecl::Create(Context, CurContext,
Douglas Gregord0434102009-01-09 00:49:46 +0000400 IdentList[i].second, Ident);
Sebastian Redl0b17c612010-08-13 00:28:03 +0000401 PushOnScopeChains(PDecl, TUScope, false);
402 isNew = true;
Douglas Gregord0434102009-01-09 00:49:46 +0000403 }
Sebastian Redl0b17c612010-08-13 00:28:03 +0000404 if (attrList) {
Douglas Gregor9cdda0c2009-06-17 21:51:59 +0000405 ProcessDeclAttributeList(TUScope, PDecl, attrList);
Sebastian Redl0b17c612010-08-13 00:28:03 +0000406 if (!isNew)
407 PDecl->setChangedSinceDeserialization(true);
408 }
Chris Lattner4d391482007-12-12 07:09:47 +0000409 Protocols.push_back(PDecl);
Douglas Gregor18df52b2010-01-16 15:02:53 +0000410 ProtoLocs.push_back(IdentList[i].second);
Chris Lattner4d391482007-12-12 07:09:47 +0000411 }
Mike Stump1eb44332009-09-09 15:08:12 +0000412
413 ObjCForwardProtocolDecl *PDecl =
Douglas Gregord0434102009-01-09 00:49:46 +0000414 ObjCForwardProtocolDecl::Create(Context, CurContext, AtProtocolLoc,
Douglas Gregor18df52b2010-01-16 15:02:53 +0000415 Protocols.data(), Protocols.size(),
416 ProtoLocs.data());
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000417 CurContext->addDecl(PDecl);
Anders Carlsson15281452008-11-04 16:57:32 +0000418 CheckObjCDeclScope(PDecl);
John McCalld226f652010-08-21 09:40:31 +0000419 return PDecl;
Chris Lattner4d391482007-12-12 07:09:47 +0000420}
421
John McCalld226f652010-08-21 09:40:31 +0000422Decl *Sema::
Chris Lattner7caeabd2008-07-21 22:17:28 +0000423ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
424 IdentifierInfo *ClassName, SourceLocation ClassLoc,
425 IdentifierInfo *CategoryName,
426 SourceLocation CategoryLoc,
John McCalld226f652010-08-21 09:40:31 +0000427 Decl * const *ProtoRefs,
Chris Lattner7caeabd2008-07-21 22:17:28 +0000428 unsigned NumProtoRefs,
Douglas Gregor18df52b2010-01-16 15:02:53 +0000429 const SourceLocation *ProtoLocs,
Chris Lattner7caeabd2008-07-21 22:17:28 +0000430 SourceLocation EndProtoLoc) {
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000431 ObjCCategoryDecl *CDecl;
Douglas Gregorc83c6872010-04-15 22:33:43 +0000432 ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName, ClassLoc, true);
Ted Kremenek09b68972010-02-23 19:39:46 +0000433
434 /// Check that class of this category is already completely declared.
435 if (!IDecl || IDecl->isForwardDecl()) {
436 // Create an invalid ObjCCategoryDecl to serve as context for
437 // the enclosing method declarations. We mark the decl invalid
438 // to make it clear that this isn't a valid AST.
439 CDecl = ObjCCategoryDecl::Create(Context, CurContext, AtInterfaceLoc,
440 ClassLoc, CategoryLoc, CategoryName);
441 CDecl->setInvalidDecl();
442 Diag(ClassLoc, diag::err_undef_interface) << ClassName;
John McCalld226f652010-08-21 09:40:31 +0000443 return CDecl;
Ted Kremenek09b68972010-02-23 19:39:46 +0000444 }
445
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000446 if (!CategoryName && IDecl->getImplementation()) {
447 Diag(ClassLoc, diag::err_class_extension_after_impl) << ClassName;
448 Diag(IDecl->getImplementation()->getLocation(),
449 diag::note_implementation_declared);
Ted Kremenek09b68972010-02-23 19:39:46 +0000450 }
451
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000452 CDecl = ObjCCategoryDecl::Create(Context, CurContext, AtInterfaceLoc,
453 ClassLoc, CategoryLoc, CategoryName);
454 // FIXME: PushOnScopeChains?
455 CurContext->addDecl(CDecl);
Chris Lattner4d391482007-12-12 07:09:47 +0000456
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000457 CDecl->setClassInterface(IDecl);
458 // Insert class extension to the list of class's categories.
459 if (!CategoryName)
460 CDecl->insertNextClassCategory();
Mike Stump1eb44332009-09-09 15:08:12 +0000461
Chris Lattner16b34b42009-02-16 21:30:01 +0000462 // If the interface is deprecated, warn about it.
Douglas Gregor48f3bb92009-02-18 21:56:37 +0000463 (void)DiagnoseUseOfDecl(IDecl, ClassLoc);
Chris Lattner70f19542009-02-16 21:26:43 +0000464
Fariborz Jahanian25760612010-02-15 21:55:26 +0000465 if (CategoryName) {
466 /// Check for duplicate interface declaration for this category
467 ObjCCategoryDecl *CDeclChain;
468 for (CDeclChain = IDecl->getCategoryList(); CDeclChain;
469 CDeclChain = CDeclChain->getNextClassCategory()) {
470 if (CDeclChain->getIdentifier() == CategoryName) {
471 // Class extensions can be declared multiple times.
472 Diag(CategoryLoc, diag::warn_dup_category_def)
473 << ClassName << CategoryName;
474 Diag(CDeclChain->getLocation(), diag::note_previous_definition);
475 break;
476 }
Chris Lattner70f19542009-02-16 21:26:43 +0000477 }
Fariborz Jahanian25760612010-02-15 21:55:26 +0000478 if (!CDeclChain)
479 CDecl->insertNextClassCategory();
Chris Lattner70f19542009-02-16 21:26:43 +0000480 }
Chris Lattner70f19542009-02-16 21:26:43 +0000481
Chris Lattner4d391482007-12-12 07:09:47 +0000482 if (NumProtoRefs) {
Fariborz Jahanianb106fc62009-10-05 21:32:49 +0000483 CDecl->setProtocolList((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs,
Douglas Gregor18df52b2010-01-16 15:02:53 +0000484 ProtoLocs, Context);
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000485 // Protocols in the class extension belong to the class.
Fariborz Jahanian25760612010-02-15 21:55:26 +0000486 if (CDecl->IsClassExtension())
Fariborz Jahanian339798e2009-10-05 20:41:32 +0000487 IDecl->mergeClassExtensionProtocolList((ObjCProtocolDecl**)ProtoRefs,
Ted Kremenek53b94412010-09-01 01:21:15 +0000488 NumProtoRefs, Context);
Chris Lattner4d391482007-12-12 07:09:47 +0000489 }
Mike Stump1eb44332009-09-09 15:08:12 +0000490
Anders Carlsson15281452008-11-04 16:57:32 +0000491 CheckObjCDeclScope(CDecl);
John McCalld226f652010-08-21 09:40:31 +0000492 return CDecl;
Chris Lattner4d391482007-12-12 07:09:47 +0000493}
494
495/// ActOnStartCategoryImplementation - Perform semantic checks on the
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000496/// category implementation declaration and build an ObjCCategoryImplDecl
Chris Lattner4d391482007-12-12 07:09:47 +0000497/// object.
John McCalld226f652010-08-21 09:40:31 +0000498Decl *Sema::ActOnStartCategoryImplementation(
Chris Lattner4d391482007-12-12 07:09:47 +0000499 SourceLocation AtCatImplLoc,
500 IdentifierInfo *ClassName, SourceLocation ClassLoc,
501 IdentifierInfo *CatName, SourceLocation CatLoc) {
Douglas Gregorc83c6872010-04-15 22:33:43 +0000502 ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName, ClassLoc, true);
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000503 ObjCCategoryDecl *CatIDecl = 0;
504 if (IDecl) {
505 CatIDecl = IDecl->FindCategoryDeclaration(CatName);
506 if (!CatIDecl) {
507 // Category @implementation with no corresponding @interface.
508 // Create and install one.
509 CatIDecl = ObjCCategoryDecl::Create(Context, CurContext, SourceLocation(),
Douglas Gregor3db211b2010-01-16 16:38:58 +0000510 SourceLocation(), SourceLocation(),
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000511 CatName);
512 CatIDecl->setClassInterface(IDecl);
513 CatIDecl->insertNextClassCategory();
514 }
515 }
516
Mike Stump1eb44332009-09-09 15:08:12 +0000517 ObjCCategoryImplDecl *CDecl =
Douglas Gregord0434102009-01-09 00:49:46 +0000518 ObjCCategoryImplDecl::Create(Context, CurContext, AtCatImplLoc, CatName,
519 IDecl);
Chris Lattner4d391482007-12-12 07:09:47 +0000520 /// Check that class of this category is already completely declared.
521 if (!IDecl || IDecl->isForwardDecl())
Chris Lattner3c73c412008-11-19 08:23:25 +0000522 Diag(ClassLoc, diag::err_undef_interface) << ClassName;
Chris Lattner4d391482007-12-12 07:09:47 +0000523
Douglas Gregord0434102009-01-09 00:49:46 +0000524 // FIXME: PushOnScopeChains?
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000525 CurContext->addDecl(CDecl);
Douglas Gregord0434102009-01-09 00:49:46 +0000526
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000527 /// Check that CatName, category name, is not used in another implementation.
528 if (CatIDecl) {
529 if (CatIDecl->getImplementation()) {
530 Diag(ClassLoc, diag::err_dup_implementation_category) << ClassName
531 << CatName;
532 Diag(CatIDecl->getImplementation()->getLocation(),
533 diag::note_previous_definition);
534 } else
535 CatIDecl->setImplementation(CDecl);
536 }
Mike Stump1eb44332009-09-09 15:08:12 +0000537
Anders Carlsson15281452008-11-04 16:57:32 +0000538 CheckObjCDeclScope(CDecl);
John McCalld226f652010-08-21 09:40:31 +0000539 return CDecl;
Chris Lattner4d391482007-12-12 07:09:47 +0000540}
541
John McCalld226f652010-08-21 09:40:31 +0000542Decl *Sema::ActOnStartClassImplementation(
Chris Lattner4d391482007-12-12 07:09:47 +0000543 SourceLocation AtClassImplLoc,
544 IdentifierInfo *ClassName, SourceLocation ClassLoc,
Mike Stump1eb44332009-09-09 15:08:12 +0000545 IdentifierInfo *SuperClassname,
Chris Lattner4d391482007-12-12 07:09:47 +0000546 SourceLocation SuperClassLoc) {
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000547 ObjCInterfaceDecl* IDecl = 0;
Chris Lattner4d391482007-12-12 07:09:47 +0000548 // Check for another declaration kind with the same name.
John McCallf36e02d2009-10-09 21:13:30 +0000549 NamedDecl *PrevDecl
Douglas Gregorc0b39642010-04-15 23:40:53 +0000550 = LookupSingleName(TUScope, ClassName, ClassLoc, LookupOrdinaryName,
551 ForRedeclaration);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000552 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
Chris Lattner3c73c412008-11-19 08:23:25 +0000553 Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
Chris Lattner5f4a6822008-11-23 23:12:31 +0000554 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000555 } else if ((IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl))) {
556 // If this is a forward declaration of an interface, warn.
557 if (IDecl->isForwardDecl()) {
Chris Lattner3c73c412008-11-19 08:23:25 +0000558 Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000559 IDecl = 0;
Fariborz Jahanian77a6be42009-04-23 21:49:04 +0000560 }
Douglas Gregor95ff7422010-01-04 17:27:12 +0000561 } else {
562 // We did not find anything with the name ClassName; try to correct for
563 // typos in the class name.
564 LookupResult R(*this, ClassName, ClassLoc, LookupOrdinaryName);
Douglas Gregoraaf87162010-04-14 20:04:41 +0000565 if (CorrectTypo(R, TUScope, 0, 0, false, CTC_NoKeywords) &&
Douglas Gregor95ff7422010-01-04 17:27:12 +0000566 (IDecl = R.getAsSingle<ObjCInterfaceDecl>())) {
Douglas Gregora6f26382010-01-06 23:44:25 +0000567 // Suggest the (potentially) correct interface name. However, put the
568 // fix-it hint itself in a separate note, since changing the name in
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000569 // the warning would make the fix-it change semantics.However, don't
Douglas Gregor95ff7422010-01-04 17:27:12 +0000570 // provide a code-modification hint or use the typo name for recovery,
571 // because this is just a warning. The program may actually be correct.
572 Diag(ClassLoc, diag::warn_undef_interface_suggest)
573 << ClassName << R.getLookupName();
Douglas Gregora6f26382010-01-06 23:44:25 +0000574 Diag(IDecl->getLocation(), diag::note_previous_decl)
575 << R.getLookupName()
Douglas Gregor849b2432010-03-31 17:46:05 +0000576 << FixItHint::CreateReplacement(ClassLoc,
577 R.getLookupName().getAsString());
Douglas Gregor95ff7422010-01-04 17:27:12 +0000578 IDecl = 0;
579 } else {
580 Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
581 }
Chris Lattner4d391482007-12-12 07:09:47 +0000582 }
Mike Stump1eb44332009-09-09 15:08:12 +0000583
Chris Lattner4d391482007-12-12 07:09:47 +0000584 // Check that super class name is valid class name
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000585 ObjCInterfaceDecl* SDecl = 0;
Chris Lattner4d391482007-12-12 07:09:47 +0000586 if (SuperClassname) {
587 // Check if a different kind of symbol declared in this scope.
Douglas Gregorc83c6872010-04-15 22:33:43 +0000588 PrevDecl = LookupSingleName(TUScope, SuperClassname, SuperClassLoc,
589 LookupOrdinaryName);
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000590 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
Chris Lattner3c73c412008-11-19 08:23:25 +0000591 Diag(SuperClassLoc, diag::err_redefinition_different_kind)
592 << SuperClassname;
Chris Lattner5f4a6822008-11-23 23:12:31 +0000593 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
Chris Lattner3c73c412008-11-19 08:23:25 +0000594 } else {
Mike Stump1eb44332009-09-09 15:08:12 +0000595 SDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
Chris Lattner4d391482007-12-12 07:09:47 +0000596 if (!SDecl)
Chris Lattner3c73c412008-11-19 08:23:25 +0000597 Diag(SuperClassLoc, diag::err_undef_superclass)
598 << SuperClassname << ClassName;
Chris Lattner4d391482007-12-12 07:09:47 +0000599 else if (IDecl && IDecl->getSuperClass() != SDecl) {
600 // This implementation and its interface do not have the same
601 // super class.
Chris Lattner3c73c412008-11-19 08:23:25 +0000602 Diag(SuperClassLoc, diag::err_conflicting_super_class)
Chris Lattner08631c52008-11-23 21:45:46 +0000603 << SDecl->getDeclName();
Chris Lattner5f4a6822008-11-23 23:12:31 +0000604 Diag(SDecl->getLocation(), diag::note_previous_definition);
Chris Lattner4d391482007-12-12 07:09:47 +0000605 }
606 }
607 }
Mike Stump1eb44332009-09-09 15:08:12 +0000608
Chris Lattner4d391482007-12-12 07:09:47 +0000609 if (!IDecl) {
610 // Legacy case of @implementation with no corresponding @interface.
611 // Build, chain & install the interface decl into the identifier.
Daniel Dunbarf6414922008-08-20 18:02:42 +0000612
Mike Stump390b4cc2009-05-16 07:39:55 +0000613 // FIXME: Do we support attributes on the @implementation? If so we should
614 // copy them over.
Mike Stump1eb44332009-09-09 15:08:12 +0000615 IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassImplLoc,
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000616 ClassName, ClassLoc, false, true);
Chris Lattner4d391482007-12-12 07:09:47 +0000617 IDecl->setSuperClass(SDecl);
618 IDecl->setLocEnd(ClassLoc);
Douglas Gregor8b9fb302009-04-24 00:16:12 +0000619
620 PushOnScopeChains(IDecl, TUScope);
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000621 } else {
622 // Mark the interface as being completed, even if it was just as
623 // @class ....;
624 // declaration; the user cannot reopen it.
625 IDecl->setForwardDecl(false);
Chris Lattner4d391482007-12-12 07:09:47 +0000626 }
Mike Stump1eb44332009-09-09 15:08:12 +0000627
628 ObjCImplementationDecl* IMPDecl =
629 ObjCImplementationDecl::Create(Context, CurContext, AtClassImplLoc,
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000630 IDecl, SDecl);
Mike Stump1eb44332009-09-09 15:08:12 +0000631
Anders Carlsson15281452008-11-04 16:57:32 +0000632 if (CheckObjCDeclScope(IMPDecl))
John McCalld226f652010-08-21 09:40:31 +0000633 return IMPDecl;
Mike Stump1eb44332009-09-09 15:08:12 +0000634
Chris Lattner4d391482007-12-12 07:09:47 +0000635 // Check that there is no duplicate implementation of this class.
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000636 if (IDecl->getImplementation()) {
637 // FIXME: Don't leak everything!
Chris Lattner3c73c412008-11-19 08:23:25 +0000638 Diag(ClassLoc, diag::err_dup_implementation_class) << ClassName;
Argyrios Kyrtzidis87018772009-07-21 00:06:04 +0000639 Diag(IDecl->getImplementation()->getLocation(),
640 diag::note_previous_definition);
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000641 } else { // add it to the list.
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000642 IDecl->setImplementation(IMPDecl);
Douglas Gregor8fc463a2009-04-24 00:11:27 +0000643 PushOnScopeChains(IMPDecl, TUScope);
Argyrios Kyrtzidis8a1d7222009-07-21 00:05:53 +0000644 }
John McCalld226f652010-08-21 09:40:31 +0000645 return IMPDecl;
Chris Lattner4d391482007-12-12 07:09:47 +0000646}
647
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000648void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
649 ObjCIvarDecl **ivars, unsigned numIvars,
Chris Lattner4d391482007-12-12 07:09:47 +0000650 SourceLocation RBrace) {
651 assert(ImpDecl && "missing implementation decl");
Douglas Gregor4afa39d2009-01-20 01:17:11 +0000652 ObjCInterfaceDecl* IDecl = ImpDecl->getClassInterface();
Chris Lattner4d391482007-12-12 07:09:47 +0000653 if (!IDecl)
654 return;
655 /// Check case of non-existing @interface decl.
656 /// (legacy objective-c @implementation decl without an @interface decl).
657 /// Add implementations's ivar to the synthesize class's ivar list.
Steve Naroff33feeb02009-04-20 20:09:33 +0000658 if (IDecl->isImplicitInterfaceDecl()) {
Chris Lattner38af2de2009-02-20 21:35:13 +0000659 IDecl->setLocEnd(RBrace);
Fariborz Jahanian3a21cd92010-02-17 17:00:07 +0000660 // Add ivar's to class's DeclContext.
661 for (unsigned i = 0, e = numIvars; i != e; ++i) {
Fariborz Jahanian2f14c4d2010-02-17 18:10:54 +0000662 ivars[i]->setLexicalDeclContext(ImpDecl);
663 IDecl->makeDeclVisibleInContext(ivars[i], false);
Fariborz Jahanian11062e12010-02-19 00:31:17 +0000664 ImpDecl->addDecl(ivars[i]);
Fariborz Jahanian3a21cd92010-02-17 17:00:07 +0000665 }
666
Chris Lattner4d391482007-12-12 07:09:47 +0000667 return;
668 }
669 // If implementation has empty ivar list, just return.
670 if (numIvars == 0)
671 return;
Mike Stump1eb44332009-09-09 15:08:12 +0000672
Chris Lattner4d391482007-12-12 07:09:47 +0000673 assert(ivars && "missing @implementation ivars");
Fariborz Jahanianbd94d442010-02-19 20:58:54 +0000674 if (LangOpts.ObjCNonFragileABI2) {
675 if (ImpDecl->getSuperClass())
676 Diag(ImpDecl->getLocation(), diag::warn_on_superclass_use);
677 for (unsigned i = 0; i < numIvars; i++) {
678 ObjCIvarDecl* ImplIvar = ivars[i];
679 if (const ObjCIvarDecl *ClsIvar =
680 IDecl->getIvarDecl(ImplIvar->getIdentifier())) {
681 Diag(ImplIvar->getLocation(), diag::err_duplicate_ivar_declaration);
682 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
683 continue;
684 }
Fariborz Jahanianbd94d442010-02-19 20:58:54 +0000685 // Instance ivar to Implementation's DeclContext.
686 ImplIvar->setLexicalDeclContext(ImpDecl);
687 IDecl->makeDeclVisibleInContext(ImplIvar, false);
688 ImpDecl->addDecl(ImplIvar);
689 }
690 return;
691 }
Chris Lattner4d391482007-12-12 07:09:47 +0000692 // Check interface's Ivar list against those in the implementation.
693 // names and types must match.
694 //
Chris Lattner4d391482007-12-12 07:09:47 +0000695 unsigned j = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000696 ObjCInterfaceDecl::ivar_iterator
Chris Lattner4c525092007-12-12 17:58:05 +0000697 IVI = IDecl->ivar_begin(), IVE = IDecl->ivar_end();
698 for (; numIvars > 0 && IVI != IVE; ++IVI) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000699 ObjCIvarDecl* ImplIvar = ivars[j++];
700 ObjCIvarDecl* ClsIvar = *IVI;
Chris Lattner4d391482007-12-12 07:09:47 +0000701 assert (ImplIvar && "missing implementation ivar");
702 assert (ClsIvar && "missing class ivar");
Mike Stump1eb44332009-09-09 15:08:12 +0000703
Steve Naroffca331292009-03-03 14:49:36 +0000704 // First, make sure the types match.
Chris Lattner1b63eef2008-07-27 00:05:05 +0000705 if (Context.getCanonicalType(ImplIvar->getType()) !=
706 Context.getCanonicalType(ClsIvar->getType())) {
Chris Lattnerfa25bbb2008-11-19 05:08:23 +0000707 Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_type)
Chris Lattner08631c52008-11-23 21:45:46 +0000708 << ImplIvar->getIdentifier()
709 << ImplIvar->getType() << ClsIvar->getType();
Chris Lattner5f4a6822008-11-23 23:12:31 +0000710 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
Steve Naroffca331292009-03-03 14:49:36 +0000711 } else if (ImplIvar->isBitField() && ClsIvar->isBitField()) {
712 Expr *ImplBitWidth = ImplIvar->getBitWidth();
713 Expr *ClsBitWidth = ClsIvar->getBitWidth();
Eli Friedman9a901bb2009-04-26 19:19:15 +0000714 if (ImplBitWidth->EvaluateAsInt(Context).getZExtValue() !=
715 ClsBitWidth->EvaluateAsInt(Context).getZExtValue()) {
Steve Naroffca331292009-03-03 14:49:36 +0000716 Diag(ImplBitWidth->getLocStart(), diag::err_conflicting_ivar_bitwidth)
717 << ImplIvar->getIdentifier();
718 Diag(ClsBitWidth->getLocStart(), diag::note_previous_definition);
719 }
Mike Stump1eb44332009-09-09 15:08:12 +0000720 }
Steve Naroffca331292009-03-03 14:49:36 +0000721 // Make sure the names are identical.
722 if (ImplIvar->getIdentifier() != ClsIvar->getIdentifier()) {
Chris Lattnerfa25bbb2008-11-19 05:08:23 +0000723 Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_name)
Chris Lattner08631c52008-11-23 21:45:46 +0000724 << ImplIvar->getIdentifier() << ClsIvar->getIdentifier();
Chris Lattner5f4a6822008-11-23 23:12:31 +0000725 Diag(ClsIvar->getLocation(), diag::note_previous_definition);
Chris Lattner4d391482007-12-12 07:09:47 +0000726 }
727 --numIvars;
Chris Lattner4d391482007-12-12 07:09:47 +0000728 }
Mike Stump1eb44332009-09-09 15:08:12 +0000729
Chris Lattner609e4c72007-12-12 18:11:49 +0000730 if (numIvars > 0)
Chris Lattner0e391052007-12-12 18:19:52 +0000731 Diag(ivars[j]->getLocation(), diag::err_inconsistant_ivar_count);
Chris Lattner609e4c72007-12-12 18:11:49 +0000732 else if (IVI != IVE)
Chris Lattner0e391052007-12-12 18:19:52 +0000733 Diag((*IVI)->getLocation(), diag::err_inconsistant_ivar_count);
Chris Lattner4d391482007-12-12 07:09:47 +0000734}
735
Steve Naroff3c2eb662008-02-10 21:38:56 +0000736void Sema::WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
Fariborz Jahanian52146832010-03-31 18:23:33 +0000737 bool &IncompleteImpl, unsigned DiagID) {
Steve Naroff3c2eb662008-02-10 21:38:56 +0000738 if (!IncompleteImpl) {
739 Diag(ImpLoc, diag::warn_incomplete_impl);
740 IncompleteImpl = true;
741 }
Fariborz Jahanian52146832010-03-31 18:23:33 +0000742 Diag(method->getLocation(), DiagID)
Fariborz Jahanian8822f7c2010-03-27 19:02:17 +0000743 << method->getDeclName();
Steve Naroff3c2eb662008-02-10 21:38:56 +0000744}
745
Fariborz Jahanian8daab972008-12-05 18:18:52 +0000746void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl,
747 ObjCMethodDecl *IntfMethodDecl) {
Chris Lattner5272b7f2009-04-11 18:01:59 +0000748 if (!Context.typesAreCompatible(IntfMethodDecl->getResultType(),
Fariborz Jahanian2574a682009-05-14 23:52:54 +0000749 ImpMethodDecl->getResultType()) &&
Steve Naroff4084c302009-07-23 01:01:38 +0000750 !Context.QualifiedIdConformsQualifiedId(IntfMethodDecl->getResultType(),
751 ImpMethodDecl->getResultType())) {
Mike Stump1eb44332009-09-09 15:08:12 +0000752 Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_ret_types)
Chris Lattner3aff9192009-04-11 19:58:42 +0000753 << ImpMethodDecl->getDeclName() << IntfMethodDecl->getResultType()
754 << ImpMethodDecl->getResultType();
Fariborz Jahanian8daab972008-12-05 18:18:52 +0000755 Diag(IntfMethodDecl->getLocation(), diag::note_previous_definition);
756 }
Mike Stump1eb44332009-09-09 15:08:12 +0000757
Chris Lattner3aff9192009-04-11 19:58:42 +0000758 for (ObjCMethodDecl::param_iterator IM = ImpMethodDecl->param_begin(),
759 IF = IntfMethodDecl->param_begin(), EM = ImpMethodDecl->param_end();
760 IM != EM; ++IM, ++IF) {
Fariborz Jahanian3393f812009-11-18 18:56:09 +0000761 QualType ParmDeclTy = (*IF)->getType().getUnqualifiedType();
762 QualType ParmImpTy = (*IM)->getType().getUnqualifiedType();
763 if (Context.typesAreCompatible(ParmDeclTy, ParmImpTy) ||
764 Context.QualifiedIdConformsQualifiedId(ParmDeclTy, ParmImpTy))
Chris Lattner3aff9192009-04-11 19:58:42 +0000765 continue;
Mike Stump1eb44332009-09-09 15:08:12 +0000766
767 Diag((*IM)->getLocation(), diag::warn_conflicting_param_types)
Chris Lattner3aff9192009-04-11 19:58:42 +0000768 << ImpMethodDecl->getDeclName() << (*IF)->getType()
769 << (*IM)->getType();
Chris Lattnerd1e0f5a2009-04-11 20:14:49 +0000770 Diag((*IF)->getLocation(), diag::note_previous_definition);
Chris Lattner3aff9192009-04-11 19:58:42 +0000771 }
Fariborz Jahanian561da7e2010-05-21 23:28:58 +0000772 if (ImpMethodDecl->isVariadic() != IntfMethodDecl->isVariadic()) {
773 Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_variadic);
774 Diag(IntfMethodDecl->getLocation(), diag::note_previous_declaration);
775 }
Fariborz Jahanian8daab972008-12-05 18:18:52 +0000776}
777
Mike Stump390b4cc2009-05-16 07:39:55 +0000778/// FIXME: Type hierarchies in Objective-C can be deep. We could most likely
779/// improve the efficiency of selector lookups and type checking by associating
780/// with each protocol / interface / category the flattened instance tables. If
781/// we used an immutable set to keep the table then it wouldn't add significant
782/// memory cost and it would be handy for lookups.
Daniel Dunbarb20ef3e2008-08-27 05:40:03 +0000783
Steve Naroffefe7f362008-02-08 22:06:17 +0000784/// CheckProtocolMethodDefs - This routine checks unimplemented methods
Chris Lattner4d391482007-12-12 07:09:47 +0000785/// Declared in protocol, and those referenced by it.
Steve Naroffefe7f362008-02-08 22:06:17 +0000786void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc,
787 ObjCProtocolDecl *PDecl,
Chris Lattner4d391482007-12-12 07:09:47 +0000788 bool& IncompleteImpl,
Steve Naroffefe7f362008-02-08 22:06:17 +0000789 const llvm::DenseSet<Selector> &InsMap,
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000790 const llvm::DenseSet<Selector> &ClsMap,
Fariborz Jahanianf2838592010-03-27 21:10:05 +0000791 ObjCContainerDecl *CDecl) {
792 ObjCInterfaceDecl *IDecl;
793 if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl))
794 IDecl = C->getClassInterface();
795 else
796 IDecl = dyn_cast<ObjCInterfaceDecl>(CDecl);
797 assert (IDecl && "CheckProtocolMethodDefs - IDecl is null");
798
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000799 ObjCInterfaceDecl *Super = IDecl->getSuperClass();
Fariborz Jahaniancd187622009-05-22 17:12:32 +0000800 ObjCInterfaceDecl *NSIDecl = 0;
801 if (getLangOptions().NeXTRuntime) {
Mike Stump1eb44332009-09-09 15:08:12 +0000802 // check to see if class implements forwardInvocation method and objects
803 // of this class are derived from 'NSProxy' so that to forward requests
Fariborz Jahaniancd187622009-05-22 17:12:32 +0000804 // from one object to another.
Mike Stump1eb44332009-09-09 15:08:12 +0000805 // Under such conditions, which means that every method possible is
806 // implemented in the class, we should not issue "Method definition not
Fariborz Jahaniancd187622009-05-22 17:12:32 +0000807 // found" warnings.
808 // FIXME: Use a general GetUnarySelector method for this.
809 IdentifierInfo* II = &Context.Idents.get("forwardInvocation");
810 Selector fISelector = Context.Selectors.getSelector(1, &II);
811 if (InsMap.count(fISelector))
812 // Is IDecl derived from 'NSProxy'? If so, no instance methods
813 // need be implemented in the implementation.
814 NSIDecl = IDecl->lookupInheritedClass(&Context.Idents.get("NSProxy"));
815 }
Mike Stump1eb44332009-09-09 15:08:12 +0000816
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000817 // If a method lookup fails locally we still need to look and see if
818 // the method was implemented by a base class or an inherited
819 // protocol. This lookup is slow, but occurs rarely in correct code
820 // and otherwise would terminate in a warning.
821
Chris Lattner4d391482007-12-12 07:09:47 +0000822 // check unimplemented instance methods.
Fariborz Jahaniancd187622009-05-22 17:12:32 +0000823 if (!NSIDecl)
Mike Stump1eb44332009-09-09 15:08:12 +0000824 for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(),
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000825 E = PDecl->instmeth_end(); I != E; ++I) {
Fariborz Jahaniancd187622009-05-22 17:12:32 +0000826 ObjCMethodDecl *method = *I;
Mike Stump1eb44332009-09-09 15:08:12 +0000827 if (method->getImplementationControl() != ObjCMethodDecl::Optional &&
Fariborz Jahaniancd187622009-05-22 17:12:32 +0000828 !method->isSynthesized() && !InsMap.count(method->getSelector()) &&
Mike Stump1eb44332009-09-09 15:08:12 +0000829 (!Super ||
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000830 !Super->lookupInstanceMethod(method->getSelector()))) {
Fariborz Jahaniancd187622009-05-22 17:12:32 +0000831 // Ugly, but necessary. Method declared in protcol might have
832 // have been synthesized due to a property declared in the class which
833 // uses the protocol.
Mike Stump1eb44332009-09-09 15:08:12 +0000834 ObjCMethodDecl *MethodInClass =
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000835 IDecl->lookupInstanceMethod(method->getSelector());
Fariborz Jahanian8822f7c2010-03-27 19:02:17 +0000836 if (!MethodInClass || !MethodInClass->isSynthesized()) {
Fariborz Jahanian52146832010-03-31 18:23:33 +0000837 unsigned DIAG = diag::warn_unimplemented_protocol_method;
838 if (Diags.getDiagnosticLevel(DIAG) != Diagnostic::Ignored) {
839 WarnUndefinedMethod(ImpLoc, method, IncompleteImpl, DIAG);
840 Diag(CDecl->getLocation(), diag::note_required_for_protocol_at)
841 << PDecl->getDeclName();
842 }
Fariborz Jahanian8822f7c2010-03-27 19:02:17 +0000843 }
Fariborz Jahaniancd187622009-05-22 17:12:32 +0000844 }
845 }
Chris Lattner4d391482007-12-12 07:09:47 +0000846 // check unimplemented class methods
Mike Stump1eb44332009-09-09 15:08:12 +0000847 for (ObjCProtocolDecl::classmeth_iterator
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000848 I = PDecl->classmeth_begin(), E = PDecl->classmeth_end();
Douglas Gregor6ab35242009-04-09 21:40:53 +0000849 I != E; ++I) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000850 ObjCMethodDecl *method = *I;
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000851 if (method->getImplementationControl() != ObjCMethodDecl::Optional &&
852 !ClsMap.count(method->getSelector()) &&
Fariborz Jahanian8822f7c2010-03-27 19:02:17 +0000853 (!Super || !Super->lookupClassMethod(method->getSelector()))) {
Fariborz Jahanian52146832010-03-31 18:23:33 +0000854 unsigned DIAG = diag::warn_unimplemented_protocol_method;
855 if (Diags.getDiagnosticLevel(DIAG) != Diagnostic::Ignored) {
856 WarnUndefinedMethod(ImpLoc, method, IncompleteImpl, DIAG);
857 Diag(IDecl->getLocation(), diag::note_required_for_protocol_at) <<
858 PDecl->getDeclName();
859 }
Fariborz Jahanian8822f7c2010-03-27 19:02:17 +0000860 }
Steve Naroff58dbdeb2007-12-14 23:37:57 +0000861 }
Chris Lattner780f3292008-07-21 21:32:27 +0000862 // Check on this protocols's referenced protocols, recursively.
863 for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
864 E = PDecl->protocol_end(); PI != E; ++PI)
Daniel Dunbar7ad1b1f2008-09-04 20:01:15 +0000865 CheckProtocolMethodDefs(ImpLoc, *PI, IncompleteImpl, InsMap, ClsMap, IDecl);
Chris Lattner4d391482007-12-12 07:09:47 +0000866}
867
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000868/// MatchAllMethodDeclarations - Check methods declaraed in interface or
869/// or protocol against those declared in their implementations.
870///
871void Sema::MatchAllMethodDeclarations(const llvm::DenseSet<Selector> &InsMap,
872 const llvm::DenseSet<Selector> &ClsMap,
873 llvm::DenseSet<Selector> &InsMapSeen,
874 llvm::DenseSet<Selector> &ClsMapSeen,
875 ObjCImplDecl* IMPDecl,
876 ObjCContainerDecl* CDecl,
877 bool &IncompleteImpl,
Mike Stump1eb44332009-09-09 15:08:12 +0000878 bool ImmediateClass) {
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000879 // Check and see if instance methods in class interface have been
880 // implemented in the implementation class. If so, their types match.
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000881 for (ObjCInterfaceDecl::instmeth_iterator I = CDecl->instmeth_begin(),
882 E = CDecl->instmeth_end(); I != E; ++I) {
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000883 if (InsMapSeen.count((*I)->getSelector()))
884 continue;
885 InsMapSeen.insert((*I)->getSelector());
Mike Stump1eb44332009-09-09 15:08:12 +0000886 if (!(*I)->isSynthesized() &&
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000887 !InsMap.count((*I)->getSelector())) {
888 if (ImmediateClass)
Fariborz Jahanian52146832010-03-31 18:23:33 +0000889 WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl,
890 diag::note_undef_method_impl);
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000891 continue;
Mike Stumpac5fc7c2009-08-04 21:02:39 +0000892 } else {
Mike Stump1eb44332009-09-09 15:08:12 +0000893 ObjCMethodDecl *ImpMethodDecl =
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000894 IMPDecl->getInstanceMethod((*I)->getSelector());
Mike Stump1eb44332009-09-09 15:08:12 +0000895 ObjCMethodDecl *IntfMethodDecl =
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000896 CDecl->getInstanceMethod((*I)->getSelector());
Mike Stump1eb44332009-09-09 15:08:12 +0000897 assert(IntfMethodDecl &&
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000898 "IntfMethodDecl is null in ImplMethodsVsClassMethods");
899 // ImpMethodDecl may be null as in a @dynamic property.
900 if (ImpMethodDecl)
901 WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl);
902 }
903 }
Mike Stump1eb44332009-09-09 15:08:12 +0000904
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000905 // Check and see if class methods in class interface have been
906 // implemented in the implementation class. If so, their types match.
Mike Stump1eb44332009-09-09 15:08:12 +0000907 for (ObjCInterfaceDecl::classmeth_iterator
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000908 I = CDecl->classmeth_begin(), E = CDecl->classmeth_end(); I != E; ++I) {
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000909 if (ClsMapSeen.count((*I)->getSelector()))
910 continue;
911 ClsMapSeen.insert((*I)->getSelector());
912 if (!ClsMap.count((*I)->getSelector())) {
913 if (ImmediateClass)
Fariborz Jahanian52146832010-03-31 18:23:33 +0000914 WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl,
915 diag::note_undef_method_impl);
Mike Stumpac5fc7c2009-08-04 21:02:39 +0000916 } else {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000917 ObjCMethodDecl *ImpMethodDecl =
918 IMPDecl->getClassMethod((*I)->getSelector());
Mike Stump1eb44332009-09-09 15:08:12 +0000919 ObjCMethodDecl *IntfMethodDecl =
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000920 CDecl->getClassMethod((*I)->getSelector());
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000921 WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl);
922 }
923 }
924 if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl> (CDecl)) {
925 // Check for any implementation of a methods declared in protocol.
Ted Kremenek53b94412010-09-01 01:21:15 +0000926 for (ObjCInterfaceDecl::all_protocol_iterator
927 PI = I->all_referenced_protocol_begin(),
928 E = I->all_referenced_protocol_end(); PI != E; ++PI)
Mike Stump1eb44332009-09-09 15:08:12 +0000929 MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen,
930 IMPDecl,
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000931 (*PI), IncompleteImpl, false);
932 if (I->getSuperClass())
933 MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen,
Mike Stump1eb44332009-09-09 15:08:12 +0000934 IMPDecl,
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000935 I->getSuperClass(), IncompleteImpl, false);
936 }
937}
938
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000939void Sema::ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl,
Mike Stump1eb44332009-09-09 15:08:12 +0000940 ObjCContainerDecl* CDecl,
Chris Lattnercddc8882009-03-01 00:56:52 +0000941 bool IncompleteImpl) {
Chris Lattner4d391482007-12-12 07:09:47 +0000942 llvm::DenseSet<Selector> InsMap;
943 // Check and see if instance methods in class interface have been
944 // implemented in the implementation class.
Mike Stump1eb44332009-09-09 15:08:12 +0000945 for (ObjCImplementationDecl::instmeth_iterator
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000946 I = IMPDecl->instmeth_begin(), E = IMPDecl->instmeth_end(); I!=E; ++I)
Chris Lattner4c525092007-12-12 17:58:05 +0000947 InsMap.insert((*I)->getSelector());
Mike Stump1eb44332009-09-09 15:08:12 +0000948
Fariborz Jahanian12bac252009-04-14 23:15:21 +0000949 // Check and see if properties declared in the interface have either 1)
950 // an implementation or 2) there is a @synthesize/@dynamic implementation
951 // of the property in the @implementation.
Fariborz Jahanian509d4772010-05-14 18:35:57 +0000952 if (isa<ObjCInterfaceDecl>(CDecl) && !LangOpts.ObjCNonFragileABI2)
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000953 DiagnoseUnimplementedProperties(S, IMPDecl, CDecl, InsMap);
Fariborz Jahanian3ac1eda2010-01-20 01:51:55 +0000954
Chris Lattner4d391482007-12-12 07:09:47 +0000955 llvm::DenseSet<Selector> ClsMap;
Mike Stump1eb44332009-09-09 15:08:12 +0000956 for (ObjCImplementationDecl::classmeth_iterator
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000957 I = IMPDecl->classmeth_begin(),
958 E = IMPDecl->classmeth_end(); I != E; ++I)
Chris Lattner4c525092007-12-12 17:58:05 +0000959 ClsMap.insert((*I)->getSelector());
Mike Stump1eb44332009-09-09 15:08:12 +0000960
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000961 // Check for type conflict of methods declared in a class/protocol and
962 // its implementation; if any.
963 llvm::DenseSet<Selector> InsMapSeen, ClsMapSeen;
Mike Stump1eb44332009-09-09 15:08:12 +0000964 MatchAllMethodDeclarations(InsMap, ClsMap, InsMapSeen, ClsMapSeen,
965 IMPDecl, CDecl,
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000966 IncompleteImpl, true);
Mike Stump1eb44332009-09-09 15:08:12 +0000967
Chris Lattner4d391482007-12-12 07:09:47 +0000968 // Check the protocol list for unimplemented methods in the @implementation
969 // class.
Fariborz Jahanianb33f3ad2009-05-01 20:07:12 +0000970 // Check and see if class methods in class interface have been
971 // implemented in the implementation class.
Mike Stump1eb44332009-09-09 15:08:12 +0000972
Chris Lattnercddc8882009-03-01 00:56:52 +0000973 if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl> (CDecl)) {
Ted Kremenek53b94412010-09-01 01:21:15 +0000974 for (ObjCInterfaceDecl::all_protocol_iterator
975 PI = I->all_referenced_protocol_begin(),
976 E = I->all_referenced_protocol_end(); PI != E; ++PI)
Mike Stump1eb44332009-09-09 15:08:12 +0000977 CheckProtocolMethodDefs(IMPDecl->getLocation(), *PI, IncompleteImpl,
Chris Lattnercddc8882009-03-01 00:56:52 +0000978 InsMap, ClsMap, I);
979 // Check class extensions (unnamed categories)
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000980 for (const ObjCCategoryDecl *Categories = I->getFirstClassExtension();
981 Categories; Categories = Categories->getNextClassExtension())
982 ImplMethodsVsClassMethods(S, IMPDecl,
983 const_cast<ObjCCategoryDecl*>(Categories),
984 IncompleteImpl);
Chris Lattnercddc8882009-03-01 00:56:52 +0000985 } else if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(CDecl)) {
Fariborz Jahanianb106fc62009-10-05 21:32:49 +0000986 // For extended class, unimplemented methods in its protocols will
987 // be reported in the primary class.
Fariborz Jahanian25760612010-02-15 21:55:26 +0000988 if (!C->IsClassExtension()) {
Fariborz Jahanianb106fc62009-10-05 21:32:49 +0000989 for (ObjCCategoryDecl::protocol_iterator PI = C->protocol_begin(),
990 E = C->protocol_end(); PI != E; ++PI)
991 CheckProtocolMethodDefs(IMPDecl->getLocation(), *PI, IncompleteImpl,
Fariborz Jahanianf2838592010-03-27 21:10:05 +0000992 InsMap, ClsMap, CDecl);
Fariborz Jahanian3ad230e2010-01-20 19:36:21 +0000993 // Report unimplemented properties in the category as well.
994 // When reporting on missing setter/getters, do not report when
995 // setter/getter is implemented in category's primary class
996 // implementation.
997 if (ObjCInterfaceDecl *ID = C->getClassInterface())
998 if (ObjCImplDecl *IMP = ID->getImplementation()) {
999 for (ObjCImplementationDecl::instmeth_iterator
1000 I = IMP->instmeth_begin(), E = IMP->instmeth_end(); I!=E; ++I)
1001 InsMap.insert((*I)->getSelector());
1002 }
Fariborz Jahanian17cb3262010-05-05 21:52:17 +00001003 DiagnoseUnimplementedProperties(S, IMPDecl, CDecl, InsMap);
Fariborz Jahanian3ad230e2010-01-20 19:36:21 +00001004 }
Chris Lattnercddc8882009-03-01 00:56:52 +00001005 } else
1006 assert(false && "invalid ObjCContainerDecl type.");
Chris Lattner4d391482007-12-12 07:09:47 +00001007}
1008
Mike Stump1eb44332009-09-09 15:08:12 +00001009/// ActOnForwardClassDeclaration -
John McCalld226f652010-08-21 09:40:31 +00001010Decl *
Chris Lattner4d391482007-12-12 07:09:47 +00001011Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
Chris Lattnerbdbde4d2009-02-16 19:25:52 +00001012 IdentifierInfo **IdentList,
Ted Kremenekc09cba62009-11-17 23:12:20 +00001013 SourceLocation *IdentLocs,
Chris Lattnerbdbde4d2009-02-16 19:25:52 +00001014 unsigned NumElts) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001015 llvm::SmallVector<ObjCInterfaceDecl*, 32> Interfaces;
Mike Stump1eb44332009-09-09 15:08:12 +00001016
Chris Lattner4d391482007-12-12 07:09:47 +00001017 for (unsigned i = 0; i != NumElts; ++i) {
1018 // Check for another declaration kind with the same name.
John McCallf36e02d2009-10-09 21:13:30 +00001019 NamedDecl *PrevDecl
Douglas Gregorc83c6872010-04-15 22:33:43 +00001020 = LookupSingleName(TUScope, IdentList[i], IdentLocs[i],
Douglas Gregorc0b39642010-04-15 23:40:53 +00001021 LookupOrdinaryName, ForRedeclaration);
Douglas Gregorf57172b2008-12-08 18:40:42 +00001022 if (PrevDecl && PrevDecl->isTemplateParameter()) {
Douglas Gregor72c3f312008-12-05 18:15:24 +00001023 // Maybe we will complain about the shadowed template parameter.
1024 DiagnoseTemplateParameterShadow(AtClassLoc, PrevDecl);
1025 // Just pretend that we didn't see the previous declaration.
1026 PrevDecl = 0;
1027 }
1028
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001029 if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
Steve Naroffc7333882008-06-05 22:57:10 +00001030 // GCC apparently allows the following idiom:
1031 //
1032 // typedef NSObject < XCElementTogglerP > XCElementToggler;
1033 // @class XCElementToggler;
1034 //
Mike Stump1eb44332009-09-09 15:08:12 +00001035 // FIXME: Make an extension?
Steve Naroffc7333882008-06-05 22:57:10 +00001036 TypedefDecl *TDD = dyn_cast<TypedefDecl>(PrevDecl);
John McCallc12c5bb2010-05-15 11:32:37 +00001037 if (!TDD || !TDD->getUnderlyingType()->isObjCObjectType()) {
Chris Lattner3c73c412008-11-19 08:23:25 +00001038 Diag(AtClassLoc, diag::err_redefinition_different_kind) << IdentList[i];
Chris Lattner5f4a6822008-11-23 23:12:31 +00001039 Diag(PrevDecl->getLocation(), diag::note_previous_definition);
John McCallc12c5bb2010-05-15 11:32:37 +00001040 } else {
Mike Stumpac5fc7c2009-08-04 21:02:39 +00001041 // a forward class declaration matching a typedef name of a class refers
1042 // to the underlying class.
John McCallc12c5bb2010-05-15 11:32:37 +00001043 if (const ObjCObjectType *OI =
1044 TDD->getUnderlyingType()->getAs<ObjCObjectType>())
1045 PrevDecl = OI->getInterface();
Fariborz Jahaniancae27c52009-05-07 21:49:26 +00001046 }
Chris Lattner4d391482007-12-12 07:09:47 +00001047 }
Douglas Gregordeacbdc2010-08-11 12:19:30 +00001048 ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
1049 if (!IDecl) { // Not already seen? Make a forward decl.
1050 IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassLoc,
1051 IdentList[i], IdentLocs[i], true);
1052
1053 // Push the ObjCInterfaceDecl on the scope chain but do *not* add it to
1054 // the current DeclContext. This prevents clients that walk DeclContext
1055 // from seeing the imaginary ObjCInterfaceDecl until it is actually
1056 // declared later (if at all). We also take care to explicitly make
1057 // sure this declaration is visible for name lookup.
1058 PushOnScopeChains(IDecl, TUScope, false);
1059 CurContext->makeDeclVisibleInContext(IDecl, true);
1060 }
Chris Lattner4d391482007-12-12 07:09:47 +00001061
1062 Interfaces.push_back(IDecl);
1063 }
Mike Stump1eb44332009-09-09 15:08:12 +00001064
Ted Kremenek321c22f2009-11-18 00:28:11 +00001065 assert(Interfaces.size() == NumElts);
Douglas Gregord0434102009-01-09 00:49:46 +00001066 ObjCClassDecl *CDecl = ObjCClassDecl::Create(Context, CurContext, AtClassLoc,
Ted Kremenek321c22f2009-11-18 00:28:11 +00001067 Interfaces.data(), IdentLocs,
Anders Carlsson15281452008-11-04 16:57:32 +00001068 Interfaces.size());
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001069 CurContext->addDecl(CDecl);
Anders Carlsson15281452008-11-04 16:57:32 +00001070 CheckObjCDeclScope(CDecl);
John McCalld226f652010-08-21 09:40:31 +00001071 return CDecl;
Chris Lattner4d391482007-12-12 07:09:47 +00001072}
1073
1074
1075/// MatchTwoMethodDeclarations - Checks that two methods have matching type and
1076/// returns true, or false, accordingly.
1077/// TODO: Handle protocol list; such as id<p1,p2> in type comparisons
Mike Stump1eb44332009-09-09 15:08:12 +00001078bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
Steve Narofffe6b0dc2008-10-21 10:37:50 +00001079 const ObjCMethodDecl *PrevMethod,
Fariborz Jahanian6b308f62010-08-09 23:27:58 +00001080 bool matchBasedOnSizeAndAlignment,
1081 bool matchBasedOnStrictEqulity) {
Steve Narofffe6b0dc2008-10-21 10:37:50 +00001082 QualType T1 = Context.getCanonicalType(Method->getResultType());
1083 QualType T2 = Context.getCanonicalType(PrevMethod->getResultType());
Mike Stump1eb44332009-09-09 15:08:12 +00001084
Steve Narofffe6b0dc2008-10-21 10:37:50 +00001085 if (T1 != T2) {
1086 // The result types are different.
Fariborz Jahanian6b308f62010-08-09 23:27:58 +00001087 if (!matchBasedOnSizeAndAlignment || matchBasedOnStrictEqulity)
Chris Lattner4d391482007-12-12 07:09:47 +00001088 return false;
Steve Narofffe6b0dc2008-10-21 10:37:50 +00001089 // Incomplete types don't have a size and alignment.
1090 if (T1->isIncompleteType() || T2->isIncompleteType())
1091 return false;
1092 // Check is based on size and alignment.
1093 if (Context.getTypeInfo(T1) != Context.getTypeInfo(T2))
1094 return false;
1095 }
Mike Stump1eb44332009-09-09 15:08:12 +00001096
Chris Lattner89951a82009-02-20 18:43:26 +00001097 ObjCMethodDecl::param_iterator ParamI = Method->param_begin(),
1098 E = Method->param_end();
1099 ObjCMethodDecl::param_iterator PrevI = PrevMethod->param_begin();
Mike Stump1eb44332009-09-09 15:08:12 +00001100
Chris Lattner89951a82009-02-20 18:43:26 +00001101 for (; ParamI != E; ++ParamI, ++PrevI) {
1102 assert(PrevI != PrevMethod->param_end() && "Param mismatch");
1103 T1 = Context.getCanonicalType((*ParamI)->getType());
1104 T2 = Context.getCanonicalType((*PrevI)->getType());
Steve Narofffe6b0dc2008-10-21 10:37:50 +00001105 if (T1 != T2) {
1106 // The result types are different.
Fariborz Jahanian6b308f62010-08-09 23:27:58 +00001107 if (!matchBasedOnSizeAndAlignment || matchBasedOnStrictEqulity)
Steve Narofffe6b0dc2008-10-21 10:37:50 +00001108 return false;
1109 // Incomplete types don't have a size and alignment.
1110 if (T1->isIncompleteType() || T2->isIncompleteType())
1111 return false;
1112 // Check is based on size and alignment.
1113 if (Context.getTypeInfo(T1) != Context.getTypeInfo(T2))
1114 return false;
1115 }
Chris Lattner4d391482007-12-12 07:09:47 +00001116 }
1117 return true;
1118}
1119
Sebastian Redldb9d2142010-08-02 23:18:59 +00001120/// \brief Read the contents of the method pool for a given selector from
1121/// external storage.
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +00001122///
Sebastian Redldb9d2142010-08-02 23:18:59 +00001123/// This routine should only be called once, when the method pool has no entry
1124/// for this selector.
1125Sema::GlobalMethodPool::iterator Sema::ReadMethodPool(Selector Sel) {
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +00001126 assert(ExternalSource && "We need an external AST source");
Sebastian Redldb9d2142010-08-02 23:18:59 +00001127 assert(MethodPool.find(Sel) == MethodPool.end() &&
1128 "Selector data already loaded into the method pool");
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +00001129
1130 // Read the method list from the external source.
Sebastian Redldb9d2142010-08-02 23:18:59 +00001131 GlobalMethods Methods = ExternalSource->ReadMethodPool(Sel);
Mike Stump1eb44332009-09-09 15:08:12 +00001132
Sebastian Redldb9d2142010-08-02 23:18:59 +00001133 return MethodPool.insert(std::make_pair(Sel, Methods)).first;
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +00001134}
1135
Sebastian Redldb9d2142010-08-02 23:18:59 +00001136void Sema::AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl,
1137 bool instance) {
1138 GlobalMethodPool::iterator Pos = MethodPool.find(Method->getSelector());
1139 if (Pos == MethodPool.end()) {
1140 if (ExternalSource)
1141 Pos = ReadMethodPool(Method->getSelector());
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +00001142 else
Sebastian Redldb9d2142010-08-02 23:18:59 +00001143 Pos = MethodPool.insert(std::make_pair(Method->getSelector(),
1144 GlobalMethods())).first;
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +00001145 }
Fariborz Jahanian3fe10412010-07-22 18:24:20 +00001146 Method->setDefined(impl);
Sebastian Redldb9d2142010-08-02 23:18:59 +00001147 ObjCMethodList &Entry = instance ? Pos->second.first : Pos->second.second;
Chris Lattnerb25df352009-03-04 05:16:45 +00001148 if (Entry.Method == 0) {
Chris Lattner4d391482007-12-12 07:09:47 +00001149 // Haven't seen a method with this selector name yet - add it.
Chris Lattnerb25df352009-03-04 05:16:45 +00001150 Entry.Method = Method;
1151 Entry.Next = 0;
1152 return;
Chris Lattner4d391482007-12-12 07:09:47 +00001153 }
Mike Stump1eb44332009-09-09 15:08:12 +00001154
Chris Lattnerb25df352009-03-04 05:16:45 +00001155 // We've seen a method with this name, see if we have already seen this type
1156 // signature.
1157 for (ObjCMethodList *List = &Entry; List; List = List->Next)
Fariborz Jahanian3fe10412010-07-22 18:24:20 +00001158 if (MatchTwoMethodDeclarations(Method, List->Method)) {
1159 List->Method->setDefined(impl);
Chris Lattnerb25df352009-03-04 05:16:45 +00001160 return;
Fariborz Jahanian3fe10412010-07-22 18:24:20 +00001161 }
Mike Stump1eb44332009-09-09 15:08:12 +00001162
Chris Lattnerb25df352009-03-04 05:16:45 +00001163 // We have a new signature for an existing method - add it.
1164 // This is extremely rare. Only 1% of Cocoa selectors are "overloaded".
Ted Kremenek298ed872010-02-11 00:53:01 +00001165 ObjCMethodList *Mem = BumpAlloc.Allocate<ObjCMethodList>();
1166 Entry.Next = new (Mem) ObjCMethodList(Method, Entry.Next);
Chris Lattner4d391482007-12-12 07:09:47 +00001167}
1168
Sebastian Redldb9d2142010-08-02 23:18:59 +00001169ObjCMethodDecl *Sema::LookupMethodInGlobalPool(Selector Sel, SourceRange R,
Fariborz Jahanian6b308f62010-08-09 23:27:58 +00001170 bool receiverIdOrClass,
Sebastian Redldb9d2142010-08-02 23:18:59 +00001171 bool warn, bool instance) {
1172 GlobalMethodPool::iterator Pos = MethodPool.find(Sel);
1173 if (Pos == MethodPool.end()) {
1174 if (ExternalSource)
1175 Pos = ReadMethodPool(Sel);
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +00001176 else
1177 return 0;
1178 }
1179
Sebastian Redldb9d2142010-08-02 23:18:59 +00001180 ObjCMethodList &MethList = instance ? Pos->second.first : Pos->second.second;
Mike Stump1eb44332009-09-09 15:08:12 +00001181
Fariborz Jahanian6b308f62010-08-09 23:27:58 +00001182 bool strictSelectorMatch = receiverIdOrClass && warn &&
1183 (Diags.getDiagnosticLevel(diag::warn_strict_multiple_method_decl) !=
1184 Diagnostic::Ignored);
Sebastian Redldb9d2142010-08-02 23:18:59 +00001185 if (warn && MethList.Method && MethList.Next) {
1186 bool issueWarning = false;
Fariborz Jahanian6b308f62010-08-09 23:27:58 +00001187 if (strictSelectorMatch)
1188 for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next) {
1189 // This checks if the methods differ in type mismatch.
1190 if (!MatchTwoMethodDeclarations(MethList.Method, Next->Method, false, true))
1191 issueWarning = true;
1192 }
1193
1194 if (!issueWarning)
1195 for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next) {
1196 // This checks if the methods differ by size & alignment.
1197 if (!MatchTwoMethodDeclarations(MethList.Method, Next->Method, true))
1198 issueWarning = true;
1199 }
1200
Sebastian Redldb9d2142010-08-02 23:18:59 +00001201 if (issueWarning) {
Fariborz Jahanian6b308f62010-08-09 23:27:58 +00001202 if (strictSelectorMatch)
1203 Diag(R.getBegin(), diag::warn_strict_multiple_method_decl) << Sel << R;
1204 else
1205 Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel << R;
Sebastian Redldb9d2142010-08-02 23:18:59 +00001206 Diag(MethList.Method->getLocStart(), diag::note_using)
1207 << MethList.Method->getSourceRange();
1208 for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next)
1209 Diag(Next->Method->getLocStart(), diag::note_also_found)
1210 << Next->Method->getSourceRange();
1211 }
Douglas Gregorf0aaf7a2009-04-24 21:10:55 +00001212 }
1213 return MethList.Method;
1214}
1215
Fariborz Jahanian3fe10412010-07-22 18:24:20 +00001216ObjCMethodDecl *Sema::LookupImplementedMethodInGlobalPool(Selector Sel) {
Sebastian Redldb9d2142010-08-02 23:18:59 +00001217 GlobalMethodPool::iterator Pos = MethodPool.find(Sel);
1218 if (Pos == MethodPool.end())
1219 return 0;
1220
1221 GlobalMethods &Methods = Pos->second;
1222
1223 if (Methods.first.Method && Methods.first.Method->isDefined())
1224 return Methods.first.Method;
1225 if (Methods.second.Method && Methods.second.Method->isDefined())
1226 return Methods.second.Method;
Fariborz Jahanian3fe10412010-07-22 18:24:20 +00001227 return 0;
1228}
1229
Fariborz Jahaniane198f5d2009-08-04 17:01:09 +00001230/// CompareMethodParamsInBaseAndSuper - This routine compares methods with
1231/// identical selector names in current and its super classes and issues
1232/// a warning if any of their argument types are incompatible.
Fariborz Jahaniandbdec8b2009-08-04 01:07:16 +00001233void Sema::CompareMethodParamsInBaseAndSuper(Decl *ClassDecl,
1234 ObjCMethodDecl *Method,
1235 bool IsInstance) {
Fariborz Jahaniane198f5d2009-08-04 17:01:09 +00001236 ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(ClassDecl);
1237 if (ID == 0) return;
Mike Stump1eb44332009-09-09 15:08:12 +00001238
Fariborz Jahaniane198f5d2009-08-04 17:01:09 +00001239 while (ObjCInterfaceDecl *SD = ID->getSuperClass()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001240 ObjCMethodDecl *SuperMethodDecl =
Fariborz Jahaniane198f5d2009-08-04 17:01:09 +00001241 SD->lookupMethod(Method->getSelector(), IsInstance);
1242 if (SuperMethodDecl == 0) {
Fariborz Jahaniandbdec8b2009-08-04 01:07:16 +00001243 ID = SD;
Fariborz Jahaniane198f5d2009-08-04 17:01:09 +00001244 continue;
Fariborz Jahaniandbdec8b2009-08-04 01:07:16 +00001245 }
Fariborz Jahaniane198f5d2009-08-04 17:01:09 +00001246 ObjCMethodDecl::param_iterator ParamI = Method->param_begin(),
1247 E = Method->param_end();
1248 ObjCMethodDecl::param_iterator PrevI = SuperMethodDecl->param_begin();
1249 for (; ParamI != E; ++ParamI, ++PrevI) {
1250 // Number of parameters are the same and is guaranteed by selector match.
1251 assert(PrevI != SuperMethodDecl->param_end() && "Param mismatch");
1252 QualType T1 = Context.getCanonicalType((*ParamI)->getType());
1253 QualType T2 = Context.getCanonicalType((*PrevI)->getType());
1254 // If type of arguement of method in this class does not match its
1255 // respective argument type in the super class method, issue warning;
1256 if (!Context.typesAreCompatible(T1, T2)) {
Mike Stump1eb44332009-09-09 15:08:12 +00001257 Diag((*ParamI)->getLocation(), diag::ext_typecheck_base_super)
Fariborz Jahaniane198f5d2009-08-04 17:01:09 +00001258 << T1 << T2;
1259 Diag(SuperMethodDecl->getLocation(), diag::note_previous_declaration);
1260 return;
1261 }
1262 }
1263 ID = SD;
1264 }
Fariborz Jahaniandbdec8b2009-08-04 01:07:16 +00001265}
1266
Fariborz Jahanianf914b972010-02-23 23:41:11 +00001267/// DiagnoseDuplicateIvars -
1268/// Check for duplicate ivars in the entire class at the start of
1269/// @implementation. This becomes necesssary because class extension can
1270/// add ivars to a class in random order which will not be known until
1271/// class's @implementation is seen.
1272void Sema::DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID,
1273 ObjCInterfaceDecl *SID) {
1274 for (ObjCInterfaceDecl::ivar_iterator IVI = ID->ivar_begin(),
1275 IVE = ID->ivar_end(); IVI != IVE; ++IVI) {
1276 ObjCIvarDecl* Ivar = (*IVI);
1277 if (Ivar->isInvalidDecl())
1278 continue;
1279 if (IdentifierInfo *II = Ivar->getIdentifier()) {
1280 ObjCIvarDecl* prevIvar = SID->lookupInstanceVariable(II);
1281 if (prevIvar) {
1282 Diag(Ivar->getLocation(), diag::err_duplicate_member) << II;
1283 Diag(prevIvar->getLocation(), diag::note_previous_declaration);
1284 Ivar->setInvalidDecl();
1285 }
1286 }
1287 }
1288}
1289
Steve Naroffa56f6162007-12-18 01:30:32 +00001290// Note: For class/category implemenations, allMethods/allProperties is
1291// always null.
Fariborz Jahanian17cb3262010-05-05 21:52:17 +00001292void Sema::ActOnAtEnd(Scope *S, SourceRange AtEnd,
John McCalld226f652010-08-21 09:40:31 +00001293 Decl *ClassDecl,
1294 Decl **allMethods, unsigned allNum,
1295 Decl **allProperties, unsigned pNum,
Chris Lattner682bf922009-03-29 16:50:03 +00001296 DeclGroupPtrTy *allTUVars, unsigned tuvNum) {
Steve Naroffa56f6162007-12-18 01:30:32 +00001297 // FIXME: If we don't have a ClassDecl, we have an error. We should consider
1298 // always passing in a decl. If the decl has an error, isInvalidDecl()
Chris Lattner4d391482007-12-12 07:09:47 +00001299 // should be true.
1300 if (!ClassDecl)
1301 return;
Fariborz Jahanian63e963c2009-11-16 18:57:01 +00001302
Mike Stump1eb44332009-09-09 15:08:12 +00001303 bool isInterfaceDeclKind =
Chris Lattnerf8d17a52008-03-16 21:17:37 +00001304 isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl)
1305 || isa<ObjCProtocolDecl>(ClassDecl);
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001306 bool checkIdenticalMethods = isa<ObjCImplementationDecl>(ClassDecl);
Steve Naroff09c47192009-01-09 15:36:25 +00001307
Ted Kremenek782f2f52010-01-07 01:20:12 +00001308 if (!isInterfaceDeclKind && AtEnd.isInvalid()) {
1309 // FIXME: This is wrong. We shouldn't be pretending that there is
1310 // an '@end' in the declaration.
1311 SourceLocation L = ClassDecl->getLocation();
1312 AtEnd.setBegin(L);
1313 AtEnd.setEnd(L);
1314 Diag(L, diag::warn_missing_atend);
Fariborz Jahanian63e963c2009-11-16 18:57:01 +00001315 }
1316
Steve Naroff0701bbb2009-01-08 17:28:14 +00001317 DeclContext *DC = dyn_cast<DeclContext>(ClassDecl);
Steve Naroff0701bbb2009-01-08 17:28:14 +00001318
1319 // FIXME: Remove these and use the ObjCContainerDecl/DeclContext.
1320 llvm::DenseMap<Selector, const ObjCMethodDecl*> InsMap;
1321 llvm::DenseMap<Selector, const ObjCMethodDecl*> ClsMap;
1322
Chris Lattner4d391482007-12-12 07:09:47 +00001323 for (unsigned i = 0; i < allNum; i++ ) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001324 ObjCMethodDecl *Method =
John McCalld226f652010-08-21 09:40:31 +00001325 cast_or_null<ObjCMethodDecl>(allMethods[i]);
Chris Lattner4d391482007-12-12 07:09:47 +00001326
1327 if (!Method) continue; // Already issued a diagnostic.
Douglas Gregorf8d49f62009-01-09 17:18:27 +00001328 if (Method->isInstanceMethod()) {
Chris Lattner4d391482007-12-12 07:09:47 +00001329 /// Check for instance method of the same name with incompatible types
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001330 const ObjCMethodDecl *&PrevMethod = InsMap[Method->getSelector()];
Mike Stump1eb44332009-09-09 15:08:12 +00001331 bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod)
Chris Lattner4d391482007-12-12 07:09:47 +00001332 : false;
Mike Stump1eb44332009-09-09 15:08:12 +00001333 if ((isInterfaceDeclKind && PrevMethod && !match)
Eli Friedman82b4e762008-12-16 20:15:50 +00001334 || (checkIdenticalMethods && match)) {
Chris Lattner5f4a6822008-11-23 23:12:31 +00001335 Diag(Method->getLocation(), diag::err_duplicate_method_decl)
Chris Lattner077bf5e2008-11-24 03:33:13 +00001336 << Method->getDeclName();
Chris Lattner5f4a6822008-11-23 23:12:31 +00001337 Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
Chris Lattner4d391482007-12-12 07:09:47 +00001338 } else {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001339 DC->addDecl(Method);
Chris Lattner4d391482007-12-12 07:09:47 +00001340 InsMap[Method->getSelector()] = Method;
1341 /// The following allows us to typecheck messages to "id".
1342 AddInstanceMethodToGlobalPool(Method);
Mike Stump1eb44332009-09-09 15:08:12 +00001343 // verify that the instance method conforms to the same definition of
Fariborz Jahaniane198f5d2009-08-04 17:01:09 +00001344 // parent methods if it shadows one.
Fariborz Jahaniandbdec8b2009-08-04 01:07:16 +00001345 CompareMethodParamsInBaseAndSuper(ClassDecl, Method, true);
Chris Lattner4d391482007-12-12 07:09:47 +00001346 }
Mike Stumpac5fc7c2009-08-04 21:02:39 +00001347 } else {
Chris Lattner4d391482007-12-12 07:09:47 +00001348 /// Check for class method of the same name with incompatible types
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001349 const ObjCMethodDecl *&PrevMethod = ClsMap[Method->getSelector()];
Mike Stump1eb44332009-09-09 15:08:12 +00001350 bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod)
Chris Lattner4d391482007-12-12 07:09:47 +00001351 : false;
Mike Stump1eb44332009-09-09 15:08:12 +00001352 if ((isInterfaceDeclKind && PrevMethod && !match)
Eli Friedman82b4e762008-12-16 20:15:50 +00001353 || (checkIdenticalMethods && match)) {
Chris Lattner5f4a6822008-11-23 23:12:31 +00001354 Diag(Method->getLocation(), diag::err_duplicate_method_decl)
Chris Lattner077bf5e2008-11-24 03:33:13 +00001355 << Method->getDeclName();
Chris Lattner5f4a6822008-11-23 23:12:31 +00001356 Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
Chris Lattner4d391482007-12-12 07:09:47 +00001357 } else {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001358 DC->addDecl(Method);
Chris Lattner4d391482007-12-12 07:09:47 +00001359 ClsMap[Method->getSelector()] = Method;
Steve Naroffa56f6162007-12-18 01:30:32 +00001360 /// The following allows us to typecheck messages to "Class".
1361 AddFactoryMethodToGlobalPool(Method);
Mike Stump1eb44332009-09-09 15:08:12 +00001362 // verify that the class method conforms to the same definition of
Fariborz Jahaniane198f5d2009-08-04 17:01:09 +00001363 // parent methods if it shadows one.
Fariborz Jahaniandbdec8b2009-08-04 01:07:16 +00001364 CompareMethodParamsInBaseAndSuper(ClassDecl, Method, false);
Chris Lattner4d391482007-12-12 07:09:47 +00001365 }
1366 }
1367 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001368 if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
Mike Stump1eb44332009-09-09 15:08:12 +00001369 // Compares properties declared in this class to those of its
Fariborz Jahanian02edb982008-05-01 00:03:38 +00001370 // super class.
Fariborz Jahanianaebf0cb2008-05-02 19:17:30 +00001371 ComparePropertiesInBaseAndSuper(I);
John McCalld226f652010-08-21 09:40:31 +00001372 CompareProperties(I, I);
Steve Naroff09c47192009-01-09 15:36:25 +00001373 } else if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(ClassDecl)) {
Fariborz Jahanian77e14bd2008-12-06 19:59:02 +00001374 // Categories are used to extend the class by declaring new methods.
Mike Stump1eb44332009-09-09 15:08:12 +00001375 // By the same token, they are also used to add new properties. No
Fariborz Jahanian77e14bd2008-12-06 19:59:02 +00001376 // need to compare the added property to those in the class.
Daniel Dunbarb20ef3e2008-08-27 05:40:03 +00001377
Fariborz Jahanian107089f2010-01-18 18:41:16 +00001378 // Compare protocol properties with those in category
John McCalld226f652010-08-21 09:40:31 +00001379 CompareProperties(C, C);
Fariborz Jahanian25760612010-02-15 21:55:26 +00001380 if (C->IsClassExtension())
Fariborz Jahanianb7f95f52009-03-02 19:05:07 +00001381 DiagnoseClassExtensionDupMethods(C, C->getClassInterface());
Chris Lattner4d391482007-12-12 07:09:47 +00001382 }
Steve Naroff09c47192009-01-09 15:36:25 +00001383 if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(ClassDecl)) {
Fariborz Jahanian25760612010-02-15 21:55:26 +00001384 if (CDecl->getIdentifier())
1385 // ProcessPropertyDecl is responsible for diagnosing conflicts with any
1386 // user-defined setter/getter. It also synthesizes setter/getter methods
1387 // and adds them to the DeclContext and global method pools.
1388 for (ObjCContainerDecl::prop_iterator I = CDecl->prop_begin(),
1389 E = CDecl->prop_end();
1390 I != E; ++I)
1391 ProcessPropertyDecl(*I, CDecl);
Ted Kremenek782f2f52010-01-07 01:20:12 +00001392 CDecl->setAtEndRange(AtEnd);
Steve Naroff09c47192009-01-09 15:36:25 +00001393 }
1394 if (ObjCImplementationDecl *IC=dyn_cast<ObjCImplementationDecl>(ClassDecl)) {
Ted Kremenek782f2f52010-01-07 01:20:12 +00001395 IC->setAtEndRange(AtEnd);
Fariborz Jahanian7ca8b062009-11-11 22:40:11 +00001396 if (ObjCInterfaceDecl* IDecl = IC->getClassInterface()) {
Fariborz Jahanian509d4772010-05-14 18:35:57 +00001397 if (LangOpts.ObjCNonFragileABI2)
1398 DefaultSynthesizeProperties(S, IC, IDecl);
Fariborz Jahanian17cb3262010-05-05 21:52:17 +00001399 ImplMethodsVsClassMethods(S, IC, IDecl);
Fariborz Jahanian7ca8b062009-11-11 22:40:11 +00001400 AtomicPropertySetterGetterRules(IC, IDecl);
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001401
Fariborz Jahanianf914b972010-02-23 23:41:11 +00001402 if (LangOpts.ObjCNonFragileABI2)
1403 while (IDecl->getSuperClass()) {
1404 DiagnoseDuplicateIvars(IDecl, IDecl->getSuperClass());
1405 IDecl = IDecl->getSuperClass();
1406 }
Fariborz Jahanian7ca8b062009-11-11 22:40:11 +00001407 }
Fariborz Jahaniane4498c62010-04-28 16:11:27 +00001408 SetIvarInitializers(IC);
Mike Stump1eb44332009-09-09 15:08:12 +00001409 } else if (ObjCCategoryImplDecl* CatImplClass =
Steve Naroff09c47192009-01-09 15:36:25 +00001410 dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) {
Ted Kremenek782f2f52010-01-07 01:20:12 +00001411 CatImplClass->setAtEndRange(AtEnd);
Mike Stump1eb44332009-09-09 15:08:12 +00001412
Chris Lattner4d391482007-12-12 07:09:47 +00001413 // Find category interface decl and then check that all methods declared
Daniel Dunbarb20ef3e2008-08-27 05:40:03 +00001414 // in this interface are implemented in the category @implementation.
Chris Lattner97a58872009-02-16 18:32:47 +00001415 if (ObjCInterfaceDecl* IDecl = CatImplClass->getClassInterface()) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001416 for (ObjCCategoryDecl *Categories = IDecl->getCategoryList();
Chris Lattner4d391482007-12-12 07:09:47 +00001417 Categories; Categories = Categories->getNextClassCategory()) {
1418 if (Categories->getIdentifier() == CatImplClass->getIdentifier()) {
Fariborz Jahanian17cb3262010-05-05 21:52:17 +00001419 ImplMethodsVsClassMethods(S, CatImplClass, Categories);
Chris Lattner4d391482007-12-12 07:09:47 +00001420 break;
1421 }
1422 }
1423 }
1424 }
Chris Lattner682bf922009-03-29 16:50:03 +00001425 if (isInterfaceDeclKind) {
1426 // Reject invalid vardecls.
1427 for (unsigned i = 0; i != tuvNum; i++) {
1428 DeclGroupRef DG = allTUVars[i].getAsVal<DeclGroupRef>();
1429 for (DeclGroupRef::iterator I = DG.begin(), E = DG.end(); I != E; ++I)
1430 if (VarDecl *VDecl = dyn_cast<VarDecl>(*I)) {
Daniel Dunbar5466c7b2009-04-14 02:25:56 +00001431 if (!VDecl->hasExternalStorage())
Steve Naroff87454162009-04-13 17:58:46 +00001432 Diag(VDecl->getLocation(), diag::err_objc_var_decl_inclass);
Fariborz Jahanianb31cb7f2009-03-21 18:06:45 +00001433 }
Chris Lattner682bf922009-03-29 16:50:03 +00001434 }
Fariborz Jahanian38e24c72009-03-18 22:33:24 +00001435 }
Chris Lattner4d391482007-12-12 07:09:47 +00001436}
1437
1438
1439/// CvtQTToAstBitMask - utility routine to produce an AST bitmask for
1440/// objective-c's type qualifier from the parser version of the same info.
Mike Stump1eb44332009-09-09 15:08:12 +00001441static Decl::ObjCDeclQualifier
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001442CvtQTToAstBitMask(ObjCDeclSpec::ObjCDeclQualifier PQTVal) {
1443 Decl::ObjCDeclQualifier ret = Decl::OBJC_TQ_None;
1444 if (PQTVal & ObjCDeclSpec::DQ_In)
1445 ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_In);
1446 if (PQTVal & ObjCDeclSpec::DQ_Inout)
1447 ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Inout);
1448 if (PQTVal & ObjCDeclSpec::DQ_Out)
1449 ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Out);
1450 if (PQTVal & ObjCDeclSpec::DQ_Bycopy)
1451 ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Bycopy);
1452 if (PQTVal & ObjCDeclSpec::DQ_Byref)
1453 ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Byref);
1454 if (PQTVal & ObjCDeclSpec::DQ_Oneway)
1455 ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Oneway);
Chris Lattner4d391482007-12-12 07:09:47 +00001456
1457 return ret;
1458}
1459
Ted Kremenek422bae72010-04-18 04:59:38 +00001460static inline
Sean Huntcf807c42010-08-18 23:23:40 +00001461bool containsInvalidMethodImplAttribute(const AttrVec &A) {
Ted Kremenek422bae72010-04-18 04:59:38 +00001462 // The 'ibaction' attribute is allowed on method definitions because of
1463 // how the IBAction macro is used on both method declarations and definitions.
1464 // If the method definitions contains any other attributes, return true.
Sean Huntcf807c42010-08-18 23:23:40 +00001465 for (AttrVec::const_iterator i = A.begin(), e = A.end(); i != e; ++i)
1466 if ((*i)->getKind() != attr::IBAction)
1467 return true;
1468 return false;
Ted Kremenek422bae72010-04-18 04:59:38 +00001469}
1470
John McCalld226f652010-08-21 09:40:31 +00001471Decl *Sema::ActOnMethodDeclaration(
Chris Lattner4d391482007-12-12 07:09:47 +00001472 SourceLocation MethodLoc, SourceLocation EndLoc,
John McCalld226f652010-08-21 09:40:31 +00001473 tok::TokenKind MethodType, Decl *ClassDecl,
John McCallb3d87482010-08-24 05:47:05 +00001474 ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
Chris Lattner4d391482007-12-12 07:09:47 +00001475 Selector Sel,
1476 // optional arguments. The number of types/arguments is obtained
1477 // from the Sel.getNumArgs().
Chris Lattnere294d3f2009-04-11 18:57:04 +00001478 ObjCArgInfo *ArgInfo,
Fariborz Jahanian4f4fd922010-04-08 00:30:06 +00001479 DeclaratorChunk::ParamInfo *CParamInfo, unsigned CNumArgs, // c-style args
Chris Lattner4d391482007-12-12 07:09:47 +00001480 AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind,
1481 bool isVariadic) {
Steve Naroffda323ad2008-02-29 21:48:07 +00001482 // Make sure we can establish a context for the method.
1483 if (!ClassDecl) {
1484 Diag(MethodLoc, diag::error_missing_method_context);
John McCall781472f2010-08-25 08:40:02 +00001485 getCurFunction()->LabelMap.clear();
John McCalld226f652010-08-21 09:40:31 +00001486 return 0;
Steve Naroffda323ad2008-02-29 21:48:07 +00001487 }
Chris Lattner4d391482007-12-12 07:09:47 +00001488 QualType resultDeclType;
Mike Stump1eb44332009-09-09 15:08:12 +00001489
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001490 TypeSourceInfo *ResultTInfo = 0;
Steve Naroffccef3712009-02-20 22:59:16 +00001491 if (ReturnType) {
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001492 resultDeclType = GetTypeFromParser(ReturnType, &ResultTInfo);
Mike Stump1eb44332009-09-09 15:08:12 +00001493
Steve Naroffccef3712009-02-20 22:59:16 +00001494 // Methods cannot return interface types. All ObjC objects are
1495 // passed by reference.
John McCallc12c5bb2010-05-15 11:32:37 +00001496 if (resultDeclType->isObjCObjectType()) {
Chris Lattner2dd979f2009-04-11 19:08:56 +00001497 Diag(MethodLoc, diag::err_object_cannot_be_passed_returned_by_value)
1498 << 0 << resultDeclType;
John McCalld226f652010-08-21 09:40:31 +00001499 return 0;
Steve Naroffccef3712009-02-20 22:59:16 +00001500 }
1501 } else // get the type for "id".
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001502 resultDeclType = Context.getObjCIdType();
Mike Stump1eb44332009-09-09 15:08:12 +00001503
1504 ObjCMethodDecl* ObjCMethod =
Chris Lattner6c4ae5d2008-03-16 00:49:28 +00001505 ObjCMethodDecl::Create(Context, MethodLoc, EndLoc, Sel, resultDeclType,
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001506 ResultTInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001507 cast<DeclContext>(ClassDecl),
Chris Lattner6c4ae5d2008-03-16 00:49:28 +00001508 MethodType == tok::minus, isVariadic,
Fariborz Jahanian3fe10412010-07-22 18:24:20 +00001509 false, false,
Mike Stump1eb44332009-09-09 15:08:12 +00001510 MethodDeclKind == tok::objc_optional ?
1511 ObjCMethodDecl::Optional :
Chris Lattner6c4ae5d2008-03-16 00:49:28 +00001512 ObjCMethodDecl::Required);
Mike Stump1eb44332009-09-09 15:08:12 +00001513
Chris Lattner0ed844b2008-04-04 06:12:32 +00001514 llvm::SmallVector<ParmVarDecl*, 16> Params;
Mike Stump1eb44332009-09-09 15:08:12 +00001515
Chris Lattner7db638d2009-04-11 19:42:43 +00001516 for (unsigned i = 0, e = Sel.getNumArgs(); i != e; ++i) {
John McCall58e46772009-10-23 21:48:59 +00001517 QualType ArgType;
John McCalla93c9342009-12-07 02:54:59 +00001518 TypeSourceInfo *DI;
Mike Stump1eb44332009-09-09 15:08:12 +00001519
Chris Lattnere294d3f2009-04-11 18:57:04 +00001520 if (ArgInfo[i].Type == 0) {
John McCall58e46772009-10-23 21:48:59 +00001521 ArgType = Context.getObjCIdType();
1522 DI = 0;
Chris Lattnere294d3f2009-04-11 18:57:04 +00001523 } else {
John McCall58e46772009-10-23 21:48:59 +00001524 ArgType = GetTypeFromParser(ArgInfo[i].Type, &DI);
Steve Naroff6082c622008-12-09 19:36:17 +00001525 // Perform the default array/function conversions (C99 6.7.5.3p[7,8]).
Chris Lattnerf97e8fa2009-04-11 19:34:56 +00001526 ArgType = adjustParameterType(ArgType);
Chris Lattnere294d3f2009-04-11 18:57:04 +00001527 }
Mike Stump1eb44332009-09-09 15:08:12 +00001528
John McCall58e46772009-10-23 21:48:59 +00001529 ParmVarDecl* Param
1530 = ParmVarDecl::Create(Context, ObjCMethod, ArgInfo[i].NameLoc,
1531 ArgInfo[i].Name, ArgType, DI,
John McCalld931b082010-08-26 03:08:43 +00001532 SC_None, SC_None, 0);
Mike Stump1eb44332009-09-09 15:08:12 +00001533
John McCallc12c5bb2010-05-15 11:32:37 +00001534 if (ArgType->isObjCObjectType()) {
Chris Lattnerf97e8fa2009-04-11 19:34:56 +00001535 Diag(ArgInfo[i].NameLoc,
1536 diag::err_object_cannot_be_passed_returned_by_value)
1537 << 1 << ArgType;
1538 Param->setInvalidDecl();
1539 }
Mike Stump1eb44332009-09-09 15:08:12 +00001540
Chris Lattner0ed844b2008-04-04 06:12:32 +00001541 Param->setObjCDeclQualifier(
Chris Lattnere294d3f2009-04-11 18:57:04 +00001542 CvtQTToAstBitMask(ArgInfo[i].DeclSpec.getObjCDeclQualifier()));
Mike Stump1eb44332009-09-09 15:08:12 +00001543
Chris Lattnerf97e8fa2009-04-11 19:34:56 +00001544 // Apply the attributes to the parameter.
Douglas Gregor9cdda0c2009-06-17 21:51:59 +00001545 ProcessDeclAttributeList(TUScope, Param, ArgInfo[i].ArgAttrs);
Mike Stump1eb44332009-09-09 15:08:12 +00001546
Chris Lattner0ed844b2008-04-04 06:12:32 +00001547 Params.push_back(Param);
1548 }
1549
Fariborz Jahanian4f4fd922010-04-08 00:30:06 +00001550 for (unsigned i = 0, e = CNumArgs; i != e; ++i) {
John McCalld226f652010-08-21 09:40:31 +00001551 ParmVarDecl *Param = cast<ParmVarDecl>(CParamInfo[i].Param);
Fariborz Jahanian4f4fd922010-04-08 00:30:06 +00001552 QualType ArgType = Param->getType();
1553 if (ArgType.isNull())
1554 ArgType = Context.getObjCIdType();
1555 else
1556 // Perform the default array/function conversions (C99 6.7.5.3p[7,8]).
1557 ArgType = adjustParameterType(ArgType);
John McCallc12c5bb2010-05-15 11:32:37 +00001558 if (ArgType->isObjCObjectType()) {
Fariborz Jahanian4f4fd922010-04-08 00:30:06 +00001559 Diag(Param->getLocation(),
1560 diag::err_object_cannot_be_passed_returned_by_value)
1561 << 1 << ArgType;
1562 Param->setInvalidDecl();
1563 }
1564 Param->setDeclContext(ObjCMethod);
Douglas Gregor59c451e2010-08-07 12:29:18 +00001565 if (Param->getDeclName())
1566 IdResolver.RemoveDecl(Param);
Fariborz Jahanian4f4fd922010-04-08 00:30:06 +00001567 Params.push_back(Param);
1568 }
1569
Fariborz Jahanian4ecb25f2010-04-09 15:40:42 +00001570 ObjCMethod->setMethodParams(Context, Params.data(), Params.size(),
1571 Sel.getNumArgs());
Ted Kremeneka526c5c2008-01-07 19:49:32 +00001572 ObjCMethod->setObjCDeclQualifier(
1573 CvtQTToAstBitMask(ReturnQT.getObjCDeclQualifier()));
1574 const ObjCMethodDecl *PrevMethod = 0;
Daniel Dunbar35682492008-09-26 04:12:28 +00001575
1576 if (AttrList)
Douglas Gregor9cdda0c2009-06-17 21:51:59 +00001577 ProcessDeclAttributeList(TUScope, ObjCMethod, AttrList);
Mike Stump1eb44332009-09-09 15:08:12 +00001578
John McCall54abf7d2009-11-04 02:18:39 +00001579 const ObjCMethodDecl *InterfaceMD = 0;
1580
Mike Stump1eb44332009-09-09 15:08:12 +00001581 // For implementations (which can be very "coarse grain"), we add the
1582 // method now. This allows the AST to implement lookup methods that work
1583 // incrementally (without waiting until we parse the @end). It also allows
Chris Lattner4d391482007-12-12 07:09:47 +00001584 // us to flag multiple declaration errors as they occur.
Mike Stump1eb44332009-09-09 15:08:12 +00001585 if (ObjCImplementationDecl *ImpDecl =
Chris Lattner6c4ae5d2008-03-16 00:49:28 +00001586 dyn_cast<ObjCImplementationDecl>(ClassDecl)) {
Chris Lattner4d391482007-12-12 07:09:47 +00001587 if (MethodType == tok::minus) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001588 PrevMethod = ImpDecl->getInstanceMethod(Sel);
1589 ImpDecl->addInstanceMethod(ObjCMethod);
Chris Lattner4d391482007-12-12 07:09:47 +00001590 } else {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001591 PrevMethod = ImpDecl->getClassMethod(Sel);
1592 ImpDecl->addClassMethod(ObjCMethod);
Chris Lattner4d391482007-12-12 07:09:47 +00001593 }
John McCall54abf7d2009-11-04 02:18:39 +00001594 InterfaceMD = ImpDecl->getClassInterface()->getMethod(Sel,
1595 MethodType == tok::minus);
Sean Huntcf807c42010-08-18 23:23:40 +00001596 if (ObjCMethod->hasAttrs() &&
1597 containsInvalidMethodImplAttribute(ObjCMethod->getAttrs()))
Fariborz Jahanian5d36ac22009-05-12 21:36:23 +00001598 Diag(EndLoc, diag::warn_attribute_method_def);
Mike Stump1eb44332009-09-09 15:08:12 +00001599 } else if (ObjCCategoryImplDecl *CatImpDecl =
Mike Stumpac5fc7c2009-08-04 21:02:39 +00001600 dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) {
Chris Lattner4d391482007-12-12 07:09:47 +00001601 if (MethodType == tok::minus) {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001602 PrevMethod = CatImpDecl->getInstanceMethod(Sel);
1603 CatImpDecl->addInstanceMethod(ObjCMethod);
Chris Lattner4d391482007-12-12 07:09:47 +00001604 } else {
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001605 PrevMethod = CatImpDecl->getClassMethod(Sel);
1606 CatImpDecl->addClassMethod(ObjCMethod);
Chris Lattner4d391482007-12-12 07:09:47 +00001607 }
Sean Huntcf807c42010-08-18 23:23:40 +00001608 if (ObjCMethod->hasAttrs() &&
1609 containsInvalidMethodImplAttribute(ObjCMethod->getAttrs()))
Fariborz Jahanian5d36ac22009-05-12 21:36:23 +00001610 Diag(EndLoc, diag::warn_attribute_method_def);
Chris Lattner4d391482007-12-12 07:09:47 +00001611 }
1612 if (PrevMethod) {
1613 // You can never have two method definitions with the same name.
Chris Lattner5f4a6822008-11-23 23:12:31 +00001614 Diag(ObjCMethod->getLocation(), diag::err_duplicate_method_decl)
Chris Lattner077bf5e2008-11-24 03:33:13 +00001615 << ObjCMethod->getDeclName();
Chris Lattner5f4a6822008-11-23 23:12:31 +00001616 Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
Mike Stump1eb44332009-09-09 15:08:12 +00001617 }
John McCall54abf7d2009-11-04 02:18:39 +00001618
1619 // If the interface declared this method, and it was deprecated there,
1620 // mark it deprecated here.
Sean Huntcf807c42010-08-18 23:23:40 +00001621 if (InterfaceMD)
1622 if (Attr *DA = InterfaceMD->getAttr<DeprecatedAttr>())
1623 ObjCMethod->addAttr(::new (Context) DeprecatedAttr(DA->getLocation(),
1624 Context));
John McCall54abf7d2009-11-04 02:18:39 +00001625
John McCalld226f652010-08-21 09:40:31 +00001626 return ObjCMethod;
Chris Lattner4d391482007-12-12 07:09:47 +00001627}
1628
Chris Lattnercc98eac2008-12-17 07:13:27 +00001629bool Sema::CheckObjCDeclScope(Decl *D) {
Sebastian Redl7a126a42010-08-31 00:36:30 +00001630 if (isa<TranslationUnitDecl>(CurContext->getRedeclContext()))
Anders Carlsson15281452008-11-04 16:57:32 +00001631 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00001632
Anders Carlsson15281452008-11-04 16:57:32 +00001633 Diag(D->getLocation(), diag::err_objc_decls_may_only_appear_in_global_scope);
1634 D->setInvalidDecl();
Mike Stump1eb44332009-09-09 15:08:12 +00001635
Anders Carlsson15281452008-11-04 16:57:32 +00001636 return true;
1637}
Chris Lattnercc98eac2008-12-17 07:13:27 +00001638
Chris Lattnercc98eac2008-12-17 07:13:27 +00001639/// Called whenever @defs(ClassName) is encountered in the source. Inserts the
1640/// instance variables of ClassName into Decls.
John McCalld226f652010-08-21 09:40:31 +00001641void Sema::ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart,
Chris Lattnercc98eac2008-12-17 07:13:27 +00001642 IdentifierInfo *ClassName,
John McCalld226f652010-08-21 09:40:31 +00001643 llvm::SmallVectorImpl<Decl*> &Decls) {
Chris Lattnercc98eac2008-12-17 07:13:27 +00001644 // Check that ClassName is a valid class
Douglas Gregorc83c6872010-04-15 22:33:43 +00001645 ObjCInterfaceDecl *Class = getObjCInterfaceDecl(ClassName, DeclStart);
Chris Lattnercc98eac2008-12-17 07:13:27 +00001646 if (!Class) {
1647 Diag(DeclStart, diag::err_undef_interface) << ClassName;
1648 return;
1649 }
Fariborz Jahanian0468fb92009-04-21 20:28:41 +00001650 if (LangOpts.ObjCNonFragileABI) {
1651 Diag(DeclStart, diag::err_atdef_nonfragile_interface);
1652 return;
1653 }
Mike Stump1eb44332009-09-09 15:08:12 +00001654
Chris Lattnercc98eac2008-12-17 07:13:27 +00001655 // Collect the instance variables
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001656 llvm::SmallVector<ObjCIvarDecl*, 32> Ivars;
1657 Context.DeepCollectObjCIvars(Class, true, Ivars);
Fariborz Jahanian41833352009-06-04 17:08:55 +00001658 // For each ivar, create a fresh ObjCAtDefsFieldDecl.
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001659 for (unsigned i = 0; i < Ivars.size(); i++) {
1660 FieldDecl* ID = cast<FieldDecl>(Ivars[i]);
John McCalld226f652010-08-21 09:40:31 +00001661 RecordDecl *Record = dyn_cast<RecordDecl>(TagD);
Fariborz Jahanian41833352009-06-04 17:08:55 +00001662 Decl *FD = ObjCAtDefsFieldDecl::Create(Context, Record, ID->getLocation(),
1663 ID->getIdentifier(), ID->getType(),
1664 ID->getBitWidth());
John McCalld226f652010-08-21 09:40:31 +00001665 Decls.push_back(FD);
Fariborz Jahanian41833352009-06-04 17:08:55 +00001666 }
Mike Stump1eb44332009-09-09 15:08:12 +00001667
Chris Lattnercc98eac2008-12-17 07:13:27 +00001668 // Introduce all of these fields into the appropriate scope.
John McCalld226f652010-08-21 09:40:31 +00001669 for (llvm::SmallVectorImpl<Decl*>::iterator D = Decls.begin();
Chris Lattnercc98eac2008-12-17 07:13:27 +00001670 D != Decls.end(); ++D) {
John McCalld226f652010-08-21 09:40:31 +00001671 FieldDecl *FD = cast<FieldDecl>(*D);
Chris Lattnercc98eac2008-12-17 07:13:27 +00001672 if (getLangOptions().CPlusPlus)
1673 PushOnScopeChains(cast<FieldDecl>(FD), S);
John McCalld226f652010-08-21 09:40:31 +00001674 else if (RecordDecl *Record = dyn_cast<RecordDecl>(TagD))
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +00001675 Record->addDecl(FD);
Chris Lattnercc98eac2008-12-17 07:13:27 +00001676 }
1677}
1678
Douglas Gregor160b5632010-04-26 17:32:49 +00001679/// \brief Build a type-check a new Objective-C exception variable declaration.
1680VarDecl *Sema::BuildObjCExceptionDecl(TypeSourceInfo *TInfo,
1681 QualType T,
1682 IdentifierInfo *Name,
1683 SourceLocation NameLoc,
1684 bool Invalid) {
1685 // ISO/IEC TR 18037 S6.7.3: "The type of an object with automatic storage
1686 // duration shall not be qualified by an address-space qualifier."
1687 // Since all parameters have automatic store duration, they can not have
1688 // an address space.
1689 if (T.getAddressSpace() != 0) {
1690 Diag(NameLoc, diag::err_arg_with_address_space);
1691 Invalid = true;
1692 }
1693
1694 // An @catch parameter must be an unqualified object pointer type;
1695 // FIXME: Recover from "NSObject foo" by inserting the * in "NSObject *foo"?
1696 if (Invalid) {
1697 // Don't do any further checking.
Douglas Gregorbe270a02010-04-26 17:57:08 +00001698 } else if (T->isDependentType()) {
1699 // Okay: we don't know what this type will instantiate to.
Douglas Gregor160b5632010-04-26 17:32:49 +00001700 } else if (!T->isObjCObjectPointerType()) {
1701 Invalid = true;
1702 Diag(NameLoc ,diag::err_catch_param_not_objc_type);
1703 } else if (T->isObjCQualifiedIdType()) {
1704 Invalid = true;
1705 Diag(NameLoc, diag::err_illegal_qualifiers_on_catch_parm);
1706 }
1707
1708 VarDecl *New = VarDecl::Create(Context, CurContext, NameLoc, Name, T, TInfo,
John McCalld931b082010-08-26 03:08:43 +00001709 SC_None, SC_None);
Douglas Gregor324b54d2010-05-03 18:51:14 +00001710 New->setExceptionVariable(true);
1711
Douglas Gregor160b5632010-04-26 17:32:49 +00001712 if (Invalid)
1713 New->setInvalidDecl();
1714 return New;
1715}
1716
John McCalld226f652010-08-21 09:40:31 +00001717Decl *Sema::ActOnObjCExceptionDecl(Scope *S, Declarator &D) {
Douglas Gregor160b5632010-04-26 17:32:49 +00001718 const DeclSpec &DS = D.getDeclSpec();
1719
1720 // We allow the "register" storage class on exception variables because
1721 // GCC did, but we drop it completely. Any other storage class is an error.
1722 if (DS.getStorageClassSpec() == DeclSpec::SCS_register) {
1723 Diag(DS.getStorageClassSpecLoc(), diag::warn_register_objc_catch_parm)
1724 << FixItHint::CreateRemoval(SourceRange(DS.getStorageClassSpecLoc()));
1725 } else if (DS.getStorageClassSpec() != DeclSpec::SCS_unspecified) {
1726 Diag(DS.getStorageClassSpecLoc(), diag::err_storage_spec_on_catch_parm)
1727 << DS.getStorageClassSpec();
1728 }
1729 if (D.getDeclSpec().isThreadSpecified())
1730 Diag(D.getDeclSpec().getThreadSpecLoc(), diag::err_invalid_thread);
1731 D.getMutableDeclSpec().ClearStorageClassSpecs();
1732
1733 DiagnoseFunctionSpecifiers(D);
1734
1735 // Check that there are no default arguments inside the type of this
1736 // exception object (C++ only).
1737 if (getLangOptions().CPlusPlus)
1738 CheckExtraCXXDefaultArguments(D);
1739
Douglas Gregor160b5632010-04-26 17:32:49 +00001740 TagDecl *OwnedDecl = 0;
John McCallbf1a0282010-06-04 23:28:52 +00001741 TypeSourceInfo *TInfo = GetTypeForDeclarator(D, S, &OwnedDecl);
1742 QualType ExceptionType = TInfo->getType();
Douglas Gregor160b5632010-04-26 17:32:49 +00001743
1744 if (getLangOptions().CPlusPlus && OwnedDecl && OwnedDecl->isDefinition()) {
1745 // Objective-C++: Types shall not be defined in exception types.
1746 Diag(OwnedDecl->getLocation(), diag::err_type_defined_in_param_type)
1747 << Context.getTypeDeclType(OwnedDecl);
1748 }
1749
1750 VarDecl *New = BuildObjCExceptionDecl(TInfo, ExceptionType, D.getIdentifier(),
1751 D.getIdentifierLoc(),
1752 D.isInvalidType());
1753
1754 // Parameter declarators cannot be qualified (C++ [dcl.meaning]p1).
1755 if (D.getCXXScopeSpec().isSet()) {
1756 Diag(D.getIdentifierLoc(), diag::err_qualified_objc_catch_parm)
1757 << D.getCXXScopeSpec().getRange();
1758 New->setInvalidDecl();
1759 }
1760
1761 // Add the parameter declaration into this scope.
John McCalld226f652010-08-21 09:40:31 +00001762 S->AddDecl(New);
Douglas Gregor160b5632010-04-26 17:32:49 +00001763 if (D.getIdentifier())
1764 IdResolver.AddDecl(New);
1765
1766 ProcessDeclAttributes(S, New, D);
1767
1768 if (New->hasAttr<BlocksAttr>())
1769 Diag(New->getLocation(), diag::err_block_on_nonlocal);
John McCalld226f652010-08-21 09:40:31 +00001770 return New;
Douglas Gregor4e6c0d12010-04-23 23:01:43 +00001771}
Fariborz Jahanian786cd152010-04-27 17:18:58 +00001772
1773/// CollectIvarsToConstructOrDestruct - Collect those ivars which require
Fariborz Jahaniane4498c62010-04-28 16:11:27 +00001774/// initialization.
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001775void Sema::CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
Fariborz Jahaniane4498c62010-04-28 16:11:27 +00001776 llvm::SmallVectorImpl<ObjCIvarDecl*> &Ivars) {
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001777 for (ObjCIvarDecl *Iv = OI->all_declared_ivar_begin(); Iv;
1778 Iv= Iv->getNextIvar()) {
Fariborz Jahanian786cd152010-04-27 17:18:58 +00001779 QualType QT = Context.getBaseElementType(Iv->getType());
Douglas Gregor68dd3ee2010-05-20 02:24:22 +00001780 if (QT->isRecordType())
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +00001781 Ivars.push_back(Iv);
Fariborz Jahanian786cd152010-04-27 17:18:58 +00001782 }
1783}
Fariborz Jahaniane4498c62010-04-28 16:11:27 +00001784
1785void ObjCImplementationDecl::setIvarInitializers(ASTContext &C,
1786 CXXBaseOrMemberInitializer ** initializers,
1787 unsigned numInitializers) {
1788 if (numInitializers > 0) {
1789 NumIvarInitializers = numInitializers;
1790 CXXBaseOrMemberInitializer **ivarInitializers =
1791 new (C) CXXBaseOrMemberInitializer*[NumIvarInitializers];
1792 memcpy(ivarInitializers, initializers,
1793 numInitializers * sizeof(CXXBaseOrMemberInitializer*));
1794 IvarInitializers = ivarInitializers;
1795 }
1796}
1797
Fariborz Jahanian3fe10412010-07-22 18:24:20 +00001798void Sema::DiagnoseUseOfUnimplementedSelectors() {
1799 if (ReferencedSelectors.empty())
1800 return;
1801 for (llvm::DenseMap<Selector, SourceLocation>::iterator S =
1802 ReferencedSelectors.begin(),
1803 E = ReferencedSelectors.end(); S != E; ++S) {
1804 Selector Sel = (*S).first;
1805 if (!LookupImplementedMethodInGlobalPool(Sel))
1806 Diag((*S).second, diag::warn_unimplemented_selector) << Sel;
1807 }
1808 return;
1809}