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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42645 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Lex/IdentifierTable.cpp b/Lex/IdentifierTable.cpp
index 2ca1225..f3a6cf7 100644
--- a/Lex/IdentifierTable.cpp
+++ b/Lex/IdentifierTable.cpp
@@ -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();
diff --git a/Sema/Sema.h b/Sema/Sema.h
index b497f5e..7a6d62f 100644
--- a/Sema/Sema.h
+++ b/Sema/Sema.h
@@ -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,
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index f7d8dd8..b827732 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -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));
diff --git a/include/clang/Lex/IdentifierTable.h b/include/clang/Lex/IdentifierTable.h
index c820e86..9bb6d83 100644
--- a/include/clang/Lex/IdentifierTable.h
+++ b/include/clang/Lex/IdentifierTable.h
@@ -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