/[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 55897 - (hide annotations)
Sat Nov 26 18:55:32 2005 UTC (14 years, 2 months ago) by alexk
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 12849 byte(s)
Introduced a feature that ensures that attribute description is completely resolved in a sense that it does not depend on class type properties such as formal generics. This can also be used when resolving attributes of type "like Current".
1 manus 26913 indexing
2     description: "Type class."
3     date: "$Date$"
4     revision: "$Revision$"
5 grator 18
6     class CL_TYPE_I
7    
8     inherit
9     TYPE_I
10     redefine
11     is_reference,
12 manus 41824 is_expanded,
13 xavierl 4623 is_separate,
14 grator 236 is_valid,
15 manus 11218 is_explicit,
16 manus 28380 is_external,
17 grator 18 same_as,
18     c_type,
19 manus 10818 conforms_to_array,
20     generated_id,
21 manus 11298 generate_cid,
22 manus 14013 make_gen_type_byte_code,
23     generate_cid_array,
24 manus 30169 generate_cid_init,
25 manus 35665 generate_gen_type_il,
26 manus 41824 generate_expanded_creation,
27 manus 43364 generate_expanded_initialization,
28 alexk 55897 instantiated_description,
29 manus 41824 instantiation_in,
30     generic_derivation,
31     is_generated_as_single_type
32 grator 18 end
33    
34 manus 33952 SHARED_IL_CASING
35     export
36     {NONE} all
37     end
38    
39 manus 35665 SHARED_GENERATION
40     export
41     {NONE} all
42     end
43    
44     SHARED_DECLARATIONS
45     export
46     {NONE} all
47     end
48    
49 manus 30224 create
50     make
51 alexk 55707
52 manus 30224 feature {NONE} -- Initialization
53    
54     make (id: INTEGER) is
55 manus 30293 -- Create new instance of `Current' with `class_id'
56 manus 30224 -- assigned with `id'.
57     require
58     valid_id: id > 0
59     do
60 manus 30293 class_id := id
61 manus 41824 if is_basic then
62     -- We know for sure that it is expanded then.
63     is_expanded := True
64     end
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 manus 41824 Result.set_is_expanded (is_expanded)
108 manus 26913 Result.set_is_separate (is_separate)
109 manus 9655 end
110 grator 236
111 manus 41824 name: STRING is
112     -- String that should be displayed in debugger to represent `Current'.
113     do
114 manus 43828 Result := base_name
115 manus 41824 end
116 alexk 55707
117 manus 43828 instantiation_in (other: CLASS_TYPE): CL_TYPE_I is
118 manus 41824 -- Instantation of Current in `other'
119     do
120     Result := Current
121     end
122 alexk 55707
123 manus 33952 il_type_name (a_prefix: STRING): STRING is
124 manus 26913 -- Class name of current type.
125 manus 29681 local
126     l_class_c: like base_class
127 manus 34253 l_is_precompiled: BOOLEAN
128     l_cl_type: like associated_class_type
129 grator 18 do
130 manus 29681 l_class_c := base_class
131 manus 41824 if is_external then
132 manus 40771 Result := l_class_c.external_class_name.twin
133 manus 29681 else
134 manus 34253 l_is_precompiled := l_class_c.is_precompiled
135     if l_is_precompiled then
136     l_cl_type := associated_class_type
137     l_is_precompiled := l_cl_type.is_precompiled
138     if l_is_precompiled then
139 manus 49345 Result := l_cl_type.il_type_name (a_prefix)
140 manus 34253 end
141     end
142     if not l_is_precompiled then
143 raphaels 48802 if l_class_c.external_class_name.is_equal (l_class_c.name) then
144     Result := internal_il_type_name (l_class_c.name.twin, a_prefix)
145     else
146     Result := l_class_c.external_class_name.twin
147     if a_prefix /= Void then
148     if Result.item (Result.count) /= '.' then
149     Result.append_character ('.')
150     end
151     Result.append (a_prefix)
152     end
153     end
154 manus 34253 end
155 manus 29681 end
156 manus 11218 end
157    
158 alexk 55897 description, instantiated_description: ATTR_DESC is
159 grator 18 -- Type description for skeletons
160     local
161 michaels 7681 exp: EXPANDED_DESC
162     ref: REFERENCE_DESC
163 grator 485 do
164 manus 41824 if is_expanded then
165 julieng 37663 create exp
166 manus 42413 exp.set_cl_type_i (Current)
167 manus 13232 exp.set_type_i (Current)
168 manus 9655 Result := exp
169 grator 18 else
170 manus 9655 Result := c_type.description
171 manus 42413 ref ?= Result
172     if ref /= Void then
173     ref.set_type_i (Current)
174     end
175 manus 9655 end
176     end
177 grator 18
178     c_type: TYPE_C is
179     -- Associated C type
180     do
181 manus 9655 Result := Reference_c_type
182     end
183 manus 42413
184 grator 18 associated_class_type: CLASS_TYPE is
185     -- Associated class type
186 michaels 7681 require
187 manus 42865 has: has_associated_class_type
188 grator 485 do
189 manus 41824 Result := base_class.types.search_item (Current)
190 alexk 48670 ensure
191     result_not_void: Result /= Void
192 manus 9655 end
193 grator 18
194     type_id: INTEGER is
195     -- Type id of the correponding class type
196     do
197 manus 9655 Result := associated_class_type.type_id
198     end
199 grator 18
200 manus 26913 sk_value: INTEGER is
201     -- Generate SK value associated to the current type.
202 grator 18 do
203 manus 41824 if is_expanded then
204     Result := Sk_exp | (type_id - 1)
205     else
206 manus 31263 Result := Sk_ref | (type_id - 1)
207 manus 9655 end
208     end
209 grator 18
210     hash_code: INTEGER is
211     -- Hash code for current type
212     do
213 manus 30293 Result := Other_code + class_id
214 manus 9655 end
215 grator 18
216 manus 26913 feature -- Status
217    
218 manus 31541 element_type: INTEGER_8 is
219     -- Void element type
220     do
221 manus 41824 if is_expanded then
222 alexk 55707 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
223 manus 31541 else
224 manus 37130 if class_id = System.system_string_class.compiled_class.class_id then
225 manus 49446 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_string
226 manus 44032 elseif class_id = System.system_object_id or class_id = system.any_id then
227     -- For ANY or SYSTEM_OBJECT, we always generate a System.Object
228     -- signature since we can now assign SYSTEM_OBJECTs into ANYs.
229 manus 49446 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_object
230 manus 31541 else
231 manus 49446 Result := {MD_SIGNATURE_CONSTANTS}.Element_type_class
232 manus 31541 end
233     end
234     end
235    
236 manus 41824 tuple_code: INTEGER_8 is
237     -- Tuple code for class type
238     do
239 manus 49446 Result := {SHARED_GEN_CONF_LEVEL}.reference_tuple_code
240 manus 41824 end
241 alexk 55707
242 manus 41824 is_expanded: BOOLEAN
243 manus 26913 -- Is the type expanded?
244    
245     is_separate: BOOLEAN
246     -- Is the type separate?
247    
248     is_enum: BOOLEAN is
249     -- Is current type an IL enum type?
250     -- Useful to find out if some call optimization can be done
251     -- in FEATURE_B.
252     require
253     il_generation: System.il_generation
254 grator 18 do
255 manus 41824 Result := is_expanded and then base_class.is_enum
256 manus 26913 end
257    
258 manus 28380 is_external: BOOLEAN is
259 manus 41824 -- Is current type based on an external class?
260     local
261     l_base_class: like base_class
262 manus 28380 do
263 manus 41824 -- All Eiffel basic types are externals, and only basic types used
264     -- as reference are not external.
265     l_base_class := base_class
266     Result := is_basic or (not l_base_class.is_basic and l_base_class.is_external)
267 manus 28380 end
268 alexk 55707
269 manus 41824 is_generated_as_single_type: BOOLEAN is
270 alexk 55707 -- Is associated type generated as a single type or as an interface type and
271 manus 41824 -- an implementation type.
272     do
273 manus 44032 -- External classes have only one type.
274     Result := is_external
275 manus 41824 if not Result then
276 manus 44058 -- Classes that inherits from external classes
277 alexk 55396 -- have only one generated type as well as expanded types.
278     Result := base_class.is_single or else is_expanded
279 manus 41824 end
280     end
281 manus 28380
282 manus 26913 is_valid: BOOLEAN is
283 manus 35544 -- Is the base class still in the system and matches its specification?
284 manus 41824 local
285     l_base_class: like base_class
286 manus 26913 do
287 manus 41824 l_base_class := base_class
288     Result := l_base_class /= Void and then (l_base_class.generics = Void)
289 manus 26913 end
290    
291     is_reference: BOOLEAN is
292 alexk 55707 -- Is the type a reference type?
293 manus 26913 do
294 manus 41824 Result := not is_expanded
295 alexk 55707 end
296 manus 26913
297     is_explicit: BOOLEAN is
298 manus 39713 -- Is Current type fixed at compile time?
299 manus 26913 do
300 manus 39713 if cr_info /= Void then
301     Result := cr_info.is_explicit
302     else
303     Result := True
304     end
305 manus 26913 end
306    
307     has_associated_class_type: BOOLEAN is
308     -- Has `Current' an associated class type?
309     do
310 alexk 48670 Result := base_class.types.has_type (Current)
311 manus 9655 end
312 grator 18
313 manus 26913 same_as (other: TYPE_I): BOOLEAN is
314     -- Is `other' equal to Current ?
315     local
316     other_cl_type: CL_TYPE_I
317 grator 508 do
318 manus 26913 other_cl_type ?= other
319     Result := other_cl_type /= Void -- FIXME
320 manus 30293 and then other_cl_type.class_id = class_id
321 manus 41824 and then other_cl_type.is_expanded = is_expanded
322 manus 26913 and then other_cl_type.is_separate = is_separate
323     and then other_cl_type.meta_generic = Void
324     and then other_cl_type.true_generics = Void
325     end
326    
327     feature -- Setting
328    
329 manus 41824 set_is_expanded (b: BOOLEAN) is
330     -- Assign `b' to `is_expanded'.
331 manus 26913 do
332 manus 41824 is_expanded := b
333 manus 35178 ensure
334 manus 41824 is_expanded_set: is_expanded = b
335 manus 26913 end
336    
337     set_is_separate (b: BOOLEAN) is
338     -- Assign `b' to `is_separate'.
339     do
340     is_separate := b
341 manus 35178 ensure
342     is_separate_set: is_separate = b
343 manus 26913 end
344    
345     set_cr_info (cinfo : CREATE_INFO) is
346     -- Set `cr_info' to `cinfo'.
347 manus 30224 require
348     create_info_not_void: cinfo /= Void
349 manus 41824 not_expanded: not is_expanded
350 manus 26913 do
351     cr_info := cinfo
352     ensure
353     cr_info_set : cr_info = cinfo
354     end
355    
356     feature -- C generation
357    
358 manus 43364 generate_expanded_creation (buffer: GENERATION_BUFFER; target_name: STRING) is
359 manus 35665 -- Generate creation of expanded object associated to Current.
360     do
361 manus 43364 associated_class_type.generate_expanded_creation (buffer, target_name)
362     end
363 manus 35665
364 manus 43364 generate_expanded_initialization (buffer: GENERATION_BUFFER; target_name: STRING) is
365     -- Generate creation of expanded object associated to Current.
366     do
367     associated_class_type.generate_expanded_initialization (buffer, target_name, target_name, True)
368 manus 35665 end
369    
370 manus 26913 generate_cecil_value (buffer: GENERATION_BUFFER) is
371     -- Generate cecil value
372     do
373 manus 41824 if not is_expanded then
374 manus 43084 buffer.put_string ("SK_REF + (uint32) ")
375 grator 508 else
376 manus 43084 buffer.put_string ("SK_EXP + (uint32) ")
377 manus 9655 end
378 manus 43084 buffer.put_type_id (associated_class_type.type_id)
379 manus 9655 end
380 grator 508
381 grator 930 feature -- Array optimization
382    
383     conforms_to_array: BOOLEAN is
384     do
385     Result := base_class.conform_to (array_class_c)
386 manus 9655 end
387 grator 930
388     feature {NONE} -- Array optimization
389    
390     array_class_c: CLASS_C is
391     once
392     Result := System.array_class.compiled_class
393 manus 9655 end
394 grator 930
395 manus 10818 feature -- Generic conformance
396    
397     generated_id (final_mode : BOOLEAN) : INTEGER is
398 manus 11298
399 manus 10818 do
400 manus 11298 if final_mode then
401     Result := type_id - 1
402 manus 10818 else
403 manus 41824 Result := associated_class_type.static_type_id - 1
404 manus 10818 end
405     end
406    
407 manus 11599 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
408 manus 11298
409 manus 10818 do
410 manus 11209 if
411     use_info and then (cr_info /= Void)
412 manus 26913 and then not is_expanded
413 manus 11209 then
414 alexk 55707 -- It's an anchored type
415 manus 11599 cr_info.generate_cid (buffer, final_mode)
416 manus 39412 else
417 manus 43084 buffer.put_integer (generated_id (final_mode))
418 manus 43156 buffer.put_character (',')
419 manus 10890 end
420 manus 10818 end
421    
422 manus 10890 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
423 manus 10818 do
424 manus 11209 if
425     use_info and then (cr_info /= Void)
426 manus 26913 and then not is_expanded
427 manus 11209 then
428 alexk 55707 -- It's an anchored type
429 manus 10890 cr_info.make_gen_type_byte_code (ba)
430 manus 39412 else
431     ba.append_short_integer (generated_id (False))
432 manus 10890 end
433 manus 10818 end
434    
435 alexk 55707 generate_cid_array (buffer : GENERATION_BUFFER;
436 manus 14013 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
437     local
438     dummy : INTEGER
439     do
440     if
441     use_info and then (cr_info /= Void)
442 manus 26913 and then not is_expanded
443 manus 14013 then
444 alexk 55707 -- It's an anchored type
445 manus 14013 cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
446 manus 39412 else
447 manus 43084 buffer.put_integer (generated_id (final_mode))
448 manus 43156 buffer.put_character (',')
449 manus 39412
450     -- Increment counter
451     dummy := idx_cnt.next
452 manus 14013 end
453     end
454    
455 alexk 55707 generate_cid_init (buffer : GENERATION_BUFFER;
456 manus 14013 final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
457     local
458     dummy : INTEGER
459     do
460     if
461     use_info and then (cr_info /= Void)
462 manus 26913 and then not is_expanded
463 manus 14013 then
464 alexk 55707 -- It's an anchored type
465 manus 14013 cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
466 manus 39412 else
467     dummy := idx_cnt.next
468 manus 14013 end
469     end
470 manus 30169
471     feature -- Generic conformance for IL
472    
473     generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
474 alexk 55707 -- `use_info' is true iff we generate code for a
475 manus 30169 -- creation instruction.
476     do
477     if use_info and then cr_info /= Void then
478 manus 30582 -- It's an anchored type, we call feature
479 alexk 55707 -- that will tell us the real type of the
480 manus 30582 -- anchor in the context of Current.
481     cr_info.generate_il_type
482     else
483     il_generator.generate_class_type_instance (Current)
484 alexk 55707 end
485 manus 30169 end
486    
487 manus 33952 feature {NONE} -- Implementation
488    
489 manus 43828 base_name: STRING is
490     -- String that should be displayed in debugger to represent `Current'.
491     local
492     l_base_class: like base_class
493     do
494     create Result.make (32)
495     l_base_class := base_class
496     if is_expanded and not l_base_class.is_expanded then
497     Result.append ("expanded ")
498     elseif is_separate then
499     Result.append ("separate ")
500     end
501     Result.append (l_base_class.name)
502     end
503    
504 manus 41824 frozen internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
505 manus 33952 -- Full type name of `a_base_name' using `a_prefix' in IL code generation
506     -- with namespace specification
507     require
508     a_base_name_not_void: a_base_name /= Void
509     local
510 manus 41824 l_base_class: like base_class
511 manus 33952 do
512 manus 41824 l_base_class := base_class
513     -- Result needs to be in lower case because that's
514     -- what our casing conversion routines require to perform
515     -- a good job.
516 alexk 46609 if is_expanded and then not l_base_class.is_expanded then
517     create Result.make (6 + a_base_name.count)
518     Result.append ("value_")
519     elseif not is_expanded and then l_base_class.is_expanded then
520     create Result.make (10 + a_base_name.count)
521     Result.append ("reference_")
522 manus 41824 else
523 alexk 46609 create Result.make (a_base_name.count)
524 manus 41824 end
525 alexk 46609 Result.append (a_base_name)
526     Result.to_lower
527     Result := il_casing.type_name (l_base_class.lace_class.actual_namespace, a_prefix, Result, System.dotnet_naming_convention)
528 manus 33952 ensure
529     internal_il_type_name_not_void: Result /= Void
530     internal_il_type_name_not_empty: not Result.is_empty
531     end
532    
533 manus 41824 invariant
534     class_id_positive: class_id > 0
535    
536 grator 18 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23