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 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
47 n_base: nullable $baseprod,
57 $ template make_prods()
58 $ set baseprod = {//prod/@ename}
62 init init_${translate(@ename,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")} (
65 n_@{name}: Collection[Object][-sep ','-] # Should be Collection[@etype]
67 n_@{name}: nullable @etype[-sep ','-]
72 init init_${translate(@ename,"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")}
77 _n_@{name}.unsafe_add_all(n_@{name})
81 if n_@{name} != null then n_@{name}.parent = self
83 _n_@name = n_@{name}.as(not null)
84 n_@{name}.parent = self
90 redef fun replace_child(old_child: PNode, new_child: nullable PNode)
94 if _n_@{name}.replace_child(old_child, new_child) then return
96 if _n_@{name} == old_child then
98 n_@{name} = new_child.as(nullable @etype)
100 n_@{name} = new_child.as(@etype)
111 redef fun n_@{name}=(node)
115 if node != null then node.parent = self
124 redef fun visit_all(v: Visitor)
128 _n_@{name}.visit_all(v)
130 v.enter_visit(_n_@{name})
138 redef fun replace_child(old_child: PNode, new_child: nullable PNode)
140 if _n_base == old_child then
141 if new_child == null then
143 new_child.parent = self
144 assert new_child isa $baseprod
147 old_child.parent = null
152 redef fun visit_all(v: Visitor)
154 if _n_base != null then
155 v.enter_visit(_n_base.as(not null))
157 v.enter_visit(_n_eof)