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-10-07 12:58:51 +04:00
|
|
|
#include "clang/Basic/IdentifierTable.h"
|
2007-07-11 21:01:13 +04:00
|
|
|
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-10-12 03:42:27 +04:00
|
|
|
static unsigned nObjcCompatibleAlias = 0;
|
2007-11-07 01:01:00 +03:00
|
|
|
static unsigned nObjcPropertyDecl = 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";
|
2007-10-09 01:37:32 +04:00
|
|
|
case BlockVar:
|
|
|
|
return "BlockVar";
|
|
|
|
case FileVar:
|
|
|
|
return "FileVar";
|
|
|
|
case ParmVar:
|
|
|
|
return "ParmVar";
|
2007-09-16 20:16:00 +04:00
|
|
|
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-10-12 03:42:27 +04:00
|
|
|
fprintf(stderr, " %d compatibility alias decls, %d each (%d bytes)\n",
|
|
|
|
nObjcCompatibleAlias, (int)sizeof(ObjcCompatibleAliasDecl),
|
|
|
|
int(nObjcCompatibleAlias*sizeof(ObjcCompatibleAliasDecl)));
|
|
|
|
|
2007-11-07 01:01:00 +03:00
|
|
|
fprintf(stderr, " %d property decls, %d each (%d bytes)\n",
|
|
|
|
nObjcPropertyDecl, (int)sizeof(ObjcPropertyDecl),
|
|
|
|
int(nObjcPropertyDecl*sizeof(ObjcPropertyDecl)));
|
|
|
|
|
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;
|
2007-10-09 01:37:32 +04:00
|
|
|
case BlockVar:
|
2007-07-11 21:01:13 +04:00
|
|
|
nBlockVars++;
|
|
|
|
break;
|
2007-10-09 01:37:32 +04:00
|
|
|
case FileVar:
|
2007-07-11 21:01:13 +04:00
|
|
|
nFileVars++;
|
|
|
|
break;
|
2007-10-09 01:37:32 +04:00
|
|
|
case ParmVar:
|
2007-07-11 21:01:13 +04:00
|
|
|
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-10-12 03:42:27 +04:00
|
|
|
case CompatibleAlias:
|
|
|
|
nObjcCompatibleAlias++;
|
|
|
|
break;
|
2007-11-07 01:01:00 +03:00
|
|
|
case PropertyDecl:
|
|
|
|
nObjcPropertyDecl++;
|
|
|
|
break;
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Out-of-line virtual method providing a home for Decl.
|
|
|
|
Decl::~Decl() {
|
|
|
|
}
|
|
|
|
|
2007-10-07 02:53:46 +04:00
|
|
|
const char *NamedDecl::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 {
|
2007-12-06 20:20:20 +03:00
|
|
|
if (isa<FunctionTypeNoProto>(getCanonicalType())) return 0;
|
|
|
|
return cast<FunctionTypeProto>(getCanonicalType())->getNumArgs();
|
2007-07-11 21:01:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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-10-04 21:06:28 +04:00
|
|
|
void ObjcMethodDecl::setMethodParams(ParmVarDecl **NewParamInfo,
|
|
|
|
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.
|
|
|
|
///
|
2007-10-30 00:38:07 +03:00
|
|
|
void ObjcInterfaceDecl::addInstanceVariablesToClass(ObjcIvarDecl **ivars,
|
|
|
|
unsigned numIvars,
|
2007-10-30 05:23:23 +03:00
|
|
|
SourceLocation RBrac) {
|
2007-09-15 01:08:27 +04:00
|
|
|
NumIvars = numIvars;
|
|
|
|
if (numIvars) {
|
|
|
|
Ivars = new ObjcIvarDecl*[numIvars];
|
|
|
|
memcpy(Ivars, ivars, numIvars*sizeof(ObjcIvarDecl*));
|
|
|
|
}
|
2007-10-30 05:23:23 +03:00
|
|
|
setLocEnd(RBrac);
|
2007-09-15 01:08:27 +04:00
|
|
|
}
|
|
|
|
|
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 21:06:28 +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-10-30 00:38:07 +03:00
|
|
|
/// addMethods - Insert instance and methods declarations into
|
2007-09-11 00:33:04 +04:00
|
|
|
/// ObjcInterfaceDecl's InsMethods and ClsMethods fields.
|
|
|
|
///
|
2007-10-30 00:38:07 +03:00
|
|
|
void ObjcInterfaceDecl::addMethods(ObjcMethodDecl **insMethods,
|
|
|
|
unsigned numInsMembers,
|
|
|
|
ObjcMethodDecl **clsMethods,
|
|
|
|
unsigned numClsMembers,
|
|
|
|
SourceLocation endLoc) {
|
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-10-30 05:23:23 +03:00
|
|
|
AtEndLoc = endLoc;
|
2007-09-11 00:33:04 +04:00
|
|
|
}
|
|
|
|
|
2007-10-30 00:38:07 +03:00
|
|
|
/// addMethods - Insert instance and methods declarations into
|
2007-09-18 01:07:36 +04:00
|
|
|
/// ObjcProtocolDecl's ProtoInsMethods and ProtoClsMethods fields.
|
|
|
|
///
|
2007-10-30 00:38:07 +03:00
|
|
|
void ObjcProtocolDecl::addMethods(ObjcMethodDecl **insMethods,
|
|
|
|
unsigned numInsMembers,
|
|
|
|
ObjcMethodDecl **clsMethods,
|
|
|
|
unsigned numClsMembers,
|
2007-10-30 16:30:57 +03:00
|
|
|
SourceLocation endLoc) {
|
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-10-30 16:30:57 +03:00
|
|
|
AtEndLoc = endLoc;
|
2007-09-18 01:07:36 +04:00
|
|
|
}
|
|
|
|
|
2007-10-30 00:38:07 +03:00
|
|
|
/// addMethods - 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
|
|
|
///
|
2007-10-30 00:38:07 +03:00
|
|
|
void ObjcCategoryDecl::addMethods(ObjcMethodDecl **insMethods,
|
|
|
|
unsigned numInsMembers,
|
|
|
|
ObjcMethodDecl **clsMethods,
|
|
|
|
unsigned numClsMembers,
|
2007-10-30 16:30:57 +03:00
|
|
|
SourceLocation endLoc) {
|
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
|
|
|
}
|
2007-10-30 16:30:57 +03:00
|
|
|
AtEndLoc = endLoc;
|
2007-10-02 20:38:50 +04:00
|
|
|
}
|
|
|
|
|
2007-11-12 16:56:41 +03:00
|
|
|
ObjcIvarDecl *ObjcInterfaceDecl::lookupInstanceVariable(
|
|
|
|
IdentifierInfo *ID, ObjcInterfaceDecl *&clsDeclared) {
|
|
|
|
ObjcInterfaceDecl* ClassDecl = this;
|
|
|
|
while (ClassDecl != NULL) {
|
2007-12-12 10:56:42 +03:00
|
|
|
for (ivar_iterator I = ClassDecl->ivar_begin(), E = ClassDecl->ivar_end();
|
|
|
|
I != E; ++I) {
|
|
|
|
if ((*I)->getIdentifier() == ID) {
|
2007-11-12 16:56:41 +03:00
|
|
|
clsDeclared = ClassDecl;
|
2007-12-12 10:56:42 +03:00
|
|
|
return *I;
|
2007-11-12 16:56:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ClassDecl = ClassDecl->getSuperClass();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-12 10:30:05 +03:00
|
|
|
/// lookupInstanceMethod - This method returns an instance method by looking in
|
2007-12-12 11:17:45 +03:00
|
|
|
/// the class, its categories, and its super classes (using a linear search).
|
2007-12-20 01:27:04 +03:00
|
|
|
ObjcMethodDecl *ObjcInterfaceDecl::lookupInstanceMethod(Selector Sel) {
|
2007-10-03 00:01:56 +04:00
|
|
|
ObjcInterfaceDecl* ClassDecl = this;
|
2007-12-15 02:37:57 +03:00
|
|
|
ObjcMethodDecl *MethodDecl = 0;
|
|
|
|
|
2007-10-03 00:01:56 +04:00
|
|
|
while (ClassDecl != NULL) {
|
2007-12-20 01:27:04 +03:00
|
|
|
if ((MethodDecl = ClassDecl->getInstanceMethod(Sel)))
|
2007-12-15 02:37:57 +03:00
|
|
|
return MethodDecl;
|
|
|
|
|
2007-10-15 03:13:51 +04:00
|
|
|
// Didn't find one yet - look through protocols.
|
|
|
|
ObjcProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
|
|
|
|
int numProtocols = ClassDecl->getNumIntfRefProtocols();
|
|
|
|
for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
|
2007-12-20 01:27:04 +03:00
|
|
|
if ((MethodDecl = protocols[pIdx]->getInstanceMethod(Sel)))
|
2007-12-15 02:37:57 +03:00
|
|
|
return MethodDecl;
|
2007-10-15 03:13:51 +04:00
|
|
|
}
|
2007-10-14 22:27:41 +04:00
|
|
|
// Didn't find one yet - now look through categories.
|
2007-10-15 03:13:51 +04:00
|
|
|
ObjcCategoryDecl *CatDecl = ClassDecl->getCategoryList();
|
2007-10-14 22:27:41 +04:00
|
|
|
while (CatDecl) {
|
2007-12-20 01:27:04 +03:00
|
|
|
if ((MethodDecl = CatDecl->getInstanceMethod(Sel)))
|
2007-12-15 02:37:57 +03:00
|
|
|
return MethodDecl;
|
2007-10-14 22:27:41 +04:00
|
|
|
CatDecl = CatDecl->getNextClassCategory();
|
|
|
|
}
|
2007-10-03 00:01:56 +04:00
|
|
|
ClassDecl = ClassDecl->getSuperClass();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-10-14 22:27:41 +04:00
|
|
|
// lookupClassMethod - This method returns a class method by looking in the
|
2007-12-12 11:17:45 +03:00
|
|
|
// class, its categories, and its super classes (using a linear search).
|
2007-12-20 01:27:04 +03:00
|
|
|
ObjcMethodDecl *ObjcInterfaceDecl::lookupClassMethod(Selector Sel) {
|
2007-10-03 00:01:56 +04:00
|
|
|
ObjcInterfaceDecl* ClassDecl = this;
|
2007-12-15 02:37:57 +03:00
|
|
|
ObjcMethodDecl *MethodDecl = 0;
|
|
|
|
|
2007-10-03 00:01:56 +04:00
|
|
|
while (ClassDecl != NULL) {
|
2007-12-20 01:27:04 +03:00
|
|
|
if ((MethodDecl = ClassDecl->getClassMethod(Sel)))
|
2007-12-15 02:37:57 +03:00
|
|
|
return MethodDecl;
|
|
|
|
|
2007-10-15 03:13:51 +04:00
|
|
|
// Didn't find one yet - look through protocols.
|
|
|
|
ObjcProtocolDecl **protocols = ClassDecl->getReferencedProtocols();
|
|
|
|
int numProtocols = ClassDecl->getNumIntfRefProtocols();
|
|
|
|
for (int pIdx = 0; pIdx < numProtocols; pIdx++) {
|
2007-12-20 01:27:04 +03:00
|
|
|
if ((MethodDecl = protocols[pIdx]->getClassMethod(Sel)))
|
2007-12-15 02:37:57 +03:00
|
|
|
return MethodDecl;
|
2007-10-15 03:13:51 +04:00
|
|
|
}
|
2007-10-14 22:27:41 +04:00
|
|
|
// Didn't find one yet - now look through categories.
|
2007-10-15 03:13:51 +04:00
|
|
|
ObjcCategoryDecl *CatDecl = ClassDecl->getCategoryList();
|
2007-10-14 22:27:41 +04:00
|
|
|
while (CatDecl) {
|
2007-12-20 01:27:04 +03:00
|
|
|
if ((MethodDecl = CatDecl->getClassMethod(Sel)))
|
2007-12-15 02:37:57 +03:00
|
|
|
return MethodDecl;
|
2007-10-14 22:27:41 +04:00
|
|
|
CatDecl = CatDecl->getNextClassCategory();
|
|
|
|
}
|
2007-10-03 00:01:56 +04:00
|
|
|
ClassDecl = ClassDecl->getSuperClass();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-12 10:30:05 +03:00
|
|
|
/// lookupInstanceMethod - This method returns an instance method by looking in
|
|
|
|
/// the class implementation. Unlike interfaces, we don't look outside the
|
|
|
|
/// implementation.
|
2007-12-20 01:27:04 +03:00
|
|
|
ObjcMethodDecl *ObjcImplementationDecl::getInstanceMethod(Selector Sel) {
|
2007-12-12 10:30:05 +03:00
|
|
|
for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
|
|
|
|
if ((*I)->getSelector() == Sel)
|
|
|
|
return *I;
|
2007-11-11 03:10:47 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-12 10:30:05 +03:00
|
|
|
/// lookupClassMethod - This method returns a class method by looking in
|
|
|
|
/// the class implementation. Unlike interfaces, we don't look outside the
|
|
|
|
/// implementation.
|
2007-12-20 01:27:04 +03:00
|
|
|
ObjcMethodDecl *ObjcImplementationDecl::getClassMethod(Selector Sel) {
|
2007-12-12 10:46:12 +03:00
|
|
|
for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
|
|
|
|
I != E; ++I)
|
|
|
|
if ((*I)->getSelector() == Sel)
|
|
|
|
return *I;
|
2007-11-11 03:10:47 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-09-18 01:07:36 +04:00
|
|
|
|
2007-11-13 01:05:31 +03:00
|
|
|
// lookupInstanceMethod - This method returns an instance method by looking in
|
|
|
|
// the class implementation. Unlike interfaces, we don't look outside the
|
|
|
|
// implementation.
|
2007-12-20 01:27:04 +03:00
|
|
|
ObjcMethodDecl *ObjcCategoryImplDecl::getInstanceMethod(Selector Sel) {
|
2007-12-12 10:46:12 +03:00
|
|
|
for (instmeth_iterator I = instmeth_begin(), E = instmeth_end(); I != E; ++I)
|
|
|
|
if ((*I)->getSelector() == Sel)
|
|
|
|
return *I;
|
2007-11-13 01:05:31 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// lookupClassMethod - This method returns an instance method by looking in
|
|
|
|
// the class implementation. Unlike interfaces, we don't look outside the
|
|
|
|
// implementation.
|
2007-12-20 01:27:04 +03:00
|
|
|
ObjcMethodDecl *ObjcCategoryImplDecl::getClassMethod(Selector Sel) {
|
2007-12-12 10:46:12 +03:00
|
|
|
for (classmeth_iterator I = classmeth_begin(), E = classmeth_end();
|
|
|
|
I != E; ++I)
|
|
|
|
if ((*I)->getSelector() == Sel)
|
|
|
|
return *I;
|
2007-11-13 01:05:31 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2007-12-08 00:21:21 +03:00
|
|
|
|
|
|
|
// lookupInstanceMethod - Lookup a instance method in the protocol and protocols
|
|
|
|
// it inherited.
|
2007-12-20 01:27:04 +03:00
|
|
|
ObjcMethodDecl *ObjcProtocolDecl::lookupInstanceMethod(Selector Sel) {
|
2007-12-15 02:37:57 +03:00
|
|
|
ObjcMethodDecl *MethodDecl = NULL;
|
|
|
|
|
2007-12-20 01:27:04 +03:00
|
|
|
if ((MethodDecl = getInstanceMethod(Sel)))
|
2007-12-15 02:37:57 +03:00
|
|
|
return MethodDecl;
|
|
|
|
|
2007-12-08 00:21:21 +03:00
|
|
|
if (getNumReferencedProtocols() > 0) {
|
|
|
|
ObjcProtocolDecl **RefPDecl = getReferencedProtocols();
|
|
|
|
|
|
|
|
for (int i = 0; i < getNumReferencedProtocols(); i++) {
|
2007-12-20 01:27:04 +03:00
|
|
|
if ((MethodDecl = RefPDecl[i]->getInstanceMethod(Sel)))
|
2007-12-15 02:37:57 +03:00
|
|
|
return MethodDecl;
|
2007-12-08 00:21:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// lookupInstanceMethod - Lookup a class method in the protocol and protocols
|
|
|
|
// it inherited.
|
2007-12-20 01:27:04 +03:00
|
|
|
ObjcMethodDecl *ObjcProtocolDecl::lookupClassMethod(Selector Sel) {
|
2007-12-15 02:37:57 +03:00
|
|
|
ObjcMethodDecl *MethodDecl = NULL;
|
|
|
|
|
2007-12-20 01:27:04 +03:00
|
|
|
if ((MethodDecl = getClassMethod(Sel)))
|
2007-12-15 02:37:57 +03:00
|
|
|
return MethodDecl;
|
|
|
|
|
2007-12-08 00:21:21 +03:00
|
|
|
if (getNumReferencedProtocols() > 0) {
|
|
|
|
ObjcProtocolDecl **RefPDecl = getReferencedProtocols();
|
|
|
|
|
|
|
|
for (int i = 0; i < getNumReferencedProtocols(); i++) {
|
2007-12-20 01:27:04 +03:00
|
|
|
if ((MethodDecl = RefPDecl[i]->getClassMethod(Sel)))
|
2007-12-15 02:37:57 +03:00
|
|
|
return MethodDecl;
|
2007-12-08 00:21:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-12-15 02:37:57 +03:00
|
|
|
|
|
|
|
ObjcInterfaceDecl *const ObjcMethodDecl::getClassInterface() const {
|
|
|
|
if (ObjcInterfaceDecl *ID = dyn_cast<ObjcInterfaceDecl>(MethodContext))
|
|
|
|
return ID;
|
|
|
|
if (ObjcCategoryDecl *CD = dyn_cast<ObjcCategoryDecl>(MethodContext))
|
|
|
|
return CD->getClassInterface();
|
|
|
|
if (ObjcImplementationDecl *IMD =
|
|
|
|
dyn_cast<ObjcImplementationDecl>(MethodContext))
|
|
|
|
return IMD->getClassInterface();
|
|
|
|
if (ObjcCategoryImplDecl *CID =
|
|
|
|
dyn_cast<ObjcCategoryImplDecl>(MethodContext))
|
|
|
|
return CID->getClassInterface();
|
|
|
|
assert(false && "unknown method context");
|
|
|
|
return 0;
|
|
|
|
}
|