authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-13 23:02:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-02-13 23:02:45-07:00
log1141e4f5b262f7490fe554cd4334ec6b1c886c5f
tree18d068ad0145d87c8579ddacf4fa9eea91f7e09b
parent01fda6199ee0e2b5f79e58cbd862bd4882615a4b

if any c imports fail, don't emit undefined identifier errors


2 files changed, 20 insertions(+), 8 deletions(-)

src/all_types.hpp+1
...@@ -992,6 +992,7 @@ struct ImportTableEntry {...@@ -992,6 +992,7 @@ struct ImportTableEntry {
992 BlockContext *block_context;992 BlockContext *block_context;
993 ZigList<ImporterInfo> importers;993 ZigList<ImporterInfo> importers;
994 AstNode *c_import_node;994 AstNode *c_import_node;
995 bool any_imports_failed;
995996
996 // reminder: hash tables must be initialized before use997 // reminder: hash tables must be initialized before use
997 HashMap<Buf *, FnTableEntry *, buf_hash, buf_eql_buf> fn_table;998 HashMap<Buf *, FnTableEntry *, buf_hash, buf_eql_buf> fn_table;
src/analyze.cpp+19-8
...@@ -1378,6 +1378,15 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *parent_import, A...@@ -1378,6 +1378,15 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *parent_import, A
1378 child_import->error_table.init(8);1378 child_import->error_table.init(8);
1379 child_import->c_import_node = node;1379 child_import->c_import_node = node;
13801380
1381 child_import->importers.append({parent_import, node});
1382
1383 if (node->data.c_import.visib_mod != VisibModPrivate) {
1384 for (int i = 0; i < parent_import->importers.length; i += 1) {
1385 ImporterInfo importer = parent_import->importers.at(i);
1386 child_import->importers.append(importer);
1387 }
1388 }
1389
1381 ZigList<ErrorMsg *> errors = {0};1390 ZigList<ErrorMsg *> errors = {0};
13821391
1383 int err;1392 int err;
...@@ -1391,6 +1400,10 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *parent_import, A...@@ -1391,6 +1400,10 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *parent_import, A
1391 ErrorMsg *err_msg = errors.at(i);1400 ErrorMsg *err_msg = errors.at(i);
1392 err_msg_add_note(parent_err_msg, err_msg);1401 err_msg_add_note(parent_err_msg, err_msg);
1393 }1402 }
1403
1404 for (int i = 0; i < child_import->importers.length; i += 1) {
1405 child_import->importers.at(i).import->any_imports_failed = true;
1406 }
1394 return;1407 return;
1395 }1408 }
13961409
...@@ -1402,14 +1415,6 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *parent_import, A...@@ -1402,14 +1415,6 @@ static void resolve_c_import_decl(CodeGen *g, ImportTableEntry *parent_import, A
14021415
1403 child_import->di_file = parent_import->di_file;1416 child_import->di_file = parent_import->di_file;
1404 child_import->block_context = new_block_context(child_import->root, nullptr);1417 child_import->block_context = new_block_context(child_import->root, nullptr);
1405 child_import->importers.append({parent_import, node});
1406
1407 if (node->data.c_import.visib_mod != VisibModPrivate) {
1408 for (int i = 0; i < parent_import->importers.length; i += 1) {
1409 ImporterInfo importer = parent_import->importers.at(i);
1410 child_import->importers.append(importer);
1411 }
1412 }
14131418
1414 detect_top_level_decl_deps(g, child_import, child_import->root);1419 detect_top_level_decl_deps(g, child_import, child_import->root);
1415 analyze_top_level_decls_root(g, child_import, child_import->root);1420 analyze_top_level_decls_root(g, child_import, child_import->root);
...@@ -2613,6 +2618,12 @@ static TypeTableEntry *analyze_symbol_expr(CodeGen *g, ImportTableEntry *import,...@@ -2613,6 +2618,12 @@ static TypeTableEntry *analyze_symbol_expr(CodeGen *g, ImportTableEntry *import,
2613 return resolve_expr_const_val_as_fn(g, node, context, fn_table_entry->value);2618 return resolve_expr_const_val_as_fn(g, node, context, fn_table_entry->value);
2614 }2619 }
26152620
2621 if (import->any_imports_failed) {
2622 // skip the error message since we had a failing import in this file
2623 // if an import breaks we don't need 9999 undeclared identifier errors
2624 return g->builtin_types.entry_invalid;
2625 }
2626
2616 add_node_error(g, node, buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name)));2627 add_node_error(g, node, buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name)));
2617 return g->builtin_types.entry_invalid;2628 return g->builtin_types.entry_invalid;
2618}2629}