logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Nice/src/bossa/link Alternative.java,1.48,1.49: msg#00196

Subject: Nice/src/bossa/link Alternative.java,1.48,1.49
Update of /cvsroot/nice/Nice/src/bossa/link
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23398/src/bossa/link

Modified Files:
        Alternative.java 
Log Message:
Fix sorting of alternatives, now that alternatives can belong to several
methods.


Index: Alternative.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/link/Alternative.java,v
retrieving revision 1.48
retrieving revision 1.49
diff -C2 -d -r1.48 -r1.49
*** Alternative.java    28 Feb 2004 14:23:43 -0000      1.48
--- Alternative.java    28 Feb 2004 20:24:16 -0000      1.49
***************
*** 52,67 ****
  
    /****************************************************************
-    * Graph traversal
-    ****************************************************************/
- 
-   static final int 
-     UNVISITED = 1,
-     VISITING  = 2,
-     VISITED   = 3;
-   
-   /** Marks the state of this node in the graph traversal. */
-   int mark = UNVISITED;
-   
-   /****************************************************************
     * Order on alternatives
     ****************************************************************/
--- 52,55 ----
***************
*** 222,225 ****
--- 210,222 ----
  
    /****************************************************************
+    * Graph traversal
+    ****************************************************************/
+ 
+   /** Marks the state of this node in the graph traversal. */
+   private int mark = 0;
+ 
+   private static int currentVisitedMark = 0;
+ 
+   /****************************************************************
     * Sorting alternatives by generality
     ****************************************************************/
***************
*** 237,251 ****
        return sortedAlternatives;
  
!     // Test if another sort has been done before.
!     // In that case reset the marks.
!     if (((Alternative) alternatives.get(0)).mark != Alternative.UNVISITED)
!       for(Iterator i = alternatives.iterator(); i.hasNext();)
!       ((Alternative) i.next()).mark = Alternative.UNVISITED;
!       
      for(Iterator i = alternatives.iterator(); i.hasNext();)
        {
        Alternative a = (Alternative) i.next();
!       if (a.mark == Alternative.UNVISITED)
!         visit(a, alternatives, sortedAlternatives);
        }
  
--- 234,247 ----
        return sortedAlternatives;
  
!     // We used a different mark for each sort.
!     // Useful since an alternative can belong to several methods because of
!     // overriding, and SuperExp also lists alternatives.
!     int visited = ++currentVisitedMark;
! 
      for(Iterator i = alternatives.iterator(); i.hasNext();)
        {
        Alternative a = (Alternative) i.next();
!       if (a.mark != visited)
!         visit(a, alternatives, sortedAlternatives, visited);
        }
  
***************
*** 256,272 ****
      (final Alternative a, 
       final List alternatives,
!      final Stack sortedAlternatives
       )
    {
!     // Cycles are possible
!     //   * if two alternatives are identical (same patterns)
!     //   * if there is a cyclic subclass relation
!     //   * that's all, folks ! :-)
!     switch(a.mark)
!       {
!       case Alternative.VISITING : User.error("Cycle in alternatives: "+a);
!       case Alternative.UNVISITED: a.mark = Alternative.VISITING; break;
!       case Alternative.VISITED  : return; //should not happen
!       }
      
      for(Iterator i = alternatives.iterator();
--- 252,260 ----
      (final Alternative a, 
       final List alternatives,
!      final Stack sortedAlternatives,
!      final int visited
       )
    {
!     a.mark = visited;
      
      for(Iterator i = alternatives.iterator();
***************
*** 274,283 ****
        {
        Alternative daughter = (Alternative) i.next();
!       if(daughter != a 
!          && daughter.mark == Alternative.UNVISITED 
!          && Alternative.leq(daughter,a))
!         visit(daughter,alternatives,sortedAlternatives);
        }
!     a.mark = Alternative.VISITED;
      sortedAlternatives.push(a);
    }
--- 262,270 ----
        {
        Alternative daughter = (Alternative) i.next();
!       if (daughter.mark != visited 
!             && Alternative.leq(daughter,a))
!         visit(daughter, alternatives, sortedAlternatives, visited);
        }
! 
      sortedAlternatives.push(a);
    }



-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click


<Prev in Thread] Current Thread [Next in Thread>