add type_is_enum
This commit is contained in:
parent
0632f97757
commit
7063c63c2d
1 changed files with 24 additions and 17 deletions
|
|
@ -38,27 +38,16 @@ type_is_struct :: ($$T: Type) -> bool, *Type_Info_Struct {
|
|||
return ok, info.(*Type_Info_Struct);
|
||||
}
|
||||
|
||||
enum_max :: (T: Type) -> int #expand {
|
||||
#assert T.(*Type_Info).type == .ENUM;
|
||||
return #run -> int {
|
||||
info := T.(*Type_Info_Enum);
|
||||
if info.values.count == 0 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
max := 0;
|
||||
for info.values if it > max {
|
||||
max = it;
|
||||
}
|
||||
|
||||
return max;
|
||||
};
|
||||
type_is_enum :: ($$T: Type) -> bool, *Type_Info_Enum {
|
||||
ok, info := check_type_tag(T, .ENUM);
|
||||
return ok, info.(*Type_Info_Enum);
|
||||
}
|
||||
|
||||
enum_min :: (T: Type) -> int #expand {
|
||||
#assert T.(*Type_Info).type == .ENUM;
|
||||
return #run -> int {
|
||||
info := T.(*Type_Info_Enum);
|
||||
ok, info := type_is_enum(T);
|
||||
assert(ok, "type given to enum_min must be an enum");
|
||||
|
||||
if info.values.count == 0 {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -71,3 +60,21 @@ enum_min :: (T: Type) -> int #expand {
|
|||
return min;
|
||||
};
|
||||
}
|
||||
|
||||
enum_max :: (T: Type) -> int #expand {
|
||||
return #run -> int {
|
||||
ok, info := type_is_enum(T);
|
||||
assert(ok, "type given to enum_max must be an enum");
|
||||
|
||||
if info.values.count == 0 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
max := 0;
|
||||
for info.values if it > max {
|
||||
max = it;
|
||||
}
|
||||
|
||||
return max;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue