/[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 13232 - (show annotations)
Fri Feb 5 03:57:18 1999 UTC (21 years ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 7054 byte(s)
Fixed some problems related to the use of expanded types in generic parameter or with
simple expanded types:
- Fixed the byte code generation
- Changed the skeleton to handle correctly expanded type as a generic parameter
- Changed the attribute description to match the new skeleton
- Propagation of the expanded information (which was not done before, especially
  with inheritance)
- Changed the make routine of the TO_SPECIAL class so that it handles correctly
  an expanded type.

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 exp.set_type_i (Current)
142 Result := exp
143 elseif is_separate then
144 -- FIXME
145 Result := c_type.description
146 else
147 Result := c_type.description
148 end
149
150 ref ?= Result
151 if ref /= Void then
152 ref.set_class_type_i (Current)
153 end
154 end
155
156 c_type: TYPE_C is
157 -- Associated C type
158 do
159 Result := Reference_c_type
160 end
161
162 append_signature (st: STRUCTURED_TEXT) is
163 do
164 if is_expanded then
165 st.add_string ("expanded ")
166 elseif is_separate then
167 st.add_string ("separate ")
168 end
169 base_class.append_signature (st)
170 end
171
172 dump (buffer: GENERATION_BUFFER) is
173 local
174 s: STRING
175 do
176 if is_expanded then
177 buffer.putstring ("expanded ")
178 elseif is_separate then
179 buffer.putstring ("separate ")
180 end
181 s := clone (base_class.name)
182 s.to_upper
183 buffer.putstring (s)
184 end
185
186 has_associated_class_type: BOOLEAN is
187 -- Has `Current' an associated class type?
188 do
189 if is_expanded then
190 is_expanded := False
191 Result := base_class.types.has_type (Current)
192 is_expanded := True
193 elseif is_separate then
194 is_separate := False
195 Result := base_class.types.has_type (Current)
196 is_separate := True
197 else
198 Result := base_class.types.has_type (Current)
199 end
200 end
201
202 associated_class_type: CLASS_TYPE is
203 -- Associated class type
204 require
205 has: has_associated_class_type
206 local
207 types: TYPE_LIST
208 do
209 if is_expanded then
210 is_expanded := False
211 Result := base_class.types.conservative_search_item (Current)
212 is_expanded := True
213 elseif is_separate then
214 is_separate := False
215 Result := base_class.types.conservative_search_item (Current)
216 is_separate := True
217 else
218 Result := base_class.types.conservative_search_item (Current)
219 end
220 end
221
222 type_id: INTEGER is
223 -- Type id of the correponding class type
224 do
225 Result := associated_class_type.type_id
226 end
227
228 expanded_type_id: INTEGER is
229 -- Type id of the corresponding expanded class type
230 do
231 is_expanded := False
232 Result := base_class.types.conservative_search_item (Current).type_id
233 is_expanded := True
234 end
235
236 generate_cecil_value (buffer: GENERATION_BUFFER) is
237 -- Generate cecil value
238 do
239 -- FIXME????: separate
240 if not is_expanded then
241 buffer.putstring ("SK_DTYPE")
242 else
243 buffer.putstring ("SK_EXP + (uint32) ")
244 buffer.putint (base_id.id)
245 end
246 end
247
248 hash_code: INTEGER is
249 -- Hash code for current type
250 do
251 Result := Other_code + base_id.hash_code
252 end
253
254 sk_value: INTEGER is
255 -- Generate SK value associated to the current type.
256 do
257 -- FIXME????: separate
258 if not is_expanded then
259 Result := Sk_ref + (type_id - 1)
260 else
261 is_expanded := False
262 Result := Sk_exp + (type_id - 1)
263 is_expanded := True
264 end
265 end
266
267 cecil_value: INTEGER is
268 do
269 -- FIXME????: separate
270 if not is_expanded then
271 Result := Sk_dtype
272 else
273 Result := Sk_exp + base_id.id
274 end
275 end
276
277 feature -- Array optimization
278
279 conforms_to_array: BOOLEAN is
280 do
281 Result := base_class.conform_to (array_class_c)
282 end
283
284 feature {NONE} -- Array optimization
285
286 array_class_c: CLASS_C is
287 once
288 Result := System.array_class.compiled_class
289 end
290
291 feature
292
293 type_a: CL_TYPE_A is
294 do
295 !!Result
296 Result.set_is_expanded (is_expanded)
297 Result.set_is_separate (is_separate)
298 Result.set_base_class_id (base_id)
299 end
300
301 feature -- Generic conformance
302
303 generated_id (final_mode : BOOLEAN) : INTEGER is
304
305 do
306 if final_mode then
307 Result := type_id - 1
308 else
309 Result := associated_class_type.id.id-1
310 end
311
312 if is_expanded then
313 Result := -256 - Result
314 end
315 end
316
317 generate_cid (buffer : GENERATION_BUFFER; final_mode, use_info : BOOLEAN) is
318
319 do
320 if
321 use_info and then (cr_info /= Void)
322 and then not (is_expanded or is_basic)
323 then
324 -- It's an anchored type
325 cr_info.generate_cid (buffer, final_mode)
326 end
327 buffer.putint (generated_id (final_mode))
328 buffer.putstring (", ")
329 end
330
331 make_gen_type_byte_code (ba : BYTE_ARRAY; use_info : BOOLEAN) is
332 do
333 if
334 use_info and then (cr_info /= Void)
335 and then not (is_expanded or is_basic)
336 then
337 -- It's an anchored type
338 cr_info.make_gen_type_byte_code (ba)
339 end
340 ba.append_short_integer (generated_id (False))
341 end
342
343 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23