[cfe-commits] r42645 - in /cfe/trunk: Lex/IdentifierTable.cpp Sema/Sema.h Sema/SemaDecl.cpp include/clang/Lex/IdentifierTable.h

Chris Lattner sabre at nondot.org
Fri Oct 5 13:15:24 PDT 2007


Author: lattner
Date: Fri Oct  5 15:15:24 2007
New Revision: 42645

URL: http://llvm.org/viewvc/llvm-project?rev=42645&view=rev
Log:
Implement DenseMapInfo for Selector, allowing use of DenseMap/DenseSet of
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.

Modified:
    cfe/trunk/Lex/IdentifierTable.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/include/clang/Lex/IdentifierTable.h

Modified: cfe/trunk/Lex/IdentifierTable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/IdentifierTable.cpp?rev=42645&r1=42644&r2=42645&view=diff

==============================================================================
--- cfe/trunk/Lex/IdentifierTable.cpp (original)
+++ cfe/trunk/Lex/IdentifierTable.cpp Fri Oct  5 15:15:24 2007
@@ -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 @@
 // 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 @@
     Profile(ID, keyword_begin(), NumArgs);
   }
 };
+} // end namespace clang.
 
 unsigned Selector::getNumArgs() const {
   unsigned IIF = getIdentifierInfoFlag();

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=42645&r1=42644&r2=42645&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Fri Oct  5 15:15:24 2007
@@ -217,7 +217,7 @@
   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 @@
                                  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,

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=42645&r1=42644&r2=42645&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Fri Oct  5 15:15:24 2007
@@ -1221,7 +1221,7 @@
 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 @@
   // 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 @@
            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 @@
   // 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 @@
            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));

Modified: cfe/trunk/include/clang/Lex/IdentifierTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/IdentifierTable.h?rev=42645&r1=42644&r2=42645&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/IdentifierTable.h (original)
+++ cfe/trunk/include/clang/Lex/IdentifierTable.h Fri Oct  5 15:15:24 2007
@@ -22,11 +22,14 @@
 #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 @@
     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 @@
   // 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 @@
 
 }  // 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





More information about the cfe-commits mailing list