/[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 55897 - (show annotations)
Sat Nov 26 18:55:32 2005 UTC (14 years, 2 months ago) by alexk
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 12849 byte(s)
Introduced a feature that ensures that attribute description is completely resolved in a sense that it does not depend on class type properties such as formal generics. This can also be used when resolving attributes of type "like Current".
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_expanded,
13 is_separate,
14 is_valid,
15 is_explicit,
16 is_external,
17 same_as,
18 c_type,
19 conforms_to_array,
20 generated_id,
21 generate_cid,
22 make_gen_type_byte_code,
23 generate_cid_array,
24 generate_cid_init,
25 generate_gen_type_il,
26 generate_expanded_creation,
27 generate_expanded_initialization,
28 instantiated_description,
29 instantiation_in,
30 generic_derivation,
31 is_generated_as_single_type
32 end
33
34 SHARED_IL_CASING
35 export
36 {NONE} all
37 end
38
39 SHARED_GENERATION
40 export
41 {NONE} all
42 end
43
44 SHARED_DECLARATIONS
45 export
46 {NONE} all
47 end
48
49 create
50 make
51
52 feature {NONE} -- Initialization
53
54 make (id: INTEGER) is
55 -- Create new instance of `Current' with `class_id'
56 -- assigned with `id'.
57 require
58 valid_id: id > 0
59 do
60 class_id := id
61 if is_basic then
62 -- We know for sure that it is expanded then.
63 is_expanded := True
64 end
65 ensure
66 class_id_set: class_id = id
67 end
68
69 feature -- Access
70
71 class_id: INTEGER
72 -- Base class id of the type class
73
74 meta_generic: META_GENERIC is
75 -- Meta generic array describing the type class
76 do
77 -- No meta generic in non-generic type
78 end
79
80 cr_info : CREATE_INFO
81 -- Additional information for the creation
82 -- of generic types with anchored parameters
83
84 true_generics : ARRAY [TYPE_I] is
85 -- Array of generics: no mapping reference -> REFERENCE_I
86 do
87 -- Non generic types don't have them
88 end
89
90 base_class: CLASS_C is
91 -- Base class associated to the class type
92 do
93 Result := System.class_of_id (class_id)
94 end
95
96 generic_derivation: CL_TYPE_I is
97 -- Precise generic derivation of current type.
98 -- That is to say given a type, it gives the associated TYPE_I
99 -- which can be used to search its associated CLASS_TYPE.
100 do
101 Result := Current
102 end
103
104 type_a: CL_TYPE_A is
105 do
106 create Result.make (class_id)
107 Result.set_is_expanded (is_expanded)
108 Result.set_is_separate (is_separate)
109 end
110
111 name: STRING is
112 -- String that should be displayed in debugger to represent `Current'.
113 do
114 Result := base_name
115 end
116
117 instantiation_in (other: CLASS_TYPE): CL_TYPE_I is
118 -- Instantation of Current in `other'
119 do
120 Result := Current
121 end
122
123 il_type_name (a_prefix: STRING): STRING is
124 -- Class name of current type.
125 local
126 l_class_c: like base_class
127 l_is_precompiled: BOOLEAN
128 l_cl_type: like associated_class_type
129 do
130 l_class_c := base_class
131 if is_external then
132 Result := l_class_c.external_class_name.twin
133 else
134 l_is_precompiled := l_class_c.is_precompiled
135 if l_is_precompiled then
136 l_cl_type := associated_class_type
137 l_is_precompiled := l_cl_type.is_precompiled
138 if l_is_precompiled then
139 Result := l_cl_type.il_type_name (a_prefix)
140 end
141 end
142 if not l_is_precompiled then
143 if l_class_c.external_class_name.is_equal (l_class_c.name) then
144 Result := internal_il_type_name (l_class_c.name.twin, a_prefix)
145 else
146 Result := l_class_c.external_class_name.twin
147 if a_prefix /= Void then
148 if Result.item (Result.count) /= '.' then
149 Result.append_character ('.')
150 end
151 Result.append (a_prefix)
152 end
153 end
154 end
155 end
156 end
157
158 description, instantiated_description: ATTR_DESC is
159 -- Type description for skeletons
160 local
161 exp: EXPANDED_DESC
162 ref: REFERENCE_DESC
163 do
164 if is_expanded then
165 create exp
166 exp.set_cl_type_i (Current)
167 exp.set_type_i (Current)
168 Result := exp
169 else
170 Result := c_type.description
171 ref ?= Result
172 if ref /= Void then
173 ref.set_type_i (Current)
174 end
175 end
176 end
177
178 c_type: TYPE_C is
179 -- Associated C type
180 do
181 Result := Reference_c_type
182 end
183
184 associated_class_type: CLASS_TYPE is
185 -- Associated class type
186 require
187 has: has_associated_class_type
188 do
189 Result := base_class.types.search_item (Current)
190 ensure
191 result_not_void: Result /= Void
192 end
193
194 type_id: INTEGER is
195 -- Type id of the correponding class type
196 do
197 Result := associated_class_type.type_id
198 end
199
200 sk_value: INTEGER is
201 -- Generate SK value associated to the current type.
202 do
203 if is_expanded then
204 Result := Sk_exp | (type_id - 1)
205 else
206 Result := Sk_ref | (type_id - 1)
207 end
208 end
209
210 hash_code: INTEGER is
211 -- Hash code for current type
212 do
213 Result := Other_code + class_id
214 end
215
216 feature -- Status
217
218 element_type: INTEGER_8 is
219 -- Void element type
220 do
221 if is_expanded then
222 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
223 else
224 if class_id = System.system_string_class.compiled_class.class_id then
225 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_string
226 elseif class_id = System.system_object_id or class_id = system.any_id then
227 -- For ANY or SYSTEM_OBJECT, we always generate a System.Object
228 -- signature since we can now assign SYSTEM_OBJECTs into ANYs.
229 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_object
230 else
231 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_class
232 end
233 end
234 end
235
236 tuple_code: INTEGER_8 is
237 -- Tuple code for class type
238 do
239 Result := {SHARED_GEN_CONF_LEVEL}.reference_tuple_code
240 end
241
242 is_expanded: BOOLEAN
243 -- Is the type expanded?
244
245 is_separate: BOOLEAN
246 -- Is the type separate?
247
248 is_enum: 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 require
253 il_generation: System.il_generation
254 do
255 Result := is_expanded and then base_class.is_enum
256 end
257
258 is_external: BOOLEAN is
259 -- Is current type based on an external class?
260 local
261 l_base_class: like base_class
262 do
263 -- All Eiffel basic types are externals, and only basic types used
264 -- as reference are not external.
265 l_base_class := base_class
266 Result := is_basic or (not l_base_class.is_basic and l_base_class.is_external)
267 end
268
269 is_generated_as_single_type: BOOLEAN is
270 -- Is associated type generated as a single type or as an interface type and
271 -- an implementation type.
272 do
273 -- External classes have only one type.
274 Result := is_external
275 if not Result then
276 -- Classes that inherits from external classes
277 -- have only one generated type as well as expanded types.
278 Result := base_class.is_single or else is_expanded
279 end
280 end
281
282 is_valid: BOOLEAN is
283 -- Is the base class still in the system and matches its specification?
284 local
285 l_base_class: like base_class
286 do
287 l_base_class := base_class
288 Result := l_base_class /= Void and then (l_base_class.generics = Void)
289 end
290
291 is_reference: BOOLEAN is
292 -- Is the type a reference type?
293 do
294 Result := not is_expanded
295 end
296
297 is_explicit: BOOLEAN is
298 -- Is Current type fixed at compile time?
299 do
300 if cr_info /= Void then
301 Result := cr_info.is_explicit
302 else
303 Result := True
304 end
305 end
306
307 has_associated_class_type: BOOLEAN is
308 -- Has `Current' an associated class type?
309 do
310 Result := base_class.types.has_type (Current)
311 end
312
313 same_as (other: TYPE_I): BOOLEAN is
314 -- Is `other' equal to Current ?
315 local
316 other_cl_type: CL_TYPE_I
317 do
318 other_cl_type ?= other
319 Result := other_cl_type /= Void -- FIXME
320 and then other_cl_type.class_id = class_id
321 and then other_cl_type.is_expanded = is_expanded
322 and then other_cl_type.is_separate = is_separate
323 and then other_cl_type.meta_generic = Void
324 and then other_cl_type.true_generics = Void
325 end
326
327 feature -- Setting
328
329 set_is_expanded (b: BOOLEAN) is
330 -- Assign `b' to `is_expanded'.
331 do
332 is_expanded := b
333 ensure
334 is_expanded_set: is_expanded = b
335 end
336
337 set_is_separate (b: BOOLEAN) is
338 -- Assign `b' to `is_separate'.
339 do
340 is_separate := b
341 ensure
342 is_separate_set: is_separate = b
343 end
344
345 set_cr_info (cinfo : CREATE_INFO) is
346 -- Set `cr_info' to `cinfo'.
347 require
348 create_info_not_void: cinfo /= Void
349 not_expanded: not is_expanded
350 do
351 cr_info := cinfo
352 ensure
353 cr_info_set : cr_info = cinfo
354 end
355
356 feature -- C generation
357
358 generate_expanded_creation (buffer: GENERATION_BUFFER; target_name: STRING) is
359 -- Generate creation of expanded object associated to Current.
360 do
361 associated_class_type.generate_expanded_creation (buffer, target_name)
362 end
363
364 generate_expanded_initialization (buffer: GENERATION_BUFFER; target_name: STRING) is
365 -- Generate creation of expanded object associated to Current.
366 do
367 associated_class_type.generate_expanded_initialization (buffer, target_name, target_name, True)
368 end
369
370 generate_cecil_value (buffer: GENERATION_BUFFER) is
371 -- Generate cecil value
372 do
373 if not is_expanded then
374 buffer.put_string ("SK_REF + (uint32) ")
375 else
376 buffer.put_string ("SK_EXP + (uint32) ")
377 end
378 buffer.put_type_id (associated_class_type.type_id)
379 end
380
381 feature -- Array optimization
382
383 conforms_to_array: BOOLEAN is
384 do
385 Result := base_class.conform_to (array_class_c)
386 end
387
388 feature {NONE} -- Array optimization
389
390 array_class_c: CLASS_C is
391 once
392 Result := System.array_class.compiled_class
393 end
394
395 feature -- Generic conformance
396
397 generated_id (final_mode : BOOLEAN) : INTEGER is
398
399 do
400 if final_mode then
401 Result := type_id - 1
402 else
403 Result := associated_class_type.static_type_id - 1
404 end
405 end
406
407 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
408
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.generate_cid (buffer, final_mode)
416 else
417 buffer.put_integer (generated_id (final_mode))
418 buffer.put_character (',')
419 end
420 end
421
422 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
423 do
424 if
425 use_info and then (cr_info /= Void)
426 and then not is_expanded
427 then
428 -- It's an anchored type
429 cr_info.make_gen_type_byte_code (ba)
430 else
431 ba.append_short_integer (generated_id (False))
432 end
433 end
434
435 generate_cid_array (buffer : GENERATION_BUFFER;
436 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
437 local
438 dummy : INTEGER
439 do
440 if
441 use_info and then (cr_info /= Void)
442 and then not is_expanded
443 then
444 -- It's an anchored type
445 cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
446 else
447 buffer.put_integer (generated_id (final_mode))
448 buffer.put_character (',')
449
450 -- Increment counter
451 dummy := idx_cnt.next
452 end
453 end
454
455 generate_cid_init (buffer : GENERATION_BUFFER;
456 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
457 local
458 dummy : INTEGER
459 do
460 if
461 use_info and then (cr_info /= Void)
462 and then not is_expanded
463 then
464 -- It's an anchored type
465 cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
466 else
467 dummy := idx_cnt.next
468 end
469 end
470
471 feature -- Generic conformance for IL
472
473 generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
474 -- `use_info' is true iff we generate code for a
475 -- creation instruction.
476 do
477 if use_info and then cr_info /= Void then
478 -- It's an anchored type, we call feature
479 -- that will tell us the real type of the
480 -- anchor in the context of Current.
481 cr_info.generate_il_type
482 else
483 il_generator.generate_class_type_instance (Current)
484 end
485 end
486
487 feature {NONE} -- Implementation
488
489 base_name: STRING is
490 -- String that should be displayed in debugger to represent `Current'.
491 local
492 l_base_class: like base_class
493 do
494 create Result.make (32)
495 l_base_class := base_class
496 if is_expanded and not l_base_class.is_expanded then
497 Result.append ("expanded ")
498 elseif is_separate then
499 Result.append ("separate ")
500 end
501 Result.append (l_base_class.name)
502 end
503
504 frozen internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
505 -- Full type name of `a_base_name' using `a_prefix' in IL code generation
506 -- with namespace specification
507 require
508 a_base_name_not_void: a_base_name /= Void
509 local
510 l_base_class: like base_class
511 do
512 l_base_class := base_class
513 -- Result needs to be in lower case because that's
514 -- what our casing conversion routines require to perform
515 -- a good job.
516 if is_expanded and then not l_base_class.is_expanded then
517 create Result.make (6 + a_base_name.count)
518 Result.append ("value_")
519 elseif not is_expanded and then l_base_class.is_expanded then
520 create Result.make (10 + a_base_name.count)
521 Result.append ("reference_")
522 else
523 create Result.make (a_base_name.count)
524 end
525 Result.append (a_base_name)
526 Result.to_lower
527 Result := il_casing.type_name (l_base_class.lace_class.actual_namespace, a_prefix, Result, System.dotnet_naming_convention)
528 ensure
529 internal_il_type_name_not_void: Result /= Void
530 internal_il_type_name_not_empty: not Result.is_empty
531 end
532
533 invariant
534 class_id_positive: class_id > 0
535
536 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23