void typecheck_visit_for_stmt (struct _Visitor *visitor, struct AstNode *node) { struct AstNode *asgn = node->children; struct AstNode *expr = asgn->sibling; struct AstNode *stmt = expr->sibling; struct AstNode *id_node = asgn->children; ast_node_accept(asgn, visitor); ast_node_accept(expr, visitor); if (id_node->type != INTEGER) { node->type = ERROR; fprintf(stderr, "Error: Identifier '%s' is of %s type; it must be Integer. " "Check line %d.\n", id_node->symbol->name, type_get_lexeme(id_node->type), id_node->linenum); } if (expr->type != INTEGER) { node->type = ERROR; fprintf(stderr, "Error: Value of stop condition is not of Integer type. " "Check line %d.\n", expr->linenum); } ast_node_accept(stmt, visitor); }
void graphprinter_visit_identifier (struct _Visitor *visitor, struct AstNode *node) { _print_arrow(node); printf("\tnode_%x [label=\"", node); if (node->symbol->decl_linenum == 0) printf("UNDECLARED\\n"); printf("%s\\n'%s'\\n<%s>\",style=filled,color=", node->name, node->symbol->name, type_get_lexeme(node->type)); if (node->symbol->decl_linenum == 0) printf(COLOR_EDGE_ERROR); else if (node->symbol->is_global) printf(COLOR_FILL_GLOBAL); else printf(COLOR_FILL_LOCAL); printf(",fillcolor="); if (node->symbol->is_global) printf(COLOR_FILL_GLOBAL); else printf(COLOR_FILL_LOCAL); printf("];\n"); }
static void _typecheck_print_stmt(AstNode* node, PrimitiveType type, const char* ptype_str) { if (node->children->type != type) { node->type = ERROR; fprintf(stderr, "Error (line %d): Expression print%s statement must be of %s type\n", node->linenum, ptype_str, type_get_lexeme(type)); } }
void graphprinter_visit_literal (struct _Visitor *visitor, struct AstNode *node) { printf("\tnode_%x -> literal_%x;\n", node->parent, node); printf("\tliteral_%x [label=\"", node); value_print(stdout, &node->value, node->type); printf("\\n<%s>\",style=filled,color="COLOR_FILL_LITERAL"];\n", node->name, type_get_lexeme(node->type)); ast_node_accept_children(node->children, visitor); }
void graphprinter_visit_callparam (struct _Visitor *visitor, struct AstNode *node) { _print_arrow(node); printf("\tnode_%x [label=\"%s\\n<%s>\",style=filled,", node, node->name, type_get_lexeme(node->type)); printf("fillcolor="COLOR_FILL_COMMON",color=%s];\n", (node->type == ERROR) ? COLOR_EDGE_ERROR : COLOR_FILL_COMMON); ast_node_accept_children(node->children, visitor); }
void typecheck_visit_callparam_list (struct _Visitor *visitor, struct AstNode *node) { int i; struct AstNode *child; node->child_counter = 0; for (child = node->children; child != NULL; child = child->sibling) node->child_counter++; if (node->symbol->params != node->child_counter) { node->type = ERROR; return; } i = 0; for (child = node->children; child != NULL; child = child->sibling) { ast_node_accept(child, visitor); if (child->type != ERROR && child->type != node->symbol->param_types[i]) { node->type = ERROR; child->type = node->symbol->param_types[i]; fprintf(stderr, "Error: Call '%s' on line %d, expecting %s " "on parameter %d (", node->symbol->name, node->linenum, type_get_lexeme(node->symbol->param_types[i]), i + 1); if (child->children->kind == IDENTIFIER) fprintf(stderr, "'%s'", child->children->symbol->name); else value_print(stderr, &child->value, child->type); fprintf(stderr, "), received %s.\n", type_get_lexeme(child->type)); } i++; } }
void graphprinter_visit_procfunc (struct _Visitor *visitor, struct AstNode *node) { _print_arrow(node); printf("\tnode_%x [label=\"%s\\n<%s>\\n[line: %d]\",style=filled,", node, node->name, type_get_lexeme(node->type), node->linenum); printf("color=blue,fillcolor="COLOR_EDGE_FUNCT"];\n"); printf("\nsubgraph cluster_%x {\n\tstyle=dotted;\n", node); _print_symbol_table(node); ast_node_accept_children(node->children, visitor); printf("}\n\n"); }
static void _print_symbols(Symbol *symbol) { if (symbol == NULL) return; if (symbol->name != NULL) { printf("\t\tsymbol_%x [shape=record,label=\"{", symbol); printf("Symbol|Address: 0x%x\\l|lexeme: %s\\l|", symbol, symbol->name); printf("type: %s\\l}\"", type_get_lexeme(symbol->type)); printf(",style=filled,color=white,fillcolor="COLOR_FILL_SYMBOL"];\n"); if (symbol->next != NULL) printf("\tsymbol_%x -> symbol_%x;\n", symbol, symbol->next); } _print_symbols(symbol->next); }
void graphprinter_visit_callparam_list (struct _Visitor *visitor, struct AstNode *node) { int i; _print_arrow(node); printf("\tnode_%x [label=\"%s\\n<", node, node->name); for (i = 0; i < node->symbol->params; i++) { printf("%s", type_get_lexeme(node->symbol->param_types[i])); if (i + 1 < node->symbol->params) printf(", "); } printf(">\",style=filled,fillcolor="COLOR_FILL_COMMON",color=%s];\n", (node->type == ERROR) ? COLOR_EDGE_ERROR : COLOR_EDGE_GROUP); ast_node_accept_children(node->children, visitor); }