From f4921c5a689d3bdbb3ff53a1f34586b946d840cf Mon Sep 17 00:00:00 2001 From: Yuxiao Mao Date: Thu, 4 Apr 2024 10:23:15 +0200 Subject: [PATCH] Add VInt hint EnumIndex --- hld/Eval.hx | 5 +++++ hld/Value.hx | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/hld/Eval.hx b/hld/Eval.hx index 1feacec..bddfc80 100644 --- a/hld/Eval.hx +++ b/hld/Eval.hx @@ -777,6 +777,11 @@ class Eval { if( eproto == null ) throw "Can't resolve enum " + t; Value.intEnumFlags(i, eproto); + case HEnumIndex(t): + var eproto = module.resolveEnum(t); + if( eproto == null ) + throw "Can't resolve enum " + t; + Value.intEnumIndex(i, eproto); default: "" + i; } case VInt64(i): diff --git a/hld/Value.hx b/hld/Value.hx index 2baf8ed..88f9d4b 100644 --- a/hld/Value.hx +++ b/hld/Value.hx @@ -29,9 +29,10 @@ typedef InlinedField = { name : String, addr : Eval.VarAddress } enum Hint { HNone; - HHex; - HBin; - HEnumFlags(t : String); + HHex; // v:h + HBin; // v:b + HEnumFlags(t : String); // v:EnumFlags + HEnumIndex(t : String); // v:EnumIndex } @:structInit class Value { @@ -46,6 +47,8 @@ enum Hint { return HBin; if( StringTools.startsWith(s,"EnumFlags<") && StringTools.endsWith(s,">") ) return HEnumFlags(s.substr(10, s.length - 11)); + if( StringTools.startsWith(s,"EnumIndex<") && StringTools.endsWith(s,">") ) + return HEnumIndex(s.substr(10, s.length - 11)); return HNone; } @@ -88,4 +91,10 @@ enum Hint { return f; } + public static function intEnumIndex( value : Int, eproto : format.hl.Data.EnumPrototype ) : String { + if( value < 0 || value >= eproto.constructs.length ) + throw "Out of range [0," + eproto.constructs.length + ")"; + return eproto.constructs[value].name; + } + }