/[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 10818 - (hide annotations)
Thu Jul 30 20:33:23 1998 UTC (21 years, 6 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 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 grator 18 same_as,
13     c_type,
14 grator 930 instantiation_in,
15 manus 10818 complete_instantiation_in,
16     conforms_to_array,
17     generated_id,
18     gen_type_string,
19     make_gen_type_byte_code
20 grator 18 end
21    
22     feature
23    
24 manus 9655 base_id: CLASS_ID
25 grator 18 -- Base class id of the type class
26    
27 manus 9655 is_expanded: BOOLEAN
28 manus 8805 -- Is the type expanded?
29 grator 18
30 manus 9655 is_separate: BOOLEAN
31 manus 8805 -- Is the type separate?
32 xavierl 4623
33 ericb 3652 set_base_id (c: CLASS_ID) is
34 grator 18 -- Assign `c' to `base_id'.
35     do
36 manus 9655 base_id := c
37     end
38 grator 18
39     set_is_expanded (b: BOOLEAN) is
40     -- Assign `b' to `is_expanded'.
41     do
42 manus 9655 is_expanded := b
43     end
44 grator 18
45 xavierl 4623 set_is_separate (b: BOOLEAN) is
46     -- Assign `b' to `is_separate'.
47     do
48 manus 9655 is_separate := b
49     end
50 xavierl 4623
51 grator 18 meta_generic: META_GENERIC is
52     -- Meta generic array describing the type class
53     do
54     -- No meta generic in non-generic type
55 manus 9655 end
56 grator 18
57 manus 10818 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 grator 18 base_class: CLASS_C is
64     -- Base class associated to the class type
65     do
66 manus 9655 Result := System.class_of_id (base_id)
67     end
68 grator 18
69 grator 236 is_valid: BOOLEAN is
70     -- Is the base class still in the system ?
71     do
72 manus 9655 Result := base_class /= Void
73     end
74 grator 236
75 grator 18 is_reference: BOOLEAN is
76     -- Is the type a reference type ?
77     do
78 manus 9655 Result := not is_expanded
79 grator 18 end;
80    
81     same_as (other: TYPE_I): BOOLEAN is
82     -- Is `other' equal to Current ?
83     local
84 manus 9655 other_cl_type: CL_TYPE_I
85 grator 18 do
86 manus 9655 other_cl_type ?= other
87 manus 8805 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 manus 10818 and then other_cl_type.true_generics = Void
93 manus 9655 end
94 grator 18
95     instantiation_in (other: GEN_TYPE_I): CL_TYPE_I is
96     -- Instantiation of Current in context of `other'
97 grator 282 require else
98     True
99 grator 18 do
100 manus 9655 Result := Current
101     end
102 grator 18
103 manus 10818 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 grator 18 description: ATTR_DESC is
112     -- Type description for skeletons
113     local
114 michaels 7681 exp: EXPANDED_DESC
115     ref: REFERENCE_DESC
116 grator 485 do
117 grator 18 if is_expanded then
118 manus 10140 !! exp
119 manus 9655 is_expanded := False
120 manus 10196 exp.set_class_type (base_class.types.conservative_search_item (Current))
121 manus 9655 is_expanded := True
122     Result := exp
123 xavierl 4623 elseif is_separate then
124     -- FIXME
125     Result := c_type.description
126 grator 18 else
127 manus 9655 Result := c_type.description
128     end
129 michaels 7681
130     ref ?= Result
131     if ref /= Void then
132     ref.set_class_type_i (Current)
133     end
134 manus 9655 end
135 grator 18
136     c_type: TYPE_C is
137     -- Associated C type
138     do
139 manus 9655 Result := Reference_c_type
140     end
141 grator 18
142 guusl 3636 append_signature (st: STRUCTURED_TEXT) is
143 grator 552 do
144     if is_expanded then
145 manus 9655 st.add_string ("expanded ")
146 xavierl 4623 elseif is_separate then
147 manus 9655 st.add_string ("separate ")
148     end
149 dinov 6562 base_class.append_signature (st)
150 manus 9655 end
151 grator 552
152 grator 605 dump (file: FILE) is
153 grator 1323 local
154     s: STRING
155 grator 18 do
156     if is_expanded then
157 manus 9655 file.putstring ("expanded ")
158 xavierl 4623 elseif is_separate then
159 manus 9655 file.putstring ("separate ")
160     end
161     s := clone (base_class.name)
162     s.to_upper
163     file.putstring (s)
164     end
165 grator 18
166 michaels 7681 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 manus 10183 Result := base_class.types.has_type (Current)
172 michaels 7681 is_expanded := true
173     elseif is_separate then
174     is_separate := false
175 manus 10183 Result := base_class.types.has_type (Current)
176 michaels 7681 is_separate := true
177     else
178 manus 10183 Result := base_class.types.has_type (Current)
179 michaels 7681 end
180     end
181    
182 grator 18 associated_class_type: CLASS_TYPE is
183     -- Associated class type
184 michaels 7681 require
185     has: has_associated_class_type
186 grator 18 local
187 manus 9655 types: TYPE_LIST
188 grator 485 do
189     if is_expanded then
190     Result := associated_expanded_class_type
191 xavierl 4623 elseif is_separate then
192     Result := associated_separate_class_type
193 grator 485 else
194 manus 10196 Result := base_class.types.conservative_search_item (Current)
195 manus 9655 end
196     end
197 grator 18
198     associated_expanded_class_type: CLASS_TYPE is
199     -- Associated expanded class type
200     require
201     is_expanded: is_expanded
202 michaels 7681 has: has_associated_class_type
203 grator 18 do
204 manus 9655 is_expanded := false
205     Result := associated_class_type
206     is_expanded := true
207     end
208 grator 18
209 xavierl 4623 associated_separate_class_type: CLASS_TYPE is
210     -- Associated separate class type
211     require
212     is_separate: is_separate
213 michaels 7681 has: has_associated_class_type
214 xavierl 4623 do
215 manus 9655 is_separate := false
216     Result := associated_class_type
217     is_separate := true
218     end
219 xavierl 4623
220 grator 18 type_id: INTEGER is
221     -- Type id of the correponding class type
222     do
223 manus 9655 Result := associated_class_type.type_id
224     end
225 grator 18
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 manus 9655 end
231 grator 18
232 grator 621 generate_cecil_value (file: INDENT_FILE) is
233 grator 18 -- Generate cecil value
234     do
235 xavierl 4623 -- FIXME????: separate
236 grator 18 if not is_expanded then
237 manus 9655 file.putstring ("SK_DTYPE")
238 grator 18 else
239 manus 9655 file.putstring ("SK_EXP + (uint32) ")
240     file.putint (base_id.id)
241     end
242     end
243 grator 18
244     hash_code: INTEGER is
245     -- Hash code for current type
246     do
247 ericb 3652 Result := Other_code + base_id.hash_code
248 manus 9655 end
249 grator 18
250     sk_value: INTEGER is
251     -- Generate SK value associated to the current type.
252     do
253 xavierl 4623 -- FIXME????: separate
254 grator 18 if not is_expanded then
255 manus 9655 Result := Sk_ref + (type_id - 1)
256 grator 18 else
257 manus 9655 is_expanded := False
258     Result := Sk_exp + (type_id - 1)
259     is_expanded := True
260     end
261     end
262 grator 18
263 grator 508 cecil_value: INTEGER is
264     do
265 xavierl 4623 -- FIXME????: separate
266 grator 508 if not is_expanded then
267     Result := Sk_dtype
268     else
269 ericb 3652 Result := Sk_exp + base_id.id
270 manus 9655 end
271     end
272 grator 508
273 grator 930 feature -- Array optimization
274    
275     conforms_to_array: BOOLEAN is
276     do
277     Result := base_class.conform_to (array_class_c)
278 manus 9655 end
279 grator 930
280     feature {NONE} -- Array optimization
281    
282     array_class_c: CLASS_C is
283     once
284     Result := System.array_class.compiled_class
285 manus 9655 end
286 grator 930
287 grator 1204 feature
288    
289     type_a: CL_TYPE_A is
290     do
291     !!Result
292 manus 9655 Result.set_is_expanded (is_expanded)
293     Result.set_is_separate (is_separate)
294 ericb 3652 Result.set_base_class_id (base_id)
295 grator 1204 end
296    
297 manus 10818 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 grator 18 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23