/[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 11734 - (hide annotations)
Fri Oct 23 23:59:57 1998 UTC (21 years, 4 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 7025 byte(s)
Cosmetics

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23