/[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 63371 - (show annotations)
Thu Sep 7 22:37:35 2006 UTC (13 years, 5 months ago) by manus
Original Path: trunk/Src/Eiffel/eiffel/genericity/cl_type_i.e
File size: 17946 byte(s)
Fixed test#incr068 by first:
- renaming `is_valid' into `is_consistent' since it only checks the validity of TYPE_I objects.
- adding `is_valid' to TYPE_I which takes a CLASS_C as argument. Now is_valid will check that if
  you have a formal, then the CLASS_C has generics. Otherwise it is not valid.
- updating the pattern code to use `is_valid' instead of `is_consistent'.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23