/[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 42413 - (show annotations)
Fri Mar 26 03:31:02 2004 UTC (15 years, 10 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 15154 byte(s)
Moved down `associated_reference_class_type' and `reference_type' from BASIC_I to
  CL_TYPE_I.
Fixed `description' of CL_TYPE_I so that EXPANDED_DESC are now properly created
  using the new `set_cl_type_i' routine of EXPANDED_DESC. Simplified code.

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 cecil_value: INTEGER is
225 do
226 if not is_expanded then
227 Result := Sk_dtype
228 else
229 Result := Sk_exp | class_id
230 end
231 end
232
233 hash_code: INTEGER is
234 -- Hash code for current type
235 do
236 Result := Other_code + class_id
237 end
238
239 feature -- Status
240
241 element_type: INTEGER_8 is
242 -- Void element type
243 do
244 if is_expanded then
245 -- We only support expanded for external class at the moment.
246 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
247 else
248 if class_id = System.system_string_class.compiled_class.class_id then
249 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_string
250 elseif class_id = System.system_object_id then
251 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_object
252 else
253 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_class
254 end
255 end
256 end
257
258 tuple_code: INTEGER_8 is
259 -- Tuple code for class type
260 do
261 Result := feature {SHARED_GEN_CONF_LEVEL}.reference_tuple_code
262 end
263
264 is_expanded: BOOLEAN
265 -- Is the type expanded?
266
267 is_separate: BOOLEAN
268 -- Is the type separate?
269
270 is_enum: BOOLEAN is
271 -- Is current type an IL enum type?
272 -- Useful to find out if some call optimization can be done
273 -- in FEATURE_B.
274 require
275 il_generation: System.il_generation
276 do
277 Result := is_expanded and then base_class.is_enum
278 end
279
280 is_external: BOOLEAN is
281 -- Is current type based on an external class?
282 local
283 l_base_class: like base_class
284 do
285 -- All Eiffel basic types are externals, and only basic types used
286 -- as reference are not external.
287 l_base_class := base_class
288 Result := is_basic or (not l_base_class.is_basic and l_base_class.is_external)
289 end
290
291 is_generated_as_single_type: BOOLEAN is
292 -- Is associated type generated as a single type or as an interface type and
293 -- an implementation type.
294 local
295 l_class: CLASS_C
296 do
297 -- Expanded types do not have an interface since no polymorphic calls
298 -- are done on them.
299 Result := is_expanded
300 if not Result then
301 l_class := base_class
302 -- When `base_class' is a basic class and that we are here, it means
303 -- that we are handling the reference version of the basic type, which
304 -- needs to be generated with the interface type and the implementation type
305 if not l_class.is_basic then
306 -- External classes, or classes marked `frozen', or that
307 -- inherites from external classes have only one generated type.
308 Result := l_class.is_single or l_class.is_frozen or l_class.is_external
309 end
310 end
311 end
312
313 is_valid: BOOLEAN is
314 -- Is the base class still in the system and matches its specification?
315 local
316 l_base_class: like base_class
317 do
318 l_base_class := base_class
319 Result := l_base_class /= Void and then (l_base_class.generics = Void)
320 end
321
322 is_reference: BOOLEAN is
323 -- Is the type a reference type ?
324 do
325 Result := not is_expanded
326 end;
327
328 is_explicit: BOOLEAN is
329 -- Is Current type fixed at compile time?
330 do
331 if cr_info /= Void then
332 Result := cr_info.is_explicit
333 else
334 Result := True
335 end
336 end
337
338 has_associated_class_type: BOOLEAN is
339 -- Has `Current' an associated class type?
340 do
341 Result := base_class.types.has_type (Current)
342 end
343
344 same_as (other: TYPE_I): BOOLEAN is
345 -- Is `other' equal to Current ?
346 local
347 other_cl_type: CL_TYPE_I
348 do
349 other_cl_type ?= other
350 Result := other_cl_type /= Void -- FIXME
351 and then other_cl_type.class_id = class_id
352 and then other_cl_type.is_expanded = is_expanded
353 and then other_cl_type.is_separate = is_separate
354 and then other_cl_type.meta_generic = Void
355 and then other_cl_type.true_generics = Void
356 end
357
358 feature -- Setting
359
360 set_is_expanded (b: BOOLEAN) is
361 -- Assign `b' to `is_expanded'.
362 do
363 is_expanded := b
364 ensure
365 is_expanded_set: is_expanded = b
366 end
367
368 set_is_separate (b: BOOLEAN) is
369 -- Assign `b' to `is_separate'.
370 do
371 is_separate := b
372 ensure
373 is_separate_set: is_separate = b
374 end
375
376 set_cr_info (cinfo : CREATE_INFO) is
377 -- Set `cr_info' to `cinfo'.
378 require
379 create_info_not_void: cinfo /= Void
380 not_expanded: not is_expanded
381 do
382 cr_info := cinfo
383 ensure
384 cr_info_set : cr_info = cinfo
385 end
386
387 feature -- C generation
388
389 generate_expanded_creation (byte_code: BYTE_CODE; reg: REGISTRABLE; workbench_mode: BOOLEAN) is
390 -- Generate creation of expanded object associated to Current.
391 local
392 gen_type: GEN_TYPE_I
393 written_class: CLASS_C
394 class_type, written_type: CLASS_TYPE
395 creation_feature: FEATURE_I
396 c_name: STRING
397 buffer: GENERATION_BUFFER
398 do
399 buffer := byte_code.buffer
400
401 gen_type ?= Current
402
403 if gen_type /= Void then
404 byte_code.generate_block_open
405 byte_code.generate_gen_type_conversion (gen_type)
406 end
407 reg.print_register
408 if workbench_mode then
409 -- RTLX is a macro used to create
410 -- expanded types
411 if gen_type /= Void then
412 buffer.putstring (" = RTLX(typres")
413 else
414 buffer.putstring (" = RTLX(RTUD(")
415 buffer.generate_type_id (associated_class_type.static_type_id)
416 buffer.putchar (')')
417 end
418 else
419 if gen_type /= Void then
420 buffer.putstring (" = RTLN(typres")
421 else
422 buffer.putstring (" = RTLN(")
423 buffer.putint (type_id - 1)
424 end
425 class_type := associated_class_type
426 creation_feature := class_type.associated_class.creation_feature
427 if creation_feature /= Void then
428 written_class := System.class_of_id (creation_feature.written_in)
429 if written_class.generics = Void then
430 written_type := written_class.types.first
431 else
432 written_type :=
433 written_class.meta_type (class_type.type).associated_class_type
434 end
435 c_name := Encoder.feature_name (written_type.static_type_id,
436 creation_feature.body_index)
437 buffer.putstring (");")
438 buffer.new_line
439 buffer.putstring (c_name)
440 buffer.putchar ('(')
441 reg.print_register
442 Extern_declarations.add_routine_with_signature (Void_c_type,
443 c_name, <<"EIF_REFERENCE">>)
444 end
445 end
446 buffer.putchar (')')
447 buffer.putchar (';')
448
449 if gen_type /= Void then
450 byte_code.generate_block_close
451 end
452 buffer.new_line
453 end
454
455 generate_cecil_value (buffer: GENERATION_BUFFER) is
456 -- Generate cecil value
457 do
458 if not is_expanded then
459 buffer.putstring ("SK_DTYPE")
460 else
461 buffer.putstring ("SK_EXP + (uint32) ")
462 buffer.putint (associated_class_type.type_id - 1)
463 end
464 end
465
466 feature -- Array optimization
467
468 conforms_to_array: BOOLEAN is
469 do
470 Result := base_class.conform_to (array_class_c)
471 end
472
473 feature {NONE} -- Array optimization
474
475 array_class_c: CLASS_C is
476 once
477 Result := System.array_class.compiled_class
478 end
479
480 feature -- Generic conformance
481
482 generated_id (final_mode : BOOLEAN) : INTEGER is
483
484 do
485 if final_mode then
486 Result := type_id - 1
487 else
488 Result := associated_class_type.static_type_id - 1
489 end
490 end
491
492 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
493
494 do
495 if
496 use_info and then (cr_info /= Void)
497 and then not is_expanded
498 then
499 -- It's an anchored type
500 cr_info.generate_cid (buffer, final_mode)
501 else
502 buffer.putint (generated_id (final_mode))
503 buffer.putstring (", ")
504 end
505 end
506
507 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
508 do
509 if
510 use_info and then (cr_info /= Void)
511 and then not is_expanded
512 then
513 -- It's an anchored type
514 cr_info.make_gen_type_byte_code (ba)
515 else
516 ba.append_short_integer (generated_id (False))
517 end
518 end
519
520 generate_cid_array (buffer : GENERATION_BUFFER;
521 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
522 local
523 dummy : INTEGER
524 do
525 if
526 use_info and then (cr_info /= Void)
527 and then not is_expanded
528 then
529 -- It's an anchored type
530 cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
531 else
532 buffer.putint (generated_id (final_mode))
533 buffer.putstring (", ")
534
535 -- Increment counter
536 dummy := idx_cnt.next
537 end
538 end
539
540 generate_cid_init (buffer : GENERATION_BUFFER;
541 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
542 local
543 dummy : INTEGER
544 do
545 if
546 use_info and then (cr_info /= Void)
547 and then not is_expanded
548 then
549 -- It's an anchored type
550 cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
551 else
552 dummy := idx_cnt.next
553 end
554 end
555
556 feature -- Generic conformance for IL
557
558 generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
559 -- `use_info' is true iff we generate code for a
560 -- creation instruction.
561 do
562 if use_info and then cr_info /= Void then
563 -- It's an anchored type, we call feature
564 -- that will tell us the real type of the
565 -- anchor in the context of Current.
566 cr_info.generate_il_type
567 else
568 il_generator.generate_class_type_instance (Current)
569 end
570 end
571
572 feature {NONE} -- Implementation
573
574 frozen internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
575 -- Full type name of `a_base_name' using `a_prefix' in IL code generation
576 -- with namespace specification
577 require
578 a_base_name_not_void: a_base_name /= Void
579 local
580 l_name: STRING
581 l_base_class: like base_class
582 do
583 l_base_class := base_class
584 -- Result needs to be in lower case because that's
585 -- what our casing conversion routines require to perform
586 -- a good job.
587 if
588 (is_expanded and l_base_class.is_expanded) or
589 (not is_expanded and not l_base_class.is_expanded)
590 then
591 Result := a_base_name.as_lower
592 else
593 if is_expanded then
594 create Result.make (6 + a_base_name.count)
595 Result.append ("VALUE_")
596 else
597 create Result.make (10 + a_base_name.count)
598 Result.append ("REFERENCE_")
599 end
600 Result.append (a_base_name)
601 Result.to_lower
602 end
603 l_name := l_base_class.lace_class.actual_namespace
604 if a_prefix /= Void then
605 if l_name.is_empty then
606 l_name := a_prefix + "."
607 else
608 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
609 l_name) + "." + a_prefix + "."
610 end
611 else
612 if not l_name.is_empty then
613 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
614 l_name) + "."
615 end
616 end
617 Result := l_name + il_casing.pascal_casing (System.dotnet_naming_convention,
618 Result, feature {IL_CASING_CONVERSION}.upper_case)
619 ensure
620 internal_il_type_name_not_void: Result /= Void
621 internal_il_type_name_not_empty: not Result.is_empty
622 end
623
624 invariant
625 class_id_positive: class_id > 0
626
627 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23