morten      01/11/06 05:42:05

  Modified:    java/src/org/apache/xalan/xsltc/compiler BinOpExpr.java
                        CastExpr.java EqualityExpr.java Expression.java
                        LastCall.java LogicalExpr.java PositionCall.java
                        Predicate.java RelationalExpr.java Step.java
                        StepPattern.java UnaryOpExpr.java
  Log:
  Fix for compound predicates used in patterns.
  Obtained from:        n/a
  Submitted by: [EMAIL PROTECTED]
  Reviewed by:  [EMAIL PROTECTED]
  
  Revision  Changes    Path
  1.6       +11 -1     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/BinOpExpr.java
  
  Index: BinOpExpr.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/BinOpExpr.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BinOpExpr.java    2001/10/30 08:42:55     1.5
  +++ BinOpExpr.java    2001/11/06 13:42:04     1.6
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: BinOpExpr.java,v 1.5 2001/10/30 08:42:55 morten Exp $
  + * @(#)$Id: BinOpExpr.java,v 1.6 2001/11/06 13:42:04 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -85,6 +85,16 @@
        _op = op;
        (_left = left).setParent(this);
        (_right = right).setParent(this);
  +    }
  +
  +    /**
  +     * Returns true if this expressions contains a call to position(). This 
is
  +     * needed for context changes in node steps containing multiple 
predicates.
  +     */
  +    public boolean hasPositionCall() {
  +     if (_left.hasPositionCall()) return true;
  +     if (_right.hasPositionCall()) return true;
  +     return false;
       }
   
       public void setParser(Parser parser) {
  
  
  
  1.7       +9 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CastExpr.java
  
  Index: CastExpr.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/CastExpr.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- CastExpr.java     2001/10/09 12:08:09     1.6
  +++ CastExpr.java     2001/11/06 13:42:04     1.7
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: CastExpr.java,v 1.6 2001/10/09 12:08:09 morten Exp $
  + * @(#)$Id: CastExpr.java,v 1.7 2001/11/06 13:42:04 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -160,6 +160,14 @@
                
       public Expression getExpr() {
        return _left;
  +    }
  +
  +    /**
  +     * Returns true if this expressions contains a call to position(). This 
is
  +     * needed for context changes in node steps containing multiple 
predicates.
  +     */
  +    public boolean hasPositionCall() {
  +     return(_left.hasPositionCall());
       }
   
       public String toString() {
  
  
  
  1.6       +11 -1     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/EqualityExpr.java
  
  Index: EqualityExpr.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/EqualityExpr.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EqualityExpr.java 2001/07/30 13:35:40     1.5
  +++ EqualityExpr.java 2001/11/06 13:42:04     1.6
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: EqualityExpr.java,v 1.5 2001/07/30 13:35:40 morten Exp $
  + * @(#)$Id: EqualityExpr.java,v 1.6 2001/11/06 13:42:04 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -105,6 +105,16 @@
            return false;
        else
            return true;
  +    }
  +
  +    /**
  +     * Returns true if this expressions contains a call to position(). This 
is
  +     * needed for context changes in node steps containing multiple 
predicates.
  +     */
  +    public boolean hasPositionCall() {
  +     if (_left.hasPositionCall()) return true;
  +     if (_right.hasPositionCall()) return true;
  +     return false;
       }
   
       private void swapArguments() {
  
  
  
  1.8       +5 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Expression.java
  
  Index: Expression.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Expression.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Expression.java   2001/10/30 08:42:55     1.7
  +++ Expression.java   2001/11/06 13:42:04     1.8
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Expression.java,v 1.7 2001/10/30 08:42:55 morten Exp $
  + * @(#)$Id: Expression.java,v 1.8 2001/11/06 13:42:04 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -101,6 +101,10 @@
       }
   
       public abstract String toString();
  +
  +    public boolean hasPositionCall() {
  +     return true;
  +    }
                
       /**
        * Type check all the children of this node.
  
  
  
  1.5       +5 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LastCall.java
  
  Index: LastCall.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LastCall.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LastCall.java     2001/09/21 09:39:38     1.4
  +++ LastCall.java     2001/11/06 13:42:04     1.5
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: LastCall.java,v 1.4 2001/09/21 09:39:38 morten Exp $
  + * @(#)$Id: LastCall.java,v 1.5 2001/11/06 13:42:04 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -80,6 +80,10 @@
       public LastCall(QName fname, int type) {
        this(fname);
        _type = type;
  +    }
  +
  +    public boolean hasPositionCall() {
  +     return true;
       }
   
       public void translate(ClassGenerator classGen, MethodGenerator 
methodGen) {
  
  
  
  1.8       +11 -1     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LogicalExpr.java
  
  Index: LogicalExpr.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/LogicalExpr.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- LogicalExpr.java  2001/10/22 09:33:38     1.7
  +++ LogicalExpr.java  2001/11/06 13:42:04     1.8
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: LogicalExpr.java,v 1.7 2001/10/22 09:33:38 morten Exp $
  + * @(#)$Id: LogicalExpr.java,v 1.8 2001/11/06 13:42:04 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -89,6 +89,16 @@
        _op = op;
        (_left = left).setParent(this);
        (_right = right).setParent(this);
  +    }
  +
  +    /**
  +     * Returns true if this expressions contains a call to position(). This 
is
  +     * needed for context changes in node steps containing multiple 
predicates.
  +     */
  +    public boolean hasPositionCall() {
  +     if (_left.hasPositionCall()) return true;
  +     if (_right.hasPositionCall()) return true;
  +     return false;
       }
   
       /**
  
  
  
  1.7       +5 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/PositionCall.java
  
  Index: PositionCall.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/PositionCall.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PositionCall.java 2001/11/05 15:47:34     1.6
  +++ PositionCall.java 2001/11/06 13:42:04     1.7
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: PositionCall.java,v 1.6 2001/11/05 15:47:34 morten Exp $
  + * @(#)$Id: PositionCall.java,v 1.7 2001/11/06 13:42:04 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -80,6 +80,10 @@
       public PositionCall(QName fname, int type) {
        this(fname);
        _type = type;
  +    }
  +
  +    public boolean hasPositionCall() {
  +     return true;
       }
   
       public void translate(ClassGenerator classGen, MethodGenerator 
methodGen) {
  
  
  
  1.16      +40 -12    
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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Predicate.java    2001/11/01 09:27:24     1.15
  +++ Predicate.java    2001/11/06 13:42:04     1.16
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Predicate.java,v 1.15 2001/11/01 09:27:24 morten Exp $
  + * @(#)$Id: Predicate.java,v 1.16 2001/11/06 13:42:04 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -78,6 +78,7 @@
       private String  _className;     // Name of filter to generate
       private boolean _nthPositionFilter = false;
       private boolean _nthDescendant = false;
  +    private boolean _canOptimize = true;
       private int     _ptype = -1;
   
       public Predicate(Expression exp) {
  @@ -96,7 +97,11 @@
       public boolean isNthPositionFilter() {
        return _nthPositionFilter;
       }
  -    
  +
  +    public void dontOptimize() {
  +     _canOptimize = false;
  +    }
  +
       protected final boolean isClosureBoundary() {
        return true;
       }
  @@ -177,10 +182,12 @@
                _exp = new CastExpr(_exp, Type.Int);
            }
   
  +         SyntaxTreeNode parent = getParent();
  +
            // Expand [last()] into [position() = last()]
            if ((_exp instanceof LastCall) ||
  -             (getParent() instanceof Pattern) ||
  -             (getParent() instanceof FilterExpr)) {
  +             (parent instanceof Pattern) ||
  +             (parent instanceof FilterExpr)) {
   
                final QName position = getParser().getQName("position");
                final PositionCall positionCall = new PositionCall(position);
  @@ -191,12 +198,14 @@
                if (_exp.typeCheck(stable) != Type.Boolean) {
                    _exp = new CastExpr(_exp, Type.Boolean);
                }
  -             _nthPositionFilter = false;
  +             if (parent instanceof Pattern)
  +                 _nthPositionFilter = true;
  +             else
  +                 _nthPositionFilter = false;
                return _type = Type.Boolean;
            }
            // Use NthPositionIterator to handle [position()] or [a]
            else {
  -             SyntaxTreeNode parent = getParent();
                if ((parent != null) && (parent instanceof Step)) {
                    parent = parent.getParent();
                    if ((parent != null) &&
  @@ -210,8 +219,12 @@
                return _type = Type.NodeSet;
            }
        }
  +     else if (texp instanceof BooleanType) {
  +         if (_exp.hasPositionCall())
  +             _nthPositionFilter = true;
  +     }
        // All other types will be handled as boolean values
  -     else if (texp instanceof BooleanType == false) {
  +     else {
            _exp = new CastExpr(_exp, Type.Boolean);
        }
        _nthPositionFilter = false;
  @@ -306,6 +319,7 @@
        * very common in many stylesheets
        */
       public boolean isNodeValueTest() {
  +     if (!_canOptimize) return false;
        if ((getStep() != null) && (getCompareValue() != null))
            return true;
        else
  @@ -396,11 +410,25 @@
            il.append(new PUSH(cpg, ((EqualityExpr)_exp).getOp()));
        }
        else {
  -         compileFilter(classGen, methodGen);
  -         il.append(new NEW(cpg.addClass(_className)));
  -         il.append(DUP);
  -         il.append(new INVOKESPECIAL(cpg.addMethodref(_className,
  -                                                      "<init>", "()V")));
  +         translateFilter(classGen, methodGen);
        }
  +    }
  +
  +    /**
  +     * Translate a predicate expression. This translation pushes
  +     * two references on the stack: a reference to a newly created
  +     * filter object and a reference to the predicate's closure.
  +     */
  +    public void translateFilter(ClassGenerator classGen,
  +                             MethodGenerator methodGen) {
  +
  +     final ConstantPoolGen cpg = classGen.getConstantPool();
  +     final InstructionList il = methodGen.getInstructionList();
  +
  +     compileFilter(classGen, methodGen);
  +     il.append(new NEW(cpg.addClass(_className)));
  +     il.append(DUP);
  +     il.append(new INVOKESPECIAL(cpg.addMethodref(_className,
  +                                                  "<init>", "()V")));
       }
   }
  
  
  
  1.11      +12 -2     
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/RelationalExpr.java
  
  Index: RelationalExpr.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/RelationalExpr.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- RelationalExpr.java       2001/10/30 08:42:55     1.10
  +++ RelationalExpr.java       2001/11/06 13:42:04     1.11
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: RelationalExpr.java,v 1.10 2001/10/30 08:42:55 morten Exp $
  + * @(#)$Id: RelationalExpr.java,v 1.11 2001/11/06 13:42:04 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -84,7 +84,17 @@
        _left.setParser(parser);
        _right.setParser(parser);
       }
  -    
  +
  +    /**
  +     * Returns true if this expressions contains a call to position(). This 
is
  +     * needed for context changes in node steps containing multiple 
predicates.
  +     */
  +    public boolean hasPositionCall() {
  +     if (_left.hasPositionCall()) return true;
  +     if (_right.hasPositionCall()) return true;
  +     return false;
  +    }
  +
       public boolean hasReferenceArgs() {
        return _left.getType() instanceof ReferenceType ||
            _right.getType() instanceof ReferenceType;
  
  
  
  1.27      +3 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Step.java
  
  Index: Step.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Step.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- Step.java 2001/11/05 18:47:51     1.26
  +++ Step.java 2001/11/06 13:42:04     1.27
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Step.java,v 1.26 2001/11/05 18:47:51 morten Exp $
  + * @(#)$Id: Step.java,v 1.27 2001/11/06 13:42:04 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -489,7 +489,7 @@
                il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
                il.append(DUP);
                translatePredicates(classGen, methodGen); // recursive call
  -             predicate.translate(classGen, methodGen);
  +             predicate.translateFilter(classGen, methodGen);
                
                il.append(methodGen.loadCurrentNode());
                il.append(classGen.loadTranslet());
  @@ -504,6 +504,7 @@
                // See CurrentNodeListIterator's constructor(s) for details.
                SyntaxTreeNode parent = getParent();
                while (!(parent instanceof Template)) {
  +                 if (parent == null) break;
                    if (parent instanceof ApplyTemplates) {
                        idx = cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR,
                                               "forceNaturalOrder",
  
  
  
  1.11      +7 -5      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/StepPattern.java
  
  Index: StepPattern.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/StepPattern.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- StepPattern.java  2001/11/05 15:47:34     1.10
  +++ StepPattern.java  2001/11/06 13:42:04     1.11
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: StepPattern.java,v 1.10 2001/11/05 15:47:34 morten Exp $
  + * @(#)$Id: StepPattern.java,v 1.11 2001/11/06 13:42:04 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -158,9 +158,9 @@
        boolean noContext = true;
        final int n = _predicates.size();
        for (int i = 0; i < n && noContext; i++) {
  -         final Predicate exp = (Predicate)_predicates.elementAt(i);
  -         if (exp.isNthPositionFilter())
  -             noContext = false;
  +         final Predicate pred = (Predicate)_predicates.elementAt(i);
  +         final Expression exp = pred.getExpr();
  +         if (exp.hasPositionCall()) noContext = false;
        }
   
        if (noContext) {
  @@ -195,6 +195,9 @@
                _step.typeCheck(stable);
            }
            else if (_contextCase == GENERAL_CONTEXT) {
  +             final int len = _predicates.size();
  +             for (int i = 0; i < len; i++)
  +                 ((Predicate)_predicates.elementAt(i)).dontOptimize();
                _step = new Step(_axis, _nodeType, _predicates);
                _step.setParser(getParser());
                _step.typeCheck(stable);
  @@ -336,7 +339,6 @@
        il.append(methodGen.storeIterator());
        il.append(new ILOAD(match.getIndex()));
        il.append(methodGen.storeCurrentNode());
  -
   
        // Translate the expression of the predicate 
        Predicate pred = (Predicate) _predicates.elementAt(0);
  
  
  
  1.3       +9 -1      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnaryOpExpr.java
  
  Index: UnaryOpExpr.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/UnaryOpExpr.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UnaryOpExpr.java  2001/06/06 10:45:36     1.2
  +++ UnaryOpExpr.java  2001/11/06 13:42:04     1.3
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: UnaryOpExpr.java,v 1.2 2001/06/06 10:45:36 morten Exp $
  + * @(#)$Id: UnaryOpExpr.java,v 1.3 2001/11/06 13:42:04 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -72,6 +72,14 @@
        
       public UnaryOpExpr(Expression left) {
        (_left = left).setParent(this);
  +    }
  +
  +    /**
  +     * Returns true if this expressions contains a call to position(). This 
is
  +     * needed for context changes in node steps containing multiple 
predicates.
  +     */
  +    public boolean hasPositionCall() {
  +     return(_left.hasPositionCall());
       }
   
       public void setParser(Parser parser) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to