diff options
Diffstat (limited to 'src/ast_pretty_printer.c')
-rw-r--r-- | src/ast_pretty_printer.c | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/src/ast_pretty_printer.c b/src/ast_pretty_printer.c index e2d007a..a211fa4 100644 --- a/src/ast_pretty_printer.c +++ b/src/ast_pretty_printer.c @@ -22,10 +22,12 @@ #include <stdarg.h> #include <stdio.h> -const char operation_kinds[AST_BINOP_N] = { [AST_BINOP_ADITION] = '+', - [AST_BINOP_SUBTRACTION] = '-', - [AST_BINOP_MULTIPLICATION] = '*', - [AST_BINOP_DIVISION] = '/' }; +const char *operation_kinds[AST_BINOP_N] = { + [AST_BINOP_ADITION] = "+", [AST_BINOP_SUBTRACTION] = "-", [AST_BINOP_MULTIPLICATION] = "*", + [AST_BINOP_DIVISION] = "/", [AST_BINOP_EQUAL] = "==", [AST_BINOP_NOT_EQUAL] = "!=", + [AST_BINOP_AND] = "&&", [AST_BINOP_OR] = "||", [AST_BINOP_GT] = ">", + [AST_BINOP_LT] = "<", [AST_BINOP_LT_EQUAL] = "<=", [AST_BINOP_GT_EQUAL] = ">=", +}; void ast_pretty_printer_init(ast_pretty_printer_t *printer, FILE *stream); @@ -63,6 +65,21 @@ ast_pretty_printer_print_ast(ast_pretty_printer_t *printer, ast_node_t *ast) assert(ast); switch (ast->kind) { + case AST_FUNCTION_PARAMETER: + break; + case AST_NAMESPACE: + ast_pretty_printer_printf(printer, "Namespace\n"); + ast_pretty_printer_add_indentation(printer); + { + for (size_t i = 0; i < ast->data.ns.nodes->size; ++i) { + if (i + 1 >= ast->data.ns.nodes->size) { + ast_pretty_printer_set_lst_children(printer); + } + ast_pretty_printer_print_ast(printer, vector_at(ast->data.ns.nodes, i)); + } + ast_pretty_printer_rm_indentation(printer); + } + break; case AST_IF_STMT: { ast_if_stmt_t if_stmt = ast->data.if_stmt; ast_pretty_printer_printf(printer, "IfStmt\n"); @@ -76,6 +93,7 @@ ast_pretty_printer_print_ast(ast_pretty_printer_t *printer, ast_node_t *ast) ast_pretty_printer_rm_indentation(printer); } + ast_pretty_printer_set_lst_children(printer); ast_pretty_printer_printf(printer, "body:\n"); ast_pretty_printer_add_indentation(printer); { @@ -90,7 +108,7 @@ ast_pretty_printer_print_ast(ast_pretty_printer_t *printer, ast_node_t *ast) } case AST_BINARY_OPERATION: { ast_binary_operation_t binop = ast->data.binary_operation; - ast_pretty_printer_printf(printer, "BinaryOperation operation='%c'\n", operation_kinds[binop.kind]); + ast_pretty_printer_printf(printer, "BinaryOperation operation='%s'\n", operation_kinds[binop.kind]); ast_pretty_printer_add_indentation(printer); { @@ -120,8 +138,8 @@ ast_pretty_printer_print_ast(ast_pretty_printer_t *printer, ast_node_t *ast) break; } case AST_FUNCTION_DECLARATION: { - ast_function_declaration_t function = ast->data.function; - ast_pretty_printer_printf(printer, "FunctionDecl name='" SVFMT "'\n", SVARG(&function.identifier.name)); + string_view_t function_name = ast_node_function_declaration_name(ast); + ast_pretty_printer_printf(printer, "FunctionDecl name='" SVFMT "'\n", SVARG(&function_name)); ast_pretty_printer_add_indentation(printer); { @@ -130,6 +148,7 @@ ast_pretty_printer_print_ast(ast_pretty_printer_t *printer, ast_node_t *ast) ast_pretty_printer_add_indentation(printer); { + ast_pretty_printer_set_lst_children(printer); ast_pretty_printer_print_ast(printer, ast->data.function.body); ast_pretty_printer_rm_indentation(printer); } @@ -138,8 +157,12 @@ ast_pretty_printer_print_ast(ast_pretty_printer_t *printer, ast_node_t *ast) } break; } + case AST_FUNCTION_CALL: { + ast_function_call_t var = ast->data.function_call; + ast_pretty_printer_printf(printer, "FunctionCall name='" SVFMT "'\n", SVARG(&var.identifier->name)); + break; + } case AST_BLOCK: { - ast_pretty_printer_set_lst_children(printer); ast_pretty_printer_printf(printer, "Block\n"); ast_pretty_printer_add_indentation(printer); { |