/[eiffelstudio]/branches/eth/eve/Src/Eiffel/API/evaluated_type/qualified_anchored_type_a.e
ViewVC logotype

Contents of /branches/eth/eve/Src/Eiffel/API/evaluated_type/qualified_anchored_type_a.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 94556 - (show annotations)
Fri Feb 28 09:44:00 2014 UTC (5 years, 9 months ago) by jasonw
File size: 14163 byte(s)
<<Merged from trunk#94547.>>
1 note
2 description: "Class for an staticed type on a feature."
3 legal: "See notice at end of class."
4 status: "See notice at end of class."
5 date: "$Date$"
6 revision: "$Revision$"
7
8 class
9 QUALIFIED_ANCHORED_TYPE_A
10
11 inherit
12 LIKE_TYPE_A
13 redefine
14 description, description_with_detachable_type,
15 dispatch_anchors,
16 error_generics,
17 evaluated_type_in_descendant,
18 good_generics, internal_is_valid_for_class,
19 has_formal_generic,
20 has_like,
21 initialize_info,
22 formal_instantiated_in,
23 formal_instantiation_in,
24 instantiated_in,
25 instantiation_in,
26 is_explicit,
27 is_loose,
28 is_syntactically_equal,
29 skeleton_adapted_in,
30 update_dependance
31 end
32
33 SHARED_NAMES_HEAP
34 export
35 {NONE} all
36 end
37
38 create
39 make
40
41 feature {NONE} -- Initialization and reinitialization
42
43 make (q: like qualifier; c: like chain; w: like class_id)
44 -- Create descriptor with qualifier `q' and feature names `c' written in class `w'.
45 require
46 q_attached: attached q
47 c_attached: attached c
48 c_not_empty: c.count > 0
49 valid_w: system.classes.has (w)
50 do
51 qualifier := q
52 chain := c
53 class_id := w
54 ensure
55 qualifier_set: qualifier = q
56 chain_set: chain = c
57 class_id_set: class_id = w
58 end
59
60 feature -- Visitor
61
62 process (v: TYPE_A_VISITOR)
63 -- Process current element.
64 do
65 v.process_qualified_anchored_type_a (Current)
66 end
67
68 feature -- Properties
69
70 qualifier: TYPE_A
71 -- First part of the type, before the feature `chain'
72
73
74 chain: SPECIAL [INTEGER_32]
75 -- Feature name IDs of the second part of the type, after the `qualifier'
76
77 class_id: INTEGER
78 -- ID of a class where this type is written
79
80 feature {TYPE_A_CHECKER} -- Properties
81
82 routine_id: SPECIAL [INTEGER_32]
83 -- Routine IDs of the second part of the type, after the `qualifier'
84
85 feature -- Status Report
86
87 is_loose: BOOLEAN
88 -- <Precursor>
89 do
90 -- If qualifier type depends on the actual type of the object,
91 -- qualified anchored type depends on the dynamic type,
92 -- otherwise it is stand-alone.
93 Result := qualifier.is_loose
94 end
95
96 is_explicit: BOOLEAN
97 -- Is type fixed at compile time without anchors or formals?
98 do
99 if system.in_final_mode then
100 initialize_info (shared_create_info)
101 Result := shared_create_info.is_explicit
102 else
103 Result := False
104 end
105 end
106
107 has_formal_generic: BOOLEAN
108 -- <Precursor>
109 do
110 Result := qualifier.has_formal_generic
111 end
112
113 has_like: BOOLEAN
114 -- <Precursor>
115 do
116 Result := qualifier.has_like
117 end
118
119 feature -- Comparison
120
121 same_as (other: TYPE_A): BOOLEAN
122 -- Is the current type the same as `other' ?
123 do
124 if
125 attached {QUALIFIED_ANCHORED_TYPE_A} other as o and then
126 qualifier.same_as (o.qualifier) and then
127 chain ~ o.chain and then
128 has_same_marks (o)
129 then
130 -- Compare computed actual types as otherwise they may be left
131 -- from the previous compilation in an invalid state.
132 if attached actual_type as a then
133 Result :=
134 is_valid and then
135 o.is_valid and then
136 attached o.actual_type as oa and then
137 a.same_as (oa)
138 else
139 Result := not attached o.actual_type
140 end
141 end
142 end
143
144 feature -- Code generation
145
146 description: ATTR_DESC
147 -- Descritpion of type for skeletons.
148 local
149 gen_desc: GENERIC_DESC
150 do
151 if qualifier.is_loose then
152 create gen_desc
153 gen_desc.set_type_i (Current)
154 Result := gen_desc
155 else
156 Result := Precursor
157 end
158 end
159
160 description_with_detachable_type: ATTR_DESC
161 -- Descritpion of type for skeletons.
162 local
163 gen_desc: GENERIC_DESC
164 do
165 if qualifier.is_loose then
166 create gen_desc
167 gen_desc.set_type_i (as_detachable_type)
168 Result := gen_desc
169 else
170 Result := Precursor
171 end
172 end
173
174 skeleton_adapted_in (class_type: CLASS_TYPE): QUALIFIED_ANCHORED_TYPE_A
175 -- <Precursor>
176 local
177 q: TYPE_A
178 do
179 Result := Current
180 q := qualifier.skeleton_adapted_in (class_type)
181 if q /= qualifier then
182 Result := duplicate
183 Result.set_qualifier (q)
184 end
185 end
186
187 feature -- Type checking
188
189 good_generics: BOOLEAN
190 -- <Precursor>
191 do
192 Result := qualifier.good_generics and then Precursor
193 end
194
195 error_generics: VTUG
196 -- <Precursor>
197 do
198 if qualifier.good_generics then
199 Result := Precursor
200 else
201 Result := qualifier.error_generics
202 end
203 end
204
205 update_dependance (feat_depend: FEATURE_DEPENDANCE)
206 -- Update dependency for Dead Code Removal
207 local
208 c: CLASS_C
209 f: FEATURE_I
210 i: INTEGER
211 do
212 qualifier.update_dependance (feat_depend)
213 from
214 c := qualifier.base_class
215 until
216 i >= chain.count
217 loop
218 if attached c then
219 f := c.feature_table.item_id (chain [i])
220 if attached f then
221 feat_depend.extend_depend_unit_with_level (c.class_id, f, 0)
222 c := f.type.base_class
223 end
224 end
225 i := i + 1
226 end
227 end
228
229 feature {TYPE_A} -- Helpers
230
231 internal_is_valid_for_class (a_class: CLASS_C): BOOLEAN
232 -- Is current type valid?
233 do
234 Result := attached qualifier as l_qualifier and then l_qualifier.internal_is_valid_for_class (a_class) and then Precursor (a_class)
235 end
236
237 feature -- Modification
238
239 set_qualifier (q: like qualifier)
240 -- Set `qualifier' to `q'.
241 require
242 q_attached: attached q
243 do
244 qualifier := q
245 ensure
246 qualifier_set: qualifier = q
247 end
248
249 feature {TYPE_A_CHECKER, QUALIFIED_ANCHORED_TYPE_A} -- Modification
250
251 set_chain (n: like chain; c: CLASS_C)
252 -- Set `chain' to the value relative to class `c'.
253 require
254 n_attached: attached n
255 n_same_count: n.count = chain.count
256 c_attached: attached c
257 do
258 chain := n
259 class_id := c.class_id
260 ensure
261 chain_set: chain = n
262 class_id_set: class_id = c.class_id
263 end
264
265 feature {TYPE_A_CHECKER, QUALIFIED_ANCHORED_TYPE_A} -- Modification
266
267 set_routine_id (r: like routine_id)
268 -- Set `routine_id' to `r'.
269 require
270 r_attached: attached r
271 r_same_count: r.count = chain.count
272 do
273 routine_id := r
274 ensure
275 routine_id_set: routine_id = r
276 end
277
278 feature -- Generic conformance
279
280 initialize_info (an_info: like shared_create_info)
281 do
282 an_info.make (Current, system.class_of_id (class_id))
283 end
284
285 shared_create_info, create_info: CREATE_QUALIFIED
286 -- <Precursor>
287 do
288 --| Unlike its precursor, we cannot use a shared structure because unlike traditional
289 --| anchors, qualified anchors can be nested, therefore we cannot reuse the same object
290 --| as its value would be overridden while processing the nested definitions.
291 --| See eweasel test#anchor042 and test#anchor051 for test cases.
292 create Result.make (Current, system.class_of_id (class_id))
293 end
294
295 feature -- IL code generation
296
297 dispatch_anchors (a_context_class: CLASS_C)
298 -- <Precursor>
299 local
300 c: detachable CLASS_C
301 i: INTEGER
302 l_rid: INTEGER
303 do
304 qualifier.dispatch_anchors (a_context_class)
305 from
306 until
307 i >= routine_id.count
308 loop
309 l_rid := routine_id [i]
310 c := system.class_of_id (system.rout_info_table.item (l_rid).origin)
311 if c /= Void then
312 c.extend_type_set (l_rid)
313 end
314 i := i + 1
315 end
316 end
317
318 feature -- Output
319
320 dump: STRING
321 -- Dumped trace
322 local
323 s: STRING
324 i, nb: INTEGER
325 do
326 s := actual_type.dump
327 create Result.make (20 + s.count)
328 Result.append_character ('[')
329 dump_marks (Result)
330 Result.append ("like {")
331 Result.append (qualifier.dump)
332 Result.append ("}")
333 from
334 i := 0
335 nb := chain.count
336 until
337 i = nb
338 loop
339 Result.append_character ('.')
340 Result.append_string (names_heap.item (chain.item (i)))
341 i := i + 1
342 end
343 Result.append ("] ")
344 Result.append (s)
345 end
346
347 ext_append_to (a_text_formatter: TEXT_FORMATTER; a_context_class: CLASS_C)
348 -- <Precursor>
349 local
350 q: detachable CLASS_C
351 i: INTEGER
352 n: STRING
353 f: detachable E_FEATURE
354 do
355 a_text_formatter.process_symbol_text ({SHARED_TEXT_ITEMS}.ti_l_bracket)
356 ext_append_marks (a_text_formatter)
357 a_text_formatter.process_keyword_text ({SHARED_TEXT_ITEMS}.ti_like_keyword, Void)
358 a_text_formatter.add_space
359 a_text_formatter.process_symbol_text ({SHARED_TEXT_ITEMS}.ti_l_curly)
360 qualifier.ext_append_to (a_text_formatter, a_context_class)
361 a_text_formatter.process_symbol_text ({SHARED_TEXT_ITEMS}.ti_r_curly)
362 from
363 q := qualifier.base_class
364 until
365 i >= chain.count
366 loop
367 a_text_formatter.process_symbol_text ({SHARED_TEXT_ITEMS}.ti_dot)
368 if attached q and then q.has_feature_table then
369 f := q.feature_with_name_id (chain [i])
370 else
371 f := Void
372 end
373 n := names_heap.item (chain [i])
374 if attached f then
375 a_text_formatter.add_feature (f, n)
376 elseif attached q then
377 a_text_formatter.add_feature_name (n, q)
378 else
379 a_text_formatter.process_feature_name_text (n, Void)
380 end
381 i := i + 1
382 end
383 a_text_formatter.process_symbol_text ({SHARED_TEXT_ITEMS}.ti_r_bracket)
384 a_text_formatter.add_space
385 if is_valid then
386 actual_type.ext_append_to (a_text_formatter, a_context_class)
387 end
388 end
389
390 feature -- Primitives
391
392 formal_instantiated_in (class_type: TYPE_A): TYPE_A
393 -- <Precursor>
394 local
395 t: like Current
396 do
397 t := twin
398 t.set_actual_type (actual_type.formal_instantiated_in (class_type).actual_type)
399 t.set_qualifier (qualifier.formal_instantiated_in (class_type))
400 Result := t
401 end
402
403 instantiated_in (class_type: TYPE_A): TYPE_A
404 -- <Precursor>
405 local
406 t: like Current
407 do
408 t := twin
409 t.set_actual_type (actual_type.instantiated_in (class_type).actual_type)
410 t.set_qualifier (qualifier.instantiated_in (class_type))
411 Result := t
412 end
413
414 formal_instantiation_in (type: TYPE_A; constraint: TYPE_A; written_id: INTEGER): QUALIFIED_ANCHORED_TYPE_A
415 -- <Precursor>
416 do
417 Result := recompute (qualifier.formal_instantiation_in (type, constraint, written_id), written_id)
418 end
419
420 instantiation_in (type: TYPE_A; written_id: INTEGER): TYPE_A
421 -- <Precursor>
422 local
423 t: like Current
424 do
425 t := twin
426 t.set_actual_type (actual_type.instantiation_in (type, written_id))
427 t.set_qualifier (qualifier.instantiation_in (type, written_id))
428 Result := t
429 end
430
431 evaluated_type_in_descendant (a_ancestor, a_descendant: CLASS_C; a_feature: FEATURE_I): QUALIFIED_ANCHORED_TYPE_A
432 -- <Precursor>
433 do
434 if a_ancestor /= a_descendant then
435 Result := recompute (qualifier.evaluated_type_in_descendant (a_ancestor, a_descendant, a_feature), a_descendant.class_id)
436 else
437 Result := Current
438 end
439 end
440
441 feature {NONE} -- Recomputation in a different context
442
443 recompute (new_qualifier: TYPE_A; new_class_id: like class_id): QUALIFIED_ANCHORED_TYPE_A
444 -- Recompute the complete type starting from a new qualifier `new_qualifier' in a new class with `new_class_id'.
445 local
446 c: like chain
447 q: TYPE_A
448 i, n: like chain.count
449 w: CLASS_C
450 do
451 if new_qualifier.same_as (qualifier) and then new_class_id = class_id then
452 -- Same context.
453 Result := Current
454 else
455 -- Compute new feature names.
456 from
457 c := chain
458 q := new_qualifier
459 -- Make a copy of the original qualified anchored type with the new qualifier and class ID.
460 create Result.make (q, c, new_class_id)
461 Result.set_routine_id (routine_id)
462 -- Then traverse the feature chain and update it in the `Result' if required.
463 w := system.class_of_id (new_class_id)
464 n := c.count
465 until
466 i >= n
467 loop
468 -- Find a corresponding feature in the written type.
469 feature_finder.find_by_routine_id (routine_id [i], q, w)
470 check
471 is_feature_found: attached feature_finder.found_feature as f
472 then
473 if f.feature_name_id /= c [i] then
474 -- New feature name is used.
475 if c = chain then
476 -- Duplicate chain.
477 c := chain.twin
478 Result.set_chain (c, w)
479 end
480 c [i] := f.feature_name_id
481 end
482 q := f.type.instantiated_in (q)
483 end
484 i := i + 1
485 end
486 -- It's possible that `q' is an anchored type.
487 -- Its actual type should be used to set the actual type of the result.
488 Result.set_actual_type (q.actual_type)
489 Result.set_marks_from (Current)
490 end
491 end
492
493 feature -- Comparison
494
495 is_equivalent (other: like Current): BOOLEAN
496 -- Is `other' equivalent to the current object ?
497 do
498 Result :=
499 equivalent (qualifier, other.qualifier) and then
500 chain ~ other.chain and then
501 has_same_marks (other)
502 end
503
504 is_syntactically_equal (other: TYPE_A): BOOLEAN
505 -- <Precursor>
506 do
507 if attached {like Current} other then
508 Result := same_as (other)
509 elseif attached {UNEVALUATED_QUALIFIED_ANCHORED_TYPE} other as o then
510 Result :=
511 qualifier.is_syntactically_equal (o.qualifier) and then
512 chain ~ o.chain and then
513 has_same_marks (o)
514 end
515 end
516
517 feature {NONE} -- Lookup
518
519 feature_finder: TYPE_A_FEATURE_FINDER
520 -- Lookup facility
521 once
522 create Result
523 ensure
524 feature_finder_attached: Result /= Void
525 end
526
527 note
528 copyright: "Copyright (c) 1984-2014, Eiffel Software"
529 license: "GPL version 2 (see http://www.eiffel.com/licensing/gpl.txt)"
530 licensing_options: "http://www.eiffel.com/licensing"
531 copying: "[
532 This file is part of Eiffel Software's Eiffel Development Environment.
533
534 Eiffel Software's Eiffel Development Environment is free
535 software; you can redistribute it and/or modify it under
536 the terms of the GNU General Public License as published
537 by the Free Software Foundation, version 2 of the License
538 (available at the URL listed under "license" above).
539
540 Eiffel Software's Eiffel Development Environment is
541 distributed in the hope that it will be useful, but
542 WITHOUT ANY WARRANTY; without even the implied warranty
543 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
544 See the GNU General Public License for more details.
545
546 You should have received a copy of the GNU General Public
547 License along with Eiffel Software's Eiffel Development
548 Environment; if not, write to the Free Software Foundation,
549 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
550 ]"
551 source: "[
552 Eiffel Software
553 5949 Hollister Ave., Goleta, CA 93117 USA
554 Telephone 805-685-1006, Fax 805-685-6869
555 Website http://www.eiffel.com
556 Customer support http://support.eiffel.com
557 ]"
558
559 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23