Moving the astvalidation module in astbuilder
authorFlorian Deljarry <deljarry.florian@gmail.com>
Wed, 27 Feb 2019 16:31:02 +0000 (11:31 -0500)
committerFlorian Deljarry <deljarry.florian@gmail.com>
Wed, 27 Feb 2019 17:08:49 +0000 (12:08 -0500)
Signed-off-by: Florian Deljarry <deljarry.florian@gmail.com>

src/astbuilder.nit
src/astvalidation.nit [deleted file]
src/frontend/explain_assert.nit
src/frontend/parallelization_phase.nit
src/transform.nit

index 79d0ba1..6340ad2 100644 (file)
@@ -159,6 +159,14 @@ redef class AExpr
                print "add not implemented in {inspect}"
                abort
        end
+
+       redef fun accept_ast_validation(v)
+       do
+               super
+               if mtype == null and not is_typed then
+                       #debug "TYPING: untyped expression"
+               end
+       end
 end
 
 # A placeholder for a `AExpr` node
@@ -173,6 +181,12 @@ class APlaceholderExpr
        private init make
        do
        end
+
+       redef fun accept_ast_validation(v)
+       do
+               super
+               debug "PARENT: remaining placeholder"
+       end
 end
 
 redef class ABlockExpr
@@ -354,3 +368,66 @@ redef class AVarAssignExpr
        end
 end
 
+# Check the consitency of AST
+class ASTValidationVisitor
+       super Visitor
+       redef fun visit(node)
+       do
+               node.accept_ast_validation(self)
+       end
+       private var path = new CircularArray[ANode]
+       private var seen = new HashSet[ANode]
+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
+               var path = v.path
+
+               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
+                               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 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 AAnnotation
+       redef fun accept_ast_validation(v)
+       do
+               # Do not enter in annotations
+       end
+end
diff --git a/src/astvalidation.nit b/src/astvalidation.nit
deleted file mode 100644 (file)
index cf3da76..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# Check the consitency of AST
-module astvalidation
-
-intrude import parser
-import astbuilder
-
-class ASTValidationVisitor
-       super Visitor
-       redef fun visit(node)
-       do
-               node.accept_ast_validation(self)
-       end
-       private var path = new CircularArray[ANode]
-       private var seen = new HashSet[ANode]
-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
-               var path = v.path
-
-               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
-                               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 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 AAnnotation
-       redef fun accept_ast_validation(v)
-       do
-               # Do not enter in annotations
-       end
-end
-
-redef class AExpr
-       redef fun accept_ast_validation(v)
-       do
-               super
-               if mtype == null and not is_typed then
-                       #debug "TYPING: untyped expression"
-               end
-       end
-end
-
-redef class APlaceholderExpr
-       redef fun accept_ast_validation(v)
-       do
-               super
-               debug "PARENT: remaining placeholder"
-       end
-end
index 326f588..f8b4710 100644 (file)
@@ -35,7 +35,6 @@ module explain_assert
 import astbuilder
 intrude import literal # for value=
 intrude import typing # for mtype=
-import astvalidation
 
 import explain_assert_api
 
index 080efe6..b5cc9fd 100644 (file)
@@ -22,7 +22,6 @@ private import parser_util
 import modelize
 import astbuilder
 private import annotation
-private import astvalidation
 
 redef class ToolContext
        # Transforms a function annotated with "threaded"
index 3e5865b..3499d9b 100644 (file)
@@ -17,7 +17,6 @@
 module transform
 
 import astbuilder
-import astvalidation
 import semantize
 intrude import semantize::scope
 intrude import semantize::typing