/[eiffelstudio]/branches/CAT_mono/Src/Eiffel/eiffel/genericity/cl_type_i.e
ViewVC logotype

Contents of /branches/CAT_mono/Src/Eiffel/eiffel/genericity/cl_type_i.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 28618 - (show annotations)
Wed Oct 31 04:02:12 2001 UTC (18 years, 3 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 8853 byte(s)
Implemented `typecode' that returns the typecode for elements in a TUPLE.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23