/[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 35544 - (hide annotations)
Fri Jan 24 06:26:36 2003 UTC (17 years, 1 month ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 12354 byte(s)
Fixed `is_valid' to take into account case where class is still in system
but its generic specification has changed.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23