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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23