public boolean includesBinding(Binding binding) { for (Operand o : operands()) { if (((LocalVariableReference)o.getChildExpression()).getBinding() == binding) { return true; } } return false; }
public boolean includesBinding(Binding binding) { for (Operand o : operands()) { if (((LocalVariableReference)o.getChildExpression()).getBinding() == binding) { return true; } } return false; }
/** * Determine whether an expression contains a local variable reference, * other than a reference to a local variable whose binding occurs * within this expression * * @param exp the expression to be tested * @return true if the expression contains a local variable reference to a local * variable declared outside this expression. */ public static boolean containsLocalVariableReference(final Expression exp) { return contains(exp, false, e -> { if (e instanceof LocalVariableReference) { LocalVariableReference vref = (LocalVariableReference)e; LocalBinding binding = vref.getBinding(); return !(binding instanceof Expression && contains(exp, (Expression) binding)); } return false; }); }
/** * Determine whether an expression contains a local variable reference, * other than a reference to a local variable whose binding occurs * within this expression * * @param exp the expression to be tested * @return true if the expression contains a local variable reference to a local * variable declared outside this expression. */ public static boolean containsLocalVariableReference(final Expression exp) { return contains(exp, false, e -> { if (e instanceof LocalVariableReference) { LocalVariableReference vref = (LocalVariableReference)e; LocalBinding binding = vref.getBinding(); return !(binding instanceof Expression && contains(exp, (Expression) binding)); } return false; }); }
private static void countReferences(Binding binding, Expression exp, List<VariableReference> references, int[] results) { // results[0] = nominal reference count // results[1] = quota nodes visited if (exp instanceof LocalVariableReference) { LocalVariableReference ref = (LocalVariableReference) exp; if (ref.getBinding() == binding) { ref.recomputeInLoop(); results[0] += ref.isInLoop() ? 10 : 1; references.add((LocalVariableReference) exp); } } else if ((exp.getDependencies() & StaticProperty.DEPENDS_ON_LOCAL_VARIABLES) != 0) { if (--results[1] <= 0) { // abandon the search results[0] = 100; results[1] = 0; } else { for (Operand o : exp.operands()) { countReferences(binding, o.getChildExpression(), references, results); } } } }
/** * Set the local variables in the current stack frame to values corresponding to a supplied tuple * * @param context identifies the stack frame to be modified * @param tuple the tuple containing the current values */ public void setCurrentTuple(XPathContext context, Tuple tuple) throws XPathException { Sequence[] members = tuple.getMembers(); int n = getSize(); for (int i = 0; i < n; i++) { context.setLocalVariable(getSlot(i).getBinding().getLocalSlotNumber(), members[i]); } }
/** * Set the local variables in the current stack frame to values corresponding to a supplied tuple * * @param context identifies the stack frame to be modified * @param tuple the tuple containing the current values */ public void setCurrentTuple(XPathContext context, Tuple tuple) throws XPathException { Sequence[] members = tuple.getMembers(); int n = getSize(); for (int i = 0; i < n; i++) { context.setLocalVariable(getSlot(i).getBinding().getLocalSlotNumber(), members[i]); } }
private static void countReferences(Binding binding, Expression exp, List<VariableReference> references, int[] results) { // results[0] = nominal reference count // results[1] = quota nodes visited if (exp instanceof LocalVariableReference) { LocalVariableReference ref = (LocalVariableReference) exp; if (ref.getBinding() == binding) { ref.recomputeInLoop(); results[0] += ref.isInLoop() ? 10 : 1; references.add((LocalVariableReference) exp); } } else if ((exp.getDependencies() & StaticProperty.DEPENDS_ON_LOCAL_VARIABLES) != 0) { if (--results[1] <= 0) { // abandon the search results[0] = 100; results[1] = 0; } else { for (Operand o : exp.operands()) { countReferences(binding, o.getChildExpression(), references, results); } } } }
/** * Return the value of the variable * * @param c the XPath dynamic context * @return the value of the variable * @throws XPathException if any dynamic error occurs while evaluating the variable */ /*@NotNull*/ public Sequence<?> evaluateVariable(XPathContext c) throws XPathException { try { return c.getStackFrame().slots[slotNumber]; } catch (ArrayIndexOutOfBoundsException err) { if (slotNumber == -999) { if (binding != null) { try { slotNumber = getBinding().getLocalSlotNumber(); return c.getStackFrame().slots[slotNumber]; } catch (ArrayIndexOutOfBoundsException err2) { // fall through } } throw new ArrayIndexOutOfBoundsException("Local variable $" + getDisplayName() + " has not been allocated a stack frame slot"); } else { int actual = c.getStackFrame().slots.length; throw new ArrayIndexOutOfBoundsException("Local variable $" + getDisplayName() + " uses slot " + slotNumber + " but " + (actual == 0 ? "no" : "only " + c.getStackFrame().slots.length) + " slots" + " are allocated on the stack frame"); } } }
/** * Return the value of the variable * * @param c the XPath dynamic context * @return the value of the variable * @throws XPathException if any dynamic error occurs while evaluating the variable */ /*@NotNull*/ public Sequence<?> evaluateVariable(XPathContext c) throws XPathException { try { return c.getStackFrame().slots[slotNumber]; } catch (ArrayIndexOutOfBoundsException err) { if (slotNumber == -999) { if (binding != null) { try { slotNumber = getBinding().getLocalSlotNumber(); return c.getStackFrame().slots[slotNumber]; } catch (ArrayIndexOutOfBoundsException err2) { // fall through } } throw new ArrayIndexOutOfBoundsException("Local variable $" + getDisplayName() + " has not been allocated a stack frame slot"); } else { int actual = c.getStackFrame().slots.length; throw new ArrayIndexOutOfBoundsException("Local variable $" + getDisplayName() + " uses slot " + slotNumber + " but " + (actual == 0 ? "no" : "only " + c.getStackFrame().slots.length) + " slots" + " are allocated on the stack frame"); } } }
Binding bind = ((LocalVariableReference) exp).getBinding(); PathBuilder pb = null; if (bind instanceof Expression) {
/** * Reset cached static properties within a subtree, meaning that they have to be * recalulated next time they are required * * @param exp the root of the subtree within which static properties should be reset */ public static void resetPropertiesWithinSubtree(Expression exp) { exp.resetLocalStaticProperties(); if (exp instanceof LocalVariableReference) { LocalVariableReference ref = (LocalVariableReference) exp; Binding binding = ref.getBinding(); if (binding instanceof Assignation) { binding.addReference(ref, ref.isInLoop()); } } for (Operand o : exp.operands()) { resetPropertiesWithinSubtree(o.getChildExpression()); o.getChildExpression().setParentExpression(exp); } }
/** * Reset cached static properties within a subtree, meaning that they have to be * recalulated next time they are required * * @param exp the root of the subtree within which static properties should be reset */ public static void resetPropertiesWithinSubtree(Expression exp) { exp.resetLocalStaticProperties(); if (exp instanceof LocalVariableReference) { LocalVariableReference ref = (LocalVariableReference) exp; Binding binding = ref.getBinding(); if (binding instanceof Assignation) { binding.addReference(ref, ref.isInLoop()); } } for (Operand o : exp.operands()) { resetPropertiesWithinSubtree(o.getChildExpression()); o.getChildExpression().setParentExpression(exp); } }
/** * Diagnostic print of expression structure. The abstract expression tree * is written to the supplied output destination. * * @param out the expression presenter used to display the structure */ @Override public void explain(ExpressionPresenter out) { out.startElement("group-by"); for (Operand o : getRetainedTupleExpression().operands()) { LocalVariableReference ref = (LocalVariableReference)o.getChildExpression(); out.startSubsidiaryElement("by"); out.emitAttribute("var", ref.getDisplayName()); out.emitAttribute("slot", ref.getBinding().getLocalSlotNumber() + ""); out.endSubsidiaryElement(); } out.endElement(); }
/** * Diagnostic print of expression structure. The abstract expression tree * is written to the supplied output destination. * * @param out the expression presenter used to display the structure */ @Override public void explain(ExpressionPresenter out) { out.startElement("group-by"); for (Operand o : getRetainedTupleExpression().operands()) { LocalVariableReference ref = (LocalVariableReference)o.getChildExpression(); out.startSubsidiaryElement("by"); out.emitAttribute("var", ref.getDisplayName()); out.emitAttribute("slot", ref.getBinding().getLocalSlotNumber() + ""); out.endSubsidiaryElement(); } out.endElement(); }