Skip to content

Commit 17c97d3

Browse files
committed
Allow Map key/value pair add to watch by index
1 parent da664ea commit 17c97d3

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

hld/Eval.hx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,8 @@ class Eval {
984984
content.toString() + ":" + nkeys;
985985
} else
986986
content.toString();
987+
case VMapPair(key, value):
988+
valueStr(key, maxStringRec) + "=>" + valueStr(value, maxStringRec);
987989
case VType(t):
988990
typeStr(t);
989991
case VEnum(c, values, _):
@@ -1353,10 +1355,19 @@ class Eval {
13531355
}
13541356
}
13551357

1356-
public function readField( v : Value, name : String ) {
1358+
public function readField( v : Value, name : String ) : Value {
13571359
switch( v.v ) {
13581360
case VEnum(_,values,_) if( name.charCodeAt(0) == "$".code ):
13591361
return values[Std.parseInt(name.substr(1))];
1362+
case VMap(t, len, readKey, readValue, _) if( name.charCodeAt(0) == "$".code ):
1363+
var i = Std.parseInt(name.substr(1));
1364+
var key = readKey(i);
1365+
var value = readValue(i);
1366+
return i < 0 || i >= len ? { v : VUndef, t : t } : { v: VMapPair(key,value), t : t };
1367+
case VMapPair(key, _) if( name == "$key" ):
1368+
return key;
1369+
case VMapPair(_, value) if( name == "$value" ):
1370+
return value;
13601371
default:
13611372
}
13621373
var a = readFieldAddress(v, name);

hld/Value.hx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ enum ValueRepr {
1414
VMethod( f : FunRepr, obj : Value, p : Pointer );
1515
VArray( t : HLType, length : Int, read : Int -> Value, p : Pointer );
1616
VMap( tkey : HLType, nkeys : Int, readKey : Int -> Value, readValue : Int -> Value, p : Pointer );
17+
VMapPair( key : Value, value : Value );
1718
VType( t : HLType );
1819
VEnum( c : String, values : Array<Value>, p : Pointer );
1920
VBytes( length : Int, read : Int -> Int, p : Pointer );

src/HLAdapter.hx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ enum VarValue {
1111
VValue( v : hld.Value, evalName : String );
1212
VUnkownFile( file : String );
1313
VObjFields( v : hld.Value, o : format.hl.Data.ObjPrototype, evalName : String );
14-
VMapPair( key : hld.Value, value : hld.Value );
1514
VStatics( cl : String );
1615
VStack( stack : Array<hld.Debugger.StackInfo> );
1716
}
@@ -762,6 +761,9 @@ class HLAdapter extends DebugSession {
762761
case VInlined(fields):
763762
var str = dbg.eval.valueStr(value);
764763
return { name : name, type : tstr, value : str, evaluateName : evalName ?? "#" + str, variablesReference : fields.length == 0 ? 0 : allocValue(VValue(value, evalName)), namedVariables : fields.length };
764+
case VMapPair(_, _):
765+
var str = dbg.eval.valueStr(value);
766+
return { name : name, type : tstr, value : str + pstr, evaluateName : evalName ?? "#" + str, variablesReference : allocValue(VValue(value, evalName)), namedVariables : 2 };
765767
case VString(_, _):
766768
if( value.hint == HNone )
767769
value.hint = HNoEscape;
@@ -877,13 +879,9 @@ class HLAdapter extends DebugSession {
877879
var key = getKey(i);
878880
var value = getValue(i);
879881
if( tkey == HDyn ) {
880-
vars.push({
881-
name : "" + i,
882-
value : "",
883-
variablesReference : allocValue(VMapPair(key,value)),
884-
});
882+
vars.push(makeVar("" + i, { v: VMapPair(key,value), t : tkey }, evalName == null ? null : evalName+".$"+i));
885883
} else
886-
vars.push(makeVar(dbg.eval.valueStr(key), value));
884+
vars.push(makeVar(dbg.eval.valueStr(key), value, evalName == null ? null : evalName+".$"+i+".$value"));
887885
} catch( e : Dynamic ) {
888886
vars.push({
889887
name : "" + i,
@@ -892,6 +890,9 @@ class HLAdapter extends DebugSession {
892890
});
893891
}
894892
}
893+
case VMapPair(key, value):
894+
vars.push(makeVar("key", key, evalName == null ? null : evalName+".$key"));
895+
vars.push(makeVar("value", value, evalName == null ? null : evalName+".$value"));
895896
case VClosure(_, context, _):
896897
if( context != null )
897898
switch( context.t ) {
@@ -936,9 +937,6 @@ class HLAdapter extends DebugSession {
936937
if( v.t.match(HFun(_)) ) continue;
937938
vars.push(makeVar(f, v, cl+"."+f));
938939
}
939-
case VMapPair(key, value):
940-
vars.push(makeVar("key", key));
941-
vars.push(makeVar("value", value));
942940
case VStack(stack):
943941
for( i in 0...stack.length ) {
944942
var st = stack[i];

0 commit comments

Comments
 (0)