authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-11 19:09:17-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-11 19:09:17-05:00
log25a670d74e16463c7a8f91c3af91f44bf52a9e27
tree976b0e279fe21ca7407356cdf804c5cbb49b52a2
parentde9ecaf96470c9d2b9f165608a57ba03c9c0f17c

pass more tests


5 files changed, 37 insertions(+), 17 deletions(-)

src/all_types.hpp+1
...@@ -1022,6 +1022,7 @@ struct FnTableEntry {...@@ -1022,6 +1022,7 @@ struct FnTableEntry {
1022 IrExecutable analyzed_executable;1022 IrExecutable analyzed_executable;
1023 size_t prealloc_bbc;1023 size_t prealloc_bbc;
1024 AstNode **param_source_nodes;1024 AstNode **param_source_nodes;
1025 Buf **param_names;
10251026
1026 AstNode *fn_no_inline_set_node;1027 AstNode *fn_no_inline_set_node;
1027 AstNode *fn_export_set_node;1028 AstNode *fn_export_set_node;
src/ast_render.cpp+4-1
...@@ -902,10 +902,13 @@ static void ast_render_tld_fn(AstRender *ar, TldFn *tld_fn) {...@@ -902,10 +902,13 @@ static void ast_render_tld_fn(AstRender *ar, TldFn *tld_fn) {
902 fprintf(ar->f, "%s%s%s%sfn %s(", visib_mod_str, extern_str, coldcc_str, nakedcc_str, buf_ptr(&fn_entry->symbol_name));902 fprintf(ar->f, "%s%s%s%sfn %s(", visib_mod_str, extern_str, coldcc_str, nakedcc_str, buf_ptr(&fn_entry->symbol_name));
903 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {903 for (size_t i = 0; i < fn_type_id->param_count; i += 1) {
904 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];904 FnTypeParamInfo *param_info = &fn_type_id->param_info[i];
905 if (i != 0) {
906 fprintf(ar->f, ", ");
907 }
905 if (param_info->is_noalias) {908 if (param_info->is_noalias) {
906 fprintf(ar->f, "noalias ");909 fprintf(ar->f, "noalias ");
907 }910 }
908 fprintf(ar->f, "arg_%zu: %s", i, buf_ptr(&param_info->type->name));911 fprintf(ar->f, "%s: %s", buf_ptr(tld_fn->fn_entry->param_names[i]), buf_ptr(&param_info->type->name));
909 }912 }
910 if (fn_type_id->return_type->id == TypeTableEntryIdVoid) {913 if (fn_type_id->return_type->id == TypeTableEntryIdVoid) {
911 fprintf(ar->f, ");\n");914 fprintf(ar->f, ");\n");
src/ir.cpp+6
...@@ -8471,6 +8471,9 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source...@@ -8471,6 +8471,9 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
8471 FnTableEntry *fn_entry = tld_fn->fn_entry;8471 FnTableEntry *fn_entry = tld_fn->fn_entry;
8472 assert(fn_entry->type_entry);8472 assert(fn_entry->type_entry);
84738473
8474 if (fn_entry->type_entry->id == TypeTableEntryIdInvalid)
8475 return ira->codegen->builtin_types.entry_invalid;
8476
8474 // TODO instead of allocating this every time, put it in the tld value and we can reference8477 // TODO instead of allocating this every time, put it in the tld value and we can reference
8475 // the same one every time8478 // the same one every time
8476 ConstExprValue *const_val = allocate<ConstExprValue>(1);8479 ConstExprValue *const_val = allocate<ConstExprValue>(1);
...@@ -8568,6 +8571,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -8568,6 +8571,9 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
8568 } else if (is_container(child_type)) {8571 } else if (is_container(child_type)) {
8569 if (child_type->id == TypeTableEntryIdEnum) {8572 if (child_type->id == TypeTableEntryIdEnum) {
8570 ensure_complete_type(ira->codegen, child_type);8573 ensure_complete_type(ira->codegen, child_type);
8574 if (child_type->data.enumeration.is_invalid)
8575 return ira->codegen->builtin_types.entry_invalid;
8576
8571 TypeEnumField *field = find_enum_type_field(child_type, field_name);8577 TypeEnumField *field = find_enum_type_field(child_type, field_name);
8572 if (field) {8578 if (field) {
8573 if (field->type_entry->id == TypeTableEntryIdVoid) {8579 if (field->type_entry->id == TypeTableEntryIdVoid) {
src/parseh.cpp+14
...@@ -618,6 +618,20 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {...@@ -618,6 +618,20 @@ static void visit_fn_decl(Context *c, const FunctionDecl *fn_decl) {
618618
619 assert(!fn_type->data.fn.fn_type_id.is_naked);619 assert(!fn_type->data.fn.fn_type_id.is_naked);
620620
621 size_t arg_count = fn_type->data.fn.fn_type_id.param_count;
622 fn_entry->param_names = allocate<Buf *>(arg_count);
623 Buf *name_buf;
624 for (size_t i = 0; i < arg_count; i += 1) {
625 const ParmVarDecl *param = fn_decl->getParamDecl(i);
626 const char *name = decl_name(param);
627 if (strlen(name) == 0) {
628 name_buf = buf_sprintf("arg%zu", i);
629 } else {
630 name_buf = buf_create_from_str(name);
631 }
632 fn_entry->param_names[i] = name_buf;
633 }
634
621 TldFn *tld_fn = allocate<TldFn>(1);635 TldFn *tld_fn = allocate<TldFn>(1);
622 parseh_init_tld(c, &tld_fn->base, TldIdFn, fn_name);636 parseh_init_tld(c, &tld_fn->base, TldIdFn, fn_name);
623 tld_fn->fn_entry = fn_entry;637 tld_fn->fn_entry = fn_entry;
test/run_tests.cpp+12-16
...@@ -1486,11 +1486,11 @@ pub fn f() {...@@ -1486,11 +1486,11 @@ pub fn f() {
1486pub fn main(args: [][]bogus) -> %void {}1486pub fn main(args: [][]bogus) -> %void {}
1487 )SOURCE", 1, ".tmp_source.zig:2:23: error: use of undeclared identifier 'bogus'");1487 )SOURCE", 1, ".tmp_source.zig:2:23: error: use of undeclared identifier 'bogus'");
14881488
1489 add_compile_fail_case("main function with bogus args type", R"SOURCE(1489 add_compile_fail_case("for loop missing element param", R"SOURCE(
1490fn foo(blah: []u8) {1490fn foo(blah: []u8) {
1491 for (blah) { }1491 for (blah) { }
1492}1492}
1493 )SOURCE", 1, ".tmp_source.zig:3:16: error: for loop expression missing element parameter");1493 )SOURCE", 1, ".tmp_source.zig:3:5: error: for loop expression missing element parameter");
14941494
1495 add_compile_fail_case("misspelled type with pointer only reference", R"SOURCE(1495 add_compile_fail_case("misspelled type with pointer only reference", R"SOURCE(
1496const JasonHM = u8;1496const JasonHM = u8;
...@@ -1511,14 +1511,14 @@ const JsonType = enum {...@@ -1511,14 +1511,14 @@ const JsonType = enum {
1511 JSONObject,1511 JSONObject,
1512};1512};
15131513
1514pub struct JsonNode {1514pub const JsonNode = struct {
1515 kind: JsonType,1515 kind: JsonType,
1516 jobject: ?JsonOA,1516 jobject: ?JsonOA,
1517}1517};
15181518
1519fn foo() {1519fn foo() {
1520 var jll: JasonList = undefined;1520 var jll: JasonList = undefined;
1521 jll.init(&debug.global_allocator);1521 jll.init(1234);
1522 var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };1522 var jd = JsonNode {.kind = JsonType.JSONArray , .jobject = JsonOA.JSONArray {jll} };
1523}1523}
1524 )SOURCE", 2,1524 )SOURCE", 2,
...@@ -1526,7 +1526,7 @@ fn foo() {...@@ -1526,7 +1526,7 @@ fn foo() {
1526 ".tmp_source.zig:27:8: error: no member named 'init' in 'JsonNode'");1526 ".tmp_source.zig:27:8: error: no member named 'init' in 'JsonNode'");
15271527
1528 add_compile_fail_case("method call with first arg type primitive", R"SOURCE(1528 add_compile_fail_case("method call with first arg type primitive", R"SOURCE(
1529const Foo = {1529const Foo = struct {
1530 x: i32,1530 x: i32,
15311531
1532 fn init(x: i32) -> Foo {1532 fn init(x: i32) -> Foo {
...@@ -1541,12 +1541,10 @@ fn f() {...@@ -1541,12 +1541,10 @@ fn f() {
15411541
1542 derp.init();1542 derp.init();
1543}1543}
1544 )SOURCE", 2,1544 )SOURCE", 1, ".tmp_source.zig:15:5: error: expected type 'i32', found '&const Foo'");
1545 ".tmp_source.zig:15:14: error: function called as method of 'Foo', but first parameter is of type 'i32'",
1546 ".tmp_source.zig:5:5: note: function declared here");
15471545
1548 add_compile_fail_case("method call with first arg type wrong container", R"SOURCE(1546 add_compile_fail_case("method call with first arg type wrong container", R"SOURCE(
1549pub struct List {1547pub const List = struct {
1550 len: usize,1548 len: usize,
1551 allocator: &Allocator,1549 allocator: &Allocator,
15521550
...@@ -1556,23 +1554,21 @@ pub struct List {...@@ -1556,23 +1554,21 @@ pub struct List {
1556 .allocator = allocator,1554 .allocator = allocator,
1557 }1555 }
1558 }1556 }
1559}1557};
15601558
1561pub var global_allocator = Allocator {1559pub var global_allocator = Allocator {
1562 .field = 1234,1560 .field = 1234,
1563};1561};
15641562
1565pub struct Allocator {1563pub const Allocator = struct {
1566 field: i32,1564 field: i32,
1567}1565};
15681566
1569fn foo() {1567fn foo() {
1570 var x = List.init(&global_allocator);1568 var x = List.init(&global_allocator);
1571 x.init();1569 x.init();
1572}1570}
1573 )SOURCE", 2,1571 )SOURCE", 1, ".tmp_source.zig:24:5: error: expected type '&Allocator', found '&List'");
1574 ".tmp_source.zig:24:11: error: function called as method of 'List', but first parameter is of type '&Allocator'",
1575 ".tmp_source.zig:6:9: note: function declared here");
15761572
1577 add_compile_fail_case("binary not on number literal", R"SOURCE(1573 add_compile_fail_case("binary not on number literal", R"SOURCE(
1578const TINY_QUANTUM_SHIFT = 4;1574const TINY_QUANTUM_SHIFT = 4;