/[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 30224 - (hide annotations)
Thu Jan 17 00:57:45 2002 UTC (18 years, 1 month ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 9777 byte(s)
Added `make' as a creation procedure that basically does the same thing as
`set_base_id' which has been removed.
Added precondition to `set_cr_info'.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23