commit e5bfff86c09a0ed4a82baabe3f9bc7b91b2348a9
parent 8dfd5bd4457d7251c79135d7051750e8da5a91e4
Author: Drew DeVault <sir@cmpwn.com>
Date: Tue, 4 May 2021 13:57:25 -0400
hare::types: test embedded structs & unions
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
1 file changed, 42 insertions(+), 2 deletions(-)
diff --git a/hare/types/+test.ha b/hare/types/+test.ha
@@ -107,10 +107,50 @@ fn parse_type(in: str) ast::_type = {
assert(stype.fields[3].name == "z");
// Embedded struct
- // TODO
+ let atype = parse_type("struct {
+ x: int,
+ y: int,
+ struct {
+ z: int,
+ q: int,
+ },
+ }");
+ defer ast::type_free(atype);
+ let htype = lookup(st, &atype)!;
+ assert(htype.sz == 16);
+ assert(htype.align == 4);
+ let stype = htype._type as _struct;
+ assert(stype.fields[0].name == "q");
+ assert(stype.fields[0].offs == 12);
+ assert(stype.fields[1].name == "x");
+ assert(stype.fields[1].offs == 0);
+ assert(stype.fields[2].name == "y");
+ assert(stype.fields[2].offs == 4);
+ assert(stype.fields[3].name == "z");
+ assert(stype.fields[3].offs == 8);
// Embedded union
- // TODO
+ let atype = parse_type("struct {
+ x: int,
+ y: int,
+ union {
+ z: int,
+ q: int,
+ },
+ }");
+ defer ast::type_free(atype);
+ let htype = lookup(st, &atype)!;
+ assert(htype.sz == 12);
+ assert(htype.align == 4);
+ let stype = htype._type as _struct;
+ assert(stype.fields[0].name == "q");
+ assert(stype.fields[0].offs == 8);
+ assert(stype.fields[1].name == "x");
+ assert(stype.fields[1].offs == 0);
+ assert(stype.fields[2].name == "y");
+ assert(stype.fields[2].offs == 4);
+ assert(stype.fields[3].name == "z");
+ assert(stype.fields[3].offs == 8);
// Embedded (struct) alias
// TODO