Add where clauses to struct and union

This commit is contained in:
gingerBill
2019-09-08 12:12:41 +01:00
parent d54255505a
commit 4afc78efc6
8 changed files with 125 additions and 61 deletions
+11 -7
View File
@@ -568,13 +568,15 @@ Dynamic_Array_Type :: struct {
Struct_Type :: struct {
using node: Expr,
tok_pos: token.Pos,
poly_params: ^Field_List,
align: ^Expr,
is_packed: bool,
is_raw_union: bool,
fields: ^Field_List,
name_count: int,
tok_pos: token.Pos,
poly_params: ^Field_List,
align: ^Expr,
fields: ^Field_List,
name_count: int,
where_token: token.Token,
where_clauses: []^Expr,
is_packed: bool,
is_raw_union: bool,
}
Union_Type :: struct {
@@ -583,6 +585,8 @@ Union_Type :: struct {
poly_params: ^Field_List,
align: ^Expr,
variants: []^Expr,
where_token: token.Token,
where_clauses: []^Expr,
}
Enum_Type :: struct {
+33 -9
View File
@@ -2174,17 +2174,29 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
error(p, tok.pos, "'#raw_union' cannot also be '#packed");
}
where_token: token.Token;
where_clauses: []^ast.Expr;
if (p.curr_tok.kind == token.Where) {
where_token = expect_token(p, token.Where);
prev_level := p.expr_level;
p.expr_level = -1;
where_clauses = parse_rhs_expr_list(p);
p.expr_level = prev_level;
}
expect_token(p, token.Open_Brace);
fields, name_count = parse_field_list(p, token.Close_Brace, ast.Field_Flags_Struct);
close := expect_token(p, token.Close_Brace);
st := ast.new(ast.Struct_Type, tok.pos, end_pos(close));
st.poly_params = poly_params;
st.align = align;
st.is_packed = is_packed;
st.is_raw_union = is_raw_union;
st.fields = fields;
st.name_count = name_count;
st.poly_params = poly_params;
st.align = align;
st.is_packed = is_packed;
st.is_raw_union = is_raw_union;
st.fields = fields;
st.name_count = name_count;
st.where_token = where_token;
st.where_clauses = where_clauses;
return st;
case token.Union:
@@ -2217,6 +2229,16 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
}
p.expr_level = prev_level;
where_token: token.Token;
where_clauses: []^ast.Expr;
if (p.curr_tok.kind == token.Where) {
where_token = expect_token(p, token.Where);
prev_level := p.expr_level;
p.expr_level = -1;
where_clauses = parse_rhs_expr_list(p);
p.expr_level = prev_level;
}
variants: [dynamic]^ast.Expr;
expect_token_after(p, token.Open_Brace, "union");
@@ -2234,9 +2256,11 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
close := expect_token(p, token.Close_Brace);
ut := ast.new(ast.Union_Type, tok.pos, end_pos(close));
ut.poly_params = poly_params;
ut.variants = variants[:];
ut.align = align;
ut.poly_params = poly_params;
ut.variants = variants[:];
ut.align = align;
ut.where_token = where_token;
ut.where_clauses = where_clauses;
return ut;