]> granicus.if.org Git - clang/commitdiff
Implement DenseMapInfo for Selector, allowing use of DenseMap/DenseSet of
authorChris Lattner <sabre@nondot.org>
Fri, 5 Oct 2007 20:15:24 +0000 (20:15 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 5 Oct 2007 20:15:24 +0000 (20:15 +0000)
Selector's instead of requiring void* to be used.  I converted one use of
DenseSet<void*> over to use DenseSet<Selector> but the others should change
as well.

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

Lex/IdentifierTable.cpp
Sema/Sema.h
Sema/SemaDecl.cpp
include/clang/Lex/IdentifierTable.h

index 2ca1225b176fc5df879aaffdd240ebc0b8639a51..f3a6cf7175f474044d881bfc4154356e4f6b1d11 100644 (file)
@@ -16,6 +16,7 @@
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/ADT/DenseMap.h"
 using namespace clang;
 
 //===----------------------------------------------------------------------===//
@@ -215,10 +216,16 @@ void IdentifierTable::PrintStats() const {
 // SelectorTable Implementation
 //===----------------------------------------------------------------------===//
 
+unsigned llvm::DenseMapInfo<clang::Selector>::getHashValue(clang::Selector S) {
+  return DenseMapInfo<void*>::getHashValue(S.getAsOpaquePtr());
+}
+
+
 /// MultiKeywordSelector - One of these variable length records is kept for each
 /// selector containing more than one keyword. We use a folding set
 /// to unique aggregate names (keyword selectors in ObjC parlance). Access to 
 /// this class is provided strictly through Selector.
+namespace clang {
 class MultiKeywordSelector : public llvm::FoldingSetNode {
 public:  
   unsigned NumArgs;
@@ -263,6 +270,7 @@ public:
     Profile(ID, keyword_begin(), NumArgs);
   }
 };
+} // end namespace clang.
 
 unsigned Selector::getNumArgs() const {
   unsigned IIF = getIdentifierInfoFlag();
index b497f5e0ffe00181a726aa632c1588e2a5697e88..7a6d62fac25298b356950678eb9d56257ff57609 100644 (file)
@@ -217,7 +217,7 @@ private:
   void CheckProtocolMethodDefs(ObjcProtocolDecl *PDecl,
                                bool& IncompleteImpl,
                                const llvm::DenseSet<void *>& InsMap,
-                               const llvm::DenseSet<void *>& ClsMap);
+                               const llvm::DenseSet<Selector> &ClsMap);
   
   /// CheckImplementationIvars - This routine checks if the instance variables
   /// listed in the implelementation match those listed in the interface. 
@@ -260,8 +260,8 @@ public:
                                  StmtTy *ThenVal, SourceLocation ElseLoc,
                                  StmtTy *ElseVal);
   virtual StmtResult ActOnStartOfSwitchStmt(ExprTy *Cond);
-  virtual StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtTy *Switch, 
-                                      ExprTy *Body);
+  virtual StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc,
+                                           StmtTy *Switch, ExprTy *Body);
   virtual StmtResult ActOnWhileStmt(SourceLocation WhileLoc, ExprTy *Cond,
                                     StmtTy *Body);
   virtual StmtResult ActOnDoStmt(SourceLocation DoLoc, StmtTy *Body,
index f7d8dd8493b7b4015ec7e3910ded94deb0e9dc83..b827732b872cc9871815cdd07b23056079f83391 100644 (file)
@@ -1221,7 +1221,7 @@ void Sema::CheckImplementationIvars(ObjcImplementationDecl *ImpDecl,
 void Sema::CheckProtocolMethodDefs(ObjcProtocolDecl *PDecl,
                                    bool& IncompleteImpl,
              const llvm::DenseSet<void *>& InsMap,
-             const llvm::DenseSet<void *>& ClsMap) {
+             const llvm::DenseSet<Selector> &ClsMap) {
   // check unimplemented instance methods.
   ObjcMethodDecl** methods = PDecl->getInstanceMethods();
   for (int j = 0; j < PDecl->getNumInstanceMethods(); j++) {
@@ -1236,7 +1236,7 @@ void Sema::CheckProtocolMethodDefs(ObjcProtocolDecl *PDecl,
   // check unimplemented class methods
   methods = PDecl->getClassMethods();
   for (int j = 0; j < PDecl->getNumClassMethods(); j++)
-    if (!ClsMap.count(methods[j]->getSelector().getAsOpaquePtr())) {
+    if (!ClsMap.count(methods[j]->getSelector())) {
       llvm::SmallString<128> buf;
       Diag(methods[j]->getLocation(), diag::warn_undef_method_impl,
            methods[j]->getSelector().getName(buf));
@@ -1267,16 +1267,16 @@ void Sema::ImplMethodsVsClassMethods(ObjcImplementationDecl* IMPDecl,
            methods[j]->getSelector().getName(buf));
       IncompleteImpl = true;
     }
-  llvm::DenseSet<void *> ClsMap;
+  llvm::DenseSet<Selector> ClsMap;
   // Check and see if class methods in class interface have been
   // implemented in the implementation class.
   methods = IMPDecl->getClassMethods();
   for (int i=0; i < IMPDecl->getNumClassMethods(); i++)
-    ClsMap.insert(methods[i]->getSelector().getAsOpaquePtr());
+    ClsMap.insert(methods[i]->getSelector());
   
   methods = IDecl->getClassMethods();
   for (int j = 0; j < IDecl->getNumClassMethods(); j++)
-    if (!ClsMap.count(methods[j]->getSelector().getAsOpaquePtr())) {
+    if (!ClsMap.count(methods[j]->getSelector())) {
       llvm::SmallString<128> buf;
       Diag(methods[j]->getLocation(), diag::warn_undef_method_impl,
            methods[j]->getSelector().getName(buf));
@@ -1286,10 +1286,9 @@ void Sema::ImplMethodsVsClassMethods(ObjcImplementationDecl* IMPDecl,
   // Check the protocol list for unimplemented methods in the @implementation
   // class.
   ObjcProtocolDecl** protocols = IDecl->getReferencedProtocols();
-  for (int i = 0; i < IDecl->getNumIntfRefProtocols(); i++) {
-    ObjcProtocolDecl* PDecl = protocols[i];
-    CheckProtocolMethodDefs(PDecl, IncompleteImpl, InsMap, ClsMap);
-  }
+  for (int i = 0; i < IDecl->getNumIntfRefProtocols(); i++)
+    CheckProtocolMethodDefs(protocols[i], IncompleteImpl, InsMap, ClsMap);
+
   if (IncompleteImpl)
     Diag(IMPDecl->getLocation(), diag::warn_incomplete_impl_class, 
          IMPDecl->getName());
@@ -1315,16 +1314,16 @@ void Sema::ImplCategoryMethodsVsIntfMethods(ObjcCategoryImplDecl *CatImplDecl,
            methods[j]->getSelector().getName(buf));
       IncompleteImpl = true;
     }
-  llvm::DenseSet<void *> ClsMap;
+  llvm::DenseSet<Selector> ClsMap;
   // Check and see if class methods in category interface have been
   // implemented in its implementation class.
   methods = CatImplDecl->getClassMethods();
   for (int i=0; i < CatImplDecl->getNumClassMethods(); i++)
-    ClsMap.insert(methods[i]->getSelector().getAsOpaquePtr());
+    ClsMap.insert(methods[i]->getSelector());
   
   methods = CatClassDecl->getClassMethods();
   for (int j = 0; j < CatClassDecl->getNumClassMethods(); j++)
-    if (!ClsMap.count(methods[j]->getSelector().getAsOpaquePtr())) {
+    if (!ClsMap.count(methods[j]->getSelector())) {
       llvm::SmallString<128> buf;
       Diag(methods[j]->getLocation(), diag::warn_undef_method_impl,
            methods[j]->getSelector().getName(buf));
index c820e86fa75337e542c4750b8d2e72eeb00f6aca..9bb6d83cc56cc26773932452e30eba40535152a7 100644 (file)
 #include <string> 
 #include <cassert> 
 
-class MultiKeywordSelector; // a private class used by Selector.
+namespace llvm {
+  template <typename T> struct DenseMapInfo;
+}
 
 namespace clang {
   class MacroInfo;
   struct LangOptions;
+  class MultiKeywordSelector; // a private class used by Selector.
   
 /// IdentifierInfo - One of these records is kept for each identifier that
 /// is lexed.  This contains information about whether the token was #define'd,
@@ -202,6 +205,7 @@ class Selector {
     InfoPtr = reinterpret_cast<uintptr_t>(SI);
     assert((InfoPtr & ArgFlags) == 0 &&"Insufficiently aligned IdentifierInfo");
   }
+  Selector(intptr_t V) : InfoPtr(V) {}
 public:
   friend class SelectorTable; // only the SelectorTable can create these.
   
@@ -237,6 +241,13 @@ public:
   // As a convenience, a pointer to the first character is returned.
   // Example usage: llvm::SmallString<128> mbuf; Selector->getName(mbuf);
   char *getName(llvm::SmallVectorImpl<char> &methodBuffer);
+  
+  static Selector getEmptyMarker() {
+    return Selector(uintptr_t(-1));
+  }
+  static Selector getTombstoneMarker() {
+    return Selector(uintptr_t(-2));
+  }
 };
 
 /// SelectorTable - This table allows us to fully hide how we implement
@@ -256,4 +267,25 @@ public:
 
 }  // end namespace clang
 
+namespace llvm {
+template <>
+struct DenseMapInfo<clang::Selector> {
+  static inline clang::Selector getEmptyKey() {
+    return clang::Selector::getEmptyMarker();
+  }
+  static inline clang::Selector getTombstoneKey() {
+    return clang::Selector::getTombstoneMarker(); 
+  }
+  
+  static unsigned getHashValue(clang::Selector S);
+  
+  static bool isEqual(clang::Selector LHS, clang::Selector RHS) {
+    return LHS == RHS;
+  }
+  
+  static bool isPod() { return true; }
+};
+
+}  // end namespace llvm
+
 #endif