Exemple #1
0
 /**
  * Replace all references to the variable bound by this let expression, that occur within the
  * action expression, with the given expression
  *
  * @param opt The optimizer
  * @param seq the expression
  * @throws net.sf.saxon.trans.XPathException
  */
 public void replaceVariable(Optimizer opt, Expression seq) throws XPathException {
   PromotionOffer offer2 = new PromotionOffer(opt);
   offer2.action = PromotionOffer.INLINE_VARIABLE_REFERENCES;
   offer2.bindingList = new Binding[] {this};
   offer2.containingExpression = seq;
   action = doPromotion(action, offer2);
   if (offer2.accepted) {
     // there might be further references to the variable
     offer2.accepted = false;
     replaceVariable(opt, seq);
   }
   if (isIndexedVariable() && seq instanceof VariableReference) {
     Binding newBinding = ((VariableReference) seq).getBinding();
     if (newBinding instanceof Assignation) {
       ((Assignation) newBinding).setIndexedVariable();
     }
   }
 }
Exemple #2
0
 /**
  * Refine the type information associated with this variable declaration. This is useful when the
  * type of the variable has not been explicitly declared (which is common); the variable then
  * takes a static type based on the type of the expression to which it is bound. The effect of
  * this call is to update the static expression type for all references to this variable.
  *
  * @param type the inferred item type of the expression to which the variable is bound
  * @param cardinality the inferred cardinality of the expression to which the variable is bound
  * @param constantValue the constant value to which the variable is bound (null if there is no
  *     constant value)
  * @param properties other static properties of the expression to which the variable is bound
  * @param visitor an expression visitor to provide context information
  * @param currentExpression the expression that binds the variable
  */
 public void refineTypeInformation(
     ItemType type,
     int cardinality,
     Value constantValue,
     int properties,
     ExpressionVisitor visitor,
     Assignation currentExpression) {
   List references = new ArrayList();
   ExpressionTool.gatherVariableReferences(currentExpression.getAction(), this, references);
   for (Iterator iter = references.iterator(); iter.hasNext(); ) {
     BindingReference ref = (BindingReference) iter.next();
     if (ref instanceof VariableReference) {
       ((VariableReference) ref)
           .refineVariableType(type, cardinality, constantValue, properties, visitor);
       visitor.resetStaticProperties();
     }
   }
 }