1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Check the consitency of AST
21 class ASTValidationVisitor
25 node
.accept_ast_validation
(self)
27 private var path
= new List[ANode]
28 private var seen
= new HashSet[ANode]
32 private fun accept_ast_validation
(v
: ASTValidationVisitor)
34 var parent
= self.parent
37 if path
.length
> 0 then
38 var path_parent
= v
.path
.first
39 if parent
== null then
40 self.parent
= path_parent
41 #debug "PARENT: expected parent: {path_parent}"
43 else if parent
!= path_parent
then
44 self.parent
= path_parent
45 if v
.seen
.has
(self) then
46 debug
"DUPLICATE (NOTATREE): already seen node with parent {parent} now with {path_parent}."
49 debug
"PARENT: expected parent: {path_parent}, got {parent}"
54 if not isset _location
then
55 #debug "LOCATION: unlocated node {v.path.join(", ")}"
56 _location
= self.parent
.location
65 redef class AAnnotation
66 redef fun accept_ast_validation
(v
)
68 # Do not enter in annotations
73 redef fun accept_ast_validation
(v
)
76 if mtype
== null and not is_typed
then
77 #debug "TYPING: untyped expression"
82 redef class APlaceholderExpr
83 redef fun accept_ast_validation
(v
)
86 debug
"PARENT: remaining placeholder"