public override void Eval(EvaluatorState ev) { //Console.WriteLine(this.ToString()); // calling a function = entering a deeper run level ev.IncreaseRunLevel(); // get the number of local variables int numlocals = parameter; // push(reg_FP) ev.Stack.Push(new STFPValue(ev.RegFP)); // set FP to current stack position ev.RegFP = ev.Stack.StackTop; // create room for local variables ev.Stack.StackTop += numlocals; // set locals to undefined IValue undefinedValue = new UndefinedValue(); int stackTop = ev.Stack.StackTop; for (int i = 0; i < numlocals; i++) { ev.Stack.WriteN(stackTop - i, undefinedValue); } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.Identical: case Operations.And: result = OutSet.CreateBool(false); break; case Operations.NotIdentical: result = OutSet.CreateBool(true); break; case Operations.BitAnd: result = OutSet.CreateInt(0); break; case Operations.Div: result = ArithmeticOperation.DivisionByNull(flow); break; case Operations.Mod: result = ModuloOperation.ModuloByNull(flow); break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> protected override Value cloneValue() { UndefinedValue value = new UndefinedValue(); value.setStorage(getStorage()); return(value); }
public override void VisitUndefinedValue(UndefinedValue value) { if (!removeUndefined) { base.VisitUndefinedValue(value); } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { integerIndex = null; stringIndex = TypeConversion.ToString(OutSet, value); isNotConvertibleToInteger = true; isCompoundValue = false; }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { // When comparing, both operands are converted to boolean switch (operation) { case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: IntervalValue <int> convertedValue; if (TypeConversion.TryConvertToIntegerInterval(OutSet, leftOperand, out convertedValue)) { result = convertedValue; } else { result = OutSet.AnyIntegerValue; } break; case Operations.Mul: result = OutSet.CreateDouble(0.0); break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { // When comparing, both operands are converted to boolean switch (operation) { case Operations.Equal: case Operations.LessThanOrEqual: result = OutSet.CreateBool(!TypeConversion.ToBoolean(leftOperand.Value)); break; case Operations.NotEqual: case Operations.GreaterThan: case Operations.Or: case Operations.Xor: result = TypeConversion.ToBoolean(OutSet, leftOperand); break; case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = leftOperand; break; case Operations.Mul: result = OutSet.CreateInt(0); break; default: base.VisitUndefinedValue(value); break; } }
private Completion EvaluateTypeof(Interpreter interpreter) { var valComp = unaryExpression.Evaluate(interpreter); if (valComp.value is ReferenceValue reference) { if (reference.IsUnresolvableReference()) { return(Completion.NormalCompletion(new StringValue("undefined"))); } } var val = valComp.GetValue(); if (val.IsAbrupt()) { return(val); } return(Completion.NormalCompletion(new StringValue(val.value switch { UndefinedValue _ => "undefined", NullValue _ => "object", BooleanValue _ => "boolean", NumberValue _ => "number", StringValue _ => "string", FunctionObject _ => "function", Object _ => "object", _ => throw new InvalidOperationException("OperatorUnaryExpression.EvaluateTypeof: unknown type"), })));
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.Add: case Operations.Sub: result = OutSet.AnyFloatValue; break; case Operations.Mul: result = OutSet.CreateDouble(0.0); break; case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = OutSet.AnyIntegerValue; break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { _hasOnlyArrays = false; var array = getImplicitArray(); applyIndex(array); }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { int integerValue; double floatValue; bool isInteger; switch (operation) { case Operations.Or: case Operations.Xor: result = TypeConversion.ToBoolean(OutSet, leftOperand); break; case Operations.Add: case Operations.Sub: TypeConversion.TryConvertToNumber(leftOperand.Value, true, out integerValue, out floatValue, out isInteger); if (isInteger) { result = OutSet.CreateInt(integerValue); } else { result = OutSet.CreateDouble(floatValue); } break; case Operations.Mul: TypeConversion.TryConvertToNumber(leftOperand.Value, true, out integerValue, out floatValue, out isInteger); if (isInteger) { result = OutSet.CreateInt(0); } else { result = OutSet.CreateDouble(0.0); } break; case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = TypeConversion.ToInteger(OutSet, leftOperand); break; default: result = Comparison.Compare(OutSet, operation, leftOperand.Value, string.Empty); if (result != null) { break; } base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { // When comparing, both operands are converted to boolean switch (operation) { case Operations.Identical: case Operations.LessThan: case Operations.And: result = OutSet.CreateBool(false); break; case Operations.NotIdentical: case Operations.GreaterThanOrEqual: result = OutSet.CreateBool(true); break; case Operations.Equal: case Operations.LessThanOrEqual: bool convertedValue; if (TypeConversion.TryConvertToBoolean(leftOperand, out convertedValue)) { result = OutSet.CreateBool(!convertedValue); } else { result = OutSet.AnyBooleanValue; } break; case Operations.NotEqual: case Operations.GreaterThan: case Operations.Or: case Operations.Xor: result = TypeConversion.ToBoolean(OutSet, leftOperand); break; case Operations.Add: case Operations.Sub: result = leftOperand; break; case Operations.BitAnd: result = OutSet.CreateInt(0); break; case Operations.Div: result = ArithmeticOperation.DivisionByNull(flow); break; case Operations.Mod: result = ModuloOperation.ModuloByNull(flow); break; default: base.VisitUndefinedValue(value); break; } }
/// <summary> /// Constructs a new IR context. /// </summary> /// <param name="context">The associated main context.</param> public IRContext(Context context) { Context = context ?? throw new ArgumentNullException(nameof(context)); TypeContext = context.TypeContext; UndefinedValue = new UndefinedValue(TypeContext.VoidType); Create(UndefinedValue); gcDelegate = (Method method) => method.GC(); }
/// <summary> /// Constructs a new IR context. /// </summary> /// <param name="context">The associated main context.</param> protected IRBaseContext(Context context) { Context = context ?? throw new ArgumentNullException(nameof(context)); TypeContext = context.TypeContext; UndefinedValue = new UndefinedValue( new ValueInitializer( this, null, Location.Nowhere)); }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { if (isIncrement) { result = OutSet.CreateInt(1); } else { result = value; } }
/// <summary> /// Constructs a new IR context. /// </summary> /// <param name="context">The associated main context.</param> public IRContext(Context context) { Context = context ?? throw new ArgumentNullException(nameof(context)); TypeContext = context.TypeContext; UndefinedValue = new UndefinedValue( new ValueInitializer( this, null, Location.Nowhere)); gcDelegate = (Method method) => method.GC(); }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.Identical: case Operations.LessThan: case Operations.And: result = OutSet.CreateBool(false); break; case Operations.NotIdentical: case Operations.GreaterThanOrEqual: result = OutSet.CreateBool(true); break; case Operations.Equal: case Operations.LessThanOrEqual: result = OutSet.CreateBool(!TypeConversion.ToNativeBoolean(Snapshot, leftOperand)); break; case Operations.NotEqual: case Operations.GreaterThan: case Operations.Or: case Operations.Xor: result = TypeConversion.ToBoolean(Snapshot, leftOperand); break; case Operations.BitAnd: result = OutSet.CreateInt(0); break; case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = TypeConversion.ToInteger(Snapshot, leftOperand); break; case Operations.Div: result = ArithmeticOperation.DivisionByNull(flow); break; case Operations.Mod: result = ModuloOperation.ModuloByNull(flow); break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.Add: case Operations.Sub: result = leftOperand; break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.Identical: case Operations.Equal: case Operations.LessThan: case Operations.LessThanOrEqual: case Operations.And: result = OutSet.CreateBool(false); break; case Operations.NotIdentical: case Operations.NotEqual: case Operations.GreaterThan: case Operations.GreaterThanOrEqual: case Operations.Or: case Operations.Xor: result = OutSet.CreateBool(true); break; case Operations.Add: case Operations.Sub: case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = OutSet.AnyIntegerValue; break; case Operations.Mul: case Operations.BitAnd: result = OutSet.CreateInt(0); break; case Operations.Div: result = ArithmeticOperation.DivisionByNull(flow); break; case Operations.Mod: result = ModuloOperation.ModuloByNull(flow); break; default: base.VisitUndefinedValue(value); break; } }
public JsAnalyzer(AnalysisLimits limits = null) { _modules = new ModuleTable(); _itemCache = new Dictionary <object, AnalysisValue>(); _builtinEntry = new ProjectEntry(this, String.Empty, null); Limits = limits ?? new AnalysisLimits(); _queue = new Deque <AnalysisUnit>(); _nullInst = new NullValue(this); _trueInst = new BooleanValue(true, this); _falseInst = new BooleanValue(false, this); _undefined = new UndefinedValue(this); _emptyStringValue = GetConstant(String.Empty); _zeroIntValue = GetConstant(0.0); var globals = GlobalBuilder.MakeGlobal(this); _globalObject = globals.GlobalObject; _numberPrototype = globals.NumberPrototype; _stringPrototype = globals.StringPrototype; _booleanPrototype = globals.BooleanPrototype; _functionPrototype = globals.FunctionPrototype; _arrayFunction = globals.ArrayFunction; _objectPrototype = globals.ObjectPrototype; _requireFunc = globals.RequireFunction; _arrayPrototype = globals.ArrayPrototype; _objectGetOwnPropertyDescriptor = globals.ObjectGetOwnPropertyDescriptor; _immutableObject = new ImmutableObjectValue(_builtinEntry); var allJson = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "all.json" ); if (File.Exists(allJson)) { NodejsModuleBuilder.Build(allJson, this); } else { Debug.Fail("Could not find all.json"); } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.LessThan: result = OutSet.CreateBool(false); break; case Operations.GreaterThanOrEqual: result = OutSet.CreateBool(true); break; case Operations.Equal: case Operations.LessThanOrEqual: result = OutSet.CreateBool(!leftOperand.Value); break; case Operations.NotEqual: case Operations.GreaterThan: case Operations.Or: case Operations.Xor: result = leftOperand; break; case Operations.Add: case Operations.Sub: case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = TypeConversion.ToInteger(OutSet, leftOperand); break; case Operations.Mul: result = OutSet.CreateInt(0); break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { // When comparing, both operands are converted to boolean switch (operation) { case Operations.Identical: case Operations.LessThan: case Operations.And: result = OutSet.CreateBool(false); break; case Operations.NotIdentical: case Operations.GreaterThanOrEqual: result = OutSet.CreateBool(true); break; case Operations.Equal: case Operations.NotEqual: case Operations.GreaterThan: case Operations.LessThanOrEqual: case Operations.Or: case Operations.Xor: result = OutSet.AnyBooleanValue; break; case Operations.BitAnd: result = OutSet.CreateInt(0); break; case Operations.Div: result = ArithmeticOperation.DivisionByNull(flow); break; case Operations.Mod: result = ModuloOperation.ModuloByNull(flow); break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = leftOperand; break; case Operations.Mul: result = OutSet.CreateInt(0); break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.Plus: result = TypeConversion.ToInteger(OutSet, value); break; case Operations.Minus: result = TypeConversion.ToInteger(OutSet, value); break; case Operations.LogicNegation: result = OutSet.CreateBool(!TypeConversion.ToBoolean(value)); break; case Operations.BitNegation: // TODO: This must be fatal error SetWarning("Unsupported operand types: Bit negation of null value"); result = OutSet.AnyValue; break; case Operations.Int32Cast: result = TypeConversion.ToInteger(OutSet, value); break; case Operations.FloatCast: case Operations.DoubleCast: result = TypeConversion.ToFloat(Snapshot, value); break; default: if (PerformUsualOperation(value)) { break; } base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { // When comparing, both operands are converted to boolean switch (operation) { case Operations.Equal: case Operations.LessThanOrEqual: result = OutSet.CreateBool(!TypeConversion.ToBoolean(leftOperand.Value)); break; case Operations.NotEqual: case Operations.GreaterThan: case Operations.Or: case Operations.Xor: result = TypeConversion.ToBoolean(OutSet, leftOperand); break; case Operations.Mul: result = OutSet.CreateDouble(0.0); break; case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: int leftInteger; if (TypeConversion.TryConvertToInteger(leftOperand.Value, out leftInteger)) { result = OutSet.CreateInt(leftInteger); } else { result = OutSet.AnyIntegerValue; } break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { // When comparing, both operands are converted to boolean switch (operation) { case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = leftOperand; break; case Operations.Mul: result = OutSet.CreateInt(0); break; default: base.VisitUndefinedValue(value); break; } }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { switch (operation) { case Operations.Add: case Operations.Sub: case Operations.BitOr: case Operations.BitXor: case Operations.ShiftLeft: case Operations.ShiftRight: result = TypeConversion.AnyBooleanToIntegerInterval(OutSet); break; case Operations.Mul: result = OutSet.CreateInt(0); break; default: base.VisitUndefinedValue(value); break; } }
public override NodeValue Visit(ASTNode node) { if (_visitedNodesValuesCache.ContainsKey(node)) { if (_visitedNodesValuesCache[node] is UninitializedValue) { node.Annotations.Add(new InfiniteConstReferenceLoopError()); _visitedNodesValuesCache[node] = new UndefinedValue(); } return(_visitedNodesValuesCache[node]); } _visitedNodesValuesCache[node] = new UninitializedValue(); NodeValue resultValue = base.Visit(node); _visitedNodesValuesCache[node] = resultValue; if (resultValue is UndefinedValue) { return(new UndefinedValue()); } return(_visitedNodesValuesCache[node]); }
/// <inheritdoc /> public override void VisitUndefinedValue(UndefinedValue value) { // When comparing, both operands are converted to boolean switch (operation) { case Operations.LessThan: result = OutSet.CreateBool(false); break; case Operations.GreaterThanOrEqual: result = OutSet.CreateBool(true); break; case Operations.Add: case Operations.Sub: result = leftOperand; break; default: base.VisitUndefinedValue(value); break; } }
/// <summary cref="IValueVisitor.Visit(UndefinedValue)"/> public void Visit(UndefinedValue undefined) => throw new InvalidCodeGenerationException();