/[eiffelstudio]/branches/CAT_mono/Src/Eiffel/eiffel/genericity/cl_type_i.e
ViewVC logotype

Annotation of /branches/CAT_mono/Src/Eiffel/eiffel/genericity/cl_type_i.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 35702 - (hide 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 manus 26913 indexing
2     description: "Type class."
3     date: "$Date$"
4     revision: "$Revision$"
5 grator 18
6     class CL_TYPE_I
7    
8     inherit
9     TYPE_I
10     redefine
11     is_reference,
12 manus 26913 is_true_expanded,
13 xavierl 4623 is_separate,
14 manus 35178 is_out,
15 grator 236 is_valid,
16 manus 11218 is_explicit,
17 manus 28380 is_external,
18 grator 18 same_as,
19     c_type,
20 grator 930 instantiation_in,
21 manus 10818 complete_instantiation_in,
22     conforms_to_array,
23     generated_id,
24 manus 11298 generate_cid,
25 manus 14013 make_gen_type_byte_code,
26     generate_cid_array,
27 manus 30169 generate_cid_init,
28 manus 35665 generate_gen_type_il,
29     generate_expanded_creation
30 grator 18 end
31 manus 30169
32     DEBUG_OUTPUT
33     export
34     {NONE} all
35     end
36 grator 18
37 manus 33952 SHARED_IL_CASING
38     export
39     {NONE} all
40     end
41    
42 manus 35665 SHARED_GENERATION
43     export
44     {NONE} all
45     end
46    
47     SHARED_DECLARATIONS
48     export
49     {NONE} all
50     end
51    
52 manus 30224 create
53     make
54    
55     feature {NONE} -- Initialization
56    
57     make (id: INTEGER) is
58 manus 30293 -- Create new instance of `Current' with `class_id'
59 manus 30224 -- assigned with `id'.
60     require
61     valid_id: id > 0
62     do
63 manus 30293 class_id := id
64 manus 30224 ensure
65 manus 30293 class_id_set: class_id = id
66 manus 30224 end
67    
68 manus 26913 feature -- Access
69 grator 18
70 manus 30293 class_id: INTEGER
71 grator 18 -- 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 manus 9655 end
78 grator 18
79 manus 10890 cr_info : CREATE_INFO
80     -- Additional information for the creation
81     -- of generic types with anchored parameters
82    
83 manus 10818 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 grator 18 base_class: CLASS_C is
90     -- Base class associated to the class type
91     do
92 manus 30293 Result := System.class_of_id (class_id)
93 manus 9655 end
94 grator 18
95 manus 26913 type_a: CL_TYPE_A is
96 grator 236 do
97 manus 30293 create Result.make (class_id)
98 manus 26913 Result.set_is_true_expanded (is_true_expanded)
99     Result.set_is_separate (is_separate)
100 manus 9655 end
101 grator 236
102 manus 33952 il_type_name (a_prefix: STRING): STRING is
103 manus 26913 -- Class name of current type.
104 manus 29681 local
105     l_class_c: like base_class
106 manus 34253 l_is_precompiled: BOOLEAN
107     l_cl_type: like associated_class_type
108 grator 18 do
109 manus 29681 l_class_c := base_class
110     if l_class_c.is_external then
111 manus 34253 Result := clone (l_class_c.external_class_name)
112 manus 29681 else
113 manus 34253 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 manus 29681 end
125 manus 11218 end
126    
127 grator 18 instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
128     -- Instantiation of Current in context of `other'
129 grator 282 require else
130     True
131 grator 18 do
132 manus 9655 Result := Current
133     end
134 grator 18
135 manus 10818 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 grator 18 description: ATTR_DESC is
144     -- Type description for skeletons
145     local
146 michaels 7681 exp: EXPANDED_DESC
147     ref: REFERENCE_DESC
148 grator 485 do
149 manus 26913 if is_true_expanded then
150 manus 10140 !! exp
151 manus 26913 is_true_expanded := False
152 manus 32282 exp.set_class_type (base_class.types.search_item (Current))
153 manus 26913 is_true_expanded := True
154 manus 13232 exp.set_type_i (Current)
155 manus 9655 Result := exp
156 xavierl 4623 elseif is_separate then
157     -- FIXME
158     Result := c_type.description
159 grator 18 else
160 manus 9655 Result := c_type.description
161     end
162 michaels 7681
163     ref ?= Result
164     if ref /= Void then
165 manus 34621 ref.set_type_i (Current)
166 michaels 7681 end
167 manus 9655 end
168 grator 18
169     c_type: TYPE_C is
170     -- Associated C type
171     do
172 manus 9655 Result := Reference_c_type
173     end
174 grator 18
175 manus 28618 typecode: INTEGER is
176     -- Typecode for TUPLE element.
177     do
178     Result := feature {SHARED_TYPECODE}.reference_code
179     end
180    
181 grator 18 associated_class_type: CLASS_TYPE is
182     -- Associated class type
183 michaels 7681 require
184 manus 16188 -- has: has_associated_class_type
185 grator 485 do
186 manus 26913 if is_true_expanded then
187     is_true_expanded := False
188 manus 32282 Result := base_class.types.search_item (Current)
189 manus 26913 is_true_expanded := True
190 xavierl 4623 elseif is_separate then
191 manus 11065 is_separate := False
192 manus 32282 Result := base_class.types.search_item (Current)
193 manus 11065 is_separate := True
194 grator 485 else
195 manus 32282 Result := base_class.types.search_item (Current)
196 manus 9655 end
197     end
198 grator 18
199     type_id: INTEGER is
200     -- Type id of the correponding class type
201     do
202 manus 9655 Result := associated_class_type.type_id
203     end
204 grator 18
205 manus 26913 sk_value: INTEGER is
206     -- Generate SK value associated to the current type.
207 grator 18 do
208 xavierl 4623 -- FIXME????: separate
209 manus 26913 if not is_true_expanded then
210 manus 31263 Result := Sk_ref | (type_id - 1)
211 grator 18 else
212 manus 26913 is_true_expanded := False
213 manus 31263 Result := Sk_exp | (type_id - 1)
214 manus 26913 is_true_expanded := True
215 manus 9655 end
216     end
217 grator 18
218 manus 26913 cecil_value: INTEGER is
219     do
220     -- FIXME????: separate
221     if not is_true_expanded then
222     Result := Sk_dtype
223     else
224 manus 31263 Result := Sk_exp | class_id
225 manus 26913 end
226     end
227    
228 grator 18 hash_code: INTEGER is
229     -- Hash code for current type
230     do
231 manus 30293 Result := Other_code + class_id
232 manus 9655 end
233 grator 18
234 manus 26913 feature -- Status
235    
236 manus 31541 element_type: INTEGER_8 is
237     -- Void element type
238     do
239 manus 31580 if is_expanded and base_class.is_external then
240     -- We only support expanded for external class at the moment.
241 manus 31541 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 manus 26913 is_true_expanded: BOOLEAN
254     -- Is the type expanded?
255    
256     is_separate: BOOLEAN
257     -- Is the type separate?
258    
259 manus 35178 is_out: BOOLEAN
260     -- Is current actual type represent a out parameter type?
261    
262 manus 26913 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 grator 18 do
269 manus 26913 Result := is_true_expanded and then base_class.is_enum
270     end
271    
272 manus 28380 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 manus 26913 is_valid: BOOLEAN is
281 manus 35544 -- Is the base class still in the system and matches its specification?
282 manus 26913 do
283 manus 35544 Result := base_class /= Void and then (base_class.generics = Void)
284 manus 26913 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 grator 18 else
310 manus 26913 Result := base_class.types.has_type (Current)
311 manus 9655 end
312     end
313 grator 18
314 manus 26913 same_as (other: TYPE_I): BOOLEAN is
315     -- Is `other' equal to Current ?
316     local
317     other_cl_type: CL_TYPE_I
318 grator 508 do
319 manus 26913 other_cl_type ?= other
320     Result := other_cl_type /= Void -- FIXME
321 manus 30293 and then other_cl_type.class_id = class_id
322 manus 26913 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 manus 35178 ensure
335     is_true_expanded_set: is_true_expanded = b
336 manus 26913 end
337    
338     set_is_separate (b: BOOLEAN) is
339     -- Assign `b' to `is_separate'.
340     do
341     is_separate := b
342 manus 35178 ensure
343     is_separate_set: is_separate = b
344 manus 26913 end
345    
346 manus 35178 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 manus 26913 set_cr_info (cinfo : CREATE_INFO) is
355     -- Set `cr_info' to `cinfo'.
356 manus 30224 require
357     create_info_not_void: cinfo /= Void
358 manus 26913 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 manus 30169 buffer.putstring (debug_output)
379 manus 26913 end
380    
381     feature -- C generation
382    
383 manus 35665 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 manus 35702 buffer.putstring (");")
432     buffer.new_line
433 manus 35665 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 manus 26913 generate_cecil_value (buffer: GENERATION_BUFFER) is
450     -- Generate cecil value
451     do
452 xavierl 4623 -- FIXME????: separate
453 manus 26913 if not is_true_expanded then
454     buffer.putstring ("SK_DTYPE")
455 grator 508 else
456 manus 26913 buffer.putstring ("SK_EXP + (uint32) ")
457 manus 34563 buffer.putint (associated_class_type.type_id - 1)
458 manus 9655 end
459     end
460 grator 508
461 grator 930 feature -- Array optimization
462    
463     conforms_to_array: BOOLEAN is
464     do
465     Result := base_class.conform_to (array_class_c)
466 manus 9655 end
467 grator 930
468     feature {NONE} -- Array optimization
469    
470     array_class_c: CLASS_C is
471     once
472     Result := System.array_class.compiled_class
473 manus 9655 end
474 grator 930
475 manus 10818 feature -- Generic conformance
476    
477     generated_id (final_mode : BOOLEAN) : INTEGER is
478 manus 11298
479 manus 10818 do
480 manus 11298 if final_mode then
481     Result := type_id - 1
482 manus 10818 else
483 manus 26913 Result := associated_class_type.static_type_id-1
484 manus 10818 end
485 manus 11298
486 manus 26913 if is_true_expanded then
487     Result := Expanded_level - Result
488 manus 11298 end
489 manus 10818 end
490    
491 manus 11599 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
492 manus 11298
493 manus 10818 do
494 manus 11209 if
495     use_info and then (cr_info /= Void)
496 manus 26913 and then not is_expanded
497 manus 11209 then
498     -- It's an anchored type
499 manus 11599 cr_info.generate_cid (buffer, final_mode)
500 manus 10890 end
501 manus 11599 buffer.putint (generated_id (final_mode))
502     buffer.putstring (", ")
503 manus 10818 end
504    
505 manus 10890 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
506 manus 10818 do
507 manus 11209 if
508     use_info and then (cr_info /= Void)
509 manus 26913 and then not is_expanded
510 manus 11209 then
511     -- It's an anchored type
512 manus 10890 cr_info.make_gen_type_byte_code (ba)
513     end
514 manus 10818 ba.append_short_integer (generated_id (False))
515     end
516    
517 manus 14013 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 manus 26913 and then not is_expanded
525 manus 14013 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 manus 26913 and then not is_expanded
544 manus 14013 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 manus 30169
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 manus 30582 -- 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 manus 30169 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 manus 33952
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 manus 34253 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
599     l_name) + "." + a_prefix + "."
600 manus 33952 end
601     else
602     if not l_name.is_empty then
603 manus 34253 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
604     l_name) + "."
605 manus 33952 end
606     end
607 manus 34253 Result := l_name + il_casing.pascal_casing (System.dotnet_naming_convention,
608     Result, feature {IL_CASING_CONVERSION}.upper_case)
609 manus 33952 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 grator 18 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23