-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheat-baseline1-dead-code.cpp
More file actions
75 lines (65 loc) · 2.07 KB
/
cheat-baseline1-dead-code.cpp
File metadata and controls
75 lines (65 loc) · 2.07 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
#include <iostream>
#include "lang.h"
#include "transform.h"
int a = 0;
class Cheat : public Transform {
public:
Statement *transformSetStatement(SetStatement *node) override {
return ifForSure(new SetStatement(
transformVariable(node->name),
transformExpression(node->value)
));
}
Statement* transformIfStatement(IfStatement* node) override {
return new IfStatement(
transformExpression(node->condition),
ifForSure(transformStatement(node->body))
);
}
Statement* transformForStatement(ForStatement *node) override {
return new ForStatement(
transformStatement(node->init),
transformExpression(node->test),
transformStatement(node->update),
ifForSure(transformStatement(node->body))
);
}
Statement* transformBlockStatement(BlockStatement *node) override {
std::vector<Statement*> body;
for (auto stmt : node->body) {
body.push_back(transformStatement(stmt));
}
return ifForSure(new BlockStatement(body));
}
Statement* transformExpressionStatement(ExpressionStatement *node) override {
return ifForSure(new ExpressionStatement(transformExpression(node->expr)));
}
FunctionDeclaration* transformFunctionDeclaration(FunctionDeclaration *node) override {
std::vector<Variable *> params;
for (auto param : node->params) {
params.push_back(transformVariable(param));
}
Statement* body = new BlockStatement({
new SetStatement(new Variable("ppcappcappcappcappca"), new IntegerLiteral(0)),
new SetStatement(new Variable("ppcappcappcappcappcb"), new IntegerLiteral(0)),
transformStatement(node->body)
});
return new FunctionDeclaration(node->name, params, body);
}
private:
Statement* ifForSure(Statement* node) {
return new IfStatement(
new CallExpression(
"==",
{new Variable("ppcappcappcappcappca"), new Variable("ppcappcappcappcappcb")}
),
node
);
}
};
int main() {
auto code = scanProgram(std::cin);
auto cheat = Cheat().transformProgram(code);
std::cout << cheat->toString();
return 0;
}