/[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 39412 - (hide annotations)
Sat Oct 4 22:08:21 2003 UTC (16 years, 4 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 13908 byte(s)
Fixed eweasel bug exec176. The change is quite dramatic. Instead of generating
special marker in `typarr' for anchored type, we generate just 0. Then the associated
entry is computed later on by applying RTID to the result since `typarr' needs
the `static_type_id', not the `type_id' when in workbench mode.
Moreover when a type has a `cr_info' then we generate the info for this only,
we do not repeat code generation for the type we think we have. I don't understand
why it was done before, I think this was just a mistake to do both, so now
they are separated by a `else'.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23