Return-Path: Delivered-To: apmail-xml-xalan-cvs-archive@xml.apache.org Received: (qmail 40336 invoked by uid 500); 8 Oct 2001 13:31:24 -0000 Mailing-List: contact xalan-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: Delivered-To: mailing list xalan-cvs@xml.apache.org Received: (qmail 40306 invoked from network); 8 Oct 2001 13:31:24 -0000 Date: 8 Oct 2001 13:27:38 -0000 Message-ID: <20011008132738.42063.qmail@icarus.apache.org> From: morten@apache.org To: xml-xalan-cvs@apache.org Subject: cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/compiler xpath.cup X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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