mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-18 11:52:22 -07:00
Add -disallow-do
This commit is contained in:
@@ -154,6 +154,7 @@ struct BuildContext {
|
||||
bool cross_compiling;
|
||||
bool different_os;
|
||||
bool keep_object_files;
|
||||
bool disallow_do;
|
||||
|
||||
bool use_llvm_api;
|
||||
|
||||
|
||||
@@ -579,6 +579,7 @@ enum BuildFlagKind {
|
||||
BuildFlag_UseLLVMApi,
|
||||
BuildFlag_IgnoreUnknownAttributes,
|
||||
BuildFlag_ExtraLinkerFlags,
|
||||
BuildFlag_DisallowDo,
|
||||
|
||||
BuildFlag_DefaultToNilAllocator,
|
||||
|
||||
@@ -677,6 +678,7 @@ bool parse_build_flags(Array<String> args) {
|
||||
add_flag(&build_flags, BuildFlag_UseLLVMApi, str_lit("llvm-api"), BuildFlagParam_None);
|
||||
add_flag(&build_flags, BuildFlag_IgnoreUnknownAttributes, str_lit("ignore-unknown-attributes"), BuildFlagParam_None);
|
||||
add_flag(&build_flags, BuildFlag_ExtraLinkerFlags, str_lit("extra-linker-flags"), BuildFlagParam_String);
|
||||
add_flag(&build_flags, BuildFlag_DisallowDo, str_lit("disallow-do"), BuildFlagParam_None);
|
||||
|
||||
add_flag(&build_flags, BuildFlag_DefaultToNilAllocator, str_lit("default-to-nil-allocator"), BuildFlagParam_None);
|
||||
|
||||
@@ -1103,6 +1105,10 @@ bool parse_build_flags(Array<String> args) {
|
||||
build_context.extra_linker_flags = value.value_string;
|
||||
break;
|
||||
|
||||
case BuildFlag_DisallowDo:
|
||||
build_context.disallow_do = true;
|
||||
break;
|
||||
|
||||
case BuildFlag_DefaultToNilAllocator:
|
||||
build_context.ODIN_DEFAULT_TO_NIL_ALLOCATOR = true;
|
||||
break;
|
||||
|
||||
@@ -1998,6 +1998,10 @@ Ast *parse_operand(AstFile *f, bool lhs) {
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
f->curr_proc = curr_proc;
|
||||
|
||||
if (build_context.disallow_do) {
|
||||
syntax_error(body, "'do' has been disallowed");
|
||||
}
|
||||
|
||||
return ast_proc_lit(f, type, body, tags, where_token, where_clauses);
|
||||
}
|
||||
|
||||
@@ -3558,6 +3562,9 @@ Ast *parse_if_stmt(AstFile *f) {
|
||||
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
if (build_context.disallow_do) {
|
||||
syntax_error(body, "'do' has been disallowed");
|
||||
}
|
||||
} else {
|
||||
body = parse_block_stmt(f, false);
|
||||
}
|
||||
@@ -3573,6 +3580,9 @@ Ast *parse_if_stmt(AstFile *f) {
|
||||
case Token_do: {
|
||||
Token arrow = expect_token(f, Token_do);
|
||||
else_stmt = convert_stmt_to_body(f, parse_stmt(f));
|
||||
if (build_context.disallow_do) {
|
||||
syntax_error(else_stmt, "'do' has been disallowed");
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
syntax_error(f->curr_token, "Expected if statement block statement");
|
||||
@@ -3603,6 +3613,9 @@ Ast *parse_when_stmt(AstFile *f) {
|
||||
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
if (build_context.disallow_do) {
|
||||
syntax_error(body, "'do' has been disallowed");
|
||||
}
|
||||
} else {
|
||||
body = parse_block_stmt(f, true);
|
||||
}
|
||||
@@ -3618,6 +3631,9 @@ Ast *parse_when_stmt(AstFile *f) {
|
||||
case Token_do: {
|
||||
Token arrow = expect_token(f, Token_do);
|
||||
else_stmt = convert_stmt_to_body(f, parse_stmt(f));
|
||||
if (build_context.disallow_do) {
|
||||
syntax_error(else_stmt, "'do' has been disallowed");
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
syntax_error(f->curr_token, "Expected when statement block statement");
|
||||
@@ -3698,6 +3714,9 @@ Ast *parse_for_stmt(AstFile *f) {
|
||||
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
if (build_context.disallow_do) {
|
||||
syntax_error(body, "'do' has been disallowed");
|
||||
}
|
||||
} else {
|
||||
body = parse_block_stmt(f, false);
|
||||
}
|
||||
@@ -3728,6 +3747,9 @@ Ast *parse_for_stmt(AstFile *f) {
|
||||
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
if (build_context.disallow_do) {
|
||||
syntax_error(body, "'do' has been disallowed");
|
||||
}
|
||||
} else {
|
||||
body = parse_block_stmt(f, false);
|
||||
}
|
||||
@@ -4072,6 +4094,9 @@ Ast *parse_stmt(AstFile *f) {
|
||||
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = convert_stmt_to_body(f, parse_stmt(f));
|
||||
if (build_context.disallow_do) {
|
||||
syntax_error(body, "'do' has been disallowed");
|
||||
}
|
||||
} else {
|
||||
body = parse_block_stmt(f, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user