#include "copyright.h"
#include "cool_tree.h"
#include "tree.h"
#include "utils.h"
void Expression_class::dump_type(std::ostream &stream, int n) {
if (type) {
stream << pad(n) << ": " << type->get_string() << std::endl;
} else {
stream << pad(n) << ": _no_type" << std::endl;
}
}
void dump_line(std::ostream &stream, int n, tree_node *t) {
stream << pad(n) << "#" << t->get_line_number() << "\n";
}
void program_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_program\n";
for (int i = classes->first(); classes->more(i); i = classes->next(i)) {
classes->nth(i)->dump_with_types(stream, n + 2);
}
}
void class__class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_class\n";
dump_Symbol(stream, n + 2, name);
dump_Symbol(stream, n + 2, parent);
stream << pad(n + 2) << "\"";
print_escaped_string(stream, filename->get_string());
stream << "\"\n" << pad(n + 2) << "(\n";
for (int i = features->first(); features->more(i); i = features->next(i))
features->nth(i)->dump_with_types(stream, n + 2);
stream << pad(n + 2) << ")\n";
}
void method_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_method\n";
dump_Symbol(stream, n + 2, name);
for (int i = formals->first(); formals->more(i); i = formals->next(i))
formals->nth(i)->dump_with_types(stream, n + 2);
dump_Symbol(stream, n + 2, return_type);
expr->dump_with_types(stream, n + 2);
}
void attr_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_attr\n";
dump_Symbol(stream, n + 2, name);
dump_Symbol(stream, n + 2, type_decl);
init->dump_with_types(stream, n + 2);
}
void formal_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_formal\n";
dump_Symbol(stream, n + 2, name);
dump_Symbol(stream, n + 2, type_decl);
}
void branch_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_branch\n";
dump_Symbol(stream, n + 2, name);
dump_Symbol(stream, n + 2, type_decl);
expr->dump_with_types(stream, n + 2);
}
void assign_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_assign\n";
dump_Symbol(stream, n + 2, name);
expr->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void static_dispatch_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_static_dispatch\n";
expr->dump_with_types(stream, n + 2);
dump_Symbol(stream, n + 2, type_name);
dump_Symbol(stream, n + 2, name);
stream << pad(n + 2) << "(\n";
for (int i = actual->first(); actual->more(i); i = actual->next(i))
actual->nth(i)->dump_with_types(stream, n + 2);
stream << pad(n + 2) << ")\n";
dump_type(stream, n);
}
void dispatch_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_dispatch\n";
expr->dump_with_types(stream, n + 2);
dump_Symbol(stream, n + 2, name);
stream << pad(n + 2) << "(\n";
for (int i = actual->first(); actual->more(i); i = actual->next(i))
actual->nth(i)->dump_with_types(stream, n + 2);
stream << pad(n + 2) << ")\n";
dump_type(stream, n);
}
void cond_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_cond\n";
pred->dump_with_types(stream, n + 2);
then_exp->dump_with_types(stream, n + 2);
else_exp->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void loop_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_loop\n";
pred->dump_with_types(stream, n + 2);
body->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void typcase_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_typcase\n";
expr->dump_with_types(stream, n + 2);
for (int i = cases->first(); cases->more(i); i = cases->next(i))
cases->nth(i)->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void block_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_block\n";
for (int i = body->first(); body->more(i); i = body->next(i))
body->nth(i)->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void let_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_let\n";
dump_Symbol(stream, n + 2, identifier);
dump_Symbol(stream, n + 2, type_decl);
init->dump_with_types(stream, n + 2);
body->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void plus_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_plus\n";
e1->dump_with_types(stream, n + 2);
e2->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void sub_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_sub\n";
e1->dump_with_types(stream, n + 2);
e2->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void mul_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_mul\n";
e1->dump_with_types(stream, n + 2);
e2->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void divide_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_divide\n";
e1->dump_with_types(stream, n + 2);
e2->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void neg_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_neg\n";
e1->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void lt_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_lt\n";
e1->dump_with_types(stream, n + 2);
e2->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void eq_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_eq\n";
e1->dump_with_types(stream, n + 2);
e2->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void leq_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_leq\n";
e1->dump_with_types(stream, n + 2);
e2->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void comp_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_comp\n";
e1->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void int_const_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_int\n";
dump_Symbol(stream, n + 2, token);
dump_type(stream, n);
}
void bool_const_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_bool\n";
dump_Boolean(stream, n + 2, val);
dump_type(stream, n);
}
void string_const_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_string\n";
stream << pad(n + 2) << "\"";
print_escaped_string(stream, token->get_string());
stream << "\"\n";
dump_type(stream, n);
}
void new__class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_new\n";
dump_Symbol(stream, n + 2, type_name);
dump_type(stream, n);
}
void isvoid_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_isvoid\n";
e1->dump_with_types(stream, n + 2);
dump_type(stream, n);
}
void no_expr_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_no_expr\n";
dump_type(stream, n);
}
void object_class::dump_with_types(std::ostream &stream, int n) {
dump_line(stream, n, this);
stream << pad(n) << "_object\n";
dump_Symbol(stream, n + 2, name);
dump_type(stream, n);
}