[cfe-commits] r48423 - in /cfe/trunk: Driver/RewriteTest.cpp include/clang/AST/DeclObjC.h lib/AST/DeclObjC.cpp lib/Parse/ParseObjc.cpp lib/Sema/SemaDeclObjC.cpp

Chris Lattner sabre at nondot.org
Sun Mar 16 13:19:15 PDT 2008


Author: lattner
Date: Sun Mar 16 15:19:15 2008
New Revision: 48423

URL: http://llvm.org/viewvc/llvm-project?rev=48423&view=rev
Log:
minor cleanups, make getNumInstanceMethods always return unsigned.

Modified:
    cfe/trunk/Driver/RewriteTest.cpp
    cfe/trunk/include/clang/AST/DeclObjC.h
    cfe/trunk/lib/AST/DeclObjC.cpp
    cfe/trunk/lib/Parse/ParseObjc.cpp
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp

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

==============================================================================
--- cfe/trunk/Driver/RewriteTest.cpp (original)
+++ cfe/trunk/Driver/RewriteTest.cpp Sun Mar 16 15:19:15 2008
@@ -2348,9 +2348,7 @@
     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 @@
         
         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 @@
       }
       
       // 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 @@
         "{\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 += ", ";

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

==============================================================================
--- cfe/trunk/include/clang/AST/DeclObjC.h (original)
+++ cfe/trunk/include/clang/AST/DeclObjC.h Sun Mar 16 15:19:15 2008
@@ -429,19 +429,17 @@
   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 @@
     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 @@
   
   /// 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 @@
   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 @@
     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;

Modified: cfe/trunk/lib/AST/DeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclObjC.cpp?rev=48423&r1=48422&r2=48423&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclObjC.cpp (original)
+++ cfe/trunk/lib/AST/DeclObjC.cpp Sun Mar 16 15:19:15 2008
@@ -49,10 +49,9 @@
 
 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);
 }
 
 

Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=48423&r1=48422&r2=48423&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Sun Mar 16 15:19:15 2008
@@ -847,7 +847,6 @@
 ///   "@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 @@
     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());

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=48423&r1=48422&r2=48423&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sun Mar 16 15:19:15 2008
@@ -214,12 +214,13 @@
     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 @@
   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);





More information about the cfe-commits mailing list