/[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 30169 - (show annotations)
Fri Jan 11 01:28:57 2002 UTC (18 years, 1 month ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 9565 byte(s)
Addeg `generate_gen_type_il' in TYPE_I and redefined it in descendants. This is
  used for generic conformance in IL code generation where we generate in IL
  stream the data about the type being analyzed. This data is then used for creation
  of objects or reverse assignment.
In CL_TYPE_I added inheritance to `DEBUG_OUTPUT' so that we can see the associated
  class name in debugger.
Cosmetics.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23