summaryrefslogtreecommitdiffstats
path: root/src/ast.c
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2015-12-07 02:47:50 +0800
committerTing-Wei Lan <lantw44@gmail.com>2015-12-07 02:47:50 +0800
commit9f1f1c719ced16636fa9e37d3cea5a9e782b72b6 (patch)
treea561d501947461af6059df026ee40522053f5ae5 /src/ast.c
parent39b409c9625f427966ae577aa3caa4d8caaa56a0 (diff)
downloadcompiler2015-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.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/ast.c b/src/ast.c
index 5eac631..2ba1e7d 100644
--- a/src/ast.c
+++ b/src/ast.c
@@ -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)