sboag       00/12/08 19:56:48

  Modified:    java/src/org/apache/xpath/axes AxesWalker.java
                        LocPathIterator.java
  Log:
  Add value to the itterator to mark the start of where the waiters
  should be looked at.  In the walker, set the bottom of the waiters
  list to be the current size of the stack when executing a predicate,
  then restore it on return.  This fixes a bug when executing the
  last() function inside a predicate in a walker that has to wait for
  the parent walker to walk past it.  Fixes test axes91.
  
  Revision  Changes    Path
  1.12      +62 -27    xml-xalan/java/src/org/apache/xpath/axes/AxesWalker.java
  
  Index: AxesWalker.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xpath/axes/AxesWalker.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AxesWalker.java   2000/11/23 04:59:00     1.11
  +++ AxesWalker.java   2000/12/09 03:56:47     1.12
  @@ -133,7 +133,7 @@
     /**
      * Construct an AxesWalker using a LocPathIterator.
      *
  -   * NEEDSDOC @param locPathIterator
  +   * @param locPathIterator non-null reference to the parent iterator.
      */
     public AxesWalker(LocPathIterator locPathIterator)
     {
  @@ -176,7 +176,7 @@
     /**
      * Get a cloned AxesWalker.
      *
  -   * NEEDSDOC ($objectName$) @return
  +   * @return A new AxesWalker that can be used without mutating this one.
      *
      * @throws CloneNotSupportedException
      */
  @@ -390,7 +390,7 @@
       m_predicateIndex = 0;
   
       int nPredicates = m_predicateCount;
  -
  +    // System.out.println("nPredicates: "+nPredicates);
       if (nPredicates == 0)
         return true;
   
  @@ -404,25 +404,52 @@
   
         for (int i = 0; i < nPredicates; i++)
         {
  +        // System.out.println("Executing predicate expression - waiting 
count: "+m_lpi.getWaitingCount());
  +        int savedWaitingBottom = m_lpi.m_waitingBottom;
  +        m_lpi.m_waitingBottom = m_lpi.getWaitingCount();
           XObject pred;
  -
  -        pred = m_predicates[i].execute(xctxt);
  -
  +        try
  +        {
  +          pred = m_predicates[i].execute(xctxt);
  +        }
  +        finally
  +        {
  +          m_lpi.m_waitingBottom = savedWaitingBottom;
  +        }
  +        // System.out.println("\nBack from executing predicate expression - 
waiting count: "+m_lpi.getWaitingCount());
  +        // System.out.println("pred.getType(): "+pred.getType());
           if (XObject.CLASS_NUMBER == pred.getType())
           {
             if (DEBUG_PREDICATECOUNTING)
             {
  -            System.out.println("=============");
  +            System.out.flush();
  +            System.out.println("\n===== start predicate count ========");
               System.out.println("m_predicateIndex: " + m_predicateIndex);
  -            System.out.println("getProximityPosition(m_predicateIndex): "
  -                               + getProximityPosition(m_predicateIndex));
  +            // System.out.println("getProximityPosition(m_predicateIndex): "
  +            //                   + getProximityPosition(m_predicateIndex));
               System.out.println("pred.num(): " + pred.num());
  +            System.out.println("waiting count: "+m_lpi.getWaitingCount());
             }
   
  -          if (this.getProximityPosition(m_predicateIndex) != (int) 
pred.num())
  +          int proxPos = this.getProximityPosition(m_predicateIndex);
  +          if (proxPos != (int) pred.num())
             {
  +            if (DEBUG_PREDICATECOUNTING)
  +            {
  +              System.out.println("\nnode context: "+nodeToString(context));
  +              System.out.println("index predicate is false: "+proxPos);
  +              System.out.println("waiting count: "+m_lpi.getWaitingCount());
  +              System.out.println("\n===== end predicate count ========");
  +            }
               return false;
             }
  +          else if (DEBUG_PREDICATECOUNTING)
  +          {
  +            System.out.println("\nnode context: "+nodeToString(context));
  +            System.out.println("index predicate is true: "+proxPos);
  +            System.out.println("waiting count: "+m_lpi.getWaitingCount());
  +            System.out.println("\n===== end predicate count ========");
  +          }
           }
           else if (!pred.bool())
             return false;
  @@ -1028,9 +1055,9 @@
   
       if (DEBUG_WAITING)
       {
  -      int nWaiting = m_lpi.m_waiting.size();
  +      int nWaiting = m_lpi.getWaitingCount();
   
  -      for (int i = 0; i < nWaiting; i++)
  +      for (int i = m_lpi.m_waitingBottom; i < nWaiting; i++)
         {
           AxesWalker ws = (AxesWalker) m_lpi.m_waiting.elementAt(i);
   
  @@ -1163,9 +1190,9 @@
       if ((null != walker) && (null == walker.m_currentNode))
         return walker;
   
  -    int nWaiting = m_lpi.m_waiting.size();
  +    int nWaiting = m_lpi.getWaitingCount();
   
  -    for (int i = 0; i < nWaiting; i++)
  +    for (int i = m_lpi.m_waitingBottom; i < nWaiting; i++)
       {
         AxesWalker ws = (AxesWalker) m_lpi.m_waiting.elementAt(i);
         AxesWalker prevStepWalker = ws.m_prevWalker;
  @@ -1183,13 +1210,10 @@
             {
               AxesWalker deferedWalker = walker;
   
  -            if (DEBUG_WAITING)
  -              printDebug("[Moving " + deferedWalker.toString() + ", "
  -                         + nodeToString(deferedWalker.m_currentNode)
  -                         + " to WAITING list]");
  -
               if (!isWaiting(deferedWalker))
  -              m_lpi.addToWaitList(deferedWalker);
  +            {
  +              addToWaitList(deferedWalker);
  +            }
             }
   
             walker = ws;
  @@ -1222,9 +1246,9 @@
   
       DOMHelper dh = m_lpi.getDOMHelper();
       AxesWalker first = null;
  -    int nWaiting = m_lpi.m_waiting.size();
  +    int nWaiting = m_lpi.getWaitingCount();
   
  -    for (int i = 0; i < nWaiting; i++)
  +    for (int i = m_lpi.m_waitingBottom; i < nWaiting; i++)
       {
         AxesWalker ws = (AxesWalker) m_lpi.m_waiting.elementAt(i);
   
  @@ -1261,9 +1285,9 @@
     boolean isWaiting(AxesWalker walker)
     {
   
  -    int nWaiting = m_lpi.m_waiting.size();
  +    int nWaiting = m_lpi.getWaitingCount();
   
  -    for (int i = 0; i < nWaiting; i++)
  +    for (int i = m_lpi.m_waitingBottom; i < nWaiting; i++)
       {
         AxesWalker ws = (AxesWalker) m_lpi.m_waiting.elementAt(i);
   
  @@ -1273,6 +1297,16 @@
   
       return false;
     }
  +  
  +  private final void addToWaitList(AxesWalker walker)
  +  {
  +      if (DEBUG_WAITING)
  +        printDebug("[Moving " + walker.toString() + ", "
  +                   + nodeToString(walker.m_currentNode)
  +                   + " to WAITING list]");
  +                   
  +      m_lpi.addToWaitList(walker);
  +  }
   
     /**
      * Check if a given walker needs to wait for the previous walker to
  @@ -1306,12 +1340,12 @@
               if (DEBUG_WAITING)
                 printDebug("checkNeedsToWait.clone: " + walker.toString());
   
  -            m_lpi.addToWaitList((AxesWalker) walker.clone());
  +            addToWaitList((AxesWalker) walker.clone());
             }
             catch (CloneNotSupportedException cnse){}
           }
           else
  -          m_lpi.addToWaitList(walker);
  +          addToWaitList(walker);
   
           walker = walker.m_prevWalker;
   
  @@ -1621,7 +1655,8 @@
   
         XObject score = execute(xctxt);
   
  -      // System.out.println("::acceptNode - score: "+score.num()+"::");
  +      if(DEBUG)
  +        System.out.println("\n::acceptNode - score: "+score.num()+"::");
         if (score != NodeTest.SCORE_NONE)
         {
           if (m_predicateCount > 0)
  
  
  
  1.17      +10 -1     
xml-xalan/java/src/org/apache/xpath/axes/LocPathIterator.java
  
  Index: LocPathIterator.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xpath/axes/LocPathIterator.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- LocPathIterator.java      2000/11/30 16:26:50     1.16
  +++ LocPathIterator.java      2000/12/09 03:56:47     1.17
  @@ -156,8 +156,16 @@
   
     /** The list of "waiting" step walkers.
      * @see org.apache.xpath.axes.AxesWalker     */
  -  public Vector m_waiting = new Vector();
  +  Vector m_waiting = new Vector();
     
  +  int getWaitingCount()
  +  {
  +    return m_waiting.size() - m_waitingBottom;
  +  }
  +    
  +  /** The starting point in m_waiting where the waiting step walkers are. */
  +  int m_waitingBottom = 0;
  +  
     /** An index to the point in the variable stack where we should
      * begin variable searches for this iterator.
      * This is -1 if m_isTopLevel is false. 
  @@ -641,6 +649,7 @@
       m_lastFetched = null;
       m_next = 0;
       m_last = 0;
  +    m_waitingBottom = 0;
   
       if (null != m_firstWalker)
       {
  
  
  

Reply via email to