Skip to content

Commit

Permalink
Add VInt hint EnumIndex<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxiaomao committed Apr 4, 2024
1 parent 519a3ff commit f4921c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions hld/Eval.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 12 additions & 3 deletions hld/Value.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>
HEnumIndex(t : String); // v:EnumIndex<T>
}

@:structInit class Value {
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

}

0 comments on commit f4921c5

Please sign in to comment.