/[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 56564 - (show annotations)
Tue Jan 17 15:00:56 2006 UTC (14 years, 1 month ago) by alexk
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 17011 byte(s)
Added a feature to replace "like Current" with the supplied context class
type.
Added a feature to determine if a generic type has a given class type as an
actual parameter.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23