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) {...@@ -537,6 +537,10 @@ static void visit_enum_decl(Context *c, const EnumDecl *enum_decl) {
537 return;537 return;
538 }538 }
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
540 const EnumDecl *enum_def = enum_decl->getDefinition();544 const EnumDecl *enum_def = enum_decl->getDefinition();
541545
542 if (!enum_def) {546 if (!enum_def) {
...@@ -553,10 +557,6 @@ static void visit_enum_decl(Context *c, const EnumDecl *enum_decl) {...@@ -553,10 +557,6 @@ static void visit_enum_decl(Context *c, const EnumDecl *enum_decl) {
553 node->data.struct_decl.visib_mod = VisibModExport;557 node->data.struct_decl.visib_mod = VisibModExport;
554 node->data.struct_decl.directives = create_empty_directives(c);558 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
561 ZigList<AstNode *> var_decls = {0};561 ZigList<AstNode *> var_decls = {0};
562 int i = 0;562 int i = 0;
...@@ -624,6 +624,11 @@ static void visit_record_decl(Context *c, const RecordDecl *record_decl) {...@@ -624,6 +624,11 @@ static void visit_record_decl(Context *c, const RecordDecl *record_decl) {
624 return;624 return;
625 }625 }
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
627 RecordDecl *record_def = record_decl->getDefinition();632 RecordDecl *record_def = record_decl->getDefinition();
628 if (!record_def) {633 if (!record_def) {
629 // this is a type that we can point to but that's it, such as `struct Foo;`.634 // 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) {...@@ -639,10 +644,6 @@ static void visit_record_decl(Context *c, const RecordDecl *record_decl) {
639 node->data.struct_decl.visib_mod = VisibModExport;644 node->data.struct_decl.visib_mod = VisibModExport;
640 node->data.struct_decl.directives = create_empty_directives(c);645 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
646 for (auto it = record_def->field_begin(),647 for (auto it = record_def->field_begin(),
647 it_end = record_def->field_end();648 it_end = record_def->field_end();
648 it != it_end; ++it)649 it != it_end; ++it)
test/run_tests.cpp+9
...@@ -1962,6 +1962,7 @@ pub const Bar = enum_Bar;)OUTPUT");...@@ -1962,6 +1962,7 @@ pub const Bar = enum_Bar;)OUTPUT");
1962void func(int array[20]);1962void func(int array[20]);
1963 )SOURCE", R"OUTPUT(pub extern fn func(array: [20]c_int);)OUTPUT");1963 )SOURCE", R"OUTPUT(pub extern fn func(array: [20]c_int);)OUTPUT");
19641964
1965
1965 add_parseh_case("self referential struct with function pointer", R"SOURCE(1966 add_parseh_case("self referential struct with function pointer", R"SOURCE(
1966struct Foo {1967struct Foo {
1967 void (*derp)(struct Foo *foo);1968 void (*derp)(struct Foo *foo);
...@@ -1969,6 +1970,14 @@ struct Foo {...@@ -1969,6 +1970,14 @@ struct Foo {
1969 )SOURCE", R"OUTPUT(export struct struct_Foo {1970 )SOURCE", R"OUTPUT(export struct struct_Foo {
1970 derp: ?extern fn (?&struct_Foo),1971 derp: ?extern fn (?&struct_Foo),
1971}1972}
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;
1972pub const Foo = struct_Foo;)OUTPUT");1981pub const Foo = struct_Foo;)OUTPUT");
1973}1982}
19741983