morten 01/09/25 08:57:22
Modified: java/src/org/apache/xalan/xsltc/compiler Param.java
Step.java Variable.java VariableBase.java xpath.cup
java/src/org/apache/xalan/xsltc/dom DOMAdapter.java
DOMImpl.java
java/src/org/apache/xalan/xsltc/runtime BasisLibrary.java
Log:
Fix for nth-position typed descendant iterators (previously not fully
implemented).
PR: bugzilla 3468
Obtained from: n/a
Submitted by: [EMAIL PROTECTED]
Reviewed by: [EMAIL PROTECTED]
Revision Changes Path
1.15 +9 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Param.java
Index: Param.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Param.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Param.java 2001/09/25 12:59:56 1.14
+++ Param.java 2001/09/25 15:57:22 1.15
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Param.java,v 1.14 2001/09/25 12:59:56 morten Exp $
+ * @(#)$Id: Param.java,v 1.15 2001/09/25 15:57:22 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -128,10 +128,7 @@
parser.reportError(Constants.ERROR, msg);
}
- final String select = getAttribute("select");
- if (select.length() > 0) {
- _select = parser.parseExpression(this, "select", null);
- }
+ select = getAttribute("select");
// Children must be parsed first -> static scoping
parseChildren(parser);
@@ -177,6 +174,13 @@
* element has a body and no 'select' expression.
*/
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+
+ // Parse the XPath expression in this method to allow for
+ // forward references to other varibables
+ if (select.length() > 0) {
+ _select = getParser().parseExpression(this, "select", null);
+ }
+
// Get the type from the select exrepssion...
if (_select != null) {
_type = _select.typeCheck(stable);
1.12 +24 -11
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.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- Step.java 2001/09/21 11:55:55 1.11
+++ Step.java 2001/09/25 15:57:22 1.12
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Step.java,v 1.11 2001/09/21 11:55:55 morten Exp $
+ * @(#)$Id: Step.java,v 1.12 2001/09/25 15:57:22 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -404,7 +404,8 @@
// Handle '//*[n]' expression
else if (predicate.isNthDescendant()) {
il.append(methodGen.loadDOM());
- il.append(methodGen.loadContextNode());
+ //il.append(methodGen.loadContextNode());
+ il.append(new ICONST(-1));
predicate.translate(classGen, methodGen);
int iter = cpg.addInterfaceMethodref(DOM_INTF,
"getNthDescendant",
@@ -413,15 +414,27 @@
}
// Handle 'elem[n]' expression
else if (predicate.isNthPositionFilter()) {
- final int initNI =
- cpg.addMethodref(NTH_ITERATOR_CLASS,
- "<init>",
- "(" + NODE_ITERATOR_SIG + "I)V");
- il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));
- il.append(DUP);
- translatePredicates(classGen, methodGen); // recursive call
- predicate.translate(classGen, methodGen);
- il.append(new INVOKESPECIAL(initNI));
+ if ((_axis == 4) || (_axis == 5)) {
+ il.append(methodGen.loadDOM());
+ System.err.println("node type is "+_nodeType);
+ il.append(new PUSH(cpg, _nodeType));
+ predicate.translate(classGen, methodGen);
+ int iter = cpg.addInterfaceMethodref(DOM_INTF,
+ "getNthDescendant",
+
"(II)"+NODE_ITERATOR_SIG);
+ il.append(new INVOKEINTERFACE(iter, 3));
+ }
+ else {
+ final int initNI =
+ cpg.addMethodref(NTH_ITERATOR_CLASS,
+ "<init>",
+ "(" + NODE_ITERATOR_SIG + "I)V");
+ il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));
+ il.append(DUP);
+ translatePredicates(classGen, methodGen); // recursive call
+ predicate.translate(classGen, methodGen);
+ il.append(new INVOKESPECIAL(initNI));
+ }
}
else {
final int init = cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR,
1.18 +9 -5
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Variable.java
Index: Variable.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/Variable.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Variable.java 2001/09/25 12:59:56 1.17
+++ Variable.java 2001/09/25 15:57:22 1.18
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: Variable.java,v 1.17 2001/09/25 12:59:56 morten Exp $
+ * @(#)$Id: Variable.java,v 1.18 2001/09/25 15:57:22 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -121,10 +121,7 @@
reportError(this, parser, ErrorMsg.VARREDEF_ERR, _name.toString());
}
- final String select = getAttribute("select");
- if (select.length() > 0) {
- _select = parser.parseExpression(this, "select", null);
- }
+ select = getAttribute("select");
// Children must be parsed first -> static scoping
parseChildren(parser);
@@ -168,6 +165,13 @@
* expression in the 'select' attribute
*/
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
+
+ // Parse the XPath expression in this method to allow for
+ // forward references to other varibables
+ if (select.length() > 0) {
+ _select = getParser().parseExpression(this, "select", null);
+ }
+
// Type check the 'select' expression if present
if (_select != null) {
_type = _select.typeCheck(stable);
1.7 +2 -1
xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableBase.java
Index: VariableBase.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/compiler/VariableBase.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- VariableBase.java 2001/09/25 12:59:56 1.6
+++ VariableBase.java 2001/09/25 15:57:22 1.7
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: VariableBase.java,v 1.6 2001/09/25 12:59:56 morten Exp $
+ * @(#)$Id: VariableBase.java,v 1.7 2001/09/25 15:57:22 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -84,6 +84,7 @@
protected LocalVariableGen _local; // Reference to JVM variable
protected Instruction _loadInstruction; // Instruction to load JVM
variable
protected Expression _select; // Reference to variable
expression
+ protected String select; // Textual repr. of variable
expr.
protected int _stackIndex = -1; // Stack index relative to base
ptr.
// References to this variable (when local)
1.16 +2 -1
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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- xpath.cup 2001/09/13 12:30:53 1.15
+++ xpath.cup 2001/09/25 15:57:22 1.16
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: xpath.cup,v 1.15 2001/09/13 12:30:53 tmiller Exp $
+ * @(#)$Id: xpath.cup,v 1.16 2001/09/25 15:57:22 morten Exp $
*
* Copyright 2000 Sun Microsystems, Inc. All Rights Reserved.
*
@@ -452,6 +452,7 @@
{:
Step nodeStep;
final Step temp = (Step) step;
+ // THIS CODE IS NOT GOOD - PREDICATES ARE MISPLACED!!!!!
if (temp.getAxis() == Axis.CHILD) {
// Expand 'rlp//child::E' into 'rlp/descendant::E'
nodeStep = new Step(Axis.DESCENDANT,
1.6 +3 -3
xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMAdapter.java
Index: DOMAdapter.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/DOMAdapter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DOMAdapter.java 2001/09/21 11:55:55 1.5
+++ DOMAdapter.java 2001/09/25 15:57:22 1.6
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: DOMAdapter.java,v 1.5 2001/09/21 11:55:55 morten Exp $
+ * @(#)$Id: DOMAdapter.java,v 1.6 2001/09/25 15:57:22 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -148,8 +148,8 @@
return(iterator);
}
- public NodeIterator getNthDescendant(int node, int n) {
- return _domImpl.getNthDescendant(node, n);
+ public NodeIterator getNthDescendant(int type, int n) {
+ return _domImpl.getNthDescendant(_reverse[type], n);
}
public NodeIterator getNodeValueIterator(NodeIterator iterator, int type,
1.34 +34 -13
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.33
retrieving revision 1.34
diff -u -r1.33 -r1.34
--- DOMImpl.java 2001/09/24 15:43:14 1.33
+++ DOMImpl.java 2001/09/25 15:57:22 1.34
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: DOMImpl.java,v 1.33 2001/09/24 15:43:14 morten Exp $
+ * @(#)$Id: DOMImpl.java,v 1.34 2001/09/25 15:57:22 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -1361,35 +1361,51 @@
*/
private class NthDescendantIterator extends DescendantIterator {
- int _pos;
+ final NodeIterator _source;
+ final int _pos;
+ final int _ourtype;
- public NthDescendantIterator(int pos) {
+ public NthDescendantIterator(NodeIterator source, int pos, int type) {
+ _source = source;
+ _ourtype = type;
_pos = pos;
- _limit = _treeNodeLimit;
}
// The start node of this iterator is always the root!!!
public NodeIterator setStartNode(int node) {
- NodeIterator iterator = super.setStartNode(1);
- _limit = _treeNodeLimit;
- return iterator;
+ _source.setStartNode(node);
+ return this;
}
public int next() {
int node;
- while ((node = super.next()) != END) {
+ while ((node = _source.next()) != END) {
int parent = _parent[node];
int child = _offsetOrChild[parent];
int pos = 0;
- do {
- if (isElement(child)) pos++;
- } while ((pos < _pos) && (child = _nextSibling[child]) != 0);
+ if (_ourtype != -1) {
+ do {
+ if (isElement(child) && _type[child] == _ourtype) pos++;
+ } while ((pos<_pos) && (child = _nextSibling[child]) != 0);
+ }
+ else {
+ do {
+ if (isElement(child)) pos++;
+ } while ((pos<_pos) && (child = _nextSibling[child]) != 0);
+ }
+
if (node == child) return node;
}
return(END);
}
+ public NodeIterator reset() {
+ _source.reset();
+ return this;
+ }
+
+
} // end of NthDescendantIterator
@@ -2335,8 +2351,13 @@
/**
* Returns the nth descendant of a node (1 = parent, 2 = gramps)
*/
- public NodeIterator getNthDescendant(int node, int n) {
- return (new NthDescendantIterator(n));
+ public NodeIterator getNthDescendant(int type, int n) {
+ NodeIterator source;
+ if (type == -1)
+ source = new DescendantIterator();
+ else
+ source = new TypedDescendantIterator(type);
+ return(new NthDescendantIterator(source, n, type));
}
/**
1.17 +5 -2
xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java
Index: BasisLibrary.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/runtime/BasisLibrary.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- BasisLibrary.java 2001/09/25 13:10:54 1.16
+++ BasisLibrary.java 2001/09/25 15:57:22 1.17
@@ -1,5 +1,5 @@
/*
- * @(#)$Id: BasisLibrary.java,v 1.16 2001/09/25 13:10:54 morten Exp $
+ * @(#)$Id: BasisLibrary.java,v 1.17 2001/09/25 15:57:22 morten Exp $
*
* The Apache Software License, Version 1.1
*
@@ -153,7 +153,10 @@
return ((DOM)obj).getStringValue();
}
else {
- return obj.toString();
+ if (obj != null)
+ return obj.toString();
+ else
+ return stringF(node, dom);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]