-
Notifications
You must be signed in to change notification settings - Fork 0
/
tempVarCounter.cpp
38 lines (36 loc) · 1.43 KB
/
tempVarCounter.cpp
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
#include "compiler.h"
map<string, int> tempVarCounter;
void counterTempVar() {
for (auto &inter:intermediateCodeInner) {
for (auto &var:inter) {
if (!var.empty() && var.find('$') != string::npos) {
string temp;
if (var.at(0) == '$')
temp = var;
else {
vector<string> elements = boomVec(var);
if (elements.at(0).find('$') != string::npos) {
temp = elements.at(0);
}
if (elements.size() > 1 && elements.at(1).find('$') != string::npos) {
if (!temp.empty()) {
if (tempVarCounter.count(temp) == 0) {
tempVarCounter.insert(pair<string, int>(temp, 1));
} else {
int counter = tempVarCounter.at(temp);
tempVarCounter[temp] = counter + 1;
}
}
temp = elements.at(1);
}
}
if (tempVarCounter.count(temp) == 0) {
tempVarCounter.insert(pair<string, int>(temp, 1));
} else {
int counter = tempVarCounter.at(temp);
tempVarCounter[temp] = counter + 1;
}
}
}
}
}