[cfe-commits] r48429 - in /cfe/trunk: Driver/ASTConsumers.cpp Driver/RewriteTest.cpp include/clang/AST/DeclObjC.h

Chris Lattner sabre at nondot.org
Sun Mar 16 14:08:55 PDT 2008


Author: lattner
Date: Sun Mar 16 16:08:55 2008
New Revision: 48429

URL: http://llvm.org/viewvc/llvm-project?rev=48429&view=rev
Log:
Convert more counts to be zero based instead of -1 based, make them unsigned.

Modified:
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Driver/RewriteTest.cpp
    cfe/trunk/include/clang/AST/DeclObjC.h

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=48429&r1=48428&r2=48429&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Sun Mar 16 16:08:55 2008
@@ -247,7 +247,7 @@
   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) {

Modified: cfe/trunk/Driver/RewriteTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteTest.cpp?rev=48429&r1=48428&r2=48429&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Sun Mar 16 16:08:55 2008
@@ -2178,7 +2178,7 @@
   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 @@
   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 @@
   }
   
   // 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 @@
     Result += "\n";
     
     ObjCInterfaceDecl::ivar_iterator IVI, IVE;
-    if (IDecl->getImplDeclNumIvars() > 0) {
+    if (!IDecl->ivar_empty()) {
       IVI = IDecl->ivar_begin();
       IVE = IDecl->ivar_end();
     } else {

Modified: cfe/trunk/include/clang/AST/DeclObjC.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=48429&r1=48428&r2=48429&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Sun Mar 16 16:08:55 2008
@@ -202,7 +202,7 @@
   
   /// 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 @@
                     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 @@
   }
   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 @@
     
   /// 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 @@
                          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 @@
   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 @@
   
   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;





More information about the cfe-commits mailing list