-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParserGraphs.cpp
More file actions
164 lines (145 loc) · 4.79 KB
/
ParserGraphs.cpp
File metadata and controls
164 lines (145 loc) · 4.79 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "ParserGraphs.h"
void WhereConditionGraph::init(WhereCondition* wc) {
mGraph = NULL;
if (wc->type == WHERE_FILENAME_TYPE) {
type = wc->type;
nodeAttributes = new unordered_map<int, unordered_map<string, string>>();
edgeAttributes = new unordered_map<int, unordered_map<int, unordered_map<string, string>>>();
outedges = new vector<unordered_map<int, vector<string>>>();
inedges = new vector<unordered_map<int, vector<string>>>();
nodeLabels = new vector<string>();
unordered_map<int, unordered_map<string, unordered_set<string>>> commna;
unordered_map<int, unordered_map<int, unordered_map<string, unordered_set<string>>>> commea;
string filename = wc->filename->substr(1, (int)wc->filename->size() - 2);
loadPatternGraph(filename, nodes, *nodeAttributes, *edgeAttributes, *outedges, *inedges, nodeLabels);
}
else if (wc->type == WHERE_FIRSTORDER_TYPE) {
type = wc->type;
// generateFirstOrderStatGraph(wc->firstOrderStat);
}
}
void WhereConditionGraph::loadPatternGraph(string filename, vector<int>& nodes
, unordered_map<int, unordered_map<string, string>>& nodeAttributes
, unordered_map<int, unordered_map<int, unordered_map<string, string>>>& edgeAttributes
, vector<unordered_map<int, vector<string>>>& outedges
, vector<unordered_map<int, vector<string>>>& inedges, vector<string>* nodeLabels)
{
fstream infile(filename);
string buff = "";
int nodenum, edgenum, type;
infile >> nodenum >> edgenum >> type;
nodeLabels->resize(nodenum + 1);
outedges.resize(nodenum + 1);
inedges.resize(nodenum + 1);
nodeAttributes.clear();
edgeAttributes.clear();
for (int i = 1; i <= nodenum; ++i) {
int nodeid, attrnum;
string nlabel;
infile >> nodeid >> nlabel >> attrnum;
(*nodeLabels)[nodeid] = nlabel;
if (attrnum != 0) {
for (int j = 0; j < attrnum; ++j) {
string attrname;
string attrval;
infile >> attrname >> attrval;
nodeAttributes[nodeid][attrname] = attrval;
}
}
nodes.push_back(nodeid);
}
if (type == 0) {
for (int i = 0; i < edgenum; ++i) {
int src, dst, eattrnum;
string elabel;
infile >> src >> dst >> elabel >> eattrnum;
outedges[src][dst].push_back(elabel);
outedges[dst][src].push_back(elabel);
if (eattrnum != 0) {
for (int j = 0; j < eattrnum; ++j) {
string attrname;
string attrval;
infile >> attrname >> attrval;
edgeAttributes[src][dst][attrname] = attrval;
edgeAttributes[dst][src][attrname] = attrval;
}
}
}
}
else {
for (int i = 0; i < edgenum; ++i) {
int src, dst, eattrnum;
string elabel;
infile >> src >> dst >> elabel >> eattrnum;
outedges[src][dst].push_back(elabel);
if (eattrnum != 0) {
for (int j = 0; j < eattrnum; ++j) {
string attrname;
string attrval;
infile >> attrname >> attrval;
edgeAttributes[src][dst][attrname] = attrval;
}
}
}
}
}
void WhereConditionGraph::loadComboParameter(string filename, unordered_map<string, string>& paras) {
ifstream input(filename, ios::in);
string item, value;
while (input >> item >> value) {
paras[item] = value;
}
input.close();
}
void WhereConditionGraph::convert(GraphSchema& gschema) {
vector<unordered_map<int, vector<int>>> outedges_i(outedges->size());
vector<unordered_map<int, vector<int>>> inedges_i(inedges->size());
vector<int> nodeLabels_i(nodeLabels->size());
for (int i = 0; i < outedges->size(); ++i) {
for (const auto& oe : (*outedges)[i]) {
int node1 = i;
int node2 = oe.first;
for (int j = 0; j < oe.second.size(); ++j) {
outedges_i[node1][node2].push_back(gschema.edgenamemap[oe.second[j]]);
}
}
}
for (int i = 0; i < inedges->size(); ++i) {
for (const auto& ie : (*inedges)[i]) {
int node1 = i;
int node2 = ie.first;
for (int j = 0; j < ie.second.size(); ++j) {
inedges_i[node1][node2].push_back(gschema.edgenamemap[ie.second[j]]);
}
}
}
for (int i = 1; i < nodeLabels->size(); ++i) {
nodeLabels_i[i] = gschema.nodenamemap[(*nodeLabels)[i]];
}
if (mGraph != NULL)
delete mGraph;
mGraph = new MemoryGraph(nodes, nodeAttributes, edgeAttributes, &outedges_i, &inedges_i, gschema.nodenum, &nodeLabels_i, true);
}
void WhereConditionGraph::generateFirstOrderStatGraph(FirstOrderStat* fos) {
if (fos->type == FIRST_ORDER_STAT_UNIT_TYPE) {
analyzeFirstOrderUnit(fos->firstOrderUnit);
}
}
void WhereConditionGraph::analyzeFirstOrderUnit(FirstOrderUnit* fou) {
if (fou->type == FUNC_TYPE) {
string funcname = fou->funcstat->funcName;
if (!fou->funcstat->objList.empty()) {
string first = fou->funcstat->objList[0];
if (first.substr(0, 7) == "'-file ") {
related_file = first.substr(7, first.size() - 8);
type = 1;
}
}
}
}
void FromConditionGraph::init(FromCondition* fc) {
if (fc->type == FROM_OPERATOR_GSET && fc->operatorGSet->type == GSET_GSID_TYPE) {
type = 0;
gsid = *fc->operatorGSet->gsid;
}
}