From: Chris Lattner Date: Sun, 16 Mar 2008 21:08:55 +0000 (+0000) Subject: Convert more counts to be zero based instead of -1 based, make them unsigned. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f3a7af901231535191d14cb524d58f22907ac4d2;p=clang Convert more counts to be zero based instead of -1 based, make them unsigned. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48429 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Driver/ASTConsumers.cpp b/Driver/ASTConsumers.cpp index dcbe6796c0..0dc6692945 100644 --- a/Driver/ASTConsumers.cpp +++ b/Driver/ASTConsumers.cpp @@ -247,7 +247,7 @@ void DeclPrinter::PrintObjCInterfaceDecl(ObjCInterfaceDecl *OID) { else Out << '\n'; - if (OID->getNumInstanceVariables() > 0) { + if (OID->ivar_size() > 0) { Out << '{'; for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(), E = OID->ivar_end(); I != E; ++I) { diff --git a/Driver/RewriteTest.cpp b/Driver/RewriteTest.cpp index 7bdec9390a..2b88c0c8f3 100644 --- a/Driver/RewriteTest.cpp +++ b/Driver/RewriteTest.cpp @@ -2178,7 +2178,7 @@ void RewriteTest::SynthesizeObjCInternalStruct(ObjCInterfaceDecl *CDecl, if (ObjCSynthesizedStructs.count(CDecl)) return; ObjCInterfaceDecl *RCDecl = CDecl->getSuperClass(); - int NumIvars = CDecl->getNumInstanceVariables(); + int NumIvars = CDecl->ivar_size(); SourceLocation LocStart = CDecl->getLocStart(); SourceLocation LocEnd = CDecl->getLocEnd(); @@ -2186,7 +2186,8 @@ void RewriteTest::SynthesizeObjCInternalStruct(ObjCInterfaceDecl *CDecl, const char *endBuf = SM->getCharacterData(LocEnd); // If no ivars and no root or if its root, directly or indirectly, // have no ivars (thus not synthesized) then no need to synthesize this class. - if (NumIvars <= 0 && (!RCDecl || !ObjCSynthesizedStructs.count(RCDecl))) { + if ((CDecl->isForwardDecl() || NumIvars == 0) && + (!RCDecl || !ObjCSynthesizedStructs.count(RCDecl))) { endBuf += Lexer::MeasureTokenLength(LocEnd, *SM); ReplaceText(LocStart, endBuf-startBuf, Result.c_str(), Result.size()); return; @@ -2634,9 +2635,9 @@ void RewriteTest::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, } // Build _objc_ivar_list metadata for classes ivars if needed - int NumIvars = IDecl->getImplDeclNumIvars() > 0 - ? IDecl->getImplDeclNumIvars() - : (CDecl ? CDecl->getNumInstanceVariables() : 0); + unsigned NumIvars = !IDecl->ivar_empty() + ? IDecl->ivar_size() + : (CDecl ? CDecl->ivar_size() : 0); if (NumIvars > 0) { static bool objc_ivar = false; if (!objc_ivar) { @@ -2672,7 +2673,7 @@ void RewriteTest::RewriteObjCClassMetaData(ObjCImplementationDecl *IDecl, Result += "\n"; ObjCInterfaceDecl::ivar_iterator IVI, IVE; - if (IDecl->getImplDeclNumIvars() > 0) { + if (!IDecl->ivar_empty()) { IVI = IDecl->ivar_begin(); IVE = IDecl->ivar_end(); } else { diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h index 048661cdf8..066e6cd430 100644 --- a/include/clang/AST/DeclObjC.h +++ b/include/clang/AST/DeclObjC.h @@ -202,7 +202,7 @@ class ObjCInterfaceDecl : public TypeDecl { /// Ivars/NumIvars - This is a new[]'d array of pointers to Decls. ObjCIvarDecl **Ivars; // Null if not defined. - int NumIvars; // -1 if not defined. + unsigned NumIvars; // 0 if none. /// instance methods ObjCMethodDecl **InstanceMethods; // Null if not defined @@ -229,7 +229,7 @@ class ObjCInterfaceDecl : public TypeDecl { IdentifierInfo *Id, bool FD, bool isInternal) : TypeDecl(ObjCInterface, atLoc, Id, 0), SuperClass(0), ReferencedProtocols(0), NumReferencedProtocols(0), Ivars(0), - NumIvars(-1), + NumIvars(0), InstanceMethods(0), NumInstanceMethods(-1), ClassMethods(0), NumClassMethods(0), CategoryList(0), PropertyDecl(0), NumPropertyDecl(-1), @@ -258,12 +258,10 @@ public: } unsigned getNumIntfRefProtocols() const { return NumReferencedProtocols; } - int getNumInstanceVariables() const { return NumIvars; } - typedef ObjCIvarDecl * const *ivar_iterator; - unsigned ivar_size() const { return NumIvars == -1 ?0 : NumIvars; } ivar_iterator ivar_begin() const { return Ivars; } ivar_iterator ivar_end() const { return Ivars + ivar_size();} + unsigned ivar_size() const { return NumIvars; } int getNumInstanceMethods() const { return NumInstanceMethods; } unsigned getNumClassMethods() const { return NumClassMethods; } @@ -799,7 +797,7 @@ class ObjCImplementationDecl : public NamedDecl { /// Optional Ivars/NumIvars - This is a new[]'d array of pointers to Decls. ObjCIvarDecl **Ivars; // Null if not specified - int NumIvars; // -1 if not defined. + unsigned NumIvars; // 0 if none. /// implemented instance methods llvm::SmallVector InstanceMethods; @@ -814,7 +812,7 @@ class ObjCImplementationDecl : public NamedDecl { ObjCInterfaceDecl *superDecl) : NamedDecl(ObjCImplementation, L, Id), ClassInterface(classInterface), SuperClass(superDecl), - Ivars(0), NumIvars(-1) {} + Ivars(0), NumIvars(0) {} public: static ObjCImplementationDecl *Create(ASTContext &C, SourceLocation L, IdentifierInfo *Id, @@ -839,15 +837,11 @@ public: ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; } ObjCInterfaceDecl *getSuperClass() const { return SuperClass; } - void setSuperClass(ObjCInterfaceDecl * superCls) - { SuperClass = superCls; } + void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; } int getNumInstanceMethods() const { return InstanceMethods.size(); } unsigned getNumClassMethods() const { return ClassMethods.size(); } - int getImplDeclNumIvars() const { return NumIvars; } - - typedef llvm::SmallVector::const_iterator instmeth_iterator; instmeth_iterator instmeth_begin() const { return InstanceMethods.begin(); } @@ -866,7 +860,9 @@ public: typedef ObjCIvarDecl * const *ivar_iterator; ivar_iterator ivar_begin() const { return Ivars; } - ivar_iterator ivar_end() const {return Ivars+(NumIvars == -1 ? 0 : NumIvars);} + ivar_iterator ivar_end() const { return Ivars+NumIvars; } + unsigned ivar_size() const { return NumIvars; } + bool ivar_empty() const { return NumIvars == 0; } static bool classof(const Decl *D) { return D->getKind() == ObjCImplementation;