public void VisitNode(JSUnaryOperatorExpression uoe) { var isBoolean = TypeUtil.IsBoolean(uoe.GetActualType(TypeSystem)); if (isBoolean) { if (uoe.Operator == JSOperator.IsTrue) { ParentNode.ReplaceChild( uoe, uoe.Expression ); VisitReplacement(uoe.Expression); return; } else if (uoe.Operator == JSOperator.LogicalNot) { var nestedUoe = uoe.Expression as JSUnaryOperatorExpression; var boe = uoe.Expression as JSBinaryOperatorExpression; JSBinaryOperator newOperator; if ((boe != null) && InvertedOperators.TryGetValue(boe.Operator, out newOperator) ) { var newBoe = new JSBinaryOperatorExpression( newOperator, boe.Left, boe.Right, boe.ActualType ); ParentNode.ReplaceChild(uoe, newBoe); VisitReplacement(newBoe); return; } else if ( (nestedUoe != null) && (nestedUoe.Operator == JSOperator.LogicalNot) ) { var nestedExpression = nestedUoe.Expression; ParentNode.ReplaceChild(uoe, nestedExpression); VisitReplacement(nestedExpression); return; } } } VisitChildren(uoe); }
public void VisitNode(JSUnaryOperatorExpression uoe) { var variable = ExtractAffectedVariable(uoe.Expression); var isMutator = uoe.Operator is JSUnaryMutationOperator; VisitChildren(uoe); if (isMutator) { if (variable != null) { State.Assignments.Add( new FunctionAnalysis1stPass.Assignment( GetParentNodeIndices(), StatementIndex, NodeIndex, variable, uoe, uoe.Operator, variable.GetActualType(TypeSystem), uoe.GetActualType(TypeSystem) ) ); ModifiedVariable(variable); } } }
public void VisitNode(JSUnaryOperatorExpression uoe) { var resultType = uoe.GetActualType(TypeSystem); var typeToken = WasmUtil.PickTypeKeyword(resultType); if (typeToken == null) { Console.WriteLine("Unhandled unary operator type {0}", resultType); return; } if (uoe.Operator == JSOperator.LogicalNot) { Formatter.WriteRaw("({0}.xor ", typeToken); Visit(uoe.Expression); Formatter.WriteRaw(" ({0}.const 1))", typeToken); return; } else if (uoe.Operator == JSOperator.Negation) { Formatter.WriteRaw("({0}.sub ({0}.const 0) ", typeToken); Visit(uoe.Expression); Formatter.WriteRaw(")", typeToken); return; } string keyword; if (!OperatorTable.TryGetValue(uoe.Operator, out keyword)) { Console.WriteLine("Unimplemented operator {0}", uoe.Operator); return; } var operandType = uoe.Expression.GetActualType(TypeSystem); var sign = TypeUtil.IsSigned(operandType); var signSuffix = ""; if ( (sign.HasValue && TypeUtil.IsIntegral(operandType)) || // HACK (operandType.FullName == "System.Char") ) { signSuffix = sign.GetValueOrDefault(true) ? "_s" : "_u"; } var actualKeyword = string.Format( typeToken + "." + keyword, signSuffix ); Formatter.WriteSExpr( actualKeyword, (_) => EmitArgumentList(_, new[] { uoe.Expression }, true), true, false ); }