/[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 46609 - (show annotations)
Tue Nov 23 13:23:01 2004 UTC (15 years, 3 months ago) by alexk
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 12475 byte(s)
Used IL_CASING.type_name to calculate a class type name.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23