for (int i = 0; i < NumProtocols; i++) {
ObjCProtocolDecl *PDecl = Protocols[i];
// Output struct protocol_methods holder of method selector and type.
- if (!objc_protocol_methods &&
- (PDecl->getNumInstanceMethods() > 0
- || PDecl->getNumClassMethods() > 0)) {
+ if (!objc_protocol_methods && !PDecl->isForwardDecl()) {
/* struct protocol_methods {
SEL _cmd;
char *method_types;
objc_protocol_methods = true;
}
- int NumMethods = PDecl->getNumInstanceMethods();
- if(NumMethods > 0) {
+ if (PDecl->instmeth_begin() != PDecl->instmeth_end()) {
+ unsigned NumMethods = PDecl->getNumInstanceMethods();
/* struct _objc_protocol_method_list {
int protocol_method_count;
struct protocol_methods protocols[];
}
// Output class methods declared in this protocol.
- NumMethods = PDecl->getNumClassMethods();
+ int NumMethods = PDecl->getNumClassMethods();
if (NumMethods > 0) {
/* struct _objc_protocol_method_list {
int protocol_method_count;
"{\n\t0, \"";
Result += PDecl->getName();
Result += "\", 0, ";
- if (PDecl->getNumInstanceMethods() > 0) {
+ if (PDecl->instmeth_begin() != PDecl->instmeth_end()) {
Result += "(struct _objc_protocol_method_list *)&_OBJC_PROTOCOL_INSTANCE_METHODS_";
Result += PDecl->getName();
Result += ", ";
SourceLocation EndLoc; // marks the '>' or identifier.
SourceLocation AtEndLoc; // marks the end of the entire interface.
- ObjCProtocolDecl(SourceLocation L, unsigned numRefProtos,
- IdentifierInfo *Id, bool FD)
+ ObjCProtocolDecl(SourceLocation L, unsigned numRefProtos, IdentifierInfo *Id)
: NamedDecl(ObjCProtocol, L, Id),
ReferencedProtocols(0), NumReferencedProtocols(0),
InstanceMethods(0), NumInstanceMethods(-1),
ClassMethods(0), NumClassMethods(-1),
- isForwardProtoDecl(FD) {
+ isForwardProtoDecl(true) {
AllocReferencedProtocols(numRefProtos);
}
public:
static ObjCProtocolDecl *Create(ASTContext &C, SourceLocation L,
- unsigned numRefProtos, IdentifierInfo *Id,
- bool ForwardDecl = false);
+ unsigned numRefProtos, IdentifierInfo *Id);
void AllocReferencedProtocols(unsigned numRefProtos) {
if (numRefProtos) {
return ReferencedProtocols;
}
unsigned getNumReferencedProtocols() const { return NumReferencedProtocols; }
- int getNumInstanceMethods() const { return NumInstanceMethods; }
+ unsigned getNumInstanceMethods() const { return NumInstanceMethods; }
int getNumClassMethods() const { return NumClassMethods; }
typedef ObjCMethodDecl * const * instmeth_iterator;
/// category instance methods
ObjCMethodDecl **InstanceMethods; // Null if not defined
- int NumInstanceMethods; // -1 if not defined
+ unsigned NumInstanceMethods; // 0 if none
/// category class methods
ObjCMethodDecl **ClassMethods; // Null if not defined
ObjCCategoryDecl(SourceLocation L, unsigned numRefProtocol,IdentifierInfo *Id)
: NamedDecl(ObjCCategory, L, Id),
ClassInterface(0), ReferencedProtocols(0), NumReferencedProtocols(0),
- InstanceMethods(0), NumInstanceMethods(-1),
+ InstanceMethods(0), NumInstanceMethods(0),
ClassMethods(0), NumClassMethods(-1),
NextClassCategory(0) {
if (numRefProtocol) {
return ReferencedProtocols;
}
unsigned getNumReferencedProtocols() const { return NumReferencedProtocols; }
- int getNumInstanceMethods() const { return NumInstanceMethods; }
+ unsigned getNumInstanceMethods() const { return NumInstanceMethods; }
int getNumClassMethods() const { return NumClassMethods; }
typedef ObjCMethodDecl * const * instmeth_iterator;
instmeth_iterator instmeth_begin() const { return InstanceMethods; }
instmeth_iterator instmeth_end() const {
- return InstanceMethods+(NumInstanceMethods == -1 ? 0 : NumInstanceMethods);
+ return InstanceMethods+NumInstanceMethods;
}
typedef ObjCMethodDecl * const * classmeth_iterator;
ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, SourceLocation L,
unsigned numRefProtos,
- IdentifierInfo *Id,
- bool ForwardDecl) {
+ IdentifierInfo *Id) {
void *Mem = C.getAllocator().Allocate<ObjCProtocolDecl>();
- return new (Mem) ObjCProtocolDecl(L, numRefProtos, Id, ForwardDecl);
+ return new (Mem) ObjCProtocolDecl(L, numRefProtos, Id);
}
/// "@protocol identifier ;" should be resolved as "@protocol
/// identifier-list ;": objc-interface-decl-list may not start with a
/// semicolon in the first alternative if objc-protocol-refs are omitted.
-
Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) {
assert(Tok.isObjCAtKeyword(tok::objc_protocol) &&
"ParseObjCAtProtocolDeclaration(): Expected @protocol");
if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@protocol"))
return 0;
}
- if (ProtocolRefs.size() > 0)
+ if (!ProtocolRefs.empty())
return Actions.ActOnForwardProtocolDeclaration(AtLoc,
&ProtocolRefs[0],
ProtocolRefs.size());
PDecl->AllocReferencedProtocols(NumProtoRefs);
} else {
PDecl = ObjCProtocolDecl::Create(Context, AtProtoInterfaceLoc, NumProtoRefs,
- ProtocolName, false);
+ ProtocolName);
+ PDecl->setForwardDecl(false);
ObjCProtocols[ProtocolName] = PDecl;
}
if (NumProtoRefs) {
- /// Check then save referenced protocols
+ /// Check then save referenced protocols.
for (unsigned int i = 0; i != NumProtoRefs; i++) {
ObjCProtocolDecl* RefPDecl = ObjCProtocols[ProtoRefNames[i]];
if (!RefPDecl || RefPDecl->isForwardDecl())
llvm::SmallVector<ObjCProtocolDecl*, 32> Protocols;
for (unsigned i = 0; i != NumElts; ++i) {
- IdentifierInfo *P = IdentList[i];
- ObjCProtocolDecl *PDecl = ObjCProtocols[P];
- if (!PDecl) { // Not already seen?
+ IdentifierInfo *Ident = IdentList[i];
+ ObjCProtocolDecl *&PDecl = ObjCProtocols[Ident];
+ if (PDecl == 0) { // Not already seen?
// FIXME: Pass in the location of the identifier!
- PDecl = ObjCProtocolDecl::Create(Context, AtProtocolLoc, 0, P, true);
- ObjCProtocols[P] = PDecl;
+ PDecl = ObjCProtocolDecl::Create(Context, AtProtocolLoc, 0, Ident);
}
Protocols.push_back(PDecl);