/[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 30293 - (show 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 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.conservative_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.conservative_search_item (Current)
160 is_true_expanded := True
161 elseif is_separate then
162 is_separate := False
163 Result := base_class.types.conservative_search_item (Current)
164 is_separate := True
165 else
166 Result := base_class.types.conservative_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.conservative_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 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 do
228 Result := is_true_expanded and then base_class.is_enum
229 end
230
231 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 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 else
269 Result := base_class.types.has_type (Current)
270 end
271 end
272
273 same_as (other: TYPE_I): BOOLEAN is
274 -- Is `other' equal to Current ?
275 local
276 other_cl_type: CL_TYPE_I
277 do
278 other_cl_type ?= other
279 Result := other_cl_type /= Void -- FIXME
280 and then other_cl_type.class_id = class_id
281 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 require
304 create_info_not_void: cinfo /= Void
305 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 buffer.putstring (debug_output)
326 end
327
328 feature -- C generation
329
330 generate_cecil_value (buffer: GENERATION_BUFFER) is
331 -- Generate cecil value
332 do
333 -- FIXME????: separate
334 if not is_true_expanded then
335 buffer.putstring ("SK_DTYPE")
336 else
337 buffer.putstring ("SK_EXP + (uint32) ")
338 buffer.putint (class_id)
339 end
340 end
341
342 feature -- Array optimization
343
344 conforms_to_array: BOOLEAN is
345 do
346 Result := base_class.conform_to (array_class_c)
347 end
348
349 feature {NONE} -- Array optimization
350
351 array_class_c: CLASS_C is
352 once
353 Result := System.array_class.compiled_class
354 end
355
356 feature -- Generic conformance
357
358 generated_id (final_mode : BOOLEAN) : INTEGER is
359
360 do
361 if final_mode then
362 Result := type_id - 1
363 else
364 Result := associated_class_type.static_type_id-1
365 end
366
367 if is_true_expanded then
368 Result := Expanded_level - Result
369 end
370 end
371
372 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
373
374 do
375 if
376 use_info and then (cr_info /= Void)
377 and then not is_expanded
378 then
379 -- It's an anchored type
380 cr_info.generate_cid (buffer, final_mode)
381 end
382 buffer.putint (generated_id (final_mode))
383 buffer.putstring (", ")
384 end
385
386 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
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.make_gen_type_byte_code (ba)
394 end
395 ba.append_short_integer (generated_id (False))
396 end
397
398 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 and then not is_expanded
406 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 and then not is_expanded
425 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
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 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23