/[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 35178 - (show annotations)
Mon Dec 23 20:08:09 2002 UTC (17 years, 2 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 12287 byte(s)
Added `is_out' which is used to mark a parameter type has been a `out' parameter.
Only used for interfaces with languages that support out parameters.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23