santiagopg    2002/09/17 07:20:59

  Modified:    java/src/org/apache/xalan/xsltc/compiler xpath.cup
  Log:
  Additional optimizations in expansion of '//'.
  
  Revision  Changes    Path
  1.43      +45 -10    
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.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- xpath.cup 16 Sep 2002 19:40:28 -0000      1.42
  +++ xpath.cup 17 Sep 2002 14:20:59 -0000      1.43
  @@ -70,6 +70,7 @@
   import java.io.StringReader;
   import java_cup.runtime.*;
   
  +import org.apache.xalan.xsltc.DOM;
   import org.apache.xalan.xsltc.dom.Axis;
   import org.apache.xalan.xsltc.runtime.Operators;
   import org.apache.xalan.xsltc.compiler.util.ErrorMsg;
  @@ -229,6 +230,16 @@
            return rlp;
        }
       }
  +
  +    /**
  +     * Returns true if the axis applies to elements only. The axes
  +     * child, attribute, namespace, descendant result in non-empty
  +     * nodesets only if the context node is of type element.
  +     */
  +    public boolean isElementAxis(int axis) {
  +     return (axis == Axis.CHILD || axis == Axis.ATTRIBUTE ||
  +             axis == Axis.NAMESPACE || axis == Axis.DESCENDANT);
  +    }
   :}
   
   terminal SLASH, DOT, LBRACK, RBRACK, VBAR, LPAREN, RPAREN, STAR, COMMA;
  @@ -513,12 +524,22 @@
   
           | FilterExpr:fexp DSLASH RelativeLocationPath:rlp
           {:
  -           // Expand '//' into '/descendant-or-self::node()/'
  -           Step step = new Step(Axis.DESCENDANTORSELF, NodeTest.ANODE, null);
  +           // 
  +        // Expand '//' into '/descendant-or-self::node()/' or
  +        // into /descendant-or-self::*/
  +        //
  +        int nodeType = DOM.NO_TYPE;
  +        if (rlp instanceof Step && 
  +            parser.isElementAxis(((Step) rlp).getAxis())) 
  +        {
  +            nodeType = DOM.ELEMENT;
  +        }
  +           final Step step = new Step(Axis.DESCENDANTORSELF, nodeType, null);
              FilterParentPath fpp = new FilterParentPath(fexp, step);
              fpp = new FilterParentPath(fpp, rlp);
  -           if (!(fexp instanceof KeyCall))
  +           if (fexp instanceof KeyCall == false) {
                  fpp.setDescendantAxis();
  +        }
              RESULT = fpp;
           :};
   
  @@ -580,13 +601,15 @@
                  else {
                      // Expand './/step' -> 'descendant-or-self::*/step'
                      if (rlp instanceof Step && 
((Step)rlp).isAbbreviatedDot()) {
  -                       Step left = new Step(Axis.DESCENDANTORSELF, -1, null);
  +                       Step left = new Step(Axis.DESCENDANTORSELF, 
  +                         DOM.ELEMENT, null);
                          RESULT = new ParentLocationPath(left, right);
                      }
                      else {
                          // Expand 'rlp//step' -> 
'rlp/descendant-or-self::*/step'
                          RelativeLocationPath left = (RelativeLocationPath)rlp;
  -                       Step mid = new Step(Axis.DESCENDANTORSELF, -1, null);
  +                       Step mid = new Step(Axis.DESCENDANTORSELF, 
  +                         DOM.ELEMENT, null);
                          ParentLocationPath ppl = new ParentLocationPath(mid, 
right);
                          RESULT = new ParentLocationPath(left, ppl);
                      }
  @@ -595,14 +618,16 @@
              else if ((axis == Axis.ATTRIBUTE) || (type == 
NodeTest.ATTRIBUTE)) {
                  // Expand 'rlp//step' -> 'rlp/descendant-or-self::*/step'
                  RelativeLocationPath left = (RelativeLocationPath)rlp;
  -               Step middle = new Step(Axis.DESCENDANTORSELF, -1, null);
  +               Step middle = new Step(Axis.DESCENDANTORSELF, 
  +                 DOM.ELEMENT, null);
                  ParentLocationPath ppl = new ParentLocationPath(middle, 
right);
                  RESULT = new ParentLocationPath(left, ppl);
           }
           else {
               // Expand 'rlp//step' -> 'rlp/descendant-or-self::node()/step'
                  RelativeLocationPath left = (RelativeLocationPath)rlp;
  -            Step middle = new Step(Axis.DESCENDANTORSELF, -1, null); 
  +            Step middle = new Step(Axis.DESCENDANTORSELF, 
  +                 DOM.NO_TYPE, null); 
                  ParentLocationPath ppl = new ParentLocationPath(middle, 
right);
               RESULT = new ParentLocationPath(left, ppl);
           }
  @@ -611,8 +636,18 @@
   
   AbbreviatedAbsoluteLocationPath ::= DSLASH RelativeLocationPath:rlp
           {:
  -         final Step step = new Step(Axis.DESCENDANTORSELF, -1, null);
  -         RESULT = new AbsoluteLocationPath(parser.insertStep(step, 
  +           // 
  +        // Expand '//' into '/descendant-or-self::node()/' or
  +        // into /descendant-or-self::*/
  +        //
  +        int nodeType = DOM.NO_TYPE;
  +        if (rlp instanceof Step && 
  +            parser.isElementAxis(((Step) rlp).getAxis())) 
  +        {
  +            nodeType = DOM.ELEMENT;
  +        }
  +        final Step step = new Step(Axis.DESCENDANTORSELF, nodeType, null);
  +        RESULT = new AbsoluteLocationPath(parser.insertStep(step, 
                                (RelativeLocationPath) rlp));
        :};
   
  
  
  

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

Reply via email to