/[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 30224 - (show annotations)
Thu Jan 17 00:57:45 2002 UTC (18 years, 1 month ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 9777 byte(s)
Added `make' as a creation procedure that basically does the same thing as
`set_base_id' which has been removed.
Added precondition to `set_cr_info'.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23