You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by sa...@apache.org on 2004/02/11 20:52:15 UTC

cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler Predicate.java

santiagopg    2004/02/11 11:52:15

  Modified:    java/src/org/apache/xalan/xsltc/compiler Predicate.java
  Log:
  Fix for Bugzilla 24788. NodeValue optimization was too optimistic. Since the value in 'step = value' is not compiled in the predicate's context, it must be limited to expressions that are context independent, but this was not the case as the example in 24788 shows.
  
  Revision  Changes    Path
  1.32      +74 -44    xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Predicate.java
  
  Index: Predicate.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Predicate.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- Predicate.java	5 Feb 2004 22:53:42 -0000	1.31
  +++ Predicate.java	11 Feb 2004 19:52:15 -0000	1.32
  @@ -484,68 +484,98 @@
   	return (getStep() != null && getCompareValue() != null);
       }
   
  -    /**
  -     * Utility method for optimisation. See isNodeValueTest()
  +   /**
  +     * Returns the step in an expression of the form 'step = value'. 
  +     * Null is returned if the expression is not of the right form.
  +     * Optimization if off if null is returned.
        */
  -    public Expression getCompareValue() {
  -	if (_value != null) return _value;
  -	if (_exp == null) return null;
  +    public Step getStep() {
  +        // Returned cached value if called more than once
  +	if (_step != null) {
  +            return _step;
  +        }
  +        
  +        // Nothing to do if _exp is null
  +	if (_exp == null) {
  +            return null;
  +        }
   
  +        // Ignore if not equality expression
   	if (_exp instanceof EqualityExpr) {
   	    EqualityExpr exp = (EqualityExpr)_exp;
   	    Expression left = exp.getLeft();
   	    Expression right = exp.getRight();
   
  -	    Type tleft = left.getType();
  -	    Type tright = right.getType();
  -
  -	    
  -	    if (left instanceof CastExpr) left = ((CastExpr)left).getExpr();
  -	    if (right instanceof CastExpr) right = ((CastExpr)right).getExpr();
  +            // Unwrap and set _step if appropriate
  +	    if (left instanceof CastExpr) {
  +                left = ((CastExpr) left).getExpr();
  +            }
  +	    if (left instanceof Step) {
  +                _step = (Step) left;
  +            }
   	    
  -	    try {
  -		if ((tleft == Type.String) && (!(left instanceof Step)))
  -		    _value = exp.getLeft();
  -		if (left instanceof VariableRefBase) 
  -		    _value = new CastExpr(left, Type.String);
  -		if (_value != null) return _value;
  -	    }
  -	    catch (TypeCheckError e) { }
  -
  -	    try {
  -		if ((tright == Type.String) && (!(right instanceof Step)))
  -		    _value = exp.getRight();
  -		if (right instanceof VariableRefBase)
  -		    _value = new CastExpr(right, Type.String);
  -		if (_value != null) return _value;
  -	    }
  -	    catch (TypeCheckError e) { }
  -
  +            // Unwrap and set _step if appropriate
  +	    if (right instanceof CastExpr) {
  +                right = ((CastExpr)right).getExpr();
  +            }
  +	    if (right instanceof Step) {
  +                _step = (Step)right;
  +            }
   	}
  -	return null;
  +	return _step;
       }
   
       /**
  -     * Utility method for optimisation. See isNodeValueTest()
  +     * Returns the value in an expression of the form 'step = value'. 
  +     * A value may be either a literal string or a variable whose 
  +     * type is string. Optimization if off if null is returned.
        */
  -    public Step getStep() {
  -	if (_step != null) return _step;
  -	if (_exp == null) return null;
  +    public Expression getCompareValue() {
  +        // Returned cached value if called more than once
  +	if (_value != null) {
  +            return _value;
  +        }
  +        
  +        // Nothing to to do if _exp is null
  +	if (_exp == null) {
  +            return null;
  +        }
   
  +        // Ignore if not an equality expression
   	if (_exp instanceof EqualityExpr) {
  -	    EqualityExpr exp = (EqualityExpr)_exp;
  +	    EqualityExpr exp = (EqualityExpr) _exp;
   	    Expression left = exp.getLeft();
   	    Expression right = exp.getRight();
  -
  -	    if (left instanceof CastExpr) left = ((CastExpr)left).getExpr();
  -	    if (left instanceof Step) _step = (Step)left;
  -	    
  -	    if (right instanceof CastExpr) right = ((CastExpr)right).getExpr();
  -	    if (right instanceof Step) _step = (Step)right;
  +            
  +            // Return if left is literal string
  +            if (left instanceof LiteralExpr) {
  +                _value = left;
  +                return _value;
  +            }
  +            // Return if left is a variable reference of type string
  +            if (left instanceof VariableRefBase &&
  +                left.getType() == Type.String) 
  +            {
  +                _value = left;
  +                return _value;
  +            }
  +            
  +            // Return if right is literal string
  +            if (right instanceof LiteralExpr) {
  +                _value = right;
  +                return _value;
  +            }
  +            // Return if left is a variable reference whose type is string
  +            if (right instanceof VariableRefBase &&
  +                right.getType() == Type.String) 
  +            {
  +                _value = right;
  +                return _value;
  +            }
   	}
  -	return _step;
  +	return null;
       }
  -
  + 
       /**
        * Translate a predicate expression. This translation pushes
        * two references on the stack: a reference to a newly created
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org