Skip to content

Commit e25007b

Browse files
committed
Do not store reachability_id in flow graph nodes themselves
1 parent 794a93a commit e25007b

File tree

3 files changed

+20
-30
lines changed

3 files changed

+20
-30
lines changed

src/callgraph.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,7 @@ define(function (require, exports) {
5252

5353
flowgraph.getNativeVertices().forEach(processFuncVertex);
5454

55-
// the following if condition is an ad-hoc fix to the problem of unknownVertex
56-
// details: when reach.getReachable is called, the src node's reachability_id attribute will be set
57-
// but since unknownVertex is re-used between queries, its reachability_id attribute would be already set
58-
// in the second or following calls to reach.getReachable and thus bypass the normal procedures
59-
// this ad-hoc fix checks whether unknownVertex's reachability_id attribute is undefined or not
60-
// before calling reach.getReachable
61-
let unknownVertex = flowgraph.unknownVertex();
62-
if (unknownVertex.reachability_id !== undefined) {
63-
unknownVertex.reachability_id = undefined;
64-
}
65-
var unknown_r = reach.getReachable(unknownVertex);
55+
var unknown_r = reach.getReachable(flowgraph.unknownVertex());
6656
unknown_r.forEach(function (nd) {
6757
if (nd.type === 'CalleeVertex')
6858
unknown[unknown.length] = nd;

src/dftc.js

+18-19
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (typeof define !== 'function') {
1818
}
1919

2020
define(function (require, exports) {
21-
var numset = require('./numset');
21+
const { nd2str } = require('./graph');
2222

2323
exports.reachability = function (graph, nodePred) {
2424
let enum_nodes = new Array();
@@ -27,9 +27,11 @@ define(function (require, exports) {
2727

2828
let n = nodes.length;
2929

30+
const str2rid = {};
31+
3032
for (let i = 0; i < n; i++) {
3133
enum_nodes[i] = nodes[i];
32-
nodes[i].reachability_id = i;
34+
str2rid[nd2str(nodes[i])] = i;
3335
}
3436

3537
let visited = new Array(n).fill(0),
@@ -44,18 +46,14 @@ define(function (require, exports) {
4446
t.push(new Set());
4547
}
4648

47-
function add(a, b) {
48-
return a + b;
49-
}
50-
5149
function visit1(i) {
5250
visited[i] = 1;
5351

5452
if (!nodePred || nodePred(enum_nodes[i])) {
5553
let succ = graph.succ(enum_nodes[i])
5654

5755
for (let j= 0; j < succ.length; j++) {
58-
let index = succ[j].reachability_id;
56+
let index = str2rid[nd2str(succ[j])];
5957
if (nodePred && !nodePred(succ[j]))
6058
continue;
6159
if (m[i].has(index) || t[i].has(index))
@@ -103,7 +101,7 @@ define(function (require, exports) {
103101
let succ = graph.succ(enum_nodes[i])
104102

105103
for (let j= 0; j < succ.length; j++) {
106-
let index = succ[j].reachability_id;
104+
let index = str2rid[nd2str(succ[j])];
107105
if (nodePred && !nodePred(succ[j]))
108106
return;
109107
if (visited2[index] == 0 && t[index].size !== 0)
@@ -116,17 +114,17 @@ define(function (require, exports) {
116114
}
117115
return {
118116
getReachable: function (src) {
119-
var src_id = src.reachability_id;
120-
if (src_id === undefined) {
117+
const nodeStr = nd2str(src);
118+
if (!(nodeStr in str2rid)) {
121119
enum_nodes.push(src);
122120
visited.push(0);
123121
visited2.push(0);
124122
popped.push(0);
125123
m.push(new Set());
126124
t.push(new Set());
127-
src.reachability_id = enum_nodes.length - 1;
128-
src_id = src.reachability_id;
125+
str2rid[nodeStr] = enum_nodes.length - 1;
129126
}
127+
const src_id = str2rid[nodeStr];
130128

131129
if (visited[src_id] == 0)
132130
visit1(src_id);
@@ -143,17 +141,18 @@ define(function (require, exports) {
143141
return ret;
144142
},
145143
iterReachable: function (src, cb) {
146-
var src_id = src.reachability_id;
147-
if (src_id === undefined) {
144+
const nodeStr = nd2str(src);
145+
if (!(nodeStr in str2rid)) {
148146
enum_nodes.push(src);
149147
visited.push(0);
150148
visited2.push(0);
151149
popped.push(0);
152150
m.push(new Set());
153151
t.push(new Set());
154-
src.reachability_id = enum_nodes.length - 1;
155-
src_id = src.reachability_id;
152+
str2rid[nodeStr] = enum_nodes.length - 1;
156153
}
154+
const src_id = str2rid[nodeStr];
155+
157156
if (visited[src_id] == 0)
158157
visit1(src_id);
159158

@@ -165,8 +164,8 @@ define(function (require, exports) {
165164
cb(enum_nodes[elem]);
166165
},
167166
reaches: function (src, dest) {
168-
var src_id = src.reachability_id,
169-
dest_id = dest.reachability_id;
167+
const src_id = str2rid[nd2str(src)];
168+
const dest_id = str2rid[nd2str(dest)];
170169

171170
if (visited[src_id] == 0)
172171
visit1(src_id);
@@ -175,7 +174,7 @@ define(function (require, exports) {
175174
for (let elem of t[src_id].values())
176175
tc.add(elem);
177176

178-
return tc.has(des_id);
177+
return tc.has(dest_id);
179178
}
180179
};
181180
};

src/graph.js

+1
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,6 @@ define(function (require, exports) {
208208
}
209209

210210
exports.Graph = Graph;
211+
exports.nd2str = nodeToString;
211212
return exports;
212213
});

0 commit comments

Comments
 (0)