authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-28 21:53:46-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-28 21:53:46-07:00
log53c14da2206c74783acb792eab6085cc7d06f068
treea555c2ec6bb6e2e05d8a71f3a69765753ac919a6
parentc3516b80044732e18eedcd8cd49c424fec497bb3

parseh understands bodyless struct used in fn


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

src/parseh.cpp+9-8
......@@ -537,6 +537,10 @@ static void visit_enum_decl(Context *c, const EnumDecl *enum_decl) {
537537 return;
538538 }
539539
540 // eagerly put the name in the table, but we need to remember to remove it if it fails
541 // boy it would be nice to have defer here wouldn't it
542 c->enum_type_table.put(bare_name, true);
543
540544 const EnumDecl *enum_def = enum_decl->getDefinition();
541545
542546 if (!enum_def) {
......@@ -553,10 +557,6 @@ static void visit_enum_decl(Context *c, const EnumDecl *enum_decl) {
553557 node->data.struct_decl.visib_mod = VisibModExport;
554558 node->data.struct_decl.directives = create_empty_directives(c);
555559
556 // eagerly put the name in the table, but we need to remember to remove it if it fails
557 // boy it would be nice to have defer here wouldn't it
558 c->enum_type_table.put(bare_name, true);
559
560560
561561 ZigList<AstNode *> var_decls = {0};
562562 int i = 0;
......@@ -624,6 +624,11 @@ static void visit_record_decl(Context *c, const RecordDecl *record_decl) {
624624 return;
625625 }
626626
627 // eagerly put the name in the table, but we need to remember to remove it if it fails
628 // boy it would be nice to have defer here wouldn't it
629 c->struct_type_table.put(bare_name, true);
630
631
627632 RecordDecl *record_def = record_decl->getDefinition();
628633 if (!record_def) {
629634 // this is a type that we can point to but that's it, such as `struct Foo;`.
......@@ -639,10 +644,6 @@ static void visit_record_decl(Context *c, const RecordDecl *record_decl) {
639644 node->data.struct_decl.visib_mod = VisibModExport;
640645 node->data.struct_decl.directives = create_empty_directives(c);
641646
642 // eagerly put the name in the table, but we need to remember to remove it if it fails
643 // boy it would be nice to have defer here wouldn't it
644 c->struct_type_table.put(bare_name, true);
645
646647 for (auto it = record_def->field_begin(),
647648 it_end = record_def->field_end();
648649 it != it_end; ++it)
test/run_tests.cpp+9
......@@ -1962,6 +1962,7 @@ pub const Bar = enum_Bar;)OUTPUT");
19621962void func(int array[20]);
19631963 )SOURCE", R"OUTPUT(pub extern fn func(array: [20]c_int);)OUTPUT");
19641964
1965
19651966 add_parseh_case("self referential struct with function pointer", R"SOURCE(
19661967struct Foo {
19671968 void (*derp)(struct Foo *foo);
......@@ -1969,6 +1970,14 @@ struct Foo {
19691970 )SOURCE", R"OUTPUT(export struct struct_Foo {
19701971 derp: ?extern fn (?&struct_Foo),
19711972}
1973pub const Foo = struct_Foo;)OUTPUT");
1974
1975
1976 add_parseh_case("struct prototype used in func", R"SOURCE(
1977struct Foo;
1978struct Foo *some_func(struct Foo *foo, int x);
1979 )SOURCE", R"OUTPUT(pub const struct_Foo = u8;
1980pub extern fn some_func(foo: ?&struct_Foo, x: c_int) -> ?&struct_Foo;
19721981pub const Foo = struct_Foo;)OUTPUT");
19731982}
19741983