public void TestValidate() { // test success _orNode.AddChildNode(new SupportExprNode(typeof(Boolean))); _orNode.AddChildNode(new SupportExprNode(typeof(Boolean))); _orNode.Validate(ExprValidationContextFactory.MakeEmpty()); // test failure, type mismatch _orNode.AddChildNode(new SupportExprNode(typeof(string))); try { _orNode.Validate(ExprValidationContextFactory.MakeEmpty()); Assert.Fail(); } catch (ExprValidationException ex) { // Expected } // test failed - with just one child _orNode = new ExprOrNode(); _orNode.AddChildNode(new SupportExprNode(typeof(Boolean))); try { _orNode.Validate(ExprValidationContextFactory.MakeEmpty()); Assert.Fail(); } catch (ExprValidationException ex) { // Expected } }
public void Visit(ExprOrNode node) { foreach (var subnode in node) { Visit((dynamic)subnode); } }
private static FilterSpecPlanPathTripletForge HandleOrAlternateExpression( ExprOrNode orNode, bool performConditionPlanning, IDictionary <string, Pair <EventType, string> > taggedEventTypes, IDictionary <string, Pair <EventType, string> > arrayEventTypes, ISet <string> allTagNamesOrdered, string statementName, StreamTypeService streamTypeService, StatementRawInfo raw, StatementCompileTimeServices services) { IList <ExprNode> valueExpressions = new List <ExprNode>(orNode.ChildNodes.Length); foreach (ExprNode child in orNode.ChildNodes) { FilterSpecExprNodeVisitorValueLimitedExpr visitor = new FilterSpecExprNodeVisitorValueLimitedExpr(); child.Accept(visitor); if (visitor.IsLimited) { valueExpressions.Add(child); } } // The or-node must have a single constituent and one or more value expressions if (orNode.ChildNodes.Length != valueExpressions.Count + 1) { return(null); } IList <ExprNode> constituents = new List <ExprNode>(orNode.ChildNodes); constituents.RemoveAll(valueExpressions); if (constituents.Count != 1) { throw new IllegalStateException("Found multiple constituents"); } ExprNode constituent = constituents[0]; FilterSpecPlanPathTripletForge triplet = MakeFilterParam( constituent, performConditionPlanning, taggedEventTypes, arrayEventTypes, allTagNamesOrdered, statementName, streamTypeService, raw, services); if (triplet == null) { return(null); } ExprNode controlConfirm = ExprNodeUtilityMake.ConnectExpressionsByLogicalOrWhenNeeded(valueExpressions); return(new FilterSpecPlanPathTripletForge(triplet.Param, controlConfirm)); }
public static ExprOrNode ConnectExpressionsByLogicalOr(ICollection<ExprNode> nodes) { if (nodes.Count < 2) { throw new ArgumentException("Invalid empty or 1-element list of nodes"); } ExprOrNode orNode = new ExprOrNode(); foreach (ExprNode node in nodes) { orNode.AddChildNode(node); } return orNode; }
public Node Expr() { var node = ExprAnd(); while (CurrentToken == TokenCategory.OR) { var node1 = new ExprOrNode() { AnchorToken = Expect(TokenCategory.OR) }; node1.Add(node); node1.Add(ExprAnd()); node = node1; } return(node); }
private static IList <ExprNode> GetNonValueChildNodes(ExprOrNode orNode) { IList <ExprNode> childNodes = new List <ExprNode>(orNode.ChildNodes.Length); foreach (var node in orNode.ChildNodes) { var visitor = new FilterSpecExprNodeVisitorValueLimitedExpr(); node.Accept(visitor); if (!visitor.IsLimited) { childNodes.Add(node); } } return(childNodes); }
public void TestEvaluate() { _orNode.AddChildNode(new SupportBoolExprNode(true)); _orNode.AddChildNode(new SupportBoolExprNode(false)); SupportExprNodeUtil.Validate(_orNode); Assert.IsTrue(_orNode.Evaluate(new EvaluateParams(null, false, null)).AsBoolean()); _orNode = new ExprOrNode(); _orNode.AddChildNode(new SupportBoolExprNode(false)); _orNode.AddChildNode(new SupportBoolExprNode(false)); SupportExprNodeUtil.Validate(_orNode); Assert.IsFalse(_orNode.Evaluate(new EvaluateParams(null, false, null)).AsBoolean()); _orNode = new ExprOrNode(); _orNode.AddChildNode(new SupportExprNode(null, typeof(Boolean))); _orNode.AddChildNode(new SupportExprNode(false)); SupportExprNodeUtil.Validate(_orNode); Assert.IsNull(_orNode.Evaluate(new EvaluateParams(null, false, null))); }
public void QExprOr(ExprOrNode exprOrNode) { }
public void SetUp() { _orNode = new ExprOrNode(); }
private static ExprNode Unwind(ExprNode node) { var isOr = node is ExprOrNode; var isAnd = node is ExprAndNode; if (!isOr && !isAnd) { return node; } var needsUnwind = false; foreach (var child in node.ChildNodes) { if (child is ExprOrNode && isOr || child is ExprAndNode && isAnd) { needsUnwind = true; break; } } if (!needsUnwind) { return node; } if (isOr) { var unwoundX = new ExprOrNode(); foreach (var child in node.ChildNodes) { if (child is ExprOrNode) { foreach (var orChild in child.ChildNodes) { var unwoundChild = Unwind(orChild); if (unwoundChild is ExprOrNode) { unwoundX.AddChildNodes(Arrays.AsList(unwoundChild.ChildNodes)); } else { unwoundX.AddChildNode(unwoundChild); } } } else { unwoundX.AddChildNode(Unwind(child)); } } return unwoundX; } ExprAndNode unwound = new ExprAndNodeImpl(); foreach (var child in node.ChildNodes) { if (child is ExprAndNode) { foreach (var andChild in child.ChildNodes) { var unwoundChild = Unwind(andChild); if (unwoundChild is ExprAndNode) { unwound.AddChildNodes(Arrays.AsList(unwoundChild.ChildNodes)); } else { unwound.AddChildNode(unwoundChild); } } } else { unwound.AddChildNode(Unwind(child)); } } return unwound; }