/[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 34621 - (hide annotations)
Fri Oct 11 02:31:18 2002 UTC (17 years, 4 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 11975 byte(s)
Updated to `set_type_i', new name for `set_class_type_i' in REFERENCE_DESC.

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     generate_gen_type_il
28 grator 18 end
29 manus 30169
30     DEBUG_OUTPUT
31     export
32     {NONE} all
33     end
34 grator 18
35 manus 33952 SHARED_IL_CASING
36     export
37     {NONE} all
38     end
39    
40 manus 30224 create
41     make
42    
43     feature {NONE} -- Initialization
44    
45     make (id: INTEGER) is
46 manus 30293 -- Create new instance of `Current' with `class_id'
47 manus 30224 -- assigned with `id'.
48     require
49     valid_id: id > 0
50     do
51 manus 30293 class_id := id
52 manus 30224 ensure
53 manus 30293 class_id_set: class_id = id
54 manus 30224 end
55    
56 manus 26913 feature -- Access
57 grator 18
58 manus 30293 class_id: INTEGER
59 grator 18 -- Base class id of the type class
60    
61     meta_generic: META_GENERIC is
62     -- Meta generic array describing the type class
63     do
64     -- No meta generic in non-generic type
65 manus 9655 end
66 grator 18
67 manus 10890 cr_info : CREATE_INFO
68     -- Additional information for the creation
69     -- of generic types with anchored parameters
70    
71 manus 10818 true_generics : ARRAY [TYPE_I] is
72     -- Array of generics: no mapping reference -> REFERENCE_I
73     do
74     -- Non generic types don't have them
75     end
76    
77 grator 18 base_class: CLASS_C is
78     -- Base class associated to the class type
79     do
80 manus 30293 Result := System.class_of_id (class_id)
81 manus 9655 end
82 grator 18
83 manus 26913 type_a: CL_TYPE_A is
84 grator 236 do
85 manus 30293 create Result.make (class_id)
86 manus 26913 Result.set_is_true_expanded (is_true_expanded)
87     Result.set_is_separate (is_separate)
88 manus 9655 end
89 grator 236
90 manus 33952 il_type_name (a_prefix: STRING): STRING is
91 manus 26913 -- Class name of current type.
92 manus 29681 local
93     l_class_c: like base_class
94 manus 34253 l_is_precompiled: BOOLEAN
95     l_cl_type: like associated_class_type
96 grator 18 do
97 manus 29681 l_class_c := base_class
98     if l_class_c.is_external then
99 manus 34253 Result := clone (l_class_c.external_class_name)
100 manus 29681 else
101 manus 34253 l_is_precompiled := l_class_c.is_precompiled
102     if l_is_precompiled then
103     l_cl_type := associated_class_type
104     l_is_precompiled := l_cl_type.is_precompiled
105     if l_is_precompiled then
106     Result := associated_class_type.il_type_name (a_prefix)
107     end
108     end
109     if not l_is_precompiled then
110     Result := internal_il_type_name (clone (l_class_c.name), a_prefix)
111     end
112 manus 29681 end
113 manus 11218 end
114    
115 grator 18 instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
116     -- Instantiation of Current in context of `other'
117 grator 282 require else
118     True
119 grator 18 do
120 manus 9655 Result := Current
121     end
122 grator 18
123 manus 10818 complete_instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
124     -- Instantiation of Current in context of `other'
125     require else
126     True
127     do
128     Result := Current
129     end
130    
131 grator 18 description: ATTR_DESC is
132     -- Type description for skeletons
133     local
134 michaels 7681 exp: EXPANDED_DESC
135     ref: REFERENCE_DESC
136 grator 485 do
137 manus 26913 if is_true_expanded then
138 manus 10140 !! exp
139 manus 26913 is_true_expanded := False
140 manus 32282 exp.set_class_type (base_class.types.search_item (Current))
141 manus 26913 is_true_expanded := True
142 manus 13232 exp.set_type_i (Current)
143 manus 9655 Result := exp
144 xavierl 4623 elseif is_separate then
145     -- FIXME
146     Result := c_type.description
147 grator 18 else
148 manus 9655 Result := c_type.description
149     end
150 michaels 7681
151     ref ?= Result
152     if ref /= Void then
153 manus 34621 ref.set_type_i (Current)
154 michaels 7681 end
155 manus 9655 end
156 grator 18
157     c_type: TYPE_C is
158     -- Associated C type
159     do
160 manus 9655 Result := Reference_c_type
161     end
162 grator 18
163 manus 28618 typecode: INTEGER is
164     -- Typecode for TUPLE element.
165     do
166     Result := feature {SHARED_TYPECODE}.reference_code
167     end
168    
169 grator 18 associated_class_type: CLASS_TYPE is
170     -- Associated class type
171 michaels 7681 require
172 manus 16188 -- has: has_associated_class_type
173 grator 485 do
174 manus 26913 if is_true_expanded then
175     is_true_expanded := False
176 manus 32282 Result := base_class.types.search_item (Current)
177 manus 26913 is_true_expanded := True
178 xavierl 4623 elseif is_separate then
179 manus 11065 is_separate := False
180 manus 32282 Result := base_class.types.search_item (Current)
181 manus 11065 is_separate := True
182 grator 485 else
183 manus 32282 Result := base_class.types.search_item (Current)
184 manus 9655 end
185     end
186 grator 18
187     type_id: INTEGER is
188     -- Type id of the correponding class type
189     do
190 manus 9655 Result := associated_class_type.type_id
191     end
192 grator 18
193     expanded_type_id: INTEGER is
194     -- Type id of the corresponding expanded class type
195     do
196 manus 26913 is_true_expanded := False
197 manus 32282 Result := base_class.types.search_item (Current).type_id
198 manus 26913 is_true_expanded := True
199 manus 9655 end
200 grator 18
201 manus 26913 sk_value: INTEGER is
202     -- Generate SK value associated to the current type.
203 grator 18 do
204 xavierl 4623 -- FIXME????: separate
205 manus 26913 if not is_true_expanded then
206 manus 31263 Result := Sk_ref | (type_id - 1)
207 grator 18 else
208 manus 26913 is_true_expanded := False
209 manus 31263 Result := Sk_exp | (type_id - 1)
210 manus 26913 is_true_expanded := True
211 manus 9655 end
212     end
213 grator 18
214 manus 26913 cecil_value: INTEGER is
215     do
216     -- FIXME????: separate
217     if not is_true_expanded then
218     Result := Sk_dtype
219     else
220 manus 31263 Result := Sk_exp | class_id
221 manus 26913 end
222     end
223    
224 grator 18 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 31580 if is_expanded and base_class.is_external then
236     -- We only support expanded for external class at the moment.
237 manus 31541 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
238     else
239     if base_class = System.system_string_class.compiled_class then
240     Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_string
241     elseif base_class.class_id = System.system_object_id then
242     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 26913 is_true_expanded: BOOLEAN
250     -- Is the type expanded?
251    
252     is_separate: BOOLEAN
253     -- Is the type separate?
254    
255     is_enum: BOOLEAN is
256     -- Is current type an IL enum type?
257     -- Useful to find out if some call optimization can be done
258     -- in FEATURE_B.
259     require
260     il_generation: System.il_generation
261 grator 18 do
262 manus 26913 Result := is_true_expanded and then base_class.is_enum
263     end
264    
265 manus 28380 is_external: BOOLEAN is
266     -- Is current type an IL enum type?
267     -- Useful to find out if some call optimization can be done
268     -- in FEATURE_B.
269     do
270     Result := base_class.is_external
271     end
272    
273 manus 26913 is_valid: BOOLEAN is
274     -- Is the base class still in the system ?
275     do
276     Result := base_class /= Void
277     end
278    
279     is_reference: BOOLEAN is
280     -- Is the type a reference type ?
281     do
282     Result := not is_true_expanded
283     end;
284    
285     is_explicit: BOOLEAN is
286    
287     do
288     Result := (cr_info = Void) or else is_expanded
289     end
290    
291     has_associated_class_type: BOOLEAN is
292     -- Has `Current' an associated class type?
293     do
294     if is_true_expanded then
295     is_true_expanded := False
296     Result := base_class.types.has_type (Current)
297     is_true_expanded := True
298     elseif is_separate then
299     is_separate := False
300     Result := base_class.types.has_type (Current)
301     is_separate := True
302 grator 18 else
303 manus 26913 Result := base_class.types.has_type (Current)
304 manus 9655 end
305     end
306 grator 18
307 manus 26913 same_as (other: TYPE_I): BOOLEAN is
308     -- Is `other' equal to Current ?
309     local
310     other_cl_type: CL_TYPE_I
311 grator 508 do
312 manus 26913 other_cl_type ?= other
313     Result := other_cl_type /= Void -- FIXME
314 manus 30293 and then other_cl_type.class_id = class_id
315 manus 26913 and then other_cl_type.is_true_expanded = is_true_expanded
316     and then other_cl_type.is_separate = is_separate
317     and then other_cl_type.meta_generic = Void
318     and then other_cl_type.true_generics = Void
319     end
320    
321     feature -- Setting
322    
323     set_is_true_expanded (b: BOOLEAN) is
324     -- Assign `b' to `is_true_expanded'.
325     do
326     is_true_expanded := b
327     end
328    
329     set_is_separate (b: BOOLEAN) is
330     -- Assign `b' to `is_separate'.
331     do
332     is_separate := b
333     end
334    
335     set_cr_info (cinfo : CREATE_INFO) is
336     -- Set `cr_info' to `cinfo'.
337 manus 30224 require
338     create_info_not_void: cinfo /= Void
339 manus 26913 do
340     cr_info := cinfo
341     ensure
342     cr_info_set : cr_info = cinfo
343     end
344    
345     feature -- Formatting
346    
347     append_signature (st: STRUCTURED_TEXT) is
348     do
349     if is_true_expanded then
350     st.add_string ("expanded ")
351     elseif is_separate then
352     st.add_string ("separate ")
353     end
354     base_class.append_signature (st)
355     end
356    
357     dump (buffer: GENERATION_BUFFER) is
358     do
359 manus 30169 buffer.putstring (debug_output)
360 manus 26913 end
361    
362     feature -- C generation
363    
364     generate_cecil_value (buffer: GENERATION_BUFFER) is
365     -- Generate cecil value
366     do
367 xavierl 4623 -- FIXME????: separate
368 manus 26913 if not is_true_expanded then
369     buffer.putstring ("SK_DTYPE")
370 grator 508 else
371 manus 26913 buffer.putstring ("SK_EXP + (uint32) ")
372 manus 34563 buffer.putint (associated_class_type.type_id - 1)
373 manus 9655 end
374     end
375 grator 508
376 grator 930 feature -- Array optimization
377    
378     conforms_to_array: BOOLEAN is
379     do
380     Result := base_class.conform_to (array_class_c)
381 manus 9655 end
382 grator 930
383     feature {NONE} -- Array optimization
384    
385     array_class_c: CLASS_C is
386     once
387     Result := System.array_class.compiled_class
388 manus 9655 end
389 grator 930
390 manus 10818 feature -- Generic conformance
391    
392     generated_id (final_mode : BOOLEAN) : INTEGER is
393 manus 11298
394 manus 10818 do
395 manus 11298 if final_mode then
396     Result := type_id - 1
397 manus 10818 else
398 manus 26913 Result := associated_class_type.static_type_id-1
399 manus 10818 end
400 manus 11298
401 manus 26913 if is_true_expanded then
402     Result := Expanded_level - Result
403 manus 11298 end
404 manus 10818 end
405    
406 manus 11599 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
407 manus 11298
408 manus 10818 do
409 manus 11209 if
410     use_info and then (cr_info /= Void)
411 manus 26913 and then not is_expanded
412 manus 11209 then
413     -- It's an anchored type
414 manus 11599 cr_info.generate_cid (buffer, final_mode)
415 manus 10890 end
416 manus 11599 buffer.putint (generated_id (final_mode))
417     buffer.putstring (", ")
418 manus 10818 end
419    
420 manus 10890 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
421 manus 10818 do
422 manus 11209 if
423     use_info and then (cr_info /= Void)
424 manus 26913 and then not is_expanded
425 manus 11209 then
426     -- It's an anchored type
427 manus 10890 cr_info.make_gen_type_byte_code (ba)
428     end
429 manus 10818 ba.append_short_integer (generated_id (False))
430     end
431    
432 manus 14013 generate_cid_array (buffer : GENERATION_BUFFER;
433     final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
434     local
435     dummy : INTEGER
436     do
437     if
438     use_info and then (cr_info /= Void)
439 manus 26913 and then not is_expanded
440 manus 14013 then
441     -- It's an anchored type
442     cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
443     end
444     buffer.putint (generated_id (final_mode))
445     buffer.putstring (", ")
446    
447     -- Increment counter
448     dummy := idx_cnt.next
449     end
450    
451     generate_cid_init (buffer : GENERATION_BUFFER;
452     final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
453     local
454     dummy : INTEGER
455     do
456     if
457     use_info and then (cr_info /= Void)
458 manus 26913 and then not is_expanded
459 manus 14013 then
460     -- It's an anchored type
461     cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
462     end
463    
464     dummy := idx_cnt.next
465     end
466 manus 30169
467     feature -- Generic conformance for IL
468    
469     generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
470     -- `use_info' is true iff we generate code for a
471     -- creation instruction.
472     do
473     if use_info and then cr_info /= Void then
474 manus 30582 -- It's an anchored type, we call feature
475     -- that will tell us the real type of the
476     -- anchor in the context of Current.
477     cr_info.generate_il_type
478     else
479     il_generator.generate_class_type_instance (Current)
480 manus 30169 end
481     end
482    
483     feature -- Output
484    
485     debug_output: STRING is
486     -- String that should be displayed in debugger to represent `Current'.
487     do
488     create Result.make (32)
489     if is_true_expanded then
490     Result.append ("expanded ")
491     elseif is_separate then
492     Result.append ("separate ")
493     end
494     Result.append (base_class.name_in_upper)
495     end
496 manus 33952
497     feature {NONE} -- Implementation
498    
499     internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
500     -- Full type name of `a_base_name' using `a_prefix' in IL code generation
501     -- with namespace specification
502     require
503     a_base_name_not_void: a_base_name /= Void
504     local
505     l_name: STRING
506     do
507     Result := a_base_name
508     l_name := base_class.lace_class.actual_namespace
509     if a_prefix /= Void then
510     if l_name.is_empty then
511     l_name := a_prefix + "."
512     else
513 manus 34253 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
514     l_name) + "." + a_prefix + "."
515 manus 33952 end
516     else
517     if not l_name.is_empty then
518 manus 34253 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
519     l_name) + "."
520 manus 33952 end
521     end
522 manus 34253 Result := l_name + il_casing.pascal_casing (System.dotnet_naming_convention,
523     Result, feature {IL_CASING_CONVERSION}.upper_case)
524 manus 33952 ensure
525     internal_il_type_name_not_void: Result /= Void
526     internal_il_type_name_not_empty: not Result.is_empty
527     end
528    
529 grator 18 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23