diff --git a/clang/Lex/IdentifierTable.cpp b/clang/Lex/IdentifierTable.cpp index 2ca1225b176f..f3a6cf7175f4 100644 --- a/clang/Lex/IdentifierTable.cpp +++ b/clang/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 @@ void IdentifierTable::PrintStats() const { // SelectorTable Implementation //===----------------------------------------------------------------------===// +unsigned llvm::DenseMapInfo::getHashValue(clang::Selector S) { + return DenseMapInfo::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(); diff --git a/clang/Sema/Sema.h b/clang/Sema/Sema.h index b497f5e0ffe0..7a6d62fac252 100644 --- a/clang/Sema/Sema.h +++ b/clang/Sema/Sema.h @@ -217,7 +217,7 @@ private: void CheckProtocolMethodDefs(ObjcProtocolDecl *PDecl, bool& IncompleteImpl, const llvm::DenseSet& InsMap, - const llvm::DenseSet& ClsMap); + const llvm::DenseSet &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, diff --git a/clang/Sema/SemaDecl.cpp b/clang/Sema/SemaDecl.cpp index f7d8dd8493b7..b827732b872c 100644 --- a/clang/Sema/SemaDecl.cpp +++ b/clang/Sema/SemaDecl.cpp @@ -1221,7 +1221,7 @@ void Sema::CheckImplementationIvars(ObjcImplementationDecl *ImpDecl, void Sema::CheckProtocolMethodDefs(ObjcProtocolDecl *PDecl, bool& IncompleteImpl, const llvm::DenseSet& InsMap, - const llvm::DenseSet& ClsMap) { + const llvm::DenseSet &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 ClsMap; + llvm::DenseSet 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 ClsMap; + llvm::DenseSet 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/clang/include/clang/Lex/IdentifierTable.h b/clang/include/clang/Lex/IdentifierTable.h index c820e86fa753..9bb6d83cc56c 100644 --- a/clang/include/clang/Lex/IdentifierTable.h +++ b/clang/include/clang/Lex/IdentifierTable.h @@ -22,11 +22,14 @@ #include #include -class MultiKeywordSelector; // a private class used by Selector. +namespace llvm { + template 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(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 &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 { + 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