Rename REAMDE to README.md
[nit.git] / src / astvalidation.nit
index a3c4bbc..2883197 100644 (file)
@@ -15,7 +15,6 @@
 # Check the consitency of AST
 module astvalidation
 
-private import typing
 intrude import parser
 import astbuilder
 
@@ -23,9 +22,7 @@ class ASTValidationVisitor
        super Visitor
        redef fun visit(node)
        do
-               path.unshift(node)
                node.accept_ast_validation(self)
-               path.shift
        end
        private var path = new List[ANode]
        private var seen = new HashSet[ANode]
@@ -35,33 +32,37 @@ redef class ANode
        private fun accept_ast_validation(v: ASTValidationVisitor)
        do
                var parent = self.parent
+               var path = v.path
 
-               if v.path.length > 1 then
-                       var path_parent = v.path[1]
+               if path.length > 0 then
+                       var path_parent = v.path.first
                        if parent == null then
                                self.parent = path_parent
                                #debug "PARENT: expected parent: {path_parent}"
+                               v.seen.add(self)
                        else if parent != path_parent then
                                self.parent = path_parent
-                               debug "PARENT: expected parent: {path_parent}, got {parent}"
+                               if v.seen.has(self) then
+                                       debug "DUPLICATE (NOTATREE): already seen node with parent {parent} now with {path_parent}."
+                               else
+                                       v.seen.add(self)
+                                       debug "PARENT: expected parent: {path_parent}, got {parent}"
+                               end
                        end
                end
 
-               if v.seen.has(self) then
-                       debug "DUPLICATE: already seen node. NOTATREE"
-               end
-               v.seen.add(self)
-
                if not isset _location then
                        #debug "LOCATION: unlocated node {v.path.join(", ")}"
                        _location = self.parent.location
                end
 
+               path.unshift(self)
                visit_all(v)
+               path.shift
        end
 end
 
-redef class AAnnotations
+redef class AAnnotation
        redef fun accept_ast_validation(v)
        do
                # Do not enter in annotations
@@ -73,7 +74,7 @@ redef class AExpr
        do
                super
                if mtype == null and not is_typed then
-                       debug "TYPING: untyped expression"
+                       #debug "TYPING: untyped expression"
                end
        end
 end