Static Value-Flow Analysis
GeneralType.h
Go to the documentation of this file.
1 //===- GeneralType.h -- Primitive types used in SVF--------------------------//
2 //
3 // SVF: Static Value-Flow Analysis
4 //
5 // Copyright (C) <2013-> <Yulei Sui>
6 //
7 
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
17 
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 /*
24  * GeneralType.h
25  *
26  * Created on: Feb 8, 2024
27  * Author: Jiawei Wang
28  */
29 
30 #pragma once
31 #include <cstdint>
32 #include <deque>
33 #include <iostream>
34 #include <list>
35 #include <map>
36 #include <set>
37 #include <stack>
38 #include <unordered_map>
39 #include <unordered_set>
40 #include <vector>
41 #include "Util/SparseBitVector.h"
42 
43 namespace SVF
44 {
45 typedef std::ostream OutStream;
46 typedef unsigned u32_t;
47 typedef signed s32_t;
48 typedef unsigned long long u64_t;
49 typedef signed long long s64_t;
50 typedef unsigned char u8_t;
51 typedef signed char s8_t;
52 typedef unsigned short u16_t;
53 typedef signed short s16_t;
54 
55 typedef u32_t NodeID;
56 typedef u32_t EdgeID;
57 typedef unsigned SymID;
58 typedef unsigned CallSiteID;
59 typedef unsigned ThreadID;
60 typedef s64_t APOffset;
61 
63 typedef unsigned PointsToID;
64 
66 template <class T> struct Hash;
67 
68 template <class S, class T> struct Hash<std::pair<S, T>>
69 {
70  // Pairing function from: http://szudzik.com/ElegantPairing.pdf
71  static size_t szudzik(size_t a, size_t b)
72  {
73  return a > b ? b * b + a : a * a + a + b;
74  }
75 
76  size_t operator()(const std::pair<S, T>& t) const
77  {
78  Hash<decltype(t.first)> first;
79  Hash<decltype(t.second)> second;
80  return szudzik(first(t.first), second(t.second));
81  }
82 };
83 
84 template <class T> struct Hash
85 {
86  size_t operator()(const T& t) const
87  {
88  std::hash<T> h;
89  return h(t);
90  }
91 };
92 
93 template <typename Key, typename Hash = Hash<Key>,
94  typename KeyEqual = std::equal_to<Key>,
95  typename Allocator = std::allocator<Key>>
96 using Set = std::unordered_set<Key, Hash, KeyEqual, Allocator>;
97 
98 template <typename Key, typename Value, typename Hash = Hash<Key>,
99  typename KeyEqual = std::equal_to<Key>,
100  typename Allocator = std::allocator<std::pair<const Key, Value>>>
101  using Map = std::unordered_map<Key, Value, Hash, KeyEqual, Allocator>;
102 
103  template <typename Key, typename Compare = std::less<Key>,
104  typename Allocator = std::allocator<Key>>
105  using OrderedSet = std::set<Key, Compare, Allocator>;
106 
107  template <typename Key, typename Value, typename Compare = std::less<Key>,
108  typename Allocator = std::allocator<std::pair<const Key, Value>>>
109  using OrderedMap = std::map<Key, Value, Compare, Allocator>;
110 
111  typedef std::pair<NodeID, NodeID> NodePair;
116  typedef std::vector<NodeID> NodeVector;
117  typedef std::vector<EdgeID> EdgeVector;
118  typedef std::stack<NodeID> NodeStack;
119  typedef std::list<NodeID> NodeList;
120  typedef std::deque<NodeID> NodeDeque;
121  typedef NodeSet EdgeSet;
122  typedef std::vector<u32_t> CallStrCxt;
123  typedef unsigned Version;
125  typedef std::pair<NodeID, Version> VersionedVar;
127 }
cJSON * a
Definition: cJSON.cpp:2560
const cJSON *const b
Definition: cJSON.h:255
for isBitcode
Definition: BasicTypes.h:68
unsigned CallSiteID
Definition: GeneralType.h:58
Set< Version > VersionSet
Definition: GeneralType.h:124
NodeSet EdgeSet
Definition: GeneralType.h:121
unsigned ThreadID
Definition: GeneralType.h:59
std::stack< NodeID > NodeStack
Definition: GeneralType.h:118
Set< NodeID > NodeSet
Definition: GeneralType.h:113
std::pair< NodeID, Version > VersionedVar
Definition: GeneralType.h:125
std::deque< NodeID > NodeDeque
Definition: GeneralType.h:120
unsigned long long u64_t
Definition: GeneralType.h:48
std::vector< NodeID > NodeVector
Definition: GeneralType.h:116
OrderedSet< NodeID > OrderedNodeSet
Definition: GeneralType.h:112
u32_t NodeID
Definition: GeneralType.h:55
std::vector< EdgeID > EdgeVector
Definition: GeneralType.h:117
std::set< Key, Compare, Allocator > OrderedSet
Definition: GeneralType.h:105
Set< VersionedVar > VersionedVarSet
Definition: GeneralType.h:126
Map< NodePair, NodeID > NodePairMap
Definition: GeneralType.h:115
s64_t APOffset
Definition: GeneralType.h:60
signed char s8_t
Definition: GeneralType.h:51
signed short s16_t
Definition: GeneralType.h:53
unsigned short u16_t
Definition: GeneralType.h:52
std::unordered_map< Key, Value, Hash, KeyEqual, Allocator > Map
Definition: GeneralType.h:101
std::ostream OutStream
Definition: GeneralType.h:45
signed s32_t
Definition: GeneralType.h:47
unsigned char u8_t
Definition: GeneralType.h:50
unsigned Version
Definition: GeneralType.h:123
SparseBitVector NodeBS
Definition: GeneralType.h:62
std::vector< u32_t > CallStrCxt
Definition: GeneralType.h:122
std::list< NodeID > NodeList
Definition: GeneralType.h:119
Set< NodePair > NodePairSet
Definition: GeneralType.h:114
unsigned SymID
Definition: GeneralType.h:57
unsigned u32_t
Definition: GeneralType.h:46
signed long long s64_t
Definition: GeneralType.h:49
unsigned PointsToID
Definition: GeneralType.h:63
u32_t EdgeID
Definition: GeneralType.h:56
std::map< Key, Value, Compare, Allocator > OrderedMap
Definition: GeneralType.h:109
std::pair< NodeID, NodeID > NodePair
Definition: GeneralType.h:111
std::unordered_set< Key, Hash, KeyEqual, Allocator > Set
Definition: GeneralType.h:96
size_t operator()(const std::pair< S, T > &t) const
Definition: GeneralType.h:76
static size_t szudzik(size_t a, size_t b)
Definition: GeneralType.h:71
provide extra hash function for std::pair handling
Definition: GeneralType.h:85
size_t operator()(const T &t) const
Definition: GeneralType.h:86