/[eiffelstudio]/trunk/Src/Eiffel/API/evaluated_type/like_current.e
ViewVC logotype

Contents of /trunk/Src/Eiffel/API/evaluated_type/like_current.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 75151 - (show annotations)
Fri Oct 17 08:35:38 2008 UTC (11 years, 3 months ago) by alexk
File size: 15900 byte(s)
Added a query that tells if initialization is required for a type (this is
different from attachment status, because entities of formal generic type
require initialization though we do not know if the actual type will be
attached or not).
Factored out a function that transfers attachment status of the current
type to the specified one which is required for processing anchored types.

1 indexing
2 description:"Actual type like Current."
3 legal: "See notice at end of class."
4 status: "See notice at end of class."
5 date: "$Date$"
6 revision: "$Revision $"
7
8 class
9 LIKE_CURRENT
10
11 inherit
12 LIKE_TYPE_A
13 redefine
14 actual_type, deep_actual_type, context_free_type,
15 associated_class, associated_class_type, conform_to, conformance_type, convert_to,
16 generics, has_associated_class, has_associated_class_type, instantiated_in, duplicate,
17 is_basic, is_expanded, is_external, is_like_current, is_none, is_reference,
18 meta_type, set_actual_type, evaluated_type_in_descendant, is_tuple,
19 set_attached_mark, set_detachable_mark, set_is_implicitly_attached,
20 unset_is_implicitly_attached, description, c_type, is_explicit,
21 generated_id, generate_cid, generate_cid_array, generate_cid_init,
22 make_type_byte_code, generate_gen_type_il, internal_is_valid_for_class,
23 maximum_interval_value, minimum_interval_value, is_optimized_as_frozen,
24 is_generated_as_single_type, heaviest, instantiation_in, adapted_in,
25 hash_code, internal_generic_derivation, internal_same_generic_derivation_as,
26 is_class_valid, skeleton_adapted_in, good_generics, has_like_current, is_type_set
27 end
28
29 feature -- Visitor
30
31 process (v: TYPE_A_VISITOR) is
32 -- Process current element.
33 do
34 v.process_like_current (Current)
35 end
36
37 feature -- Properties
38
39 actual_type: LIKE_CURRENT
40 -- Actual type of the anchored type in a given class
41
42 deep_actual_type: TYPE_A is
43 -- <Precursor>
44 do
45 Result := conformance_type.deep_actual_type
46 end
47
48 context_free_type: like Current is
49 -- <Precursor>
50 do
51 create Result
52 Result.set_actual_type (conformance_type.context_free_type)
53 end
54
55 conformance_type: TYPE_A
56 -- Type of the anchored type as specified in `set_actual_type'
57
58 has_associated_class: BOOLEAN is
59 -- Does Current have an associated class?
60 do
61 Result := conformance_type /= Void and then conformance_type.has_associated_class
62 end
63
64 has_associated_class_type (a_context_type: TYPE_A): BOOLEAN is
65 -- Does Current have an associated class?
66 do
67 Result := conformance_type /= Void and then conformance_type.has_associated_class_type (a_context_type)
68 end
69
70 is_class_valid: BOOLEAN is
71 do
72 Result := conformance_type /= Void and then conformance_type.is_class_valid
73 end
74
75 has_like_current, is_like_current: BOOLEAN is True
76 -- Is the current type an anchored type on Current ?
77
78 is_explicit: BOOLEAN is False
79 -- Is type fixed at compile time without anchors or formals?
80 --| Ideally, it is explicit if at runtime there is no descendants and
81 --| that conformance_type is also explicit (to prevent case
82 --| where like Current represents A [G] for which we can have
83 --| many types) using the following code
84 --| Result := associated_class.direct_descendants.is_empty and then
85 --| conformance_type.is_explicit
86 --| Unfortunately it does not work because code generation is still
87 --| generating `dftype' instead which cannot be used in static array
88 --| type initialization.
89
90 is_expanded: BOOLEAN is
91 -- Is type expanded?
92 do
93 if conformance_type /= Void then
94 Result := conformance_type.is_expanded
95 end
96 end
97
98 is_reference: BOOLEAN is
99 -- Is type reference?
100 do
101 if conformance_type /= Void then
102 Result := conformance_type.is_reference
103 end
104 end
105
106 is_tuple: BOOLEAN is
107 -- Is type reference?
108 do
109 if conformance_type /= Void then
110 Result := conformance_type.is_tuple
111 end
112 end
113
114 is_external: BOOLEAN is False
115 -- Is type external?
116
117 is_none: BOOLEAN is False
118 -- Is current actual type NONE?
119
120 is_type_set: BOOLEAN is
121 -- <Precursor>
122 do
123 Result := conformance_type /= Void and then conformance_type.is_type_set
124 end
125
126 is_basic: BOOLEAN is
127 -- Is the current actual type a basic one?
128 do
129 if conformance_type /= Void then
130 Result := conformance_type.is_basic
131 end
132 end
133
134 same_as (other: TYPE_A): BOOLEAN is
135 -- Is the current type the same as `other' ?
136 local
137 l: LIKE_CURRENT
138 do
139 if other.is_like_current then
140 l ?= other
141 Result := has_same_attachment_marks (l)
142 end
143 end
144
145 good_generics: BOOLEAN is True
146 --| A current type always has the right number of generic parameter.
147
148 feature -- Access
149
150 hash_code: INTEGER is
151 do
152 Result := {SHARED_HASH_CODE}.other_code
153 end
154
155 associated_class: CLASS_C is
156 -- Associated class
157 do
158 Result := conformance_type.associated_class
159 end
160
161 associated_class_type (a_context_type: TYPE_A): CLASS_TYPE is
162 -- Associated class
163 do
164 Result := conformance_type.associated_class_type (a_context_type)
165 end
166
167 generics: ARRAY [TYPE_A] is
168 -- Actual generic types
169 do
170 if conformance_type /= Void then
171 Result := conformance_type.generics
172 end
173 end
174
175 description: GENERIC_DESC is
176 do
177 create Result
178 Result.set_type_i (Current)
179 end
180
181 c_type: TYPE_C is
182 do
183 if conformance_type /= Void then
184 Result := conformance_type.c_type
185 else
186 Result := reference_c_type
187 end
188 end
189
190 feature -- Comparison
191
192 is_equivalent (other: like Current): BOOLEAN is
193 -- Is `other' equivalent to the current object ?
194 do
195 Result := same_as (other)
196 end
197
198 feature -- Output
199
200 dump: STRING is
201 -- Dumped trace
202 local
203 actual_dump: STRING
204 do
205 actual_dump := conformance_type.dump
206 create Result.make (17 + actual_dump.count)
207 Result.append_character ('[')
208 if has_attached_mark then
209 Result.append_character ('!')
210 elseif has_detachable_mark then
211 Result.append_character ('?')
212 end
213 Result.append ("like Current] ")
214 Result.append (actual_dump)
215 end
216
217 ext_append_to (st: TEXT_FORMATTER; c: CLASS_C) is
218 do
219 st.process_symbol_text ({SHARED_TEXT_ITEMS}.ti_L_bracket)
220 if has_attached_mark then
221 st.process_symbol_text ({SHARED_TEXT_ITEMS}.ti_exclamation)
222 elseif has_detachable_mark then
223 st.process_symbol_text ({SHARED_TEXT_ITEMS}.ti_question)
224 end
225 st.process_keyword_text ({SHARED_TEXT_ITEMS}.ti_Like_keyword, Void)
226 st.add_space
227 st.process_keyword_text ({SHARED_TEXT_ITEMS}.ti_Current, Void)
228 st.process_symbol_text ({SHARED_TEXT_ITEMS}.ti_R_bracket)
229 st.add_space
230 conformance_type.ext_append_to (st, c)
231 end
232
233 feature -- IL code generation
234
235 minimum_interval_value: INTERVAL_VAL_B is
236 require else
237 valid_type: conformance_type.is_integer or conformance_type.is_natural or conformance_type.is_character
238 do
239 Result := conformance_type.minimum_interval_value
240 end
241
242 maximum_interval_value: INTERVAL_VAL_B is
243 require else
244 valid_type: conformance_type.is_integer or conformance_type.is_natural or conformance_type.is_character
245 do
246 Result := conformance_type.maximum_interval_value
247 end
248
249 heaviest (other: TYPE_A): TYPE_A
250 do
251 Result := conformance_type.heaviest (other)
252 end
253
254 is_optimized_as_frozen: BOOLEAN is
255 do
256 Result := conformance_type.is_optimized_as_frozen
257 end
258
259 is_generated_as_single_type: BOOLEAN is
260 -- Is associated type generated as a single type or as an interface type and
261 -- an implementation type.
262 do
263 Result := conformance_type.is_generated_as_single_type
264 end
265
266 feature -- Generic conformance
267
268 generated_id (final_mode: BOOLEAN; a_context_type: TYPE_A): NATURAL_16 is
269 -- Id of a `like xxx'.
270 do
271 Result := {SHARED_GEN_CONF_LEVEL}.like_current_type
272 end
273
274 generate_cid (buffer: GENERATION_BUFFER; final_mode, use_info: BOOLEAN; a_context_type: TYPE_A) is
275 -- Generate mode dependent sequence of type id's
276 -- separated by commas. `use_info' is true iff
277 -- we generate code for a creation instruction.
278 do
279 if use_info then
280 create_info.generate_cid (buffer, final_mode)
281 else
282 conformance_type.generate_cid (buffer, final_mode, use_info, a_context_type)
283 end
284 end
285
286 generate_cid_array (buffer: GENERATION_BUFFER; final_mode, use_info: BOOLEAN; idx_cnt: COUNTER; a_context_type: TYPE_A) is
287 do
288 if use_info then
289 create_info.generate_cid_array (buffer, final_mode, idx_cnt)
290 else
291 conformance_type.generate_cid_array (buffer, final_mode, use_info, idx_cnt, a_context_type)
292 end
293 end
294
295 generate_cid_init (buffer: GENERATION_BUFFER; final_mode, use_info: BOOLEAN; idx_cnt: COUNTER; a_level: NATURAL) is
296 do
297 if use_info then
298 create_info.generate_cid_init (buffer, final_mode, idx_cnt, a_level)
299 else
300 conformance_type.generate_cid_init (buffer, final_mode, use_info, idx_cnt, a_level)
301 end
302 end
303
304 make_type_byte_code (ba: BYTE_ARRAY; use_info: BOOLEAN; a_context_type: TYPE_A) is
305 do
306 if use_info then
307 create_info.make_type_byte_code (ba)
308 else
309 conformance_type.make_type_byte_code (ba, use_info, a_context_type)
310 end
311 end
312
313 generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info: BOOLEAN) is
314 -- `use_info' is true iff we generate code for a
315 -- creation instruction.
316 do
317 il_generator.generate_current_as_reference
318 il_generator.load_type
319 end
320
321 feature {TYPE_A} -- Helpers
322
323 internal_is_valid_for_class (a_class: CLASS_C): BOOLEAN is
324 -- Is current type valid?
325 do
326 -- If no `conformance_type' is specified, then `like Current' makes sense.
327 -- If one is specified, then it should be correct.
328 Result := conformance_type = Void or else conformance_type.internal_is_valid_for_class (a_class)
329 end
330
331 internal_generic_derivation (a_level: INTEGER_32): TYPE_A is
332 do
333 -- We keep the same level since we are merely forwarding the call.
334 Result := conformance_type.internal_generic_derivation (a_level)
335 end
336
337 internal_same_generic_derivation_as (current_type, other: TYPE_A; a_level: INTEGER_32): BOOLEAN is
338 do
339 -- We keep the same level since we are merely forwarding the call.
340 Result := conformance_type.internal_same_generic_derivation_as (current_type, other, a_level)
341 end
342
343 feature {COMPILER_EXPORTER} -- Modification
344
345 set_actual_type (a: TYPE_A) is
346 -- Assign `a' to `conformance_type'.
347 do
348 conformance_type := to_current_attachment (a)
349 actual_type := Current
350 end
351
352 set_attached_mark is
353 -- Mark type declaration as having an explicit attached mark.
354 do
355 Precursor
356 if not conformance_type.is_attached then
357 conformance_type := conformance_type.as_attached
358 end
359 end
360
361 set_detachable_mark is
362 -- Set class type declaration as having an explicit detachable mark.
363 do
364 Precursor
365 if not is_expanded and then (conformance_type.is_attached or else conformance_type.is_implicitly_attached) then
366 conformance_type := conformance_type.as_detachable
367 end
368 end
369
370 set_is_implicitly_attached
371 local
372 a: like conformance_type
373 do
374 Precursor
375 a := conformance_type
376 if a /= Void and then not a.is_attached and then not a.is_implicitly_attached then
377 conformance_type := a.as_implicitly_attached
378 end
379 end
380
381 unset_is_implicitly_attached
382 local
383 a: like conformance_type
384 do
385 Precursor
386 a := conformance_type
387 if a /= Void and then not a.is_attached and then a.is_implicitly_attached then
388 conformance_type := a.as_implicitly_detachable
389 end
390 end
391
392 feature {COMPILER_EXPORTER} -- Duplication
393
394 duplicate: LIKE_CURRENT
395 -- Duplication
396 do
397 Result := Precursor
398 -- Ensure `Result.actual_type = Result'
399 -- that is expected when working with attachment properties
400 Result.set_actual_type (conformance_type)
401 end
402
403 feature {COMPILER_EXPORTER} -- Primitives
404
405 instantiation_in (type: TYPE_A; written_id: INTEGER): TYPE_A is
406 -- Instantiation of Current in the context of `class_type',
407 -- assuming that Current is written in class of id `written_id'.
408 do
409 -- Special cases for calls on a target which is a manifest integer
410 -- that might be compatible with _8 or _16. The returned
411 -- `actual_type' should not take into consideration the
412 -- `compatibility_size' of `type', just its intrinsic type.
413 -- Because manifest integers are by default 32 bits, when
414 -- you apply a routine whose result is of type `like Current'
415 -- then it should really be a 32 bits integer. Note that in the
416 -- past we were keeping the size of the manifest integers and the
417 -- following code was accepted:
418 -- i16: INTEGER_16
419 -- i8: INTEGER_8
420 -- i16 := 0x00FF & i8
421 -- Now the code is rejected because target expect an INTEGER_16
422 -- and not an INTEGER, therefore the code needs to be fixed with:
423 -- i16 := (0x00FF).to_integer_16 & i8
424 -- or
425 -- i16 := (0x00FF & i8).to_integer_16
426 Result := to_current_attachment (type.intrinsic_type)
427 end
428
429 adapted_in, skeleton_adapted_in (a_class_type: CLASS_TYPE): CL_TYPE_A is
430 -- Instantiation of Current in context of `other'.
431 do
432 Result := a_class_type.type
433 end
434
435 instantiated_in (class_type: TYPE_A): TYPE_A is
436 -- Instantiation of Current in the context of `class_type'
437 -- assuming that Current is written in the associated class
438 -- of `class_type'.
439 local
440 l_like: like Current
441 do
442 Result := class_type
443 if Result.is_like_current then
444 -- We cannot allow aliasing as otherwise we might end up updating
445 -- `like Current' type that should not be updated (Allowing the
446 -- aliasing would break eweasel test#valid218).
447 create l_like
448 l_like.set_actual_type (class_type.conformance_type)
449 Result := l_like
450 end
451 Result := to_current_attachment (Result)
452 end
453
454 evaluated_type_in_descendant (a_ancestor, a_descendant: CLASS_C; a_feature: FEATURE_I): LIKE_CURRENT is
455 do
456 if a_ancestor /= a_descendant then
457 create Result
458 Result.set_actual_type (a_descendant.actual_type)
459 if has_attached_mark then
460 Result.set_attached_mark
461 elseif has_detachable_mark then
462 Result.set_detachable_mark
463 end
464 else
465 Result := Current
466 end
467 end
468
469 create_info, shared_create_info: CREATE_CURRENT is
470 -- Byte code information for entity type creation
471 once
472 create Result
473 end
474
475 conform_to (other: TYPE_A): BOOLEAN is
476 -- Does `Current' conform to `other'?
477 do
478 Result := other.is_like_current or else conformance_type.conform_to (other.conformance_type)
479 end
480
481 convert_to (a_context_class: CLASS_C; a_target_type: TYPE_A): BOOLEAN is
482 -- Does current convert to `a_target_type' in `a_context_class'?
483 -- Update `last_conversion_info' of AST_CONTEXT.
484 do
485 Result := conformance_type.convert_to (a_context_class, a_target_type)
486 end
487
488 meta_type: LIKE_CURRENT is
489 -- Meta type.
490 do
491 -- Because `like Current' could possibly means a basic type
492 -- when processing an inherited routine using `like Current'
493 -- we keep LIKE_CURRENT for the metatype, but simply replace
494 -- its `conformance_type' with its `meta_type'.
495 create Result
496 Result.set_actual_type (conformance_type.meta_type)
497 end
498
499 indexing
500 copyright: "Copyright (c) 1984-2007, Eiffel Software"
501 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
502 licensing_options: "http://www.eiffel.com/licensing"
503 copying: "[
504 This file is part of Eiffel Software's Eiffel Development Environment.
505
506 Eiffel Software's Eiffel Development Environment is free
507 software; you can redistribute it and/or modify it under
508 the terms of the GNU General Public License as published
509 by the Free Software Foundation, version 2 of the License
510 (available at the URL listed under "license" above).
511
512 Eiffel Software's Eiffel Development Environment is
513 distributed in the hope that it will be useful, but
514 WITHOUT ANY WARRANTY; without even the implied warranty
515 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
516 See the GNU General Public License for more details.
517
518 You should have received a copy of the GNU General Public
519 License along with Eiffel Software's Eiffel Development
520 Environment; if not, write to the Free Software Foundation,
521 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
522 ]"
523 source: "[
524 Eiffel Software
525 356 Storke Road, Goleta, CA 93117 USA
526 Telephone 805-685-1006, Fax 805-685-6869
527 Website http://www.eiffel.com
528 Customer support http://support.eiffel.com
529 ]"
530
531 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23