mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Deprecate MyEnum.elements.
This commit is contained in:
@@ -6,7 +6,7 @@ import std::io;
|
||||
|
||||
struct EnumMap (Printable)
|
||||
{
|
||||
ValueType[Enum.len] values;
|
||||
ValueType[Enum.values.len] values;
|
||||
}
|
||||
|
||||
fn void EnumMap.init(&self, ValueType init_value)
|
||||
|
||||
@@ -8,9 +8,10 @@
|
||||
module std::collections::enumset{Enum};
|
||||
import std::io;
|
||||
|
||||
alias EnumSetType @private = $typefrom(type_for_enum_elements(Enum.elements));
|
||||
const ENUM_COUNT @private = Enum.values.len;
|
||||
alias EnumSetType @private = $typefrom(type_for_enum_elements(ENUM_COUNT));
|
||||
|
||||
const IS_CHAR_ARRAY = Enum.elements > 128;
|
||||
const IS_CHAR_ARRAY = ENUM_COUNT > 128;
|
||||
typedef EnumSet (Printable) = EnumSetType;
|
||||
|
||||
fn void EnumSet.add(&self, Enum v)
|
||||
|
||||
@@ -24,11 +24,9 @@ struct SliceRaw
|
||||
|
||||
macro @enum_lookup($Type, #value, value)
|
||||
{
|
||||
var $elements = $Type.elements;
|
||||
$for var $i = 0; $i < $elements; $i++:
|
||||
var $val = $Type.from_ordinal($i);
|
||||
$foreach $val : $Type.values:
|
||||
if ($val.#value == value) return $val;
|
||||
$endfor
|
||||
$endforeach
|
||||
return NOT_FOUND?;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
- Added `@rnd()` compile time random function (using the `$$rnd()` builtin). #2078
|
||||
- Add `math::@ceil()` compile time ceil function. #2134
|
||||
- Improve error message when using keywords as functions/macros/variables #2133.
|
||||
- Deprecate `MyEnum.elements`.
|
||||
|
||||
### Fixes
|
||||
- Assert triggered when casting from `int[2]` to `uint[2]` #2115
|
||||
|
||||
@@ -2851,7 +2851,7 @@ INLINE bool sema_expr_analyse_lookup(SemaContext *context, Expr *expr, Expr *tag
|
||||
Decl *decl = tag->type_call_expr.type;
|
||||
if (inline_field)
|
||||
{
|
||||
if (arg_count != 1) RETURN_SEMA_ERROR(expr, "Expected one (1) argument to 'lookup'.");
|
||||
if (arg_count != 1) RETURN_SEMA_ERROR(expr, "Expected one (1) argument to 'lookup', did you want 'lookup_field' perhaps?");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -5126,6 +5126,7 @@ static bool sema_expr_rewrite_to_type_property(SemaContext *context, Expr *expr,
|
||||
case TYPE_PROPERTY_ELEMENTS:
|
||||
ASSERT_SPAN(expr, flat->type_kind == TYPE_ENUM);
|
||||
if (!sema_analyse_decl(context, type->decl)) return false;
|
||||
SEMA_DEPRECATED(expr, ".elements is deprecated. Use .values.len instead.");
|
||||
expr_rewrite_const_int(expr, type_isz, vec_size(flat->decl->enums.values));
|
||||
return true;
|
||||
case TYPE_PROPERTY_VALUES:
|
||||
|
||||
@@ -6,7 +6,7 @@ enum MyEnum : short
|
||||
BYE
|
||||
}
|
||||
|
||||
int myenum_elements = MyEnum.elements;
|
||||
int myenum_elements = MyEnum.values.len;
|
||||
int myenum_alignof = MyEnum.alignof;
|
||||
int myenum_sizeof = MyEnum.sizeof;
|
||||
|
||||
|
||||
@@ -129,9 +129,9 @@ fn void main()
|
||||
}
|
||||
list.free();
|
||||
|
||||
printf("Elements: %d\n", (int)(MyEnum.elements));
|
||||
printf("Elements: %d\n", (int)(MyEnum.values.len));
|
||||
|
||||
int elements = MyEnum.elements;
|
||||
int elements = MyEnum.values.len;
|
||||
printf("Hello\n");
|
||||
IntArray array;
|
||||
array.push(100);
|
||||
|
||||
@@ -131,9 +131,9 @@ fn void main()
|
||||
}
|
||||
list.free();
|
||||
|
||||
printf("Elements: %d\n", (int)(MyEnum.elements));
|
||||
printf("Elements: %d\n", (int)(MyEnum.values.len));
|
||||
|
||||
int elements = MyEnum.elements;
|
||||
int elements = MyEnum.values.len;
|
||||
printf("Hello\n");
|
||||
IntArray array;
|
||||
array.push(100);
|
||||
|
||||
Reference in New Issue
Block a user