declareEnumValues function
Declares an enum with the given values
.
For example:
enum Color {
red,
green,
blue,
}
final EnumInfo color = declareEnumValues(Color.values);
final Expr x = constVar('x', color.sort);
final Expr red = $(Color.red);
print('red: ${red.to<Color>()}'); // red: Color.red
Implementation
EnumInfo declareEnumValues(List<Enum> values) {
final t = values[0].runtimeType;
final info = declareEnum('$t', values.map((e) => e.name));
_declaredEnums[currentContext] ??= {};
_declaredEnums[currentContext]![t] = (values, info);
return info;
}