YqlCompiledNode CompileAndOr(YqlCompiler compiler) { if (Args.Count == 0) { ReportError("The " + Operation + " operation requires at least one argument"); } var compiledArgs = compiler.CompileNodes(Args); Expression expression = compiledArgs[0].Expression; for (int i = 1; i < compiledArgs.Length; ++i) { if (Operation == YqlOperation.And) { expression = Expression.And(expression, compiledArgs[i].Expression); } else { expression = Expression.Or(expression, compiledArgs[i].Expression); } } return(new YqlCompiledNode(this, expression, compiledArgs)); }
protected internal override YqlCompiledNode CompileNode(YqlCompiler compiler) { if (Items.Count == 0) { ReportError("The list must contain at least one item"); } var compiledItems = compiler.CompileNodes(Items); Type itemType = compiledItems[0].Expression.Type; // Enforce that the other items have the same type for (int i = 0; i < compiledItems.Length; ++i) { var compiledItem = compiledItems[i]; if (compiledItem.Expression.Type != itemType) { ReportError("The list items must all have the same type as the first item: " + itemType.Name); } } // TODO: It would be more efficient to store the array in ExecutionContext // rather than reconstructing it each time the expression is evaluated NewArrayExpression expression = Expression.NewArrayInit(itemType, compiledItems.Select(x => x.Expression).ToArray() ); return(new YqlCompiledNode(this, expression, compiledItems)); }
YqlCompiledNode CompileBinaryOp(YqlCompiler compiler) { if (Args.Count != 2) { ReportError("The " + Operation + " operation requires two arguments"); } var compiledArgs = compiler.CompileNodes(Args); var leftExpression = compiledArgs[0].Expression; var rightExpression = compiledArgs[1].Expression; Expression expression; switch (Operation) { case YqlOperation.GreaterThan: expression = Expression.GreaterThan(leftExpression, rightExpression); break; case YqlOperation.GreaterThanOrEqual: expression = Expression.GreaterThanOrEqual(leftExpression, rightExpression); break; case YqlOperation.LessThan: expression = Expression.LessThan(leftExpression, rightExpression); break; case YqlOperation.LessThanOrEqual: expression = Expression.LessThanOrEqual(leftExpression, rightExpression); break; case YqlOperation.Equal: expression = Expression.Equal(leftExpression, rightExpression); break; case YqlOperation.NotEqual: expression = Expression.NotEqual(leftExpression, rightExpression); break; default: throw new NotImplementedException(); } return(new YqlCompiledNode(this, expression, compiledArgs)); }
YqlCompiledNode CompileUnary(YqlCompiler compiler) { if (Args.Count != 1) { ReportError("The " + Operation + " operation requires one argument"); } var compiledArgs = compiler.CompileNodes(Args); var operandExpression = compiledArgs[0].Expression; Expression expression; switch (Operation) { case YqlOperation.Not: expression = Expression.Not(operandExpression); break; default: throw new NotImplementedException(); } return(new YqlCompiledNode(this, expression, compiledArgs)); }