phase: use a extensible work-list for `run_phases`
authorJean Privat <jean@pryen.org>
Tue, 31 Jan 2017 19:30:08 +0000 (14:30 -0500)
committerJean Privat <jean@pryen.org>
Thu, 2 Feb 2017 18:51:15 +0000 (13:51 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/phase.nit

index c94dcdc..2d400c9 100644 (file)
@@ -86,6 +86,11 @@ redef class ToolContext
        # Set of already analyzed modules.
        private var phased_modules = new HashSet[AModule]
 
+       # List of module to process according to `run_phases`
+       #
+       # This allow some new modules to be found and added while analysing the code.
+       var todo_nmodules: Sequence[AModule]
+
        # Run all registered phases on a set of modules
        fun run_phases(nmodules: Collection[AModule])
        do
@@ -99,7 +104,11 @@ redef class ToolContext
                        self.info(" registered phases: {phase}", 2)
                end
 
-               for nmodule in nmodules do
+               var todo_nmodules = nmodules.to_a
+               self.todo_nmodules = todo_nmodules
+
+               while not todo_nmodules.is_empty do
+                       var nmodule = todo_nmodules.shift
                        if phased_modules.has(nmodule) then continue
                        phased_modules.add nmodule