/[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 10890 - (hide annotations)
Tue Aug 11 00:12:19 1998 UTC (21 years, 6 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 7202 byte(s)
Updated version of generic conformance

1 grator 18 -- Type class
2    
3     class CL_TYPE_I
4    
5     inherit
6     TYPE_I
7     redefine
8     is_reference,
9     is_expanded,
10 xavierl 4623 is_separate,
11 grator 236 is_valid,
12 grator 18 same_as,
13     c_type,
14 grator 930 instantiation_in,
15 manus 10818 complete_instantiation_in,
16     conforms_to_array,
17     generated_id,
18     gen_type_string,
19     make_gen_type_byte_code
20 grator 18 end
21    
22     feature
23    
24 manus 9655 base_id: CLASS_ID
25 grator 18 -- Base class id of the type class
26    
27 manus 9655 is_expanded: BOOLEAN
28 manus 8805 -- Is the type expanded?
29 grator 18
30 manus 9655 is_separate: BOOLEAN
31 manus 8805 -- Is the type separate?
32 xavierl 4623
33 ericb 3652 set_base_id (c: CLASS_ID) is
34 grator 18 -- Assign `c' to `base_id'.
35     do
36 manus 9655 base_id := c
37     end
38 grator 18
39     set_is_expanded (b: BOOLEAN) is
40     -- Assign `b' to `is_expanded'.
41     do
42 manus 9655 is_expanded := b
43     end
44 grator 18
45 xavierl 4623 set_is_separate (b: BOOLEAN) is
46     -- Assign `b' to `is_separate'.
47     do
48 manus 9655 is_separate := b
49     end
50 xavierl 4623
51 grator 18 meta_generic: META_GENERIC is
52     -- Meta generic array describing the type class
53     do
54     -- No meta generic in non-generic type
55 manus 9655 end
56 grator 18
57 manus 10890 cr_info : CREATE_INFO
58     -- Additional information for the creation
59     -- of generic types with anchored parameters
60    
61     set_cr_info (cinfo : CREATE_INFO) is
62     -- Set `cr_infoļ to `cinfoļ.
63     do
64     cr_info := cinfo
65     ensure
66     cr_info_set : cr_info = cinfo
67     end
68    
69 manus 10818 true_generics : ARRAY [TYPE_I] is
70     -- Array of generics: no mapping reference -> REFERENCE_I
71     do
72     -- Non generic types don't have them
73     end
74    
75 grator 18 base_class: CLASS_C is
76     -- Base class associated to the class type
77     do
78 manus 9655 Result := System.class_of_id (base_id)
79     end
80 grator 18
81 grator 236 is_valid: BOOLEAN is
82     -- Is the base class still in the system ?
83     do
84 manus 9655 Result := base_class /= Void
85     end
86 grator 236
87 grator 18 is_reference: BOOLEAN is
88     -- Is the type a reference type ?
89     do
90 manus 9655 Result := not is_expanded
91 grator 18 end;
92    
93     same_as (other: TYPE_I): BOOLEAN is
94     -- Is `other' equal to Current ?
95     local
96 manus 9655 other_cl_type: CL_TYPE_I
97 grator 18 do
98 manus 9655 other_cl_type ?= other
99 manus 8805 Result := other_cl_type /= Void -- FIXME
100     and then equal (other_cl_type.base_id, base_id)
101     and then other_cl_type.is_expanded = is_expanded
102     and then other_cl_type.is_separate = is_separate
103     and then other_cl_type.meta_generic = Void
104 manus 10818 and then other_cl_type.true_generics = Void
105 manus 9655 end
106 grator 18
107     instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
108     -- Instantiation of Current in context of `other'
109 grator 282 require else
110     True
111 grator 18 do
112 manus 9655 Result := Current
113     end
114 grator 18
115 manus 10818 complete_instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
116     -- Instantiation of Current in context of `other'
117     require else
118     True
119     do
120     Result := Current
121     end
122    
123 grator 18 description: ATTR_DESC is
124     -- Type description for skeletons
125     local
126 michaels 7681 exp: EXPANDED_DESC
127     ref: REFERENCE_DESC
128 grator 485 do
129 grator 18 if is_expanded then
130 manus 10140 !! exp
131 manus 9655 is_expanded := False
132 manus 10196 exp.set_class_type (base_class.types.conservative_search_item (Current))
133 manus 9655 is_expanded := True
134     Result := exp
135 xavierl 4623 elseif is_separate then
136     -- FIXME
137     Result := c_type.description
138 grator 18 else
139 manus 9655 Result := c_type.description
140     end
141 michaels 7681
142     ref ?= Result
143     if ref /= Void then
144     ref.set_class_type_i (Current)
145     end
146 manus 9655 end
147 grator 18
148     c_type: TYPE_C is
149     -- Associated C type
150     do
151 manus 9655 Result := Reference_c_type
152     end
153 grator 18
154 guusl 3636 append_signature (st: STRUCTURED_TEXT) is
155 grator 552 do
156     if is_expanded then
157 manus 9655 st.add_string ("expanded ")
158 xavierl 4623 elseif is_separate then
159 manus 9655 st.add_string ("separate ")
160     end
161 dinov 6562 base_class.append_signature (st)
162 manus 9655 end
163 grator 552
164 grator 605 dump (file: FILE) is
165 grator 1323 local
166     s: STRING
167 grator 18 do
168     if is_expanded then
169 manus 9655 file.putstring ("expanded ")
170 xavierl 4623 elseif is_separate then
171 manus 9655 file.putstring ("separate ")
172     end
173     s := clone (base_class.name)
174     s.to_upper
175     file.putstring (s)
176     end
177 grator 18
178 michaels 7681 has_associated_class_type: BOOLEAN is
179     -- Has `Current' an associated class type?
180     do
181     if is_expanded then
182     is_expanded := false
183 manus 10183 Result := base_class.types.has_type (Current)
184 michaels 7681 is_expanded := true
185     elseif is_separate then
186     is_separate := false
187 manus 10183 Result := base_class.types.has_type (Current)
188 michaels 7681 is_separate := true
189     else
190 manus 10183 Result := base_class.types.has_type (Current)
191 michaels 7681 end
192     end
193    
194 grator 18 associated_class_type: CLASS_TYPE is
195     -- Associated class type
196 michaels 7681 require
197     has: has_associated_class_type
198 grator 18 local
199 manus 9655 types: TYPE_LIST
200 grator 485 do
201     if is_expanded then
202     Result := associated_expanded_class_type
203 xavierl 4623 elseif is_separate then
204     Result := associated_separate_class_type
205 grator 485 else
206 manus 10196 Result := base_class.types.conservative_search_item (Current)
207 manus 9655 end
208     end
209 grator 18
210     associated_expanded_class_type: CLASS_TYPE is
211     -- Associated expanded class type
212     require
213     is_expanded: is_expanded
214 michaels 7681 has: has_associated_class_type
215 grator 18 do
216 manus 9655 is_expanded := false
217     Result := associated_class_type
218     is_expanded := true
219     end
220 grator 18
221 xavierl 4623 associated_separate_class_type: CLASS_TYPE is
222     -- Associated separate class type
223     require
224     is_separate: is_separate
225 michaels 7681 has: has_associated_class_type
226 xavierl 4623 do
227 manus 9655 is_separate := false
228     Result := associated_class_type
229     is_separate := true
230     end
231 xavierl 4623
232 grator 18 type_id: INTEGER is
233     -- Type id of the correponding class type
234     do
235 manus 9655 Result := associated_class_type.type_id
236     end
237 grator 18
238     expanded_type_id: INTEGER is
239     -- Type id of the corresponding expanded class type
240     do
241     Result := associated_expanded_class_type.type_id
242 manus 9655 end
243 grator 18
244 grator 621 generate_cecil_value (file: INDENT_FILE) is
245 grator 18 -- Generate cecil value
246     do
247 xavierl 4623 -- FIXME????: separate
248 grator 18 if not is_expanded then
249 manus 9655 file.putstring ("SK_DTYPE")
250 grator 18 else
251 manus 9655 file.putstring ("SK_EXP + (uint32) ")
252     file.putint (base_id.id)
253     end
254     end
255 grator 18
256     hash_code: INTEGER is
257     -- Hash code for current type
258     do
259 ericb 3652 Result := Other_code + base_id.hash_code
260 manus 9655 end
261 grator 18
262     sk_value: INTEGER is
263     -- Generate SK value associated to the current type.
264     do
265 xavierl 4623 -- FIXME????: separate
266 grator 18 if not is_expanded then
267 manus 9655 Result := Sk_ref + (type_id - 1)
268 grator 18 else
269 manus 9655 is_expanded := False
270     Result := Sk_exp + (type_id - 1)
271     is_expanded := True
272     end
273     end
274 grator 18
275 grator 508 cecil_value: INTEGER is
276     do
277 xavierl 4623 -- FIXME????: separate
278 grator 508 if not is_expanded then
279     Result := Sk_dtype
280     else
281 ericb 3652 Result := Sk_exp + base_id.id
282 manus 9655 end
283     end
284 grator 508
285 grator 930 feature -- Array optimization
286    
287     conforms_to_array: BOOLEAN is
288     do
289     Result := base_class.conform_to (array_class_c)
290 manus 9655 end
291 grator 930
292     feature {NONE} -- Array optimization
293    
294     array_class_c: CLASS_C is
295     once
296     Result := System.array_class.compiled_class
297 manus 9655 end
298 grator 930
299 grator 1204 feature
300    
301     type_a: CL_TYPE_A is
302     do
303     !!Result
304 manus 9655 Result.set_is_expanded (is_expanded)
305     Result.set_is_separate (is_separate)
306 ericb 3652 Result.set_base_class_id (base_id)
307 grator 1204 end
308    
309 manus 10818 feature -- Generic conformance
310    
311     generated_id (final_mode : BOOLEAN) : INTEGER is
312     do
313     if has_associated_class_type then
314     if final_mode then
315     Result := type_id - 1
316     else
317     Result := associated_class_type.id.id-1
318     end
319    
320     if is_expanded then
321     Result := -256 - Result
322     end
323     else
324     Result := -10 -- Invalid - should never happen
325     end
326     end
327    
328 manus 10890 gen_type_string (final_mode, use_info : BOOLEAN) : STRING is
329 manus 10818 do
330     !!Result.make (0)
331 manus 10890
332     if use_info and then (cr_info /= Void) then
333     -- It's an ancored type
334     Result.append (cr_info.gen_type_string (final_mode))
335     end
336 manus 10818 Result.append_integer (generated_id (final_mode))
337     Result.append (", ")
338     end
339    
340 manus 10890 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
341 manus 10818 do
342 manus 10890 if use_info and then (cr_info /= Void) then
343     -- It's an ancored type
344     cr_info.make_gen_type_byte_code (ba)
345     end
346 manus 10818 ba.append_short_integer (generated_id (False))
347     end
348    
349 grator 18 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23