/[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 57781 - (show annotations)
Mon Mar 27 17:11:27 2006 UTC (13 years, 11 months ago) by patrickr
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 17136 byte(s)
New compiler with new configuration system
For now only the batch compiler works

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23