public static string GenerateVariableName(VariableModifierKind modifier, ValueKind kind, short index, bool isTopLevel) { switch (kind) { case ValueKind.Int: switch (modifier) { case VariableModifierKind.Local: return(isTopLevel ? $"sVar{index}" : $"var{index}"); case VariableModifierKind.Global: return(isTopLevel ? $"gVar{index}" : $"gVar{index}"); } break; case ValueKind.Float: switch (modifier) { case VariableModifierKind.Local: return(isTopLevel ? $"sfVar{index}" : $"fVar{index}"); case VariableModifierKind.Global: return(isTopLevel ? $"gfVar{index}" : $"gfVar{index}"); } break; } Debug.Assert(false); return(null); }
public static object Gen(FuncDef fd, object arg, CallExpr ce) { ValueKind kind = KindOf(arg); var call = New((Fx)fd.func, arg, fd.flagsArgCanBeVector != 0, fd.resultCanBeLazy, ce); return(call.Gen((kind == ValueKind.Const && fd.isNotPure) ? ValueKind.Sync : kind)); }
/// <summary> /// Gets kind of a remote setting value. /// </summary> /// <param name="collectionPath">Path to the remote setting collection in the form My\Custom\Path</param> /// <param name="key">Key of the remote setting</param> /// <returns>Kind of the value or unknown if it does not exist or error.</returns> public ValueKind GetValueKind(string collectionPath, string key) { RequiresNotDisposed(); CodeContract.RequiresArgumentNotNull <string>(collectionPath, "collectionPath"); CodeContract.RequiresArgumentNotNull <string>(key, "key"); ValueKind valueKind = ValueKind.Unknown; if (AllRemoteSettingsProviders.Any()) { bool isFirst = true; ValueKind firstKind = valueKind; ValueKind currentKind; if (AllRemoteSettingsProviders.All(delegate(IRemoteSettingsProvider x) { if (x.TryGetValueKind(collectionPath, key, out currentKind)) { if (isFirst) { firstKind = currentKind; isFirst = false; } return(firstKind == currentKind); } return(true); })) { valueKind = firstKind; } } return(valueKind); }
public ICheckLogic <T> DefineExpectedValues(IEnumerable values, long count, string comparisonMessage = null, string newNegatedComparison = null) { this.expectedKind = ValueKind.Values; this.expectedCount = count; return(this.DefineExpectedValue(values, comparisonMessage, newNegatedComparison)); }
/// <summary> /// Constructs a new abstract object operation. /// </summary> /// <param name="kind">The value kind.</param> /// <param name="basicBlock">The parent basic block.</param> /// <param name="initialType">The initial node type.</param> internal ObjectOperationValue( ValueKind kind, BasicBlock basicBlock, TypeNode initialType) : base(kind, basicBlock, initialType) { }
public ICheckLogic <T> DefineExpectedValues <TU>(IEnumerable <TU> values, long count, string comparisonMessage = null, string newNegatedComparison = null) { this.DefineExpectations(values, false, comparisonMessage, newNegatedComparison, count, typeof(TU)); this.expectedKind = ValueKind.Values; return(this); }
/// <summary> /// Constructs a new value. /// </summary> /// <param name="kind">The value kind.</param> /// <param name="basicBlock">The parent basic block.</param> /// <param name="constantType">The constant type node.</param> internal DeviceConstantValue( ValueKind kind, BasicBlock basicBlock, TypeNode constantType) : base(kind, basicBlock, constantType) { }
public ICheckLogic <T> DefinePossibleTypes(IEnumerable <System.Type> values, string comparisonMessage = null, string newNegatedComparison = null) { this.DefineExpectations(new TypeEnumerationValue(values), false, comparisonMessage, newNegatedComparison, values.Count(), typeof(System.Type)); this.expectedKind = ValueKind.Types; return(this); }
internal EvaluationResult(EvaluationContext context, Int32 level, Object val, ValueKind kind) { m_level = level; Value = val; Kind = kind; TraceValue(context); }
internal static String FormatValue( ISecretMasker secretMasker, Object value, ValueKind kind) { switch (kind) { case ValueKind.Null: return(ExpressionConstants.Null); case ValueKind.Boolean: return(((Boolean)value) ? ExpressionConstants.True : ExpressionConstants.False); case ValueKind.Number: var strNumber = ((Double)value).ToString(ExpressionConstants.NumberFormat, CultureInfo.InvariantCulture); return(secretMasker != null?secretMasker.MaskSecrets(strNumber) : strNumber); case ValueKind.String: // Mask secrets before string-escaping. var strValue = secretMasker != null?secretMasker.MaskSecrets(value as String) : value as String; return($"'{StringEscape(strValue)}'"); case ValueKind.Array: case ValueKind.Object: return(kind.ToString()); default: // Should never reach here. throw new NotSupportedException($"Unable to convert to realized expression. Unexpected value kind: {kind}"); } }
public static bool TryGetValueKind(Type type, out ValueKind kind) { if (type == typeof(int)) { kind = ValueKind.Int32; return(true); } if (type == typeof(long)) { kind = ValueKind.Int64; return(true); } if (type == typeof(float)) { kind = ValueKind.Float32; return(true); } if (type == typeof(double)) { kind = ValueKind.Float64; return(true); } kind = default(ValueKind); return(false); }
public Variable Push(ValueKind type) { Variable variable = Variable.Stack(type, varCount++); Stack.Push(variable); return(variable); }
private void TraceTreeResult( EvaluationContext context, Object result, ValueKind kind) { // Get the realized expression String realizedExpression = ConvertToRealizedExpression(context); // Format the result String traceValue = ExpressionUtility.FormatValue(context.SecretMasker, result, kind); // Only trace the realized expression if it is meaningfully different if (!String.Equals(realizedExpression, traceValue, StringComparison.Ordinal)) { if (kind == ValueKind.Number && String.Equals(realizedExpression, $"'{traceValue}'", StringComparison.Ordinal)) { // Don't bother tracing the realized expression when the result is a number and the // realized expresion is a precisely matching string. } else { context.Trace.Info($"Expanded: {realizedExpression}"); } } // Always trace the result context.Trace.Info($"Result: {traceValue}"); }
public static wasm_val_t ToValue(object o, ValueKind kind) { wasm_val_t value = new wasm_val_t(); switch (kind) { case ValueKind.Int32: value.kind = wasm_valkind_t.WASM_I32; value.of.i32 = (int)Convert.ChangeType(o, TypeCode.Int32); break; case ValueKind.Int64: value.kind = wasm_valkind_t.WASM_I64; value.of.i64 = (long)Convert.ChangeType(o, TypeCode.Int64); break; case ValueKind.Float32: value.kind = wasm_valkind_t.WASM_F32; value.of.f32 = (float)Convert.ChangeType(o, TypeCode.Single); break; case ValueKind.Float64: value.kind = wasm_valkind_t.WASM_F64; value.of.f64 = (double)Convert.ChangeType(o, TypeCode.Double); break; // TODO: support AnyRef default: throw new NotSupportedException("Unsupported value type."); } return(value); }
/// <summary> /// Constructs a new pointer value. /// </summary> /// <param name="kind">The value kind.</param> /// <param name="basicBlock">The parent basic block.</param> /// <param name="initialType">The initial node type.</param> internal PointerValue( ValueKind kind, BasicBlock basicBlock, TypeNode initialType) : base(kind, basicBlock, initialType) { }
public ICheckLogic <T> ExpectingValues(IEnumerable values, long count, string comparisonMessage = null, string negatedComparison = null, string expectedLabel = null, string negatedExpLabel = null) { this.expectedKind = ValueKind.Values; this.expectedCount = count; return(this.Expecting(values, comparisonMessage, negatedComparison, expectedLabel, negatedExpLabel)); }
public IValue GetOrCreateValue(VPath vpath, Func <Stream> content, ValueKind valueKind) { using (Vault.ExposeReadOnly()) { var steps = vpath.Steps.ToArray(); var parent = (Branch)GetOrCreateBranch(steps.Take(steps.Length - 1).ToArray()); var regularValue = (valueKind & ValueKind.Regular) != 0 ? parent.Children.Values[steps.Last()] : null; var internalValue = (valueKind & ValueKind.Internal) != 0 ? parent.Children.InternalValues[steps.Last()] : null; var value = regularValue ?? internalValue; if (value != null) { return(value); } else { using (Vault.ExposeReadWrite()) { var newValue = new Value(Vault, steps.Last(), null); newValue.Parent = parent; newValue.SetContent(content); return(newValue); } } } }
static void Assert(ValueKind?forceValue, ValueKind type) { if (forceValue is not null && forceValue.Value != type) { throw new DataException("Value is not of the forced type."); } }
internal MutableGlobal(Interop.StoreHandle store, T initialValue) { if (!Interop.TryGetValueKind(typeof(T), out var kind)) { throw new WasmtimeException($"Mutable global variables cannot be of type '{typeof(T).ToString()}'."); } Kind = kind; var value = Interop.ToValue((object)initialValue, Kind); var valueType = Interop.wasm_valtype_new(value.kind); var valueTypeHandle = valueType.DangerousGetHandle(); valueType.SetHandleAsInvalid(); using var globalType = Interop.wasm_globaltype_new( valueTypeHandle, Interop.wasm_mutability_t.WASM_VAR ); unsafe { Handle = Interop.wasm_global_new(store, globalType, &value); if (Handle.IsInvalid) { throw new WasmtimeException("Failed to create mutable Wasmtime global."); } } }
public bool TryGetValueKind(string collectionPath, string key, out ValueKind kind) { collectionPath = collectionPath.NormalizePath(); kind = ValueKind.Unknown; if (collections.TryGetValue(collectionPath, out KeyValueCollection value) && value.Properties.TryGetValue(key, out object value2)) { Type type = value2.GetType(); if (type == typeof(double) || type == typeof(ulong) || type == typeof(long)) { kind = ValueKind.QWord; } else if (type == typeof(short) || type == typeof(ushort) || type == typeof(int) || type == typeof(uint) || type == typeof(float) || type == typeof(bool)) { kind = ValueKind.DWord; } else if (type == typeof(string)) { kind = ValueKind.String; } else { kind = ValueKind.Unknown; } return(true); } return(false); }
public IReadOnlyDictionary <NameString, ArgumentValue> CoerceArguments( IVariableValueCollection variables, ITypeConversion converter) { if (_hasArgumentErrors) { throw new QueryException(_args.Values.Select(t => t.Error)); } if (_vars == null) { return(_args); } var args = _args.ToDictionary(t => t.Key, t => t.Value); foreach (KeyValuePair <NameString, ArgumentVariableValue> var in _vars) { IError error = null; if (variables.TryGetVariable( var.Value.VariableName, out object value)) { value = var.Value.CoerceValue(value); } else { value = var.Value.DefaultValue; if (var.Value.Type.NamedType().IsLeafType() && value is IValueNode literal) { value = var.Value.Type.ParseLiteral(literal); } if (var.Value.Type.IsNonNullType() && (value is null || value is NullValueNode)) { error = ErrorBuilder.New() .SetMessage(string.Format( CultureInfo.InvariantCulture, TypeResources.ArgumentValueBuilder_NonNull, var.Key, TypeVisualizer.Visualize(var.Value.Type))) .AddLocation(Selection) .SetExtension(_argumentProperty, Path.New(var.Key)) .SetPath(_path) .Build(); } } if (error is null) { ValueKind kind = ValueKind.Unknown; if (value is IValueNode literal) { kind = literal.GetValueKind();
public IValue CreateValue(VPath vpath, Func <Stream> content, ValueKind valueKind) { using (Vault.ExposeReadWrite()) { GetValue(vpath).AssertNull(); return(GetOrCreateValue(vpath, content, valueKind)); } }
/// <summary> /// Constructs a new cast value. /// </summary> /// <param name="kind">The value kind.</param> /// <param name="basicBlock">The parent basic block.</param> /// <param name="value">The value to convert.</param> /// <param name="targetType">The target type to convert the value to.</param> internal BaseAddressSpaceCast( ValueKind kind, BasicBlock basicBlock, ValueReference value, AddressSpaceType targetType) : base(kind, basicBlock, value, targetType) { }
/// <summary> /// Constructs a new generic barrier operation. /// </summary> /// <param name="kind">The value kind.</param> /// <param name="basicBlock">The parent basic block.</param> /// <param name="values">Additional values.</param> /// <param name="initialType">The initial node type.</param> internal BarrierOperation( ValueKind kind, BasicBlock basicBlock, ImmutableArray <ValueReference> values, TypeNode initialType) : base(kind, basicBlock, values, initialType) { }
public void ItHasTheExpectedGlobalExports(string exportName, ValueKind expectedKind, bool expectedMutable) { var export = Fixture.Module.Exports.Globals.Where(f => f.Name == exportName).FirstOrDefault(); export.Should().NotBeNull(); export.Kind.Should().Be(expectedKind); export.IsMutable.Should().Be(expectedMutable); }
/// <summary> /// Constructs a view property. /// </summary> /// <param name="kind">The value kind.</param> /// <param name="basicBlock">The parent basic block.</param> /// <param name="initialType">The initial node type.</param> /// <param name="view">The underlying view.</param> internal ViewPropertyValue( ValueKind kind, BasicBlock basicBlock, ValueReference view, TypeNode initialType) : base(kind, basicBlock, initialType) { Seal(ImmutableArray.Create(view)); }
/// <summary> /// Constructs a new constant value. /// </summary> /// <param name="kind">The value kind.</param> /// <param name="basicBlock">The parent basic block.</param> /// <param name="constantType">The type of the constant node.</param> internal ConstantNode( ValueKind kind, BasicBlock basicBlock, TypeNode constantType) : base(kind, basicBlock, constantType) { ConstantType = constantType; Seal(ImmutableArray <ValueReference> .Empty); }
public static object GenFnCall(FuncDef fd, IList lst, ValueKind argMaxKind, CallExpr ce) { Fn fn = (Fn)fd.func; Fx fx = delegate(object arg) { return(fn((IList)arg)); }; var valueKind = fd.resultCanBeLazy ? ValueKind.Async : (argMaxKind == ValueKind.Const && fd.isNotPure) ? ValueKind.Sync : argMaxKind; var call = FxCall.New(arg => fn((IList)arg), lst, true, fd.resultCanBeLazy, ce); return(call.Gen(valueKind)); }
/// <summary> /// Constructs a new terminator value that is marked. /// </summary> /// <param name="kind">The value kind.</param> /// <param name="basicBlock">The parent basic block.</param> /// <param name="targets">The associated targets.</param> /// <param name="initialType">The initial node type.</param> protected TerminatorValue( ValueKind kind, BasicBlock basicBlock, ImmutableArray <BasicBlock> targets, TypeNode initialType) : base(kind, basicBlock, initialType) { Targets = targets; }
public void ItHasTheExpectedTableExports(string exportName, ValueKind expectedKind, uint expectedMinimum, uint expectedMaximum) { var export = Fixture.Module.Exports.Tables.Where(f => f.Name == exportName).FirstOrDefault(); export.Should().NotBeNull(); export.Kind.Should().Be(expectedKind); export.Minimum.Should().Be(expectedMinimum); export.Maximum.Should().Be(expectedMaximum); }
public VoiceParm(VoiceParmKind kind, string name, string description, ValueKind valueKind, Object value, int index, bool common, float min, float max) { this.kind = kind; this.name = name; this.description = description; this.valueKind = valueKind; this.value = value; this.common = common; this.fmin = min; this.fmax = max; this.ctlIndex = index; }
public void Add(VoiceParmKind kind, string name, string description, ValueKind valueKind, Object value, int index, bool common) { switch (valueKind) { case ValueKind.Int: Add(kind, name, description, valueKind, value, index, common, Int32.MinValue, Int32.MaxValue); break; case ValueKind.Float: Add(kind, name, description, valueKind, value, index, common, Single.MinValue, Single.MaxValue); break; default: Add(kind, name, description, valueKind, value, index, common, 0, 0); break; } }
public void Add(VoiceParmKind kind, string name, string description, ValueKind valueKind, Object value, int index, bool common, float min, float max) { VoiceParm newParm = new VoiceParm(kind, name, description, valueKind, value, index, common, min, max); Add(newParm); }
/// <summary>Shows values to the user</summary> /// <param name="vk">Which values to show</param> public void ShowValues(ValueKind vk) { if (!AdvancedConfig.InfoPane) { return; } if (form == null) { return; } if (form.InvokeRequired) { form.BeginInvoke(new Action<ValueKind>(ShowValues), vk); return; } if (!form.panInfoPane.Visible) { return; } if ((vk & ValueKind.ActualSpeed) != 0) { form.lblSpeed.Text = (ActualSpeed * AdvancedConfig.SpeedMultiplier).ToString("0.0") + AdvancedConfig.SpeedUnitName; } if ((vk & ValueKind.Avg) != 0) { form.lblAverage.Text = (AverageSpeed * AdvancedConfig.SpeedMultiplier).ToString("0.0") + AdvancedConfig.SpeedUnitName; } if ((vk & ValueKind.Distance) != 0) { form.lblDistance.Text = (SumLength * AdvancedConfig.DistanceMultiplier).ToString("0.000") + AdvancedConfig.DistanceUnitName; } if ((vk & ValueKind.Aerial) != 0) { form.lblAerial.Text = (AerialDistance * AdvancedConfig.DistanceMultiplier).ToString("0.000") + AdvancedConfig.DistanceUnitName; } if ((vk & ValueKind.ElePlus) != 0) { form.lblElevation.Text = (SumElePlus * AdvancedConfig.ElevationMultiplier).ToString("0") + AdvancedConfig.ElevationUnitName; } if ((vk & ValueKind.EleMinus) != 0) { form.lblElevationMinus.Text = (SumEleMinus * AdvancedConfig.ElevationMultiplier).ToString("0") + AdvancedConfig.ElevationUnitName; } if ((vk & ValueKind.Time) != 0) { form.lblTime.Text = string.Format("{1:0}{0}{2:00}{0}{3:00}", CultureInfo.CurrentCulture.DateTimeFormat.TimeSeparator, Math.Floor(Time.TotalHours), Math.Abs(Time.Minutes), Math.Abs(Time.Seconds)); } if ((vk & ValueKind.StopTime) != 0) { form.lblStopTime.Text = string.Format("{1:0}{0}{2:00}{0}{3:00}", CultureInfo.CurrentCulture.DateTimeFormat.TimeSeparator, Math.Floor(PauseTime.TotalHours), Math.Abs(PauseTime.Minutes), Math.Abs(PauseTime.Seconds)); } if ((vk & ValueKind.Points) != 0) { form.lblPoints.Text = PointsTotal.ToString(); } if ((vk & ValueKind.Sats) != 0) { form.lblSatellites.Text = CurrentSats.ToString(); } }
public IValue[] GetValues(ValueKind valueKind) { using (Vault.ExposeReadOnly()) { var regularValues = (valueKind & ValueKind.Regular) != 0 ? Children.Values.Cast<IValue>() : Enumerable.Empty<IValue>(); var internalValues = (valueKind & ValueKind.Internal) != 0 ? Children.InternalValues.Cast<IValue>() : Enumerable.Empty<IValue>(); // no laziness here since it's a thread-unsafe approach return regularValues.Concat(internalValues).ToArray(); } }
public IValue[] GetValuesRecursive(ValueKind valueKind) { using (Vault.ExposeReadOnly()) { var regularValues = (valueKind & ValueKind.Regular) != 0 ? this.Flatten(b => b.Children.Branches).SelectMany(b => b.Children.Values).Cast<IValue>() : Enumerable.Empty<IValue>(); var internalValues = (valueKind & ValueKind.Internal) != 0 ? this.Flatten(b => b.Children.Branches).SelectMany(b => b.Children.InternalValues).Cast<IValue>() : Enumerable.Empty<IValue>(); // no laziness here since it's a thread-unsafe approach return regularValues.Concat(internalValues).ToArray(); } }
public IValue GetOrCreateValue(VPath vpath, Func<Stream> content, ValueKind valueKind) { using (Vault.ExposeReadOnly()) { var steps = vpath.Steps.ToArray(); var parent = (Branch)GetOrCreateBranch(steps.Take(steps.Length - 1).ToArray()); var regularValue = (valueKind & ValueKind.Regular) != 0 ? parent.Children.Values[steps.Last()] : null; var internalValue = (valueKind & ValueKind.Internal) != 0 ? parent.Children.InternalValues[steps.Last()] : null; var value = regularValue ?? internalValue; if (value != null) { return value; } else { using (Vault.ExposeReadWrite()) { var newValue = new Value(Vault, steps.Last(), null); newValue.Parent = parent; newValue.SetContent(content); return newValue; } } } }
public IValue CreateValue(VPath vpath, Func<Stream> content, ValueKind valueKind) { using (Vault.ExposeReadWrite()) { GetValue(vpath).AssertNull(); return GetOrCreateValue(vpath, content, valueKind); } }
public VoiceParm(VoiceParm other) { this.kind = other.kind; this.name = other.name; this.description = other.description; this.valueKind = other.valueKind; this.value = other.value; this.imin = other.imin; this.imax = other.imax; this.fmin = other.fmin; this.fmax = other.fmax; this.ctlIndex = other.ctlIndex; this.ret = other.ret; }