public override void PerformBefore(Interval node) { if (node == null) { throw new ArgumentNullException("node"); } base.PerformBefore(node); IntegerValue integerValue = node.Value as IntegerValue; if (integerValue == null) { throw new InvalidOperationException( "Non-constant interval cannot be stringified."); } if (!node.Positive) { node.Value = node.GetSignedValue(); node.Positive = true; } decimal v = integerValue.Value; if (v < 0) { v = -1 * v; } string s = Convert.ToString(v); int requiredPrecision = s.Length; if (requiredPrecision < Interval.ImplicitPrecision) { requiredPrecision = Interval.ImplicitPrecision; } if (node.Precision < requiredPrecision) { node.Precision = requiredPrecision; } }
/// <summary> /// Constructs the last argument for substring functions. /// </summary> /// <param name="startExpr"> /// First argument of the substring function /// (<c>ExpressionItem.Expression</c>, not the top-level <c>ExpressionItem</c>). /// </param> /// <param name="valExpr"> /// Second argument of the substring function /// (<c>ExpressionItem.Expression</c>, not the top-level <c>ExpressionItem</c>). /// </param> /// <param name="lenName"> /// Name of the length function (must not be null). /// </param> public static IExpression MakeLenArg(INode startExpr, INode valExpr, string lenName) { if (startExpr == null) { throw new ArgumentNullException("startExpr"); } if (valExpr == null) { throw new ArgumentNullException("valExpr"); } if (lenName == null) { throw new ArgumentNullException("lenName"); } FunctionCall lenCall = new FunctionCall(lenName); lenCall.ExpressionArguments = new ExpressionItem(valExpr.Clone()); IExpression argument; INode startTerm = GetTerm(startExpr); IntegerValue integerValue = startTerm as IntegerValue; if ((integerValue != null) && (integerValue.Value == 1)) { argument = lenCall; } else { Expression left = new Expression(lenCall, ExpressionOperator.Plus, new IntegerValue(1)); argument = new Expression(left, ExpressionOperator.Minus, startTerm.Clone()); } return(argument); }
/// <summary> /// The value of this interval. /// </summary> public INode GetSignedValue() { if (m_positive) { return(m_value.Clone()); } else { IntegerValue integerValue = m_value as IntegerValue; if (integerValue != null) { return(new IntegerValue(-1 * integerValue.Value)); } else { return(new Expression( new IntegerValue(-1), ExpressionOperator.Mult, m_value.Clone())); } } }
public virtual void Perform(IntegerValue node) { }
public static ExpressionItem MakeLiteralInteger(int literal) { IntegerValue integerValue = new IntegerValue(literal); return(new ExpressionItem(integerValue)); }