Struct field tags

This commit is contained in:
gingerBill
2019-08-09 21:59:58 +01:00
parent 65d41d4248
commit 9c63212824
9 changed files with 127 additions and 32 deletions
+12 -8
View File
@@ -435,7 +435,9 @@ Field_Flag :: enum {
C_Vararg,
Auto_Cast,
In,
Results,
Tags,
Default_Parameters,
Typeid_Token,
}
@@ -443,18 +445,19 @@ Field_Flag :: enum {
Field_Flags :: distinct bit_set[Field_Flag];
Field_Flags_Struct :: Field_Flags{
Field_Flag.Using,
.Using,
.Tags,
};
Field_Flags_Record_Poly_Params :: Field_Flags{
Field_Flag.Typeid_Token,
.Typeid_Token,
};
Field_Flags_Signature :: Field_Flags{
Field_Flag.Ellipsis,
Field_Flag.Using,
Field_Flag.No_Alias,
Field_Flag.C_Vararg,
Field_Flag.Auto_Cast,
Field_Flag.Default_Parameters,
.Ellipsis,
.Using,
.No_Alias,
.C_Vararg,
.Auto_Cast,
.Default_Parameters,
};
Field_Flags_Signature_Params :: Field_Flags_Signature | {Field_Flag.Typeid_Token};
@@ -483,6 +486,7 @@ Field :: struct {
names: []^Expr, // Could be polymorphic
type: ^Expr,
default_value: ^Expr,
tag: token.Token,
flags: Field_Flags,
comment: ^Comment_Group,
}
+17 -7
View File
@@ -1388,19 +1388,18 @@ check_field_flag_prefixes :: proc(p: ^Parser, name_count: int, allowed_flags, se
for flag in ast.Field_Flag {
if flag notin allowed_flags && flag in flags {
using ast.Field_Flag;
#complete switch flag {
case Using:
case .Using:
error(p, p.curr_tok.pos, "'using' is not allowed within this field list");
case No_Alias:
case .No_Alias:
error(p, p.curr_tok.pos, "'#no_alias' is not allowed within this field list");
case C_Vararg:
case .C_Vararg:
error(p, p.curr_tok.pos, "'#c_vararg' is not allowed within this field list");
case Auto_Cast:
case .Auto_Cast:
error(p, p.curr_tok.pos, "'auto_cast' is not allowed within this field list");
case In:
case .In:
error(p, p.curr_tok.pos, "'in' is not allowed within this field list");
case Ellipsis, Results, Default_Parameters, Typeid_Token:
case .Tags, .Ellipsis, .Results, .Default_Parameters, .Typeid_Token:
panic("Impossible prefixes");
}
flags &~= {flag};
@@ -1540,6 +1539,7 @@ parse_field_list :: proc(p: ^Parser, follow: token.Kind, allowed_flags: ast.Fiel
type: ^ast.Expr;
default_value: ^ast.Expr;
tag: token.Token;
expect_token_after(p, token.Colon, "field list");
if p.curr_tok.kind != token.Eq {
@@ -1579,9 +1579,19 @@ parse_field_list :: proc(p: ^Parser, follow: token.Kind, allowed_flags: ast.Fiel
error(p, p.curr_tok.pos, "extra parameter after ellipsis without a default value");
}
if type != nil && default_value == nil {
if p.curr_tok.kind == token.String {
tag = expect_token(p, token.String);
if .Tags notin allowed_flags {
error(p, tag.pos, "Field tags are only allowed within structures");
}
}
}
ok := expect_field_separator(p, type);
field := new_ast_field(names, type, default_value);
field.tag = tag;
field.docs = docs;
field.flags = flags;
field.comment = p.line_comment;
+3 -2
View File
@@ -79,8 +79,9 @@ Type_Info_Tuple :: struct { // Only really used for procedures
Type_Info_Struct :: struct {
types: []^Type_Info,
names: []string,
offsets: []uintptr, // offsets may not be used in tuples
usings: []bool, // usings may not be used in tuples
offsets: []uintptr,
usings: []bool,
tags: []string,
is_packed: bool,
is_raw_union: bool,
custom_align: bool,