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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23