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);
22     setRawData(B1, BlockEdgeSrcKind);
23   }
24   else if (B2->pred_size() == 1) {
25     assert (*(B2->pred_begin()) == B1);
26     setRawData(B2, BlockEdgeDstKind);
27   }
28   else
29     setRawData(cfg.getBlockEdgeImpl(B1,B2), BlockEdgeAuxKind);
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 }
65