/[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 43156 - (hide annotations)
Fri May 21 23:45:44 2004 UTC (15 years, 9 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 15088 byte(s)
Cosmetic in code generation, now spaces after the comma in generation of type arrays
  used for generic conformance.

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 42865 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     hash_code: INTEGER is
225     -- Hash code for current type
226     do
227 manus 30293 Result := Other_code + class_id
228 manus 9655 end
229 grator 18
230 manus 26913 feature -- Status
231    
232 manus 31541 element_type: INTEGER_8 is
233     -- Void element type
234     do
235 manus 41824 if is_expanded then
236 manus 31580 -- We only support expanded for external class at the moment.
237 manus 31541 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
238     else
239 manus 37130 if class_id = System.system_string_class.compiled_class.class_id then
240 manus 31541 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_string
241 manus 37130 elseif class_id = System.system_object_id then
242 manus 31541 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_object
243     else
244     Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_class
245     end
246     end
247     end
248    
249 manus 41824 tuple_code: INTEGER_8 is
250     -- Tuple code for class type
251     do
252     Result := feature {SHARED_GEN_CONF_LEVEL}.reference_tuple_code
253     end
254    
255     is_expanded: BOOLEAN
256 manus 26913 -- Is the type expanded?
257    
258     is_separate: BOOLEAN
259     -- Is the type separate?
260    
261     is_enum: BOOLEAN is
262     -- Is current type an IL enum type?
263     -- Useful to find out if some call optimization can be done
264     -- in FEATURE_B.
265     require
266     il_generation: System.il_generation
267 grator 18 do
268 manus 41824 Result := is_expanded and then base_class.is_enum
269 manus 26913 end
270    
271 manus 28380 is_external: BOOLEAN is
272 manus 41824 -- Is current type based on an external class?
273     local
274     l_base_class: like base_class
275 manus 28380 do
276 manus 41824 -- All Eiffel basic types are externals, and only basic types used
277     -- as reference are not external.
278     l_base_class := base_class
279     Result := is_basic or (not l_base_class.is_basic and l_base_class.is_external)
280 manus 28380 end
281 manus 41824
282     is_generated_as_single_type: BOOLEAN is
283     -- Is associated type generated as a single type or as an interface type and
284     -- an implementation type.
285     local
286     l_class: CLASS_C
287     do
288     -- Expanded types do not have an interface since no polymorphic calls
289     -- are done on them.
290     Result := is_expanded
291     if not Result then
292     l_class := base_class
293     -- When `base_class' is a basic class and that we are here, it means
294     -- that we are handling the reference version of the basic type, which
295     -- needs to be generated with the interface type and the implementation type
296     if not l_class.is_basic then
297     -- External classes, or classes marked `frozen', or that
298     -- inherites from external classes have only one generated type.
299     Result := l_class.is_single or l_class.is_frozen or l_class.is_external
300     end
301     end
302     end
303 manus 28380
304 manus 26913 is_valid: BOOLEAN is
305 manus 35544 -- Is the base class still in the system and matches its specification?
306 manus 41824 local
307     l_base_class: like base_class
308 manus 26913 do
309 manus 41824 l_base_class := base_class
310     Result := l_base_class /= Void and then (l_base_class.generics = Void)
311 manus 26913 end
312    
313     is_reference: BOOLEAN is
314     -- Is the type a reference type ?
315     do
316 manus 41824 Result := not is_expanded
317 manus 26913 end;
318    
319     is_explicit: BOOLEAN is
320 manus 39713 -- Is Current type fixed at compile time?
321 manus 26913 do
322 manus 39713 if cr_info /= Void then
323     Result := cr_info.is_explicit
324     else
325     Result := True
326     end
327 manus 26913 end
328    
329     has_associated_class_type: BOOLEAN is
330     -- Has `Current' an associated class type?
331     do
332 manus 41824 Result := base_class.types.has_type (Current)
333 manus 9655 end
334 grator 18
335 manus 26913 same_as (other: TYPE_I): BOOLEAN is
336     -- Is `other' equal to Current ?
337     local
338     other_cl_type: CL_TYPE_I
339 grator 508 do
340 manus 26913 other_cl_type ?= other
341     Result := other_cl_type /= Void -- FIXME
342 manus 30293 and then other_cl_type.class_id = class_id
343 manus 41824 and then other_cl_type.is_expanded = is_expanded
344 manus 26913 and then other_cl_type.is_separate = is_separate
345     and then other_cl_type.meta_generic = Void
346     and then other_cl_type.true_generics = Void
347     end
348    
349     feature -- Setting
350    
351 manus 41824 set_is_expanded (b: BOOLEAN) is
352     -- Assign `b' to `is_expanded'.
353 manus 26913 do
354 manus 41824 is_expanded := b
355 manus 35178 ensure
356 manus 41824 is_expanded_set: is_expanded = b
357 manus 26913 end
358    
359     set_is_separate (b: BOOLEAN) is
360     -- Assign `b' to `is_separate'.
361     do
362     is_separate := b
363 manus 35178 ensure
364     is_separate_set: is_separate = b
365 manus 26913 end
366    
367     set_cr_info (cinfo : CREATE_INFO) is
368     -- Set `cr_info' to `cinfo'.
369 manus 30224 require
370     create_info_not_void: cinfo /= Void
371 manus 41824 not_expanded: not is_expanded
372 manus 26913 do
373     cr_info := cinfo
374     ensure
375     cr_info_set : cr_info = cinfo
376     end
377    
378     feature -- C generation
379    
380 manus 35665 generate_expanded_creation (byte_code: BYTE_CODE; reg: REGISTRABLE; workbench_mode: BOOLEAN) is
381     -- Generate creation of expanded object associated to Current.
382     local
383     gen_type: GEN_TYPE_I
384     written_class: CLASS_C
385     class_type, written_type: CLASS_TYPE
386     creation_feature: FEATURE_I
387     c_name: STRING
388     buffer: GENERATION_BUFFER
389     do
390     buffer := byte_code.buffer
391    
392     gen_type ?= Current
393    
394     if gen_type /= Void then
395     byte_code.generate_block_open
396     byte_code.generate_gen_type_conversion (gen_type)
397     end
398     reg.print_register
399     if workbench_mode then
400     -- RTLX is a macro used to create
401     -- expanded types
402     if gen_type /= Void then
403 manus 43084 buffer.put_string (" = RTLX(typres")
404 manus 35665 else
405 manus 43084 buffer.put_string (" = RTLX(RTUD(")
406     buffer.put_static_type_id (associated_class_type.static_type_id)
407     buffer.put_character (')')
408 manus 35665 end
409     else
410     if gen_type /= Void then
411 manus 43084 buffer.put_string (" = RTLN(typres")
412 manus 35665 else
413 manus 43084 buffer.put_string (" = RTLN(")
414     buffer.put_type_id (type_id)
415 manus 35665 end
416     class_type := associated_class_type
417     creation_feature := class_type.associated_class.creation_feature
418     if creation_feature /= Void then
419     written_class := System.class_of_id (creation_feature.written_in)
420     if written_class.generics = Void then
421     written_type := written_class.types.first
422     else
423     written_type :=
424     written_class.meta_type (class_type.type).associated_class_type
425     end
426     c_name := Encoder.feature_name (written_type.static_type_id,
427     creation_feature.body_index)
428 manus 43084 buffer.put_string (");")
429     buffer.put_new_line
430     buffer.put_string (c_name)
431     buffer.put_character ('(')
432 manus 35665 reg.print_register
433     Extern_declarations.add_routine_with_signature (Void_c_type,
434     c_name, <<"EIF_REFERENCE">>)
435     end
436     end
437 manus 43084 buffer.put_character (')')
438     buffer.put_character (';')
439 manus 35665
440     if gen_type /= Void then
441     byte_code.generate_block_close
442     end
443 manus 43084 buffer.put_new_line
444 manus 35665 end
445    
446 manus 26913 generate_cecil_value (buffer: GENERATION_BUFFER) is
447     -- Generate cecil value
448     do
449 manus 41824 if not is_expanded then
450 manus 43084 buffer.put_string ("SK_REF + (uint32) ")
451 grator 508 else
452 manus 43084 buffer.put_string ("SK_EXP + (uint32) ")
453 manus 9655 end
454 manus 43084 buffer.put_type_id (associated_class_type.type_id)
455 manus 9655 end
456 grator 508
457 grator 930 feature -- Array optimization
458    
459     conforms_to_array: BOOLEAN is
460     do
461     Result := base_class.conform_to (array_class_c)
462 manus 9655 end
463 grator 930
464     feature {NONE} -- Array optimization
465    
466     array_class_c: CLASS_C is
467     once
468     Result := System.array_class.compiled_class
469 manus 9655 end
470 grator 930
471 manus 10818 feature -- Generic conformance
472    
473     generated_id (final_mode : BOOLEAN) : INTEGER is
474 manus 11298
475 manus 10818 do
476 manus 11298 if final_mode then
477     Result := type_id - 1
478 manus 10818 else
479 manus 41824 Result := associated_class_type.static_type_id - 1
480 manus 10818 end
481     end
482    
483 manus 11599 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
484 manus 11298
485 manus 10818 do
486 manus 11209 if
487     use_info and then (cr_info /= Void)
488 manus 26913 and then not is_expanded
489 manus 11209 then
490 manus 43156 -- It's an anchored type
491 manus 11599 cr_info.generate_cid (buffer, final_mode)
492 manus 39412 else
493 manus 43084 buffer.put_integer (generated_id (final_mode))
494 manus 43156 buffer.put_character (',')
495 manus 10890 end
496 manus 10818 end
497    
498 manus 10890 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
499 manus 10818 do
500 manus 11209 if
501     use_info and then (cr_info /= Void)
502 manus 26913 and then not is_expanded
503 manus 11209 then
504     -- It's an anchored type
505 manus 10890 cr_info.make_gen_type_byte_code (ba)
506 manus 39412 else
507     ba.append_short_integer (generated_id (False))
508 manus 10890 end
509 manus 10818 end
510    
511 manus 14013 generate_cid_array (buffer : GENERATION_BUFFER;
512     final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
513     local
514     dummy : INTEGER
515     do
516     if
517     use_info and then (cr_info /= Void)
518 manus 26913 and then not is_expanded
519 manus 14013 then
520 manus 39412 -- It's an anchored type
521 manus 14013 cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
522 manus 39412 else
523 manus 43084 buffer.put_integer (generated_id (final_mode))
524 manus 43156 buffer.put_character (',')
525 manus 39412
526     -- Increment counter
527     dummy := idx_cnt.next
528 manus 14013 end
529     end
530    
531     generate_cid_init (buffer : GENERATION_BUFFER;
532     final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
533     local
534     dummy : INTEGER
535     do
536     if
537     use_info and then (cr_info /= Void)
538 manus 26913 and then not is_expanded
539 manus 14013 then
540     -- It's an anchored type
541     cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
542 manus 39412 else
543     dummy := idx_cnt.next
544 manus 14013 end
545     end
546 manus 30169
547     feature -- Generic conformance for IL
548    
549     generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
550     -- `use_info' is true iff we generate code for a
551     -- creation instruction.
552     do
553     if use_info and then cr_info /= Void then
554 manus 30582 -- It's an anchored type, we call feature
555     -- that will tell us the real type of the
556     -- anchor in the context of Current.
557     cr_info.generate_il_type
558     else
559     il_generator.generate_class_type_instance (Current)
560 manus 30169 end
561     end
562    
563 manus 33952 feature {NONE} -- Implementation
564    
565 manus 41824 frozen internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
566 manus 33952 -- Full type name of `a_base_name' using `a_prefix' in IL code generation
567     -- with namespace specification
568     require
569     a_base_name_not_void: a_base_name /= Void
570     local
571     l_name: STRING
572 manus 41824 l_base_class: like base_class
573 manus 33952 do
574 manus 41824 l_base_class := base_class
575     -- Result needs to be in lower case because that's
576     -- what our casing conversion routines require to perform
577     -- a good job.
578     if
579     (is_expanded and l_base_class.is_expanded) or
580     (not is_expanded and not l_base_class.is_expanded)
581     then
582     Result := a_base_name.as_lower
583     else
584     if is_expanded then
585     create Result.make (6 + a_base_name.count)
586     Result.append ("VALUE_")
587     else
588     create Result.make (10 + a_base_name.count)
589     Result.append ("REFERENCE_")
590     end
591     Result.append (a_base_name)
592     Result.to_lower
593     end
594     l_name := l_base_class.lace_class.actual_namespace
595 manus 33952 if a_prefix /= Void then
596     if l_name.is_empty then
597     l_name := a_prefix + "."
598     else
599 manus 34253 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
600     l_name) + "." + a_prefix + "."
601 manus 33952 end
602     else
603     if not l_name.is_empty then
604 manus 34253 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
605     l_name) + "."
606 manus 33952 end
607     end
608 manus 34253 Result := l_name + il_casing.pascal_casing (System.dotnet_naming_convention,
609     Result, feature {IL_CASING_CONVERSION}.upper_case)
610 manus 33952 ensure
611     internal_il_type_name_not_void: Result /= Void
612     internal_il_type_name_not_empty: not Result.is_empty
613     end
614    
615 manus 41824 invariant
616     class_id_positive: class_id > 0
617    
618 grator 18 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23