/[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 10818 - (show annotations)
Thu Jul 30 20:33:23 1998 UTC (21 years, 7 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 6648 byte(s)
Add the generic conformance to the compiler

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 true_generics : ARRAY [TYPE_I] is
58 -- Array of generics: no mapping reference -> REFERENCE_I
59 do
60 -- Non generic types don't have them
61 end
62
63 base_class: CLASS_C is
64 -- Base class associated to the class type
65 do
66 Result := System.class_of_id (base_id)
67 end
68
69 is_valid: BOOLEAN is
70 -- Is the base class still in the system ?
71 do
72 Result := base_class /= Void
73 end
74
75 is_reference: BOOLEAN is
76 -- Is the type a reference type ?
77 do
78 Result := not is_expanded
79 end;
80
81 same_as (other: TYPE_I): BOOLEAN is
82 -- Is `other' equal to Current ?
83 local
84 other_cl_type: CL_TYPE_I
85 do
86 other_cl_type ?= other
87 Result := other_cl_type /= Void -- FIXME
88 and then equal (other_cl_type.base_id, base_id)
89 and then other_cl_type.is_expanded = is_expanded
90 and then other_cl_type.is_separate = is_separate
91 and then other_cl_type.meta_generic = Void
92 and then other_cl_type.true_generics = Void
93 end
94
95 instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
96 -- Instantiation of Current in context of `other'
97 require else
98 True
99 do
100 Result := Current
101 end
102
103 complete_instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
104 -- Instantiation of Current in context of `other'
105 require else
106 True
107 do
108 Result := Current
109 end
110
111 description: ATTR_DESC is
112 -- Type description for skeletons
113 local
114 exp: EXPANDED_DESC
115 ref: REFERENCE_DESC
116 do
117 if is_expanded then
118 !! exp
119 is_expanded := False
120 exp.set_class_type (base_class.types.conservative_search_item (Current))
121 is_expanded := True
122 Result := exp
123 elseif is_separate then
124 -- FIXME
125 Result := c_type.description
126 else
127 Result := c_type.description
128 end
129
130 ref ?= Result
131 if ref /= Void then
132 ref.set_class_type_i (Current)
133 end
134 end
135
136 c_type: TYPE_C is
137 -- Associated C type
138 do
139 Result := Reference_c_type
140 end
141
142 append_signature (st: STRUCTURED_TEXT) is
143 do
144 if is_expanded then
145 st.add_string ("expanded ")
146 elseif is_separate then
147 st.add_string ("separate ")
148 end
149 base_class.append_signature (st)
150 end
151
152 dump (file: FILE) is
153 local
154 s: STRING
155 do
156 if is_expanded then
157 file.putstring ("expanded ")
158 elseif is_separate then
159 file.putstring ("separate ")
160 end
161 s := clone (base_class.name)
162 s.to_upper
163 file.putstring (s)
164 end
165
166 has_associated_class_type: BOOLEAN is
167 -- Has `Current' an associated class type?
168 do
169 if is_expanded then
170 is_expanded := false
171 Result := base_class.types.has_type (Current)
172 is_expanded := true
173 elseif is_separate then
174 is_separate := false
175 Result := base_class.types.has_type (Current)
176 is_separate := true
177 else
178 Result := base_class.types.has_type (Current)
179 end
180 end
181
182 associated_class_type: CLASS_TYPE is
183 -- Associated class type
184 require
185 has: has_associated_class_type
186 local
187 types: TYPE_LIST
188 do
189 if is_expanded then
190 Result := associated_expanded_class_type
191 elseif is_separate then
192 Result := associated_separate_class_type
193 else
194 Result := base_class.types.conservative_search_item (Current)
195 end
196 end
197
198 associated_expanded_class_type: CLASS_TYPE is
199 -- Associated expanded class type
200 require
201 is_expanded: is_expanded
202 has: has_associated_class_type
203 do
204 is_expanded := false
205 Result := associated_class_type
206 is_expanded := true
207 end
208
209 associated_separate_class_type: CLASS_TYPE is
210 -- Associated separate class type
211 require
212 is_separate: is_separate
213 has: has_associated_class_type
214 do
215 is_separate := false
216 Result := associated_class_type
217 is_separate := true
218 end
219
220 type_id: INTEGER is
221 -- Type id of the correponding class type
222 do
223 Result := associated_class_type.type_id
224 end
225
226 expanded_type_id: INTEGER is
227 -- Type id of the corresponding expanded class type
228 do
229 Result := associated_expanded_class_type.type_id
230 end
231
232 generate_cecil_value (file: INDENT_FILE) is
233 -- Generate cecil value
234 do
235 -- FIXME????: separate
236 if not is_expanded then
237 file.putstring ("SK_DTYPE")
238 else
239 file.putstring ("SK_EXP + (uint32) ")
240 file.putint (base_id.id)
241 end
242 end
243
244 hash_code: INTEGER is
245 -- Hash code for current type
246 do
247 Result := Other_code + base_id.hash_code
248 end
249
250 sk_value: INTEGER is
251 -- Generate SK value associated to the current type.
252 do
253 -- FIXME????: separate
254 if not is_expanded then
255 Result := Sk_ref + (type_id - 1)
256 else
257 is_expanded := False
258 Result := Sk_exp + (type_id - 1)
259 is_expanded := True
260 end
261 end
262
263 cecil_value: INTEGER is
264 do
265 -- FIXME????: separate
266 if not is_expanded then
267 Result := Sk_dtype
268 else
269 Result := Sk_exp + base_id.id
270 end
271 end
272
273 feature -- Array optimization
274
275 conforms_to_array: BOOLEAN is
276 do
277 Result := base_class.conform_to (array_class_c)
278 end
279
280 feature {NONE} -- Array optimization
281
282 array_class_c: CLASS_C is
283 once
284 Result := System.array_class.compiled_class
285 end
286
287 feature
288
289 type_a: CL_TYPE_A is
290 do
291 !!Result
292 Result.set_is_expanded (is_expanded)
293 Result.set_is_separate (is_separate)
294 Result.set_base_class_id (base_id)
295 end
296
297 feature -- Generic conformance
298
299 generated_id (final_mode : BOOLEAN) : INTEGER is
300
301 do
302 if has_associated_class_type then
303 if final_mode then
304 Result := type_id - 1
305 else
306 Result := associated_class_type.id.id-1
307 end
308
309 if is_expanded then
310 Result := -256 - Result
311 end
312 else
313 Result := -10 -- Invalid - should never happen
314 end
315 end
316
317 gen_type_string (final_mode : BOOLEAN) : STRING is
318
319 do
320 !!Result.make (0)
321 Result.append_integer (generated_id (final_mode))
322 Result.append (", ")
323 end
324
325 make_gen_type_byte_code (ba : BYTE_ARRAY) is
326
327 do
328 ba.append_short_integer (generated_id (False))
329 end
330
331 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23