You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mo...@apache.org on 2001/11/05 19:47:51 UTC
cvs commit: xml-xalan/java/src/org/apache/xalan/xsltc/dom CurrentNodeListIterator.java DOMImpl.java
morten 01/11/05 10:47:51
Modified: java/src/org/apache/xalan/xsltc/compiler Step.java
java/src/org/apache/xalan/xsltc/dom
CurrentNodeListIterator.java DOMImpl.java
Log:
Fixed the last() function for the typed and untyped ancestor iterators.
I also updated our node list iterator (used to implement some predicates)
to handle the last() function properly for reverse-order axes.
PR: bugzilla 4602
Obtained from: n/a
Submitted by: morten@xml.apache.org
Reviewed by: morten@xml.apache.org
Revision Changes Path
1.26 +16 -21 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.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- Step.java 2001/11/01 13:05:49 1.25
+++ Step.java 2001/11/05 18:47:51 1.26
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Step.java,v 1.25 2001/11/01 13:05:49 morten Exp $
+ * @(#)$Id: Step.java,v 1.26 2001/11/05 18:47:51 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -467,26 +467,6 @@
}
// Handle 'elem[n]' expression
else if (predicate.isNthPositionFilter()) {
- // Special case for typed descendant / decendant-or-self axis
- /* Crap piece of code right here, I added it, and I am
- taking it away as well. Very wrong ideed. Morten
- if (((_axis == Axis.DESCENDANT) ||
- (_axis == Axis.DESCENDANTORSELF)) &&
- (_nodeType > DOM.ATTRIBUTE)) {
- il.append(methodGen.loadDOM());
- il.append(new PUSH(cpg, _nodeType));
- predicate.translate(classGen, methodGen);
- if (_axis == Axis.DESCENDANT)
- il.append(new ICONST(0));
- else
- il.append(new ICONST(1));
- idx = cpg.addInterfaceMethodref(DOM_INTF,
- "getNthDescendant",
- "(IIZ)"+NODE_ITERATOR_SIG);
- il.append(new INVOKEINTERFACE(idx, 4));
- }
- else {
- */
idx = cpg.addMethodref(NTH_ITERATOR_CLASS,
"<init>",
"("+NODE_ITERATOR_SIG+"I)V");
@@ -518,6 +498,21 @@
il.append(new CHECKCAST(cpg.addClass(className)));
}
il.append(new INVOKESPECIAL(idx));
+
+ // Determine if the node set should be generated using the
+ // natural order of the node set or document order.
+ // See CurrentNodeListIterator's constructor(s) for details.
+ SyntaxTreeNode parent = getParent();
+ while (!(parent instanceof Template)) {
+ if (parent instanceof ApplyTemplates) {
+ idx = cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR,
+ "forceNaturalOrder",
+ "()"+NODE_ITERATOR_SIG);
+ il.append(new INVOKEVIRTUAL(idx));
+ break;
+ }
+ parent = parent.getParent();
+ }
}
}
}
1.3 +8 -3 xml-xalan/java/src/org/apache/xalan/xsltc/dom/CurrentNodeListIterator.java
Index: CurrentNodeListIterator.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/CurrentNodeListIterator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- CurrentNodeListIterator.java 2001/10/30 15:49:31 1.2
+++ CurrentNodeListIterator.java 2001/11/05 18:47:51 1.3
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: CurrentNodeListIterator.java,v 1.2 2001/10/30 15:49:31 morten Exp $
+ * @(#)$Id: CurrentNodeListIterator.java,v 1.3 2001/11/05 18:47:51 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -71,7 +71,7 @@
public final class CurrentNodeListIterator extends NodeIteratorBase {
private NodeIterator _source;
- private final boolean _docOrder;
+ private boolean _docOrder;
private final CurrentNodeListFilter _filter;
private IntegerArray _nodes = new IntegerArray();
@@ -98,7 +98,12 @@
_docOrder = docOrder;
_currentNode = currentNode;
}
-
+
+ public NodeIterator forceNaturalOrder() {
+ _docOrder = true;
+ return this;
+ }
+
public boolean isReverse() {
return !_docOrder;
}
1.59 +17 -15 xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java
Index: DOMImpl.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMImpl.java,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- DOMImpl.java 2001/11/05 15:47:35 1.58
+++ DOMImpl.java 2001/11/05 18:47:51 1.59
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: DOMImpl.java,v 1.58 2001/11/05 15:47:35 morten Exp $
+ * @(#)$Id: DOMImpl.java,v 1.59 2001/11/05 18:47:51 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -1319,13 +1319,19 @@
private class AncestorIterator extends NodeIteratorBase {
protected int _index;
+ protected int _last = -1;
public final boolean isReverse() {
return true;
}
public int getLast() {
- return(ROOT);
+ if (_last > -1) return _last;
+ int count = 1;
+ int node = _startNode;
+ while ((node = _parent[node]) != ROOT) count++;
+ _last = count;
+ return(count);
}
public NodeIterator cloneIterator() {
@@ -1344,6 +1350,7 @@
public NodeIterator setStartNode(int node) {
if (_isRestartable) {
+ _last = -1;
if (node >= _firstAttributeNode)
_startNode = node = _parent[node];
else if (_includeSelf)
@@ -1404,19 +1411,14 @@
}
public int getLast() {
- int last = _index;
- int curr = _index;
-
- while (curr >= 0) {
- if (curr == 0)
- curr = -1;
- else {
- curr = _parent[curr];
- if (_type[curr] == _nodeType)
- last = curr;
- }
- }
- return(last);
+ if (_last > -1) return _last;
+ int count = 1;
+ int node = _startNode;
+ do {
+ if (_type[node] == _nodeType) count++;
+ } while ((node = _parent[node]) != ROOT);
+ _last = count;
+ return(count);
}
} // end of TypedAncestorIterator
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org