From 952a00429838b86245c2a61a0945a661007db856 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 22 Jul 2009 04:38:22 +0000 Subject: [PATCH] Restructure ProgramPoint to have the 'Kind' value be its own instance variable. This gives us much more flexibility with defining more ProgramPoints, which is the direction we are heading. The removal of various bit-mangling of pointers also cleans up the logic. llvm-svn: 76721 --- clang/include/clang/Analysis/ProgramPoint.h | 97 +++++++++-------------------- 1 file changed, 28 insertions(+), 69 deletions(-) diff --git a/clang/include/clang/Analysis/ProgramPoint.h b/clang/include/clang/Analysis/ProgramPoint.h index 197edb9..1c6f998 100644 --- a/clang/include/clang/Analysis/ProgramPoint.h +++ b/clang/include/clang/Analysis/ProgramPoint.h @@ -45,87 +45,46 @@ public: MaxPostStmtKind = PostLValueKind }; private: - enum { TwoPointers = 0x1, Custom = 0x2, Mask = 0x3 }; - - std::pair Data; + std::pair Data; + Kind K; const void *Tag; protected: ProgramPoint(const void* P, Kind k, const void *tag = 0) - : Data(reinterpret_cast(P), - (uintptr_t) k), Tag(tag) {} + : Data(P, NULL), K(k), Tag(tag) {} - ProgramPoint(const void* P1, const void* P2, const void *tag = 0) - : Data(reinterpret_cast(P1) | TwoPointers, - reinterpret_cast(P2)), Tag(tag) {} - - ProgramPoint(const void* P1, const void* P2, bool, const void *tag = 0) - : Data(reinterpret_cast(P1) | Custom, - reinterpret_cast(P2)), Tag(tag) {} + ProgramPoint(const void* P1, const void* P2, Kind k, const void *tag = 0) + : Data(P1, P2), K(k), Tag(tag) {} protected: - void* getData1NoMask() const { - Kind k = getKind(); k = k; - assert(k == BlockEntranceKind || k == BlockExitKind); - return reinterpret_cast(Data.first); - } - - void* getData1() const { - Kind k = getKind(); k = k; - assert(k == BlockEdgeKind ||(k >= MinPostStmtKind && k <= MaxPostStmtKind)); - return reinterpret_cast(Data.first & ~Mask); - } - - void* getData2() const { - Kind k = getKind(); k = k; - assert(k == BlockEdgeKind || k == PostStmtCustomKind); - return reinterpret_cast(Data.second); - } - + const void* getData1() const { return Data.first; } + const void* getData2() const { return Data.second; } const void *getTag() const { return Tag; } public: - Kind getKind() const { - switch (Data.first & Mask) { - case TwoPointers: return BlockEdgeKind; - case Custom: return PostStmtCustomKind; - default: return (Kind) Data.second; - } - } + Kind getKind() const { return K; } // For use with DenseMap. This hash is probably slow. unsigned getHashValue() const { llvm::FoldingSetNodeID ID; - ID.AddPointer(reinterpret_cast(Data.first)); - ID.AddPointer(reinterpret_cast(Data.second)); - ID.AddPointer(Tag); + Profile(ID); return ID.ComputeHash(); } static bool classof(const ProgramPoint*) { return true; } bool operator==(const ProgramPoint & RHS) const { - return Data == RHS.Data && Tag == RHS.Tag; + return K == RHS.K && Data == RHS.Data && Tag == RHS.Tag; } bool operator!=(const ProgramPoint& RHS) const { - return Data != RHS.Data || Tag != RHS.Tag; + return K != RHS.K || Data != RHS.Data || Tag != RHS.Tag; } - bool operator<(const ProgramPoint& RHS) const { - return Data < RHS.Data && Tag < RHS.Tag; - } - void Profile(llvm::FoldingSetNodeID& ID) const { - ID.AddPointer(reinterpret_cast(Data.first)); - if (getKind() != PostStmtCustomKind) - ID.AddPointer(reinterpret_cast(Data.second)); - else { - const std::pair *P = - reinterpret_cast*>(Data.second); - ID.AddPointer(P->first); - ID.AddPointer(P->second); - } + ID.AddInteger((unsigned) K); + ID.AddPointer(Data.first); + ID.AddPointer(Data.second); ID.AddPointer(Tag); } }; @@ -136,11 +95,11 @@ public: : ProgramPoint(B, BlockEntranceKind, tag) {} CFGBlock* getBlock() const { - return reinterpret_cast(getData1NoMask()); + return const_cast(reinterpret_cast(getData1())); } Stmt* getFirstStmt() const { - CFGBlock* B = getBlock(); + const CFGBlock* B = getBlock(); return B->empty() ? NULL : B->front(); } @@ -154,11 +113,11 @@ public: BlockExit(const CFGBlock* B) : ProgramPoint(B, BlockExitKind) {} CFGBlock* getBlock() const { - return reinterpret_cast(getData1NoMask()); + return const_cast(reinterpret_cast(getData1())); } Stmt* getLastStmt() const { - CFGBlock* B = getBlock(); + const CFGBlock* B = getBlock(); return B->empty() ? NULL : B->back(); } @@ -176,16 +135,17 @@ protected: PostStmt(const Stmt* S, Kind k,const void *tag = 0) : ProgramPoint(S, k, tag) {} - PostStmt(const Stmt* S, const void* data, bool, const void *tag =0) - : ProgramPoint(S, data, true, tag) {} + PostStmt(const Stmt* S, const void* data, Kind k, const void *tag =0) + : ProgramPoint(S, data, k, tag) {} public: PostStmt(const Stmt* S, const void *tag = 0) : ProgramPoint(S, PostStmtKind, tag) {} + Stmt* getStmt() const { return (Stmt*) getData1(); } - template + template T* getStmtAs() const { return llvm::dyn_cast(getStmt()); } static bool classof(const ProgramPoint* Location) { @@ -208,12 +168,11 @@ class PostStmtCustom : public PostStmt { public: PostStmtCustom(const Stmt* S, const std::pair* TaggedData) - : PostStmt(S, TaggedData, true) { - assert(getKind() == PostStmtCustomKind); - } + : PostStmt(S, TaggedData, PostStmtCustomKind) {} const std::pair& getTaggedPair() const { - return *reinterpret_cast*>(getData2()); + return + *reinterpret_cast*>(getData2()); } const void* getTag() const { return getTaggedPair().first; } @@ -298,14 +257,14 @@ public: class BlockEdge : public ProgramPoint { public: BlockEdge(const CFGBlock* B1, const CFGBlock* B2) - : ProgramPoint(B1, B2) {} + : ProgramPoint(B1, B2, BlockEdgeKind) {} CFGBlock* getSrc() const { - return static_cast(getData1()); + return const_cast(static_cast(getData1())); } CFGBlock* getDst() const { - return static_cast(getData2()); + return const_cast(static_cast(getData2())); } static bool classof(const ProgramPoint* Location) { -- 2.7.4