morten      01/10/09 05:08:09

  Modified:    java/src/org/apache/xalan/xsltc/compiler CastExpr.java
                        ForEach.java ParentLocationPath.java
                        RelativeLocationPath.java Step.java
                        StepPattern.java xpath.cup
  Log:
  Removed a few regessions from yesterday's fixes and cleaned up the Step
  class a bit.
  PR:           n/a
  Obtained from:        n/a
  Submitted by: [EMAIL PROTECTED]
  Reviewed by:  [EMAIL PROTECTED]
  
  Revision  Changes    Path
  1.6       +3 -2      
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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- CastExpr.java     2001/08/27 09:07:19     1.5
  +++ CastExpr.java     2001/10/09 12:08:09     1.6
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: CastExpr.java,v 1.5 2001/08/27 09:07:19 morten Exp $
  + * @(#)$Id: CastExpr.java,v 1.6 2001/10/09 12:08:09 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -65,6 +65,7 @@
   
   package org.apache.xalan.xsltc.compiler;
   
  +import org.apache.xalan.xsltc.dom.Axis;
   import org.apache.xalan.xsltc.compiler.util.Type;
   import org.apache.xalan.xsltc.compiler.util.ReferenceType;
   import de.fub.bytecode.generic.*;
  @@ -146,7 +147,7 @@
   
        if ((_left instanceof Step) && (_type == Type.Boolean)) {
            Step step = (Step)_left;
  -         if ((step.isSelf()) && (step.getNodeType() != -1)) 
  +         if ((step.getAxis() == Axis.SELF) && (step.getNodeType() != -1)) 
                _typeTest = true;
        }
        
  
  
  
  1.10      +1 -4      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ForEach.java
  
  Index: ForEach.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ForEach.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ForEach.java      2001/08/27 09:07:19     1.9
  +++ ForEach.java      2001/10/09 12:08:09     1.10
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: ForEach.java,v 1.9 2001/08/27 09:07:19 morten Exp $
  + * @(#)$Id: ForEach.java,v 1.10 2001/10/09 12:08:09 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -161,9 +161,6 @@
            }
            else {
                _select.translate(classGen, methodGen);
  -             if (_select instanceof Step) {
  -                 ((Step)_select).orderIterator(classGen, methodGen);
  -             }
            }
            if (!(_type instanceof ReferenceType)) {
                _select.startResetIterator(classGen, methodGen);
  
  
  
  1.10      +1 -9      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ParentLocationPath.java
  
  Index: ParentLocationPath.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/ParentLocationPath.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ParentLocationPath.java   2001/10/08 07:47:59     1.9
  +++ ParentLocationPath.java   2001/10/09 12:08:09     1.10
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: ParentLocationPath.java,v 1.9 2001/10/08 07:47:59 morten Exp $
  + * @(#)$Id: ParentLocationPath.java,v 1.10 2001/10/09 12:08:09 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -177,14 +177,6 @@
            return true;
   
        return false;
  -    }
  -
  -    public final boolean descendantAxis() {
  -     if (_path.descendantAxis())
  -         return true;
  -     if (_step instanceof RelativeLocationPath)
  -         return ((RelativeLocationPath)_step).descendantAxis();
  -     return(false);
       }
   
       public void translate(ClassGenerator classGen, MethodGenerator 
methodGen) {
  
  
  
  1.3       +1 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/RelativeLocationPath.java
  
  Index: RelativeLocationPath.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/RelativeLocationPath.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- RelativeLocationPath.java 2001/10/08 07:47:59     1.2
  +++ RelativeLocationPath.java 2001/10/09 12:08:09     1.3
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: RelativeLocationPath.java,v 1.2 2001/10/08 07:47:59 morten Exp $
  + * @(#)$Id: RelativeLocationPath.java,v 1.3 2001/10/09 12:08:09 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -66,5 +66,4 @@
   abstract class RelativeLocationPath extends Expression {
       public abstract int getAxis();
       public abstract void setAxis(int axis);
  -    public abstract boolean descendantAxis();
   }
  
  
  
  1.21      +48 -40    
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.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- Step.java 2001/10/08 09:50:28     1.20
  +++ Step.java 2001/10/09 12:08:09     1.21
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: Step.java,v 1.20 2001/10/08 09:50:28 morten Exp $
  + * @(#)$Id: Step.java,v 1.21 2001/10/09 12:08:09 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -77,14 +77,17 @@
       // This step's axis as defined in class Axis.
       private int _axis;
   
  -    // A vector of predicates (filters) defined on this step.
  -    private final Vector _predicates;        // may be null
  +    // A vector of predicates (filters) defined on this step - may be null
  +    private final Vector _predicates;
   
  +    // Some simple predicates can be handled by this class (and not by the
  +    // Predicate class) and will be removed from the above vector as they are
  +    // handled. We use this boolean to remember if we did have any 
predicates.
  +    private boolean _hadPredicates = false;
  +
       // Type of the node test.
       private int _nodeType;
   
  -    private boolean _hadPredicates = false;
  -
       /**
        * Constructor
        */
  @@ -94,7 +97,6 @@
        _predicates = predicates;
       }
   
  -
       /**
        * Set the parser for this element and all child predicates
        */
  @@ -109,7 +111,6 @@
            }
        }
       }
  -
       
       /**
        * Define the axis (defined in Axis class) for this step
  @@ -117,7 +118,6 @@
       public int getAxis() {
        return _axis;
       }
  -
        
       /**
        * Get the axis (defined in Axis class) for this step
  @@ -126,17 +126,6 @@
        _axis = axis;
       }
   
  -    public boolean descendantAxis() {
  -     if ((_axis == Axis.DESCENDANT) || (_axis == Axis.DESCENDANTORSELF))
  -         return(true);
  -     else
  -         return(false);
  -    }
  -
  -    public boolean isSelf() {
  -     return (_axis == Axis.SELF);
  -    }
  -     
       /**
        * Returns the node-type for this step
        */
  @@ -151,18 +140,12 @@
        return _predicates;
       }
   
  -
       /**
  -     *
  +     * Returns 'true' if this step has a parent pattern.
  +     * This method will return 'false' if this step occurs on its own under
  +     * an element like <xsl:for-each> or <xsl:apply-templates>.
        */
  -    protected void setParent(SyntaxTreeNode node) {
  -     _parent = node;
  -    }
  -
  -    /**
  -     * Returns 'true' if this step has a parent pattern
  -     */
  -    public boolean hasParent() {
  +    private boolean hasParentPattern() {
        SyntaxTreeNode parent = getParent();
        if ((parent instanceof ParentPattern) ||
            (parent instanceof ParentLocationPath) ||
  @@ -177,7 +160,7 @@
       /**
        * Returns 'true' if this step has any predicates
        */
  -    public boolean hasPredicates() {
  +    private boolean hasPredicates() {
        return _predicates != null && _predicates.size() > 0;
       }
   
  @@ -203,27 +186,34 @@
        * have type node-set.
        */
       public Type typeCheck(SymbolTable stable) throws TypeCheckError {
  +
  +     // Save this value for later - important for testing for special
  +     // combinations of steps and patterns than can be optimised
        _hadPredicates = hasPredicates();
   
  +     // Special case for '.' 
        if (isAbbreviatedDot()) {
  -         if (hasParent())
  +         if (hasParentPattern())
                _type = Type.NodeSet;
            else
                _type = Type.Node;
        }
  +     // Special case for '..'
        else if (isAbbreviatedDDot()) {
            _type = Type.NodeSet;
        }
        else {
            // Special case for '@attr' with no parent or predicates
            if ((_axis == Axis.ATTRIBUTE) && (_nodeType!=NodeTest.ATTRIBUTE) &&
  -             (!hasParent()) && (!hasPredicates())) {
  +             (!hasParentPattern()) && (!hasPredicates())) {
                _type = Type.Node;
            }
            else {
                _type = Type.NodeSet;
            }
        }
  +
  +     // Type check all predicates (expressions applied to the step)
        if (_predicates != null) {
            final int n = _predicates.size();
            for (int i = 0; i < n; i++) {
  @@ -231,6 +221,8 @@
                pred.typeCheck(stable);
            }
        }
  +
  +     // Return either Type.Node or Type.NodeSet
        return _type;
       }
   
  @@ -248,15 +240,24 @@
   
            // Do not reverse nodes if we have a parent step that will reverse
            // the nodes for us.
  -         if (hasParent()) return false;
  +         if (hasParentPattern()) return false;
            if (hasPredicates()) return false;
            if (_hadPredicates) return false;
            
            // Check if this step occured under an <xsl:apply-templates> element
            SyntaxTreeNode parent = this;
            do {
  +             // Get the next ancestor element and check its type
                parent = parent.getParent();
  +
  +             // Order node set if descendant of these elements:
  +             if (parent instanceof ApplyImports) return true;
                if (parent instanceof ApplyTemplates) return true;
  +             if (parent instanceof ForEach) return true;
  +
  +             // No not order node set if descendant of these elements:
  +             if (parent instanceof ValueOf) return false;
  +
            } while (parent != null);
        }
        return false;
  @@ -279,7 +280,7 @@
        else {
            // If it is an attribute but not '@*' or '@attr' with a parent
            if ((_axis == Axis.ATTRIBUTE) &&
  -             (_nodeType != NodeTest.ATTRIBUTE) && (!hasParent())) {
  +             (_nodeType != NodeTest.ATTRIBUTE) && (!hasParentPattern())) {
                int node = cpg.addInterfaceMethodref(DOM_INTF,
                                                     "getAttributeNode",
                                                     "(II)I");
  @@ -305,14 +306,16 @@
            // Special case for '.'
            if (isAbbreviatedDot()) {
                if (_type == Type.Node) {
  +                 // Put context node on stack if using Type.Node
                    il.append(methodGen.loadContextNode());
                }
                else {
  +                 // Wrap the context node in a singleton iterator if not.
  +                 int init = cpg.addMethodref(SINGLETON_ITERATOR,
  +                                             "<init>", "("+NODE_SIG+")V");
                    il.append(new NEW(cpg.addClass(SINGLETON_ITERATOR)));
                    il.append(DUP);
                    il.append(methodGen.loadContextNode());
  -                 final int init = cpg.addMethodref(SINGLETON_ITERATOR, 
"<init>",
  -                                                   "(" + NODE_SIG +")V");
                    il.append(new INVOKESPECIAL(init));
                }
                return;
  @@ -322,7 +325,9 @@
            SyntaxTreeNode parent = getParent();
            if ((parent instanceof ParentLocationPath) &&
                (parent.getParent() instanceof ParentLocationPath)) {
  -             if (_nodeType == NodeTest.ELEMENT) _nodeType = NodeTest.ANODE;
  +             if ((_nodeType == NodeTest.ELEMENT) && (!_hadPredicates)) {
  +                 _nodeType = NodeTest.ANODE;
  +             }
            }
   
            // "ELEMENT" or "*" or "@*" or ".." or "@attr" with a parent.
  @@ -376,7 +381,7 @@
                il.append(new PUSH(cpg, _axis));
                il.append(new PUSH(cpg, _nodeType));
                il.append(new INVOKEINTERFACE(ty, 3));
  -             //orderIterator(classGen, methodGen);
  +             orderIterator(classGen, methodGen);
                break;
            }
   
  @@ -505,11 +510,14 @@
       }
   
   
  -    /*
  -     * Order nodes for iterators with reverse axis
  +    /**
  +     * This method tests if this step needs to have its axis reversed,
  +     * and wraps its iterator inside a ReverseIterator to return the node-set
  +     * in document order.
        */
       public void orderIterator(ClassGenerator classGen,
                              MethodGenerator methodGen) {
  +     // First test if nodes are in reverse document order
        if (!reverseNodeSet()) return;
   
        final ConstantPoolGen cpg = classGen.getConstantPool();
  
  
  
  1.7       +2 -2      
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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StepPattern.java  2001/09/19 11:50:31     1.6
  +++ StepPattern.java  2001/10/09 12:08:09     1.7
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: StepPattern.java,v 1.6 2001/09/19 11:50:31 morten Exp $
  + * @(#)$Id: StepPattern.java,v 1.7 2001/10/09 12:08:09 morten Exp $
    *
    * The Apache Software License, Version 1.1
    *
  @@ -117,7 +117,7 @@
        return _isEpsilon && hasPredicates() == false;
       }
       
  -    public boolean hasPredicates() {
  +    private boolean hasPredicates() {
        return _predicates != null && _predicates.size() > 0;
       }
   
  
  
  
  1.21      +2 -2      
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/xpath.cup
  
  Index: xpath.cup
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/xpath.cup,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- xpath.cup 2001/10/08 13:27:38     1.20
  +++ xpath.cup 2001/10/09 12:08:09     1.21
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: xpath.cup,v 1.20 2001/10/08 13:27:38 morten Exp $
  + * @(#)$Id: xpath.cup,v 1.21 2001/10/09 12:08:09 morten Exp $
    *
    * Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.
    * 
  @@ -459,8 +459,8 @@
              if ((axis == Axis.CHILD) && (type != NodeTest.ATTRIBUTE)) {
                  // Compress './/child:E' into 'descendant::E' - if possible
                  if (predicates == null) {
  +                   right.setAxis(Axis.DESCENDANT);
                      if (rlp instanceof Step && 
((Step)rlp).isAbbreviatedDot()) {
  -                       right.setAxis(Axis.DESCENDANT);
                       RESULT = right;
                      }
                      else {
  
  
  

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

Reply via email to