/[eiffelstudio]/branches/CAT_mono/Src/Eiffel/eiffel/genericity/cl_type_i.e
ViewVC logotype

Annotation of /branches/CAT_mono/Src/Eiffel/eiffel/genericity/cl_type_i.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 56564 - (hide annotations)
Tue Jan 17 15:00:56 2006 UTC (14 years, 1 month ago) by alexk
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 17011 byte(s)
Added a feature to replace "like Current" with the supplied context class
type.
Added a feature to determine if a generic type has a given class type as an
actual parameter.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23