astvalidation: add `ANode::validate` to simplify validation
authorJean Privat <jean@pryen.org>
Sat, 17 Oct 2015 02:18:07 +0000 (22:18 -0400)
committerJean Privat <jean@pryen.org>
Sat, 17 Oct 2015 02:18:07 +0000 (22:18 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/astvalidation.nit

index 2883197..183b4b2 100644 (file)
@@ -29,6 +29,18 @@ class ASTValidationVisitor
 end
 
 redef class ANode
+       # Recursively validate a AST node.
+       # This ensure that location and parenting are defined and coherent.
+       #
+       # After complex low-level AST manipulation and construction,
+       # it is recommended to call it.
+       #
+       # Note: this just instantiate and run an `ASTValidationVisitor`.
+       fun validate
+       do
+               (new ASTValidationVisitor).enter_visit(self)
+       end
+
        private fun accept_ast_validation(v: ASTValidationVisitor)
        do
                var parent = self.parent