mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Remove bit_field keyword and parsing logic
This commit is contained in:
@@ -713,15 +713,6 @@ Enum_Type :: struct {
|
|||||||
is_using: bool,
|
is_using: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
Bit_Field_Type :: struct {
|
|
||||||
using node: Expr,
|
|
||||||
tok_pos: tokenizer.Pos,
|
|
||||||
align: ^Expr,
|
|
||||||
open: tokenizer.Pos,
|
|
||||||
fields: []^Field_Value, // Field_Value with ':' rather than '='
|
|
||||||
close: tokenizer.Pos,
|
|
||||||
}
|
|
||||||
|
|
||||||
Bit_Set_Type :: struct {
|
Bit_Set_Type :: struct {
|
||||||
using node: Expr,
|
using node: Expr,
|
||||||
tok_pos: tokenizer.Pos,
|
tok_pos: tokenizer.Pos,
|
||||||
|
|||||||
@@ -269,8 +269,6 @@ clone_node :: proc(node: ^Node) -> ^Node {
|
|||||||
case Enum_Type:
|
case Enum_Type:
|
||||||
r.base_type = clone(r.base_type);
|
r.base_type = clone(r.base_type);
|
||||||
r.fields = clone(r.fields);
|
r.fields = clone(r.fields);
|
||||||
case Bit_Field_Type:
|
|
||||||
r.fields = clone(r.fields);
|
|
||||||
case Bit_Set_Type:
|
case Bit_Set_Type:
|
||||||
r.elem = clone(r.elem);
|
r.elem = clone(r.elem);
|
||||||
r.underlying = clone(r.underlying);
|
r.underlying = clone(r.underlying);
|
||||||
|
|||||||
@@ -387,13 +387,6 @@ walk :: proc(v: ^Visitor, node: ^Node) {
|
|||||||
walk(v, n.base_type);
|
walk(v, n.base_type);
|
||||||
}
|
}
|
||||||
walk_expr_list(v, n.fields);
|
walk_expr_list(v, n.fields);
|
||||||
case Bit_Field_Type:
|
|
||||||
if n.align != nil {
|
|
||||||
walk(v, n.align);
|
|
||||||
}
|
|
||||||
for x in n.fields {
|
|
||||||
walk(v, x);
|
|
||||||
}
|
|
||||||
case Bit_Set_Type:
|
case Bit_Set_Type:
|
||||||
walk(v, n.elem);
|
walk(v, n.elem);
|
||||||
if n.underlying != nil {
|
if n.underlying != nil {
|
||||||
|
|||||||
@@ -415,7 +415,7 @@ is_semicolon_optional_for_node :: proc(p: ^Parser, node: ^ast.Node) -> bool {
|
|||||||
return is_semicolon_optional_for_node(p, n.type);
|
return is_semicolon_optional_for_node(p, n.type);
|
||||||
case ast.Pointer_Type:
|
case ast.Pointer_Type:
|
||||||
return is_semicolon_optional_for_node(p, n.elem);
|
return is_semicolon_optional_for_node(p, n.elem);
|
||||||
case ast.Struct_Type, ast.Union_Type, ast.Enum_Type, ast.Bit_Field_Type:
|
case ast.Struct_Type, ast.Union_Type, ast.Enum_Type:
|
||||||
// Require semicolon within a procedure body
|
// Require semicolon within a procedure body
|
||||||
return p.curr_proc == nil;
|
return p.curr_proc == nil;
|
||||||
case ast.Proc_Lit:
|
case ast.Proc_Lit:
|
||||||
@@ -2538,59 +2538,6 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
|
|||||||
et.close = close.pos;
|
et.close = close.pos;
|
||||||
return et;
|
return et;
|
||||||
|
|
||||||
case .Bit_Field:
|
|
||||||
tok := expect_token(p, .Bit_Field);
|
|
||||||
|
|
||||||
fields: [dynamic]^ast.Field_Value;
|
|
||||||
align: ^ast.Expr;
|
|
||||||
|
|
||||||
prev_level := p.expr_level;
|
|
||||||
p.expr_level = -1;
|
|
||||||
|
|
||||||
for allow_token(p, .Hash) {
|
|
||||||
tag := expect_token_after(p, .Ident, "#");
|
|
||||||
switch tag.text {
|
|
||||||
case "align":
|
|
||||||
if align != nil {
|
|
||||||
error(p, tag.pos, "duplicate bit_field tag '#%s", tag.text);
|
|
||||||
}
|
|
||||||
align = parse_expr(p, true);
|
|
||||||
case:
|
|
||||||
error(p, tag.pos, "invalid bit_field tag '#%s", tag.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
p.expr_level = prev_level;
|
|
||||||
|
|
||||||
open := expect_token_after(p, .Open_Brace, "bit_field");
|
|
||||||
|
|
||||||
for p.curr_tok.kind != .Close_Brace && p.curr_tok.kind != .EOF {
|
|
||||||
name := parse_ident(p);
|
|
||||||
colon := expect_token(p, .Colon);
|
|
||||||
value := parse_expr(p, true);
|
|
||||||
|
|
||||||
fv := ast.new(ast.Field_Value, name.pos, value.end);
|
|
||||||
fv.field = name;
|
|
||||||
fv.sep = colon.pos;
|
|
||||||
fv.value = value;
|
|
||||||
append(&fields, fv);
|
|
||||||
|
|
||||||
if !allow_token(p, .Comma) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close := expect_token(p, .Close_Brace);
|
|
||||||
|
|
||||||
bft := ast.new(ast.Bit_Field_Type, tok.pos, end_pos(close));
|
|
||||||
bft.tok_pos = tok.pos;
|
|
||||||
bft.open = open.pos;
|
|
||||||
bft.fields = fields[:];
|
|
||||||
bft.close = close.pos;
|
|
||||||
bft.align = align;
|
|
||||||
|
|
||||||
return bft;
|
|
||||||
|
|
||||||
case .Bit_Set:
|
case .Bit_Set:
|
||||||
tok := expect_token(p, .Bit_Set);
|
tok := expect_token(p, .Bit_Set);
|
||||||
open := expect_token(p, .Open_Bracket);
|
open := expect_token(p, .Open_Bracket);
|
||||||
@@ -2719,7 +2666,6 @@ is_literal_type :: proc(expr: ^ast.Expr) -> bool {
|
|||||||
ast.Enum_Type,
|
ast.Enum_Type,
|
||||||
ast.Dynamic_Array_Type,
|
ast.Dynamic_Array_Type,
|
||||||
ast.Map_Type,
|
ast.Map_Type,
|
||||||
ast.Bit_Field_Type,
|
|
||||||
ast.Bit_Set_Type,
|
ast.Bit_Set_Type,
|
||||||
ast.Call_Expr:
|
ast.Call_Expr:
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -134,7 +134,6 @@ Token_Kind :: enum u32 {
|
|||||||
Struct, // struct
|
Struct, // struct
|
||||||
Union, // union
|
Union, // union
|
||||||
Enum, // enum
|
Enum, // enum
|
||||||
Bit_Field, // bit_field
|
|
||||||
Bit_Set, // bit_set
|
Bit_Set, // bit_set
|
||||||
Map, // map
|
Map, // map
|
||||||
Dynamic, // dynamic
|
Dynamic, // dynamic
|
||||||
@@ -261,7 +260,6 @@ tokens := [Token_Kind.COUNT]string {
|
|||||||
"struct",
|
"struct",
|
||||||
"union",
|
"union",
|
||||||
"enum",
|
"enum",
|
||||||
"bit_field",
|
|
||||||
"bit_set",
|
"bit_set",
|
||||||
"map",
|
"map",
|
||||||
"dynamic",
|
"dynamic",
|
||||||
|
|||||||
@@ -201,7 +201,6 @@ bool is_type_distinct(Ast *node) {
|
|||||||
case Ast_StructType:
|
case Ast_StructType:
|
||||||
case Ast_UnionType:
|
case Ast_UnionType:
|
||||||
case Ast_EnumType:
|
case Ast_EnumType:
|
||||||
case Ast_BitFieldType:
|
|
||||||
case Ast_ProcType:
|
case Ast_ProcType:
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|||||||
@@ -10175,7 +10175,6 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
|
|||||||
case Ast_MapType:
|
case Ast_MapType:
|
||||||
case Ast_OpaqueType:
|
case Ast_OpaqueType:
|
||||||
case Ast_BitSetType:
|
case Ast_BitSetType:
|
||||||
case Ast_BitFieldType:
|
|
||||||
o->mode = Addressing_Type;
|
o->mode = Addressing_Type;
|
||||||
o->type = check_type(c, node);
|
o->type = check_type(c, node);
|
||||||
break;
|
break;
|
||||||
@@ -10594,21 +10593,6 @@ gbString write_expr_to_string(gbString str, Ast *node, bool shorthand) {
|
|||||||
str = write_expr_to_string(str, at->elem, shorthand);
|
str = write_expr_to_string(str, at->elem, shorthand);
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(bf, BitFieldType, node);
|
|
||||||
str = gb_string_appendc(str, "bit_field ");
|
|
||||||
if (bf->align) {
|
|
||||||
str = gb_string_appendc(str, "#align ");
|
|
||||||
str = write_expr_to_string(str, bf->align, shorthand);
|
|
||||||
}
|
|
||||||
str = gb_string_appendc(str, "{");
|
|
||||||
if (shorthand) {
|
|
||||||
str = gb_string_appendc(str, "...");
|
|
||||||
} else {
|
|
||||||
str = write_struct_fields_to_string(str, bf->fields);
|
|
||||||
}
|
|
||||||
str = gb_string_appendc(str, "}");
|
|
||||||
case_end;
|
|
||||||
|
|
||||||
case_ast_node(bs, BitSetType, node);
|
case_ast_node(bs, BitSetType, node);
|
||||||
str = gb_string_appendc(str, "bit_set[");
|
str = gb_string_appendc(str, "bit_set[");
|
||||||
str = write_expr_to_string(str, bs->elem, shorthand);
|
str = write_expr_to_string(str, bs->elem, shorthand);
|
||||||
|
|||||||
@@ -3517,12 +3517,6 @@ bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_t
|
|||||||
return true;
|
return true;
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
case_ast_node(et, BitFieldType, e);
|
|
||||||
error(e, "'bit_field' types have now been removed");
|
|
||||||
error_line("\tSuggestion: package math/bits 'bitfield_extract' and 'bitfield_insert' are better replacements\n");
|
|
||||||
return false;
|
|
||||||
case_end;
|
|
||||||
|
|
||||||
case_ast_node(bs, BitSetType, e);
|
case_ast_node(bs, BitSetType, e);
|
||||||
*type = alloc_type_bit_set();
|
*type = alloc_type_bit_set();
|
||||||
set_base_type(named_type, *type);
|
set_base_type(named_type, *type);
|
||||||
|
|||||||
@@ -333,7 +333,6 @@ void check_open_scope(CheckerContext *c, Ast *node) {
|
|||||||
case Ast_StructType:
|
case Ast_StructType:
|
||||||
case Ast_EnumType:
|
case Ast_EnumType:
|
||||||
case Ast_UnionType:
|
case Ast_UnionType:
|
||||||
case Ast_BitFieldType:
|
|
||||||
case Ast_BitSetType:
|
case Ast_BitSetType:
|
||||||
scope->flags |= ScopeFlag_Type;
|
scope->flags |= ScopeFlag_Type;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -100,7 +100,6 @@ Token ast_token(Ast *node) {
|
|||||||
case Ast_StructType: return node->StructType.token;
|
case Ast_StructType: return node->StructType.token;
|
||||||
case Ast_UnionType: return node->UnionType.token;
|
case Ast_UnionType: return node->UnionType.token;
|
||||||
case Ast_EnumType: return node->EnumType.token;
|
case Ast_EnumType: return node->EnumType.token;
|
||||||
case Ast_BitFieldType: return node->BitFieldType.token;
|
|
||||||
case Ast_BitSetType: return node->BitSetType.token;
|
case Ast_BitSetType: return node->BitSetType.token;
|
||||||
case Ast_MapType: return node->MapType.token;
|
case Ast_MapType: return node->MapType.token;
|
||||||
}
|
}
|
||||||
@@ -417,10 +416,6 @@ Ast *clone_ast(Ast *node) {
|
|||||||
n->EnumType.base_type = clone_ast(n->EnumType.base_type);
|
n->EnumType.base_type = clone_ast(n->EnumType.base_type);
|
||||||
n->EnumType.fields = clone_ast_array(n->EnumType.fields);
|
n->EnumType.fields = clone_ast_array(n->EnumType.fields);
|
||||||
break;
|
break;
|
||||||
case Ast_BitFieldType:
|
|
||||||
n->BitFieldType.fields = clone_ast_array(n->BitFieldType.fields);
|
|
||||||
n->BitFieldType.align = clone_ast(n->BitFieldType.align);
|
|
||||||
break;
|
|
||||||
case Ast_BitSetType:
|
case Ast_BitSetType:
|
||||||
n->BitSetType.elem = clone_ast(n->BitSetType.elem);
|
n->BitSetType.elem = clone_ast(n->BitSetType.elem);
|
||||||
n->BitSetType.underlying = clone_ast(n->BitSetType.underlying);
|
n->BitSetType.underlying = clone_ast(n->BitSetType.underlying);
|
||||||
@@ -1054,14 +1049,6 @@ Ast *ast_enum_type(AstFile *f, Token token, Ast *base_type, Array<Ast *> const &
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ast *ast_bit_field_type(AstFile *f, Token token, Array<Ast *> const &fields, Ast *align) {
|
|
||||||
Ast *result = alloc_ast_node(f, Ast_BitFieldType);
|
|
||||||
result->BitFieldType.token = token;
|
|
||||||
result->BitFieldType.fields = slice_from_array(fields);
|
|
||||||
result->BitFieldType.align = align;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ast *ast_bit_set_type(AstFile *f, Token token, Ast *elem, Ast *underlying) {
|
Ast *ast_bit_set_type(AstFile *f, Token token, Ast *elem, Ast *underlying) {
|
||||||
Ast *result = alloc_ast_node(f, Ast_BitSetType);
|
Ast *result = alloc_ast_node(f, Ast_BitSetType);
|
||||||
result->BitSetType.token = token;
|
result->BitSetType.token = token;
|
||||||
@@ -1509,7 +1496,6 @@ bool is_semicolon_optional_for_node(AstFile *f, Ast *s) {
|
|||||||
case Ast_StructType:
|
case Ast_StructType:
|
||||||
case Ast_UnionType:
|
case Ast_UnionType:
|
||||||
case Ast_EnumType:
|
case Ast_EnumType:
|
||||||
case Ast_BitFieldType:
|
|
||||||
// Require semicolon within a procedure body
|
// Require semicolon within a procedure body
|
||||||
return f->curr_proc == nullptr;
|
return f->curr_proc == nullptr;
|
||||||
case Ast_ProcLit:
|
case Ast_ProcLit:
|
||||||
@@ -2369,51 +2355,6 @@ Ast *parse_operand(AstFile *f, bool lhs) {
|
|||||||
return ast_enum_type(f, token, base_type, values);
|
return ast_enum_type(f, token, base_type, values);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Token_bit_field: {
|
|
||||||
Token token = expect_token(f, Token_bit_field);
|
|
||||||
auto fields = array_make<Ast *>(heap_allocator());
|
|
||||||
Ast *align = nullptr;
|
|
||||||
Token open, close;
|
|
||||||
|
|
||||||
isize prev_level = f->expr_level;
|
|
||||||
f->expr_level = -1;
|
|
||||||
|
|
||||||
while (allow_token(f, Token_Hash)) {
|
|
||||||
Token tag = expect_token_after(f, Token_Ident, "#");
|
|
||||||
if (tag.string == "align") {
|
|
||||||
if (align) {
|
|
||||||
syntax_error(tag, "Duplicate bit_field tag '#%.*s'", LIT(tag.string));
|
|
||||||
}
|
|
||||||
align = parse_expr(f, true);
|
|
||||||
} else {
|
|
||||||
syntax_error(tag, "Invalid bit_field tag '#%.*s'", LIT(tag.string));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
f->expr_level = prev_level;
|
|
||||||
|
|
||||||
open = expect_token_after(f, Token_OpenBrace, "bit_field");
|
|
||||||
|
|
||||||
while (f->curr_token.kind != Token_EOF &&
|
|
||||||
f->curr_token.kind != Token_CloseBrace) {
|
|
||||||
Ast *name = parse_ident(f);
|
|
||||||
Token colon = expect_token(f, Token_Colon);
|
|
||||||
Ast *value = parse_expr(f, true);
|
|
||||||
|
|
||||||
Ast *field = ast_field_value(f, name, value, colon);
|
|
||||||
array_add(&fields, field);
|
|
||||||
|
|
||||||
if (f->curr_token.kind != Token_Comma) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
advance_token(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
close = expect_token(f, Token_CloseBrace);
|
|
||||||
|
|
||||||
return ast_bit_field_type(f, token, fields, align);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case Token_bit_set: {
|
case Token_bit_set: {
|
||||||
Token token = expect_token(f, Token_bit_set);
|
Token token = expect_token(f, Token_bit_set);
|
||||||
expect_token(f, Token_OpenBracket);
|
expect_token(f, Token_OpenBracket);
|
||||||
@@ -2524,7 +2465,6 @@ bool is_literal_type(Ast *node) {
|
|||||||
case Ast_EnumType:
|
case Ast_EnumType:
|
||||||
case Ast_DynamicArrayType:
|
case Ast_DynamicArrayType:
|
||||||
case Ast_MapType:
|
case Ast_MapType:
|
||||||
case Ast_BitFieldType:
|
|
||||||
case Ast_BitSetType:
|
case Ast_BitSetType:
|
||||||
case Ast_CallExpr:
|
case Ast_CallExpr:
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -594,11 +594,6 @@ AST_KIND(_TypeBegin, "", bool) \
|
|||||||
Slice<Ast *> fields; /* FieldValue */ \
|
Slice<Ast *> fields; /* FieldValue */ \
|
||||||
bool is_using; \
|
bool is_using; \
|
||||||
}) \
|
}) \
|
||||||
AST_KIND(BitFieldType, "bit field type", struct { \
|
|
||||||
Token token; \
|
|
||||||
Slice<Ast *> fields; /* FieldValue with : */ \
|
|
||||||
Ast * align; \
|
|
||||||
}) \
|
|
||||||
AST_KIND(BitSetType, "bit set type", struct { \
|
AST_KIND(BitSetType, "bit set type", struct { \
|
||||||
Token token; \
|
Token token; \
|
||||||
Ast * elem; \
|
Ast * elem; \
|
||||||
|
|||||||
@@ -102,7 +102,6 @@ TOKEN_KIND(Token__KeywordBegin, ""), \
|
|||||||
TOKEN_KIND(Token_struct, "struct"), \
|
TOKEN_KIND(Token_struct, "struct"), \
|
||||||
TOKEN_KIND(Token_union, "union"), \
|
TOKEN_KIND(Token_union, "union"), \
|
||||||
TOKEN_KIND(Token_enum, "enum"), \
|
TOKEN_KIND(Token_enum, "enum"), \
|
||||||
TOKEN_KIND(Token_bit_field, "bit_field"), \
|
|
||||||
TOKEN_KIND(Token_bit_set, "bit_set"), \
|
TOKEN_KIND(Token_bit_set, "bit_set"), \
|
||||||
TOKEN_KIND(Token_map, "map"), \
|
TOKEN_KIND(Token_map, "map"), \
|
||||||
TOKEN_KIND(Token_dynamic, "dynamic"), \
|
TOKEN_KIND(Token_dynamic, "dynamic"), \
|
||||||
|
|||||||
Reference in New Issue
Block a user