2008-03-16 03:19:01 +03:00
|
|
|
//===--- DeclObjC.cpp - ObjC Declaration AST Node Implementation ----------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the Objective-C related Decl classes.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/DeclObjC.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
2008-08-11 08:54:23 +04:00
|
|
|
#include "clang/AST/Stmt.h"
|
2009-02-22 22:35:57 +03:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2008-03-16 03:19:01 +03:00
|
|
|
using namespace clang;
|
|
|
|
|
2009-02-21 00:16:26 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCListBase
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-02-21 00:35:13 +03:00
|
|
|
void ObjCListBase::Destroy(ASTContext &Ctx) {
|
2009-02-21 00:44:01 +03:00
|
|
|
Ctx.Deallocate(List);
|
2009-02-21 00:16:26 +03:00
|
|
|
NumElts = 0;
|
|
|
|
List = 0;
|
|
|
|
}
|
|
|
|
|
2009-02-21 00:35:13 +03:00
|
|
|
void ObjCListBase::set(void *const* InList, unsigned Elts, ASTContext &Ctx) {
|
2009-02-21 00:16:26 +03:00
|
|
|
assert(List == 0 && "Elements already set!");
|
|
|
|
if (Elts == 0) return; // Setting to an empty list is a noop.
|
2009-09-09 19:08:12 +04:00
|
|
|
|
|
|
|
|
2009-02-21 00:44:01 +03:00
|
|
|
List = new (Ctx) void*[Elts];
|
2009-02-21 00:16:26 +03:00
|
|
|
NumElts = Elts;
|
|
|
|
memcpy(List, InList, sizeof(void*)*Elts);
|
|
|
|
}
|
|
|
|
|
2010-01-16 18:02:53 +03:00
|
|
|
void ObjCProtocolList::set(ObjCProtocolDecl* const* InList, unsigned Elts,
|
|
|
|
const SourceLocation *Locs, ASTContext &Ctx) {
|
|
|
|
if (Elts == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Locations = new (Ctx) SourceLocation[Elts];
|
|
|
|
memcpy(Locations, Locs, sizeof(SourceLocation) * Elts);
|
|
|
|
set(InList, Elts, Ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjCProtocolList::Destroy(ASTContext &Ctx) {
|
|
|
|
Ctx.Deallocate(Locations);
|
|
|
|
Locations = 0;
|
|
|
|
ObjCList<ObjCProtocolDecl>::Destroy(Ctx);
|
|
|
|
}
|
2009-02-21 00:16:26 +03:00
|
|
|
|
2008-03-16 03:49:28 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
2009-02-20 23:59:54 +03:00
|
|
|
// ObjCInterfaceDecl
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-06-05 22:16:35 +04:00
|
|
|
/// getIvarDecl - This method looks up an ivar in this ContextDecl.
|
|
|
|
///
|
|
|
|
ObjCIvarDecl *
|
2009-06-30 06:36:12 +04:00
|
|
|
ObjCContainerDecl::getIvarDecl(IdentifierInfo *Id) const {
|
2009-06-05 22:16:35 +04:00
|
|
|
lookup_const_iterator Ivar, IvarEnd;
|
2009-06-30 06:36:12 +04:00
|
|
|
for (llvm::tie(Ivar, IvarEnd) = lookup(Id); Ivar != IvarEnd; ++Ivar) {
|
2009-06-05 22:16:35 +04:00
|
|
|
if (ObjCIvarDecl *ivar = dyn_cast<ObjCIvarDecl>(*Ivar))
|
|
|
|
return ivar;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-26 02:15:22 +04:00
|
|
|
// Get the local instance/class method declared in this interface.
|
2009-04-10 01:40:53 +04:00
|
|
|
ObjCMethodDecl *
|
2009-07-26 02:15:22 +04:00
|
|
|
ObjCContainerDecl::getMethod(Selector Sel, bool isInstance) const {
|
2009-02-22 22:35:57 +03:00
|
|
|
// Since instance & class methods can have the same name, the loop below
|
|
|
|
// ensures we get the correct method.
|
|
|
|
//
|
|
|
|
// @interface Whatever
|
|
|
|
// - (int) class_method;
|
|
|
|
// + (float) class_method;
|
|
|
|
// @end
|
|
|
|
//
|
|
|
|
lookup_const_iterator Meth, MethEnd;
|
2009-06-30 06:36:12 +04:00
|
|
|
for (llvm::tie(Meth, MethEnd) = lookup(Sel); Meth != MethEnd; ++Meth) {
|
2009-02-22 22:35:57 +03:00
|
|
|
ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(*Meth);
|
2009-07-26 02:15:22 +04:00
|
|
|
if (MD && MD->isInstanceMethod() == isInstance)
|
2009-02-22 22:35:57 +03:00
|
|
|
return MD;
|
|
|
|
}
|
2009-02-20 23:59:54 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-15 23:11:46 +03:00
|
|
|
ObjCPropertyDecl *
|
2010-03-15 23:11:53 +03:00
|
|
|
ObjCPropertyDecl::findPropertyDecl(const DeclContext *DC,
|
2010-03-15 23:11:46 +03:00
|
|
|
IdentifierInfo *propertyID) {
|
|
|
|
|
2010-03-15 23:11:53 +03:00
|
|
|
DeclContext::lookup_const_iterator I, E;
|
2010-03-15 23:11:46 +03:00
|
|
|
llvm::tie(I, E) = DC->lookup(propertyID);
|
|
|
|
for ( ; I != E; ++I)
|
|
|
|
if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(*I))
|
|
|
|
return PD;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
/// FindPropertyDeclaration - Finds declaration of the property given its name
|
|
|
|
/// in 'PropertyId' and returns it. It returns 0, if not found.
|
|
|
|
ObjCPropertyDecl *
|
2009-06-30 06:36:12 +04:00
|
|
|
ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2010-03-15 23:11:53 +03:00
|
|
|
if (ObjCPropertyDecl *PD =
|
|
|
|
ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
|
|
|
|
return PD;
|
|
|
|
|
|
|
|
switch (getKind()) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case Decl::ObjCProtocol: {
|
|
|
|
const ObjCProtocolDecl *PID = cast<ObjCProtocolDecl>(this);
|
|
|
|
for (ObjCProtocolDecl::protocol_iterator I = PID->protocol_begin(),
|
|
|
|
E = PID->protocol_end(); I != E; ++I)
|
|
|
|
if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
|
2010-02-16 00:55:26 +03:00
|
|
|
return P;
|
2010-03-15 23:11:53 +03:00
|
|
|
break;
|
2009-02-20 23:59:54 +03:00
|
|
|
}
|
2010-03-15 23:11:53 +03:00
|
|
|
case Decl::ObjCInterface: {
|
|
|
|
const ObjCInterfaceDecl *OID = cast<ObjCInterfaceDecl>(this);
|
|
|
|
// Look through categories.
|
|
|
|
for (ObjCCategoryDecl *Cat = OID->getCategoryList();
|
|
|
|
Cat; Cat = Cat->getNextClassCategory())
|
|
|
|
if (!Cat->IsClassExtension())
|
|
|
|
if (ObjCPropertyDecl *P = Cat->FindPropertyDeclaration(PropertyId))
|
|
|
|
return P;
|
|
|
|
|
|
|
|
// Look through protocols.
|
|
|
|
for (ObjCInterfaceDecl::protocol_iterator
|
|
|
|
I = OID->protocol_begin(), E = OID->protocol_end(); I != E; ++I)
|
|
|
|
if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
|
|
|
|
return P;
|
|
|
|
|
|
|
|
// Finally, check the super class.
|
|
|
|
if (const ObjCInterfaceDecl *superClass = OID->getSuperClass())
|
|
|
|
return superClass->FindPropertyDeclaration(PropertyId);
|
|
|
|
break;
|
2009-02-20 23:59:54 +03:00
|
|
|
}
|
2010-03-15 23:11:53 +03:00
|
|
|
case Decl::ObjCCategory: {
|
|
|
|
const ObjCCategoryDecl *OCD = cast<ObjCCategoryDecl>(this);
|
|
|
|
// Look through protocols.
|
|
|
|
if (!OCD->IsClassExtension())
|
|
|
|
for (ObjCCategoryDecl::protocol_iterator
|
|
|
|
I = OCD->protocol_begin(), E = OCD->protocol_end(); I != E; ++I)
|
2010-02-16 00:55:26 +03:00
|
|
|
if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
|
|
|
|
return P;
|
2010-03-15 23:11:53 +03:00
|
|
|
|
|
|
|
break;
|
2009-02-20 23:59:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-03 01:45:15 +03:00
|
|
|
/// FindPropertyVisibleInPrimaryClass - Finds declaration of the property
|
|
|
|
/// with name 'PropertyId' in the primary class; including those in protocols
|
2010-03-15 23:30:07 +03:00
|
|
|
/// (direct or indirect) used by the primary class.
|
2009-11-03 01:45:15 +03:00
|
|
|
///
|
|
|
|
ObjCPropertyDecl *
|
2010-03-15 23:30:07 +03:00
|
|
|
ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass(
|
2009-11-03 01:45:15 +03:00
|
|
|
IdentifierInfo *PropertyId) const {
|
2010-03-15 23:30:07 +03:00
|
|
|
if (ObjCPropertyDecl *PD =
|
|
|
|
ObjCPropertyDecl::findPropertyDecl(cast<DeclContext>(this), PropertyId))
|
|
|
|
return PD;
|
|
|
|
|
2009-11-03 01:45:15 +03:00
|
|
|
// Look through protocols.
|
2010-03-15 23:30:07 +03:00
|
|
|
for (ObjCInterfaceDecl::protocol_iterator
|
|
|
|
I = protocol_begin(), E = protocol_end(); I != E; ++I)
|
2009-11-03 01:45:15 +03:00
|
|
|
if (ObjCPropertyDecl *P = (*I)->FindPropertyDeclaration(PropertyId))
|
|
|
|
return P;
|
2010-03-15 23:30:07 +03:00
|
|
|
|
2009-11-03 01:45:15 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-06 00:41:32 +04:00
|
|
|
void ObjCInterfaceDecl::mergeClassExtensionProtocolList(
|
|
|
|
ObjCProtocolDecl *const* ExtList, unsigned ExtNum,
|
2010-01-16 18:02:53 +03:00
|
|
|
const SourceLocation *Locs,
|
2009-10-06 00:41:32 +04:00
|
|
|
ASTContext &C)
|
|
|
|
{
|
|
|
|
if (ReferencedProtocols.empty()) {
|
2010-01-16 18:02:53 +03:00
|
|
|
ReferencedProtocols.set(ExtList, ExtNum, Locs, C);
|
2009-10-06 00:41:32 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Check for duplicate protocol in class's protocol list.
|
|
|
|
// This is (O)2. But it is extremely rare and number of protocols in
|
|
|
|
// class or its extension are very few.
|
|
|
|
llvm::SmallVector<ObjCProtocolDecl*, 8> ProtocolRefs;
|
2010-01-16 18:02:53 +03:00
|
|
|
llvm::SmallVector<SourceLocation, 8> ProtocolLocs;
|
2009-10-06 00:41:32 +04:00
|
|
|
for (unsigned i = 0; i < ExtNum; i++) {
|
|
|
|
bool protocolExists = false;
|
|
|
|
ObjCProtocolDecl *ProtoInExtension = ExtList[i];
|
|
|
|
for (protocol_iterator p = protocol_begin(), e = protocol_end();
|
|
|
|
p != e; p++) {
|
|
|
|
ObjCProtocolDecl *Proto = (*p);
|
|
|
|
if (C.ProtocolCompatibleWithProtocol(ProtoInExtension, Proto)) {
|
|
|
|
protocolExists = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Do we want to warn on a protocol in extension class which
|
|
|
|
// already exist in the class? Probably not.
|
2010-01-16 18:02:53 +03:00
|
|
|
if (!protocolExists) {
|
2009-10-06 00:41:32 +04:00
|
|
|
ProtocolRefs.push_back(ProtoInExtension);
|
2010-01-16 18:02:53 +03:00
|
|
|
ProtocolLocs.push_back(Locs[i]);
|
|
|
|
}
|
2009-10-06 00:41:32 +04:00
|
|
|
}
|
|
|
|
if (ProtocolRefs.empty())
|
|
|
|
return;
|
2009-10-06 01:32:49 +04:00
|
|
|
// Merge ProtocolRefs into class's protocol list;
|
2010-01-16 18:02:53 +03:00
|
|
|
protocol_loc_iterator pl = protocol_loc_begin();
|
2009-10-06 00:41:32 +04:00
|
|
|
for (protocol_iterator p = protocol_begin(), e = protocol_end();
|
2010-01-16 18:02:53 +03:00
|
|
|
p != e; ++p, ++pl) {
|
2009-10-06 00:41:32 +04:00
|
|
|
ProtocolRefs.push_back(*p);
|
2010-01-16 18:02:53 +03:00
|
|
|
ProtocolLocs.push_back(*pl);
|
|
|
|
}
|
2009-10-06 00:41:32 +04:00
|
|
|
ReferencedProtocols.Destroy(C);
|
|
|
|
unsigned NumProtoRefs = ProtocolRefs.size();
|
2010-01-16 18:02:53 +03:00
|
|
|
setProtocolList(ProtocolRefs.data(), NumProtoRefs, ProtocolLocs.data(), C);
|
2009-10-06 00:41:32 +04:00
|
|
|
}
|
|
|
|
|
2010-02-23 04:26:30 +03:00
|
|
|
/// getClassExtension - Find class extension of the given class.
|
|
|
|
// FIXME. can speed it up, if need be.
|
|
|
|
ObjCCategoryDecl* ObjCInterfaceDecl::getClassExtension() const {
|
|
|
|
const ObjCInterfaceDecl* ClassDecl = this;
|
|
|
|
for (ObjCCategoryDecl *CDecl = ClassDecl->getCategoryList(); CDecl;
|
|
|
|
CDecl = CDecl->getNextClassCategory())
|
|
|
|
if (CDecl->IsClassExtension())
|
|
|
|
return CDecl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-30 06:36:12 +04:00
|
|
|
ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(IdentifierInfo *ID,
|
|
|
|
ObjCInterfaceDecl *&clsDeclared) {
|
2009-02-20 23:59:54 +03:00
|
|
|
ObjCInterfaceDecl* ClassDecl = this;
|
|
|
|
while (ClassDecl != NULL) {
|
2009-06-30 06:36:12 +04:00
|
|
|
if (ObjCIvarDecl *I = ClassDecl->getIvarDecl(ID)) {
|
2009-06-05 22:16:35 +04:00
|
|
|
clsDeclared = ClassDecl;
|
|
|
|
return I;
|
2009-02-20 23:59:54 +03:00
|
|
|
}
|
2010-02-23 04:26:30 +03:00
|
|
|
if (const ObjCCategoryDecl *CDecl = ClassDecl->getClassExtension())
|
|
|
|
if (ObjCIvarDecl *I = CDecl->getIvarDecl(ID)) {
|
|
|
|
clsDeclared = ClassDecl;
|
|
|
|
return I;
|
|
|
|
}
|
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
ClassDecl = ClassDecl->getSuperClass();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-22 21:12:32 +04:00
|
|
|
/// lookupInheritedClass - This method returns ObjCInterfaceDecl * of the super
|
|
|
|
/// class whose name is passed as argument. If it is not one of the super classes
|
|
|
|
/// the it returns NULL.
|
|
|
|
ObjCInterfaceDecl *ObjCInterfaceDecl::lookupInheritedClass(
|
|
|
|
const IdentifierInfo*ICName) {
|
|
|
|
ObjCInterfaceDecl* ClassDecl = this;
|
|
|
|
while (ClassDecl != NULL) {
|
|
|
|
if (ClassDecl->getIdentifier() == ICName)
|
|
|
|
return ClassDecl;
|
|
|
|
ClassDecl = ClassDecl->getSuperClass();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-07-26 02:15:51 +04:00
|
|
|
/// lookupMethod - This method returns an instance/class method by looking in
|
2009-02-20 23:59:54 +03:00
|
|
|
/// the class, its categories, and its super classes (using a linear search).
|
2009-07-26 02:15:51 +04:00
|
|
|
ObjCMethodDecl *ObjCInterfaceDecl::lookupMethod(Selector Sel,
|
|
|
|
bool isInstance) const {
|
|
|
|
const ObjCInterfaceDecl* ClassDecl = this;
|
2009-02-20 23:59:54 +03:00
|
|
|
ObjCMethodDecl *MethodDecl = 0;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
while (ClassDecl != NULL) {
|
2009-07-26 02:15:51 +04:00
|
|
|
if ((MethodDecl = ClassDecl->getMethod(Sel, isInstance)))
|
2009-02-20 23:59:54 +03:00
|
|
|
return MethodDecl;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
// Didn't find one yet - look through protocols.
|
|
|
|
const ObjCList<ObjCProtocolDecl> &Protocols =
|
|
|
|
ClassDecl->getReferencedProtocols();
|
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
|
|
|
|
E = Protocols.end(); I != E; ++I)
|
2009-07-26 02:15:51 +04:00
|
|
|
if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
|
2009-02-20 23:59:54 +03:00
|
|
|
return MethodDecl;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
// Didn't find one yet - now look through categories.
|
|
|
|
ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
|
|
|
|
while (CatDecl) {
|
2009-07-26 02:15:51 +04:00
|
|
|
if ((MethodDecl = CatDecl->getMethod(Sel, isInstance)))
|
2009-02-20 23:59:54 +03:00
|
|
|
return MethodDecl;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-26 14:32:02 +03:00
|
|
|
// Didn't find one yet - look through protocols.
|
|
|
|
const ObjCList<ObjCProtocolDecl> &Protocols =
|
|
|
|
CatDecl->getReferencedProtocols();
|
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
|
|
|
|
E = Protocols.end(); I != E; ++I)
|
2009-07-26 02:15:51 +04:00
|
|
|
if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
|
2009-02-26 14:32:02 +03:00
|
|
|
return MethodDecl;
|
2009-02-20 23:59:54 +03:00
|
|
|
CatDecl = CatDecl->getNextClassCategory();
|
|
|
|
}
|
|
|
|
ClassDecl = ClassDecl->getSuperClass();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-02 03:46:04 +04:00
|
|
|
ObjCMethodDecl *ObjCInterfaceDecl::lookupPrivateInstanceMethod(
|
|
|
|
const Selector &Sel) {
|
|
|
|
ObjCMethodDecl *Method = 0;
|
|
|
|
if (ObjCImplementationDecl *ImpDecl = getImplementation())
|
|
|
|
Method = ImpDecl->getInstanceMethod(Sel);
|
|
|
|
|
|
|
|
if (!Method && getSuperClass())
|
|
|
|
return getSuperClass()->lookupPrivateInstanceMethod(Sel);
|
|
|
|
return Method;
|
|
|
|
}
|
2009-02-20 23:59:54 +03:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCMethodDecl
|
2008-03-16 03:49:28 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-04-04 10:12:32 +04:00
|
|
|
ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
|
2009-09-09 19:08:12 +04:00
|
|
|
SourceLocation beginLoc,
|
2008-03-16 03:49:28 +03:00
|
|
|
SourceLocation endLoc,
|
|
|
|
Selector SelInfo, QualType T,
|
2010-03-08 17:59:44 +03:00
|
|
|
TypeSourceInfo *ResultTInfo,
|
2009-01-08 20:28:14 +03:00
|
|
|
DeclContext *contextDecl,
|
2008-08-20 22:02:42 +04:00
|
|
|
bool isInstance,
|
2008-03-16 03:49:28 +03:00
|
|
|
bool isVariadic,
|
2008-05-08 00:53:44 +04:00
|
|
|
bool isSynthesized,
|
2008-03-16 03:58:16 +03:00
|
|
|
ImplementationControl impControl) {
|
2009-01-28 00:25:57 +03:00
|
|
|
return new (C) ObjCMethodDecl(beginLoc, endLoc,
|
2010-03-08 17:59:44 +03:00
|
|
|
SelInfo, T, ResultTInfo, contextDecl,
|
|
|
|
isInstance,
|
|
|
|
isVariadic, isSynthesized, impControl);
|
2008-03-16 04:15:50 +03:00
|
|
|
}
|
|
|
|
|
2009-02-21 00:35:13 +03:00
|
|
|
void ObjCMethodDecl::Destroy(ASTContext &C) {
|
2008-06-06 20:45:15 +04:00
|
|
|
if (Body) Body->Destroy(C);
|
|
|
|
if (SelfDecl) SelfDecl->Destroy(C);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-06-06 20:45:15 +04:00
|
|
|
for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
|
|
|
|
if (*I) (*I)->Destroy(C);
|
2009-02-20 08:54:35 +03:00
|
|
|
|
2009-02-21 00:35:13 +03:00
|
|
|
ParamInfo.Destroy(C);
|
2009-02-20 08:54:35 +03:00
|
|
|
|
2008-06-06 20:45:15 +04:00
|
|
|
Decl::Destroy(C);
|
|
|
|
}
|
|
|
|
|
2009-07-21 04:06:36 +04:00
|
|
|
/// \brief A definition will return its interface declaration.
|
|
|
|
/// An interface declaration will return its definition.
|
|
|
|
/// Otherwise it will return itself.
|
|
|
|
ObjCMethodDecl *ObjCMethodDecl::getNextRedeclaration() {
|
|
|
|
ASTContext &Ctx = getASTContext();
|
|
|
|
ObjCMethodDecl *Redecl = 0;
|
|
|
|
Decl *CtxD = cast<Decl>(getDeclContext());
|
|
|
|
|
|
|
|
if (ObjCInterfaceDecl *IFD = dyn_cast<ObjCInterfaceDecl>(CtxD)) {
|
|
|
|
if (ObjCImplementationDecl *ImplD = Ctx.getObjCImplementation(IFD))
|
|
|
|
Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
|
|
|
|
|
|
|
|
} else if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(CtxD)) {
|
|
|
|
if (ObjCCategoryImplDecl *ImplD = Ctx.getObjCImplementation(CD))
|
|
|
|
Redecl = ImplD->getMethod(getSelector(), isInstanceMethod());
|
|
|
|
|
2009-07-28 09:11:05 +04:00
|
|
|
} else if (ObjCImplementationDecl *ImplD =
|
|
|
|
dyn_cast<ObjCImplementationDecl>(CtxD)) {
|
2009-07-21 04:06:36 +04:00
|
|
|
if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
|
|
|
|
Redecl = IFD->getMethod(getSelector(), isInstanceMethod());
|
2009-07-28 09:11:05 +04:00
|
|
|
|
|
|
|
} else if (ObjCCategoryImplDecl *CImplD =
|
|
|
|
dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
|
2009-10-30 00:11:04 +03:00
|
|
|
if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
|
2009-07-28 09:11:05 +04:00
|
|
|
Redecl = CatD->getMethod(getSelector(), isInstanceMethod());
|
2009-07-21 04:06:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return Redecl ? Redecl : this;
|
|
|
|
}
|
|
|
|
|
2009-07-28 09:11:17 +04:00
|
|
|
ObjCMethodDecl *ObjCMethodDecl::getCanonicalDecl() {
|
|
|
|
Decl *CtxD = cast<Decl>(getDeclContext());
|
|
|
|
|
|
|
|
if (ObjCImplementationDecl *ImplD = dyn_cast<ObjCImplementationDecl>(CtxD)) {
|
|
|
|
if (ObjCInterfaceDecl *IFD = ImplD->getClassInterface())
|
|
|
|
if (ObjCMethodDecl *MD = IFD->getMethod(getSelector(),
|
|
|
|
isInstanceMethod()))
|
|
|
|
return MD;
|
|
|
|
|
|
|
|
} else if (ObjCCategoryImplDecl *CImplD =
|
|
|
|
dyn_cast<ObjCCategoryImplDecl>(CtxD)) {
|
2009-10-30 00:11:04 +03:00
|
|
|
if (ObjCCategoryDecl *CatD = CImplD->getCategoryDecl())
|
2009-07-28 09:11:17 +04:00
|
|
|
if (ObjCMethodDecl *MD = CatD->getMethod(getSelector(),
|
|
|
|
isInstanceMethod()))
|
|
|
|
return MD;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
|
2009-02-20 23:59:54 +03:00
|
|
|
const ObjCInterfaceDecl *OID) {
|
|
|
|
QualType selfTy;
|
|
|
|
if (isInstanceMethod()) {
|
|
|
|
// There may be no interface context due to error in declaration
|
|
|
|
// of the interface (which has been reported). Recover gracefully.
|
|
|
|
if (OID) {
|
2009-04-22 08:34:53 +04:00
|
|
|
selfTy = Context.getObjCInterfaceType(OID);
|
2009-07-11 03:34:53 +04:00
|
|
|
selfTy = Context.getObjCObjectPointerType(selfTy);
|
2009-02-20 23:59:54 +03:00
|
|
|
} else {
|
|
|
|
selfTy = Context.getObjCIdType();
|
|
|
|
}
|
|
|
|
} else // we have a factory method.
|
|
|
|
selfTy = Context.getObjCClassType();
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
setSelfDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
|
2009-04-20 19:06:07 +04:00
|
|
|
&Context.Idents.get("self"), selfTy));
|
2009-02-20 23:59:54 +03:00
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(),
|
|
|
|
&Context.Idents.get("_cmd"),
|
2009-04-20 19:06:07 +04:00
|
|
|
Context.getObjCSelType()));
|
2009-02-20 23:59:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
|
|
|
|
if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
|
|
|
|
return ID;
|
|
|
|
if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
|
|
|
|
return CD->getClassInterface();
|
2009-07-28 09:10:52 +04:00
|
|
|
if (ObjCImplDecl *IMD = dyn_cast<ObjCImplDecl>(getDeclContext()))
|
2009-02-20 23:59:54 +03:00
|
|
|
return IMD->getClassInterface();
|
2009-07-28 09:10:52 +04:00
|
|
|
|
|
|
|
assert(!isa<ObjCProtocolDecl>(getDeclContext()) && "It's a protocol method");
|
2009-02-20 23:59:54 +03:00
|
|
|
assert(false && "unknown method context");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCInterfaceDecl
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-02-20 09:03:09 +03:00
|
|
|
|
2008-04-04 10:12:32 +04:00
|
|
|
ObjCInterfaceDecl *ObjCInterfaceDecl::Create(ASTContext &C,
|
2009-01-09 03:49:46 +03:00
|
|
|
DeclContext *DC,
|
2008-04-04 10:12:32 +04:00
|
|
|
SourceLocation atLoc,
|
2009-09-09 19:08:12 +04:00
|
|
|
IdentifierInfo *Id,
|
2008-04-11 23:35:35 +04:00
|
|
|
SourceLocation ClassLoc,
|
2008-03-16 04:15:50 +03:00
|
|
|
bool ForwardDecl, bool isInternal){
|
2009-01-28 00:25:57 +03:00
|
|
|
return new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, ForwardDecl,
|
2008-03-16 04:15:50 +03:00
|
|
|
isInternal);
|
|
|
|
}
|
2008-03-16 03:49:28 +03:00
|
|
|
|
2009-02-20 09:03:09 +03:00
|
|
|
ObjCInterfaceDecl::
|
|
|
|
ObjCInterfaceDecl(DeclContext *DC, SourceLocation atLoc, IdentifierInfo *Id,
|
|
|
|
SourceLocation CLoc, bool FD, bool isInternal)
|
|
|
|
: ObjCContainerDecl(ObjCInterface, DC, atLoc, Id),
|
2009-02-20 09:10:45 +03:00
|
|
|
TypeForDecl(0), SuperClass(0),
|
2009-02-20 09:03:09 +03:00
|
|
|
CategoryList(0), ForwardDecl(FD), InternalInterface(isInternal),
|
|
|
|
ClassLoc(CLoc) {
|
2009-01-07 20:57:40 +03:00
|
|
|
}
|
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
void ObjCInterfaceDecl::Destroy(ASTContext &C) {
|
2009-03-31 12:36:08 +04:00
|
|
|
for (ivar_iterator I = ivar_begin(), E = ivar_end(); I != E; ++I)
|
2008-06-06 20:45:15 +04:00
|
|
|
if (*I) (*I)->Destroy(C);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-20 09:03:09 +03:00
|
|
|
// FIXME: CategoryList?
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2008-06-06 21:21:42 +04:00
|
|
|
// FIXME: Because there is no clear ownership
|
|
|
|
// role between ObjCInterfaceDecls and the ObjCPropertyDecls that they
|
|
|
|
// reference, we destroy ObjCPropertyDecls in ~TranslationUnit.
|
2008-06-06 20:45:15 +04:00
|
|
|
Decl::Destroy(C);
|
|
|
|
}
|
|
|
|
|
2009-07-21 04:05:53 +04:00
|
|
|
ObjCImplementationDecl *ObjCInterfaceDecl::getImplementation() const {
|
|
|
|
return getASTContext().getObjCImplementation(
|
|
|
|
const_cast<ObjCInterfaceDecl*>(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjCInterfaceDecl::setImplementation(ObjCImplementationDecl *ImplD) {
|
|
|
|
getASTContext().setObjCImplementation(this, ImplD);
|
|
|
|
}
|
|
|
|
|
2008-06-06 20:45:15 +04:00
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
/// FindCategoryDeclaration - Finds category declaration in the list of
|
|
|
|
/// categories for this class and returns it. Name of the category is passed
|
|
|
|
/// in 'CategoryId'. If category not found, return 0;
|
|
|
|
///
|
|
|
|
ObjCCategoryDecl *
|
|
|
|
ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
|
|
|
|
for (ObjCCategoryDecl *Category = getCategoryList();
|
|
|
|
Category; Category = Category->getNextClassCategory())
|
|
|
|
if (Category->getIdentifier() == CategoryId)
|
|
|
|
return Category;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-21 04:06:20 +04:00
|
|
|
ObjCMethodDecl *
|
|
|
|
ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const {
|
|
|
|
for (ObjCCategoryDecl *Category = getCategoryList();
|
|
|
|
Category; Category = Category->getNextClassCategory())
|
|
|
|
if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
|
|
|
|
if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
|
|
|
|
return MD;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const {
|
|
|
|
for (ObjCCategoryDecl *Category = getCategoryList();
|
|
|
|
Category; Category = Category->getNextClassCategory())
|
|
|
|
if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
|
|
|
|
if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
|
|
|
|
return MD;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-12 02:02:25 +04:00
|
|
|
/// ClassImplementsProtocol - Checks that 'lProto' protocol
|
|
|
|
/// has been implemented in IDecl class, its super class or categories (if
|
|
|
|
/// lookupCategory is true).
|
|
|
|
bool ObjCInterfaceDecl::ClassImplementsProtocol(ObjCProtocolDecl *lProto,
|
|
|
|
bool lookupCategory,
|
|
|
|
bool RHSIsQualifiedID) {
|
|
|
|
ObjCInterfaceDecl *IDecl = this;
|
|
|
|
// 1st, look up the class.
|
|
|
|
const ObjCList<ObjCProtocolDecl> &Protocols =
|
|
|
|
IDecl->getReferencedProtocols();
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-12 02:02:25 +04:00
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator PI = Protocols.begin(),
|
|
|
|
E = Protocols.end(); PI != E; ++PI) {
|
|
|
|
if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
|
|
|
|
return true;
|
|
|
|
// This is dubious and is added to be compatible with gcc. In gcc, it is
|
|
|
|
// also allowed assigning a protocol-qualified 'id' type to a LHS object
|
|
|
|
// when protocol in qualified LHS is in list of protocols in the rhs 'id'
|
|
|
|
// object. This IMO, should be a bug.
|
|
|
|
// FIXME: Treat this as an extension, and flag this as an error when GCC
|
|
|
|
// extensions are not enabled.
|
2009-09-09 19:08:12 +04:00
|
|
|
if (RHSIsQualifiedID &&
|
2009-08-12 02:02:25 +04:00
|
|
|
getASTContext().ProtocolCompatibleWithProtocol(*PI, lProto))
|
|
|
|
return true;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-12 02:02:25 +04:00
|
|
|
// 2nd, look up the category.
|
|
|
|
if (lookupCategory)
|
|
|
|
for (ObjCCategoryDecl *CDecl = IDecl->getCategoryList(); CDecl;
|
|
|
|
CDecl = CDecl->getNextClassCategory()) {
|
|
|
|
for (ObjCCategoryDecl::protocol_iterator PI = CDecl->protocol_begin(),
|
|
|
|
E = CDecl->protocol_end(); PI != E; ++PI)
|
|
|
|
if (getASTContext().ProtocolCompatibleWithProtocol(lProto, *PI))
|
|
|
|
return true;
|
|
|
|
}
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-12 02:02:25 +04:00
|
|
|
// 3rd, look up the super class(s)
|
|
|
|
if (IDecl->getSuperClass())
|
|
|
|
return
|
|
|
|
IDecl->getSuperClass()->ClassImplementsProtocol(lProto, lookupCategory,
|
|
|
|
RHSIsQualifiedID);
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-08-12 02:02:25 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCIvarDecl
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-04-03 00:10:03 +04:00
|
|
|
ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC,
|
2009-02-17 23:20:37 +03:00
|
|
|
SourceLocation L, IdentifierInfo *Id,
|
2009-12-07 05:54:59 +03:00
|
|
|
QualType T, TypeSourceInfo *TInfo,
|
2009-08-19 05:27:57 +04:00
|
|
|
AccessControl ac, Expr *BW) {
|
2010-04-03 00:10:03 +04:00
|
|
|
if (DC) {
|
|
|
|
// Ivar's can only appear in interfaces, implementations (via synthesized
|
|
|
|
// properties), and class extensions (via direct declaration, or synthesized
|
|
|
|
// properties).
|
|
|
|
//
|
|
|
|
// FIXME: This should really be asserting this:
|
|
|
|
// (isa<ObjCCategoryDecl>(DC) &&
|
|
|
|
// cast<ObjCCategoryDecl>(DC)->IsClassExtension()))
|
|
|
|
// but unfortunately we sometimes place ivars into non-class extension
|
|
|
|
// categories on error. This breaks an AST invariant, and should not be
|
|
|
|
// fixed.
|
|
|
|
assert((isa<ObjCInterfaceDecl>(DC) || isa<ObjCImplementationDecl>(DC) ||
|
|
|
|
isa<ObjCCategoryDecl>(DC)) &&
|
|
|
|
"Invalid ivar decl context!");
|
|
|
|
}
|
|
|
|
|
2009-12-07 05:54:59 +03:00
|
|
|
return new (C) ObjCIvarDecl(DC, L, Id, T, TInfo, ac, BW);
|
2008-03-16 03:49:28 +03:00
|
|
|
}
|
|
|
|
|
2010-04-03 01:13:59 +04:00
|
|
|
const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const {
|
|
|
|
const ObjCContainerDecl *DC = cast<ObjCContainerDecl>(getDeclContext());
|
|
|
|
|
|
|
|
switch (DC->getKind()) {
|
|
|
|
default:
|
|
|
|
case ObjCCategoryImpl:
|
|
|
|
case ObjCProtocol:
|
|
|
|
assert(0 && "invalid ivar container!");
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Ivars can only appear in class extension categories.
|
|
|
|
case ObjCCategory: {
|
|
|
|
const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(DC);
|
|
|
|
assert(CD->IsClassExtension() && "invalid container for ivar!");
|
|
|
|
return CD->getClassInterface();
|
|
|
|
}
|
|
|
|
|
|
|
|
case ObjCImplementation:
|
|
|
|
return cast<ObjCImplementationDecl>(DC)->getClassInterface();
|
2008-08-20 07:26:33 +04:00
|
|
|
|
2010-04-03 01:13:59 +04:00
|
|
|
case ObjCInterface:
|
|
|
|
return cast<ObjCInterfaceDecl>(DC);
|
|
|
|
}
|
|
|
|
}
|
2009-02-20 23:59:54 +03:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCAtDefsFieldDecl
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-08-20 07:26:33 +04:00
|
|
|
ObjCAtDefsFieldDecl
|
2008-12-11 19:49:14 +03:00
|
|
|
*ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
|
2008-08-20 07:26:33 +04:00
|
|
|
IdentifierInfo *Id, QualType T, Expr *BW) {
|
2009-01-28 00:25:57 +03:00
|
|
|
return new (C) ObjCAtDefsFieldDecl(DC, L, Id, T, BW);
|
2008-08-20 07:26:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjCAtDefsFieldDecl::Destroy(ASTContext& C) {
|
|
|
|
this->~ObjCAtDefsFieldDecl();
|
2009-09-09 19:08:12 +04:00
|
|
|
C.Deallocate((void *)this);
|
2008-08-20 07:26:33 +04:00
|
|
|
}
|
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCProtocolDecl
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-01-09 03:49:46 +03:00
|
|
|
ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
|
2009-09-09 19:08:12 +04:00
|
|
|
SourceLocation L,
|
2008-03-16 23:19:15 +03:00
|
|
|
IdentifierInfo *Id) {
|
2009-01-28 00:25:57 +03:00
|
|
|
return new (C) ObjCProtocolDecl(DC, L, Id);
|
2008-03-16 04:23:04 +03:00
|
|
|
}
|
|
|
|
|
2009-02-20 08:54:35 +03:00
|
|
|
void ObjCProtocolDecl::Destroy(ASTContext &C) {
|
2009-02-21 00:35:13 +03:00
|
|
|
ReferencedProtocols.Destroy(C);
|
2009-02-20 08:54:35 +03:00
|
|
|
ObjCContainerDecl::Destroy(C);
|
2008-06-06 23:48:57 +04:00
|
|
|
}
|
|
|
|
|
2009-03-01 19:12:44 +03:00
|
|
|
ObjCProtocolDecl *ObjCProtocolDecl::lookupProtocolNamed(IdentifierInfo *Name) {
|
|
|
|
ObjCProtocolDecl *PDecl = this;
|
|
|
|
|
|
|
|
if (Name == getIdentifier())
|
|
|
|
return PDecl;
|
|
|
|
|
|
|
|
for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
|
|
|
|
if ((PDecl = (*I)->lookupProtocolNamed(Name)))
|
|
|
|
return PDecl;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-03-01 19:12:44 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-07-26 02:15:38 +04:00
|
|
|
// lookupMethod - Lookup a instance/class method in the protocol and protocols
|
2009-02-20 23:59:54 +03:00
|
|
|
// it inherited.
|
2009-07-26 02:15:38 +04:00
|
|
|
ObjCMethodDecl *ObjCProtocolDecl::lookupMethod(Selector Sel,
|
|
|
|
bool isInstance) const {
|
2009-02-20 23:59:54 +03:00
|
|
|
ObjCMethodDecl *MethodDecl = NULL;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-07-26 02:15:38 +04:00
|
|
|
if ((MethodDecl = getMethod(Sel, isInstance)))
|
2009-02-20 23:59:54 +03:00
|
|
|
return MethodDecl;
|
2009-09-09 19:08:12 +04:00
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
|
2009-07-26 02:15:38 +04:00
|
|
|
if ((MethodDecl = (*I)->lookupMethod(Sel, isInstance)))
|
2009-02-20 23:59:54 +03:00
|
|
|
return MethodDecl;
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-02-20 08:54:35 +03:00
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCClassDecl
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-02-20 08:54:35 +03:00
|
|
|
|
2009-09-09 19:08:12 +04:00
|
|
|
ObjCClassDecl::ObjCClassDecl(DeclContext *DC, SourceLocation L,
|
2009-11-18 03:28:11 +03:00
|
|
|
ObjCInterfaceDecl *const *Elts,
|
|
|
|
const SourceLocation *Locs,
|
|
|
|
unsigned nElts,
|
2009-02-21 00:35:13 +03:00
|
|
|
ASTContext &C)
|
|
|
|
: Decl(ObjCClass, DC, L) {
|
2009-11-18 03:28:11 +03:00
|
|
|
setClassList(C, Elts, Locs, nElts);
|
2009-02-21 00:35:13 +03:00
|
|
|
}
|
|
|
|
|
2009-11-18 03:28:11 +03:00
|
|
|
void ObjCClassDecl::setClassList(ASTContext &C, ObjCInterfaceDecl*const*List,
|
|
|
|
const SourceLocation *Locs, unsigned Num) {
|
|
|
|
ForwardDecls = (ObjCClassRef*) C.Allocate(sizeof(ObjCClassRef)*Num,
|
|
|
|
llvm::alignof<ObjCClassRef>());
|
|
|
|
for (unsigned i = 0; i < Num; ++i)
|
|
|
|
new (&ForwardDecls[i]) ObjCClassRef(List[i], Locs[i]);
|
|
|
|
|
|
|
|
NumDecls = Num;
|
|
|
|
}
|
2009-02-21 00:35:13 +03:00
|
|
|
|
2009-01-09 03:49:46 +03:00
|
|
|
ObjCClassDecl *ObjCClassDecl::Create(ASTContext &C, DeclContext *DC,
|
2008-04-04 10:12:32 +04:00
|
|
|
SourceLocation L,
|
2009-02-20 21:04:31 +03:00
|
|
|
ObjCInterfaceDecl *const *Elts,
|
2009-11-18 03:28:11 +03:00
|
|
|
const SourceLocation *Locs,
|
2009-02-20 21:04:31 +03:00
|
|
|
unsigned nElts) {
|
2009-11-18 03:28:11 +03:00
|
|
|
return new (C) ObjCClassDecl(DC, L, Elts, Locs, nElts, C);
|
2008-03-16 23:34:23 +03:00
|
|
|
}
|
|
|
|
|
2009-02-20 09:03:09 +03:00
|
|
|
void ObjCClassDecl::Destroy(ASTContext &C) {
|
2009-11-18 03:28:11 +03:00
|
|
|
// ObjCInterfaceDecls registered with a DeclContext will get destroyed
|
|
|
|
// when the DeclContext is destroyed. For those created only by a forward
|
|
|
|
// declaration, the first @class that created the ObjCInterfaceDecl gets
|
|
|
|
// to destroy it.
|
|
|
|
// FIXME: Note that this ownership role is very brittle; a better
|
|
|
|
// polict is surely need in the future.
|
|
|
|
for (iterator I = begin(), E = end(); I !=E ; ++I) {
|
|
|
|
ObjCInterfaceDecl *ID = I->getInterface();
|
|
|
|
if (ID->isForwardDecl() && ID->getLocStart() == getLocStart())
|
|
|
|
ID->Destroy(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
C.Deallocate(ForwardDecls);
|
2008-06-07 00:11:53 +04:00
|
|
|
Decl::Destroy(C);
|
|
|
|
}
|
|
|
|
|
2009-11-18 04:26:56 +03:00
|
|
|
SourceRange ObjCClassDecl::getSourceRange() const {
|
|
|
|
// FIXME: We should include the semicolon
|
|
|
|
assert(NumDecls);
|
|
|
|
return SourceRange(getLocation(), ForwardDecls[NumDecls-1].getLocation());
|
|
|
|
}
|
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCForwardProtocolDecl
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-02-21 00:35:13 +03:00
|
|
|
ObjCForwardProtocolDecl::
|
|
|
|
ObjCForwardProtocolDecl(DeclContext *DC, SourceLocation L,
|
|
|
|
ObjCProtocolDecl *const *Elts, unsigned nElts,
|
2010-01-16 18:02:53 +03:00
|
|
|
const SourceLocation *Locs, ASTContext &C)
|
2009-09-09 19:08:12 +04:00
|
|
|
: Decl(ObjCForwardProtocol, DC, L) {
|
2010-01-16 18:02:53 +03:00
|
|
|
ReferencedProtocols.set(Elts, nElts, Locs, C);
|
2009-02-21 00:35:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-16 23:34:23 +03:00
|
|
|
ObjCForwardProtocolDecl *
|
2009-01-09 03:49:46 +03:00
|
|
|
ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC,
|
2009-09-09 19:08:12 +04:00
|
|
|
SourceLocation L,
|
2009-02-20 21:10:37 +03:00
|
|
|
ObjCProtocolDecl *const *Elts,
|
2010-01-16 18:02:53 +03:00
|
|
|
unsigned NumElts,
|
|
|
|
const SourceLocation *Locs) {
|
|
|
|
return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts, Locs, C);
|
2009-02-20 09:03:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjCForwardProtocolDecl::Destroy(ASTContext &C) {
|
2009-02-21 00:35:13 +03:00
|
|
|
ReferencedProtocols.Destroy(C);
|
2009-02-20 21:10:37 +03:00
|
|
|
Decl::Destroy(C);
|
2008-06-07 01:05:33 +04:00
|
|
|
}
|
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCCategoryDecl
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-01-09 03:49:46 +03:00
|
|
|
ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
|
2010-01-16 19:38:58 +03:00
|
|
|
SourceLocation AtLoc,
|
|
|
|
SourceLocation ClassNameLoc,
|
|
|
|
SourceLocation CategoryNameLoc,
|
2008-03-16 23:34:23 +03:00
|
|
|
IdentifierInfo *Id) {
|
2010-01-16 19:38:58 +03:00
|
|
|
return new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id);
|
2008-03-16 23:34:23 +03:00
|
|
|
}
|
|
|
|
|
2009-07-21 04:05:53 +04:00
|
|
|
ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
|
|
|
|
return getASTContext().getObjCImplementation(
|
|
|
|
const_cast<ObjCCategoryDecl*>(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjCCategoryDecl::setImplementation(ObjCCategoryImplDecl *ImplD) {
|
|
|
|
getASTContext().setObjCImplementation(this, ImplD);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCCategoryImplDecl
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-03-16 23:53:07 +03:00
|
|
|
ObjCCategoryImplDecl *
|
2009-01-09 03:49:46 +03:00
|
|
|
ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
|
2008-04-04 10:12:32 +04:00
|
|
|
SourceLocation L,IdentifierInfo *Id,
|
2008-03-16 23:53:07 +03:00
|
|
|
ObjCInterfaceDecl *ClassInterface) {
|
2009-01-28 00:25:57 +03:00
|
|
|
return new (C) ObjCCategoryImplDecl(DC, L, Id, ClassInterface);
|
2008-03-16 23:53:07 +03:00
|
|
|
}
|
|
|
|
|
2009-10-30 00:11:04 +03:00
|
|
|
ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
|
2010-03-19 23:39:03 +03:00
|
|
|
// The class interface might be NULL if we are working with invalid code.
|
|
|
|
if (const ObjCInterfaceDecl *ID = getClassInterface())
|
|
|
|
return ID->FindCategoryDeclaration(getIdentifier());
|
|
|
|
return 0;
|
2009-07-28 09:11:05 +04:00
|
|
|
}
|
|
|
|
|
2008-03-17 00:17:37 +03:00
|
|
|
|
2009-06-30 06:36:12 +04:00
|
|
|
void ObjCImplDecl::addPropertyImplementation(ObjCPropertyImplDecl *property) {
|
2009-04-23 06:42:49 +04:00
|
|
|
// FIXME: The context should be correct before we get here.
|
2009-04-23 05:02:12 +04:00
|
|
|
property->setLexicalDeclContext(this);
|
2009-06-30 06:36:12 +04:00
|
|
|
addDecl(property);
|
2009-04-23 05:02:12 +04:00
|
|
|
}
|
|
|
|
|
2009-07-21 04:05:53 +04:00
|
|
|
void ObjCImplDecl::setClassInterface(ObjCInterfaceDecl *IFace) {
|
|
|
|
ASTContext &Ctx = getASTContext();
|
|
|
|
|
|
|
|
if (ObjCImplementationDecl *ImplD
|
2009-07-21 11:56:29 +04:00
|
|
|
= dyn_cast_or_null<ObjCImplementationDecl>(this)) {
|
2009-07-21 04:05:53 +04:00
|
|
|
if (IFace)
|
|
|
|
Ctx.setObjCImplementation(IFace, ImplD);
|
|
|
|
|
2009-07-21 11:56:29 +04:00
|
|
|
} else if (ObjCCategoryImplDecl *ImplD =
|
2009-07-21 04:05:53 +04:00
|
|
|
dyn_cast_or_null<ObjCCategoryImplDecl>(this)) {
|
|
|
|
if (ObjCCategoryDecl *CD = IFace->FindCategoryDeclaration(getIdentifier()))
|
|
|
|
Ctx.setObjCImplementation(CD, ImplD);
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassInterface = IFace;
|
|
|
|
}
|
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
|
|
|
|
/// properties implemented in this category @implementation block and returns
|
|
|
|
/// the implemented property that uses it.
|
2008-12-14 01:20:28 +03:00
|
|
|
///
|
2009-02-28 21:42:10 +03:00
|
|
|
ObjCPropertyImplDecl *ObjCImplDecl::
|
2009-06-30 06:36:12 +04:00
|
|
|
FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
|
|
|
|
for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
|
2009-02-20 23:59:54 +03:00
|
|
|
ObjCPropertyImplDecl *PID = *i;
|
|
|
|
if (PID->getPropertyIvarDecl() &&
|
|
|
|
PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
|
|
|
|
return PID;
|
|
|
|
}
|
2009-01-08 20:28:14 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
|
|
|
|
/// added to the list of those properties @synthesized/@dynamic in this
|
|
|
|
/// category @implementation block.
|
2008-04-21 23:04:53 +04:00
|
|
|
///
|
2009-02-28 21:42:10 +03:00
|
|
|
ObjCPropertyImplDecl *ObjCImplDecl::
|
2009-06-30 06:36:12 +04:00
|
|
|
FindPropertyImplDecl(IdentifierInfo *Id) const {
|
|
|
|
for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
|
2009-02-20 23:59:54 +03:00
|
|
|
ObjCPropertyImplDecl *PID = *i;
|
|
|
|
if (PID->getPropertyDecl()->getIdentifier() == Id)
|
|
|
|
return PID;
|
2009-01-19 21:16:19 +03:00
|
|
|
}
|
2008-04-21 23:04:53 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCImplementationDecl
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-03-16 03:19:01 +03:00
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
ObjCImplementationDecl *
|
2009-09-09 19:08:12 +04:00
|
|
|
ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
|
2009-02-20 23:59:54 +03:00
|
|
|
SourceLocation L,
|
|
|
|
ObjCInterfaceDecl *ClassInterface,
|
|
|
|
ObjCInterfaceDecl *SuperDecl) {
|
|
|
|
return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl);
|
|
|
|
}
|
2008-03-16 03:19:01 +03:00
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCCompatibleAliasDecl
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-03-16 03:19:01 +03:00
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
ObjCCompatibleAliasDecl *
|
|
|
|
ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation L,
|
2009-09-09 19:08:12 +04:00
|
|
|
IdentifierInfo *Id,
|
2009-02-20 23:59:54 +03:00
|
|
|
ObjCInterfaceDecl* AliasedClass) {
|
|
|
|
return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
|
2008-03-16 03:19:01 +03:00
|
|
|
}
|
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCPropertyDecl
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-03-16 03:19:01 +03:00
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
|
|
|
|
SourceLocation L,
|
|
|
|
IdentifierInfo *Id,
|
2010-01-21 20:36:00 +03:00
|
|
|
SourceLocation AtLoc,
|
2009-02-20 23:59:54 +03:00
|
|
|
QualType T,
|
|
|
|
PropertyControl propControl) {
|
2010-01-21 20:36:00 +03:00
|
|
|
return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, T);
|
2008-03-16 03:19:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-20 23:59:54 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjCPropertyImplDecl
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-03-17 04:19:02 +03:00
|
|
|
|
2008-04-23 04:06:01 +04:00
|
|
|
ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
|
2009-01-09 03:49:46 +03:00
|
|
|
DeclContext *DC,
|
2008-04-23 04:06:01 +04:00
|
|
|
SourceLocation atLoc,
|
|
|
|
SourceLocation L,
|
|
|
|
ObjCPropertyDecl *property,
|
2008-08-26 08:47:31 +04:00
|
|
|
Kind PK,
|
2008-04-23 04:06:01 +04:00
|
|
|
ObjCIvarDecl *ivar) {
|
2009-01-28 00:25:57 +03:00
|
|
|
return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar);
|
2008-04-23 04:06:01 +04:00
|
|
|
}
|
2008-03-17 04:19:02 +03:00
|
|
|
|
2008-04-04 10:12:32 +04:00
|
|
|
|