1 $ // This file is part of NIT ( http://www.nitlanguage.org ).
3 $ // Copyright 2008 Jean Privat <jean@pryen.org>
4 $ // Based on algorithms developped for ( http://www.sablecc.org/ ).
6 $ // Licensed under the Apache License, Version 2.0 (the "License");
7 $ // you may not use this file except in compliance with the License.
8 $ // You may obtain a copy of the License at
10 $ // http://www.apache.org/licenses/LICENSE-2.0
12 $ // Unless required by applicable law or agreed to in writing, software
13 $ // distributed under the License is distributed on an "AS IS" BASIS,
14 $ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 $ // See the License for the specific language governing permissions and
16 $ // limitations under the License.
18 $ template make_abs_prods()
19 $ set baseprod = {//prod/@ename}
22 class @ename special Prod end
30 readable writable var _n_@name: List[@etype] = new List[@etype]
33 readable writable var _n_@name: nullable @etype = null
35 readable writable var _n_@name: @etype
44 readable writable var _n_base: nullable $baseprod
45 readable writable var _n_eof: EOF
49 $ template make_prods()
50 $ set baseprod = {//prod/@ename}
70 private init empty_init do end
73 init init_${translate(@ename,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")} (
76 n_@{name}: Collection[Object][-sep ','-] # Should be Collection[@etype]
78 n_@{name}: nullable @etype[-sep ','-]
83 init init_${translate(@ename,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")}
97 if n_@{name} != null then
98 n_@{name}.parent = self
101 _n_@name = n_@{name}.as(not null)
102 n_@{name}.parent = self
108 redef fun replace_child(old_child: PNode, new_child: nullable PNode)
112 for i in [0.._n_@{name}.length[ do
113 if _n_@{name}[i] == old_child then
114 if new_child != null then
115 assert new_child isa @etype
116 _n_@{name}[i] = new_child
117 new_child.parent = self
119 _n_@{name}.remove_at(i)
125 if _n_@{name} == old_child then
126 if new_child != null then
127 new_child.parent = self
128 assert new_child isa @etype
129 _n_@{name} = new_child
143 redef fun visit_all(v: Visitor)
147 for n in _n_@{name} do
152 if _n_@{name} != null then
153 v.enter_visit(_n_@{name}.as(not null))
156 v.enter_visit(_n_@{name})
162 redef fun visit_all_reverse(v: Visitor)
167 var i = _n_@{name}.length
169 v.enter_visit(_n_@{name}[i])
175 if _n_@{name} != null then
176 v.enter_visit(_n_@{name}.as(not null))
179 v.enter_visit(_n_@{name})
189 n_base: nullable $baseprod,
196 redef fun replace_child(old_child: PNode, new_child: nullable PNode)
198 if _n_base == old_child then
199 if new_child == null then
201 new_child.parent = self
202 assert new_child isa $baseprod
205 old_child.parent = null
210 redef fun visit_all(v: Visitor)
212 if _n_base != null then
213 v.enter_visit(_n_base.as(not null))
217 redef fun visit_all_reverse(v: Visitor)
219 if _n_base != null then
220 v.enter_visit(_n_base.as(not null))