/[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 48670 - (show annotations)
Wed Feb 23 17:46:45 2005 UTC (15 years ago) by alexk
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 12519 byte(s)
Added a postcondition to `associated_class_type'.
Reverted to original definition of `has_associated_class_type' as it is
correct given that all class types are registered as required.

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 associated_class_type: CLASS_TYPE is
174 -- Associated class type
175 require
176 has: has_associated_class_type
177 do
178 Result := base_class.types.search_item (Current)
179 ensure
180 result_not_void: Result /= Void
181 end
182
183 type_id: INTEGER is
184 -- Type id of the correponding class type
185 do
186 Result := associated_class_type.type_id
187 end
188
189 sk_value: INTEGER is
190 -- Generate SK value associated to the current type.
191 do
192 if is_expanded then
193 Result := Sk_exp | (type_id - 1)
194 else
195 Result := Sk_ref | (type_id - 1)
196 end
197 end
198
199 hash_code: INTEGER is
200 -- Hash code for current type
201 do
202 Result := Other_code + class_id
203 end
204
205 feature -- Status
206
207 element_type: INTEGER_8 is
208 -- Void element type
209 do
210 if is_expanded then
211 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
212 else
213 if class_id = System.system_string_class.compiled_class.class_id then
214 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_string
215 elseif class_id = System.system_object_id or class_id = system.any_id then
216 -- For ANY or SYSTEM_OBJECT, we always generate a System.Object
217 -- signature since we can now assign SYSTEM_OBJECTs into ANYs.
218 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_object
219 else
220 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_class
221 end
222 end
223 end
224
225 tuple_code: INTEGER_8 is
226 -- Tuple code for class type
227 do
228 Result := feature {SHARED_GEN_CONF_LEVEL}.reference_tuple_code
229 end
230
231 is_expanded: BOOLEAN
232 -- Is the type expanded?
233
234 is_separate: BOOLEAN
235 -- Is the type separate?
236
237 is_enum: BOOLEAN is
238 -- Is current type an IL enum type?
239 -- Useful to find out if some call optimization can be done
240 -- in FEATURE_B.
241 require
242 il_generation: System.il_generation
243 do
244 Result := is_expanded and then base_class.is_enum
245 end
246
247 is_external: BOOLEAN is
248 -- Is current type based on an external class?
249 local
250 l_base_class: like base_class
251 do
252 -- All Eiffel basic types are externals, and only basic types used
253 -- as reference are not external.
254 l_base_class := base_class
255 Result := is_basic or (not l_base_class.is_basic and l_base_class.is_external)
256 end
257
258 is_generated_as_single_type: BOOLEAN is
259 -- Is associated type generated as a single type or as an interface type and
260 -- an implementation type.
261 do
262 -- External classes have only one type.
263 Result := is_external
264 if not Result then
265 -- Classes that inherits from external classes
266 -- have only one generated type.
267 Result := base_class.is_single
268 end
269 end
270
271 is_valid: BOOLEAN is
272 -- Is the base class still in the system and matches its specification?
273 local
274 l_base_class: like base_class
275 do
276 l_base_class := base_class
277 Result := l_base_class /= Void and then (l_base_class.generics = Void)
278 end
279
280 is_reference: BOOLEAN is
281 -- Is the type a reference type ?
282 do
283 Result := not is_expanded
284 end;
285
286 is_explicit: BOOLEAN is
287 -- Is Current type fixed at compile time?
288 do
289 if cr_info /= Void then
290 Result := cr_info.is_explicit
291 else
292 Result := True
293 end
294 end
295
296 has_associated_class_type: BOOLEAN is
297 -- Has `Current' an associated class type?
298 do
299 Result := base_class.types.has_type (Current)
300 end
301
302 same_as (other: TYPE_I): BOOLEAN is
303 -- Is `other' equal to Current ?
304 local
305 other_cl_type: CL_TYPE_I
306 do
307 other_cl_type ?= other
308 Result := other_cl_type /= Void -- FIXME
309 and then other_cl_type.class_id = class_id
310 and then other_cl_type.is_expanded = is_expanded
311 and then other_cl_type.is_separate = is_separate
312 and then other_cl_type.meta_generic = Void
313 and then other_cl_type.true_generics = Void
314 end
315
316 feature -- Setting
317
318 set_is_expanded (b: BOOLEAN) is
319 -- Assign `b' to `is_expanded'.
320 do
321 is_expanded := b
322 ensure
323 is_expanded_set: is_expanded = b
324 end
325
326 set_is_separate (b: BOOLEAN) is
327 -- Assign `b' to `is_separate'.
328 do
329 is_separate := b
330 ensure
331 is_separate_set: is_separate = b
332 end
333
334 set_cr_info (cinfo : CREATE_INFO) is
335 -- Set `cr_info' to `cinfo'.
336 require
337 create_info_not_void: cinfo /= Void
338 not_expanded: not is_expanded
339 do
340 cr_info := cinfo
341 ensure
342 cr_info_set : cr_info = cinfo
343 end
344
345 feature -- C generation
346
347 generate_expanded_creation (buffer: GENERATION_BUFFER; target_name: STRING) is
348 -- Generate creation of expanded object associated to Current.
349 do
350 associated_class_type.generate_expanded_creation (buffer, target_name)
351 end
352
353 generate_expanded_initialization (buffer: GENERATION_BUFFER; target_name: STRING) is
354 -- Generate creation of expanded object associated to Current.
355 do
356 associated_class_type.generate_expanded_initialization (buffer, target_name, target_name, True)
357 end
358
359 generate_cecil_value (buffer: GENERATION_BUFFER) is
360 -- Generate cecil value
361 do
362 if not is_expanded then
363 buffer.put_string ("SK_REF + (uint32) ")
364 else
365 buffer.put_string ("SK_EXP + (uint32) ")
366 end
367 buffer.put_type_id (associated_class_type.type_id)
368 end
369
370 feature -- Array optimization
371
372 conforms_to_array: BOOLEAN is
373 do
374 Result := base_class.conform_to (array_class_c)
375 end
376
377 feature {NONE} -- Array optimization
378
379 array_class_c: CLASS_C is
380 once
381 Result := System.array_class.compiled_class
382 end
383
384 feature -- Generic conformance
385
386 generated_id (final_mode : BOOLEAN) : INTEGER is
387
388 do
389 if final_mode then
390 Result := type_id - 1
391 else
392 Result := associated_class_type.static_type_id - 1
393 end
394 end
395
396 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
397
398 do
399 if
400 use_info and then (cr_info /= Void)
401 and then not is_expanded
402 then
403 -- It's an anchored type
404 cr_info.generate_cid (buffer, final_mode)
405 else
406 buffer.put_integer (generated_id (final_mode))
407 buffer.put_character (',')
408 end
409 end
410
411 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
412 do
413 if
414 use_info and then (cr_info /= Void)
415 and then not is_expanded
416 then
417 -- It's an anchored type
418 cr_info.make_gen_type_byte_code (ba)
419 else
420 ba.append_short_integer (generated_id (False))
421 end
422 end
423
424 generate_cid_array (buffer : GENERATION_BUFFER;
425 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
426 local
427 dummy : INTEGER
428 do
429 if
430 use_info and then (cr_info /= Void)
431 and then not is_expanded
432 then
433 -- It's an anchored type
434 cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
435 else
436 buffer.put_integer (generated_id (final_mode))
437 buffer.put_character (',')
438
439 -- Increment counter
440 dummy := idx_cnt.next
441 end
442 end
443
444 generate_cid_init (buffer : GENERATION_BUFFER;
445 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
446 local
447 dummy : INTEGER
448 do
449 if
450 use_info and then (cr_info /= Void)
451 and then not is_expanded
452 then
453 -- It's an anchored type
454 cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
455 else
456 dummy := idx_cnt.next
457 end
458 end
459
460 feature -- Generic conformance for IL
461
462 generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
463 -- `use_info' is true iff we generate code for a
464 -- creation instruction.
465 do
466 if use_info and then cr_info /= Void then
467 -- It's an anchored type, we call feature
468 -- that will tell us the real type of the
469 -- anchor in the context of Current.
470 cr_info.generate_il_type
471 else
472 il_generator.generate_class_type_instance (Current)
473 end
474 end
475
476 feature {NONE} -- Implementation
477
478 base_name: STRING is
479 -- String that should be displayed in debugger to represent `Current'.
480 local
481 l_base_class: like base_class
482 do
483 create Result.make (32)
484 l_base_class := base_class
485 if is_expanded and not l_base_class.is_expanded then
486 Result.append ("expanded ")
487 elseif is_separate then
488 Result.append ("separate ")
489 end
490 Result.append (l_base_class.name)
491 end
492
493 frozen internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
494 -- Full type name of `a_base_name' using `a_prefix' in IL code generation
495 -- with namespace specification
496 require
497 a_base_name_not_void: a_base_name /= Void
498 local
499 l_base_class: like base_class
500 do
501 l_base_class := base_class
502 -- Result needs to be in lower case because that's
503 -- what our casing conversion routines require to perform
504 -- a good job.
505 if is_expanded and then not l_base_class.is_expanded then
506 create Result.make (6 + a_base_name.count)
507 Result.append ("value_")
508 elseif not is_expanded and then l_base_class.is_expanded then
509 create Result.make (10 + a_base_name.count)
510 Result.append ("reference_")
511 else
512 create Result.make (a_base_name.count)
513 end
514 Result.append (a_base_name)
515 Result.to_lower
516 Result := il_casing.type_name (l_base_class.lace_class.actual_namespace, a_prefix, Result, System.dotnet_naming_convention)
517 ensure
518 internal_il_type_name_not_void: Result /= Void
519 internal_il_type_name_not_empty: not Result.is_empty
520 end
521
522 invariant
523 class_id_positive: class_id > 0
524
525 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23