/[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 43989 - (show annotations)
Mon Jun 28 20:05:51 2004 UTC (15 years, 7 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 13834 byte(s)
Single type code generation is not yet perfect especially with inherited
routine using generic types. So we make sure that it is enabled only
when it is necessary.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23