public Value Visit(OrExpr expr, Scope scope) { return(PerformOperation(expr.Left.Accept(this, scope), expr.Right.Accept(this, scope), (a, b) => { throw new InvalidOperationException(); }, (a, b) => { throw new InvalidOperationException(); }, (a, b) => a || b, (a, b) => { throw new InvalidOperationException(); })); }
public void OrAndTest() { var target = new EvaluateVisitor(); var expr = new OrExpr(new ConstantExpr(true), new AndExpr(new ConstantExpr(true), new ConstantExpr(false))); var actual = target.Visit(expr, _scope);; Assert.AreEqual(true, actual.ToBoolean()); }
public void OrAndTest() { var target = new TypeCheckingVisitor(); var expr = new OrExpr(new ConstantExpr(true), new AndExpr(new ConstantExpr(true), new ConstantExpr(false))); var actual = target.Visit(expr, scope); Assert.AreEqual(ValueType.Boolean, actual); }
public void VisitBooleanOrExpr(bool a, bool b, ValueType expected) { var target = new TypeCheckingVisitor(); var aExpression = new ConstantExpr(a); var bExpression = new ConstantExpr(b); var expr = new OrExpr(aExpression, bExpression); var actual = target.Visit(expr, scope); Assert.AreEqual(expected, actual); }
public void Visit(OrExpr orExpr, object[] args) { orExpr.FirstOp.Accept(this); orExpr.SecondOp.Accept(this); RightValue v1 = readRightValue(orExpr.FirstOp); RightValue v2 = readRightValue(orExpr.SecondOp); BoolConst result = new BoolConst(); result.Value = v1.ToBoolean() || v2.ToBoolean(); orExpr.RightValue = result; }
public void VisitBooleanOrExpr(object a, object b, string expected) { var target = new PrintVisitor(); var aExpression = new ConstantExpr(a); var bExpression = new ConstantExpr(b); var expr = new OrExpr(aExpression, bExpression); var actual = target.Visit(expr, scope); Assert.AreEqual(expected, actual); }
public void VisitBooleanOrExpr(bool a, bool b, bool expected) { var target = new EvaluateVisitor(); var aExpression = new ConstantExpr(a); var bExpression = new ConstantExpr(b); var expr = new OrExpr(aExpression, bExpression); var actual = target.Visit(expr, _scope); Assert.AreEqual(expected, actual.ToBoolean()); }
private Expr parseOrExpr() { Expr expr = parseAndExpr(); while (true) { int token = parseToken(); if (token != OR) { _peekToken = token; return(expr); } expr = new OrExpr(expr, parseAndExpr()); } }
internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > VisitAnd( AndExpr <DomainConstraint <BoolLiteral, Constant> > expression) { BoolExpr <DomainConstraint <BoolLiteral, Constant> > boolExpr = base.VisitAnd(expression); TreeExpr <DomainConstraint <BoolLiteral, Constant> > treeExpr = boolExpr as TreeExpr <DomainConstraint <BoolLiteral, Constant> >; if (treeExpr == null) { return(boolExpr); } Set <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > set = new Set <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >(); Set <Set <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > > source = new Set <Set <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > >(); foreach (BoolExpr <DomainConstraint <BoolLiteral, Constant> > child in treeExpr.Children) { OrExpr <DomainConstraint <BoolLiteral, Constant> > orExpr = child as OrExpr <DomainConstraint <BoolLiteral, Constant> >; if (orExpr != null) { source.Add(new Set <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >(orExpr.Children)); } else { set.Add(child); } } source.Add(new Set <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >((IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >) new BoolExpr <DomainConstraint <BoolLiteral, Constant> >[1] { (BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new AndExpr <DomainConstraint <BoolLiteral, Constant> >((IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >)set) })); IEnumerable <IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > > seed = (IEnumerable <IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > >) new IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >[1] { Enumerable.Empty <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >() }; IEnumerable <IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > > boolExprs = source.Aggregate <Set <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >, IEnumerable <IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > > >(seed, (Func <IEnumerable <IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > >, Set <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >, IEnumerable <IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > > >)((accumulator, bucket) => accumulator.SelectMany <IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >, BoolExpr <DomainConstraint <BoolLiteral, Constant> >, IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > >((Func <IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >, IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > >)(accseq => (IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >)bucket), (Func <IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >, BoolExpr <DomainConstraint <BoolLiteral, Constant> >, IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > >)((accseq, item) => accseq.Concat <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >((IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >) new BoolExpr <DomainConstraint <BoolLiteral, Constant> >[1] { item }))))); List <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > boolExprList = new List <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >(); foreach (IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > > children in boolExprs) { boolExprList.Add((BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new AndExpr <DomainConstraint <BoolLiteral, Constant> >(children)); } return((BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new OrExpr <DomainConstraint <BoolLiteral, Constant> >((IEnumerable <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >)boolExprList)); }
public void OrMultiple() { RequiredDataContainer ModelData = SelectDataProvider.GetData(); string HandcraftedQuery = Utils.ReadQueryFromFile("HandcraftedQueries/selectOrMultiple.js"); Assert.IsNotNull(HandcraftedQuery); MapRule PersonRule = ModelData.ERMongoMapping.Rules.First(R => R.Source.Name == "Person"); string AgeMap = PersonRule.Rules.First(R => R.Key == "age").Value; OrExpr expr = new OrExpr($"${AgeMap}", new List <object>() { 18, 21, 36 }); SelectArgument Arg = new SelectArgument(expr); SelectStage SelectOp = new SelectStage(Arg, ModelData.ERMongoMapping); List <AlgebraOperator> OperatorsToExecute = new List <AlgebraOperator>() { SelectOp }; FromArgument StartArg = new FromArgument(new QueryableEntity(ModelData.EntityRelationshipModel.FindByName("Person")), ModelData.ERMongoMapping); QueryGenerator QueryGen = new QueryGenerator(StartArg, OperatorsToExecute); string GeneratedQuery = QueryGen.Run(); Assert.IsNotNull(GeneratedQuery); QueryRunner Runner = new QueryRunner("mongodb://localhost:27017", "select"); string HandcraftedResult = Runner.GetJSON(HandcraftedQuery); string GeneratedResult = Runner.GetJSON(GeneratedQuery); // Check if either result is null Assert.IsNotNull(HandcraftedResult); Assert.IsNotNull(GeneratedResult); // Check if both results are equal Assert.IsTrue(JToken.DeepEquals(JToken.Parse(HandcraftedResult), JToken.Parse(GeneratedResult))); }
protected IType CheckExpr(OrExpr expr) { IType a = CheckExpr(expr.Expr1); IType b = CheckExpr(expr.Expr2); if (!(a is BoolType) || !a.CompatibleWith(b)) { AddError(String.Format("'||' not possible. Incompatible types: '{0}', '{1}'. Only the bool type is supported.", a.ToString(), b.ToString()), true, expr.SourcePosition); } return BoolType.Instance; }
public string Visit(OrExpr expr, Scope scope) { return(expr.Left.Accept(this, scope) + " || " + expr.Right.Accept(this, scope)); }
internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > VisitOr( OrExpr <DomainConstraint <BoolLiteral, Constant> > expression) { return((BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new AndExpr <DomainConstraint <BoolLiteral, Constant> >(expression.Children.Select <BoolExpr <DomainConstraint <BoolLiteral, Constant> >, BoolExpr <DomainConstraint <BoolLiteral, Constant> > >((Func <BoolExpr <DomainConstraint <BoolLiteral, Constant> >, BoolExpr <DomainConstraint <BoolLiteral, Constant> > >)(child => child.Accept <BoolExpr <DomainConstraint <BoolLiteral, Constant> > >((Visitor <DomainConstraint <BoolLiteral, Constant>, BoolExpr <DomainConstraint <BoolLiteral, Constant> > >) this))))); }
/// <param name="orex"> /// is the 'or' expression. </param> /// <returns> make logic expr(orex). </returns> public virtual object visit(OrExpr orex) { return(make_logic_expr(orex)); }
public object parse(XPathLexer lexer) { return(OrExpr.parse(this, lexer)); }
public void OrAndTest() { var target = new EvaluateVisitor(); var expr = new OrExpr(new ConstantExpr(true), new AndExpr(new ConstantExpr(true), new ConstantExpr(false))); var actual = target.Visit(expr, _scope); ; Assert.AreEqual(true, actual.ToBoolean()); }
/// <param name="ex"> /// is the 'or' expression. </param> /// <returns> make logic expr(orex). </returns> public virtual object visit(OrExpr ex) { ex.left().accept(this); ex.right().accept(this); return(null); }
public ValueType Visit(OrExpr expr, Scope scope) { return(BinaryOperatorTypeCheck(expr, scope)); }
internal override int VisitOr(OrExpr <T_Identifier> expression) { return(this.VisitTree((TreeExpr <T_Identifier>)expression)); }
/// <summary> /// Validate an OR expression. /// </summary> /// <param name="orex"> /// is the expression. </param> /// <returns> null. </returns> public virtual object visit(OrExpr orex) { printBinExpr("OR", orex); return(null); }
internal override bool VisitOr( OrExpr <DomainConstraint <BoolLiteral, Constant> > expression) { return(this.VisitAndOr((TreeExpr <DomainConstraint <BoolLiteral, Constant> >)expression)); }
internal override CellTreeNode VisitOr(OrExpr <DomainConstraint <BoolLiteral, Constant> > expression) { throw new NotImplementedException(); }
internal override DbExpression VisitOr( OrExpr <DomainConstraint <BoolLiteral, Constant> > expression) { return(this.VisitAndOr((TreeExpr <DomainConstraint <BoolLiteral, Constant> >)expression, new Func <DbExpression, DbExpression, DbExpression>(DbExpressionBuilder.Or))); }
internal override DomainBoolExpr VisitOr(OrExpr <DomainConstraint> expression) { return(new AndExpr <DomainConstraint>(expression.Children.Select(child => child.Accept(this)))); }
internal abstract T_Return VisitOr(OrExpr <T_Identifier> expression);
internal override IEnumerable <TermExpr <DomainConstraint <BoolLiteral, Constant> > > VisitOr( OrExpr <DomainConstraint <BoolLiteral, Constant> > expression) { return(this.VisitTreeNode((TreeExpr <DomainConstraint <BoolLiteral, Constant> >)expression)); }
internal override StringBuilder VisitOr( OrExpr <DomainConstraint <BoolLiteral, Constant> > expression) { return(this.VisitAndOr((TreeExpr <DomainConstraint <BoolLiteral, Constant> >)expression, "OR")); }