diff options
author | Ting-Wei Lan <lantw44@gmail.com> | 2015-12-07 02:47:50 +0800 |
---|---|---|
committer | Ting-Wei Lan <lantw44@gmail.com> | 2015-12-07 02:47:50 +0800 |
commit | 9f1f1c719ced16636fa9e37d3cea5a9e782b72b6 (patch) | |
tree | a561d501947461af6059df026ee40522053f5ae5 /src/ast.c | |
parent | 39b409c9625f427966ae577aa3caa4d8caaa56a0 (diff) | |
download | compiler2015-9f1f1c719ced16636fa9e37d3cea5a9e782b72b6.tar compiler2015-9f1f1c719ced16636fa9e37d3cea5a9e782b72b6.tar.gz compiler2015-9f1f1c719ced16636fa9e37d3cea5a9e782b72b6.tar.bz2 compiler2015-9f1f1c719ced16636fa9e37d3cea5a9e782b72b6.tar.lz compiler2015-9f1f1c719ced16636fa9e37d3cea5a9e782b72b6.tar.xz compiler2015-9f1f1c719ced16636fa9e37d3cea5a9e782b72b6.tar.zst compiler2015-9f1f1c719ced16636fa9e37d3cea5a9e782b72b6.zip |
Re-add line number fields in AST nodes
It is required to show line numbers in error messages.
Diffstat (limited to 'src/ast.c')
-rw-r--r-- | src/ast.c | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -10,7 +10,7 @@ #include <stdlib.h> -CcmmcAst *ccmmc_ast_new(CcmmcAstNodeType type_node) +CcmmcAst *ccmmc_ast_new(CcmmcAstNodeType type_node, size_t line_number) { CcmmcAst *node; node = malloc(sizeof(CcmmcAst)); @@ -22,6 +22,7 @@ CcmmcAst *ccmmc_ast_new(CcmmcAstNodeType type_node) node->right_sibling = NULL; node->type_node = type_node; node->type_value = CCMMC_AST_VALUE_NONE; + node->line_number = line_number; return node; } @@ -77,32 +78,32 @@ CcmmcAst *ccmmc_ast_append_children( return parent; } -CcmmcAst *ccmmc_ast_new_id(char *lexeme, CcmmcKindId kind) +CcmmcAst *ccmmc_ast_new_id(char *lexeme, CcmmcKindId kind, size_t line_number) { - CcmmcAst *node = ccmmc_ast_new(CCMMC_AST_NODE_ID); + CcmmcAst *node = ccmmc_ast_new(CCMMC_AST_NODE_ID, line_number); node->value_id.kind = kind; node->value_id.name = lexeme; // node->value_id.symbolTableEntry = NULL; return node; } -CcmmcAst *ccmmc_ast_new_stmt(CcmmcKindStmt kind) +CcmmcAst *ccmmc_ast_new_stmt(CcmmcKindStmt kind, size_t line_number) { - CcmmcAst *node = ccmmc_ast_new(CCMMC_AST_NODE_STMT); + CcmmcAst *node = ccmmc_ast_new(CCMMC_AST_NODE_STMT, line_number); node->value_stmt.kind = kind; return node; } -CcmmcAst *ccmmc_ast_new_decl(CcmmcKindDecl kind) +CcmmcAst *ccmmc_ast_new_decl(CcmmcKindDecl kind, size_t line_number) { - CcmmcAst *node = ccmmc_ast_new(CCMMC_AST_NODE_DECL); + CcmmcAst *node = ccmmc_ast_new(CCMMC_AST_NODE_DECL, line_number); node->value_decl.kind = kind; return node; } -CcmmcAst *ccmmc_ast_new_expr(CcmmcKindExpr kind, int op_kind) +CcmmcAst *ccmmc_ast_new_expr(CcmmcKindExpr kind, int op_kind, size_t line_number) { - CcmmcAst *node = ccmmc_ast_new(CCMMC_AST_NODE_EXPR); + CcmmcAst *node = ccmmc_ast_new(CCMMC_AST_NODE_EXPR, line_number); node->value_expr.kind = kind; node->value_expr.is_const_eval = false; if (kind == CCMMC_KIND_EXPR_BINARY_OP) |