]> granicus.if.org Git - clang/commitdiff
minor cleanups, make getNumInstanceMethods always return unsigned.
authorChris Lattner <sabre@nondot.org>
Sun, 16 Mar 2008 20:19:15 +0000 (20:19 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 16 Mar 2008 20:19:15 +0000 (20:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48423 91177308-0d34-0410-b5e6-96231b3b80d8

Driver/RewriteTest.cpp
include/clang/AST/DeclObjC.h
lib/AST/DeclObjC.cpp
lib/Parse/ParseObjc.cpp
lib/Sema/SemaDeclObjC.cpp

index d72aaf282b2d22a20c2fe941d5dbddb4d7f3b1fe..7bdec9390a179918749e65a23f9004fa1d09fe6c 100644 (file)
@@ -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 += ", ";
index 3ee0b9532a8ffb7d42eb870eec899cdb73759368..bfa21046dcf65d9e3268234aae61a9e4c6363cb8 100644 (file)
@@ -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;
index 17b1d28cadb363633350f1b65000b58c97bfa99c..62336b67bdf17aa8024f29e6b592e6fd74943b4f 100644 (file)
@@ -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<ObjCProtocolDecl>();
-  return new (Mem) ObjCProtocolDecl(L, numRefProtos, Id, ForwardDecl);
+  return new (Mem) ObjCProtocolDecl(L, numRefProtos, Id);
 }
 
 
index 77d2adbd320bd582a1669a793f75335028304437..7345abed991fb95c272e1d9d106c35383c63d0cf 100644 (file)
@@ -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());
index 3b8baea519fd2bc1db09e1b8ae3e9824743facca..28a92c7ba26c2491713ec7474269342ff73b1fa6 100644 (file)
@@ -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<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);