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
26 node
.accept_ast_validation
(self)
29 private var path
= new List[ANode]
30 private var seen
= new HashSet[ANode]
34 private fun accept_ast_validation
(v
: ASTValidationVisitor)
36 var parent
= self.parent
38 if v
.path
.length
> 1 then
39 var path_parent
= v
.path
[1]
40 if parent
== null then
41 self.parent
= path_parent
42 #debug "PARENT: expected parent: {path_parent}"
43 else if parent
!= path_parent
then
44 self.parent
= path_parent
45 debug
"PARENT: expected parent: {path_parent}, got {parent}"
49 if v
.seen
.has
(self) then
50 debug
"DUPLICATE: already seen node. NOTATREE"
54 if not isset _location
then
55 #debug "LOCATION: unlocated node {v.path.join(", ")}"
56 _location
= self.parent
.location
63 redef class AAnnotations
64 redef fun accept_ast_validation
(v
)
66 # Do not enter in annotations
71 redef fun accept_ast_validation
(v
)
74 if mtype
== null and not is_typed
then
75 debug
"TYPING: untyped expression"
80 redef class APlaceholderExpr
81 redef fun accept_ast_validation
(v
)
84 debug
"PARENT: remaining placeholder"