phase: Do not revisit all annotations for each phase
authorJean Privat <jean@pryen.org>
Wed, 27 Aug 2014 15:40:58 +0000 (11:40 -0400)
committerJean Privat <jean@pryen.org>
Wed, 27 Aug 2014 15:40:58 +0000 (11:40 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/phase.nit

index 0705139..7cefaf0 100644 (file)
@@ -86,6 +86,10 @@ redef class ToolContext
 
                for nmodule in nmodules do
                        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)
@@ -109,8 +113,9 @@ redef class ToolContext
                                        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
@@ -124,17 +129,17 @@ redef class ToolContext
        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