/[eiffelstudio]/branches/CAT_mono/Src/Eiffel/eiffel/genericity/multi_formal_i.e
ViewVC logotype

Contents of /branches/CAT_mono/Src/Eiffel/eiffel/genericity/multi_formal_i.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 69868 - (show annotations)
Fri Aug 3 22:28:26 2007 UTC (12 years, 4 months ago) by martins
File size: 8578 byte(s)
enabled more types to store monomorph information
1 indexing
2 description: "[
3 Representation of a compiled multi constrained formal parameter.
4 Wherever possible we replace the formals by its selected constraint (like in a call g.f,
5 where g's type is a multi-constrained formal generic.)
6 In cases where this is not possible, like in g := another_conformant_to_type_of_g we still have to provide the right
7 answers to the questions whether it is expanded or not. For this purposes this class is intended.
8 ]"
9 legal: "See notice at end of class."
10 status: "See notice at end of class."
11 date: "$Date$"
12 revision: "$Revision$"
13
14 class MULTI_FORMAL_I
15
16 inherit
17 TYPE_I
18 redefine
19 is_formal, is_multi_constrained, is_valid, same_as, has_true_formal, has_formal, instantiation_in,
20 complete_instantiation_in,
21 generated_id, is_explicit, generate_gen_type_il,
22 generate_cid, generate_cid_array, generate_cid_init,
23 make_gen_type_byte_code, is_reference, is_expanded, is_standalone, is_monomorph
24 end
25
26 SHARED_BYTE_CONTEXT
27 export
28 {NONE} all
29 end
30
31 create
32 make
33
34 feature {NONE} -- Initialization
35
36 make (is_ref: like is_reference; is_exp: like is_expanded; is_mono: like is_monomorph; i: like position; a_constraint_position: like constraint_position) is
37 -- Assign `i' to `position'.
38 require
39 valid_position: i > 0
40 do
41 is_expanded := is_exp
42 is_monomorph := is_mono
43 position := i
44 constraint_position := a_constraint_position
45 ensure
46 constraint_position_set: a_constraint_position = constraint_position
47 is_expanded_set: is_expanded = is_exp
48 is_monomorph_set: is_monomorph = is_mono
49 position_set: position = i
50 end
51
52 feature -- Status report
53
54 constraint_position: INTEGER
55
56 element_type: INTEGER_8 is
57 -- Formal element type.
58 do
59 -- Before we said that we should not be called, but now there is one case
60 -- where we are called, it is when we try to create a NATIVE_ARRAY [G] where
61 -- G is a formal generic parameter. In this case we actually considered that
62 -- we have for the type system a NATIVE_ARRAY [SYSTEM_OBJECT].
63 Result := {MD_SIGNATURE_CONSTANTS}.element_type_object
64 end
65
66 tuple_code: INTEGER_8 is
67 -- Multi Formal tuple code.
68 do
69 -- Before we said that we should not be called, but now we use `tuple_code' for the
70 -- argument passing for our new implementation of expanded conformance with generics.
71 -- For example the eweasel test#multicon005 exercises this code.
72 Result := {SHARED_GEN_CONF_LEVEL}.reference_tuple_code
73 end
74
75 feature -- Access
76
77 position: INTEGER
78 -- Position of the formal in declarations
79
80 is_reference: BOOLEAN is
81 -- Is the type a reference type?
82 do
83 Result := True
84 end
85
86 is_expanded: BOOLEAN
87 -- Is current constrained to be always an expanded?
88
89 is_valid (a_class: CLASS_C): BOOLEAN is
90 -- Is Current consistent and valid for `a_class'?
91 do
92 Result := a_class.is_generic and then position <= a_class.generics.count
93 end
94
95 hash_code: INTEGER is
96 -- Hash code for current type
97 do
98 Result := Other_code + position
99 end
100
101 description: GENERIC_DESC is
102 -- Descritpion of type for skeletons.
103 do
104 create Result
105 Result.set_type_i (Current)
106 end
107
108 feature -- Status report
109
110 is_formal: BOOLEAN is True
111 -- Is the type a formal type ?
112
113 is_multi_constrained: BOOLEAN is True
114 -- Is the type a formal type ?
115
116 is_monomorph: BOOLEAN
117 -- Is the type monomorph?
118
119 is_explicit: BOOLEAN is False
120
121 is_standalone: BOOLEAN is False
122 -- Is type standalone, i.e. does not depend on formal generic or acnhored type?
123
124 has_true_formal, has_formal: BOOLEAN is True
125 -- Has the type formal in its structure ?
126
127 instantiation_in (other: CLASS_TYPE): TYPE_I is
128 -- Instantiation of Current in context of `other'
129 do
130 Result := Current
131 end
132
133 complete_instantiation_in (other: CLASS_TYPE): TYPE_I is
134 -- Instantiation of Current in context of `other'.
135 do
136 Result := other.type.true_generics.item (position)
137 end
138
139 name: STRING is
140 -- Name of current type.
141 do
142 create Result.make (3)
143 Result.append ("G#")
144 Result.append_integer (position)
145 end
146
147 il_type_name (a_prefix: STRING): STRING is
148 -- Name of current class type.
149 do
150 Result := name
151 end
152
153 type_a: FORMAL_A is
154 -- Associated FORMAL_A object.
155 do
156 create Result.make (is_reference, is_expanded, is_monomorph, position)
157 end
158
159 feature -- Comparison
160
161 same_as (other: TYPE_I): BOOLEAN is
162 -- Is `other' equal to Current ?
163 local
164 other_formal: FORMAL_I
165 do
166 other_formal ?= other
167 Result := other_formal /= Void and then other_formal.position = position and then
168 is_reference = other.is_reference and then is_expanded = other.is_expanded
169 end
170
171 feature -- Generic conformance
172
173 generated_id (final_mode: BOOLEAN): INTEGER is
174 -- Id of a generic formal parameter.
175 do
176 Result := Formal_type
177 end
178
179 generate_cid (buffer: GENERATION_BUFFER; final_mode, use_info: BOOLEAN) is
180 do
181 buffer.put_integer (Formal_type)
182 buffer.put_character (',')
183 buffer.put_integer (position)
184 buffer.put_character (',')
185 end
186
187 make_gen_type_byte_code (ba: BYTE_ARRAY; use_info: BOOLEAN) is
188 do
189 ba.append_short_integer (formal_type)
190 ba.append_short_integer (position)
191 end
192
193 generate_cid_array (buffer: GENERATION_BUFFER; final_mode, use_info: BOOLEAN; idx_cnt: COUNTER) is
194 local
195 dummy: INTEGER
196 do
197 buffer.put_integer (Formal_type)
198 buffer.put_character (',')
199 buffer.put_integer (position)
200 buffer.put_character (',')
201 dummy := idx_cnt.next
202 dummy := idx_cnt.next
203 end
204
205 generate_cid_init (buffer: GENERATION_BUFFER; final_mode, use_info: BOOLEAN; idx_cnt: COUNTER) is
206 local
207 dummy : INTEGER
208 do
209 -- Increment counter
210 dummy := idx_cnt.next
211 dummy := idx_cnt.next
212 end
213
214 feature -- Generic conformance for IL
215
216 generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info: BOOLEAN) is
217 -- `use_info' is true iff we generate code for a
218 -- creation instruction.
219 do
220 -- We must be in a generic class otherwise having a formal creation
221 -- does not make sense.
222 check
223 generic_class: context.current_type.base_class.is_generic
224 end
225
226 -- Generate call to feature, defined in every descendant of
227 -- the current generic class, that will
228 -- create the corresponding runtime type associated with formal
229 -- in descendant class.
230 il_generator.generate_type_feature_call (context.current_type.base_class.formal_at_position (position))
231 end
232
233 feature {NONE} -- Code generation
234
235 generate_cecil_value (buffer: GENERATION_BUFFER) is
236 do
237 ensure then
238 False
239 end
240
241 feature {NONE} -- Not applicable
242
243 c_type: TYPE_C is
244 -- Associated C type.
245 do
246 -- FIXME: we should not call it, but in case we have decided that it
247 -- will always return a reference type
248 Result := Reference_c_type
249 end
250
251 sk_value: INTEGER is
252 -- Generate SK value associated to the current type.
253 do
254 -- This is called only when the actual generic parameter is a reference
255 -- since in that case we create a MULTI_FORMAL_I to find which constraints
256 -- to use if needed (See {BYTE_CONTEXT}.real_type)
257 -- This is different from FORMAL_I.sk_value which is never called because
258 -- we always use the constraint type of the FORMAL_I to resolve types.
259 Result := sk_ref
260 end
261
262 indexing
263 copyright: "Copyright (c) 1984-2006, Eiffel Software"
264 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
265 licensing_options: "http://www.eiffel.com/licensing"
266 copying: "[
267 This file is part of Eiffel Software's Eiffel Development Environment.
268
269 Eiffel Software's Eiffel Development Environment is free
270 software; you can redistribute it and/or modify it under
271 the terms of the GNU General Public License as published
272 by the Free Software Foundation, version 2 of the License
273 (available at the URL listed under "license" above).
274
275 Eiffel Software's Eiffel Development Environment is
276 distributed in the hope that it will be useful, but
277 WITHOUT ANY WARRANTY; without even the implied warranty
278 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
279 See the GNU General Public License for more details.
280
281 You should have received a copy of the GNU General Public
282 License along with Eiffel Software's Eiffel Development
283 Environment; if not, write to the Free Software Foundation,
284 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
285 ]"
286 source: "[
287 Eiffel Software
288 356 Storke Road, Goleta, CA 93117 USA
289 Telephone 805-685-1006, Fax 805-685-6869
290 Website http://www.eiffel.com
291 Customer support http://support.eiffel.com
292 ]"
293
294 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23