/[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 30293 - (hide annotations)
Mon Jan 21 02:26:16 2002 UTC (18 years, 1 month ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 9766 byte(s)
Renamed `base_id' into `class_id' to be more consistent with other classes of compiler.
Updated code to use new creation procedure of CL_TYPE_A, GEN_TYPE_A and TUPLE_TYPE_A.

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     Result := Sk_ref + (type_id - 1)
190 grator 18 else
191 manus 26913 is_true_expanded := False
192     Result := Sk_exp + (type_id - 1)
193     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 30293 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     is_true_expanded: BOOLEAN
216     -- Is the type expanded?
217    
218     is_separate: BOOLEAN
219     -- Is the type separate?
220    
221     is_enum: BOOLEAN is
222     -- Is current type an IL enum type?
223     -- Useful to find out if some call optimization can be done
224     -- in FEATURE_B.
225     require
226     il_generation: System.il_generation
227 grator 18 do
228 manus 26913 Result := is_true_expanded and then base_class.is_enum
229     end
230    
231 manus 28380 is_external: BOOLEAN is
232     -- Is current type an IL enum type?
233     -- Useful to find out if some call optimization can be done
234     -- in FEATURE_B.
235     do
236     Result := base_class.is_external
237     end
238    
239 manus 26913 is_valid: BOOLEAN is
240     -- Is the base class still in the system ?
241     do
242     Result := base_class /= Void
243     end
244    
245     is_reference: BOOLEAN is
246     -- Is the type a reference type ?
247     do
248     Result := not is_true_expanded
249     end;
250    
251     is_explicit: BOOLEAN is
252    
253     do
254     Result := (cr_info = Void) or else is_expanded
255     end
256    
257     has_associated_class_type: BOOLEAN is
258     -- Has `Current' an associated class type?
259     do
260     if is_true_expanded then
261     is_true_expanded := False
262     Result := base_class.types.has_type (Current)
263     is_true_expanded := True
264     elseif is_separate then
265     is_separate := False
266     Result := base_class.types.has_type (Current)
267     is_separate := True
268 grator 18 else
269 manus 26913 Result := base_class.types.has_type (Current)
270 manus 9655 end
271     end
272 grator 18
273 manus 26913 same_as (other: TYPE_I): BOOLEAN is
274     -- Is `other' equal to Current ?
275     local
276     other_cl_type: CL_TYPE_I
277 grator 508 do
278 manus 26913 other_cl_type ?= other
279     Result := other_cl_type /= Void -- FIXME
280 manus 30293 and then other_cl_type.class_id = class_id
281 manus 26913 and then other_cl_type.is_true_expanded = is_true_expanded
282     and then other_cl_type.is_separate = is_separate
283     and then other_cl_type.meta_generic = Void
284     and then other_cl_type.true_generics = Void
285     end
286    
287     feature -- Setting
288    
289     set_is_true_expanded (b: BOOLEAN) is
290     -- Assign `b' to `is_true_expanded'.
291     do
292     is_true_expanded := b
293     end
294    
295     set_is_separate (b: BOOLEAN) is
296     -- Assign `b' to `is_separate'.
297     do
298     is_separate := b
299     end
300    
301     set_cr_info (cinfo : CREATE_INFO) is
302     -- Set `cr_info' to `cinfo'.
303 manus 30224 require
304     create_info_not_void: cinfo /= Void
305 manus 26913 do
306     cr_info := cinfo
307     ensure
308     cr_info_set : cr_info = cinfo
309     end
310    
311     feature -- Formatting
312    
313     append_signature (st: STRUCTURED_TEXT) is
314     do
315     if is_true_expanded then
316     st.add_string ("expanded ")
317     elseif is_separate then
318     st.add_string ("separate ")
319     end
320     base_class.append_signature (st)
321     end
322    
323     dump (buffer: GENERATION_BUFFER) is
324     do
325 manus 30169 buffer.putstring (debug_output)
326 manus 26913 end
327    
328     feature -- C generation
329    
330     generate_cecil_value (buffer: GENERATION_BUFFER) is
331     -- Generate cecil value
332     do
333 xavierl 4623 -- FIXME????: separate
334 manus 26913 if not is_true_expanded then
335     buffer.putstring ("SK_DTYPE")
336 grator 508 else
337 manus 26913 buffer.putstring ("SK_EXP + (uint32) ")
338 manus 30293 buffer.putint (class_id)
339 manus 9655 end
340     end
341 grator 508
342 grator 930 feature -- Array optimization
343    
344     conforms_to_array: BOOLEAN is
345     do
346     Result := base_class.conform_to (array_class_c)
347 manus 9655 end
348 grator 930
349     feature {NONE} -- Array optimization
350    
351     array_class_c: CLASS_C is
352     once
353     Result := System.array_class.compiled_class
354 manus 9655 end
355 grator 930
356 manus 10818 feature -- Generic conformance
357    
358     generated_id (final_mode : BOOLEAN) : INTEGER is
359 manus 11298
360 manus 10818 do
361 manus 11298 if final_mode then
362     Result := type_id - 1
363 manus 10818 else
364 manus 26913 Result := associated_class_type.static_type_id-1
365 manus 10818 end
366 manus 11298
367 manus 26913 if is_true_expanded then
368     Result := Expanded_level - Result
369 manus 11298 end
370 manus 10818 end
371    
372 manus 11599 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
373 manus 11298
374 manus 10818 do
375 manus 11209 if
376     use_info and then (cr_info /= Void)
377 manus 26913 and then not is_expanded
378 manus 11209 then
379     -- It's an anchored type
380 manus 11599 cr_info.generate_cid (buffer, final_mode)
381 manus 10890 end
382 manus 11599 buffer.putint (generated_id (final_mode))
383     buffer.putstring (", ")
384 manus 10818 end
385    
386 manus 10890 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
387 manus 10818 do
388 manus 11209 if
389     use_info and then (cr_info /= Void)
390 manus 26913 and then not is_expanded
391 manus 11209 then
392     -- It's an anchored type
393 manus 10890 cr_info.make_gen_type_byte_code (ba)
394     end
395 manus 10818 ba.append_short_integer (generated_id (False))
396     end
397    
398 manus 14013 generate_cid_array (buffer : GENERATION_BUFFER;
399     final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
400     local
401     dummy : INTEGER
402     do
403     if
404     use_info and then (cr_info /= Void)
405 manus 26913 and then not is_expanded
406 manus 14013 then
407     -- It's an anchored type
408     cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
409     end
410     buffer.putint (generated_id (final_mode))
411     buffer.putstring (", ")
412    
413     -- Increment counter
414     dummy := idx_cnt.next
415     end
416    
417     generate_cid_init (buffer : GENERATION_BUFFER;
418     final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
419     local
420     dummy : INTEGER
421     do
422     if
423     use_info and then (cr_info /= Void)
424 manus 26913 and then not is_expanded
425 manus 14013 then
426     -- It's an anchored type
427     cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
428     end
429    
430     dummy := idx_cnt.next
431     end
432 manus 30169
433     feature -- Generic conformance for IL
434    
435     generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
436     -- `use_info' is true iff we generate code for a
437     -- creation instruction.
438     do
439     if use_info and then cr_info /= Void then
440     -- It's an ancored type
441     end
442     il_generator.generate_class_type_instance (Current)
443     end
444    
445     feature -- Output
446    
447     debug_output: STRING is
448     -- String that should be displayed in debugger to represent `Current'.
449     do
450     create Result.make (32)
451     if is_true_expanded then
452     Result.append ("expanded ")
453     elseif is_separate then
454     Result.append ("separate ")
455     end
456     Result.append (base_class.name_in_upper)
457     end
458    
459 grator 18 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23