/[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 56535 - (hide 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 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     c_type,
14 manus 10818 conforms_to_array,
15 alexk 56356 created_in,
16 manus 11298 generate_cid,
17 manus 14013 generate_cid_array,
18 manus 30169 generate_cid_init,
19 manus 35665 generate_gen_type_il,
20 manus 41824 generate_expanded_creation,
21 manus 43364 generate_expanded_initialization,
22 alexk 56356 generated_id,
23     generic_derivation,
24 alexk 55897 instantiated_description,
25 manus 41824 instantiation_in,
26 alexk 56356 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 grator 18 end
36    
37 manus 33952 SHARED_IL_CASING
38     export
39     {NONE} all
40     end
41    
42 manus 35665 SHARED_GENERATION
43     export
44     {NONE} all
45     end
46    
47     SHARED_DECLARATIONS
48     export
49     {NONE} all
50     end
51    
52 manus 30224 create
53     make
54 alexk 55707
55 manus 30224 feature {NONE} -- Initialization
56    
57     make (id: INTEGER) is
58 manus 30293 -- Create new instance of `Current' with `class_id'
59 manus 30224 -- assigned with `id'.
60     require
61     valid_id: id > 0
62     do
63 manus 30293 class_id := id
64 manus 30224 ensure
65 manus 30293 class_id_set: class_id = id
66 manus 30224 end
67 alexk 55707
68 manus 26913 feature -- Access
69 grator 18
70 manus 30293 class_id: INTEGER
71 grator 18 -- 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 manus 9655 end
78 grator 18
79 manus 10890 cr_info : CREATE_INFO
80     -- Additional information for the creation
81     -- of generic types with anchored parameters
82    
83 manus 10818 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 grator 18 base_class: CLASS_C is
90     -- Base class associated to the class type
91     do
92 manus 30293 Result := System.class_of_id (class_id)
93 manus 9655 end
94 grator 18
95 manus 41824 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 alexk 55707
103 manus 26913 type_a: CL_TYPE_A is
104 grator 236 do
105 manus 30293 create Result.make (class_id)
106 alexk 56011 Result.set_mark (declaration_mark)
107 manus 9655 end
108 grator 236
109 manus 41824 name: STRING is
110     -- String that should be displayed in debugger to represent `Current'.
111     do
112 manus 43828 Result := base_name
113 manus 41824 end
114 alexk 55707
115 alexk 56011 duplicate: like Current is
116     -- Duplication
117     do
118     Result := twin
119     end
120    
121 manus 43828 instantiation_in (other: CLASS_TYPE): CL_TYPE_I is
122 manus 41824 -- Instantation of Current in `other'
123     do
124     Result := Current
125     end
126 alexk 55707
127 alexk 56356 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 manus 33952 il_type_name (a_prefix: STRING): STRING is
137 manus 26913 -- Class name of current type.
138 manus 29681 local
139     l_class_c: like base_class
140 manus 34253 l_is_precompiled: BOOLEAN
141     l_cl_type: like associated_class_type
142 grator 18 do
143 manus 29681 l_class_c := base_class
144 manus 41824 if is_external then
145 manus 40771 Result := l_class_c.external_class_name.twin
146 manus 29681 else
147 manus 34253 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 manus 49345 Result := l_cl_type.il_type_name (a_prefix)
153 manus 34253 end
154     end
155     if not l_is_precompiled then
156 raphaels 48802 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 manus 34253 end
168 manus 29681 end
169 manus 11218 end
170    
171 alexk 55897 description, instantiated_description: ATTR_DESC is
172 grator 18 -- Type description for skeletons
173     local
174 michaels 7681 exp: EXPANDED_DESC
175     ref: REFERENCE_DESC
176 grator 485 do
177 manus 41824 if is_expanded then
178 julieng 37663 create exp
179 manus 42413 exp.set_cl_type_i (Current)
180 manus 13232 exp.set_type_i (Current)
181 manus 9655 Result := exp
182 grator 18 else
183 manus 9655 Result := c_type.description
184 manus 42413 ref ?= Result
185     if ref /= Void then
186     ref.set_type_i (Current)
187     end
188 manus 9655 end
189     end
190 grator 18
191     c_type: TYPE_C is
192     -- Associated C type
193     do
194 manus 9655 Result := Reference_c_type
195     end
196 manus 42413
197 grator 18 associated_class_type: CLASS_TYPE is
198     -- Associated class type
199 michaels 7681 require
200 manus 42865 has: has_associated_class_type
201 grator 485 do
202 manus 41824 Result := base_class.types.search_item (Current)
203 alexk 48670 ensure
204     result_not_void: Result /= Void
205 manus 9655 end
206 grator 18
207     type_id: INTEGER is
208     -- Type id of the correponding class type
209     do
210 manus 9655 Result := associated_class_type.type_id
211     end
212 grator 18
213 manus 26913 sk_value: INTEGER is
214     -- Generate SK value associated to the current type.
215 grator 18 do
216 manus 41824 if is_expanded then
217     Result := Sk_exp | (type_id - 1)
218     else
219 manus 31263 Result := Sk_ref | (type_id - 1)
220 manus 9655 end
221     end
222 grator 18
223     hash_code: INTEGER is
224     -- Hash code for current type
225     do
226 manus 30293 Result := Other_code + class_id
227 manus 9655 end
228 grator 18
229 manus 26913 feature -- Status
230    
231 manus 31541 element_type: INTEGER_8 is
232     -- Void element type
233     do
234 manus 41824 if is_expanded then
235 alexk 55707 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
236 manus 31541 else
237 manus 37130 if class_id = System.system_string_class.compiled_class.class_id then
238 manus 49446 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_string
239 manus 44032 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 manus 49446 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_object
243 manus 31541 else
244 manus 49446 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_class
245 manus 31541 end
246     end
247     end
248    
249 manus 41824 tuple_code: INTEGER_8 is
250     -- Tuple code for class type
251     do
252 manus 49446 Result := {SHARED_GEN_CONF_LEVEL}.reference_tuple_code
253 manus 41824 end
254 alexk 55707
255 alexk 56011 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 manus 26913 -- Is the type expanded?
289 alexk 56011 do
290     Result := has_expanded_mark or else has_no_mark and then base_class.is_expanded
291     end
292 manus 26913
293 alexk 56011 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 manus 26913 -- Is the type separate?
301 alexk 56011 do
302     Result := has_separate_mark
303     end
304 manus 26913
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 grator 18 do
312 manus 41824 Result := is_expanded and then base_class.is_enum
313 manus 26913 end
314    
315 manus 28380 is_external: BOOLEAN is
316 manus 41824 -- Is current type based on an external class?
317     local
318     l_base_class: like base_class
319 manus 28380 do
320 manus 41824 -- 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 manus 28380 end
325 alexk 55707
326 manus 41824 is_generated_as_single_type: BOOLEAN is
327 alexk 55707 -- Is associated type generated as a single type or as an interface type and
328 manus 41824 -- an implementation type.
329     do
330 manus 44032 -- External classes have only one type.
331     Result := is_external
332 manus 41824 if not Result then
333 manus 44058 -- Classes that inherits from external classes
334 alexk 55396 -- have only one generated type as well as expanded types.
335     Result := base_class.is_single or else is_expanded
336 manus 41824 end
337     end
338 manus 28380
339 manus 26913 is_valid: BOOLEAN is
340 manus 35544 -- Is the base class still in the system and matches its specification?
341 manus 41824 local
342     l_base_class: like base_class
343 manus 26913 do
344 manus 41824 l_base_class := base_class
345     Result := l_base_class /= Void and then (l_base_class.generics = Void)
346 manus 26913 end
347    
348     is_explicit: BOOLEAN is
349 manus 39713 -- Is Current type fixed at compile time?
350 manus 26913 do
351 manus 39713 if cr_info /= Void then
352     Result := cr_info.is_explicit
353     else
354     Result := True
355     end
356 manus 26913 end
357    
358     has_associated_class_type: BOOLEAN is
359     -- Has `Current' an associated class type?
360     do
361 alexk 48670 Result := base_class.types.has_type (Current)
362 manus 9655 end
363 grator 18
364 manus 26913 same_as (other: TYPE_I): BOOLEAN is
365     -- Is `other' equal to Current ?
366     local
367     other_cl_type: CL_TYPE_I
368 grator 508 do
369 manus 26913 other_cl_type ?= other
370     Result := other_cl_type /= Void -- FIXME
371 manus 30293 and then other_cl_type.class_id = class_id
372 manus 41824 and then other_cl_type.is_expanded = is_expanded
373 manus 26913 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 alexk 56011 set_expanded_mark is
381     -- Set class type declaration as expanded.
382 manus 26913 do
383 alexk 56011 declaration_mark := {CL_TYPE_A}.expanded_mark
384 manus 35178 ensure
385 alexk 56011 has_expanded_mark: has_expanded_mark
386 manus 26913 end
387    
388 alexk 56011 set_reference_mark is
389     -- Set class type declaration as reference.
390 manus 26913 do
391 alexk 56011 declaration_mark := {CL_TYPE_A}.reference_mark
392 manus 35178 ensure
393 alexk 56011 has_reference_mark: has_reference_mark
394 manus 26913 end
395    
396 alexk 56011 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 manus 26913 set_cr_info (cinfo : CREATE_INFO) is
405     -- Set `cr_info' to `cinfo'.
406 manus 30224 require
407     create_info_not_void: cinfo /= Void
408 manus 41824 not_expanded: not is_expanded
409 manus 26913 do
410     cr_info := cinfo
411     ensure
412     cr_info_set : cr_info = cinfo
413     end
414    
415     feature -- C generation
416    
417 manus 43364 generate_expanded_creation (buffer: GENERATION_BUFFER; target_name: STRING) is
418 manus 35665 -- Generate creation of expanded object associated to Current.
419     do
420 manus 43364 associated_class_type.generate_expanded_creation (buffer, target_name)
421     end
422 manus 35665
423 manus 43364 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 manus 35665 end
428    
429 manus 26913 generate_cecil_value (buffer: GENERATION_BUFFER) is
430     -- Generate cecil value
431     do
432 manus 41824 if not is_expanded then
433 manus 43084 buffer.put_string ("SK_REF + (uint32) ")
434 grator 508 else
435 manus 43084 buffer.put_string ("SK_EXP + (uint32) ")
436 manus 9655 end
437 manus 43084 buffer.put_type_id (associated_class_type.type_id)
438 manus 9655 end
439 grator 508
440 grator 930 feature -- Array optimization
441    
442     conforms_to_array: BOOLEAN is
443     do
444     Result := base_class.conform_to (array_class_c)
445 manus 9655 end
446 grator 930
447     feature {NONE} -- Array optimization
448    
449     array_class_c: CLASS_C is
450     once
451     Result := System.array_class.compiled_class
452 manus 9655 end
453 grator 930
454 manus 10818 feature -- Generic conformance
455    
456     generated_id (final_mode : BOOLEAN) : INTEGER is
457 manus 11298
458 manus 10818 do
459 manus 11298 if final_mode then
460     Result := type_id - 1
461 manus 10818 else
462 manus 41824 Result := associated_class_type.static_type_id - 1
463 manus 10818 end
464     end
465    
466 manus 11599 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
467 manus 11298
468 manus 10818 do
469 manus 11209 if
470     use_info and then (cr_info /= Void)
471 manus 26913 and then not is_expanded
472 manus 11209 then
473 alexk 55707 -- It's an anchored type
474 manus 11599 cr_info.generate_cid (buffer, final_mode)
475 manus 39412 else
476 manus 43084 buffer.put_integer (generated_id (final_mode))
477 manus 43156 buffer.put_character (',')
478 manus 10890 end
479 manus 10818 end
480    
481 manus 10890 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
482 manus 10818 do
483 manus 11209 if
484     use_info and then (cr_info /= Void)
485 manus 26913 and then not is_expanded
486 manus 11209 then
487 alexk 55707 -- It's an anchored type
488 manus 10890 cr_info.make_gen_type_byte_code (ba)
489 manus 39412 else
490     ba.append_short_integer (generated_id (False))
491 manus 10890 end
492 manus 10818 end
493    
494 alexk 55707 generate_cid_array (buffer : GENERATION_BUFFER;
495 manus 14013 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 manus 26913 and then not is_expanded
502 manus 14013 then
503 alexk 55707 -- It's an anchored type
504 manus 14013 cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
505 manus 39412 else
506 manus 43084 buffer.put_integer (generated_id (final_mode))
507 manus 43156 buffer.put_character (',')
508 manus 39412
509     -- Increment counter
510     dummy := idx_cnt.next
511 manus 14013 end
512     end
513    
514 alexk 55707 generate_cid_init (buffer : GENERATION_BUFFER;
515 manus 14013 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 manus 26913 and then not is_expanded
522 manus 14013 then
523 alexk 55707 -- It's an anchored type
524 manus 14013 cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
525 manus 39412 else
526     dummy := idx_cnt.next
527 manus 14013 end
528     end
529 manus 30169
530     feature -- Generic conformance for IL
531    
532     generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
533 alexk 55707 -- `use_info' is true iff we generate code for a
534 manus 30169 -- creation instruction.
535     do
536     if use_info and then cr_info /= Void then
537 manus 30582 -- It's an anchored type, we call feature
538 alexk 55707 -- that will tell us the real type of the
539 manus 30582 -- anchor in the context of Current.
540     cr_info.generate_il_type
541     else
542     il_generator.generate_class_type_instance (Current)
543 alexk 55707 end
544 manus 30169 end
545    
546 manus 33952 feature {NONE} -- Implementation
547    
548 manus 43828 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 alexk 56011 elseif is_reference and l_base_class.is_expanded then
558     Result.append ("reference ")
559 manus 43828 elseif is_separate then
560     Result.append ("separate ")
561     end
562     Result.append (l_base_class.name)
563     end
564    
565 manus 41824 frozen internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
566 manus 33952 -- 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 manus 41824 l_base_class: like base_class
572 manus 33952 do
573 manus 41824 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 alexk 46609 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 manus 41824 else
584 alexk 46609 create Result.make (a_base_name.count)
585 manus 41824 end
586 alexk 46609 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 manus 33952 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 alexk 56062 feature {CL_TYPE_A, TUPLE_CLASS_B} -- Implementation: class type declaration marks
595 alexk 56011
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 manus 41824 invariant
612     class_id_positive: class_id > 0
613 alexk 56011 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 manus 41824
619 manus 56535 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 grator 18 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23