/[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 31580 - (hide annotations)
Wed Apr 17 02:42:15 2002 UTC (17 years, 10 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 10530 byte(s)
For the moment we generate a value class `element_type' only for external classes.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23