/[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 11298 - (show annotations)
Sun Sep 13 20:40:22 1998 UTC (21 years, 5 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 6964 byte(s)
Improved the conformance of generic by writing in a file instead of creating a STRING.
Fixed one bug related to the use of `has_associated_class_type' in CL_TYPE_I.
Fixed one bug related to a bad generation of C code and the GC

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23