/[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 44032 - (show annotations)
Wed Jun 30 04:19:23 2004 UTC (15 years, 8 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 13626 byte(s)
Made sure to generate `Element_type_object' for something declared of type
  ANY. This is because now our ANY and System.Object maps to System.Object
  in the generated code.
Fixed `is_generated_as_single_type' to ensure that it reports proper information
  for already generated types such as .NET external types, and for Eiffel types.
  Note that we commented some code while waiting for a good code generation
  of expanded in .NET.

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 do
113 Result := base_name
114 end
115
116 instantiation_in (other: CLASS_TYPE): CL_TYPE_I is
117 -- Instantation of Current in `other'
118 do
119 Result := Current
120 end
121
122 il_type_name (a_prefix: STRING): STRING is
123 -- Class name of current type.
124 local
125 l_class_c: like base_class
126 l_is_precompiled: BOOLEAN
127 l_cl_type: like associated_class_type
128 do
129 l_class_c := base_class
130 if is_external then
131 Result := l_class_c.external_class_name.twin
132 else
133 l_is_precompiled := l_class_c.is_precompiled
134 if l_is_precompiled then
135 l_cl_type := associated_class_type
136 l_is_precompiled := l_cl_type.is_precompiled
137 if l_is_precompiled then
138 Result := associated_class_type.il_type_name (a_prefix)
139 end
140 end
141 if not l_is_precompiled then
142 Result := internal_il_type_name (l_class_c.name.twin, a_prefix)
143 end
144 end
145 end
146
147 description: ATTR_DESC is
148 -- Type description for skeletons
149 local
150 exp: EXPANDED_DESC
151 ref: REFERENCE_DESC
152 do
153 if is_expanded then
154 create exp
155 exp.set_cl_type_i (Current)
156 exp.set_type_i (Current)
157 Result := exp
158 else
159 Result := c_type.description
160 ref ?= Result
161 if ref /= Void then
162 ref.set_type_i (Current)
163 end
164 end
165 end
166
167 c_type: TYPE_C is
168 -- Associated C type
169 do
170 Result := Reference_c_type
171 end
172
173 reference_type: CL_TYPE_I is
174 -- Associated reference type of Current
175 do
176 if not is_expanded then
177 Result := Current
178 else
179 Result := twin
180 Result.set_is_expanded (False)
181 end
182 end
183
184 associated_reference_class_type: CLASS_TYPE is
185 -- Reference class type of Current
186 do
187 Result := reference_type.associated_class_type
188 end
189
190 associated_class_type: CLASS_TYPE is
191 -- Associated class type
192 require
193 has: has_associated_class_type
194 do
195 Result := base_class.types.search_item (Current)
196 end
197
198 type_id: INTEGER is
199 -- Type id of the correponding class type
200 do
201 Result := associated_class_type.type_id
202 end
203
204 sk_value: INTEGER is
205 -- Generate SK value associated to the current type.
206 do
207 if is_expanded then
208 Result := Sk_exp | (type_id - 1)
209 else
210 Result := Sk_ref | (type_id - 1)
211 end
212 end
213
214 hash_code: INTEGER is
215 -- Hash code for current type
216 do
217 Result := Other_code + class_id
218 end
219
220 feature -- Status
221
222 element_type: INTEGER_8 is
223 -- Void element type
224 do
225 if is_expanded then
226 -- We only support expanded for external class at the moment.
227 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
228 else
229 if class_id = System.system_string_class.compiled_class.class_id then
230 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_string
231 elseif class_id = System.system_object_id or class_id = system.any_id then
232 -- For ANY or SYSTEM_OBJECT, we always generate a System.Object
233 -- signature since we can now assign SYSTEM_OBJECTs into ANYs.
234 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_object
235 else
236 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_class
237 end
238 end
239 end
240
241 tuple_code: INTEGER_8 is
242 -- Tuple code for class type
243 do
244 Result := feature {SHARED_GEN_CONF_LEVEL}.reference_tuple_code
245 end
246
247 is_expanded: BOOLEAN
248 -- Is the type expanded?
249
250 is_separate: BOOLEAN
251 -- Is the type separate?
252
253 is_enum: 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 require
258 il_generation: System.il_generation
259 do
260 Result := is_expanded and then base_class.is_enum
261 end
262
263 is_external: BOOLEAN is
264 -- Is current type based on an external class?
265 local
266 l_base_class: like base_class
267 do
268 -- All Eiffel basic types are externals, and only basic types used
269 -- as reference are not external.
270 l_base_class := base_class
271 Result := is_basic or (not l_base_class.is_basic and l_base_class.is_external)
272 end
273
274 is_generated_as_single_type: BOOLEAN is
275 -- Is associated type generated as a single type or as an interface type and
276 -- an implementation type.
277 do
278 -- External classes have only one type.
279 Result := is_external
280 if not Result then
281 -- Expanded classes, or classes that inherits from external classes
282 -- have only one generated type.
283 -- FIXME: Manu 06/28/2004: Expanded cannot yet be generated as single type.
284 -- Result := is_expanded or base_class.is_single
285 Result := base_class.is_single
286 end
287 end
288
289 is_valid: BOOLEAN is
290 -- Is the base class still in the system and matches its specification?
291 local
292 l_base_class: like base_class
293 do
294 l_base_class := base_class
295 Result := l_base_class /= Void and then (l_base_class.generics = Void)
296 end
297
298 is_reference: BOOLEAN is
299 -- Is the type a reference type ?
300 do
301 Result := not is_expanded
302 end;
303
304 is_explicit: BOOLEAN is
305 -- Is Current type fixed at compile time?
306 do
307 if cr_info /= Void then
308 Result := cr_info.is_explicit
309 else
310 Result := True
311 end
312 end
313
314 has_associated_class_type: BOOLEAN is
315 -- Has `Current' an associated class type?
316 do
317 Result := base_class.types.has_type (Current)
318 end
319
320 same_as (other: TYPE_I): BOOLEAN is
321 -- Is `other' equal to Current ?
322 local
323 other_cl_type: CL_TYPE_I
324 do
325 other_cl_type ?= other
326 Result := other_cl_type /= Void -- FIXME
327 and then other_cl_type.class_id = class_id
328 and then other_cl_type.is_expanded = is_expanded
329 and then other_cl_type.is_separate = is_separate
330 and then other_cl_type.meta_generic = Void
331 and then other_cl_type.true_generics = Void
332 end
333
334 feature -- Setting
335
336 set_is_expanded (b: BOOLEAN) is
337 -- Assign `b' to `is_expanded'.
338 do
339 is_expanded := b
340 ensure
341 is_expanded_set: is_expanded = b
342 end
343
344 set_is_separate (b: BOOLEAN) is
345 -- Assign `b' to `is_separate'.
346 do
347 is_separate := b
348 ensure
349 is_separate_set: is_separate = b
350 end
351
352 set_cr_info (cinfo : CREATE_INFO) is
353 -- Set `cr_info' to `cinfo'.
354 require
355 create_info_not_void: cinfo /= Void
356 not_expanded: not is_expanded
357 do
358 cr_info := cinfo
359 ensure
360 cr_info_set : cr_info = cinfo
361 end
362
363 feature -- C generation
364
365 generate_expanded_creation (buffer: GENERATION_BUFFER; target_name: STRING) is
366 -- Generate creation of expanded object associated to Current.
367 do
368 associated_class_type.generate_expanded_creation (buffer, target_name)
369 end
370
371 generate_expanded_initialization (buffer: GENERATION_BUFFER; target_name: STRING) is
372 -- Generate creation of expanded object associated to Current.
373 do
374 associated_class_type.generate_expanded_initialization (buffer, target_name, target_name, True)
375 end
376
377 generate_cecil_value (buffer: GENERATION_BUFFER) is
378 -- Generate cecil value
379 do
380 if not is_expanded then
381 buffer.put_string ("SK_REF + (uint32) ")
382 else
383 buffer.put_string ("SK_EXP + (uint32) ")
384 end
385 buffer.put_type_id (associated_class_type.type_id)
386 end
387
388 feature -- Array optimization
389
390 conforms_to_array: BOOLEAN is
391 do
392 Result := base_class.conform_to (array_class_c)
393 end
394
395 feature {NONE} -- Array optimization
396
397 array_class_c: CLASS_C is
398 once
399 Result := System.array_class.compiled_class
400 end
401
402 feature -- Generic conformance
403
404 generated_id (final_mode : BOOLEAN) : INTEGER is
405
406 do
407 if final_mode then
408 Result := type_id - 1
409 else
410 Result := associated_class_type.static_type_id - 1
411 end
412 end
413
414 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
415
416 do
417 if
418 use_info and then (cr_info /= Void)
419 and then not is_expanded
420 then
421 -- It's an anchored type
422 cr_info.generate_cid (buffer, final_mode)
423 else
424 buffer.put_integer (generated_id (final_mode))
425 buffer.put_character (',')
426 end
427 end
428
429 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
430 do
431 if
432 use_info and then (cr_info /= Void)
433 and then not is_expanded
434 then
435 -- It's an anchored type
436 cr_info.make_gen_type_byte_code (ba)
437 else
438 ba.append_short_integer (generated_id (False))
439 end
440 end
441
442 generate_cid_array (buffer : GENERATION_BUFFER;
443 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
444 local
445 dummy : INTEGER
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.generate_cid_array (buffer, final_mode, idx_cnt)
453 else
454 buffer.put_integer (generated_id (final_mode))
455 buffer.put_character (',')
456
457 -- Increment counter
458 dummy := idx_cnt.next
459 end
460 end
461
462 generate_cid_init (buffer : GENERATION_BUFFER;
463 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
464 local
465 dummy : INTEGER
466 do
467 if
468 use_info and then (cr_info /= Void)
469 and then not is_expanded
470 then
471 -- It's an anchored type
472 cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
473 else
474 dummy := idx_cnt.next
475 end
476 end
477
478 feature -- Generic conformance for IL
479
480 generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
481 -- `use_info' is true iff we generate code for a
482 -- creation instruction.
483 do
484 if use_info and then cr_info /= Void then
485 -- It's an anchored type, we call feature
486 -- that will tell us the real type of the
487 -- anchor in the context of Current.
488 cr_info.generate_il_type
489 else
490 il_generator.generate_class_type_instance (Current)
491 end
492 end
493
494 feature {NONE} -- Implementation
495
496 base_name: STRING is
497 -- String that should be displayed in debugger to represent `Current'.
498 local
499 l_base_class: like base_class
500 do
501 create Result.make (32)
502 l_base_class := base_class
503 if is_expanded and not l_base_class.is_expanded then
504 Result.append ("expanded ")
505 elseif not is_expanded and l_base_class.is_expanded then
506 Result.append ("reference ")
507 elseif is_separate then
508 Result.append ("separate ")
509 end
510 Result.append (l_base_class.name)
511 end
512
513 frozen internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
514 -- Full type name of `a_base_name' using `a_prefix' in IL code generation
515 -- with namespace specification
516 require
517 a_base_name_not_void: a_base_name /= Void
518 local
519 l_name: STRING
520 l_base_class: like base_class
521 do
522 l_base_class := base_class
523 -- Result needs to be in lower case because that's
524 -- what our casing conversion routines require to perform
525 -- a good job.
526 if
527 (is_expanded and l_base_class.is_expanded) or
528 (not is_expanded and not l_base_class.is_expanded)
529 then
530 Result := a_base_name.as_lower
531 else
532 if is_expanded then
533 create Result.make (6 + a_base_name.count)
534 Result.append ("VALUE_")
535 else
536 create Result.make (10 + a_base_name.count)
537 Result.append ("REFERENCE_")
538 end
539 Result.append (a_base_name)
540 Result.to_lower
541 end
542 l_name := l_base_class.lace_class.actual_namespace
543 if a_prefix /= Void then
544 if l_name.is_empty then
545 l_name := a_prefix + "."
546 else
547 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
548 l_name) + "." + a_prefix + "."
549 end
550 else
551 if not l_name.is_empty then
552 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
553 l_name) + "."
554 end
555 end
556 Result := l_name + il_casing.pascal_casing (System.dotnet_naming_convention,
557 Result, feature {IL_CASING_CONVERSION}.upper_case)
558 ensure
559 internal_il_type_name_not_void: Result /= Void
560 internal_il_type_name_not_empty: not Result.is_empty
561 end
562
563 invariant
564 class_id_positive: class_id > 0
565
566 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23