Problema de checagem de tipos resolvido; mais globais eliminadas; e geracao de grafo...
[toypasc.git] / simpleprinter_visitor.c
blob5be911772ba87eef4d5fcbd64fca7919d3132a74
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include "base.h"
4 #include "simpleprinter_visitor.h"
6 Visitor *
7 simpleprinter_new()
9 Visitor *visitor = (Visitor *) malloc (sizeof(Visitor));
11 visitor->visit_program = &simpleprinter_visit;
12 visitor->visit_programdecl = &simpleprinter_visit;
13 visitor->visit_vardecl_list = &simpleprinter_visit;
14 visitor->visit_vardecl = &simpleprinter_visit;
15 visitor->visit_identifier_list = &simpleprinter_visit;
16 visitor->visit_procfunc_list = &simpleprinter_visit;
17 visitor->visit_procedure = &simpleprinter_visit;
18 visitor->visit_function = &simpleprinter_visit;
19 visitor->visit_param_list = &simpleprinter_visit;
20 visitor->visit_parameter = &simpleprinter_visit;
21 visitor->visit_statement_list = &simpleprinter_visit;
22 visitor->visit_printint_stmt = &simpleprinter_visit;
23 visitor->visit_printchar_stmt = &simpleprinter_visit;
24 visitor->visit_printbool_stmt = &simpleprinter_visit;
25 visitor->visit_printline_stmt = &simpleprinter_visit;
26 visitor->visit_assignment_stmt = &simpleprinter_visit;
27 visitor->visit_if_stmt = &simpleprinter_visit;
28 visitor->visit_while_stmt = &simpleprinter_visit;
29 visitor->visit_for_stmt = &simpleprinter_visit;
30 visitor->visit_rel_expr = &simpleprinter_visit;
31 visitor->visit_add_expr = &simpleprinter_visit;
32 visitor->visit_mul_expr = &simpleprinter_visit;
33 visitor->visit_notfactor = &simpleprinter_visit;
34 visitor->visit_call = &simpleprinter_visit;
35 visitor->visit_callparam_list = &simpleprinter_visit;
36 visitor->visit_identifier = &simpleprinter_visit;
37 visitor->visit_literal = &simpleprinter_visit;
38 visitor->visit_add_op = &simpleprinter_visit;
39 visitor->visit_mul_op = &simpleprinter_visit;
40 visitor->visit_rel_op = &simpleprinter_visit;
41 visitor->visit_not_op = &simpleprinter_visit;
43 return visitor;
46 void
47 simpleprinter_visit(struct _Visitor *visitor, struct AstNode *node)
49 int i;
50 struct AstNode *temp;
52 if (node == NULL)
53 return;
55 printf("(AstNode) %x : %s\n", node, node->name);
56 printf("kind: %d\n", node->kind);
57 printf("type: %d\n", node->type);
58 printf("value: ");
59 value_print(stdout, &node->value, node->type);
60 printf("\nlinenum: %d\n", node->linenum);
61 if (node->symbol != NULL)
62 printf("symbol: %x (\"%s\")\n", node->symbol, node->symbol->name);
64 printf("Parent: (AstNode) %x\n", node->parent);
66 if (node->children != NULL) {
67 printf("Children\n");
68 for (temp = node->children; temp != NULL; temp = temp->sibling) {
69 printf("\t(AstNode) %x", temp);
70 if (temp->name != NULL)
71 printf(" : %s", temp->name);
72 printf("\n");
75 printf("\n");
77 ast_node_accept_children(node->children, visitor);