mmidy 02/05/13 14:07:44
Modified: java/src/org/apache/xpath/compiler Compiler.java
java/src/org/apache/xpath/functions FuncLast.java
FuncPosition.java Function.java
Log:
Bugzilla6284: New function added to position() and last() that will help us
determine whether we are executing a top-level expression and therefore, not
inside a predicate
Revision Changes Path
1.28 +28 -19
xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java
Index: Compiler.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/compiler/Compiler.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- Compiler.java 22 Mar 2002 01:04:44 -0000 1.27
+++ Compiler.java 13 May 2002 21:07:44 -0000 1.28
@@ -701,32 +701,39 @@
*/
protected Expression matchPattern(int opPos) throws TransformerException
{
+ locPathDepth++;
+ try
+ {
+ // First, count...
+ int nextOpPos = opPos;
+ int i;
- // First, count...
- int nextOpPos = opPos;
- int i;
+ for (i = 0; m_opMap[nextOpPos] == OpCodes.OP_LOCATIONPATHPATTERN; i++)
+ {
+ nextOpPos = getNextOpPos(nextOpPos);
+ }
- for (i = 0; m_opMap[nextOpPos] == OpCodes.OP_LOCATIONPATHPATTERN; i++)
- {
- nextOpPos = getNextOpPos(nextOpPos);
- }
+ if (i == 1)
+ return compile(opPos);
- if (i == 1)
- return compile(opPos);
+ UnionPattern up = new UnionPattern();
+ StepPattern[] patterns = new StepPattern[i];
- UnionPattern up = new UnionPattern();
- StepPattern[] patterns = new StepPattern[i];
+ for (i = 0; m_opMap[opPos] == OpCodes.OP_LOCATIONPATHPATTERN; i++)
+ {
+ nextOpPos = getNextOpPos(opPos);
+ patterns[i] = (StepPattern) compile(opPos);
+ opPos = nextOpPos;
+ }
+
+ up.setPatterns(patterns);
- for (i = 0; m_opMap[opPos] == OpCodes.OP_LOCATIONPATHPATTERN; i++)
+ return up;
+ }
+ finally
{
- nextOpPos = getNextOpPos(opPos);
- patterns[i] = (StepPattern) compile(opPos);
- opPos = nextOpPos;
+ locPathDepth--;
}
-
- up.setPatterns(patterns);
-
- return up;
}
/**
@@ -1047,6 +1054,8 @@
{
Function func = FunctionTable.getFunction(funcID);
+ func.postCompileStep(this);
+
try
{
int i = 0;
1.11 +15 -1
xml-xalan/java/src/org/apache/xpath/functions/FuncLast.java
Index: FuncLast.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncLast.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- FuncLast.java 17 Jun 2001 21:42:29 -0000 1.10
+++ FuncLast.java 13 May 2002 21:07:44 -0000 1.11
@@ -71,6 +71,8 @@
import org.apache.xpath.axes.LocPathIterator;
import org.apache.xpath.axes.ContextNodeList;
import org.apache.xpath.axes.SubContextList;
+import org.apache.xpath.compiler.Compiler;
+
/**
* <meta name="usage" content="advanced"/>
@@ -78,6 +80,17 @@
*/
public class FuncLast extends Function
{
+
+ private boolean m_isTopLevel;
+
+ /**
+ * Figure out if we're executing a toplevel expression.
+ * If so, we can't be inside of a predicate.
+ */
+ public void postCompileStep(Compiler compiler)
+ {
+ m_isTopLevel = compiler.getLocationPathDepth() == -1;
+ }
/**
* Get the position in the current context node list.
@@ -94,7 +107,8 @@
// assert(null != m_contextNodeList, "m_contextNodeList must be
non-null");
// If we're in a predicate, then this will return non-null.
- SubContextList iter = xctxt.getSubContextList();
+ SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();
+
// System.out.println("iter: "+iter);
if (null != iter)
return iter.getLastPos(xctxt);
1.7 +12 -1
xml-xalan/java/src/org/apache/xpath/functions/FuncPosition.java
Index: FuncPosition.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/functions/FuncPosition.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FuncPosition.java 15 Jun 2001 05:15:43 -0000 1.6
+++ FuncPosition.java 13 May 2002 21:07:44 -0000 1.7
@@ -70,6 +70,7 @@
import org.apache.xpath.axes.SubContextList;
import org.apache.xpath.axes.ContextNodeList;
import org.apache.xpath.NodeSetDTM;
+import org.apache.xpath.compiler.Compiler;
/**
* <meta name="usage" content="advanced"/>
@@ -77,6 +78,16 @@
*/
public class FuncPosition extends Function
{
+ private boolean m_isTopLevel;
+
+ /**
+ * Figure out if we're executing a toplevel expression.
+ * If so, we can't be inside of a predicate.
+ */
+ public void postCompileStep(Compiler compiler)
+ {
+ m_isTopLevel = compiler.getLocationPathDepth() == -1;
+ }
/**
* Get the position in the current context node list.
@@ -91,7 +102,7 @@
// System.out.println("FuncPosition- entry");
// If we're in a predicate, then this will return non-null.
- SubContextList iter = xctxt.getSubContextList();
+ SubContextList iter = m_isTopLevel ? null : xctxt.getSubContextList();
if (null != iter)
{
1.7 +9 -1
xml-xalan/java/src/org/apache/xpath/functions/Function.java
Index: Function.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xpath/functions/Function.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Function.java 22 Mar 2002 01:04:44 -0000 1.6
+++ Function.java 13 May 2002 21:07:44 -0000 1.7
@@ -64,6 +64,7 @@
import org.apache.xpath.XPathContext;
import org.apache.xpath.XPathVisitor;
import org.apache.xpath.objects.XObject;
+import org.apache.xpath.compiler.Compiler;
/**
* <meta name="usage" content="advanced"/>
@@ -157,5 +158,12 @@
return true;
}
-
+ /**
+ * This function is currently only being used by Position()
+ * and Last(). See respective functions for more detail.
+ */
+ public void postCompileStep(Compiler compiler)
+ {
+ // no default action
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]