2007-12-12 15:09:47 +08:00
|
|
|
//===--- SemaDeclObjC.cpp - Semantic Analysis for ObjC Declarations -------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 03:59:25 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-12-12 15:09:47 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements semantic analysis for Objective C declarations.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Sema.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/DeclObjC.h"
|
2008-08-11 11:27:53 +08:00
|
|
|
#include "clang/Parse/DeclSpec.h"
|
2007-12-12 15:09:47 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
/// ObjCActOnStartOfMethodDef - This routine sets up parameters; invisible
|
2007-12-12 15:09:47 +08:00
|
|
|
/// and user declared, in the method definition's AST.
|
2008-01-08 03:49:32 +08:00
|
|
|
void Sema::ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) {
|
2008-06-28 14:07:14 +08:00
|
|
|
assert(getCurMethodDecl() == 0 && "Method parsing confused");
|
2008-07-26 01:57:26 +08:00
|
|
|
ObjCMethodDecl *MDecl = dyn_cast_or_null<ObjCMethodDecl>((Decl *)D);
|
|
|
|
|
|
|
|
// If we don't have a valid method decl, simply return.
|
|
|
|
if (!MDecl)
|
|
|
|
return;
|
2007-12-18 09:30:32 +08:00
|
|
|
|
|
|
|
// Allow the rest of sema to find private method decl implementations.
|
2009-01-10 01:18:27 +08:00
|
|
|
if (MDecl->isInstanceMethod())
|
2007-12-18 09:30:32 +08:00
|
|
|
AddInstanceMethodToGlobalPool(MDecl);
|
|
|
|
else
|
|
|
|
AddFactoryMethodToGlobalPool(MDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
|
|
|
|
// Allow all of Sema to see that we are entering a method definition.
|
2008-12-12 00:49:14 +08:00
|
|
|
PushDeclContext(FnBodyScope, MDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
|
|
|
|
// Create Decl objects for each parameter, entrring them in the scope for
|
|
|
|
// binding to their use.
|
|
|
|
|
|
|
|
// Insert the invisible arguments, self and _cmd!
|
2008-12-10 04:23:04 +08:00
|
|
|
MDecl->createImplicitParams(Context, MDecl->getClassInterface());
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2008-08-26 14:07:48 +08:00
|
|
|
PushOnScopeChains(MDecl->getSelfDecl(), FnBodyScope);
|
|
|
|
PushOnScopeChains(MDecl->getCmdDecl(), FnBodyScope);
|
2008-04-08 12:40:51 +08:00
|
|
|
|
2008-04-10 10:22:51 +08:00
|
|
|
// Introduce all of the other parameters into this scope.
|
2009-02-21 02:43:26 +08:00
|
|
|
for (ObjCMethodDecl::param_iterator PI = MDecl->param_begin(),
|
|
|
|
E = MDecl->param_end(); PI != E; ++PI)
|
|
|
|
if ((*PI)->getIdentifier())
|
|
|
|
PushOnScopeChains(*PI, FnBodyScope);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
|
2008-07-22 06:17:28 +08:00
|
|
|
Sema::DeclTy *Sema::
|
|
|
|
ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
|
|
|
|
IdentifierInfo *ClassName, SourceLocation ClassLoc,
|
|
|
|
IdentifierInfo *SuperName, SourceLocation SuperLoc,
|
2008-07-26 12:13:19 +08:00
|
|
|
DeclTy * const *ProtoRefs, unsigned NumProtoRefs,
|
2008-07-22 06:17:28 +08:00
|
|
|
SourceLocation EndProtoLoc, AttributeList *AttrList) {
|
2007-12-12 15:09:47 +08:00
|
|
|
assert(ClassName && "Missing class identifier");
|
|
|
|
|
|
|
|
// Check for another declaration kind with the same name.
|
2009-02-05 01:27:36 +08:00
|
|
|
NamedDecl *PrevDecl = LookupName(TUScope, ClassName, LookupOrdinaryName);
|
2008-12-09 02:40:42 +08:00
|
|
|
if (PrevDecl && PrevDecl->isTemplateParameter()) {
|
2008-12-06 02:15:24 +08:00
|
|
|
// Maybe we will complain about the shadowed template parameter.
|
|
|
|
DiagnoseTemplateParameterShadow(ClassLoc, PrevDecl);
|
|
|
|
// Just pretend that we didn't see the previous declaration.
|
|
|
|
PrevDecl = 0;
|
|
|
|
}
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
|
2008-11-24 07:12:31 +08:00
|
|
|
Diag(PrevDecl->getLocation(), diag::note_previous_definition);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCInterfaceDecl* IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
if (IDecl) {
|
|
|
|
// Class already seen. Is it a forward declaration?
|
2008-11-19 03:15:30 +08:00
|
|
|
if (!IDecl->isForwardDecl()) {
|
2008-11-24 13:29:24 +08:00
|
|
|
Diag(AtInterfaceLoc, diag::err_duplicate_class_def)<<IDecl->getDeclName();
|
2008-11-24 06:46:27 +08:00
|
|
|
Diag(IDecl->getLocation(), diag::note_previous_definition);
|
|
|
|
|
2008-11-19 03:15:30 +08:00
|
|
|
// Return the previous class interface.
|
|
|
|
// FIXME: don't leak the objects passed in!
|
|
|
|
return IDecl;
|
|
|
|
} else {
|
2007-12-12 15:09:47 +08:00
|
|
|
IDecl->setLocation(AtInterfaceLoc);
|
|
|
|
IDecl->setForwardDecl(false);
|
|
|
|
}
|
2008-07-21 15:06:49 +08:00
|
|
|
} else {
|
2009-01-09 08:49:46 +08:00
|
|
|
IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtInterfaceLoc,
|
2008-04-12 03:35:35 +08:00
|
|
|
ClassName, ClassLoc);
|
2008-08-21 02:02:42 +08:00
|
|
|
if (AttrList)
|
|
|
|
ProcessDeclAttributeList(IDecl, AttrList);
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2008-04-03 02:30:49 +08:00
|
|
|
ObjCInterfaceDecls[ClassName] = IDecl;
|
2009-01-09 08:49:46 +08:00
|
|
|
// FIXME: PushOnScopeChains
|
2009-01-13 07:27:07 +08:00
|
|
|
CurContext->addDecl(IDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
// Remember that this needs to be removed when the scope is popped.
|
|
|
|
TUScope->AddDecl(IDecl);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SuperName) {
|
|
|
|
// Check if a different kind of symbol declared in this scope.
|
Eliminated LookupCriteria, whose creation was causing a bottleneck for
LookupName et al. Instead, use an enum and a bool to describe its
contents.
Optimized the C/Objective-C path through LookupName, eliminating any
unnecessarily C++isms. Simplify IdentifierResolver::iterator, removing
some code and arguments that are no longer used.
Eliminated LookupDeclInScope/LookupDeclInContext, moving all callers
over to LookupName, LookupQualifiedName, or LookupParsedName, as
appropriate.
All together, I'm seeing a 0.2% speedup on Cocoa.h with PTH and
-disable-free. Plus, we're down to three name-lookup routines.
llvm-svn: 63354
2009-01-30 09:04:22 +08:00
|
|
|
PrevDecl = LookupName(TUScope, SuperName, LookupOrdinaryName);
|
2008-11-19 16:23:25 +08:00
|
|
|
|
2009-02-05 01:14:05 +08:00
|
|
|
ObjCInterfaceDecl *SuperClassDecl =
|
|
|
|
dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
|
2009-02-17 05:33:09 +08:00
|
|
|
|
|
|
|
// Diagnose classes that inherit from deprecated classes.
|
|
|
|
if (SuperClassDecl)
|
2009-02-19 05:56:37 +08:00
|
|
|
(void)DiagnoseUseOfDecl(SuperClassDecl, SuperLoc);
|
2009-02-17 05:33:09 +08:00
|
|
|
|
2009-02-05 01:14:05 +08:00
|
|
|
if (PrevDecl && SuperClassDecl == 0) {
|
|
|
|
// The previous declaration was not a class decl. Check if we have a
|
|
|
|
// typedef. If we do, get the underlying class type.
|
|
|
|
if (const TypedefDecl *TDecl = dyn_cast_or_null<TypedefDecl>(PrevDecl)) {
|
|
|
|
QualType T = TDecl->getUnderlyingType();
|
|
|
|
if (T->isObjCInterfaceType()) {
|
|
|
|
if (NamedDecl *IDecl = T->getAsObjCInterfaceType()->getDecl())
|
|
|
|
SuperClassDecl = dyn_cast<ObjCInterfaceDecl>(IDecl);
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 05:33:09 +08:00
|
|
|
|
2009-02-05 01:14:05 +08:00
|
|
|
// This handles the following case:
|
|
|
|
//
|
|
|
|
// typedef int SuperClass;
|
|
|
|
// @interface MyClass : SuperClass {} @end
|
|
|
|
//
|
|
|
|
if (!SuperClassDecl) {
|
|
|
|
Diag(SuperLoc, diag::err_redefinition_different_kind) << SuperName;
|
|
|
|
Diag(PrevDecl->getLocation(), diag::note_previous_definition);
|
|
|
|
}
|
|
|
|
}
|
2009-02-17 05:33:09 +08:00
|
|
|
|
2009-02-05 01:14:05 +08:00
|
|
|
if (!dyn_cast_or_null<TypedefDecl>(PrevDecl)) {
|
|
|
|
if (!SuperClassDecl)
|
2008-11-19 13:08:23 +08:00
|
|
|
Diag(SuperLoc, diag::err_undef_superclass)
|
2008-11-19 16:23:25 +08:00
|
|
|
<< SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc);
|
2009-02-05 01:14:05 +08:00
|
|
|
else if (SuperClassDecl->isForwardDecl())
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(SuperLoc, diag::err_undef_superclass)
|
2009-02-05 01:14:05 +08:00
|
|
|
<< SuperClassDecl->getDeclName() << ClassName
|
2008-11-19 16:23:25 +08:00
|
|
|
<< SourceRange(AtInterfaceLoc, ClassLoc);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
2009-02-05 01:14:05 +08:00
|
|
|
IDecl->setSuperClass(SuperClassDecl);
|
2008-04-12 03:35:35 +08:00
|
|
|
IDecl->setSuperClassLoc(SuperLoc);
|
2007-12-12 15:09:47 +08:00
|
|
|
IDecl->setLocEnd(SuperLoc);
|
|
|
|
} else { // we have a root class.
|
|
|
|
IDecl->setLocEnd(ClassLoc);
|
|
|
|
}
|
|
|
|
|
2008-11-19 03:15:30 +08:00
|
|
|
/// Check then save referenced protocols.
|
2008-07-26 12:13:19 +08:00
|
|
|
if (NumProtoRefs) {
|
|
|
|
IDecl->addReferencedProtocols((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs);
|
2007-12-12 15:09:47 +08:00
|
|
|
IDecl->setLocEnd(EndProtoLoc);
|
|
|
|
}
|
2008-11-05 00:57:32 +08:00
|
|
|
|
|
|
|
CheckObjCDeclScope(IDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
return IDecl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ActOnCompatiblityAlias - this action is called after complete parsing of
|
2008-09-05 04:01:15 +08:00
|
|
|
/// @compatibility_alias declaration. It sets up the alias relationships.
|
2008-04-02 07:04:06 +08:00
|
|
|
Sema::DeclTy *Sema::ActOnCompatiblityAlias(SourceLocation AtLoc,
|
|
|
|
IdentifierInfo *AliasName,
|
|
|
|
SourceLocation AliasLocation,
|
|
|
|
IdentifierInfo *ClassName,
|
|
|
|
SourceLocation ClassLocation) {
|
2007-12-12 15:09:47 +08:00
|
|
|
// Look for previous declaration of alias name
|
2009-02-05 01:27:36 +08:00
|
|
|
NamedDecl *ADecl = LookupName(TUScope, AliasName, LookupOrdinaryName);
|
2007-12-12 15:09:47 +08:00
|
|
|
if (ADecl) {
|
2008-11-24 07:20:13 +08:00
|
|
|
if (isa<ObjCCompatibleAliasDecl>(ADecl))
|
2007-12-12 15:09:47 +08:00
|
|
|
Diag(AliasLocation, diag::warn_previous_alias_decl);
|
2008-11-24 07:20:13 +08:00
|
|
|
else
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(AliasLocation, diag::err_conflicting_aliasing_type) << AliasName;
|
2008-11-24 07:20:13 +08:00
|
|
|
Diag(ADecl->getLocation(), diag::note_previous_declaration);
|
2007-12-12 15:09:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// Check for class declaration
|
2009-02-05 01:27:36 +08:00
|
|
|
NamedDecl *CDeclU = LookupName(TUScope, ClassName, LookupOrdinaryName);
|
2009-01-08 09:10:55 +08:00
|
|
|
if (const TypedefDecl *TDecl = dyn_cast_or_null<TypedefDecl>(CDeclU)) {
|
|
|
|
QualType T = TDecl->getUnderlyingType();
|
|
|
|
if (T->isObjCInterfaceType()) {
|
|
|
|
if (NamedDecl *IDecl = T->getAsObjCInterfaceType()->getDecl()) {
|
|
|
|
ClassName = IDecl->getIdentifier();
|
Eliminated LookupCriteria, whose creation was causing a bottleneck for
LookupName et al. Instead, use an enum and a bool to describe its
contents.
Optimized the C/Objective-C path through LookupName, eliminating any
unnecessarily C++isms. Simplify IdentifierResolver::iterator, removing
some code and arguments that are no longer used.
Eliminated LookupDeclInScope/LookupDeclInContext, moving all callers
over to LookupName, LookupQualifiedName, or LookupParsedName, as
appropriate.
All together, I'm seeing a 0.2% speedup on Cocoa.h with PTH and
-disable-free. Plus, we're down to three name-lookup routines.
llvm-svn: 63354
2009-01-30 09:04:22 +08:00
|
|
|
CDeclU = LookupName(TUScope, ClassName, LookupOrdinaryName);
|
2009-01-08 09:10:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-17 05:17:37 +08:00
|
|
|
ObjCInterfaceDecl *CDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDeclU);
|
|
|
|
if (CDecl == 0) {
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(ClassLocation, diag::warn_undef_interface) << ClassName;
|
2008-03-17 05:17:37 +08:00
|
|
|
if (CDeclU)
|
2008-11-24 07:20:13 +08:00
|
|
|
Diag(CDeclU->getLocation(), diag::note_previous_declaration);
|
2007-12-12 15:09:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2008-03-17 05:17:37 +08:00
|
|
|
|
|
|
|
// Everything checked out, instantiate a new alias declaration AST.
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCCompatibleAliasDecl *AliasDecl =
|
2009-01-09 08:49:46 +08:00
|
|
|
ObjCCompatibleAliasDecl::Create(Context, CurContext, AtLoc, AliasName, CDecl);
|
2008-04-02 07:04:06 +08:00
|
|
|
|
|
|
|
ObjCAliasDecls[AliasName] = AliasDecl;
|
2009-01-09 08:49:46 +08:00
|
|
|
|
|
|
|
// FIXME: PushOnScopeChains?
|
2009-01-13 07:27:07 +08:00
|
|
|
CurContext->addDecl(AliasDecl);
|
2008-11-05 00:57:32 +08:00
|
|
|
if (!CheckObjCDeclScope(AliasDecl))
|
|
|
|
TUScope->AddDecl(AliasDecl);
|
2009-01-09 08:49:46 +08:00
|
|
|
|
2007-12-12 15:09:47 +08:00
|
|
|
return AliasDecl;
|
|
|
|
}
|
|
|
|
|
2008-07-26 12:03:38 +08:00
|
|
|
Sema::DeclTy *
|
|
|
|
Sema::ActOnStartProtocolInterface(SourceLocation AtProtoInterfaceLoc,
|
|
|
|
IdentifierInfo *ProtocolName,
|
|
|
|
SourceLocation ProtocolLoc,
|
|
|
|
DeclTy * const *ProtoRefs,
|
|
|
|
unsigned NumProtoRefs,
|
2008-09-26 12:48:09 +08:00
|
|
|
SourceLocation EndProtoLoc,
|
|
|
|
AttributeList *AttrList) {
|
|
|
|
// FIXME: Deal with AttrList.
|
2007-12-12 15:09:47 +08:00
|
|
|
assert(ProtocolName && "Missing protocol identifier");
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolName];
|
2007-12-12 15:09:47 +08:00
|
|
|
if (PDecl) {
|
|
|
|
// Protocol already seen. Better be a forward protocol declaration
|
2008-03-16 09:25:17 +08:00
|
|
|
if (!PDecl->isForwardDecl()) {
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(ProtocolLoc, diag::err_duplicate_protocol_def) << ProtocolName;
|
2008-11-24 06:46:27 +08:00
|
|
|
Diag(PDecl->getLocation(), diag::note_previous_definition);
|
2008-03-16 09:25:17 +08:00
|
|
|
// Just return the protocol we already had.
|
|
|
|
// FIXME: don't leak the objects passed in!
|
|
|
|
return PDecl;
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
2008-08-14 00:39:22 +08:00
|
|
|
// Make sure the cached decl gets a valid start location.
|
|
|
|
PDecl->setLocation(AtProtoInterfaceLoc);
|
2008-03-16 09:25:17 +08:00
|
|
|
PDecl->setForwardDecl(false);
|
|
|
|
} else {
|
2009-01-09 08:49:46 +08:00
|
|
|
PDecl = ObjCProtocolDecl::Create(Context, CurContext,
|
|
|
|
AtProtoInterfaceLoc,ProtocolName);
|
|
|
|
// FIXME: PushOnScopeChains?
|
2009-01-13 07:27:07 +08:00
|
|
|
CurContext->addDecl(PDecl);
|
2008-03-17 04:19:15 +08:00
|
|
|
PDecl->setForwardDecl(false);
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCProtocols[ProtocolName] = PDecl;
|
2008-03-16 09:23:04 +08:00
|
|
|
}
|
2008-12-17 09:07:27 +08:00
|
|
|
if (AttrList)
|
|
|
|
ProcessDeclAttributeList(PDecl, AttrList);
|
2007-12-12 15:09:47 +08:00
|
|
|
if (NumProtoRefs) {
|
2008-03-17 04:19:15 +08:00
|
|
|
/// Check then save referenced protocols.
|
2008-07-26 12:03:38 +08:00
|
|
|
PDecl->addReferencedProtocols((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs);
|
2007-12-12 15:09:47 +08:00
|
|
|
PDecl->setLocEnd(EndProtoLoc);
|
|
|
|
}
|
2008-11-05 00:57:32 +08:00
|
|
|
|
|
|
|
CheckObjCDeclScope(PDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
return PDecl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// FindProtocolDeclaration - This routine looks up protocols and
|
2008-09-05 04:01:15 +08:00
|
|
|
/// issues an error if they are not declared. It returns list of
|
|
|
|
/// protocol declarations in its 'Protocols' argument.
|
2007-12-12 15:09:47 +08:00
|
|
|
void
|
2008-07-26 12:03:38 +08:00
|
|
|
Sema::FindProtocolDeclaration(bool WarnOnDeclarations,
|
2008-07-22 06:17:28 +08:00
|
|
|
const IdentifierLocPair *ProtocolId,
|
2007-12-12 15:09:47 +08:00
|
|
|
unsigned NumProtocols,
|
2008-07-22 06:17:28 +08:00
|
|
|
llvm::SmallVectorImpl<DeclTy*> &Protocols) {
|
2007-12-12 15:09:47 +08:00
|
|
|
for (unsigned i = 0; i != NumProtocols; ++i) {
|
2008-07-26 11:47:43 +08:00
|
|
|
ObjCProtocolDecl *PDecl = ObjCProtocols[ProtocolId[i].first];
|
|
|
|
if (!PDecl) {
|
2008-11-19 13:08:23 +08:00
|
|
|
Diag(ProtocolId[i].second, diag::err_undeclared_protocol)
|
2008-11-19 16:23:25 +08:00
|
|
|
<< ProtocolId[i].first;
|
2008-07-26 11:47:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
2009-02-14 16:22:25 +08:00
|
|
|
|
2009-02-19 05:56:37 +08:00
|
|
|
(void)DiagnoseUseOfDecl(PDecl, ProtocolId[i].second);
|
2008-07-26 11:47:43 +08:00
|
|
|
|
|
|
|
// If this is a forward declaration and we are supposed to warn in this
|
|
|
|
// case, do it.
|
|
|
|
if (WarnOnDeclarations && PDecl->isForwardDecl())
|
2008-11-19 13:08:23 +08:00
|
|
|
Diag(ProtocolId[i].second, diag::warn_undef_protocolref)
|
2008-11-19 16:23:25 +08:00
|
|
|
<< ProtocolId[i].first;
|
2008-07-26 11:47:43 +08:00
|
|
|
Protocols.push_back(PDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-25 03:58:34 +08:00
|
|
|
/// DiagnosePropertyMismatch - Compares two properties for their
|
2008-08-27 13:40:03 +08:00
|
|
|
/// attributes and types and warns on a variety of inconsistencies.
|
2008-04-25 03:58:34 +08:00
|
|
|
///
|
2008-05-01 08:03:38 +08:00
|
|
|
void
|
|
|
|
Sema::DiagnosePropertyMismatch(ObjCPropertyDecl *Property,
|
|
|
|
ObjCPropertyDecl *SuperProperty,
|
2008-11-24 11:54:41 +08:00
|
|
|
const IdentifierInfo *inheritedName) {
|
2008-04-25 03:58:34 +08:00
|
|
|
ObjCPropertyDecl::PropertyAttributeKind CAttr =
|
|
|
|
Property->getPropertyAttributes();
|
|
|
|
ObjCPropertyDecl::PropertyAttributeKind SAttr =
|
|
|
|
SuperProperty->getPropertyAttributes();
|
|
|
|
if ((CAttr & ObjCPropertyDecl::OBJC_PR_readonly)
|
|
|
|
&& (SAttr & ObjCPropertyDecl::OBJC_PR_readwrite))
|
2008-11-19 13:08:23 +08:00
|
|
|
Diag(Property->getLocation(), diag::warn_readonly_property)
|
2008-11-24 11:54:41 +08:00
|
|
|
<< Property->getDeclName() << inheritedName;
|
2008-04-25 03:58:34 +08:00
|
|
|
if ((CAttr & ObjCPropertyDecl::OBJC_PR_copy)
|
|
|
|
!= (SAttr & ObjCPropertyDecl::OBJC_PR_copy))
|
2008-11-19 06:52:51 +08:00
|
|
|
Diag(Property->getLocation(), diag::warn_property_attribute)
|
2008-11-24 11:54:41 +08:00
|
|
|
<< Property->getDeclName() << "copy" << inheritedName;
|
2008-04-25 03:58:34 +08:00
|
|
|
else if ((CAttr & ObjCPropertyDecl::OBJC_PR_retain)
|
|
|
|
!= (SAttr & ObjCPropertyDecl::OBJC_PR_retain))
|
2008-11-19 06:52:51 +08:00
|
|
|
Diag(Property->getLocation(), diag::warn_property_attribute)
|
2008-11-24 11:54:41 +08:00
|
|
|
<< Property->getDeclName() << "retain" << inheritedName;
|
2008-04-25 03:58:34 +08:00
|
|
|
|
|
|
|
if ((CAttr & ObjCPropertyDecl::OBJC_PR_nonatomic)
|
|
|
|
!= (SAttr & ObjCPropertyDecl::OBJC_PR_nonatomic))
|
2008-11-19 06:52:51 +08:00
|
|
|
Diag(Property->getLocation(), diag::warn_property_attribute)
|
2008-11-24 11:54:41 +08:00
|
|
|
<< Property->getDeclName() << "atomic" << inheritedName;
|
2008-04-25 03:58:34 +08:00
|
|
|
if (Property->getSetterName() != SuperProperty->getSetterName())
|
2008-11-19 06:52:51 +08:00
|
|
|
Diag(Property->getLocation(), diag::warn_property_attribute)
|
2008-11-24 11:54:41 +08:00
|
|
|
<< Property->getDeclName() << "setter" << inheritedName;
|
2008-04-25 03:58:34 +08:00
|
|
|
if (Property->getGetterName() != SuperProperty->getGetterName())
|
2008-11-19 06:52:51 +08:00
|
|
|
Diag(Property->getLocation(), diag::warn_property_attribute)
|
2008-11-24 11:54:41 +08:00
|
|
|
<< Property->getDeclName() << "getter" << inheritedName;
|
2008-04-25 03:58:34 +08:00
|
|
|
|
2008-07-27 04:50:02 +08:00
|
|
|
if (Context.getCanonicalType(Property->getType()) !=
|
|
|
|
Context.getCanonicalType(SuperProperty->getType()))
|
2008-11-19 06:52:51 +08:00
|
|
|
Diag(Property->getLocation(), diag::warn_property_type)
|
2008-11-24 11:54:41 +08:00
|
|
|
<< Property->getType() << inheritedName;
|
2008-04-25 03:58:34 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ComparePropertiesInBaseAndSuper - This routine compares property
|
|
|
|
/// declarations in base and its super class, if any, and issues
|
|
|
|
/// diagnostics in a variety of inconsistant situations.
|
|
|
|
///
|
2009-02-17 05:26:43 +08:00
|
|
|
void Sema::ComparePropertiesInBaseAndSuper(ObjCInterfaceDecl *IDecl) {
|
2008-04-25 03:58:34 +08:00
|
|
|
ObjCInterfaceDecl *SDecl = IDecl->getSuperClass();
|
|
|
|
if (!SDecl)
|
|
|
|
return;
|
2008-08-27 13:40:03 +08:00
|
|
|
// FIXME: O(N^2)
|
2009-01-09 23:36:25 +08:00
|
|
|
for (ObjCInterfaceDecl::prop_iterator S = SDecl->prop_begin(),
|
|
|
|
E = SDecl->prop_end(); S != E; ++S) {
|
2008-05-01 08:03:38 +08:00
|
|
|
ObjCPropertyDecl *SuperPDecl = (*S);
|
2008-04-25 03:58:34 +08:00
|
|
|
// Does property in super class has declaration in current class?
|
2009-01-09 23:36:25 +08:00
|
|
|
for (ObjCInterfaceDecl::prop_iterator I = IDecl->prop_begin(),
|
|
|
|
E = IDecl->prop_end(); I != E; ++I) {
|
2008-04-25 03:58:34 +08:00
|
|
|
ObjCPropertyDecl *PDecl = (*I);
|
|
|
|
if (SuperPDecl->getIdentifier() == PDecl->getIdentifier())
|
2008-11-17 22:58:09 +08:00
|
|
|
DiagnosePropertyMismatch(PDecl, SuperPDecl,
|
2008-11-24 11:54:41 +08:00
|
|
|
SDecl->getIdentifier());
|
2008-04-25 03:58:34 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-03 03:17:30 +08:00
|
|
|
/// MergeOneProtocolPropertiesIntoClass - This routine goes thru the list
|
|
|
|
/// of properties declared in a protocol and adds them to the list
|
2008-12-07 07:03:39 +08:00
|
|
|
/// of properties for current class/category if it is not there already.
|
2008-05-03 03:17:30 +08:00
|
|
|
void
|
2008-12-07 07:03:39 +08:00
|
|
|
Sema::MergeOneProtocolPropertiesIntoClass(Decl *CDecl,
|
2008-11-24 11:54:41 +08:00
|
|
|
ObjCProtocolDecl *PDecl) {
|
2008-12-07 07:03:39 +08:00
|
|
|
ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDecl);
|
|
|
|
if (!IDecl) {
|
|
|
|
// Category
|
|
|
|
ObjCCategoryDecl *CatDecl = static_cast<ObjCCategoryDecl*>(CDecl);
|
|
|
|
assert (CatDecl && "MergeOneProtocolPropertiesIntoClass");
|
2009-01-09 23:36:25 +08:00
|
|
|
for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
|
|
|
|
E = PDecl->prop_end(); P != E; ++P) {
|
2008-12-07 07:03:39 +08:00
|
|
|
ObjCPropertyDecl *Pr = (*P);
|
2009-01-09 23:36:25 +08:00
|
|
|
ObjCCategoryDecl::prop_iterator CP, CE;
|
2008-12-07 07:03:39 +08:00
|
|
|
// Is this property already in category's list of properties?
|
2009-01-09 23:36:25 +08:00
|
|
|
for (CP = CatDecl->prop_begin(), CE = CatDecl->prop_end();
|
2008-12-07 07:03:39 +08:00
|
|
|
CP != CE; ++CP)
|
|
|
|
if ((*CP)->getIdentifier() == Pr->getIdentifier())
|
|
|
|
break;
|
2009-01-10 05:04:52 +08:00
|
|
|
if (CP != CE)
|
2008-12-07 07:03:39 +08:00
|
|
|
// Property protocol already exist in class. Diagnose any mismatch.
|
|
|
|
DiagnosePropertyMismatch((*CP), Pr, PDecl->getIdentifier());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2009-01-09 23:36:25 +08:00
|
|
|
for (ObjCProtocolDecl::prop_iterator P = PDecl->prop_begin(),
|
|
|
|
E = PDecl->prop_end(); P != E; ++P) {
|
2008-05-03 03:17:30 +08:00
|
|
|
ObjCPropertyDecl *Pr = (*P);
|
2009-01-09 23:36:25 +08:00
|
|
|
ObjCInterfaceDecl::prop_iterator CP, CE;
|
2008-05-03 03:17:30 +08:00
|
|
|
// Is this property already in class's list of properties?
|
2009-01-09 23:36:25 +08:00
|
|
|
for (CP = IDecl->prop_begin(), CE = IDecl->prop_end();
|
2008-05-03 03:17:30 +08:00
|
|
|
CP != CE; ++CP)
|
|
|
|
if ((*CP)->getIdentifier() == Pr->getIdentifier())
|
|
|
|
break;
|
2009-01-10 05:04:52 +08:00
|
|
|
if (CP != CE)
|
2008-05-03 03:17:30 +08:00
|
|
|
// Property protocol already exist in class. Diagnose any mismatch.
|
2008-11-24 11:54:41 +08:00
|
|
|
DiagnosePropertyMismatch((*CP), Pr, PDecl->getIdentifier());
|
2008-05-03 03:17:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// MergeProtocolPropertiesIntoClass - This routine merges properties
|
|
|
|
/// declared in 'MergeItsProtocols' objects (which can be a class or an
|
2008-12-07 07:03:39 +08:00
|
|
|
/// inherited protocol into the list of properties for class/category 'CDecl'
|
2008-05-03 03:17:30 +08:00
|
|
|
///
|
2009-02-17 05:26:43 +08:00
|
|
|
void Sema::MergeProtocolPropertiesIntoClass(Decl *CDecl,
|
|
|
|
DeclTy *MergeItsProtocols) {
|
2008-05-03 03:17:30 +08:00
|
|
|
Decl *ClassDecl = static_cast<Decl *>(MergeItsProtocols);
|
2008-12-07 07:03:39 +08:00
|
|
|
ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(CDecl);
|
|
|
|
|
|
|
|
if (!IDecl) {
|
|
|
|
// Category
|
|
|
|
ObjCCategoryDecl *CatDecl = static_cast<ObjCCategoryDecl*>(CDecl);
|
|
|
|
assert (CatDecl && "MergeProtocolPropertiesIntoClass");
|
|
|
|
if (ObjCCategoryDecl *MDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl)) {
|
|
|
|
for (ObjCCategoryDecl::protocol_iterator P = MDecl->protocol_begin(),
|
|
|
|
E = MDecl->protocol_end(); P != E; ++P)
|
|
|
|
// Merge properties of category (*P) into IDECL's
|
|
|
|
MergeOneProtocolPropertiesIntoClass(CatDecl, *P);
|
|
|
|
|
|
|
|
// Go thru the list of protocols for this category and recursively merge
|
|
|
|
// their properties into this class as well.
|
|
|
|
for (ObjCCategoryDecl::protocol_iterator P = CatDecl->protocol_begin(),
|
|
|
|
E = CatDecl->protocol_end(); P != E; ++P)
|
|
|
|
MergeProtocolPropertiesIntoClass(CatDecl, *P);
|
|
|
|
} else {
|
|
|
|
ObjCProtocolDecl *MD = cast<ObjCProtocolDecl>(ClassDecl);
|
|
|
|
for (ObjCProtocolDecl::protocol_iterator P = MD->protocol_begin(),
|
|
|
|
E = MD->protocol_end(); P != E; ++P)
|
|
|
|
MergeOneProtocolPropertiesIntoClass(CatDecl, (*P));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-21 15:06:49 +08:00
|
|
|
if (ObjCInterfaceDecl *MDecl = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
|
2008-05-03 03:17:30 +08:00
|
|
|
for (ObjCInterfaceDecl::protocol_iterator P = MDecl->protocol_begin(),
|
|
|
|
E = MDecl->protocol_end(); P != E; ++P)
|
|
|
|
// Merge properties of class (*P) into IDECL's
|
2008-07-21 15:06:49 +08:00
|
|
|
MergeOneProtocolPropertiesIntoClass(IDecl, *P);
|
|
|
|
|
2008-05-03 03:17:30 +08:00
|
|
|
// Go thru the list of protocols for this class and recursively merge
|
|
|
|
// their properties into this class as well.
|
|
|
|
for (ObjCInterfaceDecl::protocol_iterator P = IDecl->protocol_begin(),
|
|
|
|
E = IDecl->protocol_end(); P != E; ++P)
|
2008-07-21 15:06:49 +08:00
|
|
|
MergeProtocolPropertiesIntoClass(IDecl, *P);
|
|
|
|
} else {
|
2008-07-21 17:18:38 +08:00
|
|
|
ObjCProtocolDecl *MD = cast<ObjCProtocolDecl>(ClassDecl);
|
|
|
|
for (ObjCProtocolDecl::protocol_iterator P = MD->protocol_begin(),
|
|
|
|
E = MD->protocol_end(); P != E; ++P)
|
2008-05-03 03:17:30 +08:00
|
|
|
MergeOneProtocolPropertiesIntoClass(IDecl, (*P));
|
2008-07-21 15:06:49 +08:00
|
|
|
}
|
2008-05-03 03:17:30 +08:00
|
|
|
}
|
|
|
|
|
2007-12-12 15:09:47 +08:00
|
|
|
/// ActOnForwardProtocolDeclaration -
|
|
|
|
Action::DeclTy *
|
|
|
|
Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc,
|
2008-07-22 06:17:28 +08:00
|
|
|
const IdentifierLocPair *IdentList,
|
2008-12-17 09:07:27 +08:00
|
|
|
unsigned NumElts,
|
|
|
|
AttributeList *attrList) {
|
2008-01-08 03:49:32 +08:00
|
|
|
llvm::SmallVector<ObjCProtocolDecl*, 32> Protocols;
|
2007-12-12 15:09:47 +08:00
|
|
|
|
|
|
|
for (unsigned i = 0; i != NumElts; ++i) {
|
2008-07-22 06:17:28 +08:00
|
|
|
IdentifierInfo *Ident = IdentList[i].first;
|
2008-03-17 04:19:15 +08:00
|
|
|
ObjCProtocolDecl *&PDecl = ObjCProtocols[Ident];
|
2009-01-09 08:49:46 +08:00
|
|
|
if (PDecl == 0) { // Not already seen?
|
|
|
|
PDecl = ObjCProtocolDecl::Create(Context, CurContext,
|
|
|
|
IdentList[i].second, Ident);
|
|
|
|
// FIXME: PushOnScopeChains?
|
2009-01-13 07:27:07 +08:00
|
|
|
CurContext->addDecl(PDecl);
|
2009-01-09 08:49:46 +08:00
|
|
|
}
|
2008-12-17 09:07:27 +08:00
|
|
|
if (attrList)
|
|
|
|
ProcessDeclAttributeList(PDecl, attrList);
|
2007-12-12 15:09:47 +08:00
|
|
|
Protocols.push_back(PDecl);
|
|
|
|
}
|
2008-11-05 00:57:32 +08:00
|
|
|
|
|
|
|
ObjCForwardProtocolDecl *PDecl =
|
2009-01-09 08:49:46 +08:00
|
|
|
ObjCForwardProtocolDecl::Create(Context, CurContext, AtProtocolLoc,
|
2008-11-05 00:57:32 +08:00
|
|
|
&Protocols[0], Protocols.size());
|
2009-01-13 07:27:07 +08:00
|
|
|
CurContext->addDecl(PDecl);
|
2008-11-05 00:57:32 +08:00
|
|
|
CheckObjCDeclScope(PDecl);
|
|
|
|
return PDecl;
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
|
2008-07-22 06:17:28 +08:00
|
|
|
Sema::DeclTy *Sema::
|
|
|
|
ActOnStartCategoryInterface(SourceLocation AtInterfaceLoc,
|
|
|
|
IdentifierInfo *ClassName, SourceLocation ClassLoc,
|
|
|
|
IdentifierInfo *CategoryName,
|
|
|
|
SourceLocation CategoryLoc,
|
2008-07-26 12:07:02 +08:00
|
|
|
DeclTy * const *ProtoRefs,
|
2008-07-22 06:17:28 +08:00
|
|
|
unsigned NumProtoRefs,
|
|
|
|
SourceLocation EndProtoLoc) {
|
2008-03-17 04:34:23 +08:00
|
|
|
ObjCCategoryDecl *CDecl =
|
2009-01-09 08:49:46 +08:00
|
|
|
ObjCCategoryDecl::Create(Context, CurContext, AtInterfaceLoc, CategoryName);
|
|
|
|
// FIXME: PushOnScopeChains?
|
2009-01-13 07:27:07 +08:00
|
|
|
CurContext->addDecl(CDecl);
|
2009-02-17 05:26:43 +08:00
|
|
|
|
|
|
|
ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName);
|
2008-01-18 04:33:24 +08:00
|
|
|
/// Check that class of this category is already completely declared.
|
2009-02-17 05:26:43 +08:00
|
|
|
if (!IDecl || IDecl->isForwardDecl()) {
|
|
|
|
CDecl->setInvalidDecl();
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(ClassLoc, diag::err_undef_interface) << ClassName;
|
2009-02-17 05:26:43 +08:00
|
|
|
return CDecl;
|
|
|
|
}
|
|
|
|
|
|
|
|
CDecl->setClassInterface(IDecl);
|
2009-02-17 05:30:01 +08:00
|
|
|
|
|
|
|
// If the interface is deprecated, warn about it.
|
2009-02-19 05:56:37 +08:00
|
|
|
(void)DiagnoseUseOfDecl(IDecl, ClassLoc);
|
2009-02-17 05:26:43 +08:00
|
|
|
|
|
|
|
/// Check for duplicate interface declaration for this category
|
|
|
|
ObjCCategoryDecl *CDeclChain;
|
|
|
|
for (CDeclChain = IDecl->getCategoryList(); CDeclChain;
|
|
|
|
CDeclChain = CDeclChain->getNextClassCategory()) {
|
|
|
|
if (CategoryName && CDeclChain->getIdentifier() == CategoryName) {
|
|
|
|
Diag(CategoryLoc, diag::warn_dup_category_def)
|
|
|
|
<< ClassName << CategoryName;
|
|
|
|
Diag(CDeclChain->getLocation(), diag::note_previous_definition);
|
|
|
|
break;
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
2008-01-18 04:33:24 +08:00
|
|
|
}
|
2009-02-17 05:26:43 +08:00
|
|
|
if (!CDeclChain)
|
|
|
|
CDecl->insertNextClassCategory();
|
2007-12-12 15:09:47 +08:00
|
|
|
|
|
|
|
if (NumProtoRefs) {
|
2008-07-26 12:07:02 +08:00
|
|
|
CDecl->addReferencedProtocols((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs);
|
|
|
|
CDecl->setLocEnd(EndProtoLoc);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
2008-11-05 00:57:32 +08:00
|
|
|
|
|
|
|
CheckObjCDeclScope(CDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
return CDecl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ActOnStartCategoryImplementation - Perform semantic checks on the
|
2008-01-08 03:49:32 +08:00
|
|
|
/// category implementation declaration and build an ObjCCategoryImplDecl
|
2007-12-12 15:09:47 +08:00
|
|
|
/// object.
|
|
|
|
Sema::DeclTy *Sema::ActOnStartCategoryImplementation(
|
|
|
|
SourceLocation AtCatImplLoc,
|
|
|
|
IdentifierInfo *ClassName, SourceLocation ClassLoc,
|
|
|
|
IdentifierInfo *CatName, SourceLocation CatLoc) {
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCInterfaceDecl *IDecl = getObjCInterfaceDecl(ClassName);
|
2008-03-17 04:53:07 +08:00
|
|
|
ObjCCategoryImplDecl *CDecl =
|
2009-01-09 08:49:46 +08:00
|
|
|
ObjCCategoryImplDecl::Create(Context, CurContext, AtCatImplLoc, CatName,
|
|
|
|
IDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
/// Check that class of this category is already completely declared.
|
|
|
|
if (!IDecl || IDecl->isForwardDecl())
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(ClassLoc, diag::err_undef_interface) << ClassName;
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2009-01-09 08:49:46 +08:00
|
|
|
// FIXME: PushOnScopeChains?
|
2009-01-13 07:27:07 +08:00
|
|
|
CurContext->addDecl(CDecl);
|
2009-01-09 08:49:46 +08:00
|
|
|
|
2007-12-12 15:09:47 +08:00
|
|
|
/// TODO: Check that CatName, category name, is not used in another
|
|
|
|
// implementation.
|
2008-09-28 22:55:53 +08:00
|
|
|
ObjCCategoryImpls.push_back(CDecl);
|
2008-11-05 00:57:32 +08:00
|
|
|
|
|
|
|
CheckObjCDeclScope(CDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
return CDecl;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sema::DeclTy *Sema::ActOnStartClassImplementation(
|
|
|
|
SourceLocation AtClassImplLoc,
|
|
|
|
IdentifierInfo *ClassName, SourceLocation ClassLoc,
|
|
|
|
IdentifierInfo *SuperClassname,
|
|
|
|
SourceLocation SuperClassLoc) {
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCInterfaceDecl* IDecl = 0;
|
2007-12-12 15:09:47 +08:00
|
|
|
// Check for another declaration kind with the same name.
|
2009-02-05 01:27:36 +08:00
|
|
|
NamedDecl *PrevDecl = LookupName(TUScope, ClassName, LookupOrdinaryName);
|
2008-01-08 03:49:32 +08:00
|
|
|
if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(ClassLoc, diag::err_redefinition_different_kind) << ClassName;
|
2008-11-24 07:12:31 +08:00
|
|
|
Diag(PrevDecl->getLocation(), diag::note_previous_definition);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Is there an interface declaration of this class; if not, warn!
|
2008-01-08 03:49:32 +08:00
|
|
|
IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
if (!IDecl)
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(ClassLoc, diag::warn_undef_interface) << ClassName;
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check that super class name is valid class name
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCInterfaceDecl* SDecl = 0;
|
2007-12-12 15:09:47 +08:00
|
|
|
if (SuperClassname) {
|
|
|
|
// Check if a different kind of symbol declared in this scope.
|
Eliminated LookupCriteria, whose creation was causing a bottleneck for
LookupName et al. Instead, use an enum and a bool to describe its
contents.
Optimized the C/Objective-C path through LookupName, eliminating any
unnecessarily C++isms. Simplify IdentifierResolver::iterator, removing
some code and arguments that are no longer used.
Eliminated LookupDeclInScope/LookupDeclInContext, moving all callers
over to LookupName, LookupQualifiedName, or LookupParsedName, as
appropriate.
All together, I'm seeing a 0.2% speedup on Cocoa.h with PTH and
-disable-free. Plus, we're down to three name-lookup routines.
llvm-svn: 63354
2009-01-30 09:04:22 +08:00
|
|
|
PrevDecl = LookupName(TUScope, SuperClassname, LookupOrdinaryName);
|
2008-01-08 03:49:32 +08:00
|
|
|
if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(SuperClassLoc, diag::err_redefinition_different_kind)
|
|
|
|
<< SuperClassname;
|
2008-11-24 07:12:31 +08:00
|
|
|
Diag(PrevDecl->getLocation(), diag::note_previous_definition);
|
2008-11-19 16:23:25 +08:00
|
|
|
} else {
|
2008-01-08 03:49:32 +08:00
|
|
|
SDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
if (!SDecl)
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(SuperClassLoc, diag::err_undef_superclass)
|
|
|
|
<< SuperClassname << ClassName;
|
2007-12-12 15:09:47 +08:00
|
|
|
else if (IDecl && IDecl->getSuperClass() != SDecl) {
|
|
|
|
// This implementation and its interface do not have the same
|
|
|
|
// super class.
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(SuperClassLoc, diag::err_conflicting_super_class)
|
2008-11-24 05:45:46 +08:00
|
|
|
<< SDecl->getDeclName();
|
2008-11-24 07:12:31 +08:00
|
|
|
Diag(SDecl->getLocation(), diag::note_previous_definition);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IDecl) {
|
|
|
|
// Legacy case of @implementation with no corresponding @interface.
|
|
|
|
// Build, chain & install the interface decl into the identifier.
|
2008-08-21 02:02:42 +08:00
|
|
|
|
|
|
|
// FIXME: Do we support attributes on the @implementation? If so
|
|
|
|
// we should copy them over.
|
2009-01-09 08:49:46 +08:00
|
|
|
IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassImplLoc,
|
|
|
|
ClassName, ClassLoc, false, true);
|
2008-04-03 02:30:49 +08:00
|
|
|
ObjCInterfaceDecls[ClassName] = IDecl;
|
2007-12-12 15:09:47 +08:00
|
|
|
IDecl->setSuperClass(SDecl);
|
|
|
|
IDecl->setLocEnd(ClassLoc);
|
|
|
|
|
2009-01-09 08:49:46 +08:00
|
|
|
// FIXME: PushOnScopeChains?
|
2009-01-13 07:27:07 +08:00
|
|
|
CurContext->addDecl(IDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
// Remember that this needs to be removed when the scope is popped.
|
|
|
|
TUScope->AddDecl(IDecl);
|
|
|
|
}
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCImplementationDecl* IMPDecl =
|
2009-01-09 08:49:46 +08:00
|
|
|
ObjCImplementationDecl::Create(Context, CurContext, AtClassImplLoc,
|
2009-01-20 09:17:11 +08:00
|
|
|
IDecl, SDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2009-01-09 08:49:46 +08:00
|
|
|
// FIXME: PushOnScopeChains?
|
2009-01-13 07:27:07 +08:00
|
|
|
CurContext->addDecl(IMPDecl);
|
2009-01-09 08:49:46 +08:00
|
|
|
|
2008-11-05 00:57:32 +08:00
|
|
|
if (CheckObjCDeclScope(IMPDecl))
|
|
|
|
return IMPDecl;
|
|
|
|
|
2007-12-12 15:09:47 +08:00
|
|
|
// Check that there is no duplicate implementation of this class.
|
2008-01-08 03:49:32 +08:00
|
|
|
if (ObjCImplementations[ClassName])
|
2008-03-17 04:53:07 +08:00
|
|
|
// FIXME: Don't leak everything!
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(ClassLoc, diag::err_dup_implementation_class) << ClassName;
|
2007-12-12 15:09:47 +08:00
|
|
|
else // add it to the list.
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCImplementations[ClassName] = IMPDecl;
|
2007-12-12 15:09:47 +08:00
|
|
|
return IMPDecl;
|
|
|
|
}
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl,
|
|
|
|
ObjCIvarDecl **ivars, unsigned numIvars,
|
2007-12-12 15:09:47 +08:00
|
|
|
SourceLocation RBrace) {
|
|
|
|
assert(ImpDecl && "missing implementation decl");
|
2009-01-20 09:17:11 +08:00
|
|
|
ObjCInterfaceDecl* IDecl = ImpDecl->getClassInterface();
|
2007-12-12 15:09:47 +08:00
|
|
|
if (!IDecl)
|
|
|
|
return;
|
|
|
|
/// Check case of non-existing @interface decl.
|
|
|
|
/// (legacy objective-c @implementation decl without an @interface decl).
|
|
|
|
/// Add implementations's ivar to the synthesize class's ivar list.
|
|
|
|
if (IDecl->ImplicitInterfaceDecl()) {
|
|
|
|
IDecl->addInstanceVariablesToClass(ivars, numIvars, RBrace);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// If implementation has empty ivar list, just return.
|
|
|
|
if (numIvars == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
assert(ivars && "missing @implementation ivars");
|
|
|
|
|
|
|
|
// Check interface's Ivar list against those in the implementation.
|
|
|
|
// names and types must match.
|
|
|
|
//
|
|
|
|
unsigned j = 0;
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCInterfaceDecl::ivar_iterator
|
2007-12-13 01:58:05 +08:00
|
|
|
IVI = IDecl->ivar_begin(), IVE = IDecl->ivar_end();
|
|
|
|
for (; numIvars > 0 && IVI != IVE; ++IVI) {
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCIvarDecl* ImplIvar = ivars[j++];
|
|
|
|
ObjCIvarDecl* ClsIvar = *IVI;
|
2007-12-12 15:09:47 +08:00
|
|
|
assert (ImplIvar && "missing implementation ivar");
|
|
|
|
assert (ClsIvar && "missing class ivar");
|
2008-07-27 08:05:05 +08:00
|
|
|
if (Context.getCanonicalType(ImplIvar->getType()) !=
|
|
|
|
Context.getCanonicalType(ClsIvar->getType())) {
|
2008-11-19 13:08:23 +08:00
|
|
|
Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_type)
|
2008-11-24 05:45:46 +08:00
|
|
|
<< ImplIvar->getIdentifier()
|
|
|
|
<< ImplIvar->getType() << ClsIvar->getType();
|
2008-11-24 07:12:31 +08:00
|
|
|
Diag(ClsIvar->getLocation(), diag::note_previous_definition);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
// TODO: Two mismatched (unequal width) Ivar bitfields should be diagnosed
|
|
|
|
// as error.
|
|
|
|
else if (ImplIvar->getIdentifier() != ClsIvar->getIdentifier()) {
|
2008-11-19 13:08:23 +08:00
|
|
|
Diag(ImplIvar->getLocation(), diag::err_conflicting_ivar_name)
|
2008-11-24 05:45:46 +08:00
|
|
|
<< ImplIvar->getIdentifier() << ClsIvar->getIdentifier();
|
2008-11-24 07:12:31 +08:00
|
|
|
Diag(ClsIvar->getLocation(), diag::note_previous_definition);
|
2007-12-13 02:11:49 +08:00
|
|
|
return;
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
--numIvars;
|
|
|
|
}
|
2007-12-13 02:11:49 +08:00
|
|
|
|
|
|
|
if (numIvars > 0)
|
2007-12-13 02:19:52 +08:00
|
|
|
Diag(ivars[j]->getLocation(), diag::err_inconsistant_ivar_count);
|
2007-12-13 02:11:49 +08:00
|
|
|
else if (IVI != IVE)
|
2007-12-13 02:19:52 +08:00
|
|
|
Diag((*IVI)->getLocation(), diag::err_inconsistant_ivar_count);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
|
2008-02-11 05:38:56 +08:00
|
|
|
void Sema::WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
|
|
|
|
bool &IncompleteImpl) {
|
|
|
|
if (!IncompleteImpl) {
|
|
|
|
Diag(ImpLoc, diag::warn_incomplete_impl);
|
|
|
|
IncompleteImpl = true;
|
|
|
|
}
|
2008-11-24 05:45:46 +08:00
|
|
|
Diag(ImpLoc, diag::warn_undef_method_impl) << method->getDeclName();
|
2008-02-11 05:38:56 +08:00
|
|
|
}
|
|
|
|
|
2008-12-06 02:18:52 +08:00
|
|
|
void Sema::WarnConflictingTypedMethods(ObjCMethodDecl *ImpMethodDecl,
|
|
|
|
ObjCMethodDecl *IntfMethodDecl) {
|
|
|
|
bool err = false;
|
|
|
|
QualType ImpMethodQType =
|
|
|
|
Context.getCanonicalType(ImpMethodDecl->getResultType());
|
|
|
|
QualType IntfMethodQType =
|
|
|
|
Context.getCanonicalType(IntfMethodDecl->getResultType());
|
|
|
|
if (!Context.typesAreCompatible(IntfMethodQType, ImpMethodQType))
|
|
|
|
err = true;
|
|
|
|
else for (ObjCMethodDecl::param_iterator IM=ImpMethodDecl->param_begin(),
|
|
|
|
IF=IntfMethodDecl->param_begin(),
|
|
|
|
EM=ImpMethodDecl->param_end(); IM!=EM; ++IM, IF++) {
|
|
|
|
ImpMethodQType = Context.getCanonicalType((*IM)->getType());
|
|
|
|
IntfMethodQType = Context.getCanonicalType((*IF)->getType());
|
|
|
|
if (!Context.typesAreCompatible(IntfMethodQType, ImpMethodQType)) {
|
|
|
|
err = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (err) {
|
|
|
|
Diag(ImpMethodDecl->getLocation(), diag::warn_conflicting_types)
|
|
|
|
<< ImpMethodDecl->getDeclName();
|
|
|
|
Diag(IntfMethodDecl->getLocation(), diag::note_previous_definition);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-13 03:55:42 +08:00
|
|
|
/// isPropertyReadonly - Return true if property is readonly, by searching
|
|
|
|
/// for the property in the class and in its categories and implementations
|
|
|
|
///
|
|
|
|
bool Sema::isPropertyReadonly(ObjCPropertyDecl *PDecl,
|
|
|
|
ObjCInterfaceDecl *IDecl) const {
|
|
|
|
// by far the most common case.
|
|
|
|
if (!PDecl->isReadOnly())
|
|
|
|
return false;
|
|
|
|
// Even if property is ready only, if interface has a user defined setter,
|
|
|
|
// it is not considered read only.
|
|
|
|
if (IDecl->getInstanceMethod(PDecl->getSetterName()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Main class has the property as 'readonly'. Must search
|
|
|
|
// through the category list to see if the property's
|
|
|
|
// attribute has been over-ridden to 'readwrite'.
|
|
|
|
for (ObjCCategoryDecl *Category = IDecl->getCategoryList();
|
|
|
|
Category; Category = Category->getNextClassCategory()) {
|
|
|
|
// Even if property is ready only, if a category has a user defined setter,
|
|
|
|
// it is not considered read only.
|
|
|
|
if (Category->getInstanceMethod(PDecl->getSetterName()))
|
|
|
|
return false;
|
|
|
|
ObjCPropertyDecl *P =
|
|
|
|
Category->FindPropertyDeclaration(PDecl->getIdentifier());
|
|
|
|
if (P && !P->isReadOnly())
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Also, check for definition of a setter method in the implementation if
|
|
|
|
// all else failed.
|
|
|
|
if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(CurContext)) {
|
|
|
|
if (ObjCImplementationDecl *IMD =
|
|
|
|
dyn_cast<ObjCImplementationDecl>(OMD->getDeclContext())) {
|
|
|
|
if (IMD->getInstanceMethod(PDecl->getSetterName()))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (ObjCCategoryImplDecl *CIMD =
|
|
|
|
dyn_cast<ObjCCategoryImplDecl>(OMD->getDeclContext())) {
|
|
|
|
if (CIMD->getInstanceMethod(PDecl->getSetterName()))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-27 13:40:03 +08:00
|
|
|
/// FIXME: Type hierarchies in Objective-C can be deep. We could most
|
|
|
|
/// likely improve the efficiency of selector lookups and type
|
|
|
|
/// checking by associating with each protocol / interface / category
|
|
|
|
/// the flattened instance tables. If we used an immutable set to keep
|
|
|
|
/// the table then it wouldn't add significant memory cost and it
|
|
|
|
/// would be handy for lookups.
|
|
|
|
|
2008-02-09 06:06:17 +08:00
|
|
|
/// CheckProtocolMethodDefs - This routine checks unimplemented methods
|
2007-12-12 15:09:47 +08:00
|
|
|
/// Declared in protocol, and those referenced by it.
|
2008-02-09 06:06:17 +08:00
|
|
|
void Sema::CheckProtocolMethodDefs(SourceLocation ImpLoc,
|
|
|
|
ObjCProtocolDecl *PDecl,
|
2007-12-12 15:09:47 +08:00
|
|
|
bool& IncompleteImpl,
|
2008-02-09 06:06:17 +08:00
|
|
|
const llvm::DenseSet<Selector> &InsMap,
|
2008-09-05 04:01:15 +08:00
|
|
|
const llvm::DenseSet<Selector> &ClsMap,
|
|
|
|
ObjCInterfaceDecl *IDecl) {
|
|
|
|
ObjCInterfaceDecl *Super = IDecl->getSuperClass();
|
|
|
|
|
|
|
|
// If a method lookup fails locally we still need to look and see if
|
|
|
|
// the method was implemented by a base class or an inherited
|
|
|
|
// protocol. This lookup is slow, but occurs rarely in correct code
|
|
|
|
// and otherwise would terminate in a warning.
|
|
|
|
|
2007-12-12 15:09:47 +08:00
|
|
|
// check unimplemented instance methods.
|
2008-01-08 03:49:32 +08:00
|
|
|
for (ObjCProtocolDecl::instmeth_iterator I = PDecl->instmeth_begin(),
|
2007-12-15 07:37:57 +08:00
|
|
|
E = PDecl->instmeth_end(); I != E; ++I) {
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCMethodDecl *method = *I;
|
2008-09-05 04:01:15 +08:00
|
|
|
if (method->getImplementationControl() != ObjCMethodDecl::Optional &&
|
2008-11-25 06:16:00 +08:00
|
|
|
!method->isSynthesized() && !InsMap.count(method->getSelector()) &&
|
2008-09-05 04:01:15 +08:00
|
|
|
(!Super || !Super->lookupInstanceMethod(method->getSelector())))
|
2008-02-11 05:38:56 +08:00
|
|
|
WarnUndefinedMethod(ImpLoc, method, IncompleteImpl);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
// check unimplemented class methods
|
2008-01-08 03:49:32 +08:00
|
|
|
for (ObjCProtocolDecl::classmeth_iterator I = PDecl->classmeth_begin(),
|
2007-12-15 07:37:57 +08:00
|
|
|
E = PDecl->classmeth_end(); I != E; ++I) {
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCMethodDecl *method = *I;
|
2008-09-05 04:01:15 +08:00
|
|
|
if (method->getImplementationControl() != ObjCMethodDecl::Optional &&
|
|
|
|
!ClsMap.count(method->getSelector()) &&
|
|
|
|
(!Super || !Super->lookupClassMethod(method->getSelector())))
|
2008-02-11 05:38:56 +08:00
|
|
|
WarnUndefinedMethod(ImpLoc, method, IncompleteImpl);
|
2007-12-15 07:37:57 +08:00
|
|
|
}
|
2008-07-22 05:32:27 +08:00
|
|
|
// Check on this protocols's referenced protocols, recursively.
|
|
|
|
for (ObjCProtocolDecl::protocol_iterator PI = PDecl->protocol_begin(),
|
|
|
|
E = PDecl->protocol_end(); PI != E; ++PI)
|
2008-09-05 04:01:15 +08:00
|
|
|
CheckProtocolMethodDefs(ImpLoc, *PI, IncompleteImpl, InsMap, ClsMap, IDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
void Sema::ImplMethodsVsClassMethods(ObjCImplementationDecl* IMPDecl,
|
|
|
|
ObjCInterfaceDecl* IDecl) {
|
2007-12-12 15:09:47 +08:00
|
|
|
llvm::DenseSet<Selector> InsMap;
|
|
|
|
// Check and see if instance methods in class interface have been
|
|
|
|
// implemented in the implementation class.
|
2008-01-08 03:49:32 +08:00
|
|
|
for (ObjCImplementationDecl::instmeth_iterator I = IMPDecl->instmeth_begin(),
|
2007-12-13 01:58:05 +08:00
|
|
|
E = IMPDecl->instmeth_end(); I != E; ++I)
|
|
|
|
InsMap.insert((*I)->getSelector());
|
2007-12-12 15:09:47 +08:00
|
|
|
|
|
|
|
bool IncompleteImpl = false;
|
2008-01-08 03:49:32 +08:00
|
|
|
for (ObjCInterfaceDecl::instmeth_iterator I = IDecl->instmeth_begin(),
|
2009-02-17 03:25:52 +08:00
|
|
|
E = IDecl->instmeth_end(); I != E; ++I) {
|
|
|
|
if (!(*I)->isSynthesized() && !InsMap.count((*I)->getSelector())) {
|
2008-02-11 05:38:56 +08:00
|
|
|
WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl);
|
2009-02-17 03:25:52 +08:00
|
|
|
continue;
|
2008-12-05 09:35:25 +08:00
|
|
|
}
|
2009-02-17 03:25:52 +08:00
|
|
|
|
|
|
|
ObjCMethodDecl *ImpMethodDecl =
|
|
|
|
IMPDecl->getInstanceMethod((*I)->getSelector());
|
|
|
|
ObjCMethodDecl *IntfMethodDecl =
|
|
|
|
IDecl->getInstanceMethod((*I)->getSelector());
|
|
|
|
assert(IntfMethodDecl &&
|
|
|
|
"IntfMethodDecl is null in ImplMethodsVsClassMethods");
|
|
|
|
// ImpMethodDecl may be null as in a @dynamic property.
|
|
|
|
if (ImpMethodDecl)
|
|
|
|
WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl);
|
|
|
|
}
|
2007-12-13 01:58:05 +08:00
|
|
|
|
2007-12-12 15:09:47 +08:00
|
|
|
llvm::DenseSet<Selector> ClsMap;
|
|
|
|
// Check and see if class methods in class interface have been
|
|
|
|
// implemented in the implementation class.
|
2008-01-08 03:49:32 +08:00
|
|
|
for (ObjCImplementationDecl::classmeth_iterator I =IMPDecl->classmeth_begin(),
|
2007-12-13 01:58:05 +08:00
|
|
|
E = IMPDecl->classmeth_end(); I != E; ++I)
|
|
|
|
ClsMap.insert((*I)->getSelector());
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
for (ObjCInterfaceDecl::classmeth_iterator I = IDecl->classmeth_begin(),
|
2007-12-13 01:58:05 +08:00
|
|
|
E = IDecl->classmeth_end(); I != E; ++I)
|
2008-02-11 05:38:56 +08:00
|
|
|
if (!ClsMap.count((*I)->getSelector()))
|
|
|
|
WarnUndefinedMethod(IMPDecl->getLocation(), *I, IncompleteImpl);
|
2008-12-06 02:18:52 +08:00
|
|
|
else {
|
|
|
|
ObjCMethodDecl *ImpMethodDecl =
|
|
|
|
IMPDecl->getClassMethod((*I)->getSelector());
|
|
|
|
ObjCMethodDecl *IntfMethodDecl =
|
|
|
|
IDecl->getClassMethod((*I)->getSelector());
|
|
|
|
WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl);
|
|
|
|
}
|
|
|
|
|
2007-12-12 15:09:47 +08:00
|
|
|
|
|
|
|
// Check the protocol list for unimplemented methods in the @implementation
|
|
|
|
// class.
|
2008-07-22 02:19:38 +08:00
|
|
|
const ObjCList<ObjCProtocolDecl> &Protocols =
|
|
|
|
IDecl->getReferencedProtocols();
|
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
|
|
|
|
E = Protocols.end(); I != E; ++I)
|
|
|
|
CheckProtocolMethodDefs(IMPDecl->getLocation(), *I,
|
2008-09-05 04:01:15 +08:00
|
|
|
IncompleteImpl, InsMap, ClsMap, IDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ImplCategoryMethodsVsIntfMethods - Checks that methods declared in the
|
2008-09-05 04:01:15 +08:00
|
|
|
/// category interface are implemented in the category @implementation.
|
2008-01-08 03:49:32 +08:00
|
|
|
void Sema::ImplCategoryMethodsVsIntfMethods(ObjCCategoryImplDecl *CatImplDecl,
|
|
|
|
ObjCCategoryDecl *CatClassDecl) {
|
2007-12-12 15:09:47 +08:00
|
|
|
llvm::DenseSet<Selector> InsMap;
|
|
|
|
// Check and see if instance methods in category interface have been
|
|
|
|
// implemented in its implementation class.
|
2008-01-08 03:49:32 +08:00
|
|
|
for (ObjCCategoryImplDecl::instmeth_iterator I =CatImplDecl->instmeth_begin(),
|
2007-12-13 01:58:05 +08:00
|
|
|
E = CatImplDecl->instmeth_end(); I != E; ++I)
|
|
|
|
InsMap.insert((*I)->getSelector());
|
2007-12-12 15:09:47 +08:00
|
|
|
|
|
|
|
bool IncompleteImpl = false;
|
2008-01-08 03:49:32 +08:00
|
|
|
for (ObjCCategoryDecl::instmeth_iterator I = CatClassDecl->instmeth_begin(),
|
2007-12-15 07:37:57 +08:00
|
|
|
E = CatClassDecl->instmeth_end(); I != E; ++I)
|
2008-12-23 03:05:31 +08:00
|
|
|
if (!(*I)->isSynthesized() && !InsMap.count((*I)->getSelector()))
|
2008-02-11 05:38:56 +08:00
|
|
|
WarnUndefinedMethod(CatImplDecl->getLocation(), *I, IncompleteImpl);
|
2008-12-06 02:18:52 +08:00
|
|
|
else {
|
|
|
|
ObjCMethodDecl *ImpMethodDecl =
|
|
|
|
CatImplDecl->getInstanceMethod((*I)->getSelector());
|
|
|
|
ObjCMethodDecl *IntfMethodDecl =
|
|
|
|
CatClassDecl->getInstanceMethod((*I)->getSelector());
|
2008-12-23 03:05:31 +08:00
|
|
|
assert(IntfMethodDecl &&
|
|
|
|
"IntfMethodDecl is null in ImplCategoryMethodsVsIntfMethods");
|
|
|
|
// ImpMethodDecl may be null as in a @dynamic property.
|
|
|
|
if (ImpMethodDecl)
|
|
|
|
WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl);
|
2008-12-06 02:18:52 +08:00
|
|
|
}
|
2008-02-11 05:38:56 +08:00
|
|
|
|
2007-12-12 15:09:47 +08:00
|
|
|
llvm::DenseSet<Selector> ClsMap;
|
|
|
|
// Check and see if class methods in category interface have been
|
|
|
|
// implemented in its implementation class.
|
2008-01-08 03:49:32 +08:00
|
|
|
for (ObjCCategoryImplDecl::classmeth_iterator
|
2007-12-13 01:58:05 +08:00
|
|
|
I = CatImplDecl->classmeth_begin(), E = CatImplDecl->classmeth_end();
|
|
|
|
I != E; ++I)
|
|
|
|
ClsMap.insert((*I)->getSelector());
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
for (ObjCCategoryDecl::classmeth_iterator I = CatClassDecl->classmeth_begin(),
|
2007-12-15 07:37:57 +08:00
|
|
|
E = CatClassDecl->classmeth_end(); I != E; ++I)
|
2008-02-11 05:38:56 +08:00
|
|
|
if (!ClsMap.count((*I)->getSelector()))
|
|
|
|
WarnUndefinedMethod(CatImplDecl->getLocation(), *I, IncompleteImpl);
|
2008-12-06 02:18:52 +08:00
|
|
|
else {
|
|
|
|
ObjCMethodDecl *ImpMethodDecl =
|
|
|
|
CatImplDecl->getClassMethod((*I)->getSelector());
|
|
|
|
ObjCMethodDecl *IntfMethodDecl =
|
|
|
|
CatClassDecl->getClassMethod((*I)->getSelector());
|
|
|
|
WarnConflictingTypedMethods(ImpMethodDecl, IntfMethodDecl);
|
|
|
|
}
|
2007-12-12 15:09:47 +08:00
|
|
|
// Check the protocol list for unimplemented methods in the @implementation
|
|
|
|
// class.
|
2008-07-22 05:32:27 +08:00
|
|
|
for (ObjCCategoryDecl::protocol_iterator PI = CatClassDecl->protocol_begin(),
|
|
|
|
E = CatClassDecl->protocol_end(); PI != E; ++PI)
|
|
|
|
CheckProtocolMethodDefs(CatImplDecl->getLocation(), *PI, IncompleteImpl,
|
2008-09-05 04:01:15 +08:00
|
|
|
InsMap, ClsMap, CatClassDecl->getClassInterface());
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ActOnForwardClassDeclaration -
|
|
|
|
Action::DeclTy *
|
|
|
|
Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
|
2009-02-17 03:25:52 +08:00
|
|
|
IdentifierInfo **IdentList,
|
|
|
|
unsigned NumElts) {
|
2008-01-08 03:49:32 +08:00
|
|
|
llvm::SmallVector<ObjCInterfaceDecl*, 32> Interfaces;
|
2007-12-12 15:09:47 +08:00
|
|
|
|
|
|
|
for (unsigned i = 0; i != NumElts; ++i) {
|
|
|
|
// Check for another declaration kind with the same name.
|
2009-02-05 01:27:36 +08:00
|
|
|
NamedDecl *PrevDecl = LookupName(TUScope, IdentList[i], LookupOrdinaryName);
|
2008-12-09 02:40:42 +08:00
|
|
|
if (PrevDecl && PrevDecl->isTemplateParameter()) {
|
2008-12-06 02:15:24 +08:00
|
|
|
// Maybe we will complain about the shadowed template parameter.
|
|
|
|
DiagnoseTemplateParameterShadow(AtClassLoc, PrevDecl);
|
|
|
|
// Just pretend that we didn't see the previous declaration.
|
|
|
|
PrevDecl = 0;
|
|
|
|
}
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) {
|
2008-06-06 06:57:10 +08:00
|
|
|
// GCC apparently allows the following idiom:
|
|
|
|
//
|
|
|
|
// typedef NSObject < XCElementTogglerP > XCElementToggler;
|
|
|
|
// @class XCElementToggler;
|
|
|
|
//
|
|
|
|
// FIXME: Make an extension?
|
|
|
|
TypedefDecl *TDD = dyn_cast<TypedefDecl>(PrevDecl);
|
|
|
|
if (!TDD || !isa<ObjCInterfaceType>(TDD->getUnderlyingType())) {
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(AtClassLoc, diag::err_redefinition_different_kind) << IdentList[i];
|
2008-11-24 07:12:31 +08:00
|
|
|
Diag(PrevDecl->getLocation(), diag::note_previous_definition);
|
2008-06-06 06:57:10 +08:00
|
|
|
}
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
if (!IDecl) { // Not already seen? Make a forward decl.
|
2009-01-09 08:49:46 +08:00
|
|
|
IDecl = ObjCInterfaceDecl::Create(Context, CurContext, AtClassLoc,
|
|
|
|
IdentList[i], SourceLocation(), true);
|
2008-04-03 02:30:49 +08:00
|
|
|
ObjCInterfaceDecls[IdentList[i]] = IDecl;
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2009-01-09 08:49:46 +08:00
|
|
|
// FIXME: PushOnScopeChains?
|
2009-01-13 07:27:07 +08:00
|
|
|
CurContext->addDecl(IDecl);
|
2007-12-12 15:09:47 +08:00
|
|
|
// Remember that this needs to be removed when the scope is popped.
|
|
|
|
TUScope->AddDecl(IDecl);
|
|
|
|
}
|
|
|
|
|
|
|
|
Interfaces.push_back(IDecl);
|
|
|
|
}
|
|
|
|
|
2009-01-09 08:49:46 +08:00
|
|
|
ObjCClassDecl *CDecl = ObjCClassDecl::Create(Context, CurContext, AtClassLoc,
|
2008-11-05 00:57:32 +08:00
|
|
|
&Interfaces[0],
|
|
|
|
Interfaces.size());
|
2009-01-13 07:27:07 +08:00
|
|
|
CurContext->addDecl(CDecl);
|
2008-11-05 00:57:32 +08:00
|
|
|
CheckObjCDeclScope(CDecl);
|
|
|
|
return CDecl;
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// MatchTwoMethodDeclarations - Checks that two methods have matching type and
|
|
|
|
/// returns true, or false, accordingly.
|
|
|
|
/// TODO: Handle protocol list; such as id<p1,p2> in type comparisons
|
2008-01-08 03:49:32 +08:00
|
|
|
bool Sema::MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
|
2008-10-21 18:37:50 +08:00
|
|
|
const ObjCMethodDecl *PrevMethod,
|
|
|
|
bool matchBasedOnSizeAndAlignment) {
|
|
|
|
QualType T1 = Context.getCanonicalType(Method->getResultType());
|
|
|
|
QualType T2 = Context.getCanonicalType(PrevMethod->getResultType());
|
|
|
|
|
|
|
|
if (T1 != T2) {
|
|
|
|
// The result types are different.
|
|
|
|
if (!matchBasedOnSizeAndAlignment)
|
|
|
|
return false;
|
|
|
|
// Incomplete types don't have a size and alignment.
|
|
|
|
if (T1->isIncompleteType() || T2->isIncompleteType())
|
2007-12-12 15:09:47 +08:00
|
|
|
return false;
|
2008-10-21 18:37:50 +08:00
|
|
|
// Check is based on size and alignment.
|
|
|
|
if (Context.getTypeInfo(T1) != Context.getTypeInfo(T2))
|
|
|
|
return false;
|
|
|
|
}
|
2009-02-21 02:43:26 +08:00
|
|
|
|
|
|
|
ObjCMethodDecl::param_iterator ParamI = Method->param_begin(),
|
|
|
|
E = Method->param_end();
|
|
|
|
ObjCMethodDecl::param_iterator PrevI = PrevMethod->param_begin();
|
|
|
|
|
|
|
|
for (; ParamI != E; ++ParamI, ++PrevI) {
|
|
|
|
assert(PrevI != PrevMethod->param_end() && "Param mismatch");
|
|
|
|
T1 = Context.getCanonicalType((*ParamI)->getType());
|
|
|
|
T2 = Context.getCanonicalType((*PrevI)->getType());
|
2008-10-21 18:37:50 +08:00
|
|
|
if (T1 != T2) {
|
|
|
|
// The result types are different.
|
|
|
|
if (!matchBasedOnSizeAndAlignment)
|
|
|
|
return false;
|
|
|
|
// Incomplete types don't have a size and alignment.
|
|
|
|
if (T1->isIncompleteType() || T2->isIncompleteType())
|
|
|
|
return false;
|
|
|
|
// Check is based on size and alignment.
|
|
|
|
if (Context.getTypeInfo(T1) != Context.getTypeInfo(T2))
|
|
|
|
return false;
|
|
|
|
}
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
void Sema::AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method) {
|
|
|
|
ObjCMethodList &FirstMethod = InstanceMethodPool[Method->getSelector()];
|
2007-12-12 15:09:47 +08:00
|
|
|
if (!FirstMethod.Method) {
|
|
|
|
// Haven't seen a method with this selector name yet - add it.
|
|
|
|
FirstMethod.Method = Method;
|
|
|
|
FirstMethod.Next = 0;
|
|
|
|
} else {
|
|
|
|
// We've seen a method with this name, now check the type signature(s).
|
|
|
|
bool match = MatchTwoMethodDeclarations(Method, FirstMethod.Method);
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
for (ObjCMethodList *Next = FirstMethod.Next; !match && Next;
|
2007-12-12 15:09:47 +08:00
|
|
|
Next = Next->Next)
|
|
|
|
match = MatchTwoMethodDeclarations(Method, Next->Method);
|
|
|
|
|
|
|
|
if (!match) {
|
|
|
|
// We have a new signature for an existing method - add it.
|
|
|
|
// This is extremely rare. Only 1% of Cocoa selectors are "overloaded".
|
2008-11-24 11:33:13 +08:00
|
|
|
FirstMethod.Next = new ObjCMethodList(Method, FirstMethod.Next);;
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-21 18:50:19 +08:00
|
|
|
// FIXME: Finish implementing -Wno-strict-selector-match.
|
2008-09-30 22:38:43 +08:00
|
|
|
ObjCMethodDecl *Sema::LookupInstanceMethodInGlobalPool(Selector Sel,
|
|
|
|
SourceRange R) {
|
|
|
|
ObjCMethodList &MethList = InstanceMethodPool[Sel];
|
2008-10-21 18:37:50 +08:00
|
|
|
bool issueWarning = false;
|
2008-09-30 22:38:43 +08:00
|
|
|
|
|
|
|
if (MethList.Method && MethList.Next) {
|
2008-10-21 18:37:50 +08:00
|
|
|
for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next)
|
|
|
|
// This checks if the methods differ by size & alignment.
|
|
|
|
if (!MatchTwoMethodDeclarations(MethList.Method, Next->Method, true))
|
|
|
|
issueWarning = true;
|
|
|
|
}
|
|
|
|
if (issueWarning && (MethList.Method && MethList.Next)) {
|
2008-11-24 11:33:13 +08:00
|
|
|
Diag(R.getBegin(), diag::warn_multiple_method_decl) << Sel << R;
|
2008-11-24 07:26:13 +08:00
|
|
|
Diag(MethList.Method->getLocStart(), diag::note_using_decl)
|
2008-11-19 13:27:50 +08:00
|
|
|
<< MethList.Method->getSourceRange();
|
2008-09-30 22:38:43 +08:00
|
|
|
for (ObjCMethodList *Next = MethList.Next; Next; Next = Next->Next)
|
2008-11-24 07:26:13 +08:00
|
|
|
Diag(Next->Method->getLocStart(), diag::note_also_found_decl)
|
2008-11-19 13:27:50 +08:00
|
|
|
<< Next->Method->getSourceRange();
|
2008-09-30 22:38:43 +08:00
|
|
|
}
|
|
|
|
return MethList.Method;
|
|
|
|
}
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
void Sema::AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method) {
|
|
|
|
ObjCMethodList &FirstMethod = FactoryMethodPool[Method->getSelector()];
|
2007-12-12 15:09:47 +08:00
|
|
|
if (!FirstMethod.Method) {
|
|
|
|
// Haven't seen a method with this selector name yet - add it.
|
|
|
|
FirstMethod.Method = Method;
|
|
|
|
FirstMethod.Next = 0;
|
|
|
|
} else {
|
|
|
|
// We've seen a method with this name, now check the type signature(s).
|
|
|
|
bool match = MatchTwoMethodDeclarations(Method, FirstMethod.Method);
|
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
for (ObjCMethodList *Next = FirstMethod.Next; !match && Next;
|
2007-12-12 15:09:47 +08:00
|
|
|
Next = Next->Next)
|
|
|
|
match = MatchTwoMethodDeclarations(Method, Next->Method);
|
|
|
|
|
|
|
|
if (!match) {
|
|
|
|
// We have a new signature for an existing method - add it.
|
|
|
|
// This is extremely rare. Only 1% of Cocoa selectors are "overloaded".
|
2008-01-08 03:49:32 +08:00
|
|
|
struct ObjCMethodList *OMI = new ObjCMethodList(Method, FirstMethod.Next);
|
2007-12-12 15:09:47 +08:00
|
|
|
FirstMethod.Next = OMI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-09 01:28:14 +08:00
|
|
|
/// ProcessPropertyDecl - Make sure that any user-defined setter/getter methods
|
|
|
|
/// have the property type and issue diagnostics if they don't.
|
|
|
|
/// Also synthesize a getter/setter method if none exist (and update the
|
|
|
|
/// appropriate lookup tables. FIXME: Should reconsider if adding synthesized
|
|
|
|
/// methods is the "right" thing to do.
|
|
|
|
void Sema::ProcessPropertyDecl(ObjCPropertyDecl *property,
|
|
|
|
ObjCContainerDecl *CD) {
|
|
|
|
ObjCMethodDecl *GetterMethod, *SetterMethod;
|
|
|
|
|
|
|
|
GetterMethod = CD->getInstanceMethod(property->getGetterName());
|
|
|
|
SetterMethod = CD->getInstanceMethod(property->getSetterName());
|
|
|
|
|
2008-12-03 02:39:49 +08:00
|
|
|
if (GetterMethod &&
|
2008-12-07 05:48:16 +08:00
|
|
|
GetterMethod->getResultType() != property->getType()) {
|
2008-12-03 02:39:49 +08:00
|
|
|
Diag(property->getLocation(),
|
|
|
|
diag::err_accessor_property_type_mismatch)
|
|
|
|
<< property->getDeclName()
|
|
|
|
<< GetterMethod->getSelector().getAsIdentifierInfo();
|
2008-12-07 05:48:16 +08:00
|
|
|
Diag(GetterMethod->getLocation(), diag::note_declared_at);
|
|
|
|
}
|
2008-12-03 02:39:49 +08:00
|
|
|
|
|
|
|
if (SetterMethod) {
|
2008-12-07 07:12:49 +08:00
|
|
|
if (Context.getCanonicalType(SetterMethod->getResultType())
|
|
|
|
!= Context.VoidTy)
|
2008-12-03 02:39:49 +08:00
|
|
|
Diag(SetterMethod->getLocation(), diag::err_setter_type_void);
|
2009-02-21 02:43:26 +08:00
|
|
|
if (SetterMethod->param_size() != 1 ||
|
|
|
|
((*SetterMethod->param_begin())->getType() != property->getType())) {
|
2008-12-03 02:39:49 +08:00
|
|
|
Diag(property->getLocation(),
|
|
|
|
diag::err_accessor_property_type_mismatch)
|
|
|
|
<< property->getDeclName()
|
|
|
|
<< SetterMethod->getSelector().getAsIdentifierInfo();
|
2008-12-07 05:48:16 +08:00
|
|
|
Diag(SetterMethod->getLocation(), diag::note_declared_at);
|
|
|
|
}
|
2008-12-03 02:39:49 +08:00
|
|
|
}
|
2009-01-09 01:28:14 +08:00
|
|
|
|
|
|
|
// Synthesize getter/setter methods if none exist.
|
2009-01-09 04:15:03 +08:00
|
|
|
// Find the default getter and if one not found, add one.
|
2009-01-09 04:17:34 +08:00
|
|
|
// FIXME: The synthesized property we set here is misleading. We
|
|
|
|
// almost always synthesize these methods unless the user explicitly
|
|
|
|
// provided prototypes (which is odd, but allowed). Sema should be
|
|
|
|
// typechecking that the declarations jive in that situation (which
|
|
|
|
// it is not currently).
|
2009-01-09 04:15:03 +08:00
|
|
|
if (!GetterMethod) {
|
|
|
|
// No instance method of same name as property getter name was found.
|
|
|
|
// Declare a getter method and add it to the list of methods
|
|
|
|
// for this class.
|
|
|
|
GetterMethod = ObjCMethodDecl::Create(Context, property->getLocation(),
|
|
|
|
property->getLocation(), property->getGetterName(),
|
|
|
|
property->getType(), CD, true, false, true,
|
|
|
|
(property->getPropertyImplementation() ==
|
|
|
|
ObjCPropertyDecl::Optional) ?
|
|
|
|
ObjCMethodDecl::Optional :
|
|
|
|
ObjCMethodDecl::Required);
|
2009-01-13 07:27:07 +08:00
|
|
|
CD->addDecl(GetterMethod);
|
2009-01-09 04:15:03 +08:00
|
|
|
} else
|
|
|
|
// A user declared getter will be synthesize when @synthesize of
|
|
|
|
// the property with the same name is seen in the @implementation
|
|
|
|
GetterMethod->setIsSynthesized();
|
|
|
|
property->setGetterMethodDecl(GetterMethod);
|
|
|
|
|
|
|
|
// Skip setter if property is read-only.
|
|
|
|
if (!property->isReadOnly()) {
|
|
|
|
// Find the default setter and if one not found, add one.
|
|
|
|
if (!SetterMethod) {
|
|
|
|
// No instance method of same name as property setter name was found.
|
|
|
|
// Declare a setter method and add it to the list of methods
|
|
|
|
// for this class.
|
|
|
|
SetterMethod = ObjCMethodDecl::Create(Context, property->getLocation(),
|
|
|
|
property->getLocation(),
|
|
|
|
property->getSetterName(),
|
|
|
|
Context.VoidTy, CD, true, false, true,
|
|
|
|
(property->getPropertyImplementation() ==
|
|
|
|
ObjCPropertyDecl::Optional) ?
|
|
|
|
ObjCMethodDecl::Optional :
|
|
|
|
ObjCMethodDecl::Required);
|
|
|
|
// Invent the arguments for the setter. We don't bother making a
|
|
|
|
// nice name for the argument.
|
|
|
|
ParmVarDecl *Argument = ParmVarDecl::Create(Context, SetterMethod,
|
|
|
|
SourceLocation(),
|
|
|
|
property->getIdentifier(),
|
|
|
|
property->getType(),
|
|
|
|
VarDecl::None,
|
2009-01-20 09:17:11 +08:00
|
|
|
0);
|
2009-01-09 04:15:03 +08:00
|
|
|
SetterMethod->setMethodParams(&Argument, 1);
|
2009-01-13 07:27:07 +08:00
|
|
|
CD->addDecl(SetterMethod);
|
2009-01-09 04:15:03 +08:00
|
|
|
} else
|
|
|
|
// A user declared setter will be synthesize when @synthesize of
|
|
|
|
// the property with the same name is seen in the @implementation
|
|
|
|
SetterMethod->setIsSynthesized();
|
|
|
|
property->setSetterMethodDecl(SetterMethod);
|
|
|
|
}
|
2009-01-09 01:28:14 +08:00
|
|
|
// Add any synthesized methods to the global pool. This allows us to
|
|
|
|
// handle the following, which is supported by GCC (and part of the design).
|
|
|
|
//
|
|
|
|
// @interface Foo
|
|
|
|
// @property double bar;
|
|
|
|
// @end
|
|
|
|
//
|
|
|
|
// void thisIsUnfortunate() {
|
|
|
|
// id foo;
|
|
|
|
// double bar = [foo bar];
|
|
|
|
// }
|
|
|
|
//
|
2009-01-10 03:42:16 +08:00
|
|
|
if (GetterMethod)
|
2009-01-09 01:28:14 +08:00
|
|
|
AddInstanceMethodToGlobalPool(GetterMethod);
|
2009-01-10 03:42:16 +08:00
|
|
|
if (SetterMethod)
|
2009-01-09 01:28:14 +08:00
|
|
|
AddInstanceMethodToGlobalPool(SetterMethod);
|
2008-12-03 02:39:49 +08:00
|
|
|
}
|
|
|
|
|
2007-12-18 09:30:32 +08:00
|
|
|
// Note: For class/category implemenations, allMethods/allProperties is
|
|
|
|
// always null.
|
2007-12-12 15:09:47 +08:00
|
|
|
void Sema::ActOnAtEnd(SourceLocation AtEndLoc, DeclTy *classDecl,
|
|
|
|
DeclTy **allMethods, unsigned allNum,
|
|
|
|
DeclTy **allProperties, unsigned pNum) {
|
|
|
|
Decl *ClassDecl = static_cast<Decl *>(classDecl);
|
|
|
|
|
2007-12-18 09:30:32 +08:00
|
|
|
// FIXME: If we don't have a ClassDecl, we have an error. We should consider
|
|
|
|
// always passing in a decl. If the decl has an error, isInvalidDecl()
|
2007-12-12 15:09:47 +08:00
|
|
|
// should be true.
|
|
|
|
if (!ClassDecl)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool isInterfaceDeclKind =
|
2008-03-17 05:17:37 +08:00
|
|
|
isa<ObjCInterfaceDecl>(ClassDecl) || isa<ObjCCategoryDecl>(ClassDecl)
|
|
|
|
|| isa<ObjCProtocolDecl>(ClassDecl);
|
2008-01-08 03:49:32 +08:00
|
|
|
bool checkIdenticalMethods = isa<ObjCImplementationDecl>(ClassDecl);
|
2009-01-09 23:36:25 +08:00
|
|
|
|
2009-01-09 01:28:14 +08:00
|
|
|
DeclContext *DC = dyn_cast<DeclContext>(ClassDecl);
|
|
|
|
|
|
|
|
// FIXME: Remove these and use the ObjCContainerDecl/DeclContext.
|
|
|
|
llvm::DenseMap<Selector, const ObjCMethodDecl*> InsMap;
|
|
|
|
llvm::DenseMap<Selector, const ObjCMethodDecl*> ClsMap;
|
|
|
|
|
2007-12-12 15:09:47 +08:00
|
|
|
for (unsigned i = 0; i < allNum; i++ ) {
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCMethodDecl *Method =
|
|
|
|
cast_or_null<ObjCMethodDecl>(static_cast<Decl*>(allMethods[i]));
|
2007-12-12 15:09:47 +08:00
|
|
|
|
|
|
|
if (!Method) continue; // Already issued a diagnostic.
|
2009-01-10 01:18:27 +08:00
|
|
|
if (Method->isInstanceMethod()) {
|
2007-12-12 15:09:47 +08:00
|
|
|
/// Check for instance method of the same name with incompatible types
|
2008-01-08 03:49:32 +08:00
|
|
|
const ObjCMethodDecl *&PrevMethod = InsMap[Method->getSelector()];
|
2007-12-12 15:09:47 +08:00
|
|
|
bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod)
|
|
|
|
: false;
|
2008-12-17 04:15:50 +08:00
|
|
|
if ((isInterfaceDeclKind && PrevMethod && !match)
|
|
|
|
|| (checkIdenticalMethods && match)) {
|
2008-11-24 07:12:31 +08:00
|
|
|
Diag(Method->getLocation(), diag::err_duplicate_method_decl)
|
2008-11-24 11:33:13 +08:00
|
|
|
<< Method->getDeclName();
|
2008-11-24 07:12:31 +08:00
|
|
|
Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
|
2007-12-12 15:09:47 +08:00
|
|
|
} else {
|
2009-01-13 07:27:07 +08:00
|
|
|
DC->addDecl(Method);
|
2007-12-12 15:09:47 +08:00
|
|
|
InsMap[Method->getSelector()] = Method;
|
|
|
|
/// The following allows us to typecheck messages to "id".
|
|
|
|
AddInstanceMethodToGlobalPool(Method);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/// Check for class method of the same name with incompatible types
|
2008-01-08 03:49:32 +08:00
|
|
|
const ObjCMethodDecl *&PrevMethod = ClsMap[Method->getSelector()];
|
2007-12-12 15:09:47 +08:00
|
|
|
bool match = PrevMethod ? MatchTwoMethodDeclarations(Method, PrevMethod)
|
|
|
|
: false;
|
2008-12-17 04:15:50 +08:00
|
|
|
if ((isInterfaceDeclKind && PrevMethod && !match)
|
|
|
|
|| (checkIdenticalMethods && match)) {
|
2008-11-24 07:12:31 +08:00
|
|
|
Diag(Method->getLocation(), diag::err_duplicate_method_decl)
|
2008-11-24 11:33:13 +08:00
|
|
|
<< Method->getDeclName();
|
2008-11-24 07:12:31 +08:00
|
|
|
Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
|
2007-12-12 15:09:47 +08:00
|
|
|
} else {
|
2009-01-13 07:27:07 +08:00
|
|
|
DC->addDecl(Method);
|
2007-12-12 15:09:47 +08:00
|
|
|
ClsMap[Method->getSelector()] = Method;
|
2007-12-18 09:30:32 +08:00
|
|
|
/// The following allows us to typecheck messages to "Class".
|
|
|
|
AddFactoryMethodToGlobalPool(Method);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-01-08 03:49:32 +08:00
|
|
|
if (ObjCInterfaceDecl *I = dyn_cast<ObjCInterfaceDecl>(ClassDecl)) {
|
2008-08-27 13:40:03 +08:00
|
|
|
// Compares properties declared in this class to those of its
|
2008-05-01 08:03:38 +08:00
|
|
|
// super class.
|
2008-05-03 03:17:30 +08:00
|
|
|
ComparePropertiesInBaseAndSuper(I);
|
|
|
|
MergeProtocolPropertiesIntoClass(I, I);
|
2009-01-09 23:36:25 +08:00
|
|
|
} else if (ObjCCategoryDecl *C = dyn_cast<ObjCCategoryDecl>(ClassDecl)) {
|
2008-12-07 03:59:02 +08:00
|
|
|
// Categories are used to extend the class by declaring new methods.
|
|
|
|
// By the same token, they are also used to add new properties. No
|
|
|
|
// need to compare the added property to those in the class.
|
2008-08-27 13:40:03 +08:00
|
|
|
|
2008-12-07 07:03:39 +08:00
|
|
|
// Merge protocol properties into category
|
|
|
|
MergeProtocolPropertiesIntoClass(C, C);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
2009-01-09 23:36:25 +08:00
|
|
|
if (ObjCContainerDecl *CDecl = dyn_cast<ObjCContainerDecl>(ClassDecl)) {
|
|
|
|
// ProcessPropertyDecl is responsible for diagnosing conflicts with any
|
|
|
|
// user-defined setter/getter. It also synthesizes setter/getter methods
|
|
|
|
// and adds them to the DeclContext and global method pools.
|
2009-02-17 02:32:47 +08:00
|
|
|
for (ObjCContainerDecl::prop_iterator I = CDecl->prop_begin(),
|
|
|
|
E = CDecl->prop_end(); I != E; ++I)
|
|
|
|
ProcessPropertyDecl(*I, CDecl);
|
2009-01-09 23:36:25 +08:00
|
|
|
CDecl->setAtEndLoc(AtEndLoc);
|
|
|
|
}
|
|
|
|
if (ObjCImplementationDecl *IC=dyn_cast<ObjCImplementationDecl>(ClassDecl)) {
|
2007-12-12 15:09:47 +08:00
|
|
|
IC->setLocEnd(AtEndLoc);
|
2009-01-20 09:17:11 +08:00
|
|
|
if (ObjCInterfaceDecl* IDecl = IC->getClassInterface())
|
2007-12-12 15:09:47 +08:00
|
|
|
ImplMethodsVsClassMethods(IC, IDecl);
|
2009-01-09 23:36:25 +08:00
|
|
|
} else if (ObjCCategoryImplDecl* CatImplClass =
|
|
|
|
dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) {
|
2007-12-12 15:09:47 +08:00
|
|
|
CatImplClass->setLocEnd(AtEndLoc);
|
2009-02-17 02:32:47 +08:00
|
|
|
|
2007-12-12 15:09:47 +08:00
|
|
|
// Find category interface decl and then check that all methods declared
|
2008-08-27 13:40:03 +08:00
|
|
|
// in this interface are implemented in the category @implementation.
|
2009-02-17 02:32:47 +08:00
|
|
|
if (ObjCInterfaceDecl* IDecl = CatImplClass->getClassInterface()) {
|
2008-01-08 03:49:32 +08:00
|
|
|
for (ObjCCategoryDecl *Categories = IDecl->getCategoryList();
|
2007-12-12 15:09:47 +08:00
|
|
|
Categories; Categories = Categories->getNextClassCategory()) {
|
|
|
|
if (Categories->getIdentifier() == CatImplClass->getIdentifier()) {
|
|
|
|
ImplCategoryMethodsVsIntfMethods(CatImplClass, Categories);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// CvtQTToAstBitMask - utility routine to produce an AST bitmask for
|
|
|
|
/// objective-c's type qualifier from the parser version of the same info.
|
2008-01-08 03:49:32 +08:00
|
|
|
static Decl::ObjCDeclQualifier
|
|
|
|
CvtQTToAstBitMask(ObjCDeclSpec::ObjCDeclQualifier PQTVal) {
|
|
|
|
Decl::ObjCDeclQualifier ret = Decl::OBJC_TQ_None;
|
|
|
|
if (PQTVal & ObjCDeclSpec::DQ_In)
|
|
|
|
ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_In);
|
|
|
|
if (PQTVal & ObjCDeclSpec::DQ_Inout)
|
|
|
|
ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Inout);
|
|
|
|
if (PQTVal & ObjCDeclSpec::DQ_Out)
|
|
|
|
ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Out);
|
|
|
|
if (PQTVal & ObjCDeclSpec::DQ_Bycopy)
|
|
|
|
ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Bycopy);
|
|
|
|
if (PQTVal & ObjCDeclSpec::DQ_Byref)
|
|
|
|
ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Byref);
|
|
|
|
if (PQTVal & ObjCDeclSpec::DQ_Oneway)
|
|
|
|
ret = (Decl::ObjCDeclQualifier)(ret | Decl::OBJC_TQ_Oneway);
|
2007-12-12 15:09:47 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
Sema::DeclTy *Sema::ActOnMethodDeclaration(
|
|
|
|
SourceLocation MethodLoc, SourceLocation EndLoc,
|
2008-03-16 08:49:28 +08:00
|
|
|
tok::TokenKind MethodType, DeclTy *classDecl,
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCDeclSpec &ReturnQT, TypeTy *ReturnType,
|
2007-12-12 15:09:47 +08:00
|
|
|
Selector Sel,
|
|
|
|
// optional arguments. The number of types/arguments is obtained
|
|
|
|
// from the Sel.getNumArgs().
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCDeclSpec *ArgQT, TypeTy **ArgTypes, IdentifierInfo **ArgNames,
|
2009-01-09 08:38:19 +08:00
|
|
|
llvm::SmallVectorImpl<Declarator> &Cdecls,
|
2007-12-12 15:09:47 +08:00
|
|
|
AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind,
|
|
|
|
bool isVariadic) {
|
2008-03-16 08:49:28 +08:00
|
|
|
Decl *ClassDecl = static_cast<Decl*>(classDecl);
|
2008-03-01 05:48:07 +08:00
|
|
|
|
|
|
|
// Make sure we can establish a context for the method.
|
|
|
|
if (!ClassDecl) {
|
|
|
|
Diag(MethodLoc, diag::error_missing_method_context);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-04-04 14:12:32 +08:00
|
|
|
QualType resultDeclType;
|
|
|
|
|
|
|
|
if (ReturnType)
|
|
|
|
resultDeclType = QualType::getFromOpaquePtr(ReturnType);
|
|
|
|
else // get the type for "id".
|
|
|
|
resultDeclType = Context.getObjCIdType();
|
|
|
|
|
|
|
|
ObjCMethodDecl* ObjCMethod =
|
|
|
|
ObjCMethodDecl::Create(Context, MethodLoc, EndLoc, Sel, resultDeclType,
|
2009-01-09 01:28:14 +08:00
|
|
|
dyn_cast<DeclContext>(ClassDecl),
|
2008-04-04 14:12:32 +08:00
|
|
|
MethodType == tok::minus, isVariadic,
|
2008-05-08 04:53:44 +08:00
|
|
|
false,
|
2008-04-04 14:12:32 +08:00
|
|
|
MethodDeclKind == tok::objc_optional ?
|
|
|
|
ObjCMethodDecl::Optional :
|
|
|
|
ObjCMethodDecl::Required);
|
|
|
|
|
2007-12-12 15:09:47 +08:00
|
|
|
llvm::SmallVector<ParmVarDecl*, 16> Params;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < Sel.getNumArgs(); i++) {
|
|
|
|
// FIXME: arg->AttrList must be stored too!
|
2008-12-21 07:29:59 +08:00
|
|
|
QualType argType, originalArgType;
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2008-12-10 03:36:17 +08:00
|
|
|
if (ArgTypes[i]) {
|
2007-12-12 15:09:47 +08:00
|
|
|
argType = QualType::getFromOpaquePtr(ArgTypes[i]);
|
2008-12-10 03:36:17 +08:00
|
|
|
// Perform the default array/function conversions (C99 6.7.5.3p[7,8]).
|
2008-12-21 07:29:59 +08:00
|
|
|
if (argType->isArrayType()) { // (char *[]) -> (char **)
|
|
|
|
originalArgType = argType;
|
2008-12-10 03:36:17 +08:00
|
|
|
argType = Context.getArrayDecayedType(argType);
|
2008-12-21 07:29:59 +08:00
|
|
|
}
|
2008-12-10 03:36:17 +08:00
|
|
|
else if (argType->isFunctionType())
|
|
|
|
argType = Context.getPointerType(argType);
|
2009-01-18 05:57:49 +08:00
|
|
|
else if (argType->isObjCInterfaceType()) {
|
|
|
|
// FIXME! provide more precise location for the parameter
|
|
|
|
Diag(MethodLoc, diag::err_object_as_method_param);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-12-10 03:36:17 +08:00
|
|
|
} else
|
2008-01-08 03:49:32 +08:00
|
|
|
argType = Context.getObjCIdType();
|
2008-12-21 07:29:59 +08:00
|
|
|
ParmVarDecl* Param;
|
|
|
|
if (originalArgType.isNull())
|
|
|
|
Param = ParmVarDecl::Create(Context, ObjCMethod,
|
|
|
|
SourceLocation(/*FIXME*/),
|
|
|
|
ArgNames[i], argType,
|
2009-01-20 09:17:11 +08:00
|
|
|
VarDecl::None, 0);
|
2008-12-21 07:29:59 +08:00
|
|
|
else
|
2009-02-03 07:39:07 +08:00
|
|
|
Param = OriginalParmVarDecl::Create(Context, ObjCMethod,
|
|
|
|
SourceLocation(/*FIXME*/),
|
|
|
|
ArgNames[i], argType, originalArgType,
|
|
|
|
VarDecl::None, 0);
|
2008-12-21 07:29:59 +08:00
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
Param->setObjCDeclQualifier(
|
|
|
|
CvtQTToAstBitMask(ArgQT[i].getObjCDeclQualifier()));
|
2007-12-12 15:09:47 +08:00
|
|
|
Params.push_back(Param);
|
|
|
|
}
|
2008-04-04 14:12:32 +08:00
|
|
|
|
2008-01-08 03:49:32 +08:00
|
|
|
ObjCMethod->setMethodParams(&Params[0], Sel.getNumArgs());
|
|
|
|
ObjCMethod->setObjCDeclQualifier(
|
|
|
|
CvtQTToAstBitMask(ReturnQT.getObjCDeclQualifier()));
|
|
|
|
const ObjCMethodDecl *PrevMethod = 0;
|
2008-09-26 12:12:28 +08:00
|
|
|
|
|
|
|
if (AttrList)
|
|
|
|
ProcessDeclAttributeList(ObjCMethod, AttrList);
|
2007-12-12 15:09:47 +08:00
|
|
|
|
|
|
|
// For implementations (which can be very "coarse grain"), we add the
|
|
|
|
// method now. This allows the AST to implement lookup methods that work
|
|
|
|
// incrementally (without waiting until we parse the @end). It also allows
|
|
|
|
// us to flag multiple declaration errors as they occur.
|
2008-01-08 03:49:32 +08:00
|
|
|
if (ObjCImplementationDecl *ImpDecl =
|
2008-03-16 08:49:28 +08:00
|
|
|
dyn_cast<ObjCImplementationDecl>(ClassDecl)) {
|
2007-12-12 15:09:47 +08:00
|
|
|
if (MethodType == tok::minus) {
|
2007-12-20 06:27:04 +08:00
|
|
|
PrevMethod = ImpDecl->getInstanceMethod(Sel);
|
2008-01-08 03:49:32 +08:00
|
|
|
ImpDecl->addInstanceMethod(ObjCMethod);
|
2007-12-12 15:09:47 +08:00
|
|
|
} else {
|
2007-12-20 06:27:04 +08:00
|
|
|
PrevMethod = ImpDecl->getClassMethod(Sel);
|
2008-01-08 03:49:32 +08:00
|
|
|
ImpDecl->addClassMethod(ObjCMethod);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
}
|
2008-01-08 03:49:32 +08:00
|
|
|
else if (ObjCCategoryImplDecl *CatImpDecl =
|
2008-03-16 08:49:28 +08:00
|
|
|
dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) {
|
2007-12-12 15:09:47 +08:00
|
|
|
if (MethodType == tok::minus) {
|
2007-12-20 06:27:04 +08:00
|
|
|
PrevMethod = CatImpDecl->getInstanceMethod(Sel);
|
2008-01-08 03:49:32 +08:00
|
|
|
CatImpDecl->addInstanceMethod(ObjCMethod);
|
2007-12-12 15:09:47 +08:00
|
|
|
} else {
|
2007-12-20 06:27:04 +08:00
|
|
|
PrevMethod = CatImpDecl->getClassMethod(Sel);
|
2008-01-08 03:49:32 +08:00
|
|
|
CatImpDecl->addClassMethod(ObjCMethod);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (PrevMethod) {
|
|
|
|
// You can never have two method definitions with the same name.
|
2008-11-24 07:12:31 +08:00
|
|
|
Diag(ObjCMethod->getLocation(), diag::err_duplicate_method_decl)
|
2008-11-24 11:33:13 +08:00
|
|
|
<< ObjCMethod->getDeclName();
|
2008-11-24 07:12:31 +08:00
|
|
|
Diag(PrevMethod->getLocation(), diag::note_previous_declaration);
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
2008-01-08 03:49:32 +08:00
|
|
|
return ObjCMethod;
|
2007-12-12 15:09:47 +08:00
|
|
|
}
|
|
|
|
|
2008-09-24 05:53:23 +08:00
|
|
|
void Sema::CheckObjCPropertyAttributes(QualType PropertyTy,
|
|
|
|
SourceLocation Loc,
|
|
|
|
unsigned &Attributes) {
|
|
|
|
// FIXME: Improve the reported location.
|
|
|
|
|
2008-12-06 09:12:43 +08:00
|
|
|
// readonly and readwrite/assign/retain/copy conflict.
|
2008-09-24 05:53:23 +08:00
|
|
|
if ((Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
|
2008-12-06 09:12:43 +08:00
|
|
|
(Attributes & (ObjCDeclSpec::DQ_PR_readwrite |
|
|
|
|
ObjCDeclSpec::DQ_PR_assign |
|
|
|
|
ObjCDeclSpec::DQ_PR_copy |
|
|
|
|
ObjCDeclSpec::DQ_PR_retain))) {
|
|
|
|
const char * which = (Attributes & ObjCDeclSpec::DQ_PR_readwrite) ?
|
|
|
|
"readwrite" :
|
|
|
|
(Attributes & ObjCDeclSpec::DQ_PR_assign) ?
|
|
|
|
"assign" :
|
|
|
|
(Attributes & ObjCDeclSpec::DQ_PR_copy) ?
|
|
|
|
"copy" : "retain";
|
|
|
|
|
2008-12-09 03:28:10 +08:00
|
|
|
Diag(Loc, (Attributes & (ObjCDeclSpec::DQ_PR_readwrite)) ?
|
2009-01-30 02:49:48 +08:00
|
|
|
diag::err_objc_property_attr_mutually_exclusive :
|
|
|
|
diag::warn_objc_property_attr_mutually_exclusive)
|
2008-12-06 09:12:43 +08:00
|
|
|
<< "readonly" << which;
|
2008-09-24 05:53:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for copy or retain on non-object types.
|
|
|
|
if ((Attributes & (ObjCDeclSpec::DQ_PR_copy | ObjCDeclSpec::DQ_PR_retain)) &&
|
|
|
|
!Context.isObjCObjectPointerType(PropertyTy)) {
|
2008-11-20 14:13:02 +08:00
|
|
|
Diag(Loc, diag::err_objc_property_requires_object)
|
|
|
|
<< (Attributes & ObjCDeclSpec::DQ_PR_copy ? "copy" : "retain");
|
2008-09-24 05:53:23 +08:00
|
|
|
Attributes &= ~(ObjCDeclSpec::DQ_PR_copy | ObjCDeclSpec::DQ_PR_retain);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for more than one of { assign, copy, retain }.
|
|
|
|
if (Attributes & ObjCDeclSpec::DQ_PR_assign) {
|
|
|
|
if (Attributes & ObjCDeclSpec::DQ_PR_copy) {
|
2008-11-20 14:13:02 +08:00
|
|
|
Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
|
|
|
|
<< "assign" << "copy";
|
|
|
|
Attributes &= ~ObjCDeclSpec::DQ_PR_copy;
|
2008-09-24 05:53:23 +08:00
|
|
|
}
|
|
|
|
if (Attributes & ObjCDeclSpec::DQ_PR_retain) {
|
2008-11-20 14:13:02 +08:00
|
|
|
Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
|
|
|
|
<< "assign" << "retain";
|
|
|
|
Attributes &= ~ObjCDeclSpec::DQ_PR_retain;
|
2008-09-24 05:53:23 +08:00
|
|
|
}
|
|
|
|
} else if (Attributes & ObjCDeclSpec::DQ_PR_copy) {
|
|
|
|
if (Attributes & ObjCDeclSpec::DQ_PR_retain) {
|
2008-11-20 14:13:02 +08:00
|
|
|
Diag(Loc, diag::err_objc_property_attr_mutually_exclusive)
|
|
|
|
<< "copy" << "retain";
|
|
|
|
Attributes &= ~ObjCDeclSpec::DQ_PR_retain;
|
2008-09-24 05:53:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Warn if user supplied no assignment attribute, property is
|
|
|
|
// readwrite, and this is an object type.
|
|
|
|
if (!(Attributes & (ObjCDeclSpec::DQ_PR_assign | ObjCDeclSpec::DQ_PR_copy |
|
|
|
|
ObjCDeclSpec::DQ_PR_retain)) &&
|
|
|
|
!(Attributes & ObjCDeclSpec::DQ_PR_readonly) &&
|
|
|
|
Context.isObjCObjectPointerType(PropertyTy)) {
|
|
|
|
// Skip this warning in gc-only mode.
|
|
|
|
if (getLangOptions().getGCMode() != LangOptions::GCOnly)
|
|
|
|
Diag(Loc, diag::warn_objc_property_no_assignment_attribute);
|
|
|
|
|
|
|
|
// If non-gc code warn that this is likely inappropriate.
|
|
|
|
if (getLangOptions().getGCMode() == LangOptions::NonGC)
|
|
|
|
Diag(Loc, diag::warn_objc_property_default_assign_on_object);
|
|
|
|
|
|
|
|
// FIXME: Implement warning dependent on NSCopying being
|
|
|
|
// implemented. See also:
|
|
|
|
// <rdar://5168496&4855821&5607453&5096644&4947311&5698469&4947014&5168496>
|
|
|
|
// (please trim this list while you are at it).
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-15 07:36:35 +08:00
|
|
|
Sema::DeclTy *Sema::ActOnProperty(Scope *S, SourceLocation AtLoc,
|
|
|
|
FieldDeclarator &FD,
|
2008-05-06 02:51:55 +08:00
|
|
|
ObjCDeclSpec &ODS,
|
2008-05-07 02:09:04 +08:00
|
|
|
Selector GetterSel,
|
|
|
|
Selector SetterSel,
|
2008-11-27 04:01:34 +08:00
|
|
|
DeclTy *ClassCategory,
|
|
|
|
bool *isOverridingProperty,
|
2008-05-06 02:51:55 +08:00
|
|
|
tok::ObjCKeywordKind MethodImplKind) {
|
2008-09-24 05:53:23 +08:00
|
|
|
unsigned Attributes = ODS.getPropertyAttributes();
|
2008-11-27 04:01:34 +08:00
|
|
|
bool isReadWrite = ((Attributes & ObjCDeclSpec::DQ_PR_readwrite) ||
|
|
|
|
// default is readwrite!
|
|
|
|
!(Attributes & ObjCDeclSpec::DQ_PR_readonly));
|
|
|
|
// property is defaulted to 'assign' if it is readwrite and is
|
|
|
|
// not retain or copy
|
|
|
|
bool isAssign = ((Attributes & ObjCDeclSpec::DQ_PR_assign) ||
|
|
|
|
(isReadWrite &&
|
|
|
|
!(Attributes & ObjCDeclSpec::DQ_PR_retain) &&
|
|
|
|
!(Attributes & ObjCDeclSpec::DQ_PR_copy)));
|
|
|
|
QualType T = GetTypeForDeclarator(FD.D, S);
|
|
|
|
Decl *ClassDecl = static_cast<Decl *>(ClassCategory);
|
2008-09-24 05:53:23 +08:00
|
|
|
|
|
|
|
// May modify Attributes.
|
|
|
|
CheckObjCPropertyAttributes(T, AtLoc, Attributes);
|
2008-11-27 04:01:34 +08:00
|
|
|
|
|
|
|
if (ObjCCategoryDecl *CDecl = dyn_cast<ObjCCategoryDecl>(ClassDecl))
|
|
|
|
if (!CDecl->getIdentifier()) {
|
|
|
|
// This is an anonymous category. property requires special
|
|
|
|
// handling.
|
|
|
|
if (ObjCInterfaceDecl *ICDecl = CDecl->getClassInterface()) {
|
|
|
|
if (ObjCPropertyDecl *PIDecl =
|
|
|
|
ICDecl->FindPropertyDeclaration(FD.D.getIdentifier())) {
|
|
|
|
// property 'PIDecl's readonly attribute will be over-ridden
|
|
|
|
// with anonymous category's readwrite property attribute!
|
|
|
|
unsigned PIkind = PIDecl->getPropertyAttributes();
|
|
|
|
if (isReadWrite && (PIkind & ObjCPropertyDecl::OBJC_PR_readonly)) {
|
2008-12-09 02:47:29 +08:00
|
|
|
if ((Attributes & ObjCPropertyDecl::OBJC_PR_nonatomic) !=
|
2008-11-27 04:01:34 +08:00
|
|
|
(PIkind & ObjCPropertyDecl::OBJC_PR_nonatomic))
|
|
|
|
Diag(AtLoc, diag::warn_property_attr_mismatch);
|
|
|
|
PIDecl->makeitReadWriteAttribute();
|
|
|
|
if (Attributes & ObjCDeclSpec::DQ_PR_retain)
|
|
|
|
PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain);
|
|
|
|
if (Attributes & ObjCDeclSpec::DQ_PR_copy)
|
|
|
|
PIDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy);
|
|
|
|
PIDecl->setSetterName(SetterSel);
|
|
|
|
// FIXME: use a common routine with addPropertyMethods.
|
|
|
|
ObjCMethodDecl *SetterDecl =
|
|
|
|
ObjCMethodDecl::Create(Context, AtLoc, AtLoc, SetterSel,
|
|
|
|
Context.VoidTy,
|
|
|
|
ICDecl,
|
|
|
|
true, false, true,
|
|
|
|
ObjCMethodDecl::Required);
|
|
|
|
ParmVarDecl *Argument = ParmVarDecl::Create(Context,
|
|
|
|
SetterDecl,
|
|
|
|
SourceLocation(),
|
|
|
|
FD.D.getIdentifier(),
|
|
|
|
T,
|
|
|
|
VarDecl::None,
|
2009-01-20 09:17:11 +08:00
|
|
|
0);
|
2008-11-27 04:01:34 +08:00
|
|
|
SetterDecl->setMethodParams(&Argument, 1);
|
|
|
|
PIDecl->setSetterMethodDecl(SetterDecl);
|
|
|
|
}
|
|
|
|
else
|
2008-12-05 06:56:16 +08:00
|
|
|
Diag(AtLoc, diag::err_use_continuation_class) << ICDecl->getDeclName();
|
2008-11-27 04:01:34 +08:00
|
|
|
*isOverridingProperty = true;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-11-27 04:33:54 +08:00
|
|
|
// No matching property found in the main class. Just fall thru
|
|
|
|
// and add property to the anonymous category. It looks like
|
2009-02-16 17:18:41 +08:00
|
|
|
// it works as is. This category becomes just like a category
|
|
|
|
// for its primary class.
|
2008-11-27 04:01:34 +08:00
|
|
|
} else {
|
|
|
|
Diag(CDecl->getLocation(), diag::err_continuation_class);
|
|
|
|
*isOverridingProperty = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2008-09-24 05:53:23 +08:00
|
|
|
|
2008-12-17 01:51:01 +08:00
|
|
|
Type *t = T.getTypePtr();
|
|
|
|
if (t->isArrayType() || t->isFunctionType())
|
|
|
|
Diag(AtLoc, diag::err_property_type) << T;
|
|
|
|
|
2009-01-11 20:47:58 +08:00
|
|
|
DeclContext *DC = dyn_cast<DeclContext>(ClassDecl);
|
|
|
|
assert(DC && "ClassDecl is not a DeclContext");
|
|
|
|
ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, DC, AtLoc,
|
2008-04-15 07:36:35 +08:00
|
|
|
FD.D.getIdentifier(), T);
|
2009-01-13 07:27:07 +08:00
|
|
|
DC->addDecl(PDecl);
|
2009-02-17 02:32:47 +08:00
|
|
|
|
|
|
|
ProcessDeclAttributes(PDecl, FD.D);
|
2009-01-09 08:49:46 +08:00
|
|
|
|
2008-05-08 01:43:59 +08:00
|
|
|
// Regardless of setter/getter attribute, we save the default getter/setter
|
|
|
|
// selector names in anticipation of declaration of setter/getter methods.
|
|
|
|
PDecl->setGetterName(GetterSel);
|
|
|
|
PDecl->setSetterName(SetterSel);
|
2008-04-12 07:40:25 +08:00
|
|
|
|
2008-09-24 05:53:23 +08:00
|
|
|
if (Attributes & ObjCDeclSpec::DQ_PR_readonly)
|
2008-01-08 03:49:32 +08:00
|
|
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readonly);
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2008-09-24 05:53:23 +08:00
|
|
|
if (Attributes & ObjCDeclSpec::DQ_PR_getter)
|
2008-01-08 03:49:32 +08:00
|
|
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_getter);
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2008-09-24 05:53:23 +08:00
|
|
|
if (Attributes & ObjCDeclSpec::DQ_PR_setter)
|
2008-01-08 03:49:32 +08:00
|
|
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_setter);
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2008-11-27 04:01:34 +08:00
|
|
|
if (isReadWrite)
|
2008-01-08 03:49:32 +08:00
|
|
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_readwrite);
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2008-09-24 05:53:23 +08:00
|
|
|
if (Attributes & ObjCDeclSpec::DQ_PR_retain)
|
2008-01-08 03:49:32 +08:00
|
|
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_retain);
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2008-09-24 05:53:23 +08:00
|
|
|
if (Attributes & ObjCDeclSpec::DQ_PR_copy)
|
2008-01-08 03:49:32 +08:00
|
|
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_copy);
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2008-11-27 04:01:34 +08:00
|
|
|
if (isAssign)
|
|
|
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_assign);
|
|
|
|
|
2008-09-24 05:53:23 +08:00
|
|
|
if (Attributes & ObjCDeclSpec::DQ_PR_nonatomic)
|
2008-01-08 03:49:32 +08:00
|
|
|
PDecl->setPropertyAttributes(ObjCPropertyDecl::OBJC_PR_nonatomic);
|
2007-12-12 15:09:47 +08:00
|
|
|
|
2008-05-06 02:51:55 +08:00
|
|
|
if (MethodImplKind == tok::objc_required)
|
|
|
|
PDecl->setPropertyImplementation(ObjCPropertyDecl::Required);
|
|
|
|
else if (MethodImplKind == tok::objc_optional)
|
|
|
|
PDecl->setPropertyImplementation(ObjCPropertyDecl::Optional);
|
|
|
|
|
2007-12-12 15:09:47 +08:00
|
|
|
return PDecl;
|
|
|
|
}
|
|
|
|
|
2008-04-22 03:04:53 +08:00
|
|
|
/// ActOnPropertyImplDecl - This routine performs semantic checks and
|
|
|
|
/// builds the AST node for a property implementation declaration; declared
|
|
|
|
/// as @synthesize or @dynamic.
|
2008-04-18 08:19:30 +08:00
|
|
|
///
|
|
|
|
Sema::DeclTy *Sema::ActOnPropertyImplDecl(SourceLocation AtLoc,
|
|
|
|
SourceLocation PropertyLoc,
|
|
|
|
bool Synthesize,
|
|
|
|
DeclTy *ClassCatImpDecl,
|
|
|
|
IdentifierInfo *PropertyId,
|
|
|
|
IdentifierInfo *PropertyIvar) {
|
|
|
|
Decl *ClassImpDecl = static_cast<Decl*>(ClassCatImpDecl);
|
|
|
|
// Make sure we have a context for the property implementation declaration.
|
|
|
|
if (!ClassImpDecl) {
|
|
|
|
Diag(AtLoc, diag::error_missing_property_context);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
ObjCPropertyDecl *property = 0;
|
|
|
|
ObjCInterfaceDecl* IDecl = 0;
|
|
|
|
// Find the class or category class where this property must have
|
|
|
|
// a declaration.
|
2008-04-23 08:06:01 +08:00
|
|
|
ObjCImplementationDecl *IC = 0;
|
|
|
|
ObjCCategoryImplDecl* CatImplClass = 0;
|
|
|
|
if ((IC = dyn_cast<ObjCImplementationDecl>(ClassImpDecl))) {
|
2009-01-20 09:17:11 +08:00
|
|
|
IDecl = IC->getClassInterface();
|
2008-04-22 05:05:54 +08:00
|
|
|
// We always synthesize an interface for an implementation
|
|
|
|
// without an interface decl. So, IDecl is always non-zero.
|
|
|
|
assert(IDecl &&
|
|
|
|
"ActOnPropertyImplDecl - @implementation without @interface");
|
|
|
|
|
2008-04-18 08:19:30 +08:00
|
|
|
// Look for this property declaration in the @implementation's @interface
|
2008-04-22 03:04:53 +08:00
|
|
|
property = IDecl->FindPropertyDeclaration(PropertyId);
|
|
|
|
if (!property) {
|
2008-11-24 13:29:24 +08:00
|
|
|
Diag(PropertyLoc, diag::error_bad_property_decl) << IDecl->getDeclName();
|
2008-04-18 08:19:30 +08:00
|
|
|
return 0;
|
2008-04-22 03:04:53 +08:00
|
|
|
}
|
2008-04-18 08:19:30 +08:00
|
|
|
}
|
2008-04-23 08:06:01 +08:00
|
|
|
else if ((CatImplClass = dyn_cast<ObjCCategoryImplDecl>(ClassImpDecl))) {
|
2008-04-22 05:05:54 +08:00
|
|
|
if (Synthesize) {
|
|
|
|
Diag(AtLoc, diag::error_synthesize_category_decl);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-04-18 08:19:30 +08:00
|
|
|
IDecl = CatImplClass->getClassInterface();
|
|
|
|
if (!IDecl) {
|
|
|
|
Diag(AtLoc, diag::error_missing_property_interface);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-04-22 03:04:53 +08:00
|
|
|
ObjCCategoryDecl *Category =
|
|
|
|
IDecl->FindCategoryDeclaration(CatImplClass->getIdentifier());
|
|
|
|
|
2008-04-18 08:19:30 +08:00
|
|
|
// If category for this implementation not found, it is an error which
|
|
|
|
// has already been reported eralier.
|
2008-04-22 03:04:53 +08:00
|
|
|
if (!Category)
|
2008-04-18 08:19:30 +08:00
|
|
|
return 0;
|
|
|
|
// Look for this property declaration in @implementation's category
|
2008-04-22 03:04:53 +08:00
|
|
|
property = Category->FindPropertyDeclaration(PropertyId);
|
|
|
|
if (!property) {
|
2008-11-20 14:13:02 +08:00
|
|
|
Diag(PropertyLoc, diag::error_bad_category_property_decl)
|
2008-11-24 13:29:24 +08:00
|
|
|
<< Category->getDeclName();
|
2008-04-18 08:19:30 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Diag(AtLoc, diag::error_bad_property_context);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-04-23 08:06:01 +08:00
|
|
|
ObjCIvarDecl *Ivar = 0;
|
2008-04-18 08:19:30 +08:00
|
|
|
// Check that we have a valid, previously declared ivar for @synthesize
|
|
|
|
if (Synthesize) {
|
|
|
|
// @synthesize
|
2008-04-22 05:57:36 +08:00
|
|
|
if (!PropertyIvar)
|
|
|
|
PropertyIvar = PropertyId;
|
2008-04-18 08:19:30 +08:00
|
|
|
// Check that this is a previously declared 'ivar' in 'IDecl' interface
|
2009-02-17 03:35:27 +08:00
|
|
|
Ivar = IDecl->lookupInstanceVariable(PropertyIvar);
|
2008-04-22 05:05:54 +08:00
|
|
|
if (!Ivar) {
|
2008-11-19 16:23:25 +08:00
|
|
|
Diag(PropertyLoc, diag::error_missing_property_ivar_decl) << PropertyId;
|
2008-04-18 08:19:30 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2008-09-30 18:07:56 +08:00
|
|
|
QualType PropType = Context.getCanonicalType(property->getType());
|
|
|
|
QualType IvarType = Context.getCanonicalType(Ivar->getType());
|
|
|
|
|
2008-09-30 08:24:17 +08:00
|
|
|
// Check that type of property and its ivar are type compatible.
|
2008-09-30 18:07:56 +08:00
|
|
|
if (PropType != IvarType) {
|
2008-10-16 22:59:30 +08:00
|
|
|
if (CheckAssignmentConstraints(PropType, IvarType) != Compatible) {
|
2008-11-20 14:13:02 +08:00
|
|
|
Diag(PropertyLoc, diag::error_property_ivar_type)
|
2008-11-24 13:29:24 +08:00
|
|
|
<< property->getDeclName() << Ivar->getDeclName();
|
2008-09-30 18:07:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2009-01-20 04:13:47 +08:00
|
|
|
else {
|
|
|
|
// FIXME! Rules for properties are somewhat different that those
|
|
|
|
// for assignments. Use a new routine to consolidate all cases;
|
|
|
|
// specifically for property redeclarations as well as for ivars.
|
|
|
|
QualType lhsType =
|
|
|
|
Context.getCanonicalType(PropType).getUnqualifiedType();
|
|
|
|
QualType rhsType =
|
|
|
|
Context.getCanonicalType(IvarType).getUnqualifiedType();
|
|
|
|
if (lhsType != rhsType &&
|
|
|
|
lhsType->isArithmeticType()) {
|
|
|
|
Diag(PropertyLoc, diag::error_property_ivar_type)
|
|
|
|
<< property->getDeclName() << Ivar->getDeclName();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2008-04-22 05:05:54 +08:00
|
|
|
}
|
2008-04-18 08:19:30 +08:00
|
|
|
} else if (PropertyIvar) {
|
|
|
|
// @dynamic
|
|
|
|
Diag(PropertyLoc, diag::error_dynamic_property_ivar_decl);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
assert (property && "ActOnPropertyImplDecl - property declaration missing");
|
2008-04-23 08:06:01 +08:00
|
|
|
ObjCPropertyImplDecl *PIDecl =
|
2009-01-09 08:49:46 +08:00
|
|
|
ObjCPropertyImplDecl::Create(Context, CurContext, AtLoc, PropertyLoc,
|
|
|
|
property,
|
2008-04-23 08:06:01 +08:00
|
|
|
(Synthesize ?
|
2008-08-26 12:47:31 +08:00
|
|
|
ObjCPropertyImplDecl::Synthesize
|
|
|
|
: ObjCPropertyImplDecl::Dynamic),
|
|
|
|
Ivar);
|
2009-01-13 07:27:07 +08:00
|
|
|
CurContext->addDecl(PIDecl);
|
2008-12-06 06:32:48 +08:00
|
|
|
if (IC) {
|
|
|
|
if (Synthesize)
|
|
|
|
if (ObjCPropertyImplDecl *PPIDecl =
|
|
|
|
IC->FindPropertyImplIvarDecl(PropertyIvar)) {
|
|
|
|
Diag(PropertyLoc, diag::error_duplicate_ivar_use)
|
|
|
|
<< PropertyId << PPIDecl->getPropertyDecl()->getIdentifier()
|
|
|
|
<< PropertyIvar;
|
|
|
|
Diag(PPIDecl->getLocation(), diag::note_previous_use);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjCPropertyImplDecl *PPIDecl = IC->FindPropertyImplDecl(PropertyId)) {
|
|
|
|
Diag(PropertyLoc, diag::error_property_implemented) << PropertyId;
|
|
|
|
Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-04-23 08:06:01 +08:00
|
|
|
IC->addPropertyImplementation(PIDecl);
|
2008-12-06 06:32:48 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (Synthesize)
|
|
|
|
if (ObjCPropertyImplDecl *PPIDecl =
|
|
|
|
CatImplClass->FindPropertyImplIvarDecl(PropertyIvar)) {
|
|
|
|
Diag(PropertyLoc, diag::error_duplicate_ivar_use)
|
|
|
|
<< PropertyId << PPIDecl->getPropertyDecl()->getIdentifier()
|
|
|
|
<< PropertyIvar;
|
|
|
|
Diag(PPIDecl->getLocation(), diag::note_previous_use);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ObjCPropertyImplDecl *PPIDecl =
|
|
|
|
CatImplClass->FindPropertyImplDecl(PropertyId)) {
|
|
|
|
Diag(PropertyLoc, diag::error_property_implemented) << PropertyId;
|
|
|
|
Diag(PPIDecl->getLocation(), diag::note_previous_declaration);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-04-23 08:06:01 +08:00
|
|
|
CatImplClass->addPropertyImplementation(PIDecl);
|
2008-12-06 06:32:48 +08:00
|
|
|
}
|
2008-04-23 08:06:01 +08:00
|
|
|
|
|
|
|
return PIDecl;
|
2008-04-18 08:19:30 +08:00
|
|
|
}
|
2008-11-05 00:57:32 +08:00
|
|
|
|
2008-12-17 15:13:27 +08:00
|
|
|
bool Sema::CheckObjCDeclScope(Decl *D) {
|
2009-01-07 07:51:29 +08:00
|
|
|
if (isa<TranslationUnitDecl>(CurContext->getLookupContext()))
|
2008-11-05 00:57:32 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
Diag(D->getLocation(), diag::err_objc_decls_may_only_appear_in_global_scope);
|
|
|
|
D->setInvalidDecl();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2008-12-17 15:13:27 +08:00
|
|
|
|
|
|
|
/// Collect the instance variables declared in an Objective-C object. Used in
|
|
|
|
/// the creation of structures from objects using the @defs directive.
|
|
|
|
/// FIXME: This should be consolidated with CollectObjCIvars as it is also
|
|
|
|
/// part of the AST generation logic of @defs.
|
|
|
|
static void CollectIvars(ObjCInterfaceDecl *Class, RecordDecl *Record,
|
|
|
|
ASTContext& Ctx,
|
|
|
|
llvm::SmallVectorImpl<Sema::DeclTy*> &ivars) {
|
|
|
|
if (Class->getSuperClass())
|
|
|
|
CollectIvars(Class->getSuperClass(), Record, Ctx, ivars);
|
|
|
|
|
|
|
|
// For each ivar, create a fresh ObjCAtDefsFieldDecl.
|
|
|
|
for (ObjCInterfaceDecl::ivar_iterator
|
|
|
|
I=Class->ivar_begin(), E=Class->ivar_end(); I!=E; ++I) {
|
|
|
|
|
|
|
|
ObjCIvarDecl* ID = *I;
|
|
|
|
ivars.push_back(ObjCAtDefsFieldDecl::Create(Ctx, Record,
|
|
|
|
ID->getLocation(),
|
|
|
|
ID->getIdentifier(),
|
|
|
|
ID->getType(),
|
|
|
|
ID->getBitWidth()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Called whenever @defs(ClassName) is encountered in the source. Inserts the
|
|
|
|
/// instance variables of ClassName into Decls.
|
|
|
|
void Sema::ActOnDefs(Scope *S, DeclTy *TagD, SourceLocation DeclStart,
|
|
|
|
IdentifierInfo *ClassName,
|
|
|
|
llvm::SmallVectorImpl<DeclTy*> &Decls) {
|
|
|
|
// Check that ClassName is a valid class
|
|
|
|
ObjCInterfaceDecl *Class = getObjCInterfaceDecl(ClassName);
|
|
|
|
if (!Class) {
|
|
|
|
Diag(DeclStart, diag::err_undef_interface) << ClassName;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Collect the instance variables
|
|
|
|
CollectIvars(Class, dyn_cast<RecordDecl>((Decl*)TagD), Context, Decls);
|
|
|
|
|
|
|
|
// Introduce all of these fields into the appropriate scope.
|
|
|
|
for (llvm::SmallVectorImpl<DeclTy*>::iterator D = Decls.begin();
|
|
|
|
D != Decls.end(); ++D) {
|
|
|
|
FieldDecl *FD = cast<FieldDecl>((Decl*)*D);
|
|
|
|
if (getLangOptions().CPlusPlus)
|
|
|
|
PushOnScopeChains(cast<FieldDecl>(FD), S);
|
|
|
|
else if (RecordDecl *Record = dyn_cast<RecordDecl>((Decl*)TagD))
|
2009-01-13 07:27:07 +08:00
|
|
|
Record->addDecl(FD);
|
2008-12-17 15:13:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|