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 var _n_@name: List[@etype] = new List[@etype]
34 readable writable var _n_@name: nullable @etype = null
36 readable writable var _n_@name: @etype
45 readable writable var _n_base: nullable $baseprod
46 readable writable var _n_eof: EOF
50 $ template make_prods()
51 $ set baseprod = {//prod/@ename}
71 private init empty_init do end
74 init init_${translate(@ename,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")} (
77 n_@{name}: Collection[Object] [-sep ','-] # Should be Collection[@etype]
79 n_@{name}: nullable @etype [-sep ','-]
84 init init_${translate(@ename,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")}
98 if n_@{name} != null then
99 n_@{name}.parent = self
102 _n_@name = n_@{name}.as(not null)
103 n_@{name}.parent = self
109 redef fun replace_child(old_child: PNode, new_child: nullable PNode)
113 for i in [0.._n_@{name}.length[ do
114 if _n_@{name}[i] == old_child then
115 if new_child != null then
116 assert new_child isa @etype
117 _n_@{name}[i] = new_child
118 new_child.parent = self
120 _n_@{name}.remove_at(i)
126 if _n_@{name} == old_child then
127 if new_child != null then
128 new_child.parent = self
129 assert new_child isa @etype
130 _n_@{name} = new_child
144 redef fun visit_all(v: Visitor)
148 for n in _n_@{name} do
153 if _n_@{name} != null then
154 v.visit(_n_@{name}.as(not null))
163 redef fun visit_all_reverse(v: Visitor)
168 var i = _n_@{name}.length
170 v.visit(_n_@{name}[i])
176 if _n_@{name} != null then
177 v.visit(_n_@{name}.as(not null))
190 n_base: nullable $baseprod,
197 redef fun replace_child(old_child: PNode, new_child: nullable PNode)
199 if _n_base == old_child then
200 if new_child == null then
202 new_child.parent = self
203 assert new_child isa $baseprod
206 old_child.parent = null
211 redef fun visit_all(v: Visitor)
213 if _n_base != null then
214 v.visit(_n_base.as(not null))
218 redef fun visit_all_reverse(v: Visitor)
220 if _n_base != null then
221 v.visit(_n_base.as(not null))