From f8e061c94bb50ab483b505a51757b0e6b5631e78 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Astor?= Date: Thu, 29 Jul 2021 19:10:31 +0200 Subject: [PATCH] :art: Make enum type mandatory --- ast | 2 +- examples/class_enum.gw | 2 +- src/parse/scan0.c | 13 +------------ tests/error/class_enum.gw | 2 +- tests/tree/cpy_ast.gw | 2 +- tests/tree/enum.gw | 2 +- tests/tree/private_enum.gw | 2 +- 7 files changed, 7 insertions(+), 18 deletions(-) diff --git a/ast b/ast index 45c938d4..2505a7e7 160000 --- a/ast +++ b/ast @@ -1 +1 @@ -Subproject commit 45c938d4ea5b0c768e1ea9eae671f9c49eaacc08 +Subproject commit 2505a7e746b8a63731c11310593d3d7aaddce714 diff --git a/examples/class_enum.gw b/examples/class_enum.gw index f620b7ee..bd1eb29e 100644 --- a/examples/class_enum.gw +++ b/examples/class_enum.gw @@ -1,5 +1,5 @@ class C { - enum { + enum E { zero, one, two, diff --git a/src/parse/scan0.c b/src/parse/scan0.c index d05038ef..f29249e5 100644 --- a/src/parse/scan0.c +++ b/src/parse/scan0.c @@ -192,23 +192,12 @@ ANN m_bool scan0_type_def(const Env env, const Type_Def tdef) { return GW_OK; } -ANN static Symbol scan0_sym(const Env env, const m_str name, const loc_t pos) { - const size_t line_len = num_digit(pos.first.line); - const size_t col_len = num_digit(pos.first.column); - char c[strlen(env->curr->name) + strlen(env->name) + line_len + col_len + - strlen(name) + 6]; - sprintf(c, "@%s:%s:%s:%u:%u", name, env->name, env->curr->name, - pos.first.line, pos.first.column); - return insert_symbol(c); -} - #define scan0_nspc(env, a) \ GET_FLAG(a, global) ? !env->class_def ? env->global_nspc : NULL : env->curr ANN static Type enum_type(const Env env, const Enum_Def edef) { const Type t = type_copy(env->gwion->mp, env->gwion->type[et_int]); - const Symbol sym = scan0_sym(env, "enum", edef->pos); - t->name = edef->xid ? s_name(edef->xid) : s_name(sym); + t->name = s_name(edef->xid); t->info->parent = env->gwion->type[et_int]; const bool global = GET_FLAG(edef, global); // TODO: handle global in class if (global) { diff --git a/tests/error/class_enum.gw b/tests/error/class_enum.gw index 3a16175f..29970bf0 100644 --- a/tests/error/class_enum.gw +++ b/tests/error/class_enum.gw @@ -1,7 +1,7 @@ #! [contains] unary operator '--' cannot be used on non-mutable data-types class C { - enum { a, b }; + enum E { a, b }; } C.a; diff --git a/tests/tree/cpy_ast.gw b/tests/tree/cpy_ast.gw index d481961d..25c18fb6 100644 --- a/tests/tree/cpy_ast.gw +++ b/tests/tree/cpy_ast.gw @@ -19,7 +19,7 @@ class C:[A] { case 12 when 0:; case _,2 when 0:; } where var int b; - enum { zero }; + enum E { zero }; typedef int Int; new Object; spork { <<< __func__ >>>; }; diff --git a/tests/tree/enum.gw b/tests/tree/enum.gw index 05b4fa6e..4c29fd9e 100644 --- a/tests/tree/enum.gw +++ b/tests/tree/enum.gw @@ -1,4 +1,4 @@ -enum { +enum E { zero, one, two, three }; <<< zero, " ", one, " ", two, " ", three >>>; diff --git a/tests/tree/private_enum.gw b/tests/tree/private_enum.gw index 0c2d9de2..2715e6a6 100644 --- a/tests/tree/private_enum.gw +++ b/tests/tree/private_enum.gw @@ -1,5 +1,5 @@ class C { - enum private { + enum private E { TEST }; } -- 2.43.0