Merge: doc: fixed some typos and other misc. corrections
[nit.git] / src / phase.nit
index 5f0faf1..2a9d7b8 100644 (file)
@@ -28,10 +28,10 @@ redef class ToolContext
        var phases = new POSet[Phase]
 
        # --disable-phase
-       var opt_disable_phase = new OptionArray("DEBUG: Disable a specific phase; use `list` to get the list.", "--disable-phase")
+       var opt_disable_phase = new OptionArray("Disable a specific phase; use `list` to get the list (debug)", "--disable-phase")
 
-       # --disable-phase
-       var opt_sloppy = new OptionBool("DEBUG: force lazy semantic analysis of the source-code", "--sloppy")
+       # --sloppy
+       var opt_sloppy = new OptionBool("Force lazy semantic analysis of the source-code (debug)", "--sloppy")
 
        redef init
        do
@@ -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
 
@@ -115,7 +124,6 @@ redef class ToolContext
                                phase.process_nmodule(nmodule)
                                if errcount != self.error_count then
                                        self.check_errors
-                                       break
                                end
                                errcount = self.error_count
                                for nclassdef in nmodule.n_classdefs do
@@ -128,7 +136,6 @@ redef class ToolContext
                                end
                                if errcount != self.error_count then
                                        self.check_errors
-                                       break
                                end
                                for na in vannot.annotations do
                                        var p = na.parent
@@ -138,8 +145,8 @@ redef class ToolContext
                                end
                                if errcount != self.error_count then
                                        self.check_errors
-                                       break
                                end
+                               phase.process_nmodule_after(nmodule)
                        end
                        self.check_errors
                end
@@ -248,4 +255,10 @@ abstract class Phase
        # Note that the order of the visit is the one of the file
        # @toimplement
        fun process_annotated_node(node: ANode, nat: AAnnotation) do end
+
+       # Specific actions to execute on the whole tree of a module
+       # Called at the end of a phase on a module
+       # Last called hook
+       # @toimplement
+       fun process_nmodule_after(nmodule: AModule) do end
 end