2007-07-11 21:01:13 +04:00
|
|
|
//===--- Decl.cpp - Declaration AST Node Implementation -------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Chris Lattner and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the Decl class and subclasses.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/Decl.h"
|
2007-10-01 23:00:59 +04:00
|
|
|
#include "clang/AST/DeclObjC.h"
|
2007-07-11 21:01:13 +04:00
|
|
|
#include "clang/Lex/IdentifierTable.h"
|
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
// temporary statistics gathering
|
|
|
|
static unsigned nFuncs = 0;
|
|
|
|
static unsigned nBlockVars = 0;
|
|
|
|
static unsigned nFileVars = 0;
|
|
|
|
static unsigned nParmVars = 0;
|
|
|
|
static unsigned nSUC = 0;
|
|
|
|
static unsigned nEnumConst = 0;
|
|
|
|
static unsigned nEnumDecls = 0;
|
|
|
|
static unsigned nTypedef = 0;
|
|
|
|
static unsigned nFieldDecls = 0;
|
2007-09-07 01:24:23 +04:00
|
|
|
static unsigned nInterfaceDecls = 0;
|
2007-09-17 18:16:13 +04:00
|
|
|
static unsigned nClassDecls = 0;
|
|
|
|
static unsigned nMethodDecls = 0;
|
|
|
|
static unsigned nProtocolDecls = 0;
|
2007-09-21 19:40:54 +04:00
|
|
|
static unsigned nForwardProtocolDecls = 0;
|
2007-09-19 00:26:58 +04:00
|
|
|
static unsigned nCategoryDecls = 0;
|
2007-09-17 18:16:13 +04:00
|
|
|
static unsigned nIvarDecls = 0;
|
2007-09-25 22:38:09 +04:00
|
|
|
static unsigned nObjcImplementationDecls = 0;
|
2007-10-02 20:38:50 +04:00
|
|
|
static unsigned nObjcCategoryImpl = 0;
|
2007-09-17 18:16:13 +04:00
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
static bool StatSwitch = false;
|
|
|
|
|
2007-09-17 18:49:06 +04:00
|
|
|
const char *Decl::getDeclKindName() const {
|
2007-09-16 20:16:00 +04:00
|
|
|
switch (DeclKind) {
|
|
|
|
default: assert(0 && "Unknown decl kind!");
|
|
|
|
case Typedef:
|
|
|
|
return "Typedef";
|
|
|
|
case Function:
|
|
|
|
return "Function";
|
|
|
|
case BlockVariable:
|
|
|
|
return "BlockVariable";
|
|
|
|
case FileVariable:
|
|
|
|
return "FileVariable";
|
|
|
|
case ParmVariable:
|
|
|
|
return "ParmVariable";
|
|
|
|
case EnumConstant:
|
|
|
|
return "EnumConstant";
|
|
|
|
case ObjcInterface:
|
|
|
|
return "ObjcInterface";
|
|
|
|
case ObjcClass:
|
|
|
|
return "ObjcClass";
|
|
|
|
case ObjcMethod:
|
|
|
|
return "ObjcMethod";
|
|
|
|
case ObjcProtocol:
|
|
|
|
return "ObjcProtocol";
|
2007-09-21 19:40:54 +04:00
|
|
|
case ObjcForwardProtocol:
|
|
|
|
return "ObjcForwardProtocol";
|
2007-09-16 20:16:00 +04:00
|
|
|
case Struct:
|
|
|
|
return "Struct";
|
|
|
|
case Union:
|
|
|
|
return "Union";
|
|
|
|
case Class:
|
|
|
|
return "Class";
|
|
|
|
case Enum:
|
|
|
|
return "Enum";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
bool Decl::CollectingStats(bool enable) {
|
|
|
|
if (enable) StatSwitch = true;
|
2007-10-04 04:45:27 +04:00
|
|
|
return StatSwitch;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Decl::PrintStats() {
|
|
|
|
fprintf(stderr, "*** Decl Stats:\n");
|
|
|
|
fprintf(stderr, " %d decls total.\n",
|
|
|
|
int(nFuncs+nBlockVars+nFileVars+nParmVars+nFieldDecls+nSUC+
|
2007-09-17 18:16:13 +04:00
|
|
|
nEnumDecls+nEnumConst+nTypedef+nInterfaceDecls+nClassDecls+
|
2007-09-19 00:26:58 +04:00
|
|
|
nMethodDecls+nProtocolDecls+nCategoryDecls+nIvarDecls));
|
2007-07-11 21:01:13 +04:00
|
|
|
fprintf(stderr, " %d function decls, %d each (%d bytes)\n",
|
|
|
|
nFuncs, (int)sizeof(FunctionDecl), int(nFuncs*sizeof(FunctionDecl)));
|
|
|
|
fprintf(stderr, " %d block variable decls, %d each (%d bytes)\n",
|
|
|
|
nBlockVars, (int)sizeof(BlockVarDecl),
|
|
|
|
int(nBlockVars*sizeof(BlockVarDecl)));
|
|
|
|
fprintf(stderr, " %d file variable decls, %d each (%d bytes)\n",
|
|
|
|
nFileVars, (int)sizeof(FileVarDecl),
|
|
|
|
int(nFileVars*sizeof(FileVarDecl)));
|
|
|
|
fprintf(stderr, " %d parameter variable decls, %d each (%d bytes)\n",
|
|
|
|
nParmVars, (int)sizeof(ParmVarDecl),
|
|
|
|
int(nParmVars*sizeof(ParmVarDecl)));
|
|
|
|
fprintf(stderr, " %d field decls, %d each (%d bytes)\n",
|
|
|
|
nFieldDecls, (int)sizeof(FieldDecl),
|
|
|
|
int(nFieldDecls*sizeof(FieldDecl)));
|
|
|
|
fprintf(stderr, " %d struct/union/class decls, %d each (%d bytes)\n",
|
|
|
|
nSUC, (int)sizeof(RecordDecl),
|
|
|
|
int(nSUC*sizeof(RecordDecl)));
|
|
|
|
fprintf(stderr, " %d enum decls, %d each (%d bytes)\n",
|
|
|
|
nEnumDecls, (int)sizeof(EnumDecl),
|
|
|
|
int(nEnumDecls*sizeof(EnumDecl)));
|
|
|
|
fprintf(stderr, " %d enum constant decls, %d each (%d bytes)\n",
|
|
|
|
nEnumConst, (int)sizeof(EnumConstantDecl),
|
|
|
|
int(nEnumConst*sizeof(EnumConstantDecl)));
|
|
|
|
fprintf(stderr, " %d typedef decls, %d each (%d bytes)\n",
|
|
|
|
nTypedef, (int)sizeof(TypedefDecl),int(nTypedef*sizeof(TypedefDecl)));
|
2007-09-17 18:16:13 +04:00
|
|
|
// Objective-C decls...
|
|
|
|
fprintf(stderr, " %d interface decls, %d each (%d bytes)\n",
|
|
|
|
nInterfaceDecls, (int)sizeof(ObjcInterfaceDecl),
|
|
|
|
int(nInterfaceDecls*sizeof(ObjcInterfaceDecl)));
|
|
|
|
fprintf(stderr, " %d instance variable decls, %d each (%d bytes)\n",
|
|
|
|
nIvarDecls, (int)sizeof(ObjcIvarDecl),
|
|
|
|
int(nIvarDecls*sizeof(ObjcIvarDecl)));
|
|
|
|
fprintf(stderr, " %d class decls, %d each (%d bytes)\n",
|
|
|
|
nClassDecls, (int)sizeof(ObjcClassDecl),
|
|
|
|
int(nClassDecls*sizeof(ObjcClassDecl)));
|
|
|
|
fprintf(stderr, " %d method decls, %d each (%d bytes)\n",
|
|
|
|
nMethodDecls, (int)sizeof(ObjcMethodDecl),
|
|
|
|
int(nMethodDecls*sizeof(ObjcMethodDecl)));
|
|
|
|
fprintf(stderr, " %d protocol decls, %d each (%d bytes)\n",
|
|
|
|
nProtocolDecls, (int)sizeof(ObjcProtocolDecl),
|
|
|
|
int(nProtocolDecls*sizeof(ObjcProtocolDecl)));
|
2007-09-21 19:40:54 +04:00
|
|
|
fprintf(stderr, " %d forward protocol decls, %d each (%d bytes)\n",
|
|
|
|
nForwardProtocolDecls, (int)sizeof(ObjcForwardProtocolDecl),
|
|
|
|
int(nForwardProtocolDecls*sizeof(ObjcForwardProtocolDecl)));
|
2007-09-19 00:26:58 +04:00
|
|
|
fprintf(stderr, " %d category decls, %d each (%d bytes)\n",
|
|
|
|
nCategoryDecls, (int)sizeof(ObjcCategoryDecl),
|
|
|
|
int(nCategoryDecls*sizeof(ObjcCategoryDecl)));
|
2007-09-17 18:16:13 +04:00
|
|
|
|
2007-09-25 22:38:09 +04:00
|
|
|
fprintf(stderr, " %d class implementation decls, %d each (%d bytes)\n",
|
|
|
|
nObjcImplementationDecls, (int)sizeof(ObjcImplementationDecl),
|
|
|
|
int(nObjcImplementationDecls*sizeof(ObjcImplementationDecl)));
|
|
|
|
|
2007-10-02 20:38:50 +04:00
|
|
|
fprintf(stderr, " %d class implementation decls, %d each (%d bytes)\n",
|
|
|
|
nObjcCategoryImpl, (int)sizeof(ObjcCategoryImplDecl),
|
|
|
|
int(nObjcCategoryImpl*sizeof(ObjcCategoryImplDecl)));
|
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
fprintf(stderr, "Total bytes = %d\n",
|
|
|
|
int(nFuncs*sizeof(FunctionDecl)+nBlockVars*sizeof(BlockVarDecl)+
|
|
|
|
nFileVars*sizeof(FileVarDecl)+nParmVars*sizeof(ParmVarDecl)+
|
|
|
|
nFieldDecls*sizeof(FieldDecl)+nSUC*sizeof(RecordDecl)+
|
|
|
|
nEnumDecls*sizeof(EnumDecl)+nEnumConst*sizeof(EnumConstantDecl)+
|
2007-09-17 18:16:13 +04:00
|
|
|
nTypedef*sizeof(TypedefDecl)) /* FIXME: add Objc decls */);
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Decl::addDeclKind(const Kind k) {
|
|
|
|
switch (k) {
|
|
|
|
case Typedef:
|
|
|
|
nTypedef++;
|
|
|
|
break;
|
|
|
|
case Function:
|
|
|
|
nFuncs++;
|
|
|
|
break;
|
|
|
|
case BlockVariable:
|
|
|
|
nBlockVars++;
|
|
|
|
break;
|
|
|
|
case FileVariable:
|
|
|
|
nFileVars++;
|
|
|
|
break;
|
|
|
|
case ParmVariable:
|
|
|
|
nParmVars++;
|
|
|
|
break;
|
|
|
|
case EnumConstant:
|
|
|
|
nEnumConst++;
|
|
|
|
break;
|
|
|
|
case Field:
|
|
|
|
nFieldDecls++;
|
|
|
|
break;
|
|
|
|
case Struct:
|
|
|
|
case Union:
|
|
|
|
case Class:
|
|
|
|
nSUC++;
|
|
|
|
break;
|
|
|
|
case Enum:
|
|
|
|
nEnumDecls++;
|
|
|
|
break;
|
2007-09-07 01:24:23 +04:00
|
|
|
case ObjcInterface:
|
|
|
|
nInterfaceDecls++;
|
|
|
|
break;
|
2007-09-16 23:23:04 +04:00
|
|
|
case ObjcClass:
|
2007-09-17 18:16:13 +04:00
|
|
|
nClassDecls++;
|
|
|
|
break;
|
2007-09-16 23:23:04 +04:00
|
|
|
case ObjcMethod:
|
2007-09-17 18:16:13 +04:00
|
|
|
nMethodDecls++;
|
|
|
|
break;
|
2007-09-16 23:23:04 +04:00
|
|
|
case ObjcProtocol:
|
2007-09-17 18:16:13 +04:00
|
|
|
nProtocolDecls++;
|
|
|
|
break;
|
2007-09-21 19:40:54 +04:00
|
|
|
case ObjcForwardProtocol:
|
|
|
|
nForwardProtocolDecls++;
|
|
|
|
break;
|
2007-09-19 00:26:58 +04:00
|
|
|
case ObjcCategory:
|
|
|
|
nCategoryDecls++;
|
|
|
|
break;
|
2007-09-16 23:23:04 +04:00
|
|
|
case ObjcIvar:
|
2007-09-17 18:16:13 +04:00
|
|
|
nIvarDecls++;
|
2007-09-16 23:23:04 +04:00
|
|
|
break;
|
2007-09-25 22:38:09 +04:00
|
|
|
case ObjcImplementation:
|
|
|
|
nObjcImplementationDecls++;
|
|
|
|
break;
|
2007-10-02 20:38:50 +04:00
|
|
|
case ObjcCategoryImpl:
|
|
|
|
nObjcCategoryImpl++;
|
|
|
|
break;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Out-of-line virtual method providing a home for Decl.
|
|
|
|
Decl::~Decl() {
|
|
|
|
}
|
|
|
|
|
2007-09-14 01:41:19 +04:00
|
|
|
const char *FieldDecl::getName() const {
|
|
|
|
if (const IdentifierInfo *II = getIdentifier())
|
|
|
|
return II->getName();
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *ScopedDecl::getName() const {
|
2007-07-11 21:01:13 +04:00
|
|
|
if (const IdentifierInfo *II = getIdentifier())
|
|
|
|
return II->getName();
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FunctionDecl::~FunctionDecl() {
|
|
|
|
delete[] ParamInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned FunctionDecl::getNumParams() const {
|
|
|
|
return cast<FunctionTypeProto>(getType().getTypePtr())->getNumArgs();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FunctionDecl::setParams(ParmVarDecl **NewParamInfo, unsigned NumParams) {
|
|
|
|
assert(ParamInfo == 0 && "Already has param info!");
|
|
|
|
assert(NumParams == getNumParams() && "Parameter count mismatch!");
|
|
|
|
|
|
|
|
// Zero params -> null pointer.
|
|
|
|
if (NumParams) {
|
|
|
|
ParamInfo = new ParmVarDecl*[NumParams];
|
|
|
|
memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// defineBody - When created, RecordDecl's correspond to a forward declared
|
|
|
|
/// record. This method is used to mark the decl as being defined, with the
|
|
|
|
/// specified contents.
|
|
|
|
void RecordDecl::defineBody(FieldDecl **members, unsigned numMembers) {
|
|
|
|
assert(!isDefinition() && "Cannot redefine record!");
|
|
|
|
setDefinition(true);
|
|
|
|
NumMembers = numMembers;
|
|
|
|
if (numMembers) {
|
|
|
|
Members = new FieldDecl*[numMembers];
|
|
|
|
memcpy(Members, members, numMembers*sizeof(Decl*));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FieldDecl* RecordDecl::getMember(IdentifierInfo *name) {
|
|
|
|
if (Members == 0 || NumMembers < 0)
|
|
|
|
return 0;
|
2007-10-04 04:45:27 +04:00
|
|
|
|
2007-07-11 21:01:13 +04:00
|
|
|
// linear search. When C++ classes come along, will likely need to revisit.
|
|
|
|
for (int i = 0; i < NumMembers; ++i) {
|
|
|
|
if (Members[i]->getIdentifier() == name)
|
|
|
|
return Members[i];
|
|
|
|
}
|
|
|
|
return 0;
|
2007-07-12 19:43:07 +04:00
|
|
|
}
|
2007-09-11 00:33:04 +04:00
|
|
|
|
2007-09-12 22:23:47 +04:00
|
|
|
void ObjcMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo,
|
2007-10-01 20:53:59 +04:00
|
|
|
unsigned NumParams) {
|
2007-09-12 22:23:47 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjcMethodDecl::~ObjcMethodDecl() {
|
|
|
|
delete[] ParamInfo;
|
|
|
|
}
|
|
|
|
|
2007-09-15 01:08:27 +04:00
|
|
|
/// ObjcAddInstanceVariablesToClass - Inserts instance variables
|
|
|
|
/// into ObjcInterfaceDecl's fields.
|
|
|
|
///
|
|
|
|
void ObjcInterfaceDecl::ObjcAddInstanceVariablesToClass(ObjcIvarDecl **ivars,
|
|
|
|
unsigned numIvars) {
|
|
|
|
NumIvars = numIvars;
|
|
|
|
if (numIvars) {
|
|
|
|
Ivars = new ObjcIvarDecl*[numIvars];
|
|
|
|
memcpy(Ivars, ivars, numIvars*sizeof(ObjcIvarDecl*));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-26 22:27:25 +04: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(
|
2007-10-04 04:45:27 +04:00
|
|
|
ObjcIvarDecl **ivars, unsigned numIvars) {
|
2007-09-26 22:27:25 +04:00
|
|
|
NumIvars = numIvars;
|
|
|
|
if (numIvars) {
|
|
|
|
Ivars = new ObjcIvarDecl*[numIvars];
|
|
|
|
memcpy(Ivars, ivars, numIvars*sizeof(ObjcIvarDecl*));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-11 00:33:04 +04:00
|
|
|
/// addObjcMethods - Insert instance and methods declarations into
|
|
|
|
/// ObjcInterfaceDecl's InsMethods and ClsMethods fields.
|
|
|
|
///
|
|
|
|
void ObjcInterfaceDecl::ObjcAddMethods(ObjcMethodDecl **insMethods,
|
|
|
|
unsigned numInsMembers,
|
|
|
|
ObjcMethodDecl **clsMethods,
|
|
|
|
unsigned numClsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
NumInstanceMethods = numInsMembers;
|
2007-09-11 00:33:04 +04:00
|
|
|
if (numInsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
InstanceMethods = new ObjcMethodDecl*[numInsMembers];
|
|
|
|
memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*));
|
2007-09-11 00:33:04 +04:00
|
|
|
}
|
2007-10-03 02:05:16 +04:00
|
|
|
NumClassMethods = numClsMembers;
|
2007-09-11 00:33:04 +04:00
|
|
|
if (numClsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
ClassMethods = new ObjcMethodDecl*[numClsMembers];
|
|
|
|
memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
|
2007-09-11 00:33:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-18 01:07:36 +04:00
|
|
|
/// ObjcAddProtoMethods - Insert instance and methods declarations into
|
|
|
|
/// ObjcProtocolDecl's ProtoInsMethods and ProtoClsMethods fields.
|
|
|
|
///
|
|
|
|
void ObjcProtocolDecl::ObjcAddProtoMethods(ObjcMethodDecl **insMethods,
|
|
|
|
unsigned numInsMembers,
|
|
|
|
ObjcMethodDecl **clsMethods,
|
|
|
|
unsigned numClsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
NumInstanceMethods = numInsMembers;
|
2007-09-18 01:07:36 +04:00
|
|
|
if (numInsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
InstanceMethods = new ObjcMethodDecl*[numInsMembers];
|
|
|
|
memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*));
|
2007-09-18 01:07:36 +04:00
|
|
|
}
|
2007-10-03 02:05:16 +04:00
|
|
|
NumClassMethods = numClsMembers;
|
2007-09-18 01:07:36 +04:00
|
|
|
if (numClsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
ClassMethods = new ObjcMethodDecl*[numClsMembers];
|
|
|
|
memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
|
2007-09-18 01:07:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-19 00:26:58 +04:00
|
|
|
/// ObjcAddCat - Insert instance and methods declarations into
|
2007-10-02 20:38:50 +04:00
|
|
|
/// ObjcCategoryDecl's CatInsMethods and CatClsMethods fields.
|
2007-09-19 00:26:58 +04:00
|
|
|
///
|
|
|
|
void ObjcCategoryDecl::ObjcAddCatMethods(ObjcMethodDecl **insMethods,
|
|
|
|
unsigned numInsMembers,
|
|
|
|
ObjcMethodDecl **clsMethods,
|
|
|
|
unsigned numClsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
NumInstanceMethods = numInsMembers;
|
2007-09-19 00:26:58 +04:00
|
|
|
if (numInsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
InstanceMethods = new ObjcMethodDecl*[numInsMembers];
|
|
|
|
memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*));
|
2007-10-02 20:38:50 +04:00
|
|
|
}
|
2007-10-03 02:05:16 +04:00
|
|
|
NumClassMethods = numClsMembers;
|
2007-10-02 20:38:50 +04:00
|
|
|
if (numClsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
ClassMethods = new ObjcMethodDecl*[numClsMembers];
|
|
|
|
memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
|
2007-10-02 20:38:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ObjcAddCatImplMethods - Insert instance and methods declarations into
|
|
|
|
/// ObjcCategoryImplDecl's CatInsMethods and CatClsMethods fields.
|
|
|
|
///
|
|
|
|
void ObjcCategoryImplDecl::ObjcAddCatImplMethods(ObjcMethodDecl **insMethods,
|
|
|
|
unsigned numInsMembers,
|
|
|
|
ObjcMethodDecl **clsMethods,
|
|
|
|
unsigned numClsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
NumInstanceMethods = numInsMembers;
|
2007-10-02 20:38:50 +04:00
|
|
|
if (numInsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
InstanceMethods = new ObjcMethodDecl*[numInsMembers];
|
|
|
|
memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*));
|
2007-09-19 00:26:58 +04:00
|
|
|
}
|
2007-10-03 02:05:16 +04:00
|
|
|
NumClassMethods = numClsMembers;
|
2007-09-19 00:26:58 +04:00
|
|
|
if (numClsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
ClassMethods = new ObjcMethodDecl*[numClsMembers];
|
|
|
|
memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
|
2007-09-19 00:26:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-27 22:57:03 +04:00
|
|
|
/// ObjcAddImplMethods - Insert instance and methods declarations into
|
|
|
|
/// ObjcImplementationDecl's InsMethods and ClsMethods fields.
|
|
|
|
///
|
|
|
|
void ObjcImplementationDecl::ObjcAddImplMethods(ObjcMethodDecl **insMethods,
|
|
|
|
unsigned numInsMembers,
|
|
|
|
ObjcMethodDecl **clsMethods,
|
|
|
|
unsigned numClsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
NumInstanceMethods = numInsMembers;
|
2007-09-27 22:57:03 +04:00
|
|
|
if (numInsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
InstanceMethods = new ObjcMethodDecl*[numInsMembers];
|
|
|
|
memcpy(InstanceMethods, insMethods, numInsMembers*sizeof(ObjcMethodDecl*));
|
2007-09-27 22:57:03 +04:00
|
|
|
}
|
2007-10-03 02:05:16 +04:00
|
|
|
NumClassMethods = numClsMembers;
|
2007-09-27 22:57:03 +04:00
|
|
|
if (numClsMembers) {
|
2007-10-03 02:05:16 +04:00
|
|
|
ClassMethods = new ObjcMethodDecl*[numClsMembers];
|
|
|
|
memcpy(ClassMethods, clsMethods, numClsMembers*sizeof(ObjcMethodDecl*));
|
2007-09-27 22:57:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-03 00:01:56 +04:00
|
|
|
// FIXME: look through categories...
|
|
|
|
ObjcMethodDecl *ObjcInterfaceDecl::lookupInstanceMethod(Selector &Sel) {
|
|
|
|
ObjcInterfaceDecl* ClassDecl = this;
|
|
|
|
while (ClassDecl != NULL) {
|
2007-10-03 02:05:16 +04:00
|
|
|
ObjcMethodDecl **methods = ClassDecl->getInstanceMethods();
|
|
|
|
int methodCount = ClassDecl->getNumInstanceMethods();
|
2007-10-03 00:01:56 +04:00
|
|
|
for (int i = 0; i < methodCount; ++i) {
|
|
|
|
if (methods[i]->getSelector() == Sel) {
|
|
|
|
return methods[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ClassDecl = ClassDecl->getSuperClass();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: look through categories...
|
|
|
|
ObjcMethodDecl *ObjcInterfaceDecl::lookupClassMethod(Selector &Sel) {
|
|
|
|
ObjcInterfaceDecl* ClassDecl = this;
|
|
|
|
while (ClassDecl != NULL) {
|
2007-10-03 02:05:16 +04:00
|
|
|
ObjcMethodDecl **methods = ClassDecl->getClassMethods();
|
|
|
|
int methodCount = ClassDecl->getNumClassMethods();
|
2007-10-03 00:01:56 +04:00
|
|
|
for (int i = 0; i < methodCount; ++i) {
|
|
|
|
if (methods[i]->getSelector() == Sel) {
|
|
|
|
return methods[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ClassDecl = ClassDecl->getSuperClass();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-09-18 01:07:36 +04:00
|
|
|
|