mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Make require_results an attribute rather than a suffix tag for procedures
This commit is contained in:
@@ -5,7 +5,6 @@ import "core:odin/token"
|
|||||||
Proc_Tag :: enum {
|
Proc_Tag :: enum {
|
||||||
Bounds_Check,
|
Bounds_Check,
|
||||||
No_Bounds_Check,
|
No_Bounds_Check,
|
||||||
Require_Results,
|
|
||||||
}
|
}
|
||||||
Proc_Tags :: distinct bit_set[Proc_Tag; u32];
|
Proc_Tags :: distinct bit_set[Proc_Tag; u32];
|
||||||
|
|
||||||
|
|||||||
@@ -1745,8 +1745,6 @@ parse_proc_tags :: proc(p: ^Parser) -> (tags: ast.Proc_Tags) {
|
|||||||
ident := expect_token(p, token.Ident);
|
ident := expect_token(p, token.Ident);
|
||||||
|
|
||||||
switch ident.text {
|
switch ident.text {
|
||||||
case "require_results":
|
|
||||||
tags |= {.Require_Results};
|
|
||||||
case "bounds_check":
|
case "bounds_check":
|
||||||
tags |= {.Bounds_Check};
|
tags |= {.Bounds_Check};
|
||||||
case "no_bounds_check":
|
case "no_bounds_check":
|
||||||
|
|||||||
+3
-4
@@ -654,7 +654,6 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
|
|||||||
|
|
||||||
bool is_foreign = e->Procedure.is_foreign;
|
bool is_foreign = e->Procedure.is_foreign;
|
||||||
bool is_export = e->Procedure.is_export;
|
bool is_export = e->Procedure.is_export;
|
||||||
bool is_require_results = (pl->tags & ProcTag_require_results) != 0;
|
|
||||||
|
|
||||||
if (e->pkg != nullptr && e->token.string == "main") {
|
if (e->pkg != nullptr && e->token.string == "main") {
|
||||||
if (pt->param_count != 0 ||
|
if (pt->param_count != 0 ||
|
||||||
@@ -714,10 +713,10 @@ void check_proc_decl(CheckerContext *ctx, Entity *e, DeclInfo *d) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pt->result_count == 0 && is_require_results) {
|
if (pt->result_count == 0 && ac.require_results) {
|
||||||
error(pl->type, "'#require_results' is not needed on a procedure with no results");
|
error(pl->type, "'require_results' is not needed on a procedure with no results");
|
||||||
} else {
|
} else {
|
||||||
pt->require_results = is_require_results;
|
pt->require_results = ac.require_results;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ac.link_name.len > 0) {
|
if (ac.link_name.len > 0) {
|
||||||
|
|||||||
@@ -2187,6 +2187,12 @@ DECL_ATTRIBUTE_PROC(proc_decl_attribute) {
|
|||||||
error(elem, "Expected a string value for '%.*s'", LIT(name));
|
error(elem, "Expected a string value for '%.*s'", LIT(name));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
} else if (name == "require_results") {
|
||||||
|
if (value != nullptr) {
|
||||||
|
error(elem, "Expected no value for '%.*s'", LIT(name));
|
||||||
|
}
|
||||||
|
ac->require_results = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ struct DeferredProcedure {
|
|||||||
struct AttributeContext {
|
struct AttributeContext {
|
||||||
bool is_export;
|
bool is_export;
|
||||||
bool is_static;
|
bool is_static;
|
||||||
|
bool require_results;
|
||||||
String link_name;
|
String link_name;
|
||||||
String link_prefix;
|
String link_prefix;
|
||||||
isize init_expr_list_count;
|
isize init_expr_list_count;
|
||||||
|
|||||||
+5
-1
@@ -1855,7 +1855,7 @@ Ast *parse_operand(AstFile *f, bool lhs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (tags != 0) {
|
if (tags != 0) {
|
||||||
syntax_error(token, "A procedure type cannot have tags");
|
syntax_error(token, "A procedure type cannot have suffix tags");
|
||||||
}
|
}
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
@@ -2828,6 +2828,10 @@ Ast *parse_proc_type(AstFile *f, Token proc_token) {
|
|||||||
|
|
||||||
u64 tags = 0;
|
u64 tags = 0;
|
||||||
parse_proc_tags(f, &tags);
|
parse_proc_tags(f, &tags);
|
||||||
|
if ((tags & ProcTag_require_results) != 0) {
|
||||||
|
syntax_error(f->curr_token, "#require_results has now been replaced as an attribute @(require_results) on the declaration");
|
||||||
|
tags &= ~ProcTag_require_results;
|
||||||
|
}
|
||||||
|
|
||||||
bool is_generic = false;
|
bool is_generic = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user