From c858105d41602a2dadb2efbc1af80a7b791ebac3 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sun, 16 Mar 2008 20:19:15 +0000 Subject: [PATCH] minor cleanups, make getNumInstanceMethods always return unsigned. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48423 91177308-0d34-0410-b5e6-96231b3b80d8 --- Driver/RewriteTest.cpp | 12 +++++------- include/clang/AST/DeclObjC.h | 18 ++++++++---------- lib/AST/DeclObjC.cpp | 5 ++--- lib/Parse/ParseObjc.cpp | 3 +-- lib/Sema/SemaDeclObjC.cpp | 14 +++++++------- 5 files changed, 23 insertions(+), 29 deletions(-) diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index d72aaf282b..7bdec9390a 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -2348,9 +2348,7 @@ void RewriteTest::RewriteObjCProtocolsMetaData(ObjCProtocolDecl **Protocols, 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; @@ -2363,8 +2361,8 @@ void RewriteTest::RewriteObjCProtocolsMetaData(ObjCProtocolDecl **Protocols, 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[]; @@ -2397,7 +2395,7 @@ void RewriteTest::RewriteObjCProtocolsMetaData(ObjCProtocolDecl **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; @@ -2460,7 +2458,7 @@ void RewriteTest::RewriteObjCProtocolsMetaData(ObjCProtocolDecl **Protocols, "{\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 += ", "; diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 3ee0b9532a..bfa21046dc 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -429,19 +429,17 @@ class ObjCProtocolDecl : public NamedDecl { 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) { @@ -464,7 +462,7 @@ public: 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; @@ -616,7 +614,7 @@ class ObjCCategoryDecl : public NamedDecl { /// 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 @@ -631,7 +629,7 @@ public: 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) { @@ -654,13 +652,13 @@ public: 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; diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 17b1d28cad..62336b67bd 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -49,10 +49,9 @@ ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, SourceLocation L, ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, SourceLocation L, unsigned numRefProtos, - IdentifierInfo *Id, - bool ForwardDecl) { + IdentifierInfo *Id) { void *Mem = C.getAllocator().Allocate(); - return new (Mem) ObjCProtocolDecl(L, numRefProtos, Id, ForwardDecl); + return new (Mem) ObjCProtocolDecl(L, numRefProtos, Id); } diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 77d2adbd32..7345abed99 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -847,7 +847,6 @@ void Parser::ParseObjCClassInstanceVariables(DeclTy *interfaceDecl, /// "@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"); @@ -887,7 +886,7 @@ Parser::DeclTy *Parser::ParseObjCAtProtocolDeclaration(SourceLocation AtLoc) { 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()); diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 3b8baea519..28a92c7ba2 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -214,12 +214,13 @@ Sema::DeclTy *Sema::ActOnStartProtocolInterface( 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()) @@ -258,12 +259,11 @@ Sema::ActOnForwardProtocolDeclaration(SourceLocation AtProtocolLoc, llvm::SmallVector 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); -- 2.40.0