aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/ProgramPoint.cpp
blob: d95680ff38928e7a95ecaaba58a2d99e8ae5dee8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//= ProgramPoint.cpp - Program Points for Path-Sensitive Analysis --*- C++ -*-//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This file implements methods for subclasses of ProgramPoint.
//
//===----------------------------------------------------------------------===//

#include "clang/AST/CFG.h"
#include "clang/Analysis/ProgramPoint.h"

using namespace clang;

BlockEdge::BlockEdge(CFG& cfg, const CFGBlock* B1, const CFGBlock* B2) {    
  if (B1->succ_size() == 1) {
    assert (*(B1->succ_begin()) == B2);
    setRawData(B1, BlockEdgeSrcKind);
  }
  else if (B2->pred_size() == 1) {
    assert (*(B2->pred_begin()) == B1);
    setRawData(B2, BlockEdgeDstKind);
  }
  else 
    setRawData(cfg.getBlockEdgeImpl(B1,B2), BlockEdgeAuxKind);
}

CFGBlock* BlockEdge::getSrc() const {
  switch (getKind()) {
    default:
      assert (false && "Invalid BlockEdgeKind.");
      return NULL;
      
    case BlockEdgeSrcKind:
      return reinterpret_cast<CFGBlock*>(getRawPtr());
      
    case BlockEdgeDstKind:
      return *(reinterpret_cast<CFGBlock*>(getRawPtr())->pred_begin());        
      
    case BlockEdgeAuxKind:
      return reinterpret_cast<BPair*>(getRawPtr())->first;
  }
}

CFGBlock* BlockEdge::getDst() const {
  switch (getKind()) {
    default:
      assert (false && "Invalid BlockEdgeKind.");
      return NULL;
      
    case BlockEdgeSrcKind:
      return *(reinterpret_cast<CFGBlock*>(getRawPtr())->succ_begin());
      
    case BlockEdgeDstKind:
      return reinterpret_cast<CFGBlock*>(getRawPtr());
      
    case BlockEdgeAuxKind:
      return reinterpret_cast<BPair*>(getRawPtr())->second;
  }
}