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 super Prod end
30 var n_@name: List[@etype] = new List[@etype]
33 var n_@name: nullable @etype = null is writable
35 var n_@name: @etype is writable, noinit
44 var n_base: nullable $baseprod is writable, noinit
45 var n_eof: EOF is writable, noinit
47 n_base: nullable $baseprod,
56 $ template make_prods()
57 $ set baseprod = {//prod/@ename}
61 init init_${translate(@ename,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")} (
64 n_@{name}: Collection[Object][-sep ','-] # Should be Collection[@etype]
66 n_@{name}: nullable @etype[-sep ','-]
71 init init_${translate(@ename,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")}
76 self.n_@{name}.unsafe_add_all(n_@{name})
80 if n_@{name} != null then n_@{name}.parent = self
82 _n_@name = n_@{name}.as(not null)
83 n_@{name}.parent = self
89 redef fun replace_child(old_child: PNode, new_child: nullable PNode)
93 if n_@{name}.replace_child(old_child, new_child) then return
95 if _n_@{name} == old_child then
97 n_@{name} = new_child.as(nullable @etype)
99 n_@{name} = new_child.as(@etype)
110 redef fun n_@{name}=(node)
114 if node != null then node.parent = self
123 redef fun visit_all(v: Visitor)
127 n_@{name}.visit_all(v)
129 v.enter_visit(_n_@{name})
137 redef fun replace_child(old_child: PNode, new_child: nullable PNode)
139 if _n_base == old_child then
140 if new_child == null then
142 new_child.parent = self
143 assert new_child isa $baseprod
146 old_child.parent = null
151 redef fun visit_all(v: Visitor)
153 if _n_base != null then
154 v.enter_visit(_n_base.as(not null))
156 v.enter_visit(_n_eof)