-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPointerAnalysisFlow.cpp
More file actions
executable file
·141 lines (125 loc) · 3.84 KB
/
PointerAnalysisFlow.cpp
File metadata and controls
executable file
·141 lines (125 loc) · 3.84 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* PointerAnalysisFlow.cpp
*
* Created on: 2014-05-29
* Author: jtestard
*/
#include "PointerAnalysisFlow.h"
/*
* Flows are equal if their values are equal
*/
bool PointerAnalysisFlow::equals(Flow* otherSuper) {
PointerAnalysisFlow* other = static_cast<PointerAnalysisFlow*>(otherSuper);
if (this->isBasic() || other->isBasic())
return this->basicEquals(other);
if (other->value.size()!=this->value.size())
return false;
for (map<string, set<string> >::const_iterator it = this->value.begin(); it != this->value.end() ; it++) {
string key = it->first;
set<string> thisSet = it->second;
//Check if key is found in other
if(other->value.find(key)==other->value.end())
return false;
set<string> otherSet = other->value.find(key)->second;
for (set<string>::iterator it=thisSet.begin(); it!=thisSet.end(); ++it) {
if(otherSet.find(*it)==otherSet.end()){
return false;
}
}
}
return true;
}
//Represents a pointer analysis value as a JSON string.
string PointerAnalysisFlow::jsonString() {
if (value.size()==0)
return "\"" + basic + "\"";
//Value has something inside
stringstream ss;
map<string, set<string> >::const_iterator it = this->value.begin();
ss << "{\"" << it->first << "\" : [ ";
set<string>::iterator its=it->second.begin();
if (its != it->second.end()) {
ss << *its << " "; its++;
}
for (; its != it->second.end() ; its++) {
ss << ", " << *its;
}
//errs() << "number of keys in set : " << it->second.size() << "\n";
ss << " ] ";
if (it != this->value.end())
it++;
for (; it != this->value.end() ; it++) {
if (it->second.size()==0)
continue;
ss << ", \"" << it->first << "\" : [ ";
its=it->second.begin();
if (its != it->second.end()) {
ss << *its << " ";
its++;
}
for (; its != it->second.end() ; its++) {
ss << ", " << *its;
}
ss << "] ";
}
ss << "}";
return ss.str();
}
void PointerAnalysisFlow::copy(Flow* rhs) {
PointerAnalysisFlow* f = static_cast<PointerAnalysisFlow*>(rhs);
this->basic = f->basic;
this->value = f->value;
}
PointerAnalysisFlow::PointerAnalysisFlow() :
Flow() {
}
PointerAnalysisFlow::PointerAnalysisFlow(string input) :
Flow(input) {
}
PointerAnalysisFlow::PointerAnalysisFlow(PointerAnalysisFlow *flow) :
Flow(flow) {
this->value = flow->value;
}
//Merges flow together.
Flow* PointerAnalysisFlow::join(Flow* otherSuper) {
//join bottom-bottom gives you bottom. Anything else gives you top.
PointerAnalysisFlow* other = static_cast<PointerAnalysisFlow*>(otherSuper);
if (this->basic == BOTTOM && other->basic == BOTTOM)
return new PointerAnalysisFlow(BOTTOM);
//Anything joined with a bottom will just be itself.
if (this->basic == BOTTOM) {
PointerAnalysisFlow* f = new PointerAnalysisFlow();
f->copy(other);
return f;
}
if (other->basic == BOTTOM) {
PointerAnalysisFlow* f = new PointerAnalysisFlow();
f->copy(this);
return f;
}
//Join anything with top will give you top.
if (this->basic == TOP || other->basic == TOP)
return new PointerAnalysisFlow(TOP);
//Merge the input from both.
PointerAnalysisFlow* f = new PointerAnalysisFlow();
//Get all keys
set<string> keys;
for (map<string, set<string> >::iterator it = this->value.begin() ; it != this->value.end() ; it++)
keys.insert(it->first);
for (map<string, set<string> >::iterator it = other->value.begin() ; it != other->value.end() ; it++)
keys.insert(it->first);
for (set<string>::iterator it = keys.begin() ; it != keys.end() ; it++) {
string key = *it;
set<string> values;
for (set<string>::iterator j = this->value[key].begin(); j != this->value[key].end() ; j++)
values.insert(*j);
for (set<string>::iterator j = other->value[key].begin(); j != other->value[key].end() ; j++)
values.insert(*j);
if (values.size()>0)
f->value[key] = values;
}
return f;
}
PointerAnalysisFlow::~PointerAnalysisFlow() {
//Nothing for basic static analysis
}