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"
|
2008-03-16 03:19:01 +03:00
|
|
|
using namespace clang;
|
|
|
|
|
2008-03-16 03:49:28 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// ObjC Decl Allocation/Deallocation Method Implementations
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-04-04 10:12:32 +04:00
|
|
|
ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
|
|
|
|
SourceLocation beginLoc,
|
2008-03-16 03:49:28 +03:00
|
|
|
SourceLocation endLoc,
|
|
|
|
Selector SelInfo, QualType T,
|
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,
|
2008-04-04 10:12:32 +04:00
|
|
|
SelInfo, T, contextDecl,
|
2008-08-20 22:02:42 +04:00
|
|
|
isInstance,
|
2008-05-08 00:53:44 +04:00
|
|
|
isVariadic, isSynthesized, impControl);
|
2008-03-16 04:15:50 +03:00
|
|
|
}
|
|
|
|
|
2008-06-06 20:45:15 +04:00
|
|
|
ObjCMethodDecl::~ObjCMethodDecl() {
|
|
|
|
delete [] ParamInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjCMethodDecl::Destroy(ASTContext& C) {
|
|
|
|
if (Body) Body->Destroy(C);
|
|
|
|
if (SelfDecl) SelfDecl->Destroy(C);
|
|
|
|
|
|
|
|
for (param_iterator I=param_begin(), E=param_end(); I!=E; ++I)
|
|
|
|
if (*I) (*I)->Destroy(C);
|
|
|
|
|
|
|
|
Decl::Destroy(C);
|
|
|
|
}
|
|
|
|
|
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,
|
2008-04-11 23:35:35 +04:00
|
|
|
IdentifierInfo *Id,
|
|
|
|
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-01-07 20:57:40 +03:00
|
|
|
ObjCContainerDecl::~ObjCContainerDecl() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjCInterfaceDecl::~ObjCInterfaceDecl() {
|
|
|
|
delete [] Ivars;
|
2008-06-06 20:45:15 +04:00
|
|
|
// FIXME: CategoryList?
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjCInterfaceDecl::Destroy(ASTContext& C) {
|
|
|
|
for (ivar_iterator I=ivar_begin(), E=ivar_end(); I!=E; ++I)
|
|
|
|
if (*I) (*I)->Destroy(C);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-06 08:47:34 +04:00
|
|
|
ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L,
|
2008-07-23 22:04:17 +04:00
|
|
|
IdentifierInfo *Id, QualType T,
|
|
|
|
AccessControl ac, Expr *BW) {
|
2009-01-28 00:25:57 +03:00
|
|
|
return new (C) ObjCIvarDecl(L, Id, T, ac, BW);
|
2008-03-16 03:49:28 +03:00
|
|
|
}
|
|
|
|
|
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-01-28 00:25:57 +03:00
|
|
|
C.Deallocate((void *)this);
|
2008-08-20 07:26:33 +04:00
|
|
|
}
|
|
|
|
|
2009-01-09 03:49:46 +03:00
|
|
|
ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
|
2008-04-04 10:12:32 +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
|
|
|
}
|
|
|
|
|
2008-06-06 23:48:57 +04:00
|
|
|
ObjCProtocolDecl::~ObjCProtocolDecl() {
|
|
|
|
delete [] PropertyDecl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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,
|
2008-03-16 23:34:23 +03:00
|
|
|
ObjCInterfaceDecl **Elts, unsigned nElts) {
|
2009-01-28 00:25:57 +03:00
|
|
|
return new (C) ObjCClassDecl(DC, L, Elts, nElts);
|
2008-03-16 23:34:23 +03:00
|
|
|
}
|
|
|
|
|
2008-06-07 00:11:53 +04:00
|
|
|
ObjCClassDecl::~ObjCClassDecl() {
|
|
|
|
delete [] ForwardDecls;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjCClassDecl::Destroy(ASTContext& C) {
|
|
|
|
|
|
|
|
// FIXME: There is no clear ownership policy now for referenced
|
|
|
|
// ObjCInterfaceDecls. Some of them can be forward declarations that
|
|
|
|
// are never later defined (in which case the ObjCClassDecl owns them)
|
|
|
|
// or the ObjCInterfaceDecl later becomes a real definition later. Ideally
|
|
|
|
// we should have separate objects for forward declarations and definitions,
|
|
|
|
// obviating this problem. Because of this situation, referenced
|
|
|
|
// ObjCInterfaceDecls are destroyed in ~TranslationUnit.
|
|
|
|
|
|
|
|
Decl::Destroy(C);
|
|
|
|
}
|
|
|
|
|
2008-03-16 23:34:23 +03:00
|
|
|
ObjCForwardProtocolDecl *
|
2009-01-09 03:49:46 +03:00
|
|
|
ObjCForwardProtocolDecl::Create(ASTContext &C, DeclContext *DC,
|
2008-04-04 10:12:32 +04:00
|
|
|
SourceLocation L,
|
2008-03-16 23:34:23 +03:00
|
|
|
ObjCProtocolDecl **Elts, unsigned NumElts) {
|
2009-01-28 00:25:57 +03:00
|
|
|
return new (C) ObjCForwardProtocolDecl(DC, L, Elts, NumElts);
|
2008-03-16 23:34:23 +03:00
|
|
|
}
|
|
|
|
|
2008-06-07 01:05:33 +04:00
|
|
|
ObjCForwardProtocolDecl::~ObjCForwardProtocolDecl() {
|
|
|
|
delete [] ReferencedProtocols;
|
|
|
|
}
|
|
|
|
|
2009-01-09 03:49:46 +03:00
|
|
|
ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
|
2008-04-04 10:12:32 +04:00
|
|
|
SourceLocation L,
|
2008-03-16 23:34:23 +03:00
|
|
|
IdentifierInfo *Id) {
|
2009-01-28 00:25:57 +03:00
|
|
|
return new (C) ObjCCategoryDecl(DC, L, Id);
|
2008-03-16 23:34:23 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
ObjCImplementationDecl *
|
2009-01-09 03:49:46 +03:00
|
|
|
ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
|
2008-04-04 10:12:32 +04:00
|
|
|
SourceLocation L,
|
2008-03-16 23:53:07 +03:00
|
|
|
ObjCInterfaceDecl *ClassInterface,
|
|
|
|
ObjCInterfaceDecl *SuperDecl) {
|
2009-01-28 00:25:57 +03:00
|
|
|
return new (C) ObjCImplementationDecl(DC, L, ClassInterface, SuperDecl);
|
2008-03-16 23:53:07 +03:00
|
|
|
}
|
2008-03-16 03:19:01 +03:00
|
|
|
|
2008-03-17 00:17:37 +03:00
|
|
|
ObjCCompatibleAliasDecl *
|
2009-01-09 03:49:46 +03:00
|
|
|
ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
|
2008-04-04 10:12:32 +04:00
|
|
|
SourceLocation L,
|
2008-03-17 00:17:37 +03:00
|
|
|
IdentifierInfo *Id,
|
|
|
|
ObjCInterfaceDecl* AliasedClass) {
|
2009-01-28 00:25:57 +03:00
|
|
|
return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
|
2008-03-17 00:17:37 +03:00
|
|
|
}
|
|
|
|
|
2009-01-09 03:49:46 +03:00
|
|
|
ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
|
2008-04-12 03:40:25 +04:00
|
|
|
SourceLocation L,
|
2008-04-15 03:36:35 +04:00
|
|
|
IdentifierInfo *Id,
|
2008-05-05 22:51:55 +04:00
|
|
|
QualType T,
|
|
|
|
PropertyControl propControl) {
|
2009-01-28 00:25:57 +03:00
|
|
|
return new (C) ObjCPropertyDecl(DC, L, Id, T);
|
2008-03-17 00:17:37 +03:00
|
|
|
}
|
|
|
|
|
2008-03-16 03:19:01 +03:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Objective-C Decl Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-12-09 23:23:04 +03:00
|
|
|
void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
|
|
|
|
const ObjCInterfaceDecl *OID) {
|
2008-08-26 10:08:30 +04:00
|
|
|
QualType selfTy;
|
2009-01-09 20:18:27 +03:00
|
|
|
if (isInstanceMethod()) {
|
2008-08-26 10:08:30 +04:00
|
|
|
// There may be no interface context due to error in declaration
|
|
|
|
// of the interface (which has been reported). Recover gracefully.
|
2008-12-09 23:23:04 +03:00
|
|
|
if (OID) {
|
|
|
|
selfTy = Context.getObjCInterfaceType(const_cast<ObjCInterfaceDecl *>(OID));
|
2008-08-26 10:08:30 +04:00
|
|
|
selfTy = Context.getPointerType(selfTy);
|
|
|
|
} else {
|
|
|
|
selfTy = Context.getObjCIdType();
|
|
|
|
}
|
|
|
|
} else // we have a factory method.
|
|
|
|
selfTy = Context.getObjCClassType();
|
|
|
|
|
|
|
|
SelfDecl = ImplicitParamDecl::Create(Context, this,
|
|
|
|
SourceLocation(),
|
|
|
|
&Context.Idents.get("self"),
|
2009-01-20 04:17:11 +03:00
|
|
|
selfTy);
|
2008-08-26 10:08:30 +04:00
|
|
|
|
|
|
|
CmdDecl = ImplicitParamDecl::Create(Context, this,
|
|
|
|
SourceLocation(),
|
|
|
|
&Context.Idents.get("_cmd"),
|
2009-01-20 04:17:11 +03:00
|
|
|
Context.getObjCSelType());
|
2008-08-26 10:08:30 +04:00
|
|
|
}
|
|
|
|
|
2008-03-16 03:19:01 +03:00
|
|
|
void ObjCMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo,
|
|
|
|
unsigned NumParams) {
|
|
|
|
assert(ParamInfo == 0 && "Already has param info!");
|
|
|
|
|
|
|
|
// Zero params -> null pointer.
|
|
|
|
if (NumParams) {
|
|
|
|
ParamInfo = new ParmVarDecl*[NumParams];
|
|
|
|
memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
|
|
|
|
NumMethodParams = NumParams;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-21 23:04:53 +04: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;
|
|
|
|
}
|
|
|
|
|
2008-03-16 03:19:01 +03:00
|
|
|
/// ObjCAddInstanceVariablesToClass - Inserts instance variables
|
|
|
|
/// into ObjCInterfaceDecl's fields.
|
|
|
|
///
|
|
|
|
void ObjCInterfaceDecl::addInstanceVariablesToClass(ObjCIvarDecl **ivars,
|
|
|
|
unsigned numIvars,
|
|
|
|
SourceLocation RBrac) {
|
|
|
|
NumIvars = numIvars;
|
|
|
|
if (numIvars) {
|
|
|
|
Ivars = new ObjCIvarDecl*[numIvars];
|
|
|
|
memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*));
|
|
|
|
}
|
|
|
|
setLocEnd(RBrac);
|
|
|
|
}
|
|
|
|
|
2008-12-14 01:20:28 +03:00
|
|
|
/// lookupFieldDeclForIvar - looks up a field decl' in the laid out
|
|
|
|
/// storage which matches this 'ivar'.
|
|
|
|
///
|
|
|
|
FieldDecl *ObjCInterfaceDecl::lookupFieldDeclForIvar(ASTContext &Context,
|
2008-12-15 23:35:07 +03:00
|
|
|
const ObjCIvarDecl *ivar) {
|
2008-12-18 00:40:49 +03:00
|
|
|
const RecordDecl *RecordForDecl = Context.addRecordToClass(this);
|
2008-12-14 01:20:28 +03:00
|
|
|
assert(RecordForDecl && "lookupFieldDeclForIvar no storage for class");
|
|
|
|
DeclarationName Member = ivar->getDeclName();
|
2008-12-18 00:40:49 +03:00
|
|
|
DeclContext::lookup_result Lookup = (const_cast< RecordDecl *>(RecordForDecl))
|
2009-01-08 20:28:14 +03:00
|
|
|
->lookup(Member);
|
2008-12-14 01:20:28 +03:00
|
|
|
assert((Lookup.first != Lookup.second) && "field decl not found");
|
|
|
|
FieldDecl *MemberDecl = dyn_cast<FieldDecl>(*Lookup.first);
|
|
|
|
assert(MemberDecl && "field decl not found");
|
|
|
|
return MemberDecl;
|
|
|
|
}
|
|
|
|
|
2008-03-16 03:19:01 +03:00
|
|
|
/// ObjCAddInstanceVariablesToClassImpl - Checks for correctness of Instance
|
|
|
|
/// Variables (Ivars) relative to what declared in @implementation;s class.
|
|
|
|
/// Ivars into ObjCImplementationDecl's fields.
|
|
|
|
///
|
|
|
|
void ObjCImplementationDecl::ObjCAddInstanceVariablesToClassImpl(
|
|
|
|
ObjCIvarDecl **ivars, unsigned numIvars) {
|
|
|
|
NumIvars = numIvars;
|
|
|
|
if (numIvars) {
|
|
|
|
Ivars = new ObjCIvarDecl*[numIvars];
|
|
|
|
memcpy(Ivars, ivars, numIvars*sizeof(ObjCIvarDecl*));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-08 20:28:14 +03:00
|
|
|
// Get the local instance method declared in this interface.
|
|
|
|
// FIXME: handle overloading, instance & class methods can have the same name.
|
|
|
|
ObjCMethodDecl *ObjCContainerDecl::getInstanceMethod(Selector Sel) const {
|
|
|
|
lookup_const_result MethodResult = lookup(Sel);
|
|
|
|
if (MethodResult.first)
|
|
|
|
return const_cast<ObjCMethodDecl*>(
|
|
|
|
dyn_cast<ObjCMethodDecl>(*MethodResult.first));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the local class method declared in this interface.
|
|
|
|
ObjCMethodDecl *ObjCContainerDecl::getClassMethod(Selector Sel) const {
|
|
|
|
lookup_const_result MethodResult = lookup(Sel);
|
|
|
|
if (MethodResult.first)
|
|
|
|
return const_cast<ObjCMethodDecl*>(
|
|
|
|
dyn_cast<ObjCMethodDecl>(*MethodResult.first));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ObjCContainerDecl::getNumInstanceMethods() const {
|
|
|
|
unsigned sum = 0;
|
|
|
|
for (instmeth_iterator I=instmeth_begin(), E=instmeth_end(); I != E; ++I)
|
|
|
|
sum++;
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
unsigned ObjCContainerDecl::getNumClassMethods() const {
|
|
|
|
unsigned sum = 0;
|
|
|
|
for (classmeth_iterator I=classmeth_begin(), E=classmeth_end(); I != E; ++I)
|
|
|
|
sum++;
|
|
|
|
return sum;
|
|
|
|
}
|
2009-01-11 04:06:09 +03:00
|
|
|
unsigned ObjCContainerDecl::getNumProperties() const {
|
|
|
|
unsigned sum = 0;
|
|
|
|
for (prop_iterator I=prop_begin(), E=prop_end(); I != E; ++I)
|
|
|
|
sum++;
|
|
|
|
return sum;
|
|
|
|
}
|
2009-01-08 20:28:14 +03:00
|
|
|
|
2008-04-21 23:04:53 +04:00
|
|
|
/// FindPropertyDeclaration - Finds declaration of the property given its name
|
|
|
|
/// in 'PropertyId' and returns it. It returns 0, if not found.
|
2009-01-11 15:47:58 +03:00
|
|
|
/// FIXME: Convert to DeclContext lookup...
|
2008-04-21 23:04:53 +04:00
|
|
|
///
|
|
|
|
ObjCPropertyDecl *
|
2009-01-09 18:36:25 +03:00
|
|
|
ObjCContainerDecl::FindPropertyDeclaration(IdentifierInfo *PropertyId) const {
|
|
|
|
for (prop_iterator I = prop_begin(), E = prop_end(); I != E; ++I) {
|
2008-04-21 23:04:53 +04:00
|
|
|
ObjCPropertyDecl *property = *I;
|
|
|
|
if (property->getIdentifier() == PropertyId)
|
|
|
|
return property;
|
2008-06-05 17:55:23 +04:00
|
|
|
}
|
2009-01-10 00:04:52 +03:00
|
|
|
const ObjCProtocolDecl *PID = dyn_cast<ObjCProtocolDecl>(this);
|
|
|
|
if (PID) {
|
|
|
|
for (ObjCProtocolDecl::protocol_iterator P = PID->protocol_begin(),
|
|
|
|
E = PID->protocol_end();
|
|
|
|
P != E; ++P)
|
|
|
|
if (ObjCPropertyDecl *property =
|
|
|
|
(*P)->FindPropertyDeclaration(PropertyId))
|
|
|
|
return property;
|
|
|
|
}
|
|
|
|
|
2009-01-19 21:16:19 +03:00
|
|
|
if (const ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(this)) {
|
2009-01-09 18:36:25 +03:00
|
|
|
// Look through categories.
|
|
|
|
for (ObjCCategoryDecl *Category = OID->getCategoryList();
|
|
|
|
Category; Category = Category->getNextClassCategory()) {
|
|
|
|
ObjCPropertyDecl *property = Category->FindPropertyDeclaration(PropertyId);
|
|
|
|
if (property)
|
|
|
|
return property;
|
|
|
|
}
|
|
|
|
// Look through protocols.
|
|
|
|
for (ObjCInterfaceDecl::protocol_iterator I = OID->protocol_begin(),
|
|
|
|
E = OID->protocol_end(); I != E; ++I) {
|
|
|
|
ObjCProtocolDecl *Protocol = *I;
|
|
|
|
ObjCPropertyDecl *property = Protocol->FindPropertyDeclaration(PropertyId);
|
|
|
|
if (property)
|
|
|
|
return property;
|
|
|
|
}
|
|
|
|
if (OID->getSuperClass())
|
|
|
|
return OID->getSuperClass()->FindPropertyDeclaration(PropertyId);
|
2008-04-21 23:04:53 +04:00
|
|
|
}
|
2009-01-19 21:16:19 +03:00
|
|
|
else if (const ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(this)) {
|
|
|
|
// Look through protocols.
|
|
|
|
for (ObjCInterfaceDecl::protocol_iterator I = OCD->protocol_begin(),
|
|
|
|
E = OCD->protocol_end(); I != E; ++I) {
|
|
|
|
ObjCProtocolDecl *Protocol = *I;
|
|
|
|
ObjCPropertyDecl *property = Protocol->FindPropertyDeclaration(PropertyId);
|
|
|
|
if (property)
|
|
|
|
return property;
|
|
|
|
}
|
|
|
|
}
|
2008-04-21 23:04:53 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-16 03:19:01 +03:00
|
|
|
ObjCIvarDecl *ObjCInterfaceDecl::lookupInstanceVariable(
|
|
|
|
IdentifierInfo *ID, ObjCInterfaceDecl *&clsDeclared) {
|
|
|
|
ObjCInterfaceDecl* ClassDecl = this;
|
|
|
|
while (ClassDecl != NULL) {
|
|
|
|
for (ivar_iterator I = ClassDecl->ivar_begin(), E = ClassDecl->ivar_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if ((*I)->getIdentifier() == ID) {
|
|
|
|
clsDeclared = ClassDecl;
|
|
|
|
return *I;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ClassDecl = ClassDecl->getSuperClass();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// lookupInstanceMethod - This method returns an instance method by looking in
|
|
|
|
/// the class, its categories, and its super classes (using a linear search).
|
|
|
|
ObjCMethodDecl *ObjCInterfaceDecl::lookupInstanceMethod(Selector Sel) {
|
|
|
|
ObjCInterfaceDecl* ClassDecl = this;
|
|
|
|
ObjCMethodDecl *MethodDecl = 0;
|
|
|
|
|
|
|
|
while (ClassDecl != NULL) {
|
|
|
|
if ((MethodDecl = ClassDecl->getInstanceMethod(Sel)))
|
|
|
|
return MethodDecl;
|
|
|
|
|
|
|
|
// Didn't find one yet - look through protocols.
|
2008-07-21 22:19:38 +04:00
|
|
|
const ObjCList<ObjCProtocolDecl> &Protocols =
|
|
|
|
ClassDecl->getReferencedProtocols();
|
|
|
|
for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
|
|
|
|
E = Protocols.end(); I != E; ++I)
|
|
|
|
if ((MethodDecl = (*I)->getInstanceMethod(Sel)))
|
2008-03-16 03:19:01 +03:00
|
|
|
return MethodDecl;
|
2008-07-21 22:19:38 +04:00
|
|
|
|
2008-03-16 03:19:01 +03:00
|
|
|
// Didn't find one yet - now look through categories.
|
|
|
|
ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
|
|
|
|
while (CatDecl) {
|
|
|
|
if ((MethodDecl = CatDecl->getInstanceMethod(Sel)))
|
|
|
|
return MethodDecl;
|
2008-12-08 23:57:28 +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)
|
|
|
|
if ((MethodDecl = (*I)->getInstanceMethod(Sel)))
|
|
|
|
return MethodDecl;
|
2008-03-16 03:19:01 +03:00
|
|
|
CatDecl = CatDecl->getNextClassCategory();
|
|
|
|
}
|
|
|
|
ClassDecl = ClassDecl->getSuperClass();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// lookupClassMethod - This method returns a class method by looking in the
|
|
|
|
// class, its categories, and its super classes (using a linear search).
|
|
|
|
ObjCMethodDecl *ObjCInterfaceDecl::lookupClassMethod(Selector Sel) {
|
|
|
|
ObjCInterfaceDecl* ClassDecl = this;
|
|
|
|
ObjCMethodDecl *MethodDecl = 0;
|
|
|
|
|
|
|
|
while (ClassDecl != NULL) {
|
|
|
|
if ((MethodDecl = ClassDecl->getClassMethod(Sel)))
|
|
|
|
return MethodDecl;
|
|
|
|
|
|
|
|
// Didn't find one yet - look through protocols.
|
2008-07-22 01:32:27 +04:00
|
|
|
for (ObjCInterfaceDecl::protocol_iterator I = ClassDecl->protocol_begin(),
|
|
|
|
E = ClassDecl->protocol_end(); I != E; ++I)
|
2008-07-21 22:19:38 +04:00
|
|
|
if ((MethodDecl = (*I)->getClassMethod(Sel)))
|
2008-03-16 03:19:01 +03:00
|
|
|
return MethodDecl;
|
2008-07-22 01:32:27 +04:00
|
|
|
|
2008-03-16 03:19:01 +03:00
|
|
|
// Didn't find one yet - now look through categories.
|
|
|
|
ObjCCategoryDecl *CatDecl = ClassDecl->getCategoryList();
|
|
|
|
while (CatDecl) {
|
|
|
|
if ((MethodDecl = CatDecl->getClassMethod(Sel)))
|
|
|
|
return MethodDecl;
|
|
|
|
CatDecl = CatDecl->getNextClassCategory();
|
|
|
|
}
|
|
|
|
ClassDecl = ClassDecl->getSuperClass();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-08-26 10:53:45 +04:00
|
|
|
/// getInstanceMethod - This method returns an instance method by
|
|
|
|
/// looking in the class implementation. Unlike interfaces, we don't
|
|
|
|
/// look outside the implementation.
|
|
|
|
ObjCMethodDecl *ObjCImplementationDecl::getInstanceMethod(Selector Sel) const {
|
2008-03-16 03:19:01 +03:00
|
|
|
for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
|
|
|
|
if ((*I)->getSelector() == Sel)
|
|
|
|
return *I;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-08-26 10:53:45 +04:00
|
|
|
/// getClassMethod - This method returns a class method by looking in
|
|
|
|
/// the class implementation. Unlike interfaces, we don't look outside
|
|
|
|
/// the implementation.
|
|
|
|
ObjCMethodDecl *ObjCImplementationDecl::getClassMethod(Selector Sel) const {
|
2008-03-16 03:19:01 +03:00
|
|
|
for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
|
|
|
|
I != E; ++I)
|
|
|
|
if ((*I)->getSelector() == Sel)
|
|
|
|
return *I;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-12-06 01:32:48 +03:00
|
|
|
/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
|
|
|
|
/// added to the list of those properties @synthesized/@dynamic in this
|
|
|
|
/// @implementation block.
|
|
|
|
///
|
|
|
|
ObjCPropertyImplDecl *ObjCImplementationDecl::FindPropertyImplDecl(IdentifierInfo *Id) const {
|
|
|
|
for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) {
|
|
|
|
ObjCPropertyImplDecl *PID = *i;
|
|
|
|
if (PID->getPropertyDecl()->getIdentifier() == Id)
|
|
|
|
return PID;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
|
2008-12-06 01:36:19 +03:00
|
|
|
/// properties implemented in this @implementation block and returns the
|
|
|
|
/// implemented property that uses it.
|
2008-12-06 01:32:48 +03:00
|
|
|
///
|
|
|
|
ObjCPropertyImplDecl *ObjCImplementationDecl::FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
|
|
|
|
for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i) {
|
|
|
|
ObjCPropertyImplDecl *PID = *i;
|
|
|
|
if (PID->getPropertyIvarDecl() &&
|
|
|
|
PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
|
|
|
|
return PID;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// FindPropertyImplIvarDecl - This method lookup the ivar in the list of
|
2009-02-16 22:24:31 +03:00
|
|
|
/// properties implemented in this category @implementation block and returns
|
|
|
|
/// the implemented property that uses it.
|
2008-12-06 01:32:48 +03:00
|
|
|
///
|
2009-02-16 22:24:31 +03:00
|
|
|
ObjCPropertyImplDecl *ObjCCategoryImplDecl::
|
|
|
|
FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const {
|
|
|
|
for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
|
2008-12-06 01:32:48 +03:00
|
|
|
ObjCPropertyImplDecl *PID = *i;
|
|
|
|
if (PID->getPropertyIvarDecl() &&
|
|
|
|
PID->getPropertyIvarDecl()->getIdentifier() == ivarId)
|
|
|
|
return PID;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// FindPropertyImplDecl - This method looks up a previous ObjCPropertyImplDecl
|
|
|
|
/// added to the list of those properties @synthesized/@dynamic in this
|
|
|
|
/// category @implementation block.
|
|
|
|
///
|
2009-02-16 22:24:31 +03:00
|
|
|
ObjCPropertyImplDecl *ObjCCategoryImplDecl::
|
|
|
|
FindPropertyImplDecl(IdentifierInfo *Id) const {
|
|
|
|
for (propimpl_iterator i = propimpl_begin(), e = propimpl_end(); i != e; ++i){
|
2008-12-06 01:32:48 +03:00
|
|
|
ObjCPropertyImplDecl *PID = *i;
|
|
|
|
if (PID->getPropertyDecl()->getIdentifier() == Id)
|
|
|
|
return PID;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-16 03:19:01 +03:00
|
|
|
// lookupInstanceMethod - This method returns an instance method by looking in
|
|
|
|
// the class implementation. Unlike interfaces, we don't look outside the
|
|
|
|
// implementation.
|
2008-08-26 10:53:45 +04:00
|
|
|
ObjCMethodDecl *ObjCCategoryImplDecl::getInstanceMethod(Selector Sel) const {
|
2008-03-16 03:19:01 +03:00
|
|
|
for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
|
|
|
|
if ((*I)->getSelector() == Sel)
|
|
|
|
return *I;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// lookupClassMethod - This method returns an instance method by looking in
|
|
|
|
// the class implementation. Unlike interfaces, we don't look outside the
|
|
|
|
// implementation.
|
2008-08-26 10:53:45 +04:00
|
|
|
ObjCMethodDecl *ObjCCategoryImplDecl::getClassMethod(Selector Sel) const {
|
2008-03-16 03:19:01 +03:00
|
|
|
for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
|
|
|
|
I != E; ++I)
|
|
|
|
if ((*I)->getSelector() == Sel)
|
|
|
|
return *I;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// lookupInstanceMethod - Lookup a instance method in the protocol and protocols
|
|
|
|
// it inherited.
|
|
|
|
ObjCMethodDecl *ObjCProtocolDecl::lookupInstanceMethod(Selector Sel) {
|
|
|
|
ObjCMethodDecl *MethodDecl = NULL;
|
|
|
|
|
|
|
|
if ((MethodDecl = getInstanceMethod(Sel)))
|
|
|
|
return MethodDecl;
|
|
|
|
|
2008-07-22 01:32:27 +04:00
|
|
|
for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
|
2008-12-18 18:50:41 +03:00
|
|
|
if ((MethodDecl = (*I)->lookupInstanceMethod(Sel)))
|
2008-07-22 01:32:27 +04:00
|
|
|
return MethodDecl;
|
2008-03-16 03:19:01 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// lookupInstanceMethod - Lookup a class method in the protocol and protocols
|
|
|
|
// it inherited.
|
|
|
|
ObjCMethodDecl *ObjCProtocolDecl::lookupClassMethod(Selector Sel) {
|
|
|
|
ObjCMethodDecl *MethodDecl = NULL;
|
|
|
|
|
|
|
|
if ((MethodDecl = getClassMethod(Sel)))
|
|
|
|
return MethodDecl;
|
|
|
|
|
2008-07-22 01:32:27 +04:00
|
|
|
for (protocol_iterator I = protocol_begin(), E = protocol_end(); I != E; ++I)
|
2008-12-18 18:50:41 +03:00
|
|
|
if ((MethodDecl = (*I)->lookupClassMethod(Sel)))
|
2008-07-22 01:32:27 +04:00
|
|
|
return MethodDecl;
|
2008-03-16 03:19:01 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getSynthesizedMethodSize - Compute size of synthesized method name
|
|
|
|
/// as done be the rewrite.
|
|
|
|
///
|
|
|
|
unsigned ObjCMethodDecl::getSynthesizedMethodSize() const {
|
|
|
|
// syntesized method name is a concatenation of -/+[class-name selector]
|
|
|
|
// Get length of this name.
|
|
|
|
unsigned length = 3; // _I_ or _C_
|
2008-11-24 06:54:41 +03:00
|
|
|
length += getClassInterface()->getNameAsString().size()+1; // extra for _
|
2009-01-08 22:41:02 +03:00
|
|
|
if (const ObjCCategoryImplDecl *CID =
|
|
|
|
dyn_cast<ObjCCategoryImplDecl>(getDeclContext()))
|
2008-11-24 06:54:41 +03:00
|
|
|
length += CID->getNameAsString().size()+1;
|
2008-11-24 06:33:13 +03:00
|
|
|
length += getSelector().getAsString().size(); // selector name
|
2008-03-16 03:19:01 +03:00
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
2008-04-06 09:25:03 +04:00
|
|
|
ObjCInterfaceDecl *ObjCMethodDecl::getClassInterface() {
|
2009-01-08 22:41:02 +03:00
|
|
|
if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(getDeclContext()))
|
2008-03-16 03:19:01 +03:00
|
|
|
return ID;
|
2009-01-08 22:41:02 +03:00
|
|
|
if (ObjCCategoryDecl *CD = dyn_cast<ObjCCategoryDecl>(getDeclContext()))
|
2008-03-16 03:19:01 +03:00
|
|
|
return CD->getClassInterface();
|
|
|
|
if (ObjCImplementationDecl *IMD =
|
2009-01-08 22:41:02 +03:00
|
|
|
dyn_cast<ObjCImplementationDecl>(getDeclContext()))
|
2008-03-16 03:19:01 +03:00
|
|
|
return IMD->getClassInterface();
|
2009-01-08 22:41:02 +03:00
|
|
|
if (ObjCCategoryImplDecl *CID =
|
|
|
|
dyn_cast<ObjCCategoryImplDecl>(getDeclContext()))
|
2008-03-16 03:19:01 +03:00
|
|
|
return CID->getClassInterface();
|
|
|
|
assert(false && "unknown method context");
|
|
|
|
return 0;
|
|
|
|
}
|
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
|
|
|
|