aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-11-05 13:30:40 +0000
committergingerBill <gingerBill@users.noreply.github.com>2025-11-05 13:30:40 +0000
commit593d2e6daa1f0dd9c24c7fb8704463c8db757af0 (patch)
treebb1ba4fc37dc14b11efd9197208ba1372aac9f21 /src/parser.cpp
parentea5db0e04864f7e453a5b5faa305df22543c4b75 (diff)
Add `#all_or_none`
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 152e55f8b..d3b35f3f4 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -1230,7 +1230,7 @@ gb_internal Ast *ast_dynamic_array_type(AstFile *f, Token token, Ast *elem) {
}
gb_internal Ast *ast_struct_type(AstFile *f, Token token, Slice<Ast *> fields, isize field_count,
- Ast *polymorphic_params, bool is_packed, bool is_raw_union, bool is_no_copy,
+ Ast *polymorphic_params, bool is_packed, bool is_raw_union, bool is_no_copy, bool is_all_or_none,
Ast *align, Ast *min_field_align, Ast *max_field_align,
Token where_token, Array<Ast *> const &where_clauses) {
Ast *result = alloc_ast_node(f, Ast_StructType);
@@ -1241,6 +1241,7 @@ gb_internal Ast *ast_struct_type(AstFile *f, Token token, Slice<Ast *> fields, i
result->StructType.is_packed = is_packed;
result->StructType.is_raw_union = is_raw_union;
result->StructType.is_no_copy = is_no_copy;
+ result->StructType.is_all_or_none = is_all_or_none;
result->StructType.align = align;
result->StructType.min_field_align = min_field_align;
result->StructType.max_field_align = max_field_align;
@@ -2773,6 +2774,7 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
Token token = expect_token(f, Token_struct);
Ast *polymorphic_params = nullptr;
bool is_packed = false;
+ bool is_all_or_none = false;
bool is_raw_union = false;
bool no_copy = false;
Ast *align = nullptr;
@@ -2802,6 +2804,11 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
}
is_packed = true;
+ } else if (tag.string == "all_or_none") {
+ if (is_packed) {
+ syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
+ }
+ is_all_or_none = true;
} else if (tag.string == "align") {
if (align) {
syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
@@ -2872,6 +2879,10 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
is_packed = false;
syntax_error(token, "'#raw_union' cannot also be '#packed'");
}
+ if (is_raw_union && is_all_or_none) {
+ is_all_or_none = false;
+ syntax_error(token, "'#raw_union' cannot also be '#all_or_none'");
+ }
Token where_token = {};
Array<Ast *> where_clauses = {};
@@ -2901,7 +2912,10 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
parser_check_polymorphic_record_parameters(f, polymorphic_params);
- return ast_struct_type(f, token, decls, name_count, polymorphic_params, is_packed, is_raw_union, no_copy, align, min_field_align, max_field_align, where_token, where_clauses);
+ return ast_struct_type(f, token, decls, name_count,
+ polymorphic_params, is_packed, is_raw_union, no_copy, is_all_or_none,
+ align, min_field_align, max_field_align,
+ where_token, where_clauses);
} break;
case Token_union: {