grammar: accepts new-factory with code
[nit.git] / src / phase.nit
index ace2cb9..d1cc1cb 100644 (file)
@@ -71,6 +71,9 @@ redef class ToolContext
                return phases
        end
 
+       # Set of already analyzed modules.
+       private var phased_modules = new HashSet[AModule]
+
        # Run all registered phases on a set of modules
        fun run_phases(nmodules: Collection[AModule])
        do
@@ -85,7 +88,14 @@ redef class ToolContext
                end
 
                for nmodule in nmodules do
+                       if phased_modules.has(nmodule) then continue
+                       phased_modules.add nmodule
+
                        self.info("Semantic analysis module {nmodule.location.file.filename}", 2)
+
+                       var vannot = new AnnotationPhaseVisitor
+                       vannot.enter_visit(nmodule)
+
                        for phase in phases do
                                if phase.disabled then continue
                                self.info(" phase: {phase}", 3)
@@ -98,20 +108,20 @@ redef class ToolContext
                                end
                                errcount = self.error_count
                                for nclassdef in nmodule.n_classdefs do
-                                       self.info(" phase: {phase} for {nclassdef.location}", 3)
                                        assert phase.toolcontext == self
                                        phase.process_nclassdef(nclassdef)
                                        for npropdef in nclassdef.n_propdefs do
                                                assert phase.toolcontext == self
-                                               phase.process_npropdef(npropdef)
+                                               phase_process_npropdef(phase, npropdef)
                                        end
                                end
                                if errcount != self.error_count then
                                        self.check_errors
                                        break
                                end
-                               var v = new AnnotationPhaseVisitor(phase)
-                               v.enter_visit(nmodule)
+                               for na in vannot.annotations do
+                                       phase.process_annotated_node(na.parent.parent.as(not null), na)
+                               end
                                if errcount != self.error_count then
                                        self.check_errors
                                        break
@@ -122,20 +132,27 @@ redef class ToolContext
 
                var time1 = get_time
                self.info("*** END SEMANTIC ANALYSIS: {time1-time0} ***", 2)
+
+               errors_info
+       end
+
+       fun phase_process_npropdef(phase: Phase, npropdef: APropdef)
+       do
+               phase.process_npropdef(npropdef)
        end
 end
 
+# Collect all annotation
 private class AnnotationPhaseVisitor
        super Visitor
 
-       var phase: Phase
-
-       init(phase: Phase) do self.phase = phase
+       # The collected annotations
+       var annotations = new Array[AAnnotation]
 
        redef fun visit(n)
        do
                n.visit_all(self)
-               if n isa AAnnotation then phase.process_annotated_node(n.parent.parent.as(not null), n)
+               if n isa AAnnotation then annotations.add n
        end
 end