authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-14 15:27:42-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-14 15:27:42-07:00
log68c4f617edc2afd4f9b201b6b67248d6cb80e69d
treeef48637e2e49976c5fda6ba23b2c9f4e01e5f127
parent1645fa681f5cca05125b5aeba2bc76701c20f6bb

fix next_node_index on wrong struct

no more nondeterministic error messages closes #65

4 files changed, 12 insertions(+), 6 deletions(-)

src/all_types.hpp+1
...@@ -890,6 +890,7 @@ struct CodeGen {...@@ -890,6 +890,7 @@ struct CodeGen {
890 LLVMValueRef memcpy_fn_val;890 LLVMValueRef memcpy_fn_val;
891 LLVMValueRef memset_fn_val;891 LLVMValueRef memset_fn_val;
892 bool error_during_imports;892 bool error_during_imports;
893 uint32_t next_node_index;
893};894};
894895
895struct VariableTableEntry {896struct VariableTableEntry {
src/codegen.cpp+2-1
...@@ -2658,7 +2658,8 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *abs_full_path,...@@ -2658,7 +2658,8 @@ static ImportTableEntry *codegen_add_code(CodeGen *g, Buf *abs_full_path,
2658 import_entry->path = full_path;2658 import_entry->path = full_path;
2659 import_entry->fn_table.init(32);2659 import_entry->fn_table.init(32);
26602660
2661 import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color);2661 import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color,
2662 &g->next_node_index);
2662 assert(import_entry->root);2663 assert(import_entry->root);
2663 if (g->verbose) {2664 if (g->verbose) {
2664 ast_print(import_entry->root, 0);2665 ast_print(import_entry->root, 0);
src/parser.cpp+7-4
...@@ -401,7 +401,7 @@ struct ParseContext {...@@ -401,7 +401,7 @@ struct ParseContext {
401 ZigList<AstNode *> *directive_list;401 ZigList<AstNode *> *directive_list;
402 ImportTableEntry *owner;402 ImportTableEntry *owner;
403 ErrColor err_color;403 ErrColor err_color;
404 uint32_t next_create_index;404 uint32_t *next_node_index;
405};405};
406406
407__attribute__ ((format (printf, 4, 5)))407__attribute__ ((format (printf, 4, 5)))
...@@ -457,8 +457,8 @@ static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) {...@@ -457,8 +457,8 @@ static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) {
457 AstNode *node = allocate<AstNode>(1);457 AstNode *node = allocate<AstNode>(1);
458 node->type = type;458 node->type = type;
459 node->owner = pc->owner;459 node->owner = pc->owner;
460 node->create_index = pc->next_create_index;460 node->create_index = *pc->next_node_index;
461 pc->next_create_index += 1;461 *pc->next_node_index += 1;
462 return node;462 return node;
463}463}
464464
...@@ -2724,12 +2724,15 @@ static AstNode *ast_parse_root(ParseContext *pc, int *token_index) {...@@ -2724,12 +2724,15 @@ static AstNode *ast_parse_root(ParseContext *pc, int *token_index) {
2724 return node;2724 return node;
2725}2725}
27262726
2727AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner, ErrColor err_color) {2727AstNode *ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner,
2728 ErrColor err_color, uint32_t *next_node_index)
2729{
2728 ParseContext pc = {0};2730 ParseContext pc = {0};
2729 pc.err_color = err_color;2731 pc.err_color = err_color;
2730 pc.owner = owner;2732 pc.owner = owner;
2731 pc.buf = buf;2733 pc.buf = buf;
2732 pc.tokens = tokens;2734 pc.tokens = tokens;
2735 pc.next_node_index = next_node_index;
2733 int token_index = 0;2736 int token_index = 0;
2734 pc.root = ast_parse_root(&pc, &token_index);2737 pc.root = ast_parse_root(&pc, &token_index);
2735 return pc.root;2738 return pc.root;
src/parser.hpp+2-1
...@@ -17,7 +17,8 @@ void ast_token_error(Token *token, const char *format, ...);...@@ -17,7 +17,8 @@ void ast_token_error(Token *token, const char *format, ...);
1717
1818
19// This function is provided by generated code, generated by parsergen.cpp19// This function is provided by generated code, generated by parsergen.cpp
20AstNode * ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner, ErrColor err_color);20AstNode * ast_parse(Buf *buf, ZigList<Token> *tokens, ImportTableEntry *owner, ErrColor err_color,
21 uint32_t *next_node_index);
2122
22const char *node_type_str(NodeType node_type);23const char *node_type_str(NodeType node_type);
2324