aboutsummaryrefslogtreecommitdiff
path: root/src/check_type.cpp
diff options
context:
space:
mode:
authorVladPavliuk <pavliuk.vlad@gmail.com>2024-07-14 18:22:20 +0300
committerVladPavliuk <pavliuk.vlad@gmail.com>2024-07-14 18:22:20 +0300
commit3f8712edb03390c1eed4dced27f7c2707cf14ecb (patch)
treea186834d911e19418836bf2ca3f52f334c11267a /src/check_type.cpp
parent79e2f63182581547dcdb7593397d1c3e280a5670 (diff)
parente7d37607ef9ce54a80d83230150874b71d628d6d (diff)
Merge branch 'master' into json-add-int-key-map-support
Diffstat (limited to 'src/check_type.cpp')
-rw-r--r--src/check_type.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index dd8559114..fea937e4e 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -1953,6 +1953,10 @@ gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_para
error(name, "'#by_ptr' can only be applied to variable fields");
p->flags &= ~FieldFlag_by_ptr;
}
+ if (p->flags&FieldFlag_no_capture) {
+ error(name, "'#no_capture' can only be applied to variable fields");
+ p->flags &= ~FieldFlag_no_capture;
+ }
param = alloc_entity_type_name(scope, name->Ident.token, type, EntityState_Resolved);
param->TypeName.is_type_alias = true;
@@ -2054,6 +2058,28 @@ gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_para
p->flags &= ~FieldFlag_by_ptr; // Remove the flag
}
}
+ if (p->flags&FieldFlag_no_capture) {
+ if (is_variadic && variadic_index == variables.count) {
+ if (p->flags & FieldFlag_c_vararg) {
+ error(name, "'#no_capture' cannot be applied to a #c_vararg parameter");
+ p->flags &= ~FieldFlag_no_capture;
+ } else {
+ error(name, "'#no_capture' is already implied on all variadic parameter");
+ }
+ } else if (is_type_polymorphic(type)) {
+ // ignore
+ } else {
+ if (is_type_internally_pointer_like(type)) {
+ error(name, "'#no_capture' is currently reserved for future use");
+ } else {
+ ERROR_BLOCK();
+ error(name, "'#no_capture' can only be applied to pointer-like types");
+ error_line("\t'#no_capture' does not currently do anything useful\n");
+ p->flags &= ~FieldFlag_no_capture;
+ }
+ }
+ }
+
if (is_poly_name) {
if (p->flags&FieldFlag_no_alias) {
@@ -2072,6 +2098,11 @@ gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_para
error(name, "'#by_ptr' can only be applied to variable fields");
p->flags &= ~FieldFlag_by_ptr;
}
+ if (p->flags&FieldFlag_no_capture) {
+ error(name, "'#no_capture' can only be applied to variable fields");
+ p->flags &= ~FieldFlag_no_capture;
+ }
+
if (!is_type_polymorphic(type) && check_constant_parameter_value(type, params[i])) {
// failed
@@ -2091,6 +2122,8 @@ gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_para
param->flags |= EntityFlag_Ellipsis;
if (is_c_vararg) {
param->flags |= EntityFlag_CVarArg;
+ } else {
+ param->flags |= EntityFlag_NoCapture;
}
}
@@ -2115,6 +2148,10 @@ gb_internal Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_para
if (p->flags&FieldFlag_by_ptr) {
param->flags |= EntityFlag_ByPtr;
}
+ if (p->flags&FieldFlag_no_capture) {
+ param->flags |= EntityFlag_NoCapture;
+ }
+
param->state = EntityState_Resolved; // NOTE(bill): This should have be resolved whilst determining it
add_entity(ctx, scope, name, param);