/[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 34621 - (show annotations)
Fri Oct 11 02:31:18 2002 UTC (17 years, 4 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 11975 byte(s)
Updated to `set_type_i', new name for `set_class_type_i' in REFERENCE_DESC.

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_true_expanded,
13 is_separate,
14 is_valid,
15 is_explicit,
16 is_external,
17 same_as,
18 c_type,
19 instantiation_in,
20 complete_instantiation_in,
21 conforms_to_array,
22 generated_id,
23 generate_cid,
24 make_gen_type_byte_code,
25 generate_cid_array,
26 generate_cid_init,
27 generate_gen_type_il
28 end
29
30 DEBUG_OUTPUT
31 export
32 {NONE} all
33 end
34
35 SHARED_IL_CASING
36 export
37 {NONE} all
38 end
39
40 create
41 make
42
43 feature {NONE} -- Initialization
44
45 make (id: INTEGER) is
46 -- Create new instance of `Current' with `class_id'
47 -- assigned with `id'.
48 require
49 valid_id: id > 0
50 do
51 class_id := id
52 ensure
53 class_id_set: class_id = id
54 end
55
56 feature -- Access
57
58 class_id: INTEGER
59 -- Base class id of the type class
60
61 meta_generic: META_GENERIC is
62 -- Meta generic array describing the type class
63 do
64 -- No meta generic in non-generic type
65 end
66
67 cr_info : CREATE_INFO
68 -- Additional information for the creation
69 -- of generic types with anchored parameters
70
71 true_generics : ARRAY [TYPE_I] is
72 -- Array of generics: no mapping reference -> REFERENCE_I
73 do
74 -- Non generic types don't have them
75 end
76
77 base_class: CLASS_C is
78 -- Base class associated to the class type
79 do
80 Result := System.class_of_id (class_id)
81 end
82
83 type_a: CL_TYPE_A is
84 do
85 create Result.make (class_id)
86 Result.set_is_true_expanded (is_true_expanded)
87 Result.set_is_separate (is_separate)
88 end
89
90 il_type_name (a_prefix: STRING): STRING is
91 -- Class name of current type.
92 local
93 l_class_c: like base_class
94 l_is_precompiled: BOOLEAN
95 l_cl_type: like associated_class_type
96 do
97 l_class_c := base_class
98 if l_class_c.is_external then
99 Result := clone (l_class_c.external_class_name)
100 else
101 l_is_precompiled := l_class_c.is_precompiled
102 if l_is_precompiled then
103 l_cl_type := associated_class_type
104 l_is_precompiled := l_cl_type.is_precompiled
105 if l_is_precompiled then
106 Result := associated_class_type.il_type_name (a_prefix)
107 end
108 end
109 if not l_is_precompiled then
110 Result := internal_il_type_name (clone (l_class_c.name), a_prefix)
111 end
112 end
113 end
114
115 instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
116 -- Instantiation of Current in context of `other'
117 require else
118 True
119 do
120 Result := Current
121 end
122
123 complete_instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
124 -- Instantiation of Current in context of `other'
125 require else
126 True
127 do
128 Result := Current
129 end
130
131 description: ATTR_DESC is
132 -- Type description for skeletons
133 local
134 exp: EXPANDED_DESC
135 ref: REFERENCE_DESC
136 do
137 if is_true_expanded then
138 !! exp
139 is_true_expanded := False
140 exp.set_class_type (base_class.types.search_item (Current))
141 is_true_expanded := True
142 exp.set_type_i (Current)
143 Result := exp
144 elseif is_separate then
145 -- FIXME
146 Result := c_type.description
147 else
148 Result := c_type.description
149 end
150
151 ref ?= Result
152 if ref /= Void then
153 ref.set_type_i (Current)
154 end
155 end
156
157 c_type: TYPE_C is
158 -- Associated C type
159 do
160 Result := Reference_c_type
161 end
162
163 typecode: INTEGER is
164 -- Typecode for TUPLE element.
165 do
166 Result := feature {SHARED_TYPECODE}.reference_code
167 end
168
169 associated_class_type: CLASS_TYPE is
170 -- Associated class type
171 require
172 -- has: has_associated_class_type
173 do
174 if is_true_expanded then
175 is_true_expanded := False
176 Result := base_class.types.search_item (Current)
177 is_true_expanded := True
178 elseif is_separate then
179 is_separate := False
180 Result := base_class.types.search_item (Current)
181 is_separate := True
182 else
183 Result := base_class.types.search_item (Current)
184 end
185 end
186
187 type_id: INTEGER is
188 -- Type id of the correponding class type
189 do
190 Result := associated_class_type.type_id
191 end
192
193 expanded_type_id: INTEGER is
194 -- Type id of the corresponding expanded class type
195 do
196 is_true_expanded := False
197 Result := base_class.types.search_item (Current).type_id
198 is_true_expanded := True
199 end
200
201 sk_value: INTEGER is
202 -- Generate SK value associated to the current type.
203 do
204 -- FIXME????: separate
205 if not is_true_expanded then
206 Result := Sk_ref | (type_id - 1)
207 else
208 is_true_expanded := False
209 Result := Sk_exp | (type_id - 1)
210 is_true_expanded := True
211 end
212 end
213
214 cecil_value: INTEGER is
215 do
216 -- FIXME????: separate
217 if not is_true_expanded then
218 Result := Sk_dtype
219 else
220 Result := Sk_exp | class_id
221 end
222 end
223
224 hash_code: INTEGER is
225 -- Hash code for current type
226 do
227 Result := Other_code + class_id
228 end
229
230 feature -- Status
231
232 element_type: INTEGER_8 is
233 -- Void element type
234 do
235 if is_expanded and base_class.is_external then
236 -- We only support expanded for external class at the moment.
237 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
238 else
239 if base_class = System.system_string_class.compiled_class then
240 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_string
241 elseif base_class.class_id = System.system_object_id then
242 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_object
243 else
244 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_class
245 end
246 end
247 end
248
249 is_true_expanded: BOOLEAN
250 -- Is the type expanded?
251
252 is_separate: BOOLEAN
253 -- Is the type separate?
254
255 is_enum: BOOLEAN is
256 -- Is current type an IL enum type?
257 -- Useful to find out if some call optimization can be done
258 -- in FEATURE_B.
259 require
260 il_generation: System.il_generation
261 do
262 Result := is_true_expanded and then base_class.is_enum
263 end
264
265 is_external: BOOLEAN is
266 -- Is current type an IL enum type?
267 -- Useful to find out if some call optimization can be done
268 -- in FEATURE_B.
269 do
270 Result := base_class.is_external
271 end
272
273 is_valid: BOOLEAN is
274 -- Is the base class still in the system ?
275 do
276 Result := base_class /= Void
277 end
278
279 is_reference: BOOLEAN is
280 -- Is the type a reference type ?
281 do
282 Result := not is_true_expanded
283 end;
284
285 is_explicit: BOOLEAN is
286
287 do
288 Result := (cr_info = Void) or else is_expanded
289 end
290
291 has_associated_class_type: BOOLEAN is
292 -- Has `Current' an associated class type?
293 do
294 if is_true_expanded then
295 is_true_expanded := False
296 Result := base_class.types.has_type (Current)
297 is_true_expanded := True
298 elseif is_separate then
299 is_separate := False
300 Result := base_class.types.has_type (Current)
301 is_separate := True
302 else
303 Result := base_class.types.has_type (Current)
304 end
305 end
306
307 same_as (other: TYPE_I): BOOLEAN is
308 -- Is `other' equal to Current ?
309 local
310 other_cl_type: CL_TYPE_I
311 do
312 other_cl_type ?= other
313 Result := other_cl_type /= Void -- FIXME
314 and then other_cl_type.class_id = class_id
315 and then other_cl_type.is_true_expanded = is_true_expanded
316 and then other_cl_type.is_separate = is_separate
317 and then other_cl_type.meta_generic = Void
318 and then other_cl_type.true_generics = Void
319 end
320
321 feature -- Setting
322
323 set_is_true_expanded (b: BOOLEAN) is
324 -- Assign `b' to `is_true_expanded'.
325 do
326 is_true_expanded := b
327 end
328
329 set_is_separate (b: BOOLEAN) is
330 -- Assign `b' to `is_separate'.
331 do
332 is_separate := b
333 end
334
335 set_cr_info (cinfo : CREATE_INFO) is
336 -- Set `cr_info' to `cinfo'.
337 require
338 create_info_not_void: cinfo /= Void
339 do
340 cr_info := cinfo
341 ensure
342 cr_info_set : cr_info = cinfo
343 end
344
345 feature -- Formatting
346
347 append_signature (st: STRUCTURED_TEXT) is
348 do
349 if is_true_expanded then
350 st.add_string ("expanded ")
351 elseif is_separate then
352 st.add_string ("separate ")
353 end
354 base_class.append_signature (st)
355 end
356
357 dump (buffer: GENERATION_BUFFER) is
358 do
359 buffer.putstring (debug_output)
360 end
361
362 feature -- C generation
363
364 generate_cecil_value (buffer: GENERATION_BUFFER) is
365 -- Generate cecil value
366 do
367 -- FIXME????: separate
368 if not is_true_expanded then
369 buffer.putstring ("SK_DTYPE")
370 else
371 buffer.putstring ("SK_EXP + (uint32) ")
372 buffer.putint (associated_class_type.type_id - 1)
373 end
374 end
375
376 feature -- Array optimization
377
378 conforms_to_array: BOOLEAN is
379 do
380 Result := base_class.conform_to (array_class_c)
381 end
382
383 feature {NONE} -- Array optimization
384
385 array_class_c: CLASS_C is
386 once
387 Result := System.array_class.compiled_class
388 end
389
390 feature -- Generic conformance
391
392 generated_id (final_mode : BOOLEAN) : INTEGER is
393
394 do
395 if final_mode then
396 Result := type_id - 1
397 else
398 Result := associated_class_type.static_type_id-1
399 end
400
401 if is_true_expanded then
402 Result := Expanded_level - Result
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 end
416 buffer.putint (generated_id (final_mode))
417 buffer.putstring (", ")
418 end
419
420 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
421 do
422 if
423 use_info and then (cr_info /= Void)
424 and then not is_expanded
425 then
426 -- It's an anchored type
427 cr_info.make_gen_type_byte_code (ba)
428 end
429 ba.append_short_integer (generated_id (False))
430 end
431
432 generate_cid_array (buffer : GENERATION_BUFFER;
433 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
434 local
435 dummy : INTEGER
436 do
437 if
438 use_info and then (cr_info /= Void)
439 and then not is_expanded
440 then
441 -- It's an anchored type
442 cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
443 end
444 buffer.putint (generated_id (final_mode))
445 buffer.putstring (", ")
446
447 -- Increment counter
448 dummy := idx_cnt.next
449 end
450
451 generate_cid_init (buffer : GENERATION_BUFFER;
452 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
453 local
454 dummy : INTEGER
455 do
456 if
457 use_info and then (cr_info /= Void)
458 and then not is_expanded
459 then
460 -- It's an anchored type
461 cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
462 end
463
464 dummy := idx_cnt.next
465 end
466
467 feature -- Generic conformance for IL
468
469 generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
470 -- `use_info' is true iff we generate code for a
471 -- creation instruction.
472 do
473 if use_info and then cr_info /= Void then
474 -- It's an anchored type, we call feature
475 -- that will tell us the real type of the
476 -- anchor in the context of Current.
477 cr_info.generate_il_type
478 else
479 il_generator.generate_class_type_instance (Current)
480 end
481 end
482
483 feature -- Output
484
485 debug_output: STRING is
486 -- String that should be displayed in debugger to represent `Current'.
487 do
488 create Result.make (32)
489 if is_true_expanded then
490 Result.append ("expanded ")
491 elseif is_separate then
492 Result.append ("separate ")
493 end
494 Result.append (base_class.name_in_upper)
495 end
496
497 feature {NONE} -- Implementation
498
499 internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
500 -- Full type name of `a_base_name' using `a_prefix' in IL code generation
501 -- with namespace specification
502 require
503 a_base_name_not_void: a_base_name /= Void
504 local
505 l_name: STRING
506 do
507 Result := a_base_name
508 l_name := base_class.lace_class.actual_namespace
509 if a_prefix /= Void then
510 if l_name.is_empty then
511 l_name := a_prefix + "."
512 else
513 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
514 l_name) + "." + a_prefix + "."
515 end
516 else
517 if not l_name.is_empty then
518 l_name := il_casing.namespace_casing (System.dotnet_naming_convention,
519 l_name) + "."
520 end
521 end
522 Result := l_name + il_casing.pascal_casing (System.dotnet_naming_convention,
523 Result, feature {IL_CASING_CONVERSION}.upper_case)
524 ensure
525 internal_il_type_name_not_void: Result /= Void
526 internal_il_type_name_not_empty: not Result.is_empty
527 end
528
529 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23