Enums: Make EnumDefinition use EnumValues instead of Strings as children.

This allows us to store the index of the enum value along the name. The index can be used to compare two enum values in assembler.

Later on this might be used to enable users of KLang to set arbitrary values as the index of an enum value.
This commit is contained in:
2023-03-20 19:30:07 +01:00
parent 77fe360ffa
commit 0594542167
9 changed files with 57 additions and 11 deletions

View File

@@ -355,7 +355,7 @@ public class ContextAnalysis extends KlangBaseVisitor<Node> {
}
var enumValueName = path.get(0);
if (Arrays.stream(enumDef.enums).noneMatch(e -> e.equals(enumValueName))) {
if (Arrays.stream(enumDef.enums).noneMatch(e -> e.value.equals(enumValueName))) {
var error = "Unknown enum value " + enumValueName + " of enum " + enumDef.name + ".";
throw new RuntimeException(Helper.getErrorPrefix(line, col) + error);
}