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
22 class ASTValidationVisitor
27 node
.accept_ast_validation
(self)
30 private var path
= new List[ANode]
31 private var seen
= new HashSet[ANode]
35 private fun accept_ast_validation
(v
: ASTValidationVisitor)
37 var parent
= self.parent
39 if v
.path
.length
> 1 then
40 var path_parent
= v
.path
[1]
41 if parent
== null then
42 self.parent
= path_parent
43 #debug "PARENT: expected parent: {path_parent}"
44 else if parent
!= path_parent
then
45 self.parent
= path_parent
46 debug
"PARENT: expected parent: {path_parent}, got {parent}"
50 if v
.seen
.has
(self) then
51 debug
"DUPLICATE: already seen node. NOTATREE"
55 if _location
== null then
56 #debug "LOCATION: unlocated node {v.path.join(", ")}"
57 _location
= self.parent
.location
64 redef class AAnnotations
65 redef fun accept_ast_validation
(v
)
67 # Do not enter in annotations
72 redef fun accept_ast_validation
(v
)
75 if mtype
== null and not is_typed
then
76 debug
"TYPING: untyped expression"
81 redef class APlaceholderExpr
82 redef fun accept_ast_validation
(v
)
85 debug
"PARENT: remaining placeholder"