/[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 30169 - (hide annotations)
Fri Jan 11 01:28:57 2002 UTC (18 years, 1 month ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 9565 byte(s)
Addeg `generate_gen_type_il' in TYPE_I and redefined it in descendants. This is
  used for generic conformance in IL code generation where we generate in IL
  stream the data about the type being analyzed. This data is then used for creation
  of objects or reverse assignment.
In CL_TYPE_I added inheritance to `DEBUG_OUTPUT' so that we can see the associated
  class name in debugger.
Cosmetics.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23