]> granicus.if.org Git - clang/commitdiff
Convert more counts to be zero based instead of -1 based, make them unsigned.
authorChris Lattner <sabre@nondot.org>
Sun, 16 Mar 2008 21:08:55 +0000 (21:08 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 16 Mar 2008 21:08:55 +0000 (21:08 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48429 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/ASTConsumers.cpp
Driver/RewriteTest.cpp
include/clang/AST/DeclObjC.h

index dcbe6796c00554ba784d32df6d334fb7ad3434c3..0dc669294564a9e825af33e76455f738e1a3359d 100644 (file)
@@ -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) {
index 7bdec9390a179918749e65a23f9004fa1d09fe6c..2b88c0c8f3552d49f8685fae39512034057a25ca 100644 (file)
@@ -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 {
index 048661cdf864894ff78c1f215b57b6d0372f9e11..066e6cd430f549f14b8c76f6a160a0765facaf35 100644 (file)
@@ -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<ObjCMethodDecl*, 32> 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<ObjCMethodDecl*, 32>::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;