/[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 43084 - (show annotations)
Tue May 18 04:14:09 2004 UTC (15 years, 9 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 15083 byte(s)
Used two words names instead of just one for `put_xx', `read_xx' and `last_xxx' routines.
Used specific `put_xxx_id' routines to generate runtime IDs. This removes those
  very annoying `- 1' in the code because the runtime and the compiler are not
  indexed the same way.

1 indexing
2 description: "Type class."
3 date: "$Date$"
4 revision: "$Revision$"
5
6 class CL_TYPE_I
7
8 inherit
9 TYPE_I
10 redefine
11 is_reference,
12 is_expanded,
13 is_separate,
14 is_valid,
15 is_explicit,
16 is_external,
17 same_as,
18 c_type,
19 conforms_to_array,
20 generated_id,
21 generate_cid,
22 make_gen_type_byte_code,
23 generate_cid_array,
24 generate_cid_init,
25 generate_gen_type_il,
26 generate_expanded_creation,
27 instantiation_in,
28 generic_derivation,
29 is_generated_as_single_type
30 end
31
32 SHARED_IL_CASING
33 export
34 {NONE} all
35 end
36
37 SHARED_GENERATION
38 export
39 {NONE} all
40 end
41
42 SHARED_DECLARATIONS
43 export
44 {NONE} all
45 end
46
47 create
48 make
49
50 feature {NONE} -- Initialization
51
52 make (id: INTEGER) is
53 -- Create new instance of `Current' with `class_id'
54 -- assigned with `id'.
55 require
56 valid_id: id > 0
57 do
58 class_id := id
59 if is_basic then
60 -- We know for sure that it is expanded then.
61 is_expanded := True
62 end
63 ensure
64 class_id_set: class_id = id
65 end
66
67 feature -- Access
68
69 class_id: INTEGER
70 -- Base class id of the type class
71
72 meta_generic: META_GENERIC is
73 -- Meta generic array describing the type class
74 do
75 -- No meta generic in non-generic type
76 end
77
78 cr_info : CREATE_INFO
79 -- Additional information for the creation
80 -- of generic types with anchored parameters
81
82 true_generics : ARRAY [TYPE_I] is
83 -- Array of generics: no mapping reference -> REFERENCE_I
84 do
85 -- Non generic types don't have them
86 end
87
88 base_class: CLASS_C is
89 -- Base class associated to the class type
90 do
91 Result := System.class_of_id (class_id)
92 end
93
94 generic_derivation: CL_TYPE_I is
95 -- Precise generic derivation of current type.
96 -- That is to say given a type, it gives the associated TYPE_I
97 -- which can be used to search its associated CLASS_TYPE.
98 do
99 Result := Current
100 end
101
102 type_a: CL_TYPE_A is
103 do
104 create Result.make (class_id)
105 Result.set_is_expanded (is_expanded)
106 Result.set_is_separate (is_separate)
107 end
108
109 name: STRING is
110 -- String that should be displayed in debugger to represent `Current'.
111 local
112 l_base_class: like base_class
113 do
114 create Result.make (32)
115 l_base_class := base_class
116 if is_expanded and not l_base_class.is_expanded then
117 Result.append ("expanded ")
118 elseif not is_expanded and l_base_class.is_expanded then
119 Result.append ("reference ")
120 elseif is_separate then
121 Result.append ("separate ")
122 end
123 Result.append (l_base_class.name_in_upper)
124 end
125
126 instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
127 -- Instantation of Current in `other'
128 do
129 Result := Current
130 end
131
132 il_type_name (a_prefix: STRING): STRING is
133 -- Class name of current type.
134 local
135 l_class_c: like base_class
136 l_is_precompiled: BOOLEAN
137 l_cl_type: like associated_class_type
138 do
139 l_class_c := base_class
140 if is_external then
141 Result := l_class_c.external_class_name.twin
142 else
143 l_is_precompiled := l_class_c.is_precompiled
144 if l_is_precompiled then
145 l_cl_type := associated_class_type
146 l_is_precompiled := l_cl_type.is_precompiled
147 if l_is_precompiled then
148 Result := associated_class_type.il_type_name (a_prefix)
149 end
150 end
151 if not l_is_precompiled then
152 Result := internal_il_type_name (l_class_c.name.twin, a_prefix)
153 end
154 end
155 end
156
157 description: ATTR_DESC is
158 -- Type description for skeletons
159 local
160 exp: EXPANDED_DESC
161 ref: REFERENCE_DESC
162 do
163 if is_expanded then
164 create exp
165 exp.set_cl_type_i (Current)
166 exp.set_type_i (Current)
167 Result := exp
168 else
169 Result := c_type.description
170 ref ?= Result
171 if ref /= Void then
172 ref.set_type_i (Current)
173 end
174 end
175 end
176
177 c_type: TYPE_C is
178 -- Associated C type
179 do
180 Result := Reference_c_type
181 end
182
183 reference_type: CL_TYPE_I is
184 -- Associated reference type of Current
185 do
186 if not is_expanded then
187 Result := Current
188 else
189 Result := twin
190 Result.set_is_expanded (False)
191 end
192 end
193
194 associated_reference_class_type: CLASS_TYPE is
195 -- Reference class type of Current
196 do
197 Result := reference_type.associated_class_type
198 end
199
200 associated_class_type: CLASS_TYPE is
201 -- Associated class type
202 require
203 has: has_associated_class_type
204 do
205 Result := base_class.types.search_item (Current)
206 end
207
208 type_id: INTEGER is
209 -- Type id of the correponding class type
210 do
211 Result := associated_class_type.type_id
212 end
213
214 sk_value: INTEGER is
215 -- Generate SK value associated to the current type.
216 do
217 if is_expanded then
218 Result := Sk_exp | (type_id - 1)
219 else
220 Result := Sk_ref | (type_id - 1)
221 end
222 end
223
224 hash_code: INTEGER is
225 -- Hash code for current type
226 do
227 Result := Other_code + class_id
228 end
229
230 feature -- Status
231
232 element_type: INTEGER_8 is
233 -- Void element type
234 do
235 if is_expanded then
236 -- We only support expanded for external class at the moment.
237 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
238 else
239 if class_id = System.system_string_class.compiled_class.class_id then
240 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_string
241 elseif class_id = System.system_object_id then
242 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_object
243 else
244 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_class
245 end
246 end
247 end
248
249 tuple_code: INTEGER_8 is
250 -- Tuple code for class type
251 do
252 Result := feature {SHARED_GEN_CONF_LEVEL}.reference_tuple_code
253 end
254
255 is_expanded: BOOLEAN
256 -- Is the type expanded?
257
258 is_separate: BOOLEAN
259 -- Is the type separate?
260
261 is_enum: BOOLEAN is
262 -- Is current type an IL enum type?
263 -- Useful to find out if some call optimization can be done
264 -- in FEATURE_B.
265 require
266 il_generation: System.il_generation
267 do
268 Result := is_expanded and then base_class.is_enum
269 end
270
271 is_external: BOOLEAN is
272 -- Is current type based on an external class?
273 local
274 l_base_class: like base_class
275 do
276 -- All Eiffel basic types are externals, and only basic types used
277 -- as reference are not external.
278 l_base_class := base_class
279 Result := is_basic or (not l_base_class.is_basic and l_base_class.is_external)
280 end
281
282 is_generated_as_single_type: BOOLEAN is
283 -- Is associated type generated as a single type or as an interface type and
284 -- an implementation type.
285 local
286 l_class: CLASS_C
287 do
288 -- Expanded types do not have an interface since no polymorphic calls
289 -- are done on them.
290 Result := is_expanded
291 if not Result then
292 l_class := base_class
293 -- When `base_class' is a basic class and that we are here, it means
294 -- that we are handling the reference version of the basic type, which
295 -- needs to be generated with the interface type and the implementation type
296 if not l_class.is_basic then
297 -- External classes, or classes marked `frozen', or that
298 -- inherites from external classes have only one generated type.
299 Result := l_class.is_single or l_class.is_frozen or l_class.is_external
300 end
301 end
302 end
303
304 is_valid: BOOLEAN is
305 -- Is the base class still in the system and matches its specification?
306 local
307 l_base_class: like base_class
308 do
309 l_base_class := base_class
310 Result := l_base_class /= Void and then (l_base_class.generics = Void)
311 end
312
313 is_reference: BOOLEAN is
314 -- Is the type a reference type ?
315 do
316 Result := not is_expanded
317 end;
318
319 is_explicit: BOOLEAN is
320 -- Is Current type fixed at compile time?
321 do
322 if cr_info /= Void then
323 Result := cr_info.is_explicit
324 else
325 Result := True
326 end
327 end
328
329 has_associated_class_type: BOOLEAN is
330 -- Has `Current' an associated class type?
331 do
332 Result := base_class.types.has_type (Current)
333 end
334
335 same_as (other: TYPE_I): BOOLEAN is
336 -- Is `other' equal to Current ?
337 local
338 other_cl_type: CL_TYPE_I
339 do
340 other_cl_type ?= other
341 Result := other_cl_type /= Void -- FIXME
342 and then other_cl_type.class_id = class_id
343 and then other_cl_type.is_expanded = is_expanded
344 and then other_cl_type.is_separate = is_separate
345 and then other_cl_type.meta_generic = Void
346 and then other_cl_type.true_generics = Void
347 end
348
349 feature -- Setting
350
351 set_is_expanded (b: BOOLEAN) is
352 -- Assign `b' to `is_expanded'.
353 do
354 is_expanded := b
355 ensure
356 is_expanded_set: is_expanded = b
357 end
358
359 set_is_separate (b: BOOLEAN) is
360 -- Assign `b' to `is_separate'.
361 do
362 is_separate := b
363 ensure
364 is_separate_set: is_separate = b
365 end
366
367 set_cr_info (cinfo : CREATE_INFO) is
368 -- Set `cr_info' to `cinfo'.
369 require
370 create_info_not_void: cinfo /= Void
371 not_expanded: not is_expanded
372 do
373 cr_info := cinfo
374 ensure
375 cr_info_set : cr_info = cinfo
376 end
377
378 feature -- C generation
379
380 generate_expanded_creation (byte_code: BYTE_CODE; reg: REGISTRABLE; workbench_mode: BOOLEAN) is
381 -- Generate creation of expanded object associated to Current.
382 local
383 gen_type: GEN_TYPE_I
384 written_class: CLASS_C
385 class_type, written_type: CLASS_TYPE
386 creation_feature: FEATURE_I
387 c_name: STRING
388 buffer: GENERATION_BUFFER
389 do
390 buffer := byte_code.buffer
391
392 gen_type ?= Current
393
394 if gen_type /= Void then
395 byte_code.generate_block_open
396 byte_code.generate_gen_type_conversion (gen_type)
397 end
398 reg.print_register
399 if workbench_mode then
400 -- RTLX is a macro used to create
401 -- expanded types
402 if gen_type /= Void then
403 buffer.put_string (" = RTLX(typres")
404 else
405 buffer.put_string (" = RTLX(RTUD(")
406 buffer.put_static_type_id (associated_class_type.static_type_id)
407 buffer.put_character (')')
408 end
409 else
410 if gen_type /= Void then
411 buffer.put_string (" = RTLN(typres")
412 else
413 buffer.put_string (" = RTLN(")
414 buffer.put_type_id (type_id)
415 end
416 class_type := associated_class_type
417 creation_feature := class_type.associated_class.creation_feature
418 if creation_feature /= Void then
419 written_class := System.class_of_id (creation_feature.written_in)
420 if written_class.generics = Void then
421 written_type := written_class.types.first
422 else
423 written_type :=
424 written_class.meta_type (class_type.type).associated_class_type
425 end
426 c_name := Encoder.feature_name (written_type.static_type_id,
427 creation_feature.body_index)
428 buffer.put_string (");")
429 buffer.put_new_line
430 buffer.put_string (c_name)
431 buffer.put_character ('(')
432 reg.print_register
433 Extern_declarations.add_routine_with_signature (Void_c_type,
434 c_name, <<"EIF_REFERENCE">>)
435 end
436 end
437 buffer.put_character (')')
438 buffer.put_character (';')
439
440 if gen_type /= Void then
441 byte_code.generate_block_close
442 end
443 buffer.put_new_line
444 end
445
446 generate_cecil_value (buffer: GENERATION_BUFFER) is
447 -- Generate cecil value
448 do
449 if not is_expanded then
450 buffer.put_string ("SK_REF + (uint32) ")
451 else
452 buffer.put_string ("SK_EXP + (uint32) ")
453 end
454 buffer.put_type_id (associated_class_type.type_id)
455 end
456
457 feature -- Array optimization
458
459 conforms_to_array: BOOLEAN is
460 do
461 Result := base_class.conform_to (array_class_c)
462 end
463
464 feature {NONE} -- Array optimization
465
466 array_class_c: CLASS_C is
467 once
468 Result := System.array_class.compiled_class
469 end
470
471 feature -- Generic conformance
472
473 generated_id (final_mode : BOOLEAN) : INTEGER is
474
475 do
476 if final_mode then
477 Result := type_id - 1
478 else
479 Result := associated_class_type.static_type_id - 1
480 end
481 end
482
483 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
484
485 do
486 if
487 use_info and then (cr_info /= Void)
488 and then not is_expanded
489 then
490 -- It's an anchored type
491 cr_info.generate_cid (buffer, final_mode)
492 else
493 buffer.put_integer (generated_id (final_mode))
494 buffer.put_string (", ")
495 end
496 end
497
498 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
499 do
500 if
501 use_info and then (cr_info /= Void)
502 and then not is_expanded
503 then
504 -- It's an anchored type
505 cr_info.make_gen_type_byte_code (ba)
506 else
507 ba.append_short_integer (generated_id (False))
508 end
509 end
510
511 generate_cid_array (buffer : GENERATION_BUFFER;
512 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
513 local
514 dummy : INTEGER
515 do
516 if
517 use_info and then (cr_info /= Void)
518 and then not is_expanded
519 then
520 -- It's an anchored type
521 cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
522 else
523 buffer.put_integer (generated_id (final_mode))
524 buffer.put_string (", ")
525
526 -- Increment counter
527 dummy := idx_cnt.next
528 end
529 end
530
531 generate_cid_init (buffer : GENERATION_BUFFER;
532 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
533 local
534 dummy : INTEGER
535 do
536 if
537 use_info and then (cr_info /= Void)
538 and then not is_expanded
539 then
540 -- It's an anchored type
541 cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
542 else
543 dummy := idx_cnt.next
544 end
545 end
546
547 feature -- Generic conformance for IL
548
549 generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
550 -- `use_info' is true iff we generate code for a
551 -- creation instruction.
552 do
553 if use_info and then cr_info /= Void then
554 -- It's an anchored type, we call feature
555 -- that will tell us the real type of the
556 -- anchor in the context of Current.
557 cr_info.generate_il_type
558 else
559 il_generator.generate_class_type_instance (Current)
560 end
561 end
562
563 feature {NONE} -- Implementation
564
565 frozen internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
566 -- Full type name of `a_base_name' using `a_prefix' in IL code generation
567 -- with namespace specification
568 require
569 a_base_name_not_void: a_base_name /= Void
570 local
571 l_name: STRING
572 l_base_class: like base_class
573 do
574 l_base_class := base_class
575 -- Result needs to be in lower case because that's
576 -- what our casing conversion routines require to perform
577 -- a good job.
578 if
579 (is_expanded and l_base_class.is_expanded) or
580 (not is_expanded and not l_base_class.is_expanded)
581 then
582 Result := a_base_name.as_lower
583 else
584 if is_expanded then
585 create Result.make (6 + a_base_name.count)
586 Result.append ("VALUE_")
587 else
588 create Result.make (10 + a_base_name.count)
589 Result.append ("REFERENCE_")
590 end
591 Result.append (a_base_name)
592 Result.to_lower
593 end
594 l_name := l_base_class.lace_class.actual_namespace
595 if a_prefix /= Void then
596 if l_name.is_empty then
597 l_name := a_prefix + "."
598 else
599 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
600 l_name) + "." + a_prefix + "."
601 end
602 else
603 if not l_name.is_empty then
604 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
605 l_name) + "."
606 end
607 end
608 Result := l_name + il_casing.pascal_casing (System.dotnet_naming_convention,
609 Result, feature {IL_CASING_CONVERSION}.upper_case)
610 ensure
611 internal_il_type_name_not_void: Result /= Void
612 internal_il_type_name_not_empty: not Result.is_empty
613 end
614
615 invariant
616 class_id_positive: class_id > 0
617
618 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23