/** * Determine the special properties of this expression * * @return {@link StaticProperty#NO_NODES_NEWLY_CREATED}. */ public int computeSpecialProperties() { int p = super.computeSpecialProperties(); return p | StaticProperty.NO_NODES_NEWLY_CREATED; }
/** * Replace this expression by a simpler expression that delivers the results without regard * to order. * * @param retainAllNodes set to true if the result must contain exactly the same nodes as the * original; set to false if the result can eliminate (or introduce) duplicates. * @param forStreaming set to true if optimizing for streaming */ @Override public Expression unordered(boolean retainAllNodes, boolean forStreaming) throws XPathException { setAction(getAction().unordered(retainAllNodes, forStreaming)); return this; }
/** * Set the slot number for the range variable * @param nr the slot number allocated to the range variable on the local stack frame. * This implicitly allocates the next slot number to the position variable if there is one. */ public void setSlotNumber(int nr) { super.setSlotNumber(nr); if (positionVariable != null) { positionVariable.setSlotNumber(nr+1); } }
/** * Rebuild the reference list to guide subsequent optimization. * @param force if true, the search is exhaustive. If false, the search (and therefore the attempt to * inline variables) is abandoned after a while to avoid excessive cost. This happens when * a stylesheet contains very large templates or functions. */ public void rebuildReferenceList(boolean force) { int[] results = new int[]{0, force ? Integer.MAX_VALUE : 500}; List<VariableReference> references = new ArrayList<>(); countReferences(this, getAction(), references, results); this.references = results[1] <= 0 ? null : references; }
/** * Return the estimated cost of evaluating an expression. This is a very crude measure based * on the syntactic form of the expression (we have no knowledge of data values). We take * the cost of evaluating a simple scalar comparison or arithmetic expression as 1 (one), * and we assume that a sequence has length 5. The resulting estimates may be used, for * example, to reorder the predicates in a filter expression so cheaper predicates are * evaluated first. */ @Override public int getCost() { return getSequence().getCost() + 5 * getAction().getCost(); }
if (operator == Token.FOR) { v = new ForExpression(); v.setRequiredType(SequenceType.SINGLE_ITEM); } else /*if (operator == Token.LET)*/ { v = new LetExpression(); v.setRequiredType(SequenceType.ANY_SEQUENCE); v.setVariableQName(makeStructuredQName(var, "")); nextToken(); v.setSequence(parseExprSingle()); declareRangeVariable(v); if (previous == null) { first = v; } else { previous.setAction(v); previous.setAction(parseExprSingle()); undeclareRangeVariable(); return makeTracer(offset, first, LocationKind.FOR_EXPRESSION, first.getVariableQName());
private static int allocateSlots(Expression exp, int nextFree, SlotManager frame, boolean topLevel) { if (exp instanceof Assignation) { ((Assignation)exp).setSlotNumber(nextFree); int count = ((Assignation)exp).getRequiredSlots(); nextFree += count; if (frame != null) { frame.allocateSlotNumber(((Assignation)exp).getVariableQName()); if (count == 2) { frame.allocateSlotNumber(((ForExpression)exp).getPositionVariableName()); String msg = "*** Internal Saxon error: local variable encountered whose binding has been deleted"; System.err.println(msg); System.err.println("Variable name: " + decl.getVariableName()); System.err.println("Line number of reference: " + var.getLocationId()); System.err.println("Line number of declaration: " + decl.getLocationId()); System.err.println("DECLARATION:"); decl.explain(System.err); throw new IllegalStateException(msg);
((Assignation) exp).setSlotNumber(nextFree); int count = ((Assignation) exp).getRequiredSlots(); nextFree += count; if (frame != null) { frame.allocateSlotNumber(((Assignation) exp).getVariableQName()); err.error("Variable name: " + decl.getVariableName()); err.error("Line number of reference: " + var.getLocation().getLineNumber() + " in " + var.getLocation().getSystemId()); err.error("Line number of declaration: " + decl.getLocation().getLineNumber() + " in " + decl.getLocation().getSystemId()); err.error("DECLARATION:"); try { decl.explain(err); } catch (Exception e) {
/** * Determine whether this is an updating expression as defined in the XQuery update specification * * @return true if this is an updating expression */ public boolean isUpdatingExpression() { return getAction().isUpdatingExpression(); }
/** * Replace all references to the variable bound by this let expression, * that occur within the action expression, with the given expression * * * @param seq the expression * @return true if the variable was successfully inlined. (Returns false, for example, * if a variable reference occurs inside a try/catch, which inhibits inlining). */ public boolean replaceVariable(Expression seq) { boolean done = ExpressionTool.inlineVariableReferences(getAction(), this, seq); if (done && isIndexedVariable() && seq instanceof VariableReference) { Binding newBinding = ((VariableReference) seq).getBinding(); if (newBinding instanceof Assignation) { ((Assignation) newBinding).setIndexedVariable(); } } return done; }
setAction(oldThen); return Choose.makeConditional(condition, this); } else {
/** * Get InstructionInfo for this expression */ public InstructionInfo getInstructionInfo() { InstructionDetails details = new InstructionDetails(); details.setConstructType(getConstructType()); details.setProperty("expression", this); details.setSystemId(getSystemId()); details.setLineNumber(getLineNumber()); details.setColumnNumber(getColumnNumber()); if (this instanceof Assignation) { details.setObjectName(((Assignation)this).getVariableQName()); } return details; }
if (operator == Token.FOR) { v = new ForExpression(); v.setRequiredType(SequenceType.SINGLE_ITEM); } else /*if (operator == Token.LET)*/ { v = new LetExpression(); v.setRequiredType(SequenceType.ANY_SEQUENCE); v.setVariableQName(makeStructuredQName(var, "")); nextToken(); v.setSequence(parseExprSingle()); declareRangeVariable(v); if (previous == null) { first = v; } else { previous.setAction(v); previous.setAction(parseExprSingle()); undeclareRangeVariable(); return makeTracer(offset, first, LocationKind.FOR_EXPRESSION, first.getVariableQName());
private static int allocateSlots(Expression exp, int nextFree, SlotManager frame, boolean topLevel) { if (exp instanceof Assignation) { ((Assignation)exp).setSlotNumber(nextFree); int count = ((Assignation)exp).getRequiredSlots(); nextFree += count; if (frame != null) { frame.allocateSlotNumber(((Assignation)exp).getVariableQName()); if (count == 2) { frame.allocateSlotNumber(((ForExpression)exp).getPositionVariableName()); System.err.println("Variable name: " + decl.getVariableName()); System.err.println("Line number of reference: " + var.getLocationId()); System.err.println("Line number of declaration: " + decl.getLocationId()); System.err.println("DECLARATION:"); decl.explain(System.err); throw new IllegalStateException("*** Internal Saxon error: Unbound local variable encountered");
((Assignation) exp).setSlotNumber(nextFree); int count = ((Assignation) exp).getRequiredSlots(); nextFree += count; if (frame != null) { frame.allocateSlotNumber(((Assignation) exp).getVariableQName()); err.error("Variable name: " + decl.getVariableName()); err.error("Line number of reference: " + var.getLocation().getLineNumber() + " in " + var.getLocation().getSystemId()); err.error("Line number of declaration: " + decl.getLocation().getLineNumber() + " in " + decl.getLocation().getSystemId()); err.error("DECLARATION:"); try { decl.explain(err); } catch (Exception e) {
/** * Return the estimated cost of evaluating an expression. This is a very crude measure based * on the syntactic form of the expression (we have no knowledge of data values). We take * the cost of evaluating a simple scalar comparison or arithmetic expression as 1 (one), * and we assume that a sequence has length 5. The resulting estimates may be used, for * example, to reorder the predicates in a filter expression so cheaper predicates are * evaluated first. */ @Override public int getCost() { return getSequence().getCost() + 5 * getAction().getCost(); }
/** * Suppress validation on contained element constructors, on the grounds that the parent element * is already performing validation. The default implementation does nothing. */ public void suppressValidation(int validationMode) { getAction().suppressValidation(validationMode); }
/** * Replace all references to the variable bound by this let expression, * that occur within the action expression, with the given expression * * * @param seq the expression * @return true if the variable was successfully inlined. (Returns false, for example, * if a variable reference occurs inside a try/catch, which inhibits inlining). */ public boolean replaceVariable(Expression seq) { boolean done = ExpressionTool.inlineVariableReferences(getAction(), this, seq); if (done && isIndexedVariable() && seq instanceof VariableReference) { Binding newBinding = ((VariableReference) seq).getBinding(); if (newBinding instanceof Assignation) { ((Assignation) newBinding).setIndexedVariable(); } } return done; }
/** * Rebuild the reference list to guide subsequent optimization. * @param force if true, the search is exhaustive. If false, the search (and therefore the attempt to * inline variables) is abandoned after a while to avoid excessive cost. This happens when * a stylesheet contains very large templates or functions. */ public void rebuildReferenceList(boolean force) { int[] results = new int[]{0, force ? Integer.MAX_VALUE : 500}; List<VariableReference> references = new ArrayList<>(); countReferences(this, getAction(), references, results); this.references = results[1] <= 0 ? null : references; }
setAction(oldThen); return Choose.makeConditional(condition, this); } else {