/[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 33952 - (hide annotations)
Fri Aug 23 16:49:17 2002 UTC (17 years, 6 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 11458 byte(s)
Changed signature of `il_type_name' so that it can take a prefix, the purpose
was to move code from CLASS_TYPE into CL_TYPE_I. That way we can generate
a correct `il_type_name' for native arrays. Not doing it was basically
generating a class name that does not match what we were getting from CLASS_TYPE.

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 26913 is_true_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 grator 930 instantiation_in,
20 manus 10818 complete_instantiation_in,
21     conforms_to_array,
22     generated_id,
23 manus 11298 generate_cid,
24 manus 14013 make_gen_type_byte_code,
25     generate_cid_array,
26 manus 30169 generate_cid_init,
27     generate_gen_type_il
28 grator 18 end
29 manus 30169
30     DEBUG_OUTPUT
31     export
32     {NONE} all
33     end
34 grator 18
35 manus 33952 SHARED_IL_CASING
36     export
37     {NONE} all
38     end
39    
40 manus 30224 create
41     make
42    
43     feature {NONE} -- Initialization
44    
45     make (id: INTEGER) is
46 manus 30293 -- Create new instance of `Current' with `class_id'
47 manus 30224 -- assigned with `id'.
48     require
49     valid_id: id > 0
50     do
51 manus 30293 class_id := id
52 manus 30224 ensure
53 manus 30293 class_id_set: class_id = id
54 manus 30224 end
55    
56 manus 26913 feature -- Access
57 grator 18
58 manus 30293 class_id: INTEGER
59 grator 18 -- Base class id of the type class
60    
61     meta_generic: META_GENERIC is
62     -- Meta generic array describing the type class
63     do
64     -- No meta generic in non-generic type
65 manus 9655 end
66 grator 18
67 manus 10890 cr_info : CREATE_INFO
68     -- Additional information for the creation
69     -- of generic types with anchored parameters
70    
71 manus 10818 true_generics : ARRAY [TYPE_I] is
72     -- Array of generics: no mapping reference -> REFERENCE_I
73     do
74     -- Non generic types don't have them
75     end
76    
77 grator 18 base_class: CLASS_C is
78     -- Base class associated to the class type
79     do
80 manus 30293 Result := System.class_of_id (class_id)
81 manus 9655 end
82 grator 18
83 manus 26913 type_a: CL_TYPE_A is
84 grator 236 do
85 manus 30293 create Result.make (class_id)
86 manus 26913 Result.set_is_true_expanded (is_true_expanded)
87     Result.set_is_separate (is_separate)
88 manus 9655 end
89 grator 236
90 manus 33952 il_type_name (a_prefix: STRING): STRING is
91 manus 26913 -- Class name of current type.
92 manus 29681 local
93     l_class_c: like base_class
94 grator 18 do
95 manus 29681 l_class_c := base_class
96     if l_class_c.is_external then
97     Result := clone (base_class.external_class_name)
98     else
99 manus 33952 Result := internal_il_type_name (clone (base_class.name), a_prefix)
100 manus 29681 end
101 manus 11218 end
102    
103 grator 18 instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
104     -- Instantiation of Current in context of `other'
105 grator 282 require else
106     True
107 grator 18 do
108 manus 9655 Result := Current
109     end
110 grator 18
111 manus 10818 complete_instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
112     -- Instantiation of Current in context of `other'
113     require else
114     True
115     do
116     Result := Current
117     end
118    
119 grator 18 description: ATTR_DESC is
120     -- Type description for skeletons
121     local
122 michaels 7681 exp: EXPANDED_DESC
123     ref: REFERENCE_DESC
124 grator 485 do
125 manus 26913 if is_true_expanded then
126 manus 10140 !! exp
127 manus 26913 is_true_expanded := False
128 manus 32282 exp.set_class_type (base_class.types.search_item (Current))
129 manus 26913 is_true_expanded := True
130 manus 13232 exp.set_type_i (Current)
131 manus 9655 Result := exp
132 xavierl 4623 elseif is_separate then
133     -- FIXME
134     Result := c_type.description
135 grator 18 else
136 manus 9655 Result := c_type.description
137     end
138 michaels 7681
139     ref ?= Result
140     if ref /= Void then
141     ref.set_class_type_i (Current)
142     end
143 manus 9655 end
144 grator 18
145     c_type: TYPE_C is
146     -- Associated C type
147     do
148 manus 9655 Result := Reference_c_type
149     end
150 grator 18
151 manus 28618 typecode: INTEGER is
152     -- Typecode for TUPLE element.
153     do
154     Result := feature {SHARED_TYPECODE}.reference_code
155     end
156    
157 grator 18 associated_class_type: CLASS_TYPE is
158     -- Associated class type
159 michaels 7681 require
160 manus 16188 -- has: has_associated_class_type
161 grator 485 do
162 manus 26913 if is_true_expanded then
163     is_true_expanded := False
164 manus 32282 Result := base_class.types.search_item (Current)
165 manus 26913 is_true_expanded := True
166 xavierl 4623 elseif is_separate then
167 manus 11065 is_separate := False
168 manus 32282 Result := base_class.types.search_item (Current)
169 manus 11065 is_separate := True
170 grator 485 else
171 manus 32282 Result := base_class.types.search_item (Current)
172 manus 9655 end
173     end
174 grator 18
175     type_id: INTEGER is
176     -- Type id of the correponding class type
177     do
178 manus 9655 Result := associated_class_type.type_id
179     end
180 grator 18
181     expanded_type_id: INTEGER is
182     -- Type id of the corresponding expanded class type
183     do
184 manus 26913 is_true_expanded := False
185 manus 32282 Result := base_class.types.search_item (Current).type_id
186 manus 26913 is_true_expanded := True
187 manus 9655 end
188 grator 18
189 manus 26913 sk_value: INTEGER is
190     -- Generate SK value associated to the current type.
191 grator 18 do
192 xavierl 4623 -- FIXME????: separate
193 manus 26913 if not is_true_expanded then
194 manus 31263 Result := Sk_ref | (type_id - 1)
195 grator 18 else
196 manus 26913 is_true_expanded := False
197 manus 31263 Result := Sk_exp | (type_id - 1)
198 manus 26913 is_true_expanded := True
199 manus 9655 end
200     end
201 grator 18
202 manus 26913 cecil_value: INTEGER is
203     do
204     -- FIXME????: separate
205     if not is_true_expanded then
206     Result := Sk_dtype
207     else
208 manus 31263 Result := Sk_exp | class_id
209 manus 26913 end
210     end
211    
212 grator 18 hash_code: INTEGER is
213     -- Hash code for current type
214     do
215 manus 30293 Result := Other_code + class_id
216 manus 9655 end
217 grator 18
218 manus 26913 feature -- Status
219    
220 manus 31541 element_type: INTEGER_8 is
221     -- Void element type
222     do
223 manus 31580 if is_expanded and base_class.is_external then
224     -- We only support expanded for external class at the moment.
225 manus 31541 Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_valuetype
226     else
227     if base_class = System.system_string_class.compiled_class then
228     Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_string
229     elseif base_class.class_id = System.system_object_id then
230     Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_object
231     else
232     Result := feature {MD_SIGNATURE_CONSTANTS}.Element_type_class
233     end
234     end
235     end
236    
237 manus 26913 is_true_expanded: BOOLEAN
238     -- Is the type expanded?
239    
240     is_separate: BOOLEAN
241     -- Is the type separate?
242    
243     is_enum: BOOLEAN is
244     -- Is current type an IL enum type?
245     -- Useful to find out if some call optimization can be done
246     -- in FEATURE_B.
247     require
248     il_generation: System.il_generation
249 grator 18 do
250 manus 26913 Result := is_true_expanded and then base_class.is_enum
251     end
252    
253 manus 28380 is_external: BOOLEAN is
254     -- Is current type an IL enum type?
255     -- Useful to find out if some call optimization can be done
256     -- in FEATURE_B.
257     do
258     Result := base_class.is_external
259     end
260    
261 manus 26913 is_valid: BOOLEAN is
262     -- Is the base class still in the system ?
263     do
264     Result := base_class /= Void
265     end
266    
267     is_reference: BOOLEAN is
268     -- Is the type a reference type ?
269     do
270     Result := not is_true_expanded
271     end;
272    
273     is_explicit: BOOLEAN is
274    
275     do
276     Result := (cr_info = Void) or else is_expanded
277     end
278    
279     has_associated_class_type: BOOLEAN is
280     -- Has `Current' an associated class type?
281     do
282     if is_true_expanded then
283     is_true_expanded := False
284     Result := base_class.types.has_type (Current)
285     is_true_expanded := True
286     elseif is_separate then
287     is_separate := False
288     Result := base_class.types.has_type (Current)
289     is_separate := True
290 grator 18 else
291 manus 26913 Result := base_class.types.has_type (Current)
292 manus 9655 end
293     end
294 grator 18
295 manus 26913 same_as (other: TYPE_I): BOOLEAN is
296     -- Is `other' equal to Current ?
297     local
298     other_cl_type: CL_TYPE_I
299 grator 508 do
300 manus 26913 other_cl_type ?= other
301     Result := other_cl_type /= Void -- FIXME
302 manus 30293 and then other_cl_type.class_id = class_id
303 manus 26913 and then other_cl_type.is_true_expanded = is_true_expanded
304     and then other_cl_type.is_separate = is_separate
305     and then other_cl_type.meta_generic = Void
306     and then other_cl_type.true_generics = Void
307     end
308    
309     feature -- Setting
310    
311     set_is_true_expanded (b: BOOLEAN) is
312     -- Assign `b' to `is_true_expanded'.
313     do
314     is_true_expanded := b
315     end
316    
317     set_is_separate (b: BOOLEAN) is
318     -- Assign `b' to `is_separate'.
319     do
320     is_separate := b
321     end
322    
323     set_cr_info (cinfo : CREATE_INFO) is
324     -- Set `cr_info' to `cinfo'.
325 manus 30224 require
326     create_info_not_void: cinfo /= Void
327 manus 26913 do
328     cr_info := cinfo
329     ensure
330     cr_info_set : cr_info = cinfo
331     end
332    
333     feature -- Formatting
334    
335     append_signature (st: STRUCTURED_TEXT) is
336     do
337     if is_true_expanded then
338     st.add_string ("expanded ")
339     elseif is_separate then
340     st.add_string ("separate ")
341     end
342     base_class.append_signature (st)
343     end
344    
345     dump (buffer: GENERATION_BUFFER) is
346     do
347 manus 30169 buffer.putstring (debug_output)
348 manus 26913 end
349    
350     feature -- C generation
351    
352     generate_cecil_value (buffer: GENERATION_BUFFER) is
353     -- Generate cecil value
354     do
355 xavierl 4623 -- FIXME????: separate
356 manus 26913 if not is_true_expanded then
357     buffer.putstring ("SK_DTYPE")
358 grator 508 else
359 manus 26913 buffer.putstring ("SK_EXP + (uint32) ")
360 manus 30293 buffer.putint (class_id)
361 manus 9655 end
362     end
363 grator 508
364 grator 930 feature -- Array optimization
365    
366     conforms_to_array: BOOLEAN is
367     do
368     Result := base_class.conform_to (array_class_c)
369 manus 9655 end
370 grator 930
371     feature {NONE} -- Array optimization
372    
373     array_class_c: CLASS_C is
374     once
375     Result := System.array_class.compiled_class
376 manus 9655 end
377 grator 930
378 manus 10818 feature -- Generic conformance
379    
380     generated_id (final_mode : BOOLEAN) : INTEGER is
381 manus 11298
382 manus 10818 do
383 manus 11298 if final_mode then
384     Result := type_id - 1
385 manus 10818 else
386 manus 26913 Result := associated_class_type.static_type_id-1
387 manus 10818 end
388 manus 11298
389 manus 26913 if is_true_expanded then
390     Result := Expanded_level - Result
391 manus 11298 end
392 manus 10818 end
393    
394 manus 11599 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
395 manus 11298
396 manus 10818 do
397 manus 11209 if
398     use_info and then (cr_info /= Void)
399 manus 26913 and then not is_expanded
400 manus 11209 then
401     -- It's an anchored type
402 manus 11599 cr_info.generate_cid (buffer, final_mode)
403 manus 10890 end
404 manus 11599 buffer.putint (generated_id (final_mode))
405     buffer.putstring (", ")
406 manus 10818 end
407    
408 manus 10890 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
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     -- It's an anchored type
415 manus 10890 cr_info.make_gen_type_byte_code (ba)
416     end
417 manus 10818 ba.append_short_integer (generated_id (False))
418     end
419    
420 manus 14013 generate_cid_array (buffer : GENERATION_BUFFER;
421     final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
422     local
423     dummy : INTEGER
424     do
425     if
426     use_info and then (cr_info /= Void)
427 manus 26913 and then not is_expanded
428 manus 14013 then
429     -- It's an anchored type
430     cr_info.generate_cid_array (buffer, final_mode, idx_cnt)
431     end
432     buffer.putint (generated_id (final_mode))
433     buffer.putstring (", ")
434    
435     -- Increment counter
436     dummy := idx_cnt.next
437     end
438    
439     generate_cid_init (buffer : GENERATION_BUFFER;
440     final_mode, use_info : BOOLEAN; idx_cnt : COUNTER) is
441     local
442     dummy : INTEGER
443     do
444     if
445     use_info and then (cr_info /= Void)
446 manus 26913 and then not is_expanded
447 manus 14013 then
448     -- It's an anchored type
449     cr_info.generate_cid_init (buffer, final_mode, idx_cnt)
450     end
451    
452     dummy := idx_cnt.next
453     end
454 manus 30169
455     feature -- Generic conformance for IL
456    
457     generate_gen_type_il (il_generator: IL_CODE_GENERATOR; use_info : BOOLEAN) is
458     -- `use_info' is true iff we generate code for a
459     -- creation instruction.
460     do
461     if use_info and then cr_info /= Void then
462 manus 30582 -- It's an anchored type, we call feature
463     -- that will tell us the real type of the
464     -- anchor in the context of Current.
465     cr_info.generate_il_type
466     else
467     il_generator.generate_class_type_instance (Current)
468 manus 30169 end
469     end
470    
471     feature -- Output
472    
473     debug_output: STRING is
474     -- String that should be displayed in debugger to represent `Current'.
475     do
476     create Result.make (32)
477     if is_true_expanded then
478     Result.append ("expanded ")
479     elseif is_separate then
480     Result.append ("separate ")
481     end
482     Result.append (base_class.name_in_upper)
483     end
484 manus 33952
485     feature {NONE} -- Implementation
486    
487     internal_il_type_name (a_base_name, a_prefix: STRING): STRING is
488     -- Full type name of `a_base_name' using `a_prefix' in IL code generation
489     -- with namespace specification
490     require
491     a_base_name_not_void: a_base_name /= Void
492     local
493     l_name: STRING
494     do
495     Result := a_base_name
496     l_name := base_class.lace_class.actual_namespace
497     if a_prefix /= Void then
498     if l_name.is_empty then
499     l_name := a_prefix + "."
500     else
501     l_name := il_casing.namespace_casing (l_name) + "." + a_prefix + "."
502     end
503     else
504     if not l_name.is_empty then
505     l_name := il_casing.namespace_casing (l_name) + "."
506     end
507     end
508     Result := l_name + il_casing.pascal_casing (Result,
509     feature {IL_CASING_CONVERSION}.upper_case)
510     ensure
511     internal_il_type_name_not_void: Result /= Void
512     internal_il_type_name_not_empty: not Result.is_empty
513     end
514    
515 grator 18 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23