/[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 43364 - (hide annotations)
Sat May 29 22:49:07 2004 UTC (15 years, 8 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 13628 byte(s)
Revisited `generate_expanded_creation' and added `generate_expanded_initialization'.
Removed code from CL_TYPE_I and replaced by a call to feature of CLASS_TYPE
  which does the same job, but avoids code duplication.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23