/[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 56535 - (show annotations)
Tue Jan 17 01:37:10 2006 UTC (14 years, 1 month ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 16644 byte(s)
Added text of the GPL license to all classes of the compiler.

1 indexing
2 description: "Type class."
3 legal: "See notice at end of class."
4 status: "See notice at end of class."
5 date: "$Date$"
6 revision: "$Revision$"
7
8 class CL_TYPE_I
9
10 inherit
11 TYPE_I
12 redefine
13 c_type,
14 conforms_to_array,
15 created_in,
16 generate_cid,
17 generate_cid_array,
18 generate_cid_init,
19 generate_gen_type_il,
20 generate_expanded_creation,
21 generate_expanded_initialization,
22 generated_id,
23 generic_derivation,
24 instantiated_description,
25 instantiation_in,
26 is_expanded,
27 is_explicit,
28 is_external,
29 is_generated_as_single_type,
30 is_reference,
31 is_separate,
32 is_valid,
33 make_gen_type_byte_code,
34 same_as
35 end
36
37 SHARED_IL_CASING
38 export
39 {NONE} all
40 end
41
42 SHARED_GENERATION
43 export
44 {NONE} all
45 end
46
47 SHARED_DECLARATIONS
48 export
49 {NONE} all
50 end
51
52 create
53 make
54
55 feature {NONE} -- Initialization
56
57 make (id: INTEGER) is
58 -- Create new instance of `Current' with `class_id'
59 -- assigned with `id'.
60 require
61 valid_id: id > 0
62 do
63 class_id := id
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_mark (declaration_mark)
107 end
108
109 name: STRING is
110 -- String that should be displayed in debugger to represent `Current'.
111 do
112 Result := base_name
113 end
114
115 duplicate: like Current is
116 -- Duplication
117 do
118 Result := twin
119 end
120
121 instantiation_in (other: CLASS_TYPE): CL_TYPE_I is
122 -- Instantation of Current in `other'
123 do
124 Result := Current
125 end
126
127 created_in (other: CLASS_TYPE): TYPE_I is
128 -- Resulting type of Current as if it was used to create object in `other'.
129 do
130 Result := Current
131 if cr_info /= Void then
132 Result := cr_info.created_in (other)
133 end
134 end
135
136 il_type_name (a_prefix: STRING): STRING is
137 -- Class name of current type.
138 local
139 l_class_c: like base_class
140 l_is_precompiled: BOOLEAN
141 l_cl_type: like associated_class_type
142 do
143 l_class_c := base_class
144 if is_external then
145 Result := l_class_c.external_class_name.twin
146 else
147 l_is_precompiled := l_class_c.is_precompiled
148 if l_is_precompiled then
149 l_cl_type := associated_class_type
150 l_is_precompiled := l_cl_type.is_precompiled
151 if l_is_precompiled then
152 Result := l_cl_type.il_type_name (a_prefix)
153 end
154 end
155 if not l_is_precompiled then
156 if l_class_c.external_class_name.is_equal (l_class_c.name) then
157 Result := internal_il_type_name (l_class_c.name.twin, a_prefix)
158 else
159 Result := l_class_c.external_class_name.twin
160 if a_prefix /= Void then
161 if Result.item (Result.count) /= '.' then
162 Result.append_character ('.')
163 end
164 Result.append (a_prefix)
165 end
166 end
167 end
168 end
169 end
170
171 description, instantiated_description: ATTR_DESC is
172 -- Type description for skeletons
173 local
174 exp: EXPANDED_DESC
175 ref: REFERENCE_DESC
176 do
177 if is_expanded then
178 create exp
179 exp.set_cl_type_i (Current)
180 exp.set_type_i (Current)
181 Result := exp
182 else
183 Result := c_type.description
184 ref ?= Result
185 if ref /= Void then
186 ref.set_type_i (Current)
187 end
188 end
189 end
190
191 c_type: TYPE_C is
192 -- Associated C type
193 do
194 Result := Reference_c_type
195 end
196
197 associated_class_type: CLASS_TYPE is
198 -- Associated class type
199 require
200 has: has_associated_class_type
201 do
202 Result := base_class.types.search_item (Current)
203 ensure
204 result_not_void: Result /= Void
205 end
206
207 type_id: INTEGER is
208 -- Type id of the correponding class type
209 do
210 Result := associated_class_type.type_id
211 end
212
213 sk_value: INTEGER is
214 -- Generate SK value associated to the current type.
215 do
216 if is_expanded then
217 Result := Sk_exp | (type_id - 1)
218 else
219 Result := Sk_ref | (type_id - 1)
220 end
221 end
222
223 hash_code: INTEGER is
224 -- Hash code for current type
225 do
226 Result := Other_code + class_id
227 end
228
229 feature -- Status
230
231 element_type: INTEGER_8 is
232 -- Void element type
233 do
234 if is_expanded then
235 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
236 else
237 if class_id = System.system_string_class.compiled_class.class_id then
238 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_string
239 elseif class_id = System.system_object_id or class_id = system.any_id then
240 -- For ANY or SYSTEM_OBJECT, we always generate a System.Object
241 -- signature since we can now assign SYSTEM_OBJECTs into ANYs.
242 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_object
243 else
244 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_class
245 end
246 end
247 end
248
249 tuple_code: INTEGER_8 is
250 -- Tuple code for class type
251 do
252 Result := {SHARED_GEN_CONF_LEVEL}.reference_tuple_code
253 end
254
255 has_no_mark: BOOLEAN is
256 -- Has class type no explicit mark?
257 do
258 Result := declaration_mark = {CL_TYPE_A}.no_mark
259 ensure
260 definition: Result = (declaration_mark = {CL_TYPE_A}.no_mark)
261 end
262
263 has_expanded_mark: BOOLEAN is
264 -- Is class type explicitly marked as expanded?
265 do
266 Result := declaration_mark = {CL_TYPE_A}.expanded_mark
267 ensure
268 definition: Result = (declaration_mark = {CL_TYPE_A}.expanded_mark)
269 end
270
271 has_reference_mark: BOOLEAN is
272 -- Is class type explicitly marked as reference?
273 do
274 Result := declaration_mark = {CL_TYPE_A}.reference_mark
275 ensure
276 definition: Result = (declaration_mark = {CL_TYPE_A}.reference_mark)
277 end
278
279 has_separate_mark: BOOLEAN is
280 -- Is class type explicitly marked as reference?
281 do
282 Result := declaration_mark = {CL_TYPE_A}.separate_mark
283 ensure
284 definition: Result = (declaration_mark = {CL_TYPE_A}.separate_mark)
285 end
286
287 is_expanded: BOOLEAN is
288 -- Is the type expanded?
289 do
290 Result := has_expanded_mark or else has_no_mark and then base_class.is_expanded
291 end
292
293 is_reference: BOOLEAN is
294 -- Is the type a reference type?
295 do
296 Result := has_reference_mark or else has_no_mark and then not base_class.is_expanded
297 end
298
299 is_separate: BOOLEAN is
300 -- Is the type separate?
301 do
302 Result := has_separate_mark
303 end
304
305 is_enum: BOOLEAN is
306 -- Is current type an IL enum type?
307 -- Useful to find out if some call optimization can be done
308 -- in FEATURE_B.
309 require
310 il_generation: System.il_generation
311 do
312 Result := is_expanded and then base_class.is_enum
313 end
314
315 is_external: BOOLEAN is
316 -- Is current type based on an external class?
317 local
318 l_base_class: like base_class
319 do
320 -- All Eiffel basic types are externals, and only basic types used
321 -- as reference are not external.
322 l_base_class := base_class
323 Result := is_basic or (not l_base_class.is_basic and l_base_class.is_external)
324 end
325
326 is_generated_as_single_type: BOOLEAN is
327 -- Is associated type generated as a single type or as an interface type and
328 -- an implementation type.
329 do
330 -- External classes have only one type.
331 Result := is_external
332 if not Result then
333 -- Classes that inherits from external classes
334 -- have only one generated type as well as expanded types.
335 Result := base_class.is_single or else is_expanded
336 end
337 end
338
339 is_valid: BOOLEAN is
340 -- Is the base class still in the system and matches its specification?
341 local
342 l_base_class: like base_class
343 do
344 l_base_class := base_class
345 Result := l_base_class /= Void and then (l_base_class.generics = Void)
346 end
347
348 is_explicit: BOOLEAN is
349 -- Is Current type fixed at compile time?
350 do
351 if cr_info /= Void then
352 Result := cr_info.is_explicit
353 else
354 Result := True
355 end
356 end
357
358 has_associated_class_type: BOOLEAN is
359 -- Has `Current' an associated class type?
360 do
361 Result := base_class.types.has_type (Current)
362 end
363
364 same_as (other: TYPE_I): BOOLEAN is
365 -- Is `other' equal to Current ?
366 local
367 other_cl_type: CL_TYPE_I
368 do
369 other_cl_type ?= other
370 Result := other_cl_type /= Void -- FIXME
371 and then other_cl_type.class_id = class_id
372 and then other_cl_type.is_expanded = is_expanded
373 and then other_cl_type.is_separate = is_separate
374 and then other_cl_type.meta_generic = Void
375 and then other_cl_type.true_generics = Void
376 end
377
378 feature -- Setting
379
380 set_expanded_mark is
381 -- Set class type declaration as expanded.
382 do
383 declaration_mark := {CL_TYPE_A}.expanded_mark
384 ensure
385 has_expanded_mark: has_expanded_mark
386 end
387
388 set_reference_mark is
389 -- Set class type declaration as reference.
390 do
391 declaration_mark := {CL_TYPE_A}.reference_mark
392 ensure
393 has_reference_mark: has_reference_mark
394 end
395
396 set_separate_mark is
397 -- Set class type declaration as separate.
398 do
399 declaration_mark := {CL_TYPE_A}.separate_mark
400 ensure
401 has_separate_mark: has_separate_mark
402 end
403
404 set_cr_info (cinfo : CREATE_INFO) is
405 -- Set `cr_info' to `cinfo'.
406 require
407 create_info_not_void: cinfo /= Void
408 not_expanded: not is_expanded
409 do
410 cr_info := cinfo
411 ensure
412 cr_info_set : cr_info = cinfo
413 end
414
415 feature -- C generation
416
417 generate_expanded_creation (buffer: GENERATION_BUFFER; target_name: STRING) is
418 -- Generate creation of expanded object associated to Current.
419 do
420 associated_class_type.generate_expanded_creation (buffer, target_name)
421 end
422
423 generate_expanded_initialization (buffer: GENERATION_BUFFER; target_name: STRING) is
424 -- Generate creation of expanded object associated to Current.
425 do
426 associated_class_type.generate_expanded_initialization (buffer, target_name, target_name, True)
427 end
428
429 generate_cecil_value (buffer: GENERATION_BUFFER) is
430 -- Generate cecil value
431 do
432 if not is_expanded then
433 buffer.put_string ("SK_REF + (uint32) ")
434 else
435 buffer.put_string ("SK_EXP + (uint32) ")
436 end
437 buffer.put_type_id (associated_class_type.type_id)
438 end
439
440 feature -- Array optimization
441
442 conforms_to_array: BOOLEAN is
443 do
444 Result := base_class.conform_to (array_class_c)
445 end
446
447 feature {NONE} -- Array optimization
448
449 array_class_c: CLASS_C is
450 once
451 Result := System.array_class.compiled_class
452 end
453
454 feature -- Generic conformance
455
456 generated_id (final_mode : BOOLEAN) : INTEGER is
457
458 do
459 if final_mode then
460 Result := type_id - 1
461 else
462 Result := associated_class_type.static_type_id - 1
463 end
464 end
465
466 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
467
468 do
469 if
470 use_info and then (cr_info /= Void)
471 and then not is_expanded
472 then
473 -- It's an anchored type
474 cr_info.generate_cid (buffer, final_mode)
475 else
476 buffer.put_integer (generated_id (final_mode))
477 buffer.put_character (',')
478 end
479 end
480
481 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
482 do
483 if
484 use_info and then (cr_info /= Void)
485 and then not is_expanded
486 then
487 -- It's an anchored type
488 cr_info.make_gen_type_byte_code (ba)
489 else
490 ba.append_short_integer (generated_id (False))
491 end
492 end
493
494 generate_cid_array (buffer : GENERATION_BUFFER;
495 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
496 local
497 dummy : INTEGER
498 do
499 if
500 use_info and then (cr_info /= Void)
501 and then not is_expanded
502 then
503 -- It's an anchored type
504 cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
505 else
506 buffer.put_integer (generated_id (final_mode))
507 buffer.put_character (',')
508
509 -- Increment counter
510 dummy := idx_cnt.next
511 end
512 end
513
514 generate_cid_init (buffer : GENERATION_BUFFER;
515 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
516 local
517 dummy : INTEGER
518 do
519 if
520 use_info and then (cr_info /= Void)
521 and then not is_expanded
522 then
523 -- It's an anchored type
524 cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
525 else
526 dummy := idx_cnt.next
527 end
528 end
529
530 feature -- Generic conformance for IL
531
532 generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
533 -- `use_info' is true iff we generate code for a
534 -- creation instruction.
535 do
536 if use_info and then cr_info /= Void then
537 -- It's an anchored type, we call feature
538 -- that will tell us the real type of the
539 -- anchor in the context of Current.
540 cr_info.generate_il_type
541 else
542 il_generator.generate_class_type_instance (Current)
543 end
544 end
545
546 feature {NONE} -- Implementation
547
548 base_name: STRING is
549 -- String that should be displayed in debugger to represent `Current'.
550 local
551 l_base_class: like base_class
552 do
553 create Result.make (32)
554 l_base_class := base_class
555 if is_expanded and not l_base_class.is_expanded then
556 Result.append ("expanded ")
557 elseif is_reference and l_base_class.is_expanded then
558 Result.append ("reference ")
559 elseif is_separate then
560 Result.append ("separate ")
561 end
562 Result.append (l_base_class.name)
563 end
564
565 frozen internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
566 -- Full type name of `a_base_name' using `a_prefix' in IL code generation
567 -- with namespace specification
568 require
569 a_base_name_not_void: a_base_name /= Void
570 local
571 l_base_class: like base_class
572 do
573 l_base_class := base_class
574 -- Result needs to be in lower case because that's
575 -- what our casing conversion routines require to perform
576 -- a good job.
577 if is_expanded and then not l_base_class.is_expanded then
578 create Result.make (6 + a_base_name.count)
579 Result.append ("value_")
580 elseif not is_expanded and then l_base_class.is_expanded then
581 create Result.make (10 + a_base_name.count)
582 Result.append ("reference_")
583 else
584 create Result.make (a_base_name.count)
585 end
586 Result.append (a_base_name)
587 Result.to_lower
588 Result := il_casing.type_name (l_base_class.lace_class.actual_namespace, a_prefix, Result, System.dotnet_naming_convention)
589 ensure
590 internal_il_type_name_not_void: Result /= Void
591 internal_il_type_name_not_empty: not Result.is_empty
592 end
593
594 feature {CL_TYPE_A, TUPLE_CLASS_B} -- Implementation: class type declaration marks
595
596 declaration_mark: NATURAL_8
597 -- Declaration mark associated with a class type (if any)
598
599 set_mark (mark: like declaration_mark) is
600 -- Set `declaration_mark' to the given value `mark'.
601 require
602 valid_declaration_mark:
603 mark = {CL_TYPE_A}.no_mark or mark = {CL_TYPE_A}.expanded_mark or
604 mark = {CL_TYPE_A}.reference_mark or mark = {CL_TYPE_A}.separate_mark
605 do
606 declaration_mark := mark
607 ensure
608 declaration_mark_set: declaration_mark = mark
609 end
610
611 invariant
612 class_id_positive: class_id > 0
613 valid_declaration_mark:
614 declaration_mark = {CL_TYPE_A}.no_mark or
615 declaration_mark = {CL_TYPE_A}.expanded_mark or
616 declaration_mark = {CL_TYPE_A}.reference_mark or
617 declaration_mark = {CL_TYPE_A}.separate_mark
618
619 indexing
620 copyright: "Copyright (c) 1984-2006, Eiffel Software"
621 license: "GPL version 2 see http://www.eiffel.com/licensing/gpl.txt)"
622 licensing_options: "http://www.eiffel.com/licensing"
623 copying: "[
624 This file is part of Eiffel Software's Eiffel Development Environment.
625
626 Eiffel Software's Eiffel Development Environment is free
627 software; you can redistribute it and/or modify it under
628 the terms of the GNU General Public License as published
629 by the Free Software Foundation, version 2 of the License
630 (available at the URL listed under "license" above).
631
632 Eiffel Software's Eiffel Development Environment is
633 distributed in the hope that it will be useful, but
634 WITHOUT ANY WARRANTY; without even the implied warranty
635 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
636 See the GNU General Public License for more details.
637
638 You should have received a copy of the GNU General Public
639 License along with Eiffel Software's Eiffel Development
640 Environment; if not, write to the Free Software Foundation,
641 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
642 ]"
643 source: "[
644 Eiffel Software
645 356 Storke Road, Goleta, CA 93117 USA
646 Telephone 805-685-1006, Fax 805-685-6869
647 Website http://www.eiffel.com
648 Customer support http://support.eiffel.com
649 ]"
650
651 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23