/[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 48802 - (hide annotations)
Mon Feb 28 18:46:52 2005 UTC (15 years ago) by raphaels
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 12830 byte(s)
Enabled back "alias" clause on Eiffel classes to force .NET type name. This is needed by the CodeDom Provider (ASP.NET expects the generated type to have a specific name)

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23