/[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 14013 - (show annotations)
Wed Apr 14 19:02:53 1999 UTC (20 years, 10 months ago) by manus
Original Path: trunk/Src/bench/Eiffel/eiffel/genericity/cl_type_i.e
File size: 7934 byte(s)
Fixed a C-ANSI generation problem with generic conformance.
Previously we were generating something like:
	int16 typearr[] ={4,5,Dtype(l[0]),5,-1};
However, this is not accepted by most of the C ANSI compiler (mostly on
Unix platforms). Now, we fix this problem and are generating the following
code:
	int16 typearr[] ={4,5,0,5,-1};
	typearr[2]=Dtype(l[0]);
which is C ANSI.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23