/[eiffelstudio]/branches/CAT_mono/Src/Eiffel/eiffel/genericity/cl_type_i.e
ViewVC logotype

Contents of /branches/CAT_mono/Src/Eiffel/eiffel/genericity/cl_type_i.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11209 - (show annotations)
Thu Sep 3 23:27:31 1998 UTC (21 years, 5 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 7012 byte(s)
Fixed for generic conformance.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23