coloring: add `POSet::to_conflict_graph` for lazy peoples
authorJean Privat <jean@pryen.org>
Mon, 23 Mar 2015 06:19:52 +0000 (13:19 +0700)
committerJean Privat <jean@pryen.org>
Mon, 23 Mar 2015 08:27:34 +0000 (15:27 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>

src/compiler/coloring.nit

index 4746bc4..5a57774 100644 (file)
@@ -17,7 +17,7 @@ module coloring
 import poset
 
 # Build a conflict graph from a POSet
-class POSetConflictGraph[E: Object]
+class POSetConflictGraph[E]
 
        # Core is composed by:
        #  * elements that have mutiple direct parents
@@ -45,6 +45,7 @@ class POSetConflictGraph[E: Object]
        # REQUIRE: is_colored
        var conflicts = new HashMap[E, Set[E]]
 
+       # The associated poset
        var poset: POSet[E]
 
        # The linearisation order to visit elements in the poset
@@ -120,10 +121,14 @@ class POSetConflictGraph[E: Object]
                #print "border: {border.join(" ")} ({border.length})"
                #print "crown: {crown.join(" ")} ({crown.length})"
                print "conflicts:"
-               for e, c in conflicts do print "  {e}: {c.join(" ")}"
+               for e, c in conflicts do print "  {e or else "NULL"}: {c.join(" ")}"
        end
 end
 
+redef class POSet[E]
+       fun to_conflict_graph: POSetConflictGraph[E] do return new POSetConflictGraph[E](self)
+end
+
 # Colorize elements from a POSet
 # Two elements from a POSet cannot have the same color if they share common subelements
 #