public JSILIdentifier(MethodTypeFactory methodTypes, TypeSystem typeSystem, JSSpecialIdentifiers js) { TypeSystem = typeSystem; MethodTypes = methodTypes; JS = js; GlobalNamespace = Dot("GlobalNamespace", TypeSystem.Object); CopyMembers = Dot("CopyMembers", TypeSystem.Void); }
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 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(JSBinaryOperatorExpression boe) { var leftType = boe.Left.GetActualType(TypeSystem); var rightType = boe.Right.GetActualType(TypeSystem); bool isArithmetic = !(boe.Operator is JSAssignmentOperator); if ((leftType.FullName == "System.Char") && isArithmetic) { boe.ReplaceChild(boe.Left, CastToInteger(boe.Left)); } if ((rightType.FullName == "System.Char") && isArithmetic) { boe.ReplaceChild(boe.Right, CastToInteger(boe.Right)); } var parentInvocation = ParentNode as JSInvocationExpression; JSDotExpressionBase parentInvocationDot = (parentInvocation != null) ? parentInvocation.Method as JSDotExpressionBase : null; if ( isArithmetic && (boe.GetActualType(TypeSystem).FullName == "System.Char") && !( (parentInvocation != null) && (parentInvocationDot != null) && (parentInvocationDot.Target is JSStringIdentifier) && (((JSStringIdentifier)parentInvocationDot.Target).Identifier == "String") && (parentInvocationDot.Member is JSFakeMethod) && (((JSFakeMethod)parentInvocationDot.Member).Name == "fromCharCode") ) ) { var castBoe = CastToChar(boe); ParentNode.ReplaceChild(boe, castBoe); VisitReplacement(castBoe); } else { VisitChildren(boe); } }
protected void VisitDotExpression(JSDotExpressionBase dot) { var parens = (dot.Target is JSNumberLiteral) || (dot.Target is JSIntegerLiteral); if (parens) { Output.LPar(); } Visit(dot.Target); if (parens) { Output.RPar(); } Output.Dot(); Visit(dot.Member); }
protected JSVariable ExtractAffectedVariable(JSExpression expression) { var variable = expression as JSVariable; if (variable != null) { return(variable); } JSDotExpressionBase dot = expression as JSDotExpressionBase; while (dot != null) { variable = dot.Target as JSVariable; if (variable != null) { return(variable); } dot = dot.Target as JSDotExpressionBase; } return(null); }
public void VisitNode(JSBinaryOperatorExpression boe) { var leftType = boe.Left.GetActualType(TypeSystem); var rightType = boe.Right.GetActualType(TypeSystem); bool isArithmetic = !(boe.Operator is JSAssignmentOperator); if (!isArithmetic && boe.Operator != JSOperator.Assignment && leftType.FullName == "System.Char") { JSBinaryOperator newOperator; if (boe.Operator == JSOperator.AddAssignment) { newOperator = JSOperator.Add; } else if (boe.Operator == JSOperator.BitwiseAndAssignment) { newOperator = JSOperator.BitwiseAnd; } else if (boe.Operator == JSOperator.BitwiseOrAssignment) { newOperator = JSOperator.BitwiseOr; } else if (boe.Operator == JSOperator.BitwiseXorAssignment) { newOperator = JSOperator.BitwiseXor; } else if (boe.Operator == JSOperator.DivideAssignment) { newOperator = JSOperator.Divide; } else if (boe.Operator == JSOperator.MultiplyAssignment) { newOperator = JSOperator.Multiply; } else if (boe.Operator == JSOperator.RemainderAssignment) { newOperator = JSOperator.Remainder; } else if (boe.Operator == JSOperator.ShiftLeftAssignment) { newOperator = JSOperator.ShiftLeft; } else if (boe.Operator == JSOperator.ShiftRightAssignment) { newOperator = JSOperator.ShiftRight; } else if (boe.Operator == JSOperator.ShiftRightUnsignedAssignment) { newOperator = JSOperator.ShiftRightUnsigned; } else if (boe.Operator == JSOperator.SubtractAssignment) { newOperator = JSOperator.Subtract; } else { throw new InvalidOperationException("Unknown assigment operator"); } var newBoe = new JSBinaryOperatorExpression(JSOperator.Assignment, boe.Left, new JSBinaryOperatorExpression(newOperator, boe.Left, boe.Right, boe.ActualType), boe.ActualType); ParentNode.ReplaceChild(boe, newBoe); VisitReplacement(newBoe); return; } if (boe.Operator == JSOperator.Assignment && (leftType.FullName == "System.Char") && (rightType.FullName != "System.Char")) { boe.ReplaceChild(boe.Right, CastToChar(boe.Right)); } if (boe.Operator == JSOperator.Assignment && (leftType.FullName != "System.Char") && (rightType.FullName == "System.Char")) { boe.ReplaceChild(boe.Right, CastToInteger(boe.Right)); } if ((leftType.FullName == "System.Char") && isArithmetic) { boe.ReplaceChild(boe.Left, CastToInteger(boe.Left)); } if ((rightType.FullName == "System.Char") && isArithmetic) { boe.ReplaceChild(boe.Right, CastToInteger(boe.Right)); } var parentInvocation = ParentNode as JSInvocationExpression; JSDotExpressionBase parentInvocationDot = (parentInvocation != null) ? parentInvocation.Method as JSDotExpressionBase : null; if ( isArithmetic && (boe.GetActualType(TypeSystem).FullName == "System.Char") && !( (parentInvocation != null) && (parentInvocationDot != null) && (parentInvocationDot.Target is JSStringIdentifier) && (((JSStringIdentifier)parentInvocationDot.Target).Identifier == "String") && (parentInvocationDot.Member is JSFakeMethod) && (((JSFakeMethod)parentInvocationDot.Member).Name == "fromCharCode") ) ) { var castBoe = CastToChar(boe); ParentNode.ReplaceChild(boe, castBoe); VisitReplacement(castBoe); } else { VisitChildren(boe); } }