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] = null
33 readable writable attr _n_@name: @etype = null
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}: Collection[Object] [-sep ','-] # Should be Collection[@etype]
71 n_@{name}: @etype [-sep ','-]
76 init init_${translate(@ename,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")}
82 _n_@{name} = new List[@{etype}]
90 if n_@{name} != null then
91 n_@{name}.parent = self
97 redef meth replace_child(old_child: PNode, new_child: PNode)
99 assert old_child != null
102 for i in [0.._n_@{name}.length[ do
103 if _n_@{name}[i] == old_child then
104 if new_child != null then
105 assert new_child isa @etype
106 _n_@{name}[i] = new_child
107 new_child.parent = self
109 _n_@{name}.remove_at(i)
115 if _n_@{name} == old_child then
116 if new_child != null then
117 new_child.parent = self
118 assert new_child isa @etype
119 _n_@{name} = new_child
129 redef meth visit_all(v: Visitor)
133 for n in _n_@{name} do
137 if _n_@{name} != null then
144 redef meth visit_all_reverse(v: Visitor)
149 var i = _n_@{name}.length
151 v.visit(_n_@{name}[i])
156 if _n_@{name} != null then
174 redef meth replace_child(old_child: PNode, new_child: PNode)
176 assert old_child != null
177 if _n_base == old_child then
178 if new_child == null then
180 new_child.parent = self
181 assert new_child isa $baseprod
184 old_child.parent = null
189 redef meth visit_all(v: Visitor)
191 if _n_base != null then
196 redef meth visit_all_reverse(v: Visitor)
198 if _n_base != null then