private bool IsValuePrimitive() { if (m_fIsBoxed || m_fIsEnum) { if (m_valuePrimitive == null) { if (_rtv.IsBoxed) { RuntimeValue rtv = _rtv.GetField(1, 0); Debug.Assert(rtv.IsPrimitive); //Assert that m_class really points to a primitive m_valuePrimitive = (CorDebugValuePrimitive)CreateValue(rtv); } else { Debug.Assert(m_fIsEnum); m_valuePrimitive = new CorDebugValuePrimitive(_rtv, _appDomain); Debug.Assert(_rtv.IsPrimitive); } } } return(m_valuePrimitive != null); }
private static async Task <RuntimeValue> ExpandValueAsync(RuntimeValue value, RompExecutionContext context) { switch (value.ValueType) { case RuntimeValueType.Scalar: return(await context.ExpandVariablesAsync(value.AsString())); case RuntimeValueType.Vector: var list = new List <RuntimeValue>(); foreach (var item in value.AsEnumerable()) { list.Add(await ExpandValueAsync(item, context)); } return(new RuntimeValue(list)); case RuntimeValueType.Map: var map = new Dictionary <string, RuntimeValue>(); foreach (var pair in value.AsDictionary()) { map.Add(pair.Key, await ExpandValueAsync(pair.Value, context)); } return(new RuntimeValue(map)); default: throw new ArgumentException(); } }
private static void WriteRuntimeValue(BinaryWriter writer, RuntimeValue value) { var type = value.ValueType; writer.Write((byte)type); if (type == RuntimeValueType.Scalar) { writer.Write(value.AsString() ?? string.Empty); } else if (type == RuntimeValueType.Vector) { var list = value.AsEnumerable().ToList(); SlimBinaryFormatter.WriteLength(writer, list.Count); foreach (var i in list) { WriteRuntimeValue(writer, i); } } else if (type == RuntimeValueType.Map) { WriteDictionary(writer, value.AsDictionary()); } else { throw new ArgumentException("Unknown value type: " + type); } }
public static CorDebugClass ClassFromRuntimeValue(RuntimeValue rtv, CorDebugAppDomain appDomain) { RuntimeValue_Reflection rtvf = rtv as RuntimeValue_Reflection; CorDebugClass cls = null; object objBuiltInKey = null; Debug.Assert(!rtv.IsNull); if (rtvf != null) { objBuiltInKey = rtvf.ReflectionType; } else if (rtv.DataType == RuntimeDataType.DATATYPE_TRANSPARENT_PROXY) { objBuiltInKey = RuntimeDataType.DATATYPE_TRANSPARENT_PROXY; } else { cls = nanoCLR_TypeSystem.CorDebugClassFromTypeIndex(rtv.Type, appDomain);; } if (objBuiltInKey != null) { CorDebugProcess.BuiltinType builtInType = appDomain.Process.ResolveBuiltInType(objBuiltInKey); cls = builtInType.GetClass(appDomain); if (cls == null) { cls = new CorDebugClass(builtInType.GetAssembly(appDomain), builtInType.TokenCLR); } } return(cls); }
private bool IsValuePrimitive() { if (m_fIsBoxed || m_fIsEnum) { if (m_valuePrimitive == null) { if (m_rtv.IsBoxed) { var getField = m_rtv.GetFieldAsync(1, 0); getField.Wait(); RuntimeValue rtv = getField.Result; Debug.Assert(rtv.IsPrimitive); //Assert that m_class really points to a primitive m_valuePrimitive = (CorDebugValuePrimitive)CreateValue(rtv); } else { Debug.Assert(m_fIsEnum); m_valuePrimitive = new CorDebugValuePrimitive(m_rtv, m_appDomain); Debug.Assert(m_rtv.IsPrimitive); } } } return(m_valuePrimitive != null); }
private static void WriteJson(JsonTextWriter json, RuntimeValue data) { switch (data.ValueType) { case RuntimeValueType.Scalar: json.WriteValue(data.AsString()); break; case RuntimeValueType.Vector: json.WriteStartArray(); foreach (var v in data.AsEnumerable()) { WriteJson(json, v); } json.WriteEndArray(); break; case RuntimeValueType.Map: json.WriteStartObject(); foreach (var v in data.AsDictionary()) { json.WritePropertyName(v.Key); WriteJson(json, v.Value); } json.WriteEndObject(); break; } }
protected override object CoerceScalarValue(RuntimeValue value, Type type, PropertyInfo property) { if (type == typeof(TimeSpan)) { var maybeDouble = value.AsString(); if (maybeDouble == null) { throw new ValueCoercionException(value, type); } if (!double.TryParse(maybeDouble, out double dvalue)) { throw new ValueCoercionException(value, type); } var tsUnit = property.GetCustomAttribute <TimeSpanUnitAttribute>(); if (tsUnit != null) { return(tsUnit.GetTimeSpan(dvalue)); } return(TimeSpan.FromSeconds(dvalue)); } else { return(base.CoerceScalarValue(value, type, property)); } }
int ICorDebugObjectValue.GetFieldValue(ICorDebugClass pClass, uint fieldDef, out ICorDebugValue ppValue) { //cache fields? RuntimeValue rtv = _rtv.GetField(0, nanoCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, ((CorDebugClass)pClass).Assembly)); ppValue = CreateValue(rtv); return(COM_HResults.S_OK); }
//Object or CLASS, or VALUETYPE public CorDebugValueObject(RuntimeValue rtv, CorDebugAppDomain appDomain) : base(rtv, appDomain) { if (!rtv.IsNull) { m_class = CorDebugValue.ClassFromRuntimeValue(rtv, appDomain); m_fIsEnum = m_class.IsEnum; m_fIsBoxed = rtv.IsBoxed; } }
int ICorDebugReferenceValue.SetValue(ulong value) { Debug.Assert(value <= uint.MaxValue); RuntimeValue rtvNew = _rtv.Assign((uint)value); RuntimeValue = rtvNew; return(COM_HResults.S_OK); }
public static IEnumerable <RuntimeValue> ParseDictionary(this RuntimeValue val) { if ((val.AsDictionary()?.Keys.Count ?? 0) <= 0) { return(null); } return(new List <RuntimeValue> { val }); }
public LiteralExecuter(Literal literal) : base(literal) { value = literal.ValueType switch { LiteralType.Boolean => literal.BooleanValue ? BooleanValue.True : BooleanValue.False, LiteralType.Integer => IntegerValue.Create(literal.IntegerValue), LiteralType.String => new StringValue(literal.StringValue), LiteralType.Time => new TimeValue(literal.TimeValue), _ => throw new NotImplementedException($"Literal type {literal.ValueType} is not implemented in interpreter") }; }
int ICorDebugType.GetStaticFieldValue(uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue) { uint fd = nanoCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, this.Assembly); this.Process.SetCurrentAppDomain(this.AppDomain); RuntimeValue rtv = this.Engine.GetStaticFieldValue(fd); ppValue = CorDebugValue.CreateValue(rtv, this.AppDomain); return(COM_HResults.S_OK); }
public override RuntimeValue Execute(ExecutionContext context) { RuntimeValue result = op switch { UnaryOperator.Plus => IntegerValue.Create(argument.Execute(context).AsInteger(argument)), UnaryOperator.Minus => IntegerValue.Create(-argument.Execute(context).AsInteger(argument)), UnaryOperator.Not => argument.Execute(context).AsBoolean(argument) ? BooleanValue.False : BooleanValue.True, _ => throw new NotImplementedException($"Unary operator {op} not implemented."), }; return(result); }
public void Update(Node node, RuntimeValue value) { if (IsConstant) { ErrorHelper.ThrowTypeError(node, $"Cannot assign {value} to {Name} - it's a constant"); } if (IsImmutable) { ErrorHelper.ThrowTypeError(node, $"Cannot assign {value} to {Name} - it's immutable (e.g. a loop counter)"); } UpdateWithNoChecks(value); }
public static CorDebugValue CreateValue(RuntimeValue rtv, CorDebugAppDomain appDomain) { CorDebugValue val = null; bool fIsReference; if (rtv.IsBoxed) { val = new CorDebugValueBoxedObject(rtv, appDomain); fIsReference = true; } else if (rtv.IsPrimitive) { CorDebugClass c = ClassFromRuntimeValue(rtv, appDomain); if (c.IsEnum) { val = new CorDebugValueObject(rtv, appDomain); fIsReference = false; } else { val = new CorDebugValuePrimitive(rtv, appDomain); fIsReference = false; } } else if (rtv.IsArray) { val = new CorDebugValueArray(rtv, appDomain); fIsReference = true; } else if (rtv.CorElementType == CorElementType.ELEMENT_TYPE_STRING) { val = new CorDebugValueString(rtv, appDomain); fIsReference = true; } else { val = new CorDebugValueObject(rtv, appDomain); fIsReference = !rtv.IsValueType; } if (fIsReference) { val = new CorDebugValueReference(val, val.m_rtv, val.m_appDomain); } if (rtv.IsReference) //CorElementType.ELEMENT_TYPE_BYREF { val = new CorDebugValueReferenceByRef(val, val.m_rtv, val.m_appDomain); } return(val); }
/// Implements <CompareExpr> ::= <Value> LIKE StringLiteral public Reduction CreateRULE_COMPAREEXPR_LIKE_STRINGLITERAL(Reduction reduction) { object lhs = ((Reduction)((Token)reduction.GetToken(0)).Data).Tag; RuntimeValue rhs = new RuntimeValue(); Predicate predicate = ExpressionBuilder.CreateLikePatternPredicate(lhs, rhs); reduction.Tag = predicate; if (NCacheLog.IsInfoEnabled) { NCacheLog.Info("CreateRULE_COMPAREEXPR_LIKE_STRINGLITERAL"); } return(null); }
/// <summary> /// Invoked when the user selects an object in the stack tree view. /// </summary> /// <param name="sender">Object that caused this event to be triggered.</param> /// <param name="e">Arguments explaining why this event occured.</param> private void stackTreeView_AfterSelect(object sender, TreeViewEventArgs e) { int top = _scriptThread.Stack.TopIndex > _scriptThread.Stack.FrameIndex ? _scriptThread.Stack.TopIndex : _scriptThread.Stack.FrameIndex; for (int i = 0; i < top; i++) { RuntimeValue runtimeValue = _scriptThread.Stack.RawStack[i]; if (i == stackTreeView.SelectedNode.Index) { stackPropertyGrid.SelectedObject = runtimeValue; } } }
int ICorDebugClass.GetStaticFieldValue(uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue) { //Cache, and invalidate when necessary??? uint fd = nanoCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, Assembly); Process.SetCurrentAppDomain(AppDomain); RuntimeValue rtv = Engine.GetStaticFieldValue(fd); ppValue = CorDebugValue.CreateValue(rtv, AppDomain); return(COM_HResults.S_OK); }
public RompSessionVariable(RuntimeVariableName name, RuntimeValue value) { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (name.Type != value.ValueType) { throw new ArgumentException("Invalid variable value type."); } this.Name = name; this.value = value; }
int ICorDebugReferenceValue.SetValue(ulong value) { Debug.Assert(value <= uint.MaxValue); var assign = m_rtv.AssignAsync((uint)value); assign.Wait(); RuntimeValue rtvNew = assign.Result; this.RuntimeValue = rtvNew; return(COM_HResults.S_OK); }
int ICorDebugClass.GetStaticFieldValue(uint fieldDef, ICorDebugFrame pFrame, out ICorDebugValue ppValue) { //Cache, and invalidate when necessary??? uint fd = nanoCLR_TypeSystem.ClassMemberIndexFromCLRToken(fieldDef, this.Assembly); this.Process.SetCurrentAppDomain(this.AppDomain); var getField = this.Engine.GetStaticFieldValueAsync(fd); getField.Wait(); RuntimeValue rtv = getField.Result; ppValue = CorDebugValue.CreateValue(rtv, this.AppDomain); return(COM_HResults.S_OK); }
int ICorDebugThread.GetObject(out ICorDebugValue ppObject) { Debug.Assert(!IsVirtualThread); RuntimeValue rv = Engine.GetThread(ID); if (rv != null) { ppObject = CorDebugValue.CreateValue(rv, AppDomain); } else { ppObject = null; } return(COM_HResults.S_OK); }
public static object ConvertToPSValue(RuntimeValue value) { if (value.ValueType == RuntimeValueType.Scalar) { var s = value.AsString() ?? string.Empty; if (s.StartsWith(Functions.PsCredentialVariableFunction.Prefix)) { return(Functions.PsCredentialVariableFunction.Deserialize(s.Substring(Functions.PsCredentialVariableFunction.Prefix.Length))); } if (string.Equals(s, "true", StringComparison.OrdinalIgnoreCase)) { return(true); } if (string.Equals(s, "false", StringComparison.OrdinalIgnoreCase)) { return(false); } return(s); } else if (value.ValueType == RuntimeValueType.Vector) { return(value.AsEnumerable().Select(v => v.ToString() ?? string.Empty).ToArray()); } else if (value.ValueType == RuntimeValueType.Map) { var hashTable = new Hashtable(); foreach (var pair in value.AsDictionary()) { hashTable[pair.Key] = ConvertToPSValue(pair.Value); } return(hashTable); } else { return(null); } }
int ICorDebugThread.GetObject(out ICorDebugValue ppObject) { Debug.Assert(!IsVirtualThread); var getThread = Engine.GetThreadAsync(ID); getThread.Wait(); RuntimeValue rv = getThread.Result; if (rv != null) { ppObject = CorDebugValue.CreateValue(rv, this.AppDomain); } else { ppObject = null; } return(COM_HResults.S_OK); }
static PsModulePackageConfiguration parseModule(RuntimeValue value) { var module = value.AsDictionary(); if (module == null) { return(null); } if (!module.TryGetValue("Name", out var name) || string.IsNullOrWhiteSpace(name.AsString())) { return(null); } module.TryGetValue("Version", out var version); module.TryGetValue("ModuleType", out var moduleType); return(new PsModulePackageConfiguration { PackageName = name.AsString(), PackageVersion = version.AsString() ?? string.Empty, ModuleType = moduleType.AsString() }); }
internal static object CoerceValue(RuntimeValue value, PropertyInfo property, Type type = null) => core.CoerceValue(value, property, type);
public CorDebugValueArray(RuntimeValue rtv, CorDebugAppDomain appDomain) : base(rtv, appDomain) { }
public CorDebugValueReferenceByRef(CorDebugValue val, RuntimeValue rtv, CorDebugAppDomain appDomain) : base(val, rtv, appDomain) { }
public CorDebugValueReference(CorDebugValue val, RuntimeValue rtv, CorDebugAppDomain appDomain) : base(rtv, appDomain) { m_value = val; }