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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 69629 - (show annotations)
Mon Jul 23 21:36:18 2007 UTC (12 years, 7 months ago) by manus
File size: 21305 byte(s)
Creation of CAT_mono branch to implement variant/invariant proposal
1 indexing
2 description: "Type class."
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 CL_TYPE_I
9
10 inherit
11 TYPE_I
12 redefine
13 anchor_instantiation_in,
14 c_type,
15 conforms_to_array,
16 created_in,
17 external_id,
18 full_type_byte_code_type_id,
19 generate_cid,
20 generate_cid_array,
21 generate_cid_init,
22 generate_gen_type_il,
23 generate_expanded_creation,
24 generate_expanded_initialization,
25 generated_id,
26 internal_generic_derivation,
27 instantiated_description,
28 instantiation_in,
29 is_expanded,
30 is_explicit,
31 is_external,
32 is_frozen,
33 is_generated_as_single_type,
34 is_reference,
35 is_separate,
36 is_consistent,
37 make_gen_type_byte_code,
38 same_as,
39 static_type_id
40 end
41
42 SHARED_IL_CASING
43 export
44 {NONE} all
45 end
46
47 SHARED_GENERATION
48 export
49 {NONE} all
50 end
51
52 SHARED_DECLARATIONS
53 export
54 {NONE} all
55 end
56
57 create
58 make
59
60 feature {NONE} -- Initialization
61
62 make (id: INTEGER) is
63 -- Create new instance of `Current' with `class_id'
64 -- assigned with `id'.
65 require
66 valid_id: id > 0
67 do
68 class_id := id
69 ensure
70 class_id_set: class_id = id
71 end
72
73 feature -- Access
74
75 class_id: INTEGER
76 -- Base class id of the type class
77
78 meta_generic: META_GENERIC is
79 -- Meta generic array describing the type class
80 do
81 -- No meta generic in non-generic type
82 end
83
84 cr_info : CREATE_INFO
85 -- Additional information for the creation
86 -- of generic types with anchored parameters
87
88 true_generics : ARRAY [TYPE_I] is
89 -- Array of generics: no mapping reference -> REFERENCE_I
90 do
91 -- Non generic types don't have them
92 end
93
94 base_class: CLASS_C is
95 -- Base class associated to the class type
96 do
97 Result := System.class_of_id (class_id)
98 end
99
100 internal_generic_derivation (a_level: INTEGER): CL_TYPE_I is
101 -- Precise generic derivation of current type.
102 -- That is to say given a type, it gives the associated TYPE_I
103 -- which can be used to search its associated CLASS_TYPE.
104 local
105 c: like cr_info
106 do
107 c := cr_info
108 if c = Void then
109 Result := Current
110 else
111 -- Remove creation information.
112 cr_info := Void
113 Result := twin
114 cr_info := c
115 end
116 end
117
118 type_a: CL_TYPE_A is
119 do
120 create Result.make (class_id)
121 Result.set_mark (declaration_mark)
122 end
123
124 name: STRING is
125 -- String that should be displayed in debugger to represent `Current'.
126 do
127 Result := base_name
128 end
129
130 duplicate: like Current is
131 -- Duplication
132 do
133 Result := twin
134 end
135
136 reference_type: CL_TYPE_I is
137 -- Corresponding reference type
138 require
139 is_expanded: is_expanded
140 do
141 Result := duplicate
142 Result.set_reference_mark
143 ensure
144 result_is_reference: Result.is_reference
145 end
146
147 instantiation_in (other: CLASS_TYPE): CL_TYPE_I is
148 -- Instantation of Current in `other'
149 do
150 Result := Current
151 end
152
153 anchor_instantiation_in (other: CLASS_TYPE): CL_TYPE_I is
154 -- Instantation of `like Current' parts of Current in `other'
155 do
156 Result := Current
157 end
158
159 created_in (other: CLASS_TYPE): TYPE_I is
160 -- Resulting type of Current as if it was used to create object in `other'.
161 do
162 Result := Current
163 if cr_info /= Void then
164 Result := cr_info.created_in (other)
165 end
166 end
167
168 il_type_name (a_prefix: STRING): STRING is
169 -- Class name of current type.
170 local
171 l_class_c: like base_class
172 l_cl_type: like associated_class_type
173 l_alias_name: STRING
174 l_dot_pos: INTEGER
175 do
176 l_class_c := base_class
177 if is_external then
178 Result := l_class_c.external_class_name.twin
179 else
180 if l_class_c.is_precompiled then
181 -- Reuse the name that was computed at precompilation time.
182 l_cl_type := associated_class_type
183 if l_cl_type.is_precompiled then
184 Result := l_cl_type.il_type_name (a_prefix)
185 end
186 end
187 if Result = Void then
188 if not has_no_mark or else is_basic or else l_class_c.external_class_name.is_equal (l_class_c.name) then
189 Result := internal_il_type_name (l_class_c.name.twin, a_prefix)
190 else
191 -- Special case when an external name has been specified.
192 Result := l_class_c.external_class_name.twin
193 Result.left_adjust
194 Result.right_adjust
195 -- Remove leading `.' since it is not a valid .NET name.
196 from
197 until
198 Result.is_empty or else Result.item (1) /= '.'
199 loop
200 Result.remove_head (1)
201 end
202 -- Remove trailing `.' since it is not a valid .NET name.
203 from
204 until
205 Result.is_empty or else Result.item (Result.count) /= '.'
206 loop
207 Result.remove_tail (1)
208 end
209 if Result.is_empty then
210 -- External name is invalid since empty, we use the normal
211 -- way of generating the .Net name
212 Result := internal_il_type_name (l_class_c.name.twin, a_prefix)
213 else
214 if a_prefix /= Void then
215 l_dot_pos := Result.last_index_of ('.', Result.count)
216 if l_dot_pos = 0 then
217 Result.prepend_character ('.')
218 Result.prepend (a_prefix)
219 else
220 check
221 -- Because there are no more leading or trailing `.'.
222 valid_l_dot_pos: l_dot_pos > 1 and l_dot_pos < Result.count
223 end
224 l_alias_name := Result.substring (l_dot_pos + 1, Result.count)
225 check
226 l_alias_name_not_empty: not l_alias_name.is_empty
227 end
228 Result.keep_head (l_dot_pos)
229 l_alias_name := internal_il_base_type_name (l_alias_name)
230 Result.append (a_prefix)
231 Result.append_character ('.')
232 Result.append (l_alias_name)
233 end
234 end
235 end
236 end
237 end
238 end
239 end
240
241 description, instantiated_description: ATTR_DESC is
242 -- Type description for skeletons
243 local
244 exp: EXPANDED_DESC
245 ref: REFERENCE_DESC
246 do
247 if is_expanded then
248 create exp
249 exp.set_cl_type_i (Current)
250 exp.set_type_i (Current)
251 Result := exp
252 else
253 Result := c_type.description
254 ref ?= Result
255 if ref /= Void then
256 ref.set_type_i (Current)
257 end
258 end
259 end
260
261 c_type: TYPE_C is
262 -- Associated C type
263 do
264 Result := Reference_c_type
265 end
266
267 associated_class_type: CLASS_TYPE is
268 -- Associated class type
269 require
270 has: has_associated_class_type
271 do
272 Result := base_class.types.search_item (Current)
273 ensure
274 result_not_void: Result /= Void
275 end
276
277 type_id: INTEGER is
278 -- Type id of the correponding class type
279 do
280 Result := associated_class_type.type_id
281 end
282
283 static_type_id: INTEGER is
284 -- Type id of the correponding class type
285 require else
286 ok: True
287 do
288 Result := associated_class_type.static_type_id
289 end
290
291 external_id: INTEGER is
292 -- External type id of `Current' (or `static_type_id' for pure Eiffel type).
293 do
294 Result := associated_class_type.external_id
295 end
296
297 sk_value: INTEGER is
298 -- Generate SK value associated to the current type.
299 do
300 if is_expanded then
301 Result := Sk_exp | (type_id - 1)
302 else
303 Result := Sk_ref | (type_id - 1)
304 end
305 end
306
307 hash_code: INTEGER is
308 -- Hash code for current type
309 do
310 Result := Other_code + class_id
311 end
312
313 feature -- Type evaluation
314
315 implemented_type (implemented_in: INTEGER): CL_TYPE_I is
316 -- Parent type that corresponds to the current one.
317 require
318 valid_implemented_in: implemented_in > 0
319 local
320 written_class: CLASS_C
321 do
322 -- If it is defined in current class, that's easy and we
323 -- return `current_type'. Otherwise we have to find the
324 -- correct CLASS_TYPE object where it is implemented.
325 if class_id = implemented_in then
326 Result := Current
327 else
328 written_class := System.class_of_id (implemented_in)
329 -- We go through the hierarchy only when `written_class'
330 -- is generic, otherwise for the most general case where
331 -- `written_class' is not generic it will take a long
332 -- time to go through the inheritance hierarchy.
333 if written_class.types.count > 1 then
334 Result := type_a.find_class_type (written_class).type_i
335 else
336 Result := written_class.types.first.type
337 end
338 end
339 end
340
341 feature -- Status
342
343 element_type: INTEGER_8 is
344 -- Void element type
345 do
346 if is_expanded then
347 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
348 else
349 if class_id = System.system_string_class.compiled_class.class_id then
350 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_string
351 elseif class_id = System.system_object_id or class_id = system.any_id then
352 -- For ANY or SYSTEM_OBJECT, we always generate a System.Object
353 -- signature since we can now assign SYSTEM_OBJECTs into ANYs.
354 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_object
355 else
356 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_class
357 end
358 end
359 end
360
361 tuple_code: INTEGER_8 is
362 -- Tuple code for class type
363 do
364 Result := {SHARED_GEN_CONF_LEVEL}.reference_tuple_code
365 end
366
367 has_no_mark: BOOLEAN is
368 -- Has class type no explicit mark?
369 do
370 Result := declaration_mark = {CL_TYPE_A}.no_mark
371 ensure
372 definition: Result = (declaration_mark = {CL_TYPE_A}.no_mark)
373 end
374
375 has_expanded_mark: BOOLEAN is
376 -- Is class type explicitly marked as expanded?
377 do
378 Result := declaration_mark = {CL_TYPE_A}.expanded_mark
379 ensure
380 definition: Result = (declaration_mark = {CL_TYPE_A}.expanded_mark)
381 end
382
383 has_reference_mark: BOOLEAN is
384 -- Is class type explicitly marked as reference?
385 do
386 Result := declaration_mark = {CL_TYPE_A}.reference_mark
387 ensure
388 definition: Result = (declaration_mark = {CL_TYPE_A}.reference_mark)
389 end
390
391 has_separate_mark: BOOLEAN is
392 -- Is class type explicitly marked as reference?
393 do
394 Result := declaration_mark = {CL_TYPE_A}.separate_mark
395 ensure
396 definition: Result = (declaration_mark = {CL_TYPE_A}.separate_mark)
397 end
398
399 is_expanded: BOOLEAN is
400 -- Is the type expanded?
401 do
402 -- Do not check for `has_separate_mark' because a separate class cannot be expanded.
403 Result := has_expanded_mark or else (has_no_mark and then base_class.is_expanded)
404 end
405
406 is_reference: BOOLEAN is
407 -- Is the type a reference type?
408 do
409 Result := has_reference_mark or else
410 ((has_no_mark or has_separate_mark) and then not base_class.is_expanded)
411 end
412
413 is_separate: BOOLEAN is
414 -- Is the type separate?
415 do
416 Result := has_separate_mark
417 end
418
419 is_enum: BOOLEAN is
420 -- Is current type an IL enum type?
421 -- Useful to find out if some call optimization can be done
422 -- in FEATURE_B.
423 require
424 il_generation: System.il_generation
425 do
426 Result := is_expanded and then base_class.is_enum
427 end
428
429 is_external: BOOLEAN is
430 -- Is current type based on an external class?
431 local
432 l_base_class: like base_class
433 do
434 -- All Eiffel basic types are externals, and only basic types used
435 -- as reference are not external.
436 l_base_class := base_class
437 Result := l_base_class.is_external and then not l_base_class.is_basic
438 end
439
440 is_frozen: BOOLEAN is
441 -- Is current type based on a frozen class?
442 do
443 Result := base_class.is_frozen
444 end
445
446 is_generated_as_single_type: BOOLEAN is
447 -- Is associated type generated as a single type or as an interface type and
448 -- an implementation type.
449 do
450 -- External classes have only one type.
451 Result := is_external
452 if not Result then
453 -- Classes that inherits from external classes
454 -- have only one generated type as well as expanded types.
455 Result := base_class.is_single or else is_expanded
456 end
457 end
458
459 is_consistent: BOOLEAN is
460 -- Is the base class still in the system and matches its specification?
461 local
462 l_base_class: like base_class
463 do
464 l_base_class := base_class
465 Result := l_base_class /= Void and then (l_base_class.generics = Void)
466 end
467
468 is_explicit: BOOLEAN is
469 -- Is Current type fixed at compile time?
470 do
471 if cr_info /= Void then
472 Result := cr_info.is_explicit
473 else
474 Result := True
475 end
476 end
477
478 has_associated_class_type: BOOLEAN is
479 -- Has `Current' an associated class type?
480 do
481 Result := base_class.types.has_type (Current)
482 end
483
484 same_as (other: TYPE_I): BOOLEAN is
485 -- Is `other' equal to Current ?
486 local
487 other_cl_type: CL_TYPE_I
488 do
489 other_cl_type ?= other
490 Result := other_cl_type /= Void -- FIXME
491 and then other_cl_type.class_id = class_id
492 and then other_cl_type.is_expanded = is_expanded
493 and then other_cl_type.is_separate = is_separate
494 and then other_cl_type.meta_generic = Void
495 and then other_cl_type.true_generics = Void
496 end
497
498 has_actual (type: CL_TYPE_I): BOOLEAN is
499 -- Is `type' an (possibly nested) actual parameter of this type?
500 require
501 non_void_type: type /= Void
502 do
503 -- False here.
504 end
505
506 feature -- Setting
507
508 set_expanded_mark is
509 -- Set class type declaration as expanded.
510 do
511 declaration_mark := {CL_TYPE_A}.expanded_mark
512 ensure
513 has_expanded_mark: has_expanded_mark
514 end
515
516 set_reference_mark is
517 -- Set class type declaration as reference.
518 do
519 declaration_mark := {CL_TYPE_A}.reference_mark
520 ensure
521 has_reference_mark: has_reference_mark
522 end
523
524 set_separate_mark is
525 -- Set class type declaration as separate.
526 do
527 declaration_mark := {CL_TYPE_A}.separate_mark
528 ensure
529 has_separate_mark: has_separate_mark
530 end
531
532 set_cr_info (cinfo : CREATE_INFO) is
533 -- Set `cr_info' to `cinfo'.
534 require
535 create_info_not_void: cinfo /= Void
536 not_expanded: not is_expanded or else cinfo.is_equal (create {CREATE_CURRENT})
537 do
538 cr_info := cinfo
539 ensure
540 cr_info_set : cr_info = cinfo
541 end
542
543 feature -- C generation
544
545 generate_expanded_creation (buffer: GENERATION_BUFFER; target_name: STRING) is
546 -- Generate creation of expanded object associated to Current.
547 do
548 associated_class_type.generate_expanded_creation (buffer, target_name, Current)
549 end
550
551 generate_expanded_initialization (buffer: GENERATION_BUFFER; target_name: STRING) is
552 -- Generate creation of expanded object associated to Current.
553 do
554 associated_class_type.generate_expanded_initialization (buffer, target_name, target_name, True)
555 end
556
557 generate_cecil_value (buffer: GENERATION_BUFFER) is
558 -- Generate cecil value
559 do
560 if not is_expanded then
561 buffer.put_string ("SK_REF + (uint32) ")
562 else
563 buffer.put_string ("SK_EXP + (uint32) ")
564 end
565 buffer.put_type_id (associated_class_type.type_id)
566 end
567
568 feature -- Array optimization
569
570 conforms_to_array: BOOLEAN is
571 do
572 Result := base_class.conform_to (array_class_c)
573 end
574
575 feature {NONE} -- Array optimization
576
577 array_class_c: CLASS_C is
578 once
579 Result := System.array_class.compiled_class
580 end
581
582 feature {NONE} -- Generic conformance
583
584 full_type_byte_code_type_id: INTEGER is
585 -- Associated type ID used in type information byte code.
586 do
587 Result := type_id - 1
588 ensure then
589 definition: Result = type_id - 1
590 end
591
592 feature -- Generic conformance
593
594 generated_id (final_mode : BOOLEAN) : INTEGER is
595
596 do
597 if final_mode then
598 Result := type_id - 1
599 else
600 Result := associated_class_type.static_type_id - 1
601 end
602 end
603
604 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
605
606 do
607 if
608 use_info and then (cr_info /= Void)
609 and then not is_expanded
610 then
611 -- It's an anchored type
612 cr_info.generate_cid (buffer, final_mode)
613 else
614 buffer.put_integer (generated_id (final_mode))
615 buffer.put_character (',')
616 end
617 end
618
619 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
620 do
621 if
622 use_info and then (cr_info /= Void)
623 and then not is_expanded
624 then
625 -- It's an anchored type
626 cr_info.make_gen_type_byte_code (ba)
627 else
628 ba.append_short_integer (generated_id (False))
629 end
630 end
631
632 generate_cid_array (buffer : GENERATION_BUFFER;
633 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
634 local
635 dummy : INTEGER
636 do
637 if
638 use_info and then (cr_info /= Void)
639 and then not is_expanded
640 then
641 -- It's an anchored type
642 cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
643 else
644 buffer.put_integer (generated_id (final_mode))
645 buffer.put_character (',')
646
647 -- Increment counter
648 dummy := idx_cnt.next
649 end
650 end
651
652 generate_cid_init (buffer : GENERATION_BUFFER;
653 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
654 local
655 dummy : INTEGER
656 do
657 if
658 use_info and then (cr_info /= Void)
659 and then not is_expanded
660 then
661 -- It's an anchored type
662 cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
663 else
664 dummy := idx_cnt.next
665 end
666 end
667
668 feature -- Generic conformance for IL
669
670 generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
671 -- `use_info' is true iff we generate code for a
672 -- creation instruction.
673 do
674 if use_info and then cr_info /= Void then
675 -- It's an anchored type, we call feature
676 -- that will tell us the real type of the
677 -- anchor in the context of Current.
678 cr_info.generate_il_type
679 else
680 il_generator.generate_class_type_instance (Current)
681 end
682 end
683
684 feature {NONE} -- Implementation
685
686 base_name: STRING is
687 -- String that should be displayed in debugger to represent `Current'.
688 local
689 l_base_class: like base_class
690 do
691 create Result.make (32)
692 l_base_class := base_class
693 if is_expanded and not l_base_class.is_expanded then
694 Result.append ("expanded ")
695 elseif is_reference and l_base_class.is_expanded then
696 Result.append ("reference ")
697 elseif is_separate then
698 Result.append ("separate ")
699 end
700 Result.append (l_base_class.name)
701 end
702
703 frozen internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
704 -- Full type name of `a_base_name' using `a_prefix' in IL code generation
705 -- with namespace specification
706 require
707 a_base_name_not_void: a_base_name /= Void
708 a_base_name_not_empty: not a_base_name.is_empty
709 do
710 Result := internal_il_base_type_name (a_base_name)
711 -- Result needs to be in lower case because that's
712 -- what our casing conversion routines require to perform
713 -- a good job.
714 Result.to_lower
715 Result := il_casing.type_name (base_class.original_class.actual_namespace, a_prefix, Result, System.dotnet_naming_convention)
716 ensure
717 internal_il_type_name_not_void: Result /= Void
718 internal_il_type_name_not_empty: not Result.is_empty
719 end
720
721 frozen internal_il_base_type_name (a_base_name: STRING): STRING is
722 -- Given `a_base_name' provides its updated name depending on its usage.
723 require
724 a_base_name_not_void: a_base_name /= Void
725 a_base_name_not_empty: not a_base_name.is_empty
726 local
727 l_base_class: like base_class
728 do
729 l_base_class := base_class
730 if is_expanded and then not l_base_class.is_expanded then
731 create Result.make (6 + a_base_name.count)
732 Result.append ("value_")
733 elseif not is_expanded and then l_base_class.is_expanded then
734 create Result.make (10 + a_base_name.count)
735 Result.append ("reference_")
736 else
737 create Result.make (a_base_name.count)
738 end
739 Result.append (a_base_name)
740 ensure
741 internal_il_base_type_name_not_void: Result /= Void
742 internal_il_base_type_name_not_empty: not Result.is_empty
743 end
744
745 feature {CL_TYPE_A, TUPLE_CLASS_B, CIL_CODE_GENERATOR} -- Implementation: class type declaration marks
746
747 declaration_mark: NATURAL_8
748 -- Declaration mark associated with a class type (if any)
749
750 feature {CL_TYPE_A, TUPLE_CLASS_B} -- Implementation: class type declaration marks
751
752 set_mark (mark: like declaration_mark) is
753 -- Set `declaration_mark' to the given value `mark'.
754 require
755 valid_declaration_mark:
756 mark = {CL_TYPE_A}.no_mark or mark = {CL_TYPE_A}.expanded_mark or
757 mark = {CL_TYPE_A}.reference_mark or mark = {CL_TYPE_A}.separate_mark
758 do
759 declaration_mark := mark
760 ensure
761 declaration_mark_set: declaration_mark = mark
762 end
763
764 invariant
765 class_id_positive: class_id > 0
766 valid_declaration_mark:
767 declaration_mark = {CL_TYPE_A}.no_mark or
768 declaration_mark = {CL_TYPE_A}.expanded_mark or
769 declaration_mark = {CL_TYPE_A}.reference_mark or
770 declaration_mark = {CL_TYPE_A}.separate_mark
771
772 indexing
773 copyright: "Copyright (c) 1984-2006, Eiffel Software"
774 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
775 licensing_options: "http://www.eiffel.com/licensing"
776 copying: "[
777 This file is part of Eiffel Software's Eiffel Development Environment.
778
779 Eiffel Software's Eiffel Development Environment is free
780 software; you can redistribute it and/or modify it under
781 the terms of the GNU General Public License as published
782 by the Free Software Foundation, version 2 of the License
783 (available at the URL listed under "license" above).
784
785 Eiffel Software's Eiffel Development Environment is
786 distributed in the hope that it will be useful, but
787 WITHOUT ANY WARRANTY; without even the implied warranty
788 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
789 See the GNU General Public License for more details.
790
791 You should have received a copy of the GNU General Public
792 License along with Eiffel Software's Eiffel Development
793 Environment; if not, write to the Free Software Foundation,
794 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
795 ]"
796 source: "[
797 Eiffel Software
798 356 Storke Road, Goleta, CA 93117 USA
799 Telephone 805-685-1006, Fax 805-685-6869
800 Website http://www.eiffel.com
801 Customer support http://support.eiffel.com
802 ]"
803
804 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23