-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixer.cpp
More file actions
68 lines (57 loc) · 1.68 KB
/
fixer.cpp
File metadata and controls
68 lines (57 loc) · 1.68 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
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
const std::string header_file = "Syntax/Absyn.H";
const std::string source_file = "Syntax/Absyn.C";
void fix_header() {
std::ifstream fin(header_file);
std::string file, line;
while (getline(fin, line)) {
if (line.size() >= 10 && line.substr(0, 10) == "class List" && line.back() != ';') {
std::stringstream sline(line);
std::string name;
sline >> name >> name;
file += line + "\n";
getline(fin, line);
file += line + "\n";
getline(fin, line);
file += line + "\n";
file += " " + name + "();\n";
file += " " + name + "(const " + name + " &);\n";
}
else {
file += line + "\n";
}
}
fin.close();
std::ofstream fout(header_file);
fout << file;
fout.close();
}
void fix_source() {
std::ifstream fin(source_file);
std::string file, line;
while (getline(fin, line)) {
if (line.size() >= 28 && line.substr(0, 28) == "/******************** List") {
std::stringstream sline(line);
std::string name;
sline >> name >> name;
file += line + "\n\n";
file += name + "::" + name + "() { }\n\n";
file += name + "::" + name + "(const " + name + " & other) {\n for (auto i : other)\n push_back(i->clone());\n}\n";
}
else {
file += line + "\n";
}
}
fin.close();
std::ofstream fout(source_file);
fout << file;
fout.close();
}
int main() {
fix_header();
fix_source();
return 0;
}