/// <summary> /// Returns an array of SelectExpressions gathered from the children of the given parent AST node. /// </summary> public ISelectExpression[] CollectSelectExpressions(bool recurse) { // Get the first child to be considered. Sub-classes may do this differently in order to skip nodes that // are not select expressions (e.g. DISTINCT). IASTNode firstChild = GetFirstSelectExpression(); IASTNode parent = this; var list = new List <ISelectExpression>(parent.ChildCount); for (IASTNode n = firstChild; n != null; n = n.NextSibling) { if (recurse) { var ctor = n as ConstructorNode; if (ctor != null) { for (IASTNode cn = ctor.GetChild(1); cn != null; cn = cn.NextSibling) { var se = cn as ISelectExpression; if (se != null) { list.Add(se); } } } else { var se = n as ISelectExpression; if (se != null) { list.Add(se); } else { throw new InvalidOperationException("Unexpected AST: " + n.GetType().FullName + " " + new ASTPrinter().ShowAsString(n, "")); } } } else { var se = n as ISelectExpression; if (se != null) { list.Add(se); } else { throw new InvalidOperationException("Unexpected AST: " + n.GetType().FullName + " " + new ASTPrinter().ShowAsString(n, "")); } } } return(list.ToArray()); }
public override void Initialize() { IASTNode lhs = LeftHandOperand; if (lhs == null) { throw new SemanticException("left-hand operand of in operator was null"); } IASTNode inList = InList; if (inList == null) { throw new SemanticException("right-hand operand of in operator was null"); } // for expected parameter type injection, we expect that the lhs represents // some form of property ref and that the children of the in-list represent // one-or-more params. if (typeof(SqlNode).IsAssignableFrom(lhs.GetType())) { IType lhsType = ((SqlNode)lhs).DataType; IASTNode inListChild = inList.GetChild(0); while (inListChild != null) { if (typeof(IExpectedTypeAwareNode).IsAssignableFrom(inListChild.GetType())) { ((IExpectedTypeAwareNode)inListChild).ExpectedType = lhsType; } inListChild = inListChild.NextSibling; } } }
public virtual void RemoveChild(IASTNode child) { LoggerProvider.instance?.Source("PAR").Message("Removed child").Name(child.GetType().Name).Object(child.GetAdditionalInfo()).Pos(child.Start).End() .Message(" → from").Name(GetType().Name).Pos(Start).End();; Children.Remove(child); child.Parent = null; }
public virtual void AddChild(IASTNode child) { LoggerProvider.instance?.Source("PAR").Message("Added child").Name(child.GetType().Name).Object(child.GetAdditionalInfo()).Pos(child.Start).End() .Message(" → to").Name(GetType().Name).Pos(Start).End(); Children.Add(child); child.Parent = this; }
private static void Check(IASTNode check, IASTNode first, IASTNode second) { if (typeof(IExpectedTypeAwareNode).IsAssignableFrom(check.GetType())) { IType expectedType = null; if (typeof(SqlNode).IsAssignableFrom(first.GetType())) { expectedType = ((SqlNode)first).DataType; } if (expectedType == null && typeof(SqlNode).IsAssignableFrom(second.GetType())) { expectedType = ((SqlNode)second).DataType; } ((IExpectedTypeAwareNode)check).ExpectedType = expectedType; } }
/// <summary> /// Performs the operator node initialization by seeking out any parameter /// nodes and setting their expected type, if possible. /// </summary> public virtual void Initialize() { IASTNode lhs = LeftHandOperand; if (lhs == null) { throw new SemanticException("left-hand operand of a binary operator was null"); } IASTNode rhs = RightHandOperand; if (rhs == null) { throw new SemanticException("right-hand operand of a binary operator was null"); } IType lhsType = ExtractDataType(lhs); IType rhsType = ExtractDataType(rhs); if (lhsType == null) { lhsType = rhsType; } if (rhsType == null) { rhsType = lhsType; } if (typeof(IExpectedTypeAwareNode).IsAssignableFrom(lhs.GetType())) { (( IExpectedTypeAwareNode )lhs).ExpectedType = rhsType; } if (typeof(IExpectedTypeAwareNode).IsAssignableFrom(rhs.GetType())) { (( IExpectedTypeAwareNode )rhs).ExpectedType = lhsType; } MutateRowValueConstructorSyntaxesIfNecessary(lhsType, rhsType); }
public void Initialize() { IASTNode lhs = LeftHandOperand; IASTNode rhs = RightHandOperand; if (lhs == null) { throw new SemanticException("left-hand operand of a binary operator was null"); } if (rhs == null) { throw new SemanticException("right-hand operand of a binary operator was null"); } IType lhType = (lhs is SqlNode) ? ((SqlNode)lhs).DataType : null; IType rhType = (rhs is SqlNode) ? ((SqlNode)rhs).DataType : null; if (typeof(IExpectedTypeAwareNode).IsAssignableFrom(lhs.GetType()) && rhType != null) { IType expectedType; // we have something like : "? [op] rhs" if (IsDateTimeType(rhType)) { // more specifically : "? [op] datetime" // 1) if the operator is MINUS, the param needs to be of // some datetime type // 2) if the operator is PLUS, the param needs to be of // some numeric type expectedType = Type == HqlSqlWalker.PLUS ? NHibernateUtil.Double : rhType; } else { expectedType = rhType; } ((IExpectedTypeAwareNode)lhs).ExpectedType = expectedType; } else if (typeof(ParameterNode).IsAssignableFrom(rhs.GetType()) && lhType != null) { IType expectedType = null; // we have something like : "lhs [op] ?" if (IsDateTimeType(lhType)) { // more specifically : "datetime [op] ?" // 1) if the operator is MINUS, we really cannot determine // the expected type as either another datetime or // numeric would be valid // 2) if the operator is PLUS, the param needs to be of // some numeric type if (Type == HqlSqlWalker.PLUS) { expectedType = NHibernateUtil.Double; } } else { expectedType = lhType; } ((IExpectedTypeAwareNode)rhs).ExpectedType = expectedType; } }