xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mor...@apache.org
Subject cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler xpath.cup
Date Mon, 08 Oct 2001 13:27:38 GMT
morten      01/10/08 06:27:38

  Modified:    java/src/org/apache/xalan/xsltc/compiler xpath.cup
  Log:
  A radical fix for how the abbreviated descendant iterator is handled by
  the XPath parser. The previousl implementation could misplace/ignore
  prediates and did not properly handle .//@* style expressions.
  PR:		bugzilla 3314
  Obtained from:	n/a
  Submitted by:	morten@xml.apache.org
  Reviewed by:	morten@xml.apache.org
  
  Revision  Changes    Path
  1.20      +43 -27    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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- xpath.cup	2001/10/08 09:50:28	1.19
  +++ xpath.cup	2001/10/08 13:27:38	1.20
  @@ -1,5 +1,5 @@
   /*
  - * @(#)$Id: xpath.cup,v 1.19 2001/10/08 09:50:28 morten Exp $
  + * @(#)$Id: xpath.cup,v 1.20 2001/10/08 13:27:38 morten Exp $
    *
    * Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.
    * 
  @@ -451,36 +451,52 @@
   
   AbbreviatedRelativeLocationPath ::= RelativeLocationPath:rlp DSLASH Step:step
           {: 
  -	   Step nodeStep;
  -	   final Step temp = (Step)step;
  -           final int  axis = temp.getAxis();
  -           // THIS CODE IS NOT GOOD - PREDICATES ARE MISPLACED!!!!!
  -	   if ((axis == Axis.CHILD) || (axis == Axis.ATTRIBUTE)) {
  -	       // Expand 'rlp//child::E' into 'rlp/descendant::E'
  -	       nodeStep = new Step(Axis.DESCENDANT, 
  -				   temp.getNodeType(), 
  -				   temp.getPredicates());
  -
  -               if (rlp instanceof Step && ((Step) rlp).isAbbreviatedDot()) {
  -                  RESULT = nodeStep;       // Remove './/' from the beginning
  +	   final Step right  = (Step)step;
  +           final int  axis   = right.getAxis();
  +           final int  type   = right.getNodeType();
  +           final Vector predicates = right.getPredicates();
  +
  +           if ((axis == Axis.CHILD) && (type != NodeTest.ATTRIBUTE)) {
  +               // Compress './/child:E' into 'descendant::E' - if possible
  +               if (predicates == null) {
  +                   if (rlp instanceof Step && ((Step)rlp).isAbbreviatedDot()) {
  +                       right.setAxis(Axis.DESCENDANT);
  +	               RESULT = right;
  +                   }
  +                   else {
  +                       // Expand 'rlp//child::E' into 'rlp/descendant::E'
  +                       RelativeLocationPath left = (RelativeLocationPath)rlp;
  +	               RESULT = new ParentLocationPath(left, right);
  +                   }
                  }
  -	       else {
  -	          RESULT = new ParentLocationPath((RelativeLocationPath) rlp,
  -                                                  nodeStep);
  +               else {
  +                   // Expand './/step' -> 'descendant-or-self::*/step'
  +                   if (rlp instanceof Step && ((Step)rlp).isAbbreviatedDot()) {
  +                       Step left = new Step(Axis.DESCENDANTORSELF, -1, 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);
  +                       ParentLocationPath ppl = new ParentLocationPath(mid, right);
  +                       RESULT = new ParentLocationPath(left, ppl);
  +                   }
                  }
  +           }
  +           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);
  +               ParentLocationPath ppl = new ParentLocationPath(middle, right);
  +               RESULT = new ParentLocationPath(left, ppl);
   	   }
   	   else {
  -	       // Expand 'rlp//step' into 'rlp/descendant-or-self::node()/step'
  -	       nodeStep = new Step(Axis.DESCENDANTORSELF, 
  -					NodeTest.ANODE, null); 
  -               /*
  -	       RESULT = new ParentLocationPath(
  -			    new ParentLocationPath((RelativeLocationPath) rlp, 
  -						   nodeStep), step);
  -               */
  -	       RESULT = new ParentLocationPath((RelativeLocationPath)rlp,
  -			    new ParentLocationPath(nodeStep, step));
  -
  +	       // Expand 'rlp//step' -> 'rlp/descendant-or-self::node()/step'
  +               RelativeLocationPath left = (RelativeLocationPath)rlp;
  +	       Step middle = new Step(Axis.DESCENDANTORSELF, -1, null); 
  +               ParentLocationPath ppl = new ParentLocationPath(middle, right);
  +	       RESULT = new ParentLocationPath(left, ppl);
   	   }
           :};
   
  
  
  

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


Mime
View raw message