/[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 37130 - (show annotations)
Mon May 5 18:08:43 2003 UTC (16 years, 9 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 13985 byte(s)
Minor optimization of `element_type to avoid useless information retrieval.
Removed `is_out' related code since we are now using TYPED_POINTER [XX] to
  represent them.

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_true_expanded,
13 is_separate,
14 is_valid,
15 is_explicit,
16 is_external,
17 same_as,
18 c_type,
19 instantiation_in,
20 complete_instantiation_in,
21 conforms_to_array,
22 generated_id,
23 generate_cid,
24 make_gen_type_byte_code,
25 generate_cid_array,
26 generate_cid_init,
27 generate_gen_type_il,
28 generate_expanded_creation
29 end
30
31 DEBUG_OUTPUT
32 export
33 {NONE} all
34 end
35
36 SHARED_IL_CASING
37 export
38 {NONE} all
39 end
40
41 SHARED_GENERATION
42 export
43 {NONE} all
44 end
45
46 SHARED_DECLARATIONS
47 export
48 {NONE} all
49 end
50
51 create
52 make
53
54 feature {NONE} -- Initialization
55
56 make (id: INTEGER) is
57 -- Create new instance of `Current' with `class_id'
58 -- assigned with `id'.
59 require
60 valid_id: id > 0
61 do
62 class_id := id
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 type_a: CL_TYPE_A is
95 do
96 create Result.make (class_id)
97 Result.set_is_true_expanded (is_true_expanded)
98 Result.set_is_separate (is_separate)
99 end
100
101 il_type_name (a_prefix: STRING): STRING is
102 -- Class name of current type.
103 local
104 l_class_c: like base_class
105 l_is_precompiled: BOOLEAN
106 l_cl_type: like associated_class_type
107 do
108 l_class_c := base_class
109 if l_class_c.is_external then
110 Result := clone (l_class_c.external_class_name)
111 else
112 l_is_precompiled := l_class_c.is_precompiled
113 if l_is_precompiled then
114 l_cl_type := associated_class_type
115 l_is_precompiled := l_cl_type.is_precompiled
116 if l_is_precompiled then
117 Result := associated_class_type.il_type_name (a_prefix)
118 end
119 end
120 if not l_is_precompiled then
121 Result := internal_il_type_name (clone (l_class_c.name), a_prefix)
122 end
123 end
124 end
125
126 instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
127 -- Instantiation of Current in context of `other'
128 require else
129 True
130 do
131 Result := Current
132 end
133
134 complete_instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
135 -- Instantiation of Current in context of `other'
136 require else
137 True
138 do
139 Result := Current
140 end
141
142 description: ATTR_DESC is
143 -- Type description for skeletons
144 local
145 exp: EXPANDED_DESC
146 ref: REFERENCE_DESC
147 do
148 if is_true_expanded then
149 !! exp
150 is_true_expanded := False
151 exp.set_class_type (base_class.types.search_item (Current))
152 is_true_expanded := True
153 exp.set_type_i (Current)
154 Result := exp
155 elseif is_separate then
156 -- FIXME
157 Result := c_type.description
158 else
159 Result := c_type.description
160 end
161
162 ref ?= Result
163 if ref /= Void then
164 ref.set_type_i (Current)
165 end
166 end
167
168 c_type: TYPE_C is
169 -- Associated C type
170 do
171 Result := Reference_c_type
172 end
173
174 typecode: INTEGER is
175 -- Typecode for TUPLE element.
176 do
177 Result := feature {SHARED_TYPECODE}.reference_code
178 end
179
180 associated_class_type: CLASS_TYPE is
181 -- Associated class type
182 require
183 -- has: has_associated_class_type
184 do
185 if is_true_expanded then
186 is_true_expanded := False
187 Result := base_class.types.search_item (Current)
188 is_true_expanded := True
189 elseif is_separate then
190 is_separate := False
191 Result := base_class.types.search_item (Current)
192 is_separate := True
193 else
194 Result := base_class.types.search_item (Current)
195 end
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 -- FIXME????: separate
208 if not is_true_expanded then
209 Result := Sk_ref | (type_id - 1)
210 else
211 is_true_expanded := False
212 Result := Sk_exp | (type_id - 1)
213 is_true_expanded := True
214 end
215 end
216
217 cecil_value: INTEGER is
218 do
219 -- FIXME????: separate
220 if not is_true_expanded then
221 Result := Sk_dtype
222 else
223 Result := Sk_exp | class_id
224 end
225 end
226
227 hash_code: INTEGER is
228 -- Hash code for current type
229 do
230 Result := Other_code + class_id
231 end
232
233 feature -- Status
234
235 element_type: INTEGER_8 is
236 -- Void element type
237 do
238 if is_expanded and base_class.is_external then
239 -- We only support expanded for external class at the moment.
240 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
241 else
242 if class_id = System.system_string_class.compiled_class.class_id then
243 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_string
244 elseif class_id = System.system_object_id then
245 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_object
246 else
247 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_class
248 end
249 end
250 end
251
252 is_true_expanded: BOOLEAN
253 -- Is the type expanded?
254
255 is_separate: BOOLEAN
256 -- Is the type separate?
257
258 is_enum: BOOLEAN is
259 -- Is current type an IL enum type?
260 -- Useful to find out if some call optimization can be done
261 -- in FEATURE_B.
262 require
263 il_generation: System.il_generation
264 do
265 Result := is_true_expanded and then base_class.is_enum
266 end
267
268 is_external: BOOLEAN is
269 -- Is current type an IL enum type?
270 -- Useful to find out if some call optimization can be done
271 -- in FEATURE_B.
272 do
273 Result := base_class.is_external
274 end
275
276 is_valid: BOOLEAN is
277 -- Is the base class still in the system and matches its specification?
278 do
279 Result := base_class /= Void and then (base_class.generics = Void)
280 end
281
282 is_reference: BOOLEAN is
283 -- Is the type a reference type ?
284 do
285 Result := not is_true_expanded
286 end;
287
288 is_explicit: BOOLEAN is
289
290 do
291 Result := (cr_info = Void) or else is_expanded
292 end
293
294 has_associated_class_type: BOOLEAN is
295 -- Has `Current' an associated class type?
296 do
297 if is_true_expanded then
298 is_true_expanded := False
299 Result := base_class.types.has_type (Current)
300 is_true_expanded := True
301 elseif is_separate then
302 is_separate := False
303 Result := base_class.types.has_type (Current)
304 is_separate := True
305 else
306 Result := base_class.types.has_type (Current)
307 end
308 end
309
310 same_as (other: TYPE_I): BOOLEAN is
311 -- Is `other' equal to Current ?
312 local
313 other_cl_type: CL_TYPE_I
314 do
315 other_cl_type ?= other
316 Result := other_cl_type /= Void -- FIXME
317 and then other_cl_type.class_id = class_id
318 and then other_cl_type.is_true_expanded = is_true_expanded
319 and then other_cl_type.is_separate = is_separate
320 and then other_cl_type.meta_generic = Void
321 and then other_cl_type.true_generics = Void
322 end
323
324 feature -- Setting
325
326 set_is_true_expanded (b: BOOLEAN) is
327 -- Assign `b' to `is_true_expanded'.
328 do
329 is_true_expanded := b
330 ensure
331 is_true_expanded_set: is_true_expanded = b
332 end
333
334 set_is_separate (b: BOOLEAN) is
335 -- Assign `b' to `is_separate'.
336 do
337 is_separate := b
338 ensure
339 is_separate_set: is_separate = b
340 end
341
342 set_cr_info (cinfo : CREATE_INFO) is
343 -- Set `cr_info' to `cinfo'.
344 require
345 create_info_not_void: cinfo /= Void
346 do
347 cr_info := cinfo
348 ensure
349 cr_info_set : cr_info = cinfo
350 end
351
352 feature -- Formatting
353
354 append_signature (st: STRUCTURED_TEXT) is
355 do
356 if is_true_expanded then
357 st.add_string ("expanded ")
358 elseif is_separate then
359 st.add_string ("separate ")
360 end
361 base_class.append_signature (st)
362 end
363
364 dump (buffer: GENERATION_BUFFER) is
365 do
366 buffer.putstring (debug_output)
367 end
368
369 feature -- C generation
370
371 generate_expanded_creation (byte_code: BYTE_CODE; reg: REGISTRABLE; workbench_mode: BOOLEAN) is
372 -- Generate creation of expanded object associated to Current.
373 local
374 gen_type: GEN_TYPE_I
375 written_class: CLASS_C
376 class_type, written_type: CLASS_TYPE
377 creation_feature: FEATURE_I
378 c_name: STRING
379 buffer: GENERATION_BUFFER
380 do
381 buffer := byte_code.buffer
382
383 gen_type ?= Current
384
385 if gen_type /= Void then
386 byte_code.generate_block_open
387 byte_code.generate_gen_type_conversion (gen_type)
388 end
389 reg.print_register
390 if workbench_mode then
391 -- RTLX is a macro used to create
392 -- expanded types
393 if gen_type /= Void then
394 buffer.putstring (" = RTLX(typres")
395 else
396 buffer.putstring (" = RTLX(RTUD(")
397 buffer.generate_type_id (associated_class_type.static_type_id)
398 buffer.putchar (')')
399 end
400 else
401 if gen_type /= Void then
402 buffer.putstring (" = RTLN(typres")
403 else
404 buffer.putstring (" = RTLN(")
405 buffer.putint (type_id - 1)
406 end
407 class_type := associated_class_type
408 creation_feature := class_type.associated_class.creation_feature
409 if creation_feature /= Void then
410 written_class := System.class_of_id (creation_feature.written_in)
411 if written_class.generics = Void then
412 written_type := written_class.types.first
413 else
414 written_type :=
415 written_class.meta_type (class_type.type).associated_class_type
416 end
417 c_name := Encoder.feature_name (written_type.static_type_id,
418 creation_feature.body_index)
419 buffer.putstring (");")
420 buffer.new_line
421 buffer.putstring (c_name)
422 buffer.putchar ('(')
423 reg.print_register
424 Extern_declarations.add_routine_with_signature (Void_c_type,
425 c_name, <<"EIF_REFERENCE">>)
426 end
427 end
428 buffer.putchar (')')
429 buffer.putchar (';')
430
431 if gen_type /= Void then
432 byte_code.generate_block_close
433 end
434 buffer.new_line
435 end
436
437 generate_cecil_value (buffer: GENERATION_BUFFER) is
438 -- Generate cecil value
439 do
440 -- FIXME????: separate
441 if not is_true_expanded then
442 buffer.putstring ("SK_DTYPE")
443 else
444 buffer.putstring ("SK_EXP + (uint32) ")
445 buffer.putint (associated_class_type.type_id - 1)
446 end
447 end
448
449 feature -- Array optimization
450
451 conforms_to_array: BOOLEAN is
452 do
453 Result := base_class.conform_to (array_class_c)
454 end
455
456 feature {NONE} -- Array optimization
457
458 array_class_c: CLASS_C is
459 once
460 Result := System.array_class.compiled_class
461 end
462
463 feature -- Generic conformance
464
465 generated_id (final_mode : BOOLEAN) : INTEGER is
466
467 do
468 if final_mode then
469 Result := type_id - 1
470 else
471 Result := associated_class_type.static_type_id-1
472 end
473
474 if is_true_expanded then
475 Result := Expanded_level - Result
476 end
477 end
478
479 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
480
481 do
482 if
483 use_info and then (cr_info /= Void)
484 and then not is_expanded
485 then
486 -- It's an anchored type
487 cr_info.generate_cid (buffer, final_mode)
488 end
489 buffer.putint (generated_id (final_mode))
490 buffer.putstring (", ")
491 end
492
493 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
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.make_gen_type_byte_code (ba)
501 end
502 ba.append_short_integer (generated_id (False))
503 end
504
505 generate_cid_array (buffer : GENERATION_BUFFER;
506 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
507 local
508 dummy : INTEGER
509 do
510 if
511 use_info and then (cr_info /= Void)
512 and then not is_expanded
513 then
514 -- It's an anchored type
515 cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
516 end
517 buffer.putint (generated_id (final_mode))
518 buffer.putstring (", ")
519
520 -- Increment counter
521 dummy := idx_cnt.next
522 end
523
524 generate_cid_init (buffer : GENERATION_BUFFER;
525 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
526 local
527 dummy : INTEGER
528 do
529 if
530 use_info and then (cr_info /= Void)
531 and then not is_expanded
532 then
533 -- It's an anchored type
534 cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
535 end
536
537 dummy := idx_cnt.next
538 end
539
540 feature -- Generic conformance for IL
541
542 generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
543 -- `use_info' is true iff we generate code for a
544 -- creation instruction.
545 do
546 if use_info and then cr_info /= Void then
547 -- It's an anchored type, we call feature
548 -- that will tell us the real type of the
549 -- anchor in the context of Current.
550 cr_info.generate_il_type
551 else
552 il_generator.generate_class_type_instance (Current)
553 end
554 end
555
556 feature -- Output
557
558 debug_output: STRING is
559 -- String that should be displayed in debugger to represent `Current'.
560 do
561 create Result.make (32)
562 if is_true_expanded then
563 Result.append ("expanded ")
564 elseif is_separate then
565 Result.append ("separate ")
566 end
567 Result.append (base_class.name_in_upper)
568 end
569
570 feature {NONE} -- Implementation
571
572 internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
573 -- Full type name of `a_base_name' using `a_prefix' in IL code generation
574 -- with namespace specification
575 require
576 a_base_name_not_void: a_base_name /= Void
577 local
578 l_name: STRING
579 do
580 Result := a_base_name
581 l_name := base_class.lace_class.actual_namespace
582 if a_prefix /= Void then
583 if l_name.is_empty then
584 l_name := a_prefix + "."
585 else
586 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
587 l_name) + "." + a_prefix + "."
588 end
589 else
590 if not l_name.is_empty then
591 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
592 l_name) + "."
593 end
594 end
595 Result := l_name + il_casing.pascal_casing (System.dotnet_naming_convention,
596 Result, feature {IL_CASING_CONVERSION}.upper_case)
597 ensure
598 internal_il_type_name_not_void: Result /= Void
599 internal_il_type_name_not_empty: not Result.is_empty
600 end
601
602 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23