]> granicus.if.org Git - clang/commitdiff
Remove the ObjCCategoryImpls vector from Sema class.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 21 Jul 2009 00:06:20 +0000 (00:06 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 21 Jul 2009 00:06:20 +0000 (00:06 +0000)
Use ObjCInterfaceDecl::getCategoryClassMethod() and ObjCInterfaceDecl::getCategoryInstanceMethod() for the same functionality.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76510 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclObjC.h
include/clang/Frontend/PCHBitCodes.h
lib/AST/DeclObjC.cpp
lib/Frontend/PCHReader.cpp
lib/Frontend/PCHWriter.cpp
lib/Sema/Sema.h
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaExprObjC.cpp

index b23ad3d29b27db8f8f5441a0330d0f851e540a74..4242d8d8d0a0456babec668cd0de4b1c323109b5 100644 (file)
@@ -432,6 +432,14 @@ public:
   void setImplementation(ObjCImplementationDecl *ImplD);
 
   ObjCCategoryDecl *FindCategoryDeclaration(IdentifierInfo *CategoryId) const;
+  
+  // Get the local instance/class method declared in a category.
+  ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
+  ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
+  ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
+    return isInstance ? getInstanceMethod(Sel) 
+                      : getClassMethod(Sel);
+  }
 
   typedef ObjCList<ObjCProtocolDecl>::iterator protocol_iterator;
   protocol_iterator protocol_begin() const {return ReferencedProtocols.begin();}
index dc7f4e1b47da2dbf42ad17b30f8ce6784b9ee410..85d0c56bbbd7a68ab14668d76a2aa32ac83cb5bf 100644 (file)
@@ -212,17 +212,13 @@ namespace clang {
       /// \brief Record code for the set of ext_vector type names.
       EXT_VECTOR_DECLS = 18,
 
-      /// \brief Record code for the set of Objective-C category
-      /// implementations.
-      OBJC_CATEGORY_IMPLEMENTATIONS = 19,
-
       /// \brief Record code for the original file that was used to
       /// generate the precompiled header.
-      ORIGINAL_FILE_NAME = 20,
+      ORIGINAL_FILE_NAME = 19,
       
       /// \brief Record code for the sorted array of source ranges where
       /// comments were encountered in the source code.
-      COMMENT_RANGES = 21
+      COMMENT_RANGES = 20
     };
 
     /// \brief Record types used within a source manager block.
index 4eee28b4682ce73ce0b4d26f1e20612ab36c7955..7b86bfd195c2585b56e5c96c185a13914e810d46 100644 (file)
@@ -386,6 +386,25 @@ ObjCInterfaceDecl::FindCategoryDeclaration(IdentifierInfo *CategoryId) const {
   return 0;
 }
 
+ObjCMethodDecl *
+ObjCInterfaceDecl::getCategoryInstanceMethod(Selector Sel) const {
+  for (ObjCCategoryDecl *Category = getCategoryList();
+       Category; Category = Category->getNextClassCategory())
+    if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
+      if (ObjCMethodDecl *MD = Impl->getInstanceMethod(Sel))
+        return MD;
+  return 0;
+}
+
+ObjCMethodDecl *ObjCInterfaceDecl::getCategoryClassMethod(Selector Sel) const {
+  for (ObjCCategoryDecl *Category = getCategoryList();
+       Category; Category = Category->getNextClassCategory())
+    if (ObjCCategoryImplDecl *Impl = Category->getImplementation())
+      if (ObjCMethodDecl *MD = Impl->getClassMethod(Sel))
+        return MD;
+  return 0;
+}
+
 //===----------------------------------------------------------------------===//
 // ObjCIvarDecl
 //===----------------------------------------------------------------------===//
index d3c746501a085cba2f2ce1f3c26a899882407375..f21fc6252245cc55c98d0f2920b1d86dc83e8d01 100644 (file)
@@ -1364,14 +1364,6 @@ PCHReader::ReadPCHBlock() {
       ExtVectorDecls.swap(Record);
       break;
 
-    case pch::OBJC_CATEGORY_IMPLEMENTATIONS:
-      if (!ObjCCategoryImpls.empty()) {
-        Error("duplicate OBJC_CATEGORY_IMPLEMENTATIONS record in PCH file");
-        return Failure;
-      }
-      ObjCCategoryImpls.swap(Record);
-      break;
-
     case pch::ORIGINAL_FILE_NAME:
       OriginalFileName.assign(BlobStart, BlobLen);
       MaybeAddSystemRootToFilename(OriginalFileName);
@@ -2210,13 +2202,6 @@ void PCHReader::InitializeSema(Sema &S) {
   for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I)
     SemaObj->ExtVectorDecls.push_back(
                                cast<TypedefDecl>(GetDecl(ExtVectorDecls[I])));
-
-  // If there were any Objective-C category implementations,
-  // deserialize them and add them to Sema's vector of such
-  // definitions.
-  for (unsigned I = 0, N = ObjCCategoryImpls.size(); I != N; ++I)
-    SemaObj->ObjCCategoryImpls.push_back(
-                cast<ObjCCategoryImplDecl>(GetDecl(ObjCCategoryImpls[I])));
 }
 
 IdentifierInfo* PCHReader::get(const char *NameStart, const char *NameEnd) {
index 0a0202ba01d94ff554fd93498c0db6818b93feb2..13f564d012b02b4644eacc7da48088a57360f959 100644 (file)
@@ -385,7 +385,6 @@ void PCHWriter::WriteBlockInfoBlock() {
   RECORD(SOURCE_LOCATION_PRELOADS);
   RECORD(STAT_CACHE);
   RECORD(EXT_VECTOR_DECLS);
-  RECORD(OBJC_CATEGORY_IMPLEMENTATIONS);
   RECORD(COMMENT_RANGES);
   
   // SourceManager Block.
@@ -1820,12 +1819,6 @@ void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls,
   for (unsigned I = 0, N = SemaRef.ExtVectorDecls.size(); I != N; ++I)
     AddDeclRef(SemaRef.ExtVectorDecls[I], ExtVectorDecls);
 
-  // Build a record containing all of the Objective-C category
-  // implementations.
-  RecordData ObjCCategoryImpls;
-  for (unsigned I = 0, N = SemaRef.ObjCCategoryImpls.size(); I != N; ++I)
-    AddDeclRef(SemaRef.ObjCCategoryImpls[I], ObjCCategoryImpls);
-
   // Write the remaining PCH contents.
   RecordData Record;
   Stream.EnterSubblock(pch::PCH_BLOCK_ID, 4);
@@ -1903,10 +1896,6 @@ void PCHWriter::WritePCH(Sema &SemaRef, MemorizeStatCalls *StatCalls,
   // Write the record containing ext_vector type names.
   if (!ExtVectorDecls.empty())
     Stream.EmitRecord(pch::EXT_VECTOR_DECLS, ExtVectorDecls);
-
-  // Write the record containing Objective-C category implementations.
-  if (!ObjCCategoryImpls.empty())
-    Stream.EmitRecord(pch::OBJC_CATEGORY_IMPLEMENTATIONS, ObjCCategoryImpls);
   
   // Some simple statistics
   Record.clear();
index 1e75bb2e3de95c85f5549e5b5b5a21d4d39775d2..47938dcd417d0d96695201a664362f2346e1256e 100644 (file)
@@ -185,10 +185,6 @@ public:
   /// us to associate a raw vector type with one of the ext_vector type names.
   /// This is only necessary for issuing pretty diagnostics.
   llvm::SmallVector<TypedefDecl*, 24> ExtVectorDecls;
-
-  /// ObjCCategoryImpls - Maintain a list of category implementations so 
-  /// we can check for duplicates and find local method declarations.
-  llvm::SmallVector<ObjCCategoryImplDecl*, 8> ObjCCategoryImpls;
   
   /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
   llvm::OwningPtr<CXXFieldCollector> FieldCollector;
index 89bde815c0cc4f5b4a668f6475c208fea503e197..19cbf091b5f86d5af121b10260641eed8a39fe31 100644 (file)
@@ -638,8 +638,6 @@ Sema::DeclPtrTy Sema::ActOnStartCategoryImplementation(
     } else
       CatIDecl->setImplementation(CDecl);
   }
-
-  ObjCCategoryImpls.push_back(CDecl);
   
   CheckObjCDeclScope(CDecl);
   return DeclPtrTy::make(CDecl);
index 2f47c79777aaeebeeed384730dfcc7338269c9de..145a9287162d0feb38cba18fcb60e531a5376e56 100644 (file)
@@ -2250,12 +2250,8 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
         Setter = FindMethodInNestedImplementations(IFace, SetterSel);
       }
       // Look through local category implementations associated with the class.
-      if (!Setter) {
-        for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Setter; i++) {
-          if (ObjCCategoryImpls[i]->getClassInterface() == IFace)
-            Setter = ObjCCategoryImpls[i]->getClassMethod(SetterSel);
-        }
-      }
+      if (!Setter)
+        Setter = IFace->getCategoryClassMethod(SetterSel);
 
       if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
         return ExprError();
@@ -2431,12 +2427,8 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
       Getter = FindMethodInNestedImplementations(IFace, Sel);
 
     // Look through local category implementations associated with the class.
-    if (!Getter) {
-      for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Getter; i++) {
-        if (ObjCCategoryImpls[i]->getClassInterface() == IFace)
-          Getter = ObjCCategoryImpls[i]->getInstanceMethod(Sel);
-      }
-    }
+    if (!Getter)
+      Getter = IFace->getCategoryInstanceMethod(Sel);
     if (Getter) {
       // Check if we can reference this property.
       if (DiagnoseUseOfDecl(Getter, MemberLoc))
@@ -2454,12 +2446,8 @@ Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
       Setter = FindMethodInNestedImplementations(IFace, SetterSel);
     }
     // Look through local category implementations associated with the class.
-    if (!Setter) {
-      for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Setter; i++) {
-        if (ObjCCategoryImpls[i]->getClassInterface() == IFace)
-          Setter = ObjCCategoryImpls[i]->getInstanceMethod(SetterSel);
-      }
-    }
+    if (!Setter)
+      Setter = IFace->getCategoryInstanceMethod(SetterSel);
 
     if (Setter && DiagnoseUseOfDecl(Setter, MemberLoc))
       return ExprError();
index 141cd80bff679e7f11055ea8edd2f28a82f45498..068b386980e4f33d89b07bb6e7a7ec310fce4fad 100644 (file)
@@ -245,12 +245,8 @@ ObjCMethodDecl *Sema::LookupPrivateClassMethod(Selector Sel,
       Method = ImpDecl->getClassMethod(Sel);
     
     // Look through local category implementations associated with the class.
-    if (!Method) {
-      for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Method; i++) {
-        if (ObjCCategoryImpls[i]->getClassInterface() == ClassDecl)
-          Method = ObjCCategoryImpls[i]->getClassMethod(Sel);
-      }
-    }
+    if (!Method)
+      Method = ClassDecl->getCategoryClassMethod(Sel);
     
     // Before we give up, check if the selector is an instance method.
     // But only in the root. This matches gcc's behaviour and what the
@@ -277,12 +273,8 @@ ObjCMethodDecl *Sema::LookupPrivateInstanceMethod(Selector Sel,
       Method = ImpDecl->getInstanceMethod(Sel);
     
     // Look through local category implementations associated with the class.
-    if (!Method) {
-      for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Method; i++) {
-        if (ObjCCategoryImpls[i]->getClassInterface() == ClassDecl)
-          Method = ObjCCategoryImpls[i]->getInstanceMethod(Sel);
-      }
-    }
+    if (!Method)
+      Method = ClassDecl->getCategoryInstanceMethod(Sel);
     ClassDecl = ClassDecl->getSuperClass();
   }
   return Method;
@@ -330,12 +322,8 @@ Action::OwningExprResult Sema::ActOnClassPropertyRefExpr(
           Setter = ImpDecl->getClassMethod(SetterSel);
   }
   // Look through local category implementations associated with the class.
-  if (!Setter) {
-    for (unsigned i = 0; i < ObjCCategoryImpls.size() && !Setter; i++) {
-      if (ObjCCategoryImpls[i]->getClassInterface() == IFace)
-        Setter = ObjCCategoryImpls[i]->getClassMethod(SetterSel);
-    }
-  }
+  if (!Setter)
+    Setter = IFace->getCategoryClassMethod(SetterSel);
 
   if (Setter && DiagnoseUseOfDecl(Setter, propertyNameLoc))
     return ExprError();