/[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 31541 - (hide annotations)
Tue Apr 16 00:30:54 2002 UTC (17 years, 10 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 10436 byte(s)
Implemented `element_type', new abstract feature of TYPE_I.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23