mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-01 04:10:07 +00:00
Update core:odin for union #shared_nil
This commit is contained in:
@@ -708,13 +708,19 @@ Struct_Type :: struct {
|
|||||||
name_count: int,
|
name_count: int,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Union_Type_Kind :: enum u8 {
|
||||||
|
Normal,
|
||||||
|
maybe,
|
||||||
|
no_nil,
|
||||||
|
shared_nil,
|
||||||
|
}
|
||||||
|
|
||||||
Union_Type :: struct {
|
Union_Type :: struct {
|
||||||
using node: Expr,
|
using node: Expr,
|
||||||
tok_pos: tokenizer.Pos,
|
tok_pos: tokenizer.Pos,
|
||||||
poly_params: ^Field_List,
|
poly_params: ^Field_List,
|
||||||
align: ^Expr,
|
align: ^Expr,
|
||||||
is_maybe: bool,
|
kind: Union_Type_Kind,
|
||||||
is_no_nil: bool,
|
|
||||||
where_token: tokenizer.Token,
|
where_token: tokenizer.Token,
|
||||||
where_clauses: []^Expr,
|
where_clauses: []^Expr,
|
||||||
variants: []^Expr,
|
variants: []^Expr,
|
||||||
|
|||||||
@@ -2630,8 +2630,9 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
|
|||||||
tok := expect_token(p, .Union)
|
tok := expect_token(p, .Union)
|
||||||
poly_params: ^ast.Field_List
|
poly_params: ^ast.Field_List
|
||||||
align: ^ast.Expr
|
align: ^ast.Expr
|
||||||
is_maybe: bool
|
is_maybe: bool
|
||||||
is_no_nil: bool
|
is_no_nil: bool
|
||||||
|
is_shared_nil: bool
|
||||||
|
|
||||||
if allow_token(p, .Open_Paren) {
|
if allow_token(p, .Open_Paren) {
|
||||||
param_count: int
|
param_count: int
|
||||||
@@ -2663,12 +2664,34 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
|
|||||||
error(p, tag.pos, "duplicate union tag '#%s'", tag.text)
|
error(p, tag.pos, "duplicate union tag '#%s'", tag.text)
|
||||||
}
|
}
|
||||||
is_no_nil = true
|
is_no_nil = true
|
||||||
|
case "shared_nil":
|
||||||
|
if is_shared_nil {
|
||||||
|
error(p, tag.pos, "duplicate union tag '#%s'", tag.text)
|
||||||
|
}
|
||||||
|
is_shared_nil = true
|
||||||
case:
|
case:
|
||||||
error(p, tag.pos, "invalid union tag '#%s", tag.text)
|
error(p, tag.pos, "invalid union tag '#%s", tag.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.expr_level = prev_level
|
p.expr_level = prev_level
|
||||||
|
|
||||||
|
if is_no_nil && is_maybe {
|
||||||
|
error(p, p.curr_tok.pos, "#maybe and #no_nil cannot be applied together");
|
||||||
|
}
|
||||||
|
if is_no_nil && is_shared_nil {
|
||||||
|
error(p, p.curr_tok.pos, "#shared_nil and #no_nil cannot be applied together");
|
||||||
|
}
|
||||||
|
if is_shared_nil && is_maybe {
|
||||||
|
error(p, p.curr_tok.pos, "#maybe and #shared_nil cannot be applied together");
|
||||||
|
}
|
||||||
|
|
||||||
|
union_kind := ast.Union_Type_Kind.Normal
|
||||||
|
switch {
|
||||||
|
case is_maybe: union_kind = .maybe
|
||||||
|
case is_no_nil: union_kind = .no_nil
|
||||||
|
case is_shared_nil: union_kind = .shared_nil
|
||||||
|
}
|
||||||
|
|
||||||
where_token: tokenizer.Token
|
where_token: tokenizer.Token
|
||||||
where_clauses: []^ast.Expr
|
where_clauses: []^ast.Expr
|
||||||
|
|
||||||
@@ -2699,14 +2722,15 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
|
|||||||
|
|
||||||
close := expect_closing_brace_of_field_list(p)
|
close := expect_closing_brace_of_field_list(p)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ut := ast.new(ast.Union_Type, tok.pos, end_pos(close))
|
ut := ast.new(ast.Union_Type, tok.pos, end_pos(close))
|
||||||
ut.poly_params = poly_params
|
ut.poly_params = poly_params
|
||||||
ut.variants = variants[:]
|
ut.variants = variants[:]
|
||||||
ut.align = align
|
ut.align = align
|
||||||
ut.where_token = where_token
|
ut.where_token = where_token
|
||||||
ut.where_clauses = where_clauses
|
ut.where_clauses = where_clauses
|
||||||
ut.is_maybe = is_maybe
|
ut.kind = union_kind
|
||||||
ut.is_no_nil = is_no_nil
|
|
||||||
|
|
||||||
return ut
|
return ut
|
||||||
|
|
||||||
|
|||||||
@@ -1046,8 +1046,11 @@ visit_expr :: proc(p: ^Printer, expr: ^ast.Expr, options := List_Options{}) {
|
|||||||
|
|
||||||
push_poly_params(p, v.poly_params)
|
push_poly_params(p, v.poly_params)
|
||||||
|
|
||||||
if v.is_maybe {
|
switch v.kind {
|
||||||
push_ident_token(p, "#maybe", 1)
|
case .Normal:
|
||||||
|
case .maybe: push_ident_token(p, "#maybe", 1)
|
||||||
|
case .no_nil: push_ident_token(p, "#no_nil", 1)
|
||||||
|
case .shared_nil: push_ident_token(p, "#shared_nil", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
push_where_clauses(p, v.where_clauses)
|
push_where_clauses(p, v.where_clauses)
|
||||||
|
|||||||
Reference in New Issue
Block a user