/[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 32282 - (show annotations)
Thu May 30 18:53:24 2002 UTC (17 years, 9 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 10465 byte(s)
Use `search_item' instead of `conservative_search_item' as now TYPE_LIST
make sure not to move the cursor.

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 generate_gen_type_il
28 end
29
30 DEBUG_OUTPUT
31 export
32 {NONE} all
33 end
34
35 create
36 make
37
38 feature {NONE} -- Initialization
39
40 make (id: INTEGER) is
41 -- Create new instance of `Current' with `class_id'
42 -- assigned with `id'.
43 require
44 valid_id: id > 0
45 do
46 class_id := id
47 ensure
48 class_id_set: class_id = id
49 end
50
51 feature -- Access
52
53 class_id: INTEGER
54 -- 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 end
61
62 cr_info : CREATE_INFO
63 -- Additional information for the creation
64 -- of generic types with anchored parameters
65
66 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 base_class: CLASS_C is
73 -- Base class associated to the class type
74 do
75 Result := System.class_of_id (class_id)
76 end
77
78 type_a: CL_TYPE_A is
79 do
80 create Result.make (class_id)
81 Result.set_is_true_expanded (is_true_expanded)
82 Result.set_is_separate (is_separate)
83 end
84
85 il_type_name: STRING is
86 -- Class name of current type.
87 local
88 l_class_c: like base_class
89 do
90 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 end
97
98 instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
99 -- Instantiation of Current in context of `other'
100 require else
101 True
102 do
103 Result := Current
104 end
105
106 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 description: ATTR_DESC is
115 -- Type description for skeletons
116 local
117 exp: EXPANDED_DESC
118 ref: REFERENCE_DESC
119 do
120 if is_true_expanded then
121 !! exp
122 is_true_expanded := False
123 exp.set_class_type (base_class.types.search_item (Current))
124 is_true_expanded := True
125 exp.set_type_i (Current)
126 Result := exp
127 elseif is_separate then
128 -- FIXME
129 Result := c_type.description
130 else
131 Result := c_type.description
132 end
133
134 ref ?= Result
135 if ref /= Void then
136 ref.set_class_type_i (Current)
137 end
138 end
139
140 c_type: TYPE_C is
141 -- Associated C type
142 do
143 Result := Reference_c_type
144 end
145
146 typecode: INTEGER is
147 -- Typecode for TUPLE element.
148 do
149 Result := feature {SHARED_TYPECODE}.reference_code
150 end
151
152 associated_class_type: CLASS_TYPE is
153 -- Associated class type
154 require
155 -- has: has_associated_class_type
156 do
157 if is_true_expanded then
158 is_true_expanded := False
159 Result := base_class.types.search_item (Current)
160 is_true_expanded := True
161 elseif is_separate then
162 is_separate := False
163 Result := base_class.types.search_item (Current)
164 is_separate := True
165 else
166 Result := base_class.types.search_item (Current)
167 end
168 end
169
170 type_id: INTEGER is
171 -- Type id of the correponding class type
172 do
173 Result := associated_class_type.type_id
174 end
175
176 expanded_type_id: INTEGER is
177 -- Type id of the corresponding expanded class type
178 do
179 is_true_expanded := False
180 Result := base_class.types.search_item (Current).type_id
181 is_true_expanded := True
182 end
183
184 sk_value: INTEGER is
185 -- Generate SK value associated to the current type.
186 do
187 -- FIXME????: separate
188 if not is_true_expanded then
189 Result := Sk_ref | (type_id - 1)
190 else
191 is_true_expanded := False
192 Result := Sk_exp | (type_id - 1)
193 is_true_expanded := True
194 end
195 end
196
197 cecil_value: INTEGER is
198 do
199 -- FIXME????: separate
200 if not is_true_expanded then
201 Result := Sk_dtype
202 else
203 Result := Sk_exp | class_id
204 end
205 end
206
207 hash_code: INTEGER is
208 -- Hash code for current type
209 do
210 Result := Other_code + class_id
211 end
212
213 feature -- Status
214
215 element_type: INTEGER_8 is
216 -- Void element type
217 do
218 if is_expanded and base_class.is_external then
219 -- We only support expanded for external class at the moment.
220 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 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 do
245 Result := is_true_expanded and then base_class.is_enum
246 end
247
248 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 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 else
286 Result := base_class.types.has_type (Current)
287 end
288 end
289
290 same_as (other: TYPE_I): BOOLEAN is
291 -- Is `other' equal to Current ?
292 local
293 other_cl_type: CL_TYPE_I
294 do
295 other_cl_type ?= other
296 Result := other_cl_type /= Void -- FIXME
297 and then other_cl_type.class_id = class_id
298 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 require
321 create_info_not_void: cinfo /= Void
322 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 buffer.putstring (debug_output)
343 end
344
345 feature -- C generation
346
347 generate_cecil_value (buffer: GENERATION_BUFFER) is
348 -- Generate cecil value
349 do
350 -- FIXME????: separate
351 if not is_true_expanded then
352 buffer.putstring ("SK_DTYPE")
353 else
354 buffer.putstring ("SK_EXP + (uint32) ")
355 buffer.putint (class_id)
356 end
357 end
358
359 feature -- Array optimization
360
361 conforms_to_array: BOOLEAN is
362 do
363 Result := base_class.conform_to (array_class_c)
364 end
365
366 feature {NONE} -- Array optimization
367
368 array_class_c: CLASS_C is
369 once
370 Result := System.array_class.compiled_class
371 end
372
373 feature -- Generic conformance
374
375 generated_id (final_mode : BOOLEAN) : INTEGER is
376
377 do
378 if final_mode then
379 Result := type_id - 1
380 else
381 Result := associated_class_type.static_type_id-1
382 end
383
384 if is_true_expanded then
385 Result := Expanded_level - Result
386 end
387 end
388
389 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
390
391 do
392 if
393 use_info and then (cr_info /= Void)
394 and then not is_expanded
395 then
396 -- It's an anchored type
397 cr_info.generate_cid (buffer, final_mode)
398 end
399 buffer.putint (generated_id (final_mode))
400 buffer.putstring (", ")
401 end
402
403 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
404 do
405 if
406 use_info and then (cr_info /= Void)
407 and then not is_expanded
408 then
409 -- It's an anchored type
410 cr_info.make_gen_type_byte_code (ba)
411 end
412 ba.append_short_integer (generated_id (False))
413 end
414
415 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 and then not is_expanded
423 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 and then not is_expanded
442 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
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 -- 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 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 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23