/** * Remove dead references from the reference list of the variable; at the same time, check whether * any of the variable references is in a loop, and return true if so. References are considered dead * if they do not have this Binding as an ancestor in the expression tree; this typically occurs because * they are in a part of the tree that has been rewritten or removed. * @return true if any of the references in the reference list occurs within a looping construct. */ protected boolean removeDeadReferences() { boolean inLoop = false; if (references != null) { for (int i = references.size() - 1; i >= 0; i--) { // Check whether the reference still has this Assignation as an ancestor in the expression tree boolean found = false; inLoop |= references.get(i).isInLoop(); Expression parent = references.get(i).getParentExpression(); while (parent != null) { if (parent == this) { found = true; break; } else { parent = parent.getParentExpression(); } } if (!found) { references.remove(i); } } } return inLoop; }
/** * Remove dead references from the reference list of the variable; at the same time, check whether * any of the variable references is in a loop, and return true if so. References are considered dead * if they do not have this Binding as an ancestor in the expression tree; this typically occurs because * they are in a part of the tree that has been rewritten or removed. * @return true if any of the references in the reference list occurs within a looping construct. */ protected boolean removeDeadReferences() { boolean inLoop = false; if (references != null) { for (int i = references.size() - 1; i >= 0; i--) { // Check whether the reference still has this Assignation as an ancestor in the expression tree boolean found = false; inLoop |= references.get(i).isInLoop(); Expression parent = references.get(i).getParentExpression(); while (parent != null) { if (parent == this) { found = true; break; } else { parent = parent.getParentExpression(); } } if (!found) { references.remove(i); } } } return inLoop; }
private void inlineReferences() { // Note that the list of references might include references that are no longer reachable on the tree. // We therefore take no action if (a) the parent of the reference is null, or (b) the reference is // not found among the children of its parent. for (VariableReference ref : references) { Expression parent = ref.getParentExpression(); if (parent != null) { Operand o = ExpressionTool.findOperand(parent, ref); if (o != null) { o.setChildExpression(getSequence().copy(new RebindingMap())); } ExpressionTool.resetStaticProperties(parent); } } }
private void inlineReferences() { // Note that the list of references might include references that are no longer reachable on the tree. // We therefore take no action if (a) the parent of the reference is null, or (b) the reference is // not found among the children of its parent. for (VariableReference ref : references) { Expression parent = ref.getParentExpression(); if (parent != null) { Operand o = ExpressionTool.findOperand(parent, ref); if (o != null) { o.setChildExpression(getSequence().copy(new RebindingMap())); } ExpressionTool.resetStaticProperties(parent); } } }
/** * Get the innermost scoping expression of this expression, for expressions that directly * depend on something in the dynamic context. For example, in the case of a local variable * reference this is the expression that causes the relevant variable to be bound; for a * context item expression it is the innermost focus-setting container. For expressions * that have no intrinsic dependency on the dynamic context, the value returned is null; * the scoping container for such an expression is the innermost scoping container of its * operands. * * @return the innermost scoping container of this expression */ @Override public Expression getScopingExpression() { if (binding instanceof Expression) { if (binding instanceof LocalParam && ((LocalParam)binding).getParentExpression() instanceof LocalParamBlock) { LocalParamBlock block = (LocalParamBlock)((LocalParam) binding).getParentExpression(); return block.getParentExpression(); } else { return (Expression) binding; } } Expression parent = getParentExpression(); while (parent != null) { if (parent.hasVariableBinding(binding)) { return parent; } parent = parent.getParentExpression(); } return null; }
/** * Get the innermost scoping expression of this expression, for expressions that directly * depend on something in the dynamic context. For example, in the case of a local variable * reference this is the expression that causes the relevant variable to be bound; for a * context item expression it is the innermost focus-setting container. For expressions * that have no intrinsic dependency on the dynamic context, the value returned is null; * the scoping container for such an expression is the innermost scoping container of its * operands. * * @return the innermost scoping container of this expression */ @Override public Expression getScopingExpression() { if (binding instanceof Expression) { if (binding instanceof LocalParam && ((LocalParam)binding).getParentExpression() instanceof LocalParamBlock) { LocalParamBlock block = (LocalParamBlock)((LocalParam) binding).getParentExpression(); return block.getParentExpression(); } else { return (Expression) binding; } } Expression parent = getParentExpression(); while (parent != null) { if (parent.hasVariableBinding(binding)) { return parent; } parent = parent.getParentExpression(); } return null; }