public JSSpecialIdentifiers (MethodTypeFactory methodTypes, TypeSystem typeSystem) { TypeSystem = typeSystem; MethodTypes = methodTypes; prototype = Object("prototype"); eval = new JSFakeMethod("eval", TypeSystem.Object, new[] { TypeSystem.String }, methodTypes); toString = new JSFakeMethod("toString", TypeSystem.String, null, methodTypes); floor = new JSDotExpression(Object("Math"), new JSFakeMethod("floor", TypeSystem.Int32, null, methodTypes)); fromCharCode = new JSDotExpression(Object("String"), new JSFakeMethod("fromCharCode", TypeSystem.Char, new[] { TypeSystem.Int32 }, methodTypes)); charCodeAt = new JSFakeMethod("charCodeAt", TypeSystem.Int32, new[] { TypeSystem.Char }, methodTypes); }
public void VisitNode(JSUnaryOperatorExpression uoe) { var exType = uoe.Expression.GetActualType(TypeSystem); var opType = uoe.ActualType; if (IsLongOrULong(exType) && IsLongOrULong(opType)) //exType == TypeSystem.Int64 && opType == TypeSystem.Int64) { string verb; switch (uoe.Operator.Token) { case "-": verb = "op_UnaryNegation"; break; case "~": verb = "op_OnesComplement"; break; default: throw new NotSupportedException(); } var method = new JSFakeMethod(verb, TypeSystem.Int64, new[] { TypeSystem.Int64 }, MethodTypeFactory); var replacement = JSInvocationExpression.InvokeStatic(exType, method, new[] { uoe.Expression }, true); ParentNode.ReplaceChild(uoe, replacement); VisitReplacement(replacement); return; } VisitChildren(uoe); }
public void VisitNode(JSBinaryOperatorExpression boe) { var leftType = boe.Left.GetActualType(TypeSystem); var rightType = boe.Right.GetActualType(TypeSystem); TypeReference expectedType; try { // GetExpectedType can throw NoExpectedTypeException // Shouldn't it return null or something like a NoType instead? expectedType = boe.GetActualType(TypeSystem); } catch (NoExpectedTypeException) { expectedType = null; } var isLongExpression = IsLongOrULong(leftType) || IsLongOrULong(rightType); bool isUnsigned = (leftType.MetadataType == MetadataType.UInt64) || (rightType.MetadataType == MetadataType.UInt64); var resultType = isUnsigned ? TypeSystem.UInt64 : TypeSystem.Int64; var assignmentOperator = boe.Operator as JSAssignmentOperator; if ((assignmentOperator != null) && (isLongExpression)) { if (assignmentOperator == JSOperator.Assignment) { VisitChildren(boe); return; } // Deconstruct the mutation assignment so we can insert the appropriate operator call. var replacement = IntroduceEnumCasts.DeconstructMutationAssignment(boe, TypeSystem, resultType); ParentNode.ReplaceChild(boe, replacement); VisitReplacement(replacement); } else if (isLongExpression) { var verb = GetVerb(boe.Operator); if (verb == null) { throw new NotImplementedException("Int64 operator not yet supported: " + boe.Operator.Token); } JSIdentifier method = new JSFakeMethod( verb, boe.Operator is JSComparisonOperator ? TypeSystem.Boolean : resultType, new[] { leftType, rightType }, MethodTypeFactory ); var replacement = JSInvocationExpression .InvokeStatic(leftType, method, new[] { boe.Left, boe.Right }, true); ParentNode.ReplaceChild(boe, replacement); VisitReplacement(replacement); } else { VisitChildren(boe); } }
public JSSpecialIdentifiers(TypeSystem typeSystem) { TypeSystem = typeSystem; prototype = Object("prototype"); eval = new JSFakeMethod("eval", TypeSystem.Object, TypeSystem.String); toString = new JSFakeMethod("toString", TypeSystem.String); floor = new JSDotExpression(Object("Math"), new JSFakeMethod("floor", TypeSystem.Int64)); fromCharCode = new JSDotExpression(Object("String"), new JSFakeMethod("fromCharCode", TypeSystem.Char, TypeSystem.Int32)); charCodeAt = new JSFakeMethod("charCodeAt", TypeSystem.Int32, TypeSystem.Char); }