/[eiffelstudio]/branches/CAT_mono/Src/framework/parser/AST/visitor/ast_formal_generics_pass2.e
ViewVC logotype

Contents of /branches/CAT_mono/Src/framework/parser/AST/visitor/ast_formal_generics_pass2.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 69687 - (show annotations)
Wed Jul 25 18:55:08 2007 UTC (12 years, 4 months ago) by martins
File size: 7545 byte(s)
* monomorph for formals
* covaraince for generics (syntax only)
1 indexing
2 description: "[
3 Do a second pass over the generic declaration of a class.
4 If its not a formal record it in the supplier list of the current class.
5 ]"
6 legal: "See notice at end of class."
7 status: "See notice at end of class."
8 date: "$Date$"
9 revision: "$Revision$"
10
11 class
12 AST_FORMAL_GENERICS_PASS2
13
14 inherit
15 AST_NULL_VISITOR
16 redefine
17 process_like_id_as, process_like_cur_as,
18 process_formal_as, process_class_type_as, process_none_type_as,
19 process_bits_as, process_bits_symbol_as,
20 process_named_tuple_type_as, process_type_dec_as
21 end
22
23 COMPILER_EXPORTER
24 export
25 {NONE} all
26 end
27
28 create
29 make
30
31 feature -- Initialisation
32
33 make (a_ast_factory: AST_FACTORY; a_suppliers: SUPPLIERS_AS; a_formal_parameters: ARRAYED_LIST [FORMAL_AS])
34 -- Initialise
35 --
36 -- `a_ast_factory' is needed to instatiate AST nodes.
37 -- `a_suppliers' every identifier which is not a formal is recorded here.
38 -- `a_formal_parameters' list of formals of the current class.
39 require
40 a_ast_factory_not_void: a_ast_factory /= Void
41 a_suppliers_not_void: a_suppliers /= Void
42 a_formal_parameters_not_void: a_formal_parameters /= Void
43 do
44 ast_factory := a_ast_factory
45 suppliers := a_suppliers
46 formal_parameters := a_formal_parameters
47 ensure
48 ast_factory_set: ast_factory = a_ast_factory
49 suppliers_set: suppliers = a_suppliers
50 formal_parameters_set: formal_parameters = a_formal_parameters
51 end
52
53 feature -- Access
54
55 has_node_changed: BOOLEAN
56 -- Has the current call to the visitor created a new node object?
57 --| So far we replace CL_TYPE_AS with FORMAL_AS wherever needed.
58 do
59 Result := new_node /= Void
60 end
61
62 consume_node
63 -- Consumes a node, resets `has_node_changed' and sets `last_consumed_node'
64 require
65 has_node_changed: has_node_changed
66 do
67 last_consumed_node := new_node
68 new_node := Void
69 ensure
70 not_has_node_changed: not has_node_changed
71 last_consumed_node_set: last_consumed_node /= Void and then last_consumed_node = old new_node
72 end
73
74 last_consumed_node: TYPE_AS
75 -- Last consumed node.
76
77 feature {NONE} -- Implementation: Access
78
79 new_node: TYPE_AS
80 -- This is the new node which was produced to replace the node which was last visited.
81 --| Usually we found the need to change the object type.
82
83 ast_factory: AST_FACTORY
84 -- AST Factory
85 --| Needed to create instances of type FORMAL_AS.
86
87 suppliers: SUPPLIERS_AS
88 -- Suppliers of current class.
89 --| Here we insert all supplier dependencies found
90
91 formal_parameters: ARRAYED_LIST [FORMAL_AS]
92 -- A list of all formal generic type parameters of the class.
93
94 feature {NONE} -- Visitor implementation
95
96 process_formal_as (l_as: FORMAL_AS)
97 do
98 check not_has_node_changed: not has_node_changed end
99 -- Do nothing.
100 end
101
102 process_class_type_as (l_as: CLASS_TYPE_AS)
103 local
104 l_class_name: ID_AS
105 l_formal_type, l_new_formal: FORMAL_AS
106 l_generics: TYPE_LIST_AS
107 do
108 check not_has_node_changed: not has_node_changed end
109 l_class_name := l_as.class_name
110 if l_as.generics = Void then
111 -- Check whether this class type should actually be a formal.
112 -- If so, create a new formal instance and signal that the object has changed.
113 from
114 formal_parameters.start
115 until
116 formal_parameters.after
117 loop
118 l_formal_type := formal_parameters.item
119 if l_class_name.is_equal (l_formal_type.name) then
120 l_new_formal := ast_factory.new_formal_as (l_class_name, l_formal_type.is_reference,
121 l_formal_type.is_expanded, l_formal_type.is_monomorph, l_formal_type.monomorph_keyword)
122 l_new_formal.set_position (l_formal_type.position)
123 -- Jump out of the loop.
124 formal_parameters.finish
125 end
126 formal_parameters.forth
127 end
128
129 if l_new_formal /= Void then
130 -- We changed, update `new_node'
131 -- After we set `new_node' the query `has_node_changed' will yield true.
132 new_node := l_new_formal
133 else
134 -- We have not found a formal. So it is indeed a class type.
135 -- Add the class type to the suppliers!
136 suppliers.insert_supplier_id (l_class_name)
137 end
138 else
139 -- A formal can never be a base class of a generic class.
140 -- Something like H -> G[INTEGER] is illegal.
141 -- The error will be caught later.
142 suppliers.insert_supplier_id (l_class_name)
143 from
144 l_generics := l_as.generics
145 l_generics.start
146 until
147 l_generics.after
148 loop
149 l_generics.item.process (Current)
150 -- If we changed the object, we need to replace the references.
151 if has_node_changed then
152 consume_node
153 l_generics.replace (last_consumed_node)
154 check is_replaced: l_generics.item = last_consumed_node end
155 end
156 l_generics.forth
157 end
158 end
159
160 end
161
162 process_named_tuple_type_as (l_as: NAMED_TUPLE_TYPE_AS)
163 local
164 l_generics: EIFFEL_LIST [TYPE_DEC_AS]
165 do
166 check not_has_node_changed: not has_node_changed end
167 from
168 l_generics := l_as.generics
169 l_generics.start
170 until
171 l_generics.after
172 loop
173 l_generics.item.type.process (Current)
174 -- If we changed the object, we need to replace the references.
175 if has_node_changed then
176 consume_node
177 l_generics.item.set_type (last_consumed_node)
178 end
179 l_generics.forth
180 end
181 end
182
183 feature -- Types which should not occur
184
185 process_like_id_as (l_as: LIKE_ID_AS)
186 do
187 -- This type is not a formal and has no generics.
188 -- Do nothing.
189 -- An error will be thrown later.
190 end
191
192 process_like_cur_as (l_as: LIKE_CUR_AS)
193 do
194 -- This type is not a formal and has no generics.
195 -- Do nothing.
196 -- An error will be thrown later.
197 end
198
199 process_type_dec_as (l_as: TYPE_DEC_AS)
200 do
201 l_as.type.process (Current)
202 if has_node_changed then
203 l_as.set_type (new_node)
204 end
205 end
206
207 process_none_type_as (l_as: NONE_TYPE_AS)
208 do
209 -- This type is not a formal and has no generics.
210 -- Do nothing.
211 end
212
213 process_bits_as (l_as: BITS_AS)
214 do
215 -- This type is not a formal and has no generics.
216 -- Do nothing.
217 end
218
219 process_bits_symbol_as (l_as: BITS_SYMBOL_AS)
220 do
221 -- This type is not a formal and has no generics.
222 -- Do nothing.
223 end
224
225 indexing
226 copyright: "Copyright (c) 1984-2006, Eiffel Software"
227 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
228 licensing_options: "http://www.eiffel.com/licensing"
229 copying: "[
230 This file is part of Eiffel Software's Eiffel Development Environment.
231
232 Eiffel Software's Eiffel Development Environment is free
233 software; you can redistribute it and/or modify it under
234 the terms of the GNU General Public License as published
235 by the Free Software Foundation, version 2 of the License
236 (available at the URL listed under "license" above).
237
238 Eiffel Software's Eiffel Development Environment is
239 distributed in the hope that it will be useful, but
240 WITHOUT ANY WARRANTY; without even the implied warranty
241 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
242 See the GNU General Public License for more details.
243
244 You should have received a copy of the GNU General Public
245 License along with Eiffel Software's Eiffel Development
246 Environment; if not, write to the Free Software Foundation,
247 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
248 ]"
249 source: "[
250 Eiffel Software
251 356 Storke Road, Goleta, CA 93117 USA
252 Telephone 805-685-1006, Fax 805-685-6869
253 Website http://www.eiffel.com
254 Customer support http://support.eiffel.com
255 ]"
256
257 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date ID Revision

  ViewVC Help
Powered by ViewVC 1.1.23