/*additive-expression-p: | additive-operators multiplicative-expression additive-expression-p | EPSILON */ private ExpressionNode additive_expression_p(ExpressionNode leftExpression) { printIfDebug("additive_expression_p"); if (pass(additiveOperatorOptions)) { Token additiveOperatior = token; consumeToken(); var multExpression = multiplicative_expression(); ExpressionNode resultExpression = null; if (additiveOperatior.type == TokenType.OP_SUM) { resultExpression = new SumExpressionNode(leftExpression, multExpression, additiveOperatior); } else { resultExpression = new SubExpressionNode(leftExpression, multExpression, additiveOperatior); } return(additive_expression_p(resultExpression)); } else { return(leftExpression); } }
public void Test_WithMultipleNodes() { _registry.Register(SelectExpressionNode.GetSupportedMethods(), typeof(SelectExpressionNode)); _registry.Register(SumExpressionNode.GetSupportedMethods(), typeof(SumExpressionNode)); var type1 = _registry.GetNodeType(SelectExpressionNode.GetSupportedMethods().First()); var type2 = _registry.GetNodeType(SumExpressionNode.GetSupportedMethods().First()); var type3 = _registry.GetNodeType(SumExpressionNode.GetSupportedMethods().Skip(1).First()); Assert.That(type1, Is.SameAs(typeof(SelectExpressionNode))); Assert.That(type2, Is.SameAs(typeof(SumExpressionNode))); Assert.That(type3, Is.SameAs(typeof(SumExpressionNode))); }
public void Test_NonGenericMethod() { var registry = _registry; registry.Register(SumExpressionNode.GetSupportedMethods(), typeof(SumExpressionNode)); var nonGenericMethod = ReflectionUtility.GetMethod(() => Queryable.Sum((IQueryable <int>)null)); Assert.That(nonGenericMethod.IsGenericMethod, Is.False); var type = registry.GetNodeType(nonGenericMethod); Assert.That(type, Is.SameAs(typeof(SumExpressionNode))); }
public void Test_WithNonGenericMethod_ReturnsTrue() { var registry = _registry; registry.Register(SumExpressionNode.GetSupportedMethods(), typeof(SumExpressionNode)); var nonGenericMethod = ReflectionUtility.GetMethod(() => Queryable.Sum((IQueryable <int>)null)); Assert.That(nonGenericMethod.IsGenericMethod, Is.False); var result = registry.IsRegistered(nonGenericMethod); Assert.That(result, Is.True); }
public void GetSupportedMethods() { Assert.That( SumExpressionNode.GetSupportedMethods(), Is.EquivalentTo( new[] { GetGenericMethodDefinition(() => Queryable.Sum((IQueryable <decimal>)null)), GetGenericMethodDefinition(() => Queryable.Sum((IQueryable <decimal?>)null)), GetGenericMethodDefinition(() => Queryable.Sum((IQueryable <double>)null)), GetGenericMethodDefinition(() => Queryable.Sum((IQueryable <double?>)null)), GetGenericMethodDefinition(() => Queryable.Sum((IQueryable <int>)null)), GetGenericMethodDefinition(() => Queryable.Sum((IQueryable <int?>)null)), GetGenericMethodDefinition(() => Queryable.Sum((IQueryable <long>)null)), GetGenericMethodDefinition(() => Queryable.Sum((IQueryable <long?>)null)), GetGenericMethodDefinition(() => Queryable.Sum((IQueryable <float>)null)), GetGenericMethodDefinition(() => Queryable.Sum((IQueryable <float?>)null)), GetGenericMethodDefinition(() => Queryable.Sum <object> (null, o => (decimal)0)), GetGenericMethodDefinition(() => Queryable.Sum <object> (null, o => (decimal?)0)), GetGenericMethodDefinition(() => Queryable.Sum <object> (null, o => (double)0)), GetGenericMethodDefinition(() => Queryable.Sum <object> (null, o => (double?)0)), GetGenericMethodDefinition(() => Queryable.Sum <object> (null, o => (int)0)), GetGenericMethodDefinition(() => Queryable.Sum <object> (null, o => (int?)0)), GetGenericMethodDefinition(() => Queryable.Sum <object> (null, o => (long)0)), GetGenericMethodDefinition(() => Queryable.Sum <object> (null, o => (long?)0)), GetGenericMethodDefinition(() => Queryable.Sum <object> (null, o => (float)0)), GetGenericMethodDefinition(() => Queryable.Sum <object> (null, o => (float?)0)), GetGenericMethodDefinition(() => Enumerable.Sum((IEnumerable <decimal>)null)), GetGenericMethodDefinition(() => Enumerable.Sum((IEnumerable <decimal?>)null)), GetGenericMethodDefinition(() => Enumerable.Sum((IEnumerable <double>)null)), GetGenericMethodDefinition(() => Enumerable.Sum((IEnumerable <double?>)null)), GetGenericMethodDefinition(() => Enumerable.Sum((IEnumerable <int>)null)), GetGenericMethodDefinition(() => Enumerable.Sum((IEnumerable <int?>)null)), GetGenericMethodDefinition(() => Enumerable.Sum((IEnumerable <long>)null)), GetGenericMethodDefinition(() => Enumerable.Sum((IEnumerable <long?>)null)), GetGenericMethodDefinition(() => Enumerable.Sum((IEnumerable <float>)null)), GetGenericMethodDefinition(() => Enumerable.Sum((IEnumerable <float?>)null)), GetGenericMethodDefinition(() => Enumerable.Sum <object> (null, o => (decimal)0)), GetGenericMethodDefinition(() => Enumerable.Sum <object> (null, o => (decimal?)0)), GetGenericMethodDefinition(() => Enumerable.Sum <object> (null, o => (double)0)), GetGenericMethodDefinition(() => Enumerable.Sum <object> (null, o => (double?)0)), GetGenericMethodDefinition(() => Enumerable.Sum <object> (null, o => (int)0)), GetGenericMethodDefinition(() => Enumerable.Sum <object> (null, o => (int?)0)), GetGenericMethodDefinition(() => Enumerable.Sum <object> (null, o => (long)0)), GetGenericMethodDefinition(() => Enumerable.Sum <object> (null, o => (long?)0)), GetGenericMethodDefinition(() => Enumerable.Sum <object> (null, o => (float)0)), GetGenericMethodDefinition(() => Enumerable.Sum <object> (null, o => (float?)0)), })); }
public void Visit(SumExpressionNode sumExpressionNode) { if (sumExpressionNode.Left == null) { DazelLogger.EmitError("Expression left operand is null", sumExpressionNode.Token); } if (sumExpressionNode.Right == null) { DazelLogger.EmitError("Expression right operand is null", sumExpressionNode.Token); } sumExpressionNode.Left.Accept(this); sumExpressionNode.Right.Accept(this); }
/// <summary> /// Creates a <see cref="MethodInfoBasedNodeTypeRegistry"/> and registers all relevant <see cref="IExpressionNode"/> implementations in the <b>Remotion.Linq</b> assembly. /// </summary> /// <returns> /// A <see cref="MethodInfoBasedNodeTypeRegistry"/> with all <see cref="IExpressionNode"/> types in the <b>Remotion.Linq</b> assembly registered. /// </returns> public static MethodInfoBasedNodeTypeRegistry CreateFromRelinqAssembly() { var registry = new MethodInfoBasedNodeTypeRegistry(); registry.Register(AggregateExpressionNode.GetSupportedMethods(), typeof(AggregateExpressionNode)); registry.Register(AggregateFromSeedExpressionNode.GetSupportedMethods(), typeof(AggregateFromSeedExpressionNode)); registry.Register(AllExpressionNode.GetSupportedMethods(), typeof(AllExpressionNode)); registry.Register(AnyExpressionNode.GetSupportedMethods(), typeof(AnyExpressionNode)); registry.Register(AsQueryableExpressionNode.GetSupportedMethods(), typeof(AsQueryableExpressionNode)); registry.Register(AverageExpressionNode.GetSupportedMethods(), typeof(AverageExpressionNode)); registry.Register(CastExpressionNode.GetSupportedMethods(), typeof(CastExpressionNode)); registry.Register(ConcatExpressionNode.GetSupportedMethods(), typeof(ConcatExpressionNode)); registry.Register(ContainsExpressionNode.GetSupportedMethods(), typeof(ContainsExpressionNode)); registry.Register(CountExpressionNode.GetSupportedMethods(), typeof(CountExpressionNode)); registry.Register(DefaultIfEmptyExpressionNode.GetSupportedMethods(), typeof(DefaultIfEmptyExpressionNode)); registry.Register(DistinctExpressionNode.GetSupportedMethods(), typeof(DistinctExpressionNode)); registry.Register(ExceptExpressionNode.GetSupportedMethods(), typeof(ExceptExpressionNode)); registry.Register(FirstExpressionNode.GetSupportedMethods(), typeof(FirstExpressionNode)); registry.Register(GroupByExpressionNode.GetSupportedMethods(), typeof(GroupByExpressionNode)); registry.Register(GroupByWithResultSelectorExpressionNode.GetSupportedMethods(), typeof(GroupByWithResultSelectorExpressionNode)); registry.Register(GroupJoinExpressionNode.GetSupportedMethods(), typeof(GroupJoinExpressionNode)); registry.Register(IntersectExpressionNode.GetSupportedMethods(), typeof(IntersectExpressionNode)); registry.Register(JoinExpressionNode.GetSupportedMethods(), typeof(JoinExpressionNode)); registry.Register(LastExpressionNode.GetSupportedMethods(), typeof(LastExpressionNode)); registry.Register(LongCountExpressionNode.GetSupportedMethods(), typeof(LongCountExpressionNode)); registry.Register(MaxExpressionNode.GetSupportedMethods(), typeof(MaxExpressionNode)); registry.Register(MinExpressionNode.GetSupportedMethods(), typeof(MinExpressionNode)); registry.Register(OfTypeExpressionNode.GetSupportedMethods(), typeof(OfTypeExpressionNode)); registry.Register(OrderByDescendingExpressionNode.GetSupportedMethods(), typeof(OrderByDescendingExpressionNode)); registry.Register(OrderByExpressionNode.GetSupportedMethods(), typeof(OrderByExpressionNode)); registry.Register(ReverseExpressionNode.GetSupportedMethods(), typeof(ReverseExpressionNode)); registry.Register(SelectExpressionNode.GetSupportedMethods(), typeof(SelectExpressionNode)); registry.Register(SelectManyExpressionNode.GetSupportedMethods(), typeof(SelectManyExpressionNode)); registry.Register(SingleExpressionNode.GetSupportedMethods(), typeof(SingleExpressionNode)); registry.Register(SkipExpressionNode.GetSupportedMethods(), typeof(SkipExpressionNode)); registry.Register(SumExpressionNode.GetSupportedMethods(), typeof(SumExpressionNode)); registry.Register(TakeExpressionNode.GetSupportedMethods(), typeof(TakeExpressionNode)); registry.Register(ThenByDescendingExpressionNode.GetSupportedMethods(), typeof(ThenByDescendingExpressionNode)); registry.Register(ThenByExpressionNode.GetSupportedMethods(), typeof(ThenByExpressionNode)); registry.Register(UnionExpressionNode.GetSupportedMethods(), typeof(UnionExpressionNode)); registry.Register(WhereExpressionNode.GetSupportedMethods(), typeof(WhereExpressionNode)); return(registry); }
public void ExpressionEvaluator_Visit_SimpleAddition() { SumExpressionNode sumExpression = new SumExpressionNode { Left = new IntValueNode { Value = 1 }, OperationNode = new SumOperationNode { Operator = Operators.AddOp }, Right = new IntValueNode { Value = 2 } }; ExpressionEvaluator <int> evaluator = new ExpressionEvaluator <int>(new IntCalculator(sumExpression.Token)); sumExpression.Accept(evaluator); Assert.That(evaluator.Result == 3, "evaluator.Result == 3"); }
public void Visit(SumExpressionNode sumExpressionNode) { sumExpressionNode.Left.Accept(this); T a = Result; sumExpressionNode.Right.Accept(this); T b = Result; switch (sumExpressionNode.OperationNode.Operator) { case Operators.AddOp: Result = Calculator.Add(a, b); break; case Operators.MinOp: Result = Calculator.Subtract(a, b); break; default: DazelLogger.EmitError($"Operation {sumExpressionNode.OperationNode.Operator} is not valid.", sumExpressionNode.Token); break; } }
public void Visit(SumExpressionNode sumExpressionNode) { sumExpressionNode.Left.Accept(this); sumExpressionNode.OperationNode.Accept(this); sumExpressionNode.Right.Accept(this); }
public void Visit(SumExpressionNode sumExpressionNode) { }
public override void SetUp() { base.SetUp(); _node = new SumExpressionNode(CreateParseInfo(), null); }