From: Ted Kremenek Date: Tue, 2 Oct 2007 16:38:05 +0000 (+0000) Subject: Added DenseMapInfo traits for ProgramEdges X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4c3fbe33194cd9b1bfff773647ed785b403e1ba5;p=clang Added DenseMapInfo traits for ProgramEdges git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42530 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Analysis/PathSensitive/ProgramEdge.h b/include/clang/Analysis/PathSensitive/ProgramEdge.h index bfb7a0ae12..f28053ace7 100644 --- a/include/clang/Analysis/PathSensitive/ProgramEdge.h +++ b/include/clang/Analysis/PathSensitive/ProgramEdge.h @@ -16,6 +16,8 @@ #define LLVM_CLANG_ANALYSIS_PATHSENS_PROGRAM_POINT #include "llvm/Support/DataTypes.h" +#include "llvm/ADT/DenseMap.h" +#include namespace clang { @@ -31,8 +33,23 @@ public: unsigned getKind() const { return (unsigned) Src & 0x3; } void* RawSrc() const { return reinterpret_cast(Src & ~0x3); } void* RawDst() const { return reinterpret_cast(Dst); } + + bool operator==(const ProgramEdge & RHS) const { + // comparing pointer values canoncalizes "NULL" edges where both pointers + // are NULL without having to worry about edgekind. We can otherwise + // ignore edgekind because no CFGBlock* or Stmt* will have the same value. + return RawSrc() == RHS.RawSrc() && RawDst() == RHS.RawDst(); + } + + unsigned getHashValue() const { + uintptr_t v1 = reinterpret_cast(RawSrc()); + uintptr_t v2 = reinterpret_cast(RawDst()); + return static_cast( (v1 >> 4) ^ (v1 >> 9) ^ + (v2 >> 5) ^ (v2 >> 10) ); + } protected: + ProgramEdge(const void* src, const void* dst, EdgeKind k) { assert (k >= StmtBlk && k <= BlkBlk); Src = reinterpret_cast(const_cast(src)) | k; @@ -86,4 +103,28 @@ public: }; } // end namespace clang + + +namespace llvm { // Traits specialization for DenseMap + +template <> struct DenseMapInfo { + + static inline clang::ProgramEdge getEmptyKey() { + return clang::BlkBlkEdge(NULL,NULL); + } + + static inline clang::ProgramEdge getTombstoneKey() { + return clang::BlkBlkEdge(reinterpret_cast(-1), + reinterpret_cast(-1)); + } + + static bool isEqual(const clang::ProgramEdge& LHS, + const clang::ProgramEdge& RHS) { + return LHS == RHS; + } + + static bool isPod() { return true; } +}; +} // end namespace llvm + #endif