/[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 42413 - (hide annotations)
Fri Mar 26 03:31:02 2004 UTC (15 years, 11 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 15154 byte(s)
Moved down `associated_reference_class_type' and `reference_type' from BASIC_I to
  CL_TYPE_I.
Fixed `description' of CL_TYPE_I so that EXPANDED_DESC are now properly created
  using the new `set_cl_type_i' routine of EXPANDED_DESC. Simplified code.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23