Remove bit_field keyword and parsing logic

This commit is contained in:
gingerBill
2021-02-23 15:29:54 +00:00
parent fe33a64b2e
commit 28f279329d
12 changed files with 1 additions and 165 deletions
-1
View File
@@ -201,7 +201,6 @@ bool is_type_distinct(Ast *node) {
case Ast_StructType:
case Ast_UnionType:
case Ast_EnumType:
case Ast_BitFieldType:
case Ast_ProcType:
return true;
-16
View File
@@ -10175,7 +10175,6 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
case Ast_MapType:
case Ast_OpaqueType:
case Ast_BitSetType:
case Ast_BitFieldType:
o->mode = Addressing_Type;
o->type = check_type(c, node);
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);
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);
str = gb_string_appendc(str, "bit_set[");
str = write_expr_to_string(str, bs->elem, shorthand);
-6
View File
@@ -3517,12 +3517,6 @@ bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_t
return true;
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);
*type = alloc_type_bit_set();
set_base_type(named_type, *type);
-1
View File
@@ -333,7 +333,6 @@ void check_open_scope(CheckerContext *c, Ast *node) {
case Ast_StructType:
case Ast_EnumType:
case Ast_UnionType:
case Ast_BitFieldType:
case Ast_BitSetType:
scope->flags |= ScopeFlag_Type;
break;
-60
View File
@@ -100,7 +100,6 @@ Token ast_token(Ast *node) {
case Ast_StructType: return node->StructType.token;
case Ast_UnionType: return node->UnionType.token;
case Ast_EnumType: return node->EnumType.token;
case Ast_BitFieldType: return node->BitFieldType.token;
case Ast_BitSetType: return node->BitSetType.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.fields = clone_ast_array(n->EnumType.fields);
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:
n->BitSetType.elem = clone_ast(n->BitSetType.elem);
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;
}
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 *result = alloc_ast_node(f, Ast_BitSetType);
result->BitSetType.token = token;
@@ -1509,7 +1496,6 @@ bool is_semicolon_optional_for_node(AstFile *f, Ast *s) {
case Ast_StructType:
case Ast_UnionType:
case Ast_EnumType:
case Ast_BitFieldType:
// Require semicolon within a procedure body
return f->curr_proc == nullptr;
case Ast_ProcLit:
@@ -2369,51 +2355,6 @@ Ast *parse_operand(AstFile *f, bool lhs) {
return ast_enum_type(f, token, base_type, values);
} 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: {
Token token = expect_token(f, Token_bit_set);
expect_token(f, Token_OpenBracket);
@@ -2524,7 +2465,6 @@ bool is_literal_type(Ast *node) {
case Ast_EnumType:
case Ast_DynamicArrayType:
case Ast_MapType:
case Ast_BitFieldType:
case Ast_BitSetType:
case Ast_CallExpr:
return true;
-5
View File
@@ -594,11 +594,6 @@ AST_KIND(_TypeBegin, "", bool) \
Slice<Ast *> fields; /* FieldValue */ \
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 { \
Token token; \
Ast * elem; \
-1
View File
@@ -102,7 +102,6 @@ TOKEN_KIND(Token__KeywordBegin, ""), \
TOKEN_KIND(Token_struct, "struct"), \
TOKEN_KIND(Token_union, "union"), \
TOKEN_KIND(Token_enum, "enum"), \
TOKEN_KIND(Token_bit_field, "bit_field"), \
TOKEN_KIND(Token_bit_set, "bit_set"), \
TOKEN_KIND(Token_map, "map"), \
TOKEN_KIND(Token_dynamic, "dynamic"), \