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.
19 $ template make_abs_prods()
20 $ set baseprod = {//prod/@ename}
23 class @ename special Prod end
31 readable writable attr _n_@name: List[@etype]
33 readable writable attr _n_@name: @etype
41 readable writable attr _n_base: $baseprod
42 readable writable attr _n_eof: EOF
46 $ template make_prods()
47 $ set baseprod = {//prod/@ename}
53 redef meth n_@name=(n: @etype)
63 private init empty_init do end
66 init init_${translate(@ename,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")} (
69 n_@{name}: Array[Object] [-sep ','-] # Should be Array[@etype]
71 n_@{name}: @etype [-sep ','-]
76 init init_${translate(@ename,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")}
81 _n_@{name} = new List[@{etype}]
89 if n_@{name} != null then
90 n_@{name}.parent = self
96 redef meth replace_child(old_child: PNode, new_child: PNode)
98 assert old_child != null
101 for i in [0.._n_@{name}.length[ do
102 if _n_@{name}[i] == old_child then
103 if new_child != null then
104 assert new_child isa @etype
105 _n_@{name}[i] = new_child
106 new_child.parent = self
108 _n_@{name}.remove_at(i)
114 if _n_@{name} == old_child then
115 if new_child != null then
116 new_child.parent = self
117 assert new_child isa @etype
118 _n_@{name} = new_child
128 redef meth visit_all(v: Visitor)
132 for n in _n_@{name} do
136 if _n_@{name} != null then
143 redef meth visit_all_reverse(v: Visitor)
148 var i = _n_@{name}.length
150 v.visit(_n_@{name}[i])
155 if _n_@{name} != null then
173 redef meth replace_child(old_child: PNode, new_child: PNode)
175 assert old_child != null
176 if _n_base == old_child then
177 if new_child == null then
179 new_child.parent = self
180 assert new_child isa $baseprod
183 old_child.parent = null
188 redef meth visit_all(v: Visitor)
190 if _n_base != null then
195 redef meth visit_all_reverse(v: Visitor)
197 if _n_base != null then