aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-04-15 15:36:21 +0100
committergingerBill <bill@gingerbill.org>2023-04-15 15:37:32 +0100
commit5da76ae34bac2f54b1bda5528cf49c0551e88bba (patch)
tree78a6189f351ceb8dd070c2e453c4b0462d532235 /src/parser.cpp
parentb7b5043aea792839226baf9e6d0ca54b73dac9a5 (diff)
Add `struct #no_copy`
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 50a9ba766..790e67db6 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -1047,7 +1047,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,
+ Ast *polymorphic_params, bool is_packed, bool is_raw_union, bool is_no_copy,
Ast *align,
Token where_token, Array<Ast *> const &where_clauses) {
Ast *result = alloc_ast_node(f, Ast_StructType);
@@ -1057,6 +1057,7 @@ gb_internal Ast *ast_struct_type(AstFile *f, Token token, Slice<Ast *> fields, i
result->StructType.polymorphic_params = polymorphic_params;
result->StructType.is_packed = is_packed;
result->StructType.is_raw_union = is_raw_union;
+ result->StructType.is_no_copy = is_no_copy;
result->StructType.align = align;
result->StructType.where_token = where_token;
result->StructType.where_clauses = slice_from_array(where_clauses);
@@ -2392,6 +2393,7 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
Ast *polymorphic_params = nullptr;
bool is_packed = false;
bool is_raw_union = false;
+ bool no_copy = false;
Ast *align = nullptr;
if (allow_token(f, Token_OpenParen)) {
@@ -2427,6 +2429,11 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
}
is_raw_union = true;
+ } else if (tag.string == "no_copy") {
+ if (is_packed) {
+ syntax_error(tag, "Duplicate struct tag '#%.*s'", LIT(tag.string));
+ }
+ no_copy = true;
} else {
syntax_error(tag, "Invalid struct tag '#%.*s'", LIT(tag.string));
}
@@ -2465,7 +2472,7 @@ gb_internal Ast *parse_operand(AstFile *f, bool lhs) {
decls = fields->FieldList.list;
}
- return ast_struct_type(f, token, decls, name_count, polymorphic_params, is_packed, is_raw_union, align, where_token, where_clauses);
+ return ast_struct_type(f, token, decls, name_count, polymorphic_params, is_packed, is_raw_union, no_copy, align, where_token, where_clauses);
} break;
case Token_union: {