private Bucket(IOperand operand) { if (operand == null) throw new ArgumentNullException("operand"); _operand = operand; }
protected BinaryOperationBase(IOperationResultBuilder operationResultBuilder, IOperand columnOperand, IOperand valueOperand) : base(operationResultBuilder) { this.ColumnOperand = columnOperand; this.ValueOperand = valueOperand; }
protected BinaryOperationBase(IOperationResultBuilder operationResultBuilder, IOperand fieldRefOperand, IOperand valueOperand) : base(operationResultBuilder) { this.fieldRefOperand = fieldRefOperand; this.valueOperand = valueOperand; }
public void ReplaceLastOperand(IOperand operand) { if (Operands.Count == 0) { throw new InvalidOperationException("There are no operands to replace."); } int stealIndex = Operands.Count - 1; NativeOperation op = Operands[stealIndex] as NativeOperation; // Check if the "steal" target is itself something that we can steal from, if so, // recurse. This rule of checkiung association type is a bit confusing, this should // be a property? if (op !=null && op.Operands.Count > 1 && op.AssociationType == AssociationType.Multiplicaton) { IOperation func = (IOperation)op; func.ReplaceLastOperand(operand); } else { _Operands[Operands.Count - 1] = operand; } }
public IOperand OR(IOperand rhs) { if (!(rhs is BoolOperand)) throw new RPN_Exception("Argument invalid in BoolOperand.|| : rhs"); BoolOperand oprResult = new BoolOperand("Result"); oprResult.Value = ((bool)this.Value || (bool)((Operand)rhs).Value) ? true : false; return oprResult; }
internal static bool Match(PackageItem package, IOperand operand) { var expression = operand as Expression; if (expression != null) return MatchExpression(package, expression); return MatchPredicate(package, operand); }
public IOperand LessThanOrEqualTo(IOperand rhs) { if (!(rhs is LongOperand)) throw new RPN_Exception("Argument invalid in LongOperand.<= : rhs"); BoolOperand oprResult = new BoolOperand("Result"); oprResult.Value = ((long)this.Value <= (long)((Operand)rhs).Value) ? true : false; return oprResult; }
public IOperand GreaterThan(IOperand rhs) { if (!(rhs is LongOperand)) throw new RPN_Exception("Argument invalid in LongOperand.> : rhs"); BoolOperand oprResult = new BoolOperand("Result"); oprResult.Value = ((long)this.Value > (long)((Operand)rhs).Value) ? true : false; return oprResult; }
/// IComparisonOperators methods. Return values are always BooleanOperands type public IOperand EqualTo(IOperand rhs) { if (!(rhs is LongOperand)) throw new RPN_Exception("Argument invalid in LongOperand.== : rhs"); BoolOperand oprResult = new BoolOperand("Result"); oprResult.Value = (long)this.Value == (long)((Operand)rhs).Value; return oprResult; }
public IOperand Divide(IOperand rhs) { if (!(rhs is LongOperand)) throw new RPN_Exception("Argument invalid in LongOperand.Divide : rhs"); LongOperand oprResult = new LongOperand("Result", Type.GetType("System.Int64")); oprResult.Value = (long)this.Value / (long)((Operand)rhs).Value; return oprResult; }
public DateRangesOverlapOperation(IOperationResultBuilder operationResultBuilder, IOperand startFieldRefOperand, IOperand stopFieldRefOperand, IOperand recurrenceFieldRefOperand, IOperand dateTimeOperand) : base(operationResultBuilder) { this.startFieldRefOperand = startFieldRefOperand; this.stopFieldRefOperand = stopFieldRefOperand; this.recurrenceFieldRefOperand = recurrenceFieldRefOperand; this.dateTimeOperand = dateTimeOperand; }
protected override IOperand CopyTo(IOperand operand) { NativeOperation target = (NativeOperation)operand; foreach (var item in _Operators) { target._Operators.Add(item); } return base.CopyTo(target); }
public void ReplaceLastOperand(IOperand operand) { if (Operands.Count == 0) { throw new InvalidOperationException("There are no operands to replace."); } _Operands[Operands.Count - 1] = operand; }
private static bool MatchPredicate(PackageItem package, IOperand predicate) { var unaryPredicate = predicate as UnaryPredicate; if (unaryPredicate != null) return MatchPredicate(package, unaryPredicate); var binaryPredicate = predicate as BinaryPredicate; if (binaryPredicate != null) return MatchPredicate(package, binaryPredicate); return true; }
private Range(IOperand min = null, IOperand max = null, bool minInclusive = false, bool maxInclusive = false) { if (min == null && max == null) throw new ArgumentException("Min and max cannot both be null."); // TODO check min < max? Min = min; Max = max; MinInclusive = minInclusive; MaxInclusive = maxInclusive; }
//bool bBinaryOperator = true; //{"&&", "||"} public override IOperand Eval(IOperand lhs, IOperand rhs) { if (!(lhs is ILogicalOperations)) throw new RPN_Exception("Argument invalid in LogicalOperator.Eval - Invalid Expression : lhs"); switch (m_szOperator) { case "&&": return ((ILogicalOperations)lhs).AND(rhs); case "||": return ((ILogicalOperations)lhs).OR(rhs); } throw new RPN_Exception("Unsupported Logical operation " + m_szOperator); }
// ----- Field Ref Operand ----- public IOperand CreateFieldRefOperand(Expression expr, IOperand valueOperand) { if (expr is UnaryExpression) { expr = ((UnaryExpression)expr).Operand; } var methodCallExpression = expr as MethodCallExpression; var argumentExpression = methodCallExpression.Arguments[0]; if (argumentExpression is ConstantExpression) { return this.createFieldRefOperandFromConstantExpression(argumentExpression as ConstantExpression, valueOperand); } return this.createFieldRefOperandFromNonConstantExpression(argumentExpression, valueOperand); }
//bool bBinaryOperator = true; public override IOperand Eval(IOperand lhs, IOperand rhs) { if (!(lhs is IArithmeticOperations)) throw new RPN_Exception("Argument invalid in ArithmeticOperator.Eval - Invalid Expression : lhs"); switch (m_szOperator) { case "+": return ((IArithmeticOperations)lhs).Plus(rhs); case "-": return ((IArithmeticOperations)lhs).Minus(rhs); case "*": return ((IArithmeticOperations)lhs).Multiply(rhs); case "/": return ((IArithmeticOperations)lhs).Divide(rhs); case "%": return ((IArithmeticOperations)lhs).Modulo(rhs); } throw new RPN_Exception("Unsupported Arithmetic operation " + m_szOperator); }
//bool bBinaryOperator = true; //{"==", "!=","<", "<=", ">", ">="} public override IOperand Eval(IOperand lhs, IOperand rhs) { if (!(lhs is IComparisonOperations)) throw new RPN_Exception("Argument invalid in ComparisonOperator.Eval - Invalid Expression : lhs"); switch (m_szOperator) { case "==": return ((IComparisonOperations)lhs).EqualTo(rhs); case "!=": return ((IComparisonOperations)lhs).NotEqualTo(rhs); case "<": return ((IComparisonOperations)lhs).LessThan(rhs); case "<=": return ((IComparisonOperations)lhs).LessThanOrEqualTo(rhs); case ">": return ((IComparisonOperations)lhs).GreaterThan(rhs); case ">=": return ((IComparisonOperations)lhs).GreaterThanOrEqualTo(rhs); } throw new RPN_Exception("Unsupported Comparison operation " + m_szOperator); }
public IOperand Evaluate(IOperand op1) { if (DoubleDouble != null) { if (op1.Type == typeof(double)) { var dOp1 = op1 as GenericOperand<double>; return new GenericOperand<double>(DoubleDouble(dOp1.Value)); } } if (StringDouble != null) { if (op1.Type == typeof(string)) { var dOp1 = op1 as GenericOperand<string>; return new GenericOperand<double>(StringDouble(dOp1.Value)); } } if (DoubleTimespan != null) { if (op1.Type == typeof(double)) { var dOp1 = op1 as GenericOperand<double>; return new GenericOperand<TimeSpan>(DoubleTimespan(dOp1.Value)); } } if (TimespanDouble != null) { if (op1.Type == typeof(TimeSpan)) { var dOp1 = op1 as GenericOperand<TimeSpan>; return new GenericOperand<double>(TimespanDouble(dOp1.Value)); } } throw new ExpressionException(_name2 + " operator used incorrectly."); }
internal abstract ArgumentMarshalResult MarshalArgument(int position, IOperand op);
private IOperand createFieldRefOperandByNameOrId(string val, IOperand valueOperand) { // if string represents guid, then FieldRef with ID should be created try { var guid = new Guid(val); return this.createFieldRefOperand(guid, valueOperand); } catch { return this.createFieldRefOperand(val, valueOperand); } }
private IOperand createFieldRefOperandFromNonConstantExpression(Expression expr, IOperand valueOperand) { object value = this.evaluateExpression(expr); if (value == null || (value.GetType() != typeof(string) && value.GetType() != typeof(Guid))) { throw new InvalidValueForFieldRefException(value); } if (value.GetType() == typeof(Guid)) { return this.createFieldRefOperand((Guid)value, valueOperand); } return this.createFieldRefOperandByNameOrId((string)value, valueOperand); }
public Difference(IOperand operand1, IOperand operand2) : base() { AddOperand(operand1); AddOperand(operand2); }
public IOperand <T> Assign(IOperand <T> value) { return(value); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- public void Return(IOperand <TReturn> operand) { AddReturnStatement(operand.OrNullConstant()); }
protected IOperand GetOperand <T>() where T : IConvertible { string text = ""; IOperand output = null; scanner.SkipWhitespace(); if (scanner.Current == '-') { // convert leading - to "-1" if it precedes a variable, otherwise // just add it to the output stream scanner.Next(); if (scanner.Finished) { throw new ArgumentException("Unexpected end of string found, expected an operand (a number or variable name)"); } if (CharacterData.IsType(scanner.Current, CharacterType.Number)) { text += "-"; } else { output = new Literal <T>(-1); } } else if (scanner.Current == '+') { // ignore leading + scanner.Next(); } if (output == null) { if (scanner.Info.Numeric) { text += scanner.Get(MatchFunctions.Number()); double num; if (Double.TryParse(text, out num)) { output = IsTyped ? new Literal <T>(num) : new Literal(num); } else { throw new InvalidCastException("Unable to parse number from '" + text + "'"); } } else if (scanner.Info.Alpha) { text += scanner.GetAlpha(); if (scanner.CurrentOrEmpty == "(") { IFunction func = Utils.GetFunction <T>(text); var inner = scanner.ExpectBoundedBy('(', true).ToNewScanner("{0},"); while (!inner.Finished) { string parm = inner.Get(MatchFunctions.BoundedBy(boundEnd: ",")); EquationParserEngine innerParser = new EquationParserEngine(); IOperand innerOperand = innerParser.Parse <T>(parm); func.AddOperand(innerOperand); } CacheVariables(func); output = func; } else { IVariable var = GetVariable <T>(text); output = var; } } else if (scanner.Current == '(') { string inner = scanner.Get(MatchFunctions.BoundedBy("(")); var parser = new EquationParserEngine(); parser.Parse <T>(inner); output = parser.Clause; CacheVariables(output); } else { throw new ArgumentException("Unexpected character '" + scanner.Match + "' found, expected an operand (a number or variable name)"); } } scanner.SkipWhitespace(); ParseEnd = scanner.Finished; return(output); }
public BinaryPredicate(Operator Operator = Operator.Null, IOperand operand1 = null, IOperand operand2 = null) { this.Operator = Operator; Operand1 = operand1; Operand2 = operand2; }
//------------------------------------------------------------------------------------------------------------------------------------------------- public Expression(IOperand <TLeft> left, IOperand <TRight> right, string operation) { m_Left = left; m_Right = right; m_Operation = operation; }
public Unary(OperatorType Operator, IOperand Factor) { oper = Operator; factor = Factor; }
protected override IOperand ComputeValue(IOperand lhs, IOperand rhs, FormulaEngine engine) { return(DoDoubleOperation((DoubleOperand)lhs, (DoubleOperand)rhs, DoAdd)); }
public OpAnd(IOperand destination, IOperand lhs, IOperand rhs) { _destination = destination; _lhs = lhs; _rhs = rhs; }
public IndexDevice(IOperand baseOpe, IOperand indexOpe) => (Base, Index) = (baseOpe, indexOpe);
public bool Equals(IOperand other) { var o = other as LabelOperand; return _label == o?._label && _offset == o?._offset; }
private static void EmitAdd(Value <ulong> finalValue, IOperand firstOperand, IOperand secondOperand, CompilationContext context) { context.CurrentOperations.Add(new OpAdd <ulong>(finalValue, firstOperand, secondOperand)); }
protected override IOperand ApplyOperation(IOperand o1, IOperand o2) { return(new IntType(o1.Value & o2.Value)); }
/// <summary> /// Initializes a new instance of the <see cref="PlusNameExpression" /> class. /// </summary> /// <param name="operand">A <see cref="IOperand" /> representing part of the name expression</param> internal PlusNameExpression(IOperand operand) { Contract.Requires(operand != null); _operand = operand; }
private List <KeyValuePair <string, string> > getAdditionalAttributesForFieldRefOperands(IOperand valueOperand) { if (valueOperand is LookupIdValueOperand || valueOperand is UserIdValueOperand) { var attrs = new List <KeyValuePair <string, string> >(); attrs.Add(new KeyValuePair <string, string>(Attributes.LookupId, true.ToString())); return(attrs); } return(new List <KeyValuePair <string, string> >()); }
//----------------------------------------------------------------------------------------------------------------------------------------------------- protected override bool OnFilterOperand(IOperand operand) { return(operand is IAnonymousMethodOperand || operand is IScopedOperand); }
private IOperand createFieldRefOperand(Guid id, IOperand valueOperand) { var attrs = this.getAdditionalAttributesForFieldRefOperands(valueOperand); return(new FieldRefOperand(id, attrs)); }
public IOperand Parse <T>(string text) where T : IConvertible { IsTyped = typeof(T) != typeof(IConvertible); scanner = Scanner.Create(text); Clause = IsTyped ? new Sum <T>() : new Sum(); // it could have just one operand IOperand lastOperand = GetOperand <T>(); Clause.AddOperand(lastOperand); IOperation working = Clause; IOperand nextOperand = null; while (!ParseEnd) { IOperator op = GetOperation(); nextOperand = GetOperand <T>(); IOperation newOp; if (op.AssociationType == working.AssociationType) { // working can only be sum/product working.AddOperand(nextOperand, op.IsInverted); } else { switch (op.AssociationType) { case AssociationType.Addition: // always return to the root when adding if (!ReferenceEquals(working, Clause)) { working = Clause; } working.AddOperand(nextOperand, op.IsInverted); break; case AssociationType.Multiplicaton: //"steal" last operand from Clause, and change working to the new op newOp = op.GetFunction(); newOp.AddOperand(lastOperand); newOp.AddOperand(nextOperand, op.IsInverted); Clause.ReplaceLastOperand(newOp); working = newOp; break; case AssociationType.Power: // Similar to Multiplication, but does not change the active chain to the new operation. It can never be added to. newOp = op.GetFunction(); newOp.AddOperand(lastOperand); newOp.AddOperand(nextOperand, op.IsInverted); Clause.ReplaceLastOperand(newOp); break; case AssociationType.Function: // Similar to Multiplication, but does not change the active chain to the new operation. It can never be added to. newOp = op.GetFunction(); newOp.AddOperand(nextOperand, op.IsInverted); Clause.ReplaceLastOperand(newOp); break; default: throw new NotImplementedException("Unknown association type."); } } lastOperand = nextOperand; } Error = ""; return((IOperand)Clause); }
public GeqOperation(IOperationResultBuilder operationResultBuilder, IOperand fieldRefOperand, IOperand valueOperand) : base(operationResultBuilder, fieldRefOperand, valueOperand) { }
protected override IOperand CopyTo(IOperand operand) { CopyTo((IEquation)operand); return(operand); }
private IOperand createFieldRefOperand(string fieldName, IOperand valueOperand) { var attrs = this.getAdditionalAttributesForFieldRefOperands(valueOperand); return(new FieldRefOperand(fieldName, attrs)); }
private IOperand createFieldRefOperand(Guid id, IOperand valueOperand) { var attrs = this.getAdditionalAttributesForFieldRefOperands(valueOperand); return new FieldRefOperand(id, attrs); }
internal override ArgumentMarshalResult MarshalArgument(int position, IOperand op) { // Marshaling always succeeds in these types of functions return(new ArgumentMarshalResult(true, op)); }
private IOperand createFieldRefOperandFromConstantExpression(ConstantExpression expr, IOperand valueOperand) { // it is possible to create constant expression also of Guid type. See Query.ViewFields(IEnumerable<Guid> ids) //var val = expr.Value as string; var val = expr.Value != null ? expr.Value.ToString() : null; return this.createFieldRefOperandByNameOrId(val, valueOperand); }
public EqOperation(IOperationResultBuilder operationResultBuilder, IOperand fieldRefOperand, IOperand valueOperand) : base(operationResultBuilder, fieldRefOperand, valueOperand) { }
private List<KeyValuePair<string, string>> getAdditionalAttributesForFieldRefOperands(IOperand valueOperand) { if (valueOperand is LookupIdValueOperand || valueOperand is UserIdValueOperand) { var attrs = new List<KeyValuePair<string, string>>(); attrs.Add(new KeyValuePair<string, string>(Attributes.LookupId, true.ToString())); return attrs; } return new List<KeyValuePair<string, string>>(); }
public static High_Operand Hi(this IOperand <Address> addr) => new High_Operand(addr);
public UnaryPredicate(Operator Operator = Operator.Null, IOperand operand = null) { this.Operator = Operator; Operand = operand; }
public static Low_Operand Lo(this IOperand <Address> addr) => new Low_Operand(addr);
protected UnaryOperationBase(IOperationResultBuilder operationResultBuilder, IOperand fieldRefOperand) : base(operationResultBuilder) { this.fieldRefOperand = fieldRefOperand; }
public High_Operand(IOperand <Address> addr) { _addr = addr; }
protected string WrapParenthesis(IOperand operand) { INativeOperation oper = operand as INativeOperation; if (oper != null && oper.Operands.Count > 1 && oper.AssociationType == AssociationType.Addition) { return "(" + operand.ToString() + ")"; } else { return operand.ToString(); } }
public Low_Operand(IOperand <Address> addr) { _addr = addr; }
private IOperand createFieldRefOperandFromNonConstantExpression(Expression expr, IOperand valueOperand) { object value = this.evaluateExpression(expr); if (value == null || (value.GetType() != typeof(string) && value.GetType() != typeof(Guid))) { throw new InvalidValueForFieldRefException(value); } if (value.GetType() == typeof(Guid)) { return(this.createFieldRefOperand((Guid)value, valueOperand)); } return(this.createFieldRefOperandByNameOrId((string)value, valueOperand)); }
public Equation(IOperand operand) { Initialize(); Operand = operand; }
public IsNullOperation(IOperationResultBuilder operationResultBuilder, IOperand fieldRefOperand) : base(operationResultBuilder, fieldRefOperand) { }
private IOperand createFieldRefOperandFromConstantExpression(ConstantExpression expr, IOperand valueOperand) { // it is possible to create constant expression also of Guid type. See Query.ViewFields(IEnumerable<Guid> ids) //var val = expr.Value as string; var val = expr.Value != null?expr.Value.ToString() : null; return(this.createFieldRefOperandByNameOrId(val, valueOperand)); }