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