/[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 33952 - (show annotations)
Fri Aug 23 16:49:17 2002 UTC (17 years, 6 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 11458 byte(s)
Changed signature of `il_type_name' so that it can take a prefix, the purpose
was to move code from CLASS_TYPE into CL_TYPE_I. That way we can generate
a correct `il_type_name' for native arrays. Not doing it was basically
generating a class name that does not match what we were getting from CLASS_TYPE.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23