Ted Kremenek | 33bfb5c | 2008-01-11 16:36:20 +0000 | [diff] [blame] | 1 | //= ProgramPoint.cpp - Program Points for Path-Sensitive Analysis --*- C++ -*-// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements methods for subclasses of ProgramPoint. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/AST/CFG.h" |
| 15 | #include "clang/Analysis/ProgramPoint.h" |
| 16 | |
| 17 | using namespace clang; |
| 18 | |
| 19 | BlockEdge::BlockEdge(CFG& cfg, const CFGBlock* B1, const CFGBlock* B2) { |
| 20 | if (B1->succ_size() == 1) { |
| 21 | assert (*(B1->succ_begin()) == B2); |
Argyrios Kyrtzidis | 6e5977f | 2008-04-26 15:19:51 +0000 | [diff] [blame^] | 22 | setRawData(B1, BlockEdgeSrcKind); |
Ted Kremenek | 33bfb5c | 2008-01-11 16:36:20 +0000 | [diff] [blame] | 23 | } |
| 24 | else if (B2->pred_size() == 1) { |
| 25 | assert (*(B2->pred_begin()) == B1); |
Argyrios Kyrtzidis | 6e5977f | 2008-04-26 15:19:51 +0000 | [diff] [blame^] | 26 | setRawData(B2, BlockEdgeDstKind); |
Ted Kremenek | 33bfb5c | 2008-01-11 16:36:20 +0000 | [diff] [blame] | 27 | } |
| 28 | else |
Argyrios Kyrtzidis | 6e5977f | 2008-04-26 15:19:51 +0000 | [diff] [blame^] | 29 | setRawData(cfg.getBlockEdgeImpl(B1,B2), BlockEdgeAuxKind); |
Ted Kremenek | 33bfb5c | 2008-01-11 16:36:20 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | CFGBlock* BlockEdge::getSrc() const { |
| 33 | switch (getKind()) { |
| 34 | default: |
| 35 | assert (false && "Invalid BlockEdgeKind."); |
| 36 | return NULL; |
| 37 | |
| 38 | case BlockEdgeSrcKind: |
| 39 | return reinterpret_cast<CFGBlock*>(getRawPtr()); |
| 40 | |
| 41 | case BlockEdgeDstKind: |
| 42 | return *(reinterpret_cast<CFGBlock*>(getRawPtr())->pred_begin()); |
| 43 | |
| 44 | case BlockEdgeAuxKind: |
| 45 | return reinterpret_cast<BPair*>(getRawPtr())->first; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | CFGBlock* BlockEdge::getDst() const { |
| 50 | switch (getKind()) { |
| 51 | default: |
| 52 | assert (false && "Invalid BlockEdgeKind."); |
| 53 | return NULL; |
| 54 | |
| 55 | case BlockEdgeSrcKind: |
| 56 | return *(reinterpret_cast<CFGBlock*>(getRawPtr())->succ_begin()); |
| 57 | |
| 58 | case BlockEdgeDstKind: |
| 59 | return reinterpret_cast<CFGBlock*>(getRawPtr()); |
| 60 | |
| 61 | case BlockEdgeAuxKind: |
| 62 | return reinterpret_cast<BPair*>(getRawPtr())->second; |
| 63 | } |
| 64 | } |