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 var _n_@name: List[@etype] = new List[@etype]
33 readable var _n_@name: nullable @etype = null
35 readable var _n_@name: @etype
44 readable var _n_base: nullable $baseprod
45 readable var _n_eof: EOF
49 $ template make_prods()
50 $ set baseprod = {//prod/@ename}
53 private init empty_init do end
56 init init_${translate(@ename,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")} (
59 n_@{name}: Collection[Object][-sep ','-] # Should be Collection[@etype]
61 n_@{name}: nullable @etype[-sep ','-]
66 init init_${translate(@ename,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")}
80 if n_@{name} != null then
81 n_@{name}.parent = self
84 _n_@name = n_@{name}.as(not null)
85 n_@{name}.parent = self
91 redef fun replace_child(old_child: PNode, new_child: nullable PNode)
95 for i in [0.._n_@{name}.length[ do
96 if _n_@{name}[i] == old_child then
97 if new_child != null then
98 assert new_child isa @etype
99 _n_@{name}[i] = new_child
100 new_child.parent = self
102 _n_@{name}.remove_at(i)
108 if _n_@{name} == old_child then
109 if new_child != null then
110 new_child.parent = self
111 assert new_child isa @etype
112 _n_@{name} = new_child
126 redef fun visit_all(v: Visitor)
130 for n in _n_@{name} do
135 if _n_@{name} != null then
136 v.enter_visit(_n_@{name}.as(not null))
139 v.enter_visit(_n_@{name})
149 n_base: nullable $baseprod,
156 redef fun replace_child(old_child: PNode, new_child: nullable PNode)
158 if _n_base == old_child then
159 if new_child == null then
161 new_child.parent = self
162 assert new_child isa $baseprod
165 old_child.parent = null
170 redef fun visit_all(v: Visitor)
172 if _n_base != null then
173 v.enter_visit(_n_base.as(not null))
175 v.enter_visit(_n_eof)