/[eiffelstudio]/branches/eth/eve/Src/Eiffel/API/evaluated_type/type_a.e
ViewVC logotype

Contents of /branches/eth/eve/Src/Eiffel/API/evaluated_type/type_a.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94983 - (show annotations)
Fri May 2 11:05:28 2014 UTC (5 years, 5 months ago) by jasonw
File size: 59260 byte(s)
<<Merged from trunk#94978.>>
1 note
2 description: "Actual type description."
3 code_review: "http://docs.google.com/Doc?id=dd7kn5vj_93ng9v6cg"
4 legal: "See notice at end of class."
5 status: "See notice at end of class."
6 date: "$Date$"
7 revision: "$Revision$"
8
9 deferred class TYPE_A
10
11 inherit
12 SHARED_EIFFEL_PROJECT
13 export
14 {NONE} all
15 end
16
17 SHARED_WORKBENCH
18
19 SHARED_TYPE_I
20 export
21 {NONE} all
22 end
23
24 COMPILER_EXPORTER
25 export
26 {NONE} all
27 end
28
29 SHARED_GENERIC_CONSTRAINT
30
31 SHARED_ERROR_HANDLER
32 export
33 {NONE} all
34 end
35
36 SHARED_AST_CONTEXT
37 export
38 {NONE} all
39 end
40
41 CONF_CONSTANTS
42 export
43 {NONE} all
44 end
45
46 HASHABLE
47
48 INTERNAL_COMPILER_STRING_EXPORTER
49
50 SHARED_COMPILER_PROFILE
51
52 feature -- Visitor
53
54 process (v: TYPE_A_VISITOR)
55 -- Process current element.
56 require
57 v_not_void: v /= Void
58 v_is_valid: v.is_valid
59 deferred
60 end
61
62 feature -- Generic conformance
63
64 annotation_flags: NATURAL_16
65 -- Flags for annotations of Current.
66 -- Currently only `!' and `frozen' are supported
67 do
68 -- Only if a type is not expanded do we need to generate the
69 -- attached annotation since by default expanded implies attached.
70 if is_attached and not is_expanded then
71 Result := {SHARED_GEN_CONF_LEVEL}.attached_type
72 end
73 -- To uncomment when variant/frozen proposal for generics is supported at runtime
74 -- if is_frozen then
75 -- Result := Result | {SHARED_GEN_CONF_LEVEL}.frozen_type
76 -- end
77 end
78
79 generated_id (final_mode: BOOLEAN; a_context_type: TYPE_A): NATURAL_16
80 -- Mode dependent type id - just for convenience
81 require
82 context_type_valid: is_valid_context_type (a_context_type)
83 do
84 Result := {SHARED_GEN_CONF_LEVEL}.terminator_type -- Invalid type id.
85 check
86 not_called: False
87 end
88 end
89
90 generate_cid (buffer: GENERATION_BUFFER; final_mode, use_info: BOOLEAN; a_context_type: TYPE_A)
91 -- Generate mode dependent sequence of type id's
92 -- separated by commas. `use_info' is true iff
93 -- we generate code for a creation instruction.
94 require
95 valid_file : buffer /= Void
96 context_type_valid: is_valid_context_type (a_context_type)
97 do
98 generate_cid_prefix (buffer, Void)
99 buffer.put_integer (generated_id (final_mode, a_context_type))
100 buffer.put_character (',')
101 end
102
103 generate_cid_array (buffer: GENERATION_BUFFER; final_mode, use_info: BOOLEAN; idx_cnt: COUNTER; a_context_type: TYPE_A)
104 -- Generate mode dependent sequence of type id's
105 -- separated by commas. `use_info' is true iff
106 -- we generate code for a creation instruction.
107 -- 'idx_cnt' holds the index in the array for
108 -- this entry.
109 require
110 valid_file : buffer /= Void
111 valid_counter : idx_cnt /= Void
112 context_type_valid: is_valid_context_type (a_context_type)
113 local
114 dummy : INTEGER
115 do
116 generate_cid_prefix (buffer, idx_cnt)
117 buffer.put_integer (generated_id (final_mode, a_context_type))
118 buffer.put_character (',')
119
120 -- Increment counter
121 dummy := idx_cnt.next
122 end
123
124 generate_cid_init (buffer: GENERATION_BUFFER; final_mode, use_info: BOOLEAN; idx_cnt: COUNTER; a_context_type: TYPE_A; a_level: NATURAL)
125 -- Generate mode dependent initialization of
126 -- cid array. `use_info' is true iff
127 -- we generate code for a creation instruction.
128 -- 'idx_cnt' holds the index in the array for
129 -- this entry.
130 require
131 valid_file : buffer /= Void
132 valid_counter : idx_cnt /= Void
133 context_type_valid: is_valid_context_type (a_context_type)
134 local
135 dummy : INTEGER
136 do
137 generate_cid_prefix (Void, idx_cnt)
138 -- Increment counter
139 dummy := idx_cnt.next
140 end
141
142 frozen make_full_type_byte_code (ba: BYTE_ARRAY; a_context_type: TYPE_A)
143 -- Append full type info for the current type to `ba'
144 -- following the format for locals, creation expressions, etc.
145 require
146 ba_attached: ba /= Void
147 a_context_type_not_void: a_context_type /= Void
148 context_type_valid: is_valid_context_type (a_context_type)
149 do
150 make_type_byte_code (ba, True, a_context_type)
151 ba.append_short_integer (-1)
152 end
153
154 make_type_byte_code (ba: BYTE_ARRAY; use_info: BOOLEAN; a_context_type: TYPE_A)
155 -- Put type id's in byte array.
156 -- `use_info' is true iff we generate code for a
157 -- creation instruction.
158 require
159 ba_attached: ba /= Void
160 context_type_valid: is_valid_context_type (a_context_type)
161 do
162 make_type_prefix_byte_code (ba)
163 ba.append_natural_16 (generated_id (False, a_context_type))
164 end
165
166 generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info: BOOLEAN)
167 -- `use_info' is true iff we generate code for a
168 -- creation instruction.
169 require
170 il_generator_not_void: il_generator /= Void
171 do
172 end
173
174 feature {NONE} -- Generic conformance
175
176 generate_cid_prefix (buffer: GENERATION_BUFFER; idx_cnt: COUNTER)
177 -- Generate prefix to a type specification if `buffer' specified.
178 -- Increment `idx_cnt' accordingly if specified.
179 local
180 l_annotation: like annotation_flags
181 l_dummy: INTEGER
182 do
183 l_annotation := annotation_flags
184 if l_annotation /= 0 then
185 -- If `buffer' was provided, outputs annotation.
186 if buffer /= Void then
187 buffer.put_hex_natural_16 (l_annotation)
188 buffer.put_character (',')
189 end
190 -- If counter was provided, increments it.
191 if idx_cnt /= Void then
192 l_dummy := idx_cnt.next
193 end
194 end
195 end
196
197 make_type_prefix_byte_code (ba: BYTE_ARRAY)
198 -- Put type id's in byte array.
199 -- `use_info' is true iff we generate code for a
200 -- creation instruction.
201 require
202 ba_attached: ba /= Void
203 local
204 l_annotation: like annotation_flags
205 do
206 l_annotation := annotation_flags
207 if l_annotation /= 0 then
208 ba.append_natural_16 (l_annotation)
209 end
210 end
211
212 feature -- C code generation
213
214 generate_cecil_value (buffer: GENERATION_BUFFER; a_context_type: TYPE_A)
215 -- Generate type value for cecil.
216 require
217 buffer_not_void: buffer /= Void
218 context_type_valid: is_valid_context_type (a_context_type)
219 do
220 c_type.generate_sk_value (buffer)
221 end
222
223 feature -- IL code generation
224
225 element_type: INTEGER_8
226 -- Type of current element. See MD_SIGNATURE_CONSTANTS for
227 -- all possible values.
228 do
229 Result := c_type.element_type
230 end
231
232 il_type_name (a_prefix: STRING; a_context_type: TYPE_A): STRING
233 -- Name of current class type in IL generation.
234 require
235 in_il_generation: System.il_generation
236 context_type_valid: is_valid_context_type (a_context_type)
237 do
238 Result := name
239 ensure
240 il_type_name_not_void: Result /= Void
241 il_type_name_not_empty: not Result.is_empty
242 end
243
244 generic_il_type_name (a_context_type: TYPE_A): STRING_8
245 -- Associated name to for naming in generic derivation.
246 require
247 in_il_generation: system.il_generation
248 context_type_valid: is_valid_context_type (a_context_type)
249 do
250 Result := name
251 ensure
252 il_type_name_not_void: Result /= Void
253 il_type_name_not_empty: not Result.is_empty
254 end
255
256 minimum_interval_value: INTERVAL_VAL_B
257 -- Minimum value in inspect interval for current type
258 require
259 valid_type: is_integer or else is_natural or else is_character
260 do
261 -- Implementation is provided by descendants that meet precondition
262 ensure
263 result_not_void: Result /= Void
264 end
265
266 maximum_interval_value: INTERVAL_VAL_B
267 -- Maximum value in inspect interval for current type
268 require
269 valid_type: is_integer or else is_natural or else is_character
270 do
271 -- Implementation is provided by descendants that meet precondition
272 ensure
273 result_not_void: Result /= Void
274 end
275
276 is_optimized_as_frozen: BOOLEAN
277 -- Is current type optimizable as a frozen one in .NET code generation?
278 do
279 end
280
281 is_generated_as_single_type: BOOLEAN
282 -- Is associated type generated as a single type or as an interface type and
283 -- an implementation type.
284 require
285 il_generation: System.il_generation
286 valid_type: is_valid
287 do
288 end
289
290 heaviest (other: TYPE_A): TYPE_A
291 -- Heaviest of two numeric types.
292 do
293 Result := Current
294 end
295
296 dispatch_anchors (a_context_class: CLASS_C)
297 -- If `Current' is an anchor to a feature, we need to record this anchoring
298 -- in `a_context_class'.
299 -- We do not check that `Current' is valid because this routine simply looks
300 -- for the `routine_id' of `{LIKE_FEATURE}' and nothing else.
301 require
302 a_context_class_not_void: a_context_class /= Void
303 a_context_class_valid: a_context_class.is_valid
304 is_valid: is_valid
305 a_context_valid_for_current: is_valid_for_class (a_context_class)
306 do
307 end
308
309 feature -- Properties
310
311 has_associated_class: BOOLEAN
312 -- Does Current have an associated class?
313 do
314 Result := not (is_void or else is_formal or else is_none)
315 ensure
316 Yes_if_is: Result implies not (is_void or else
317 is_formal or else is_none)
318 end
319
320 has_associated_class_type (a_context_type: TYPE_A): BOOLEAN
321 -- Does Current have an associated class in `a_context_type'?
322 require
323 context_type_valid: is_valid_context_type (a_context_type)
324 do
325 Result := has_associated_class
326 end
327
328 generics: ARRAYED_LIST [TYPE_A]
329 -- Actual generic types
330 do
331 -- Void
332 end
333
334 is_frozen: BOOLEAN
335 -- Is type frozen?
336 do
337 Result := has_frozen_mark or else is_implicitly_frozen
338 end
339
340 is_implicitly_frozen: BOOLEAN
341 -- Is type implicitly frozen?
342 --| Case of a frozen class or an expanded class.
343 do
344 Result := (attached base_class as l_base_class and then (l_base_class.is_frozen or l_base_class.has_descendants)) or else is_expanded
345 end
346
347 is_variant: BOOLEAN
348 -- Is type marked `variant'.
349 do
350 -- Either we have the variant mark or we are in traditional mode.
351 Result := has_variant_mark or else not compiler_profile.is_experimental_mode
352 end
353
354 is_valid_generic_derivation: BOOLEAN
355 -- Is current still a valid type to be used as a generic derivation?
356 -- Note that Current has to be a generic derivation, unfortunately
357 -- we cannot use the usual precondition `same_as (generic_derivation)'
358 -- as we might be working on types that have changed their expanded
359 -- status and thus the query `generic_derivation' may yield a different value.
360 require
361 is_valid: is_valid
362 is_generic_derivation: -- same_as (generic_derivation)
363 do
364 Result := True
365 end
366
367 is_class_valid: BOOLEAN
368 -- Are all types referenced by current type part of the system?
369 do
370 Result := True
371 end
372
373 frozen is_valid: BOOLEAN
374 -- Is current a valid declaration by itself?
375 do
376 Result := internal_is_valid_for_class (Void)
377 ensure
378 true_implication: is_valid implies is_class_valid
379 false_implication: not is_class_valid implies not is_valid
380 end
381
382 frozen is_valid_for_class (a_class: CLASS_C): BOOLEAN
383 -- Is current valid for a declaration in `a_class'?
384 require
385 a_class_not_void: a_class /= Void
386 a_class_valid: a_class.is_valid
387 do
388 Result := internal_is_valid_for_class (a_class)
389 end
390
391 frozen is_valid_context_type (a_type: TYPE_A): BOOLEAN
392 -- Is `a_type' a valid context type for current type?
393 --| It is assumed that `a_type' is the type coming from
394 --| a CLASS_TYPE (see first check below).
395 --| If `a_context_type' is Void, it means that current can be resolved
396 --| without a context. However one has to be careful to not pass Void
397 --| all the time because if there are FORMAL_A in it, they
398 --| won't be properly resolved, or more precisely the reference
399 --| version will be taken which might not be the expected result.
400 do
401 if a_type /= Void then
402 Result :=
403 -- First type should be the one from a generic derivation.
404 a_type.generic_derivation.same_as (a_type) and then
405 -- Second it should be valid for Current type.
406 (a_type.has_associated_class and then is_valid_for_class (a_type.base_class))
407 else
408 Result := True
409 end
410 end
411
412 is_integer: BOOLEAN
413 -- Is the current actual type an integer type?
414 do
415 -- Do nothing
416 end
417
418 is_natural: BOOLEAN
419 -- Is current actual type a natural type?
420 do
421 -- Do nothing
422 end
423
424 is_real_32: BOOLEAN
425 -- Is the current actual type a real 32 bits type ?
426 do
427 -- Do nothing
428 end
429
430 is_real_64: BOOLEAN
431 -- Is the current actual type a real 64 bits type ?
432 do
433 -- Do nothing
434 end
435
436 is_character: BOOLEAN
437 -- Is the current actual type a character type ?
438 do
439 -- Do nothing
440 end
441
442 is_character_32: BOOLEAN
443 -- Is the current actual type a character 32 bits type ?
444 do
445 -- Do nothing
446 end
447
448 is_boolean: BOOLEAN
449 -- Is the current actual type a boolean type ?
450 do
451 -- Do nothing
452 end
453
454 is_formal: BOOLEAN
455 -- Is the current actual type a formal generic ?
456 do
457 -- Do nothing
458 end
459
460 is_expanded: BOOLEAN
461 -- Is the current actual type an expanded one ?
462 do
463 -- Do nothing
464 end
465
466 is_ephemeral: BOOLEAN
467 -- Is the current actual type base class ephemeral?
468 do
469 end
470
471 is_enum: BOOLEAN
472 -- Is the current actual type an external enum one?
473 do
474 -- Do nothing
475 end
476
477 is_reference: BOOLEAN
478 -- Is current actual type a reference one?
479 do
480 Result := not is_expanded
481 end
482
483 is_true_expanded: BOOLEAN
484 -- Is current actual type an expanded one which is not basic?
485 do
486 Result := is_expanded and not is_basic
487 end
488
489 is_basic: BOOLEAN
490 -- Is the current actual type a basic type ?
491 do
492 -- Do nothing
493 end
494
495 is_external: BOOLEAN
496 -- Is current type based on an external one?
497 do
498 end
499
500 is_true_external: BOOLEAN
501 -- Is Current type based solely on an external one?
502 local
503 l_class: CLASS_C
504 do
505 l_class := base_class
506 if l_class /= Void then
507 Result := l_class.is_external_class_c
508 end
509 end
510
511 is_separate: BOOLEAN
512 -- Is the current actual type a separate one ?
513 do
514 Result := has_separate_mark and then not is_expanded
515 end
516
517 -- Added for SCOOP: So far the type checker does not support explicit processor specifications. Thus no type in the system will have an explicit processor specification.
518 processor_tag : attached PROCESSOR_TAG_TYPE
519 require
520 already_separate: is_separate
521 do
522 create Result.make_top
523 end
524
525 is_none: BOOLEAN
526 -- Is the current actual type a none type ?
527 do
528 -- Do nothing
529 end
530
531 is_like: BOOLEAN
532 -- Is the current type an anchored one ?
533 do
534 -- Do nothing
535 end
536
537 is_like_argument: BOOLEAN
538 -- Is the current type a like argument?
539 do
540 -- Do nothing
541 end
542
543 is_multi_constrained: BOOLEAN
544 -- Is the current actual type a formal generic type representing a multiconstraint?
545 do
546 end
547
548 is_named_tuple: BOOLEAN
549 -- Is the current type a tuple with labels?
550 do
551 -- Do nothing
552 end
553
554 is_pointer: BOOLEAN
555 -- Is the current type a pointer type ?
556 do
557 -- Do nothing
558 end
559
560 is_typed_pointer: BOOLEAN
561 -- Is current type a typed pointer type ?
562 do
563 -- Do nothing
564 end
565
566 is_tuple: BOOLEAN
567 -- Is it a TUPLE type
568 do
569 -- Do nothing
570 end
571
572 is_named_type: BOOLEAN
573 -- Is it a named type?
574 do
575 end
576
577 is_full_named_type: BOOLEAN
578 -- Is it a full named type?
579 do
580 ensure
581 is_full_named_type_consistent: Result implies is_named_type
582 end
583
584 has_like: BOOLEAN
585 -- Has the type anchored type in its definition ?
586 do
587 -- Do nothing
588 end
589
590 has_like_current: BOOLEAN
591 -- Has the type `like Current' in its definition?
592 require
593 is_valid: is_valid
594 do
595 end
596
597 has_like_argument: BOOLEAN
598 -- Has the type like argument in its definition?
599 do
600 -- Do nothing
601 end
602
603 has_formal_generic: BOOLEAN
604 -- Has type a formal generic parameter?
605 do
606 -- False for non-generic type.
607 end
608
609 is_loose: BOOLEAN
610 -- Does type depend on formal generic parameters and/or anchors?
611 do
612 -- Do nothing
613 ensure
614 definition: Result = (has_like or has_formal_generic)
615 end
616
617 is_explicit: BOOLEAN
618 -- Is type fixed at compile time without anchors or formals?
619 do
620 Result := True
621 end
622
623 is_void: BOOLEAN
624 -- Is the type void (procedure type) ?
625 do
626 end
627
628 is_like_current: BOOLEAN
629 -- Is the current type a anchored type an Current ?
630 do
631 -- Do nothing
632 end
633
634 is_attached: BOOLEAN
635 -- Is type attached?
636 do
637 Result := is_directly_attached or else is_expanded
638 end
639
640 is_implicitly_attached: BOOLEAN
641 -- Is type (implicitly) attached?
642 -- True means it's safe to attach value of this type
643 -- to an attached entity without compromizing its
644 -- attachment status.
645 do
646 Result := is_directly_implicitly_attached or else is_expanded
647 end
648
649 is_initialization_required: BOOLEAN
650 -- Is initialization required for this type in void-safe mode?
651 do
652 if not is_expanded and then is_attached then
653 Result := True
654 end
655 end
656
657 is_standalone: BOOLEAN
658 -- Is type standalone, i.e. does not depend on formal generic or acnhored type?
659 do
660 Result := not is_loose
661 end
662
663 is_known: BOOLEAN
664 -- Is this type known? (Rather than being computed.)
665 do
666 Result := True
667 end
668
669 is_computable: BOOLEAN
670 -- Can this type be computed as a result of direct type analysis or type inference?
671 -- (`False' means the type cannot be computed because of an error or insufficient information.)
672 do
673 -- `True' by default.
674 Result := True
675 ensure
676 known_is_computable: is_known implies Result
677 end
678
679 feature -- Annotations: status report
680
681 has_attached_mark: BOOLEAN
682 -- Is type explicitly marked as attached?
683 do
684 Result := attachment_bits & has_attached_mark_mask /= 0
685 end
686
687 has_detachable_mark: BOOLEAN
688 -- Is type explicitly marked as attached?
689 do
690 Result := attachment_bits & has_detachable_mark_mask /= 0
691 end
692
693 is_directly_attached: BOOLEAN
694 -- Is type attached because of its declaration
695 -- without checking its anchor (if any)?
696 do
697 Result := attachment_bits & is_attached_mask /= 0
698 end
699
700 is_directly_implicitly_attached: BOOLEAN
701 -- Is type implicitly attached because of its use
702 -- without checking its anchor (if any)?
703 do
704 Result := attachment_bits & (is_attached_mask | is_implicitly_attached_mask) /= {NATURAL_8} 0
705 end
706
707 is_attachable_to (other: TYPE_A): BOOLEAN
708 -- Does type preserve attachment status of other?
709 do
710 Result := other.is_attached implies is_implicitly_attached
711 end
712
713 has_separate_mark: BOOLEAN
714 -- Is type explicitly marked as separate?
715
716 has_frozen_mark: BOOLEAN
717 -- Is type explicitly marked as frozen?
718 do
719 Result := variant_bits & has_frozen_mark_mask /= 0
720 end
721
722 has_variant_mark: BOOLEAN
723 -- Is type explicitly marked as variant?
724 do
725 Result := variant_bits & has_variant_mark_mask /= 0
726 end
727
728 feature -- Annotations: modification
729
730 set_attached_mark
731 -- Mark type declaration as having an explicit attached mark.
732 do
733 attachment_bits := has_attached_mark_mask | is_attached_mask
734 ensure
735 has_attached_mark: has_attached_mark
736 is_attached: is_attached
737 end
738
739 set_detachable_mark
740 -- Mark type declaration as having an explicit detachable mark.
741 do
742 attachment_bits := has_detachable_mark_mask
743 ensure
744 has_detachable_mark: has_detachable_mark
745 not_is_attached: not is_expanded implies not is_attached
746 end
747
748 set_frozen_mark
749 -- Mark type declaration as having an explicit `frozen' mark.
750 do
751 -- Frozen variant is only understood in experimental mode
752 -- for the time being.
753 if compiler_profile.is_experimental_mode then
754 variant_bits := has_frozen_mark_mask
755 end
756 ensure
757 has_frozen_mark: compiler_profile.is_experimental_mode implies has_frozen_mark
758 end
759
760 set_variant_mark
761 -- Mark type declaration as having an explicit `variant' mark.
762 do
763 variant_bits := has_variant_mark_mask
764 ensure
765 has_variant_mark: has_variant_mark
766 end
767
768 set_is_attached
769 -- Set attached type property.
770 require
771 not_has_detachable_mark: is_expanded or else not has_detachable_mark
772 do
773 attachment_bits := attachment_bits | is_attached_mask
774 ensure
775 is_attached: is_attached
776 end
777
778 set_is_implicitly_attached
779 -- Mark type as being implicitly attached, so that
780 -- it is allowed to be attached to an attached type.
781 do
782 attachment_bits := attachment_bits | is_implicitly_attached_mask
783 ensure
784 is_implicitly_attached: is_implicitly_attached
785 end
786
787 unset_is_implicitly_attached
788 -- Mark type as being implicitly detachable, so that
789 -- it is not allowed to be attached to an attached type.
790 require
791 not_is_attached: not is_attached
792 is_implicitly_attached: is_implicitly_attached
793 do
794 attachment_bits := attachment_bits.bit_xor (is_implicitly_attached_mask)
795 ensure
796 not_is_implicitly_attached: not is_implicitly_attached
797 end
798
799 set_separate_mark
800 -- Mark type declaration as having an explicit separate mark.
801 do
802 has_separate_mark := True
803 end
804
805 reset_separate_mark
806 -- Mark type declaration as having no separate mark.
807 do
808 has_separate_mark := False
809 end
810
811 set_marks_from (other: TYPE_A)
812 -- Set attachment marks as they are set in `other'.
813 require
814 other_attached: attached other
815 do
816 if other.has_attached_mark then
817 set_attached_mark
818 elseif other.has_detachable_mark then
819 set_detachable_mark
820 end
821 if other.has_separate_mark then
822 set_separate_mark
823 end
824 if other.has_variant_mark then
825 set_variant_mark
826 elseif other.has_frozen_mark then
827 set_frozen_mark
828 end
829 end
830
831
832 feature -- Comparison
833
834 frozen is_safe_equivalent (other: TYPE_A): BOOLEAN
835 -- Is the current type the same as `other' ?
836 --| `deep_equal' cannot be used as for STRINGS, the area
837 --| can have a different size but the STRING is still
838 --| the same (problem detected for LIKE_FEATURE). Xavier
839 do
840 if other /= Void and then other.same_type (Current) then
841 Result := is_valid and then attached {like Current} other as l_other and then
842 l_other.is_valid and then is_equivalent (l_other)
843 end
844 end;
845
846 frozen equivalent (o1, o2: TYPE_A): BOOLEAN
847 -- Are `o1' and `o2' equivalent ?
848 -- this feature is similar to `deep_equal'
849 -- but ARRAYs and STRINGs are processed correctly
850 -- (`deep_equal' will compare the size of the `area')
851 require
852 o1_is_valid: o1 /= Void
853 do
854 if o1 = Void then
855 Result := o2 = Void
856 else
857 Result := o1.is_safe_equivalent (o2)
858 end
859 end
860
861 is_equivalent (other: like Current): BOOLEAN
862 -- Is `other' equivalent to the current object ?
863 require
864 is_valid: is_valid
865 arg_non_void: other /= Void
866 same_type: same_type (other)
867 other_is_valid: other.is_valid
868 deferred
869 end
870
871 same_as (other: TYPE_A): BOOLEAN
872 -- Is the current type the same as `other' ?
873 require
874 other_attached: other /= Void
875 do
876 -- Do nothing
877 end
878
879 same_generic_derivation_as (current_type, other: TYPE_A): BOOLEAN
880 -- Is the current type the same as `other' in the context of `current_type'?
881 require
882 other_not_void: other /= Void
883 other_derived: other.generic_derivation.same_as (other)
884 do
885 Result := internal_same_generic_derivation_as (current_type, other, 0)
886 ensure
887 -- Only if `current_type' is Void, can we ensure that a True results means that they have
888 -- the same generic derivation.
889 definition: (Result and then current_type = Void) implies generic_derivation.same_as (other.generic_derivation)
890 end
891
892 is_syntactically_equal (other: TYPE_A): BOOLEAN
893 -- Does `other' represent the same syntax construct as `Current'?
894 require
895 other_attached: attached other
896 do
897 Result := same_as (other)
898 end
899
900 is_processor_attachable_to (other: TYPE_A): BOOLEAN
901 -- May processor of current type be used as a processor of type `other'?
902 do
903 if is_separate implies other.is_separate then
904 -- General rule.
905 Result := True
906 elseif attached context.current_feature as f and then
907 attached f.body as b and then attached b.indexes as l_indexing_clause then
908 -- Handle features explicitly ignoring separate status of types.
909 from
910 l_indexing_clause.start
911 until
912 l_indexing_clause.after
913 loop
914 if l_indexing_clause.item.tag.name_32.is_equal (once "ignore_invalid_separate_reattachment") then
915 if across l_indexing_clause.item.index_list as l
916 some l.item.string_value_32.is_case_insensitive_equal ("True") end then
917 Result := True
918 l_indexing_clause.finish
919 else
920 l_indexing_clause.forth
921 end
922 else
923 l_indexing_clause.forth
924 end
925 end
926 end
927 end
928
929 has_same_marks (other: TYPE_A): BOOLEAN
930 -- Are type marks of `Current' and `other' the same?
931 require
932 other_attached: other /= Void
933 do
934 Result :=
935 has_attached_mark = other.has_attached_mark and then
936 has_detachable_mark = other.has_detachable_mark and then
937 has_separate_mark = other.has_separate_mark and then
938 has_frozen_mark = other.has_frozen_mark and then
939 has_variant_mark = other.has_variant_mark
940 end
941
942 feature {CL_TYPE_A} -- Comparison
943
944 is_runnable_on_processor (other: TYPE_A): BOOLEAN
945 -- Can current type run on processor of `other'?
946 require
947 other_attached: attached other
948 other_separate: other.is_separate
949 do
950 if is_separate then
951 -- Separate type can run on the processor of `other'.
952 Result := True
953 elseif is_expanded then
954 -- Verify that all the attributes of the expanded type can run on the processor of `other'.
955 Result := is_processor_attachable_to (other)
956 end
957 end
958
959 feature -- Access
960
961 base_class: detachable CLASS_C
962 -- Base class of current type (if exists).
963 deferred
964 ensure
965 definition: (Result /= Void) = has_associated_class
966 end
967
968 associated_class: CLASS_C
969 -- Base class of current type.
970 obsolete
971 "use base_class instead"
972 do
973 Result := base_class
974 end
975
976 associated_class_type (a_context_type: TYPE_A): CLASS_TYPE
977 -- Class associated to the current type.
978 --| See comments on `has_associated_class_type' for details on `a_context_type'.
979 require
980 context_type_valid: is_valid_context_type (a_context_type)
981 has_associated_class_type: has_associated_class_type (a_context_type)
982 do
983 end
984
985 actual_type: TYPE_A
986 -- Actual type of the interpreted type
987 do
988 Result := Current
989 ensure
990 Result_not_void: Result /= Void
991 end
992
993 conformance_type: TYPE_A
994 -- Type which is used to check conformance
995 do
996 Result := actual_type
997 ensure
998 Result_not_void: Result /= Void
999 end
1000
1001 deep_actual_type: TYPE_A
1002 -- Actual type; recursive on generic types
1003 -- NOTE by M.S: Needed for ROUTINEs - perhaps
1004 -- this is the intended meaning
1005 -- of 'actual_type' - but 'actual_type'
1006 -- does not recurs on generics(?)!
1007 do
1008 Result := Current
1009 end
1010
1011 context_free_type: TYPE_A
1012 -- Type where all anchors to features are removed.
1013 do
1014 Result := Current
1015 end
1016
1017 has_generics: BOOLEAN
1018 -- Has the current type generics types ?
1019 do
1020 Result := generics /= Void
1021 end
1022
1023 intrinsic_type: TYPE_A
1024 -- Default type of a manifest constant.
1025 do
1026 Result := Current
1027 ensure
1028 result_not_void: Result /= Void
1029 end
1030
1031 renaming: RENAMING_A
1032 -- Renaming of current type.
1033 do
1034 -- Result := Void
1035 end
1036
1037 feature -- Duplication
1038
1039 duplicate: like Current
1040 -- Duplication
1041 do
1042 Result := twin
1043 end
1044
1045 as_separate: like Current
1046 -- Separate version of this type
1047 require
1048 not_separate: not is_separate
1049 do
1050 Result := duplicate
1051 Result.set_separate_mark
1052 end
1053
1054 as_non_separate: like Current
1055 -- Non-separate version of this type
1056 require
1057 is_separate: is_separate
1058 do
1059 Result := duplicate
1060 Result.reset_separate_mark
1061 end
1062
1063 as_attached_type: like Current
1064 -- Attached variant of the current type
1065 require
1066 not_is_attached: not is_attached
1067 do
1068 Result := duplicate
1069 Result.set_attached_mark
1070 ensure
1071 result_attached: Result /= Void
1072 end
1073
1074 as_implicitly_attached: like Current
1075 -- Implicitly attached type
1076 require
1077 not_is_attached: not is_attached
1078 not_is_implicitly_attached: not is_implicitly_attached
1079 do
1080 if is_implicitly_attached then
1081 Result := Current
1082 else
1083 Result := duplicate
1084 Result.set_is_implicitly_attached
1085 end
1086 ensure
1087 result_attached: Result /= Void
1088 result_not_attached: not Result.is_attached
1089 result_is_implicitly_attached: Result.is_implicitly_attached
1090 result_is_attachable_to_attached: Result.is_attachable_to (as_attached_type)
1091 end
1092
1093 as_attached_in (c: CLASS_C): like Current
1094 -- Attached or implicitly attached variant of current type depending on the void safety status of contextual class `c'.
1095 require
1096 c_attached: c /= Void
1097 do
1098 Result := Current
1099 if not is_attached then
1100 if c.lace_class.is_void_safe_conformance then
1101 Result := as_attached_type
1102 elseif not is_implicitly_attached then
1103 Result := as_implicitly_attached
1104 end
1105 end
1106 ensure
1107 result_attached: Result /= Void
1108 result_is_attached: not is_none implies (c.lace_class.is_void_safe_conformance implies Result.is_attached)
1109 result_is_implicitly_attached: not is_none implies (Result.is_attached or else Result.is_implicitly_attached)
1110 end
1111
1112 as_implicitly_detachable: like Current
1113 -- Implicitly detachable type
1114 do
1115 if not is_attached and then is_implicitly_attached then
1116 Result := duplicate
1117 Result.unset_is_implicitly_attached
1118 else
1119 Result := Current
1120 end
1121 ensure
1122 result_attached: Result /= Void
1123 end
1124
1125 as_detachable_type: like Current
1126 -- detachable type
1127 do
1128 if not has_detachable_mark then
1129 Result := duplicate
1130 Result.set_detachable_mark
1131 else
1132 Result := Current
1133 end
1134 end
1135
1136 as_attachment_mark_free: like Current
1137 -- Same as Current but without any attachment mark
1138 local
1139 l_bits: like attachment_bits
1140 do
1141 l_bits := attachment_bits
1142 if l_bits = 0 then
1143 Result := Current
1144 else
1145 attachment_bits := 0
1146 Result := duplicate
1147 attachment_bits := l_bits
1148 end
1149 ensure
1150 as_attachment_mark_free_not_void: Result /= Void
1151 result_has_no_attached_mark: not Result.has_attached_mark
1152 result_has_no_detachable_mark: not Result.has_detachable_mark
1153 end
1154
1155 as_marks_free: like Current
1156 -- Same as Current but without any attachment and separate marks
1157 local
1158 a: like attachment_bits
1159 s: BOOLEAN
1160 do
1161 a := attachment_bits
1162 s := has_separate_mark
1163 if a = 0 and then not s then
1164 Result := Current
1165 else
1166 has_separate_mark := False
1167 attachment_bits := 0
1168 Result := duplicate
1169 attachment_bits := a
1170 has_separate_mark := s
1171 end
1172 ensure
1173 as_marks_free_attached: attached Result
1174 result_has_no_attached_mark: not Result.has_attached_mark
1175 result_has_no_detachable_mark: not Result.has_detachable_mark
1176 result_has_no_separate_mark: not Result.has_separate_mark
1177 end
1178
1179 to_other_attachment (other: TYPE_A): like Current
1180 -- Current type to which attachment status of `other' is applied
1181 require
1182 other_attached: other /= Void
1183 local
1184 c: TYPE_A
1185 o: TYPE_A
1186 do
1187 Result := Current
1188 if other /= Result then
1189 if other.is_like_current then
1190 c := other.conformance_type
1191 else
1192 c := other.actual_type
1193 end
1194 if c /= Void and then c /= Result then
1195 -- Apply attachment settings of anchor if applicable and current type has none.
1196 o := c
1197 else
1198 o := other
1199 end
1200 Result := to_other_immediate_attachment (o)
1201 end
1202 ensure
1203 result_attached: Result /= Void
1204 end
1205
1206 to_other_immediate_attachment (other: TYPE_A): like Current
1207 -- Current type to which attachment status of `other' is applied
1208 -- without taking into consideration attachment status of an anchor (if any)
1209 require
1210 other_attached: other /= Void
1211 do
1212 Result := Current
1213 if other.has_attached_mark then
1214 if not has_attached_mark then
1215 Result := duplicate
1216 Result.set_attached_mark
1217 end
1218 elseif other.is_implicitly_attached then
1219 if not is_attached and then not is_implicitly_attached then
1220 Result := as_implicitly_attached
1221 end
1222 elseif other.has_detachable_mark then
1223 if not is_expanded and then not has_detachable_mark then
1224 Result := duplicate
1225 Result.set_detachable_mark
1226 end
1227 elseif not other.is_implicitly_attached and then is_implicitly_attached then
1228 Result := as_implicitly_detachable
1229 end
1230 ensure
1231 result_attached: Result /= Void
1232 end
1233
1234 to_other_separateness (other: TYPE_A): like Current
1235 -- Current type to which separateness status of `other' is applied
1236 require
1237 other_attached: other /= Void
1238 do
1239 Result := Current
1240 if other /= Result then
1241 if not other.is_separate then
1242 if is_separate then
1243 Result := as_non_separate
1244 end
1245 elseif other.has_separate_mark then
1246 if not is_expanded and then not has_separate_mark then
1247 Result := duplicate
1248 Result.set_separate_mark
1249 end
1250 elseif not is_separate then
1251 Result := as_separate
1252 end
1253 end
1254 ensure
1255 result_attached: Result /= Void
1256 end
1257
1258 to_other_variant (other: TYPE_A): like Current
1259 -- Current type to which frozen/variant status is applied.
1260 require
1261 other_attached: other /= Void
1262 local
1263 l_other_is_frozen: BOOLEAN
1264 do
1265 Result := Current
1266 -- Only do something in experimental mode.
1267 if other /= Result and then compiler_profile.is_experimental_mode then
1268 if other.is_like_current then
1269 l_other_is_frozen := other.has_frozen_mark or else other.conformance_type.is_frozen
1270 else
1271 l_other_is_frozen := other.actual_type.is_frozen
1272 end
1273 if not is_frozen and l_other_is_frozen then
1274 Result := duplicate
1275 Result.set_frozen_mark
1276 else
1277 Result := Current
1278 end
1279 end
1280 ensure
1281 result_attached: Result /= Void
1282 end
1283
1284 feature -- Output
1285
1286 frozen append_to (a_text_formatter: TEXT_FORMATTER)
1287 -- Append `Current' to `a_text_formatter'.
1288 do
1289 ext_append_to (a_text_formatter, Void)
1290 end
1291
1292 frozen name: STRING
1293 do
1294 Result := dump
1295 end
1296
1297 dump: STRING
1298 -- Dumped trace
1299 deferred
1300 end
1301
1302 ext_append_to (a_text_formatter: TEXT_FORMATTER; a_context_class: CLASS_C)
1303 -- Append `Current' to `a_text_formatter'.
1304 -- `a_context_class' is used to retrieve the generic type name for a
1305 -- formal generic parameter written in `a_context_class'.
1306 -- This replaces the "G#2" text by the actual formal generic parameter name.
1307 -- Actually used in FORMAL_A.
1308 --| Note: It used to handle LIKE_ARGUMENT as well by changing "arg#1" by the
1309 --| actual argument name, but this was dropped when we started to only use
1310 --| `a_context_class'.
1311 require
1312 a_text_formatter_not_void: a_text_formatter /= Void
1313 deferred
1314 end
1315
1316 dump_marks (s: STRING)
1317 -- Append leading type marks to `s'.
1318 require
1319 s_attached: attached s
1320 do
1321 if has_frozen_mark then
1322 s.append ("frozen ")
1323 elseif has_variant_mark then
1324 s.append ("variant ")
1325 end
1326
1327 if has_attached_mark then
1328 s.append_character ('!')
1329 elseif has_detachable_mark then
1330 s.append_character ('?')
1331 end
1332
1333 if has_separate_mark then
1334 s.append ({SHARED_TEXT_ITEMS}.ti_separate_keyword)
1335 s.append_character (' ')
1336 end
1337 end
1338
1339 ext_append_marks (f: TEXT_FORMATTER)
1340 -- Append leading type marks using formatter `t'.
1341 require
1342 f_attached: attached f
1343 do
1344 if has_frozen_mark then
1345 f.process_keyword_text ({SHARED_TEXT_ITEMS}.ti_frozen_keyword, Void)
1346 f.add_space
1347 elseif has_variant_mark then
1348 f.process_keyword_text ({SHARED_TEXT_ITEMS}.ti_variant_keyword, Void)
1349 f.add_space
1350 end
1351
1352 if has_attached_mark then
1353 f.process_keyword_text ({SHARED_TEXT_ITEMS}.ti_attached_keyword, Void)
1354 f.add_space
1355 elseif has_detachable_mark then
1356 f.process_keyword_text ({SHARED_TEXT_ITEMS}.ti_detachable_keyword, Void)
1357 f.add_space
1358 end
1359
1360 if has_separate_mark then
1361 f.process_keyword_text ({SHARED_TEXT_ITEMS}.ti_separate_keyword, Void)
1362 f.add_space
1363 end
1364 end
1365
1366 feature -- Conversion
1367
1368 to_type_set: TYPE_SET_A
1369 -- Create a type set containing one element which is `Current'.
1370 do
1371 create Result.make (1)
1372 Result.extend (create {RENAMED_TYPE_A}.make (Current, Void))
1373 ensure
1374 to_type_set_not_void: Result /= Void
1375 end
1376
1377 feature -- Access
1378
1379 sk_value (a_context_type: TYPE_A): NATURAL_32
1380 -- SK value associated to the current type.
1381 require
1382 context_type_valid: is_valid_context_type (a_context_type)
1383 do
1384 Result := c_type.sk_value
1385 end
1386
1387 has_expanded: BOOLEAN
1388 -- Has the current type some expanded types in itself ?
1389 do
1390 -- Do nothing
1391 end
1392
1393 type_id (a_context_type: TYPE_A): INTEGER
1394 -- Type ID of the corresponding class type
1395 --| See comments on `has_associated_class_type' for details on `a_context_type'.
1396 require
1397 context_type_valid: is_valid_context_type (a_context_type)
1398 has_associated_class_type: has_associated_class_type (a_context_type)
1399 do
1400 Result := associated_class_type (a_context_type).type_id
1401 end
1402
1403 static_type_id (a_context_type: TYPE_A): INTEGER
1404 -- Static type ID of the corresponding class type.
1405 --| See comments on `has_associated_class_type' for details on `a_context_type'.
1406 require
1407 context_type_valid: is_valid_context_type (a_context_type)
1408 has_associated_class_type: has_associated_class_type (a_context_type)
1409 do
1410 Result := associated_class_type (a_context_type).static_type_id
1411 end
1412
1413 external_id (a_context_type: TYPE_A): INTEGER
1414 -- External type id of `Current' (or `static_type_id' for pure Eiffel type).
1415 require
1416 context_type_valid: is_valid_context_type (a_context_type)
1417 has_associated_class_type: has_associated_class_type (a_context_type)
1418 do
1419 Result := associated_class_type (a_context_type).external_id
1420 end
1421
1422 implementation_id (a_context_type: TYPE_A): INTEGER
1423 -- Return implementation id of `Current'.
1424 require
1425 il_generation: System.il_generation
1426 context_type_valid: is_valid_context_type (a_context_type)
1427 has_associated_class_type: has_associated_class_type (a_context_type)
1428 do
1429 -- if has_associated_class_type (a_context_type) then
1430 Result := associated_class_type (a_context_type).implementation_id
1431 -- else
1432 -- check
1433 -- is_reference_at_least: is_reference
1434 -- end
1435 -- Result := System.system_object_class.compiled_class.types.first.implementation_id
1436 -- end
1437 ensure
1438 valid_result: Result > 0
1439 end
1440
1441 description: ATTR_DESC
1442 -- Description of type for skeletons
1443 local
1444 l_ref: REFERENCE_DESC
1445 do
1446 create l_ref
1447 l_ref.set_type_i (Current)
1448 Result := l_ref
1449 end
1450
1451 description_with_detachable_type: ATTR_DESC
1452 -- Description of type for skeletons
1453 -- but with detachable type if possible
1454 local
1455 l_ref: REFERENCE_DESC
1456 do
1457 create l_ref
1458 l_ref.set_type_i (as_detachable_type)
1459 Result := l_ref
1460 end
1461
1462 instantiated_description: ATTR_DESC
1463 -- Description of type when SKELETON is instantiated in the context of
1464 -- a CLASS_TYPE.
1465 do
1466 Result := description
1467 end
1468
1469 c_type: TYPE_C
1470 -- Corresponding C type
1471 do
1472 Result := reference_c_type
1473 ensure
1474 result_not_void: Result /= Void
1475 end
1476
1477 meta_type: TYPE_A
1478 -- Meta type
1479 do
1480 Result := Current
1481 end
1482
1483 generic_derivation: TYPE_A
1484 -- Precise generic derivation of current type.
1485 -- That is to say given a type, it gives the associated TYPE_A
1486 -- which can be used to search its associated CLASS_TYPE.
1487 do
1488 Result := internal_generic_derivation (0)
1489 ensure
1490 generic_derivation_not_void: Result /= Void
1491 end
1492
1493 is_numeric: BOOLEAN
1494 -- Is the current actual type a numeric type ?
1495 do
1496 -- Do nothing
1497 end
1498
1499 check_const_gen_conformance (a_gen_type: GEN_TYPE_A; a_target_type: TYPE_A; a_class: CLASS_C; i: INTEGER)
1500 -- Is `Current' a valid generic parameter at position `i' of `gen_type'?
1501 require
1502 a_gen_type_not_void: a_gen_type /= Void
1503 a_target_type_not_void: a_target_type /= Void
1504 a_class_not_void: a_class /= Void
1505 i_non_negative: i > 0
1506 local
1507 l_vtcg7: VTCG7
1508 l_formal_a: FORMAL_A
1509 l_target_type: TYPE_A
1510 do
1511 if a_target_type.is_formal then
1512 -- If we find a formal, then we get the actual generic at its position
1513 -- and check wheter Current conforms to it.
1514 -- Example: class A [G -> H, H] end
1515 -- B[G -> A[STRING, COMPARABLE]]
1516 -- `Current' is STRING
1517 -- `a_target_type' is H
1518 -- Note: We loop over all constraints of `G' an call `check_const_gen_conformance'.
1519 -- We replace `H' with `COMPARABLE' and check whether `STRING' conforms to `COMPARABLE'.
1520 l_formal_a ?= a_target_type
1521 check indeed_a_formal_a: l_formal_a /= Void end
1522 l_target_type := a_gen_type.generics.i_th (l_formal_a.position)
1523 else
1524 l_target_type := a_target_type
1525 end
1526
1527 if not conform_to (a_class, l_target_type) then
1528 -- FIXME: Manu 02/04/2004 We should be checking convertibility here,
1529 -- but for the moment it is not yet possible because this check is done
1530 -- before we do degree 4. What we need to implement is the ability
1531 -- to check converitibility without having to go through a full
1532 -- degree 4
1533 reset_constraint_error_list
1534 generate_constraint_error (a_gen_type, to_type_set, l_target_type.to_type_set, i, Void)
1535 create l_vtcg7
1536 l_vtcg7.set_in_constraint (True)
1537 l_vtcg7.set_class (a_class)
1538 l_vtcg7.set_error_list (constraint_error_list)
1539 l_vtcg7.set_parent_type (a_gen_type)
1540 Error_handler.insert_error (l_vtcg7)
1541 end
1542 end
1543
1544 frozen conform_to (a_context_class: CLASS_C; other: TYPE_A): BOOLEAN
1545 -- Does Current conform to `other' in `a_context_class'?
1546 require
1547 is_valid: is_valid
1548 a_context_class_not_void: a_context_class /= Void
1549 a_context_class_valid: a_context_class.is_valid
1550 a_context_valid_for_current: is_valid_for_class (a_context_class)
1551 other_not_void: other /= Void
1552 other_is_valid: other.is_valid
1553 a_context_valid_for_other: other.is_valid_for_class (a_context_class)
1554 do
1555 Result := internal_conform_to (a_context_class, other, False)
1556 end
1557
1558 backward_conform_to (a_context_class: CLASS_C; other: TYPE_A): BOOLEAN
1559 -- Does `other' conform to `Current' in `a_context_class'?
1560 -- The only difference with `conform_to' is that type information is collected for `Current'.
1561 require
1562 is_valid: is_valid
1563 a_context_class_not_void: a_context_class /= Void
1564 a_context_class_valid: a_context_class.is_valid
1565 a_context_valid_for_current: is_valid_for_class (a_context_class)
1566 other_not_void: other /= Void
1567 other_is_valid: other.is_valid
1568 a_context_valid_for_other: other.is_valid_for_class (a_context_class)
1569 do
1570 Result := other.internal_conform_to (a_context_class, Current, False)
1571 end
1572
1573 frozen conforms_to_array: BOOLEAN
1574 -- Does current conform to ARRAY regardless of the context.
1575 do
1576 Result := has_associated_class and then base_class.conform_to (system.array_class.compiled_class)
1577 end
1578
1579 is_conformant_to (a_context_class: CLASS_C; other: TYPE_A): BOOLEAN
1580 -- Does Current inherit from other as seen from `a_context_class'?
1581 -- Most of the time, it is equivalent to `conform_to' except
1582 -- when current is an expanded type.
1583 require
1584 is_valid: is_valid
1585 a_context_class_not_void: a_context_class /= Void
1586 a_context_class_valid: a_context_class.is_valid
1587 a_context_valid_for_current: is_valid_for_class (a_context_class)
1588 other_not_void: other /= Void
1589 other_is_valid: other.is_valid
1590 do
1591 Result := conform_to (a_context_class, other)
1592 end
1593
1594 convert_to (a_context_class: CLASS_C; a_target_type: TYPE_A): BOOLEAN
1595 -- Does current convert to `a_target_type' in `a_context_class'?
1596 -- Update `last_conversion_info' of AST_CONTEXT.
1597 require
1598 a_context_class_not_void: a_context_class /= Void
1599 a_context_class_valid: a_context_class.is_valid
1600 a_context_valid_for_current: is_valid_for_class (a_context_class)
1601 a_target_type_not_void: a_target_type /= Void
1602 a_target_type_valid: a_target_type.is_valid
1603 do
1604 Result := False
1605 context.set_last_conversion_info (Void)
1606 ensure
1607 context_set: Result implies context.last_conversion_info /= Void
1608 end
1609
1610 actual_argument_type (a_arg_types: ARRAYED_LIST [TYPE_A]): TYPE_A
1611 -- Type including like argument process based on `a_arg_types'.
1612 require
1613 a_arg_types_not_void: a_arg_types /= Void
1614 do
1615 Result := Current
1616 ensure
1617 actual_argument_type_attached: Result /= Void
1618 actual_argument_type_maintained: has_like_argument xor Result = Current
1619 end
1620
1621 formal_instantiation_in (type: TYPE_A; constraint: TYPE_A; written_id: INTEGER): TYPE_A
1622 -- Instantiation of Current written in the class of id `written_id'
1623 -- in the context of (possibly formal) `type' with actual (constraint type) `constraint'.
1624 require
1625 type_attached: type /= Void
1626 constraint_attached: constraint /= Void
1627 constraint_not_formal: not constraint.is_formal
1628 positive_id: written_id > 0
1629 do
1630 Result := Current
1631 ensure
1632 result_attached: Result /= Void
1633 end
1634
1635 instantiation_in (type: TYPE_A; written_id: INTEGER): TYPE_A
1636 -- Instantiation of Current in the context of `type'
1637 -- assuming that Current is written in the class of id `written_id'.
1638 require
1639 good_argument: type /= Void
1640 positive_id: written_id > 0
1641 do
1642 Result := Current
1643 end
1644
1645 formal_instantiated_in (a_type: TYPE_A): TYPE_A
1646 -- Instantiation of formals, if any, of Current in the context of `a_type'.
1647 --| Unlike `instantiated_in' it preserves the anchors while updating
1648 --| the `actual_type'/`conformance_type'.
1649 require
1650 valid: is_valid
1651 a_type_valid: a_type /= Void
1652 a_type_valid: a_type.is_valid
1653 do
1654 Result := Current
1655 end
1656
1657 instantiated_in (class_type: TYPE_A): TYPE_A
1658 -- Instantiation of Current in the context of `class_type'
1659 -- assuming that Current is written in the associated class
1660 -- of `class_type'.
1661 require
1662 good_argument: class_type /= Void
1663 do
1664 Result := Current
1665 ensure
1666 instantiated_in_not_void: Result /= Void
1667 end
1668
1669 adapted_in (class_type: CLASS_TYPE): TYPE_A
1670 -- See `TYPE_I.instantiation_in'.
1671 require
1672 class_type_not_void: class_type /= Void
1673 class_type_valid: class_type.associated_class.is_valid
1674 class_type_valid_for_current: is_valid_for_class (class_type.associated_class)
1675 do
1676 Result := Current
1677 ensure
1678 adapted_in_not_void: Result /= Void
1679 end
1680
1681 skeleton_adapted_in (class_type: CLASS_TYPE): TYPE_A
1682 -- Adapt current type in the context of `class_type' where all formals are adapted using
1683 -- the actual from `class_type' but only if actuals are basic types, for expanded types
1684 -- we leave the formal.
1685 -- This is a special version only used in `{GENERIC_DESC}.instantiation_in' for backward
1686 -- compatibility of storable files. If we did not care about backward compatibility, we would
1687 -- not need to use it.
1688 require
1689 class_type_not_void: class_type /= Void
1690 class_type_valid: class_type.associated_class.is_valid
1691 class_type_valid_for_current: is_valid_for_class (class_type.associated_class)
1692 do
1693 Result := Current
1694 end
1695
1696 evaluated_type_in_descendant (a_ancestor, a_descendant: CLASS_C; a_feature: FEATURE_I): TYPE_A
1697 -- Evaluate `Current' written in `a_ancestor' in the context of `a_descendant' class.
1698 -- If `a_feature' is not Void, then it is the feature seen from `a_descendant' from where
1699 -- `Current' appears (i.e. not in an inheritance clause).
1700 require
1701 type_is_valid: is_valid
1702 a_ancestor_not_void: a_ancestor /= Void
1703 a_ancestor_valid: a_ancestor.is_valid
1704 a_ancestor_compiled: a_ancestor.has_feature_table
1705 a_descendant_not_void: a_descendant /= Void
1706 a_descendant_valid: a_descendant.is_valid
1707 a_descendant_compiled: a_descendant.has_feature_table
1708 --| FIXME IEK Features from a non-conforming parent fail in this routine when assertions are evaluated.
1709 -- real_descendant: (a_feature = Void or else not a_feature.has_replicated_ast) implies a_descendant.simple_conform_to (a_ancestor)
1710 -- a_feature_valid: (a_feature /= Void and then not a_feature.has_replicated_ast) implies
1711 -- (a_feature.access_class.simple_conform_to (a_ancestor) and
1712 -- a_descendant.simple_conform_to (a_feature.access_class))
1713 is_feature_needed: has_like_argument implies a_feature /= Void
1714 is_valid_for_class: is_valid_for_class (a_ancestor)
1715 do
1716 Result := Current
1717 ensure
1718 same_object: (a_ancestor = a_descendant) implies Result = Current
1719 end
1720
1721 good_generics: BOOLEAN
1722 -- Has the base class exactly the same number of generic
1723 -- parameters in its formal generic declarations ?
1724 require
1725 is_class_valid: is_class_valid
1726 do
1727 Result := True
1728 end
1729
1730 error_generics: VTUG
1731 -- Build the error if `good_generics' returns False
1732 require
1733 not_good_generics: not good_generics
1734 do
1735 end
1736
1737 check_constraints (a_type_context: CLASS_C; a_context_feature: FEATURE_I; a_check_creation_readiness: BOOLEAN)
1738 -- Check the constained genericity validity rule and leave
1739 -- error info in `constraint_error_list'
1740 require
1741 good_argument: a_type_context /= Void
1742 good_generic_count: good_generics
1743 do
1744 end
1745
1746 check_labels (a_context_class: CLASS_C; a_node: TYPE_AS)
1747 -- Check validity of `labels' of current in `a_context_class'.
1748 require
1749 a_context_class_not_void: a_context_class /= Void
1750 a_context_class_valid: a_context_class.is_valid
1751 a_context_valid_for_current: is_valid_for_class (a_context_class)
1752 do
1753 end
1754
1755 expanded_deferred: BOOLEAN
1756 -- Is the expanded type deferred ?
1757 require
1758 has_expanded
1759 local
1760 act_type: TYPE_A
1761 do
1762 act_type := actual_type
1763 Result := act_type.is_expanded and then act_type.base_class.is_deferred
1764 end
1765
1766 valid_expanded_creation (c: CLASS_C): BOOLEAN
1767 -- Is the expanded type has an associated class with one
1768 -- creation routine which is a version of {ANY}.default_create
1769 -- exported to `class_c'.
1770 require
1771 has_expanded
1772 local
1773 a: CLASS_C
1774 creators: HASH_TABLE [EXPORT_I, STRING]
1775 do
1776 if is_expanded then
1777 a := base_class
1778 if a.is_external then
1779 Result := True
1780 else
1781 creators := a.creators
1782 if creators = Void then
1783 Result := True
1784 else
1785 creators.search (a.default_create_feature.feature_name)
1786 if creators.found then
1787 Result := creators.found_item.valid_for (c)
1788 end
1789 end
1790 end
1791 else
1792 Result := True
1793 end
1794 end
1795
1796 is_ancestor_valid: BOOLEAN
1797 -- Is type ancestor valid?
1798 -- (This is currently checked only for expanded types that have
1799 -- an external ancestor, that is not supported by CIL code generation.)
1800 require
1801 il_generation: system.il_generation
1802 do
1803 Result := True
1804 if is_expanded and then not is_external and then base_class.has_external_ancestor_class then
1805 Result := False
1806 end
1807 end
1808
1809 create_info: CREATE_INFO
1810 -- Byte code information for entity type creation
1811 require
1812 is_valid: is_valid
1813 deferred
1814 ensure
1815 create_info_not_void: Result /= Void
1816 end
1817
1818 check_for_obsolete_class (current_class: CLASS_C; current_feature: FEATURE_I)
1819 -- Check for obsolete class from Current. If
1820 -- obsolete then display warning message.
1821 require
1822 good_arg: current_class /= Void
1823 local
1824 ass_class: CLASS_C
1825 warn: OBS_CLASS_WARN
1826 do
1827 if
1828 not current_class.is_obsolete and (current_feature = Void or else not current_feature.is_obsolete) and then
1829 actual_type.has_associated_class
1830 then
1831 ass_class := actual_type.base_class
1832 if ass_class.is_obsolete and then ass_class.lace_class.options.is_warning_enabled (w_obsolete_class) then
1833 create warn.make_with_class (current_class)
1834 if current_feature /= Void then
1835 warn.set_feature (current_feature)
1836 end
1837 warn.set_obsolete_class (ass_class)
1838 Error_handler.insert_warning (warn)
1839 end
1840 end
1841 end
1842
1843 update_dependance (feat_depend: FEATURE_DEPENDANCE)
1844 -- Update dependency for Dead Code Removal
1845 do
1846 end
1847
1848 feature {TYPE_A} -- Helpers
1849
1850 internal_conform_to (a_context_class: CLASS_C; other: TYPE_A; a_in_generic: BOOLEAN): BOOLEAN
1851 -- Does Current conform to `other' in `a_context_class'?
1852 -- If `a_in_generic', it is the conformance when `Current' is an actual generic parameter
1853 -- of some other type.
1854 require
1855 is_valid: is_valid
1856 a_context_class_not_void: a_context_class /= Void
1857 a_context_class_valid: a_context_class.is_valid
1858 a_context_valid_for_current: is_valid_for_class (a_context_class)
1859 other_not_void: other /= Void
1860 other_is_valid: other.is_valid
1861 deferred
1862 end
1863
1864 valid_generic (a_context_class: CLASS_C; type: TYPE_A; a_in_generic: BOOLEAN): BOOLEAN
1865 -- Do the generic parameter of `type' conform to those of
1866 -- Current ?
1867 require
1868 a_context_class_not_void: a_context_class /= Void
1869 a_context_class_valid: a_context_class.is_valid
1870 a_context_valid_for_current: is_valid_for_class (a_context_class)
1871 type_not_void: type /= Void
1872 type_has_class: type.has_associated_class
1873 has_associated_class: has_associated_class
1874 conforming_type: type.base_class.conform_to (base_class)
1875 do
1876 end
1877
1878 internal_is_valid_for_class (a_class: CLASS_C): BOOLEAN
1879 -- Is Current consistent and valid for `a_class'?
1880 do
1881 Result := True
1882 end
1883
1884 internal_generic_derivation (a_level: INTEGER): TYPE_A
1885 -- Precise generic derivation of current type.
1886 -- That is to say given a type, it gives the associated TYPE_A
1887 -- which can be used to search its associated CLASS_TYPE.
1888 do
1889 Result := Current
1890 ensure
1891 internal_generic_derivation_not_void: Result /= Void
1892 end
1893
1894 internal_same_generic_derivation_as (current_type, other: TYPE_A; a_level: INTEGER): BOOLEAN
1895 -- Helpers for `same_generic_derivation_as'.
1896 require
1897 other_not_void: other /= Void
1898 other_derived: other.internal_generic_derivation (a_level).same_as (other)
1899 do
1900 if attached {like Current} other as l_like_current then
1901 Result := is_equal (l_like_current)
1902 end
1903 ensure
1904 -- Only if `current_type' is Void, can we ensure that a True results means that they have
1905 -- the same generic derivation.
1906 definition: (Result and current_type = Void) implies
1907 internal_generic_derivation (a_level).same_as (other.internal_generic_derivation (a_level))
1908 end
1909
1910 feature {NONE} -- Implementation
1911
1912 delayed_convert_constraint_check (
1913 context_class: CLASS_C;
1914 gen_type: GEN_TYPE_A;
1915 a_set_to_check, a_constraint_types: TYPE_SET_A;
1916 i: INTEGER;
1917 in_constraint: BOOLEAN)
1918
1919 -- Check that if we have class A [G -> ANY] and we found A [X] where
1920 -- X is expanded, then it exists a conversion routine from X to reference X
1921 -- and that `reference X' conforms to the constraint ANY.
1922 -- Delayed because could not be done during degree 4 since information
1923 -- about conversion routine is usually not yet computed.
1924 require
1925 context_class_not_void: context_class /= Void
1926 gen_type_not_void: gen_type /= Void
1927 a_set_to_check_not_void: a_set_to_check /= Void
1928 a_constraint_types_not_void: a_constraint_types /= Void
1929 a_set_to_check_is_expanded: a_set_to_check.has_expanded
1930 not_a_constraint_type_is_reference: not a_constraint_types.has_expanded
1931 local
1932 l_vtcg7: VTCG7
1933 l_to_check, l_constraint_type: TYPE_A
1934 do
1935 reset_constraint_error_list
1936
1937 -- Only used in case of a single constraint!!
1938 l_constraint_type := a_constraint_types.first.type
1939
1940 if context_class.is_valid and a_set_to_check.is_valid then
1941 l_to_check := a_set_to_check.first.type
1942 if a_set_to_check.count /= 1 or else a_constraint_types.count /= 1 then
1943 generate_constraint_error (gen_type, l_to_check.to_type_set, a_constraint_types, i, Void)
1944 -- The feature listed in the creation constraint has
1945 -- not been declared in the constraint class.
1946 create l_vtcg7
1947 l_vtcg7.set_in_constraint (in_constraint)
1948 l_vtcg7.set_class (context_class)
1949 l_vtcg7.set_error_list (constraint_error_list)
1950 l_vtcg7.set_parent_type (gen_type)
1951 Error_handler.insert_error (l_vtcg7)
1952 elseif
1953 not (l_to_check.convert_to (context_class, l_constraint_type) and
1954 l_to_check.is_conformant_to (context_class, l_constraint_type))
1955 then
1956 generate_constraint_error (gen_type, l_to_check.to_type_set, a_constraint_types, i, Void)
1957 -- The feature listed in the creation constraint has
1958 -- not been declared in the constraint class.
1959 create l_vtcg7
1960 l_vtcg7.set_in_constraint (in_constraint)
1961 l_vtcg7.set_class (context_class)
1962 l_vtcg7.set_error_list (constraint_error_list)
1963 l_vtcg7.set_parent_type (gen_type)
1964 Error_handler.insert_error (l_vtcg7)
1965 end
1966 end
1967 end
1968
1969 generate_constraint_error (gen_type: GEN_TYPE_A; current_type, constraint_type: TYPE_SET_A; position: INTEGER; a_unmatched_creation_constraints: LIST[FEATURE_I])
1970 -- Build the error corresponding to the VTCG error
1971 local
1972 constraint_info: CONSTRAINT_INFO
1973 do
1974 create constraint_info
1975 constraint_info.set_type (gen_type)
1976 constraint_info.set_actual_type_set (current_type)
1977 constraint_info.set_formal_number (position)
1978 -- This is necessary to instantiate the constraint in the context of `gen_type'
1979 -- as the constraint may involve some formal generic parameters that do not exist
1980 -- in the context of the class which triggerred the error.
1981 -- This fixes eweasel test#valid266.
1982 constraint_info.set_constraint_types (constraint_type.instantiated_in (gen_type))
1983 constraint_info.set_unmatched_creation_constraints (a_unmatched_creation_constraints)
1984 constraint_error_list.extend (constraint_info)
1985 end
1986
1987 feature {NONE} -- Attachment properties
1988
1989 attachment_bits: NATURAL_8
1990 -- Associated attachment flags
1991
1992 has_detachable_mark_mask: NATURAL_8 = 1
1993 -- Mask in `attachment_bits' that tells whether the type has an explicit detachable mark
1994
1995 has_attached_mark_mask: NATURAL_8 = 2
1996 -- Mask in `attachment_bits' that tells whether the type has an explicit attached mark
1997
1998 is_attached_mask: NATURAL_8 = 4
1999 -- Mask in `attachment_bits' that tells whether the type is attached
2000
2001 is_implicitly_attached_mask: NATURAL_8 = 8
2002 -- Mask in `attachment_bits' that tells whether the type is implicitly attached
2003
2004 variant_bits: NATURAL_8
2005 -- Associated variant flags
2006
2007 has_frozen_mark_mask: NATURAL_8 = 1
2008 -- Mask in `variant_bits' that tells whether the type has an explicit frozen mark
2009
2010 has_variant_mark_mask: NATURAL_8 = 2
2011 -- Mask in `variant_bits' that tells whether the type has an explicit variant mark
2012
2013 invariant
2014 -- A generic type should at least have one generic parameter.
2015 -- A tuple however is an eception and can have no generic parameter.
2016 generics_not_void_implies_generics_not_empty_or_tuple: (generics /= Void implies (not generics.is_empty or is_tuple))
2017
2018 expanded_consistency: is_expanded implies not is_separate
2019 separate_mark_consistency: not is_expanded implies (has_separate_mark implies is_separate)
2020
2021 note
2022 copyright: "Copyright (c) 1984-2014, Eiffel Software"
2023 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
2024 licensing_options: "http://www.eiffel.com/licensing"
2025 copying: "[
2026 This file is part of Eiffel Software's Eiffel Development Environment.
2027
2028 Eiffel Software's Eiffel Development Environment is free
2029 software; you can redistribute it and/or modify it under
2030 the terms of the GNU General Public License as published
2031 by the Free Software Foundation, version 2 of the License
2032 (available at the URL listed under "license" above).
2033
2034 Eiffel Software's Eiffel Development Environment is
2035 distributed in the hope that it will be useful, but
2036 WITHOUT ANY WARRANTY; without even the implied warranty
2037 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2038 See the GNU General Public License for more details.
2039
2040 You should have received a copy of the GNU General Public
2041 License along with Eiffel Software's Eiffel Development
2042 Environment; if not, write to the Free Software Foundation,
2043 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2044 ]"
2045 source: "[
2046 Eiffel Software
2047 5949 Hollister Ave., Goleta, CA 93117 USA
2048 Telephone 805-685-1006, Fax 805-685-6869
2049 Website http://www.eiffel.com
2050 Customer support http://support.eiffel.com
2051 ]"
2052
2053 end -- class TYPE_A

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23