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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23