private Type BinaryDual(BaseBinaryExpression expr) { var l = Visit(expr.Left); var r = Visit(expr.Right); // If a type isn't decided yet we can't type this either if (l == Type.Unassigned || r == Type.Unassigned) { return(Type.Unassigned); } // if either side is a guaranteed error, so is this if (l == Type.Error || r == Type.Error) { return(Type.Error); } // If either side may produce an error, so may this var err = l.HasFlag(Type.Error) || r.HasFlag(Type.Error) ? Type.Error : Type.Unassigned; // Check if either side can be a number var ln = l.HasFlag(Type.Number); var rn = r.HasFlag(Type.Number); var n = ln && rn ? Type.Number : Type.Unassigned; // Check if either side can be a string var ls = l.HasFlag(Type.String); var rs = l.HasFlag(Type.String); var s = ls || rs ? Type.String : Type.Unassigned; return(err | n | s); }
private Type BinaryLogical(BaseBinaryExpression expr) { var l = Visit(expr.Left); var r = Visit(expr.Right); // If either side is guaranteed to produce an error, so is this if (l == Type.Error || r == Type.Error) { return(Type.Error); } // If a type isn't decided yet we can't type this either if (l == Type.Unassigned || r == Type.Unassigned) { return(Type.Unassigned); } // If either side may produce an error, so may this if (l.HasFlag(Type.Error) || r.HasFlag(Type.Error)) { return(Type.Error | Type.Number); } return(Type.Number); }
private Type BinaryNumeric(BaseBinaryExpression expr, bool forceError) { var l = Visit(expr.Left); var r = Visit(expr.Right); // If either side is a guaranteed error, so is this if (l == Type.Error || r == Type.Error) { return(Type.Error); } // If a type isn't decided yet we can't type this either if (l == Type.Unassigned || r == Type.Unassigned) { return(Type.Unassigned); } // If either side is guaranteed not to be a number this is a guaranteed error if (!l.HasFlag(Type.Number) || !r.HasFlag(Type.Number)) { return(Type.Error); } // If either side may be a string or an error then this may error var mayError = forceError; mayError |= l.HasFlag(Type.String); mayError |= r.HasFlag(Type.String); mayError |= l.HasFlag(Type.Error); mayError |= r.HasFlag(Type.Error); var err = (mayError ? Type.Error : Type.Unassigned); return(Type.Number | err); }
[NotNull] private JToken SerializeBinary([NotNull] BaseBinaryExpression bin, string type) { return(new JObject { ["type"] = $"expression::binary_op::{type}", ["left"] = SerializeExpression(bin.Left), ["right"] = SerializeExpression(bin.Right), }); }
private BinaryOp VisitBinary(BaseBinaryExpression bin, YololBinaryOp binop) { var l = Visit(bin.Left); var r = Visit(bin.Right); var op = new BinaryOp(binop, Guid.NewGuid(), l, r); _dataFlowGraph._ops.Add(op); return(op); }
[NotNull] private BinaryOp VisitBinary([NotNull] BaseBinaryExpression bin, YololBinaryOp binop) { var l = Visit(bin.Left); var r = Visit(bin.Right); var op = new BinaryOp(binop, Guid.NewGuid(), (IDataFlowGraphExpressionNode)l, (IDataFlowGraphExpressionNode)r); _dataFlowGraph._ops.Add(op); return(op); }
protected override IEnumerable <BaseStatement> Visit(CompoundAssignment compAss) { var tmp = new VariableName(_names.Name()); var a = new ExpressionDecomposition(_names).Visit(compAss.Expression).ToArray(); var b = new Assignment(tmp, BaseBinaryExpression.Create(compAss.Op, new Variable(new VariableName(compAss.Left.Name)), new Variable(((Assignment)a.Last()).Left))); var c = new Assignment(new VariableName(compAss.Left.Name), new Variable(tmp)); return(a.Append(b).Append(c)); }
private bool VisitBinary([NotNull] BaseBinaryExpression bin) => Visit(bin.Left) && Visit(bin.Right);