You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by db...@apache.org on 2008/07/31 17:56:15 UTC

svn commit: r681402 - in /xalan/c/trunk/src/xalanc/XPath: XPath.cpp XPath.hpp

Author: dbertoni
Date: Thu Jul 31 08:56:14 2008
New Revision: 681402

URL: http://svn.apache.org/viewvc?rev=681402&view=rev
Log:
Fix for XALANC-679.

Modified:
    xalan/c/trunk/src/xalanc/XPath/XPath.cpp
    xalan/c/trunk/src/xalanc/XPath/XPath.hpp

Modified: xalan/c/trunk/src/xalanc/XPath/XPath.cpp
URL: http://svn.apache.org/viewvc/xalan/c/trunk/src/xalanc/XPath/XPath.cpp?rev=681402&r1=681401&r2=681402&view=diff
==============================================================================
--- xalan/c/trunk/src/xalanc/XPath/XPath.cpp (original)
+++ xalan/c/trunk/src/xalanc/XPath/XPath.cpp Thu Jul 31 08:56:14 2008
@@ -3019,6 +3019,71 @@
 
 
 
+XPath::eMatchScore
+XPath::doStepPredicate(
+            XPathExecutionContext&	executionContext,
+            XalanNode* 				context,
+            OpCodeMapPositionType 	opPos,
+            OpCodeMapPositionType 	startOpPos,
+            eMatchScore 			score) const
+{
+    const XPathExpression&  currentExpression = getExpression();
+
+    OpCodeMapValueType  nextStepType = currentExpression.getOpCodeMapValue(opPos);
+
+    if (XPathExpression::eOP_PREDICATE == nextStepType ||
+        XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType)
+    {
+        do
+        {
+            // This is a quick hack to look ahead and see if we have
+            // number literal as the predicate, i.e. match="foo[1]".
+            if (XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType)
+            {
+                if (m_expression.getOpCodeMapValue(opPos + 2) == XPathExpression::eOP_NUMBERLIT)
+                {
+                    score = handleFoundIndexPositional(
+                            executionContext,
+                            context,
+                            startOpPos);
+                }
+                else
+                {
+                    score = handleFoundIndex(
+                            executionContext,
+                            context,
+                            startOpPos);
+                }
+            }
+            else
+            {
+                const XObjectPtr    pred(predicate(context, opPos, executionContext));
+                assert(pred.get() != 0);
+
+                if(XObject::eTypeNumber == pred->getType())
+                {
+                    score = handleFoundIndex(executionContext, context, startOpPos);
+                }
+                else if(pred->boolean() == false)
+                {
+                    score = eMatchScoreNone;
+
+                    break;
+                }
+            }
+
+            opPos = currentExpression.getNextOpCodePosition(opPos);
+            nextStepType = currentExpression.getOpCodeMapValue(opPos);
+        }
+        while(XPathExpression::eOP_PREDICATE == nextStepType ||
+              XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType);
+    }
+
+    return score;
+}
+
+
+
 XalanNode*
 XPath::stepPattern(
             XPathExecutionContext&  executionContext,
@@ -3031,6 +3096,8 @@
     const OpCodeMapPositionType     endStep = currentExpression.getNextOpCodePosition(opPos);
     OpCodeMapValueType              nextStepType = currentExpression.getOpCodeMapValue(endStep);
 
+    bool    fDoPredicates = true;
+
     if(XPathExpression::eENDOP != nextStepType)
     {
         // Continue step via recursion...
@@ -3200,6 +3267,9 @@
     case XPathExpression::eMATCH_ANY_ANCESTOR:
     case XPathExpression::eMATCH_ANY_ANCESTOR_WITH_PREDICATE:
         {
+            assert(fDoPredicates == true);
+            fDoPredicates = false;
+
             argLen = currentExpression.getOpCodeArgumentLength(opPos);
 
             XalanNode::NodeType     nodeType = context->getNodeType();
@@ -3219,8 +3289,20 @@
                 {
                     score = theTester(*context, nodeType);
 
-                    if(eMatchScoreNone != score)
-                        break;
+                    if (eMatchScoreNone != score)
+                    {
+                        score = 
+                            doStepPredicate(
+                                executionContext,
+                                context, 
+                                opPos + argLen,
+                                startOpPos,
+                                score);
+                        if (eMatchScoreNone != score)
+                        {
+                            break;
+                        }
+                    }
 
                     context = DOMServices::getParentOfNode(*context);
 
@@ -3272,57 +3354,15 @@
         }
     }
 
-    opPos += argLen;
-
-    nextStepType = currentExpression.getOpCodeMapValue(opPos);
-
-    if(score != eMatchScoreNone &&
-       (XPathExpression::eOP_PREDICATE == nextStepType || XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType))
+    if (fDoPredicates == true && score != eMatchScoreNone)
     {
-        score = eMatchScoreOther;
-
-        while(XPathExpression::eOP_PREDICATE == nextStepType ||
-              XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType)
-        {
-            // This is a quick hack to look ahead and see if we have
-            // number literal as the predicate, i.e. match="foo[1]".
-            if (XPathExpression::eOP_PREDICATE_WITH_POSITION == nextStepType)
-            {
-                if (m_expression.getOpCodeMapValue(opPos + 2) == XPathExpression::eOP_NUMBERLIT)
-                {
-                    score = handleFoundIndexPositional(
-                            executionContext,
-                            context,
-                            startOpPos);
-                }
-                else
-                {
-                    score = handleFoundIndex(
-                            executionContext,
-                            context,
-                            startOpPos);
-                }
-            }
-            else
-            {
-                const XObjectPtr    pred(predicate(context, opPos, executionContext));
-                assert(pred.get() != 0);
-
-                if(XObject::eTypeNumber == pred->getType())
-                {
-                    score = handleFoundIndex(executionContext, context, startOpPos);
-                }
-                else if(pred->boolean() == false)
-                {
-                    score = eMatchScoreNone;
-
-                    break;
-                }
-            }
-
-            opPos = currentExpression.getNextOpCodePosition(opPos);
-            nextStepType = currentExpression.getOpCodeMapValue(opPos);
-        }
+        score =
+            doStepPredicate(
+                executionContext,
+                context, 
+                opPos + argLen,
+                startOpPos,
+                score);
     }
 
     if (scoreHolder == eMatchScoreNone || 

Modified: xalan/c/trunk/src/xalanc/XPath/XPath.hpp
URL: http://svn.apache.org/viewvc/xalan/c/trunk/src/xalanc/XPath/XPath.hpp?rev=681402&r1=681401&r2=681402&view=diff
==============================================================================
--- xalan/c/trunk/src/xalanc/XPath/XPath.hpp (original)
+++ xalan/c/trunk/src/xalanc/XPath/XPath.hpp Thu Jul 31 08:56:14 2008
@@ -2443,6 +2443,14 @@
 
 protected:
 
+    /**
+     * Execute a step in a location path.
+     *
+     * @param xpath The xpath that is executing
+     * @param context The current source tree context node
+     * @param opPos The current position in the xpath operation map array
+     * @param queryResults The set of nodes that matches the step.
+     */
     void
     step(
             XPathExecutionContext&	executionContext,
@@ -2451,7 +2459,25 @@
             MutableNodeRefList&		queryResults) const;
 
     /**
-     * Execute a step in a location path.
+     * Potentially evaluate a predicate in a match pattern step.
+     *
+     * @param executionContext The current execution context.
+     * @param context          The current source tree context node.
+     * @param opPos            The current position in the Op Map.
+     * @param startOpPos       The original position for the step in the Op Map.
+     * @param score            The current match score for the context node.
+     * @return The resulting match score
+     */
+    eMatchScore
+    doStepPredicate(
+            XPathExecutionContext&	executionContext,
+            XalanNode* 				context, 
+            OpCodeMapPositionType 	opPos,
+            OpCodeMapPositionType 	startOpPos,
+            eMatchScore 			score) const;
+
+    /**
+     * Execute a step in a match pattern's location path.
      *
      * @param xpath The xpath that is executing
      * @param context The current source tree context node



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