phase: add option --disable-phase
authorJean Privat <jean@pryen.org>
Thu, 27 Mar 2014 01:00:56 +0000 (21:00 -0400)
committerJean Privat <jean@pryen.org>
Thu, 27 Mar 2014 01:00:56 +0000 (21:00 -0400)
Can be used to desactivate specific phases when testing and debugging.
The option can also lists the sequence of phases and their dependencies.

Signed-off-by: Jean Privat <jean@pryen.org>

src/modelbuilder.nit
src/phase.nit

index b916077..614483e 100644 (file)
@@ -65,6 +65,7 @@ redef class ToolContext
                        mainmodule.set_imported_mmodules(mmodules)
                end
                for phase in phases_list do
+                       if phase.disabled then continue
                        phase.process_mainmodule(mainmodule, mmodules)
                end
        end
index 6e96e96..ace2cb9 100644 (file)
@@ -27,6 +27,43 @@ redef class ToolContext
        # it is often simpler to use the constructor in `Phase`
        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")
+
+       redef init
+       do
+               super
+
+               option_context.add_option(opt_disable_phase)
+       end
+
+       redef fun process_options(args)
+       do
+               super
+
+               for v in opt_disable_phase.value do
+                       if v == "list" then
+                               for p in phases_list do
+                                       var deps = p.in_hierarchy.direct_greaters
+                                       if deps.is_empty then
+                                               print p
+                                       else
+                                               print "{p} (dep: {deps.join(", ")})"
+                                       end
+                               end
+                               exit 0
+                       end
+
+                       var found = false
+                       for p in phases do
+                               if v != p.to_s then continue
+                               found = true
+                               p.disabled = true
+                       end
+                       if not found then fatal_error(null, "Error: no phase named `{v}`. Use `list` to list all phases.")
+               end
+       end
+
        fun phases_list: Sequence[Phase]
        do
                var phases = self.phases.to_a
@@ -50,6 +87,7 @@ redef class ToolContext
                for nmodule in nmodules do
                        self.info("Semantic analysis module {nmodule.location.file.filename}", 2)
                        for phase in phases do
+                               if phase.disabled then continue
                                self.info(" phase: {phase}", 3)
                                assert phase.toolcontext == self
                                var errcount = self.error_count
@@ -125,6 +163,10 @@ abstract class Phase
        # By default, the name is the lowercased prefix of the classname
        redef fun to_s do return class_name.strip_extension("Phase").to_lower
 
+       # Is the phase globally disabled?
+       # A disabled phase is not called automatically called by `ToolContext::run_phases` and cie.
+       var disabled = false
+
        # Specific actions to execute on the whole tree of a module
        # @toimplement
        fun process_nmodule(nmodule: AModule) do end