/[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 43364 - (show annotations)
Sat May 29 22:49:07 2004 UTC (15 years, 9 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 13628 byte(s)
Revisited `generate_expanded_creation' and added `generate_expanded_initialization'.
Removed code from CL_TYPE_I and replaced by a call to feature of CLASS_TYPE
  which does the same job, but avoids code duplication.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23