-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.hpp
34 lines (27 loc) · 1004 Bytes
/
utils.hpp
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
#pragma once
#include "ast.hpp"
#include <iostream>
#include <locale>
#include <codecvt>
auto prettyPrintStatement(const std::unique_ptr<Statement>& statement, std::string indent) -> void {
static std::unordered_map<StatementKind, std::string> kindToText = {
{ StatementKind::Print, "Print" },
{ StatementKind::Input, "Input" },
{ StatementKind::ShiftLeft, "ShiftLeft" },
{ StatementKind::ShiftRight, "ShiftRight" },
{ StatementKind::Loop, "Loop" },
{ StatementKind::Increment, "Increment" },
{ StatementKind::Decrement, "Decrement" }
};
std::cout << indent;
std::cout << kindToText[statement->kind()] << std::endl;
indent += " ";
if (statement->kind() != StatementKind::Loop)
return;
auto& loop = dynamic_cast<LoopStatement&>(*statement);
auto& children = loop.statements;
if (children.empty())
return;
for (auto& child : children)
prettyPrintStatement(child, indent);
}