/[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 35702 - (show annotations)
Fri Jan 31 23:54:48 2003 UTC (17 years ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 14201 byte(s)
Cosmetics in code generation.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23