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     Data = reinterpret_cast<uintptr_t>(B1) | BlockEdgeSrcKind;
23   }
24   else if (B2->pred_size() == 1) {
25     assert (*(B2->pred_begin()) == B1);
26     Data = reinterpret_cast<uintptr_t>(B2) | BlockEdgeDstKind;
27   }
28   else
29     Data = reinterpret_cast<uintptr_t>(cfg.getBlockEdgeImpl(B1,B2))
30             | BlockEdgeAuxKind;
31 }
32 
33 CFGBlock* BlockEdge::getSrc() const {
34   switch (getKind()) {
35     default:
36       assert (false && "Invalid BlockEdgeKind.");
37       return NULL;
38 
39     case BlockEdgeSrcKind:
40       return reinterpret_cast<CFGBlock*>(getRawPtr());
41 
42     case BlockEdgeDstKind:
43       return *(reinterpret_cast<CFGBlock*>(getRawPtr())->pred_begin());
44 
45     case BlockEdgeAuxKind:
46       return reinterpret_cast<BPair*>(getRawPtr())->first;
47   }
48 }
49 
50 CFGBlock* BlockEdge::getDst() const {
51   switch (getKind()) {
52     default:
53       assert (false && "Invalid BlockEdgeKind.");
54       return NULL;
55 
56     case BlockEdgeSrcKind:
57       return *(reinterpret_cast<CFGBlock*>(getRawPtr())->succ_begin());
58 
59     case BlockEdgeDstKind:
60       return reinterpret_cast<CFGBlock*>(getRawPtr());
61 
62     case BlockEdgeAuxKind:
63       return reinterpret_cast<BPair*>(getRawPtr())->second;
64   }
65 }
66