/[eiffelstudio]/vendor/gobosoft.com/gobo/4.0d/library/tools/src/eiffel/ast/type/et_class_type.e
ViewVC logotype

Contents of /vendor/gobosoft.com/gobo/4.0d/library/tools/src/eiffel/ast/type/et_class_type.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 98698 - (show annotations)
Mon May 9 13:53:54 2016 UTC (3 years, 5 months ago) by manus
File size: 35758 byte(s)
Update 4.0d version with changes in Gobo from 2016/05/09

1 note
2
3 description:
4
5 "Eiffel class types"
6
7 library: "Gobo Eiffel Tools Library"
8 copyright: "Copyright (c) 1999-2016, Eric Bezault and others"
9 license: "MIT License"
10 date: "$Date$"
11 revision: "$Revision$"
12
13 class ET_CLASS_TYPE
14
15 inherit
16
17 ET_BASE_TYPE
18 redefine
19 actual_parameters,
20 same_syntactical_class_type_with_type_marks,
21 same_named_class_type_with_type_marks,
22 same_base_class_type_with_type_marks,
23 same_as_base_class,
24 conforms_from_class_type_with_type_marks,
25 resolved_formal_parameters_with_type_mark,
26 append_unaliased_to_string,
27 type_with_type_mark,
28 type_mark,
29 overridden_type_mark,
30 reset
31 end
32
33 ET_SHARED_FEATURE_NAME_TESTER
34
35 create
36
37 make,
38 make_generic
39
40 feature {NONE} -- Initialization
41
42 make (a_type_mark: like type_mark; a_name: like name; a_named_base_class: like named_base_class)
43 -- Create a new class type.
44 require
45 a_name_not_void: a_name /= Void
46 a_named_base_class_not_void: a_named_base_class /= Void
47 do
48 type_mark := a_type_mark
49 name := a_name
50 named_base_class := a_named_base_class
51 ensure
52 type_mark_set: type_mark = a_type_mark
53 name_set: name = a_name
54 named_base_class_set: named_base_class = a_named_base_class
55 end
56
57 make_generic (a_type_mark: like type_mark; a_name: like name;
58 a_parameters: attached like actual_parameters; a_named_base_class: like named_base_class)
59 -- Create a new generic class type.
60 require
61 a_name_not_void: a_name /= Void
62 a_parameters_not_void: a_parameters /= Void
63 a_named_base_class_not_void: a_named_base_class /= Void
64 do
65 type_mark := a_type_mark
66 name := a_name
67 actual_parameters := a_parameters
68 named_base_class := a_named_base_class
69 ensure
70 type_mark_set: type_mark = a_type_mark
71 name_set: name = a_name
72 raw_actual_parameters_set: actual_parameters = a_parameters
73 named_base_class_set: named_base_class = a_named_base_class
74 end
75
76 feature -- Initialization
77
78 reset
79 -- Reset type as it was just after it was last parsed.
80 do
81 if tuple_actual_parameters_unfolded_1 or tuple_actual_parameters_unfolded_2 then
82 tuple_actual_parameters_unfolded_1 := False
83 tuple_actual_parameters_unfolded_2 := False
84 if attached {ET_UNFOLDED_EMPTY_TUPLE_ACTUAL_PARAMETERS} actual_parameters as l_actual_parameters then
85 actual_parameters := Void
86 elseif attached {ET_UNFOLDED_TUPLE_ACTUAL_PARAMETERS} actual_parameters as l_actual_parameters then
87 actual_parameters := l_actual_parameters.actual_parameters
88 end
89 if attached {ET_ACTUAL_PARAMETER_SUBLIST} actual_parameters as l_actual_parameters then
90 actual_parameters := l_actual_parameters.actual_parameters
91 end
92 end
93 if attached actual_parameters as l_parameters then
94 l_parameters.reset
95 end
96 end
97
98 feature -- Access
99
100 actual_parameters: detachable ET_ACTUAL_PARAMETERS
101 -- Actual generic parameters
102
103 type_mark: detachable ET_TYPE_MARK
104 -- 'attached', 'detachable', 'expanded', 'reference' or 'separate' keyword,
105 -- or '!' or '?' symbol
106
107 overridden_type_mark (a_override_type_mark: detachable ET_TYPE_MARK): detachable ET_TYPE_MARK
108 -- Version of `type_mark' overridden by `a_override_type_mark'
109 local
110 l_result_expanded_mark: BOOLEAN
111 l_result_reference_mark: BOOLEAN
112 l_result_separate_mark: BOOLEAN
113 l_result_attached_mark: BOOLEAN
114 l_result_detachable_mark: BOOLEAN
115 l_current_ok: BOOLEAN
116 l_other_ok: BOOLEAN
117 do
118 if a_override_type_mark = Void then
119 Result := type_mark
120 else
121 l_current_ok := True
122 l_other_ok := True
123 if a_override_type_mark.is_expandedness_mark then
124 if a_override_type_mark.is_expanded_mark then
125 if not is_expanded then
126 l_current_ok := False
127 end
128 if not base_class.is_expanded then
129 l_result_expanded_mark := True
130 end
131 else
132 if is_expanded then
133 l_current_ok := False
134 end
135 if base_class.is_expanded then
136 l_result_reference_mark := True
137 end
138 end
139 elseif attached type_mark as l_type_mark and then l_type_mark.is_expandedness_mark then
140 if l_type_mark.is_expanded_mark then
141 if not base_class.is_expanded then
142 l_other_ok := False
143 l_result_expanded_mark := True
144 end
145 else
146 if base_class.is_expanded then
147 l_other_ok := False
148 l_result_reference_mark := True
149 end
150 end
151 end
152 if a_override_type_mark.is_separateness_mark then
153 if not is_separate then
154 l_current_ok := False
155 end
156 if not base_class.is_separate then
157 l_result_separate_mark := True
158 end
159 elseif attached type_mark as l_type_mark and then l_type_mark.is_separateness_mark then
160 if not base_class.is_separate then
161 l_other_ok := False
162 l_result_separate_mark := True
163 end
164 end
165 if a_override_type_mark.is_attachment_mark then
166 if a_override_type_mark.is_attached_mark then
167 if not is_attached then
168 l_current_ok := False
169 end
170 if not (base_class.is_expanded or l_result_expanded_mark) or l_result_reference_mark then
171 l_result_attached_mark := True
172 end
173 else
174 if is_attached and not is_expanded then
175 l_current_ok := False
176 end
177 if not (base_class.is_expanded or l_result_expanded_mark) or l_result_reference_mark then
178 l_result_detachable_mark := True
179 end
180 end
181 elseif attached type_mark as l_type_mark and then l_type_mark.is_attachment_mark then
182 if l_type_mark.is_attached_mark then
183 if not base_class.is_expanded then
184 l_other_ok := False
185 end
186 if not (base_class.is_expanded or l_result_expanded_mark) or l_result_reference_mark then
187 l_result_attached_mark := True
188 end
189 else
190 if not base_class.is_expanded then
191 l_other_ok := False
192 end
193 if not (base_class.is_expanded or l_result_expanded_mark) or l_result_reference_mark then
194 l_result_detachable_mark := True
195 end
196 end
197 end
198 if l_current_ok then
199 Result := type_mark
200 elseif l_other_ok then
201 Result := a_override_type_mark
202 else
203 Result := tokens.implicit_type_mark (l_result_expanded_mark, l_result_reference_mark, l_result_separate_mark, l_result_attached_mark, l_result_detachable_mark)
204 end
205 end
206 end
207
208 base_type_with_type_mark (a_type_mark: detachable ET_TYPE_MARK; a_context: ET_TYPE_CONTEXT): ET_BASE_TYPE
209 -- Same as `base_type' except that its type mark status is
210 -- overridden by `a_type_mark', if not Void
211 local
212 l_actual_parameters: like actual_parameters
213 l_named_parameters: detachable ET_ACTUAL_PARAMETERS
214 l_type_mark: detachable ET_TYPE_MARK
215 do
216 l_actual_parameters := actual_parameters
217 if a_context = Current or (a_context.is_root_context and then a_context.root_context = Current) then
218 -- The current type is its own context, therefore it has the same
219 -- actual parameters as its base type.
220 l_named_parameters := l_actual_parameters
221 elseif l_actual_parameters /= Void then
222 l_named_parameters := l_actual_parameters.named_types (a_context)
223 end
224 l_type_mark := overridden_type_mark (a_type_mark)
225 if l_type_mark /= type_mark or l_named_parameters /= l_actual_parameters then
226 if l_named_parameters /= Void then
227 create {ET_CLASS_TYPE} Result.make_generic (l_type_mark, name, l_named_parameters, named_base_class)
228 else
229 create {ET_CLASS_TYPE} Result.make (l_type_mark, name, named_base_class)
230 end
231 else
232 Result := Current
233 end
234 end
235
236 type_with_type_mark (a_type_mark: detachable ET_TYPE_MARK): ET_CLASS_TYPE
237 -- Current type whose type mark status is
238 -- overridden by `a_type_mark', if not Void
239 local
240 l_type_mark: detachable ET_TYPE_MARK
241 do
242 l_type_mark := overridden_type_mark (a_type_mark)
243 if l_type_mark /= type_mark then
244 if attached actual_parameters as l_actual_parameters then
245 create {ET_CLASS_TYPE} Result.make_generic (l_type_mark, name, l_actual_parameters, named_base_class)
246 else
247 create {ET_CLASS_TYPE} Result.make (l_type_mark, name, named_base_class)
248 end
249 else
250 Result := Current
251 end
252 end
253
254 position: ET_POSITION
255 -- Position of first character of
256 -- current node in source code
257 do
258 if attached type_mark as l_type_mark and then not l_type_mark.is_implicit_mark and then not l_type_mark.position.is_null then
259 Result := l_type_mark.position
260 else
261 Result := name.position
262 end
263 end
264
265 first_leaf: ET_AST_LEAF
266 -- First leaf node in current node
267 do
268 if attached type_mark as l_type_mark and then not l_type_mark.is_implicit_mark then
269 Result := l_type_mark.first_leaf
270 else
271 Result := name.first_leaf
272 end
273 end
274
275 last_leaf: ET_AST_LEAF
276 -- Last leaf node in current node
277 do
278 if attached actual_parameters as l_actual_parameters then
279 Result := l_actual_parameters.last_leaf
280 else
281 Result := name.last_leaf
282 end
283 end
284
285 feature -- Status report
286
287 is_separate: BOOLEAN
288 -- Is current type separate?
289 do
290 if attached type_mark as l_type_mark then
291 Result := l_type_mark.is_separate_mark
292 else
293 Result := base_class.is_separate
294 end
295 end
296
297 is_type_separate_with_type_mark (a_type_mark: detachable ET_TYPE_MARK; a_context: ET_TYPE_CONTEXT): BOOLEAN
298 -- Is current type separate when viewed from `a_context'?
299 do
300 if a_type_mark = Void then
301 Result := is_separate
302 elseif a_type_mark.is_separate_mark then
303 Result := True
304 else
305 Result := is_separate
306 end
307 end
308
309 is_expanded: BOOLEAN
310 -- Is current type expanded?
311 do
312 if not attached type_mark as l_type_mark then
313 Result := base_class.is_expanded
314 elseif l_type_mark.is_expanded_mark then
315 Result := True
316 elseif l_type_mark.is_reference_mark then
317 Result := False
318 else
319 Result := base_class.is_expanded
320 end
321 end
322
323 is_type_expanded_with_type_mark (a_type_mark: detachable ET_TYPE_MARK; a_context: ET_TYPE_CONTEXT): BOOLEAN
324 -- Is current type expanded when viewed from `a_context'?
325 do
326 if a_type_mark = Void then
327 Result := is_expanded
328 elseif a_type_mark.is_expanded_mark then
329 Result := True
330 elseif a_type_mark.is_reference_mark then
331 Result := False
332 else
333 Result := is_expanded
334 end
335 end
336
337 is_attached: BOOLEAN
338 -- Is current type attached?
339 do
340 if is_expanded then
341 Result := True
342 elseif base_class.is_none then
343 -- Class type "NONE" is always detachable regardless of type marks.
344 Result := False
345 elseif attached type_mark as l_type_mark and then l_type_mark.is_attachment_mark then
346 Result := l_type_mark.is_attached_mark
347 else
348 Result := True
349 end
350 end
351
352 is_type_attached_with_type_mark (a_type_mark: detachable ET_TYPE_MARK; a_context: ET_TYPE_CONTEXT): BOOLEAN
353 -- Same as `is_type_attached' except that the type mark status is
354 -- overridden by `a_type_mark', if not Void
355 do
356 if base_class.is_none then
357 -- Class type "NONE" is always detachable regardless of type marks.
358 Result := False
359 elseif a_type_mark = Void then
360 Result := is_attached
361 elseif a_type_mark.is_attached_mark then
362 Result := True
363 elseif a_type_mark.is_detachable_mark then
364 -- Expanded types are always attached regardless of the type marks.
365 Result := is_expanded
366 else
367 Result := is_attached
368 end
369 end
370
371 base_type_has_class (a_class: ET_CLASS; a_context: ET_TYPE_CONTEXT): BOOLEAN
372 -- Does the base type of current type contain `a_class'
373 -- when it appears in `a_context'?
374 do
375 if a_class = base_class then
376 Result := True
377 elseif attached actual_parameters as l_actual_parameters then
378 Result := l_actual_parameters.named_types_have_class (a_class, a_context)
379 end
380 end
381
382 tuple_actual_parameters_unfolded_1: BOOLEAN
383 -- Has the first phase of Tuple-type-unfolding been performed?
384
385 tuple_actual_parameters_unfolded_2: BOOLEAN
386 -- Has the second phase of Tuple-type-unfolding been performed?
387
388 feature -- Comparison
389
390 same_syntactical_type_with_type_marks (other: ET_TYPE; other_type_mark: detachable ET_TYPE_MARK; other_context: ET_TYPE_CONTEXT; a_type_mark: detachable ET_TYPE_MARK; a_context: ET_TYPE_CONTEXT): BOOLEAN
391 -- Same as `same_syntactical_type' except that the type mark status of `Current'
392 -- and `other' is overridden by `a_type_mark' and `other_type_mark', if not Void
393 do
394 if base_class.is_unknown then
395 -- "*UNKNOWN*" is equal to no type, not even itself.
396 Result := False
397 elseif other = Current and then other_type_mark = a_type_mark and then (other_context = a_context or else not is_generic) then
398 Result := True
399 else
400 Result := other.same_syntactical_class_type_with_type_marks (Current, a_type_mark, a_context, other_type_mark, other_context)
401 end
402 end
403
404 same_named_type_with_type_marks (other: ET_TYPE; other_type_mark: detachable ET_TYPE_MARK; other_context: ET_TYPE_CONTEXT; a_type_mark: detachable ET_TYPE_MARK; a_context: ET_TYPE_CONTEXT): BOOLEAN
405 -- Same as `same_named_type' except that the type mark status of `Current'
406 -- and `other' is overridden by `a_type_mark' and `other_type_mark', if not Void
407 do
408 if base_class.is_unknown then
409 -- "*UNKNOWN*" is equal to no type, not even itself.
410 Result := False
411 elseif other = Current and then other_type_mark = a_type_mark and then (other_context = a_context or else not is_generic) then
412 Result := True
413 else
414 Result := other.same_named_class_type_with_type_marks (Current, a_type_mark, a_context, other_type_mark, other_context)
415 end
416 end
417
418 same_base_type_with_type_marks (other: ET_TYPE; other_type_mark: detachable ET_TYPE_MARK; other_context: ET_TYPE_CONTEXT; a_type_mark: detachable ET_TYPE_MARK; a_context: ET_TYPE_CONTEXT): BOOLEAN
419 -- Same as `same_base_type' except that the type mark status of `Current'
420 -- and `other' is overridden by `a_type_mark' and `other_type_mark', if not Void
421 do
422 if base_class.is_unknown then
423 -- "*UNKNOWN*" is equal to no type, not even itself.
424 Result := False
425 elseif other = Current and then other_type_mark = a_type_mark and then (other_context = a_context or else not is_generic) then
426 Result := True
427 else
428 Result := other.same_base_class_type_with_type_marks (Current, a_type_mark, a_context, other_type_mark, other_context)
429 end
430 end
431
432 same_as_base_class: BOOLEAN
433 -- Is current type a non-generic class type with the same
434 -- expandedness and separateness status as its base class,
435 -- or is it its own base class?
436 do
437 if base_class.is_unknown then
438 -- "*UNKNOWN*" is equal to no type, not even itself.
439 Result := False
440 elseif base_class = Current then
441 Result := True
442 else
443 Result := not is_generic and then
444 (is_expanded = base_class.is_expanded and
445 is_separate = base_class.is_separate)
446 end
447 end
448
449 feature {ET_TYPE, ET_TYPE_CONTEXT} -- Comparison
450
451 same_syntactical_class_type_with_type_marks (other: ET_CLASS_TYPE; other_type_mark: detachable ET_TYPE_MARK; other_context: ET_TYPE_CONTEXT; a_type_mark: detachable ET_TYPE_MARK; a_context: ET_TYPE_CONTEXT): BOOLEAN
452 -- Are current type appearing in `a_context' and `other'
453 -- type appearing in `other_context' the same type?
454 -- (Note: We are NOT comparing the base types here!
455 -- Therefore anchored types are considered the same
456 -- only if they have the same anchor. An anchor type
457 -- is not considered the same as any other type even
458 -- if they have the same base type.)
459 -- Note that the type mark status of `Current' and `other' is
460 -- overridden by `a_type_mark' and `other_type_mark', if not Void
461 do
462 if base_class.is_unknown then
463 -- "*UNKNOWN*" is equal to no type, not even itself.
464 Result := False
465 elseif other = Current and then other_type_mark = a_type_mark and then (other_context = a_context or else not is_generic) then
466 Result := True
467 elseif a_context.attachment_type_conformance_mode and then is_type_attached_with_type_mark (a_type_mark, a_context) /= other.is_type_attached_with_type_mark (other_type_mark, other_context) then
468 Result := False
469 elseif base_class /= other.base_class then
470 Result := False
471 elseif is_type_expanded_with_type_mark (a_type_mark, a_context) /= other.is_type_expanded_with_type_mark (other_type_mark, other_context) then
472 Result := False
473 elseif a_context.scoop_mode and then is_type_separate_with_type_mark (a_type_mark, a_context) /= other.is_type_separate_with_type_mark (other_type_mark, other_context) then
474 Result := False
475 elseif not attached other.actual_parameters as l_other_actual_parameters then
476 check other_not_generic: not other.is_generic end
477 Result := not is_generic
478 elseif not attached actual_parameters as l_actual_parameters then
479 check not_generic: not is_generic end
480 Result := l_other_actual_parameters.is_empty
481 else
482 Result := l_actual_parameters.same_syntactical_types (l_other_actual_parameters, other_context, a_context)
483 end
484 end
485
486 same_named_class_type_with_type_marks (other: ET_CLASS_TYPE; other_type_mark: detachable ET_TYPE_MARK; other_context: ET_TYPE_CONTEXT; a_type_mark: detachable ET_TYPE_MARK; a_context: ET_TYPE_CONTEXT): BOOLEAN
487 -- Do current type appearing in `a_context' and `other' type
488 -- appearing in `other_context' have the same named type?
489 -- Note that the type mark status of `Current' and `other' is
490 -- overridden by `a_type_mark' and `other_type_mark', if not Void
491 do
492 if base_class.is_unknown then
493 -- "*UNKNOWN*" is equal to no type, not even itself.
494 Result := False
495 elseif other = Current and then other_type_mark = a_type_mark and then (other_context = a_context or else not is_generic) then
496 Result := True
497 elseif a_context.attachment_type_conformance_mode and then is_type_attached_with_type_mark (a_type_mark, a_context) /= other.is_type_attached_with_type_mark (other_type_mark, other_context) then
498 Result := False
499 elseif base_class /= other.base_class then
500 Result := False
501 elseif is_type_expanded_with_type_mark (a_type_mark, a_context) /= other.is_type_expanded_with_type_mark (other_type_mark, other_context) then
502 Result := False
503 elseif a_context.scoop_mode and then is_type_separate_with_type_mark (a_type_mark, a_context) /= other.is_type_separate_with_type_mark (other_type_mark, other_context) then
504 Result := False
505 elseif not attached other.actual_parameters as l_other_actual_parameters then
506 check other_not_generic: not other.is_generic end
507 Result := not is_generic
508 elseif not attached actual_parameters as l_actual_parameters then
509 check not_generic: not is_generic end
510 Result := l_other_actual_parameters.is_empty
511 else
512 Result := l_actual_parameters.same_named_types (l_other_actual_parameters, other_context, a_context)
513 end
514 end
515
516 same_base_class_type_with_type_marks (other: ET_CLASS_TYPE; other_type_mark: detachable ET_TYPE_MARK; other_context: ET_TYPE_CONTEXT; a_type_mark: detachable ET_TYPE_MARK; a_context: ET_TYPE_CONTEXT): BOOLEAN
517 -- Do current type appearing in `a_context' and `other' type
518 -- appearing in `other_context' have the same base type?
519 -- Note that the type mark status of `Current' and `other' is
520 -- overridden by `a_type_mark' and `other_type_mark', if not Void
521 do
522 if base_class.is_unknown then
523 -- "*UNKNOWN*" is equal to no type, not even itself.
524 Result := False
525 elseif other = Current and then other_type_mark = a_type_mark and then (other_context = a_context or else not is_generic) then
526 Result := True
527 elseif a_context.attachment_type_conformance_mode and then is_type_attached_with_type_mark (a_type_mark, a_context) /= other.is_type_attached_with_type_mark (other_type_mark, other_context) then
528 Result := False
529 elseif base_class /= other.base_class then
530 Result := False
531 elseif is_type_expanded_with_type_mark (a_type_mark, a_context) /= other.is_type_expanded_with_type_mark (other_type_mark, other_context) then
532 Result := False
533 elseif a_context.scoop_mode and then is_type_separate_with_type_mark (a_type_mark, a_context) /= other.is_type_separate_with_type_mark (other_type_mark, other_context) then
534 Result := False
535 elseif not attached other.actual_parameters as l_other_actual_parameters then
536 check other_not_generic: not other.is_generic end
537 Result := not is_generic
538 elseif not attached actual_parameters as l_actual_parameters then
539 check not_generic: not is_generic end
540 Result := l_other_actual_parameters.is_empty
541 else
542 Result := l_actual_parameters.same_named_types (l_other_actual_parameters, other_context, a_context)
543 end
544 end
545
546 feature -- Conformance
547
548 conforms_to_type_with_type_marks (other: ET_TYPE; other_type_mark: detachable ET_TYPE_MARK; other_context: ET_TYPE_CONTEXT; a_type_mark: detachable ET_TYPE_MARK; a_context: ET_TYPE_CONTEXT): BOOLEAN
549 -- Same as `conforms_to_type' except that the type mark status of `Current'
550 -- and `other' is overridden by `a_type_mark' and `other_type_mark', if not Void
551 do
552 if base_class.is_unknown then
553 -- "*UNKNOWN*" conforms to no type, not even itself.
554 Result := False
555 elseif other = Current and then other_type_mark = a_type_mark and then (other_context = a_context or else not is_generic) then
556 Result := True
557 else
558 Result := other.conforms_from_class_type_with_type_marks (Current, a_type_mark, a_context, other_type_mark, other_context)
559 end
560 end
561
562 feature {ET_TYPE, ET_TYPE_CONTEXT} -- Conformance
563
564 conforms_from_class_type_with_type_marks (other: ET_CLASS_TYPE; other_type_mark: detachable ET_TYPE_MARK; other_context: ET_TYPE_CONTEXT; a_type_mark: detachable ET_TYPE_MARK; a_context: ET_TYPE_CONTEXT): BOOLEAN
565 -- Does `other' type appearing in `other_context' conform
566 -- to current type appearing in `a_context'?
567 -- Note that the type mark status of `Current' and `other' is
568 -- overridden by `a_type_mark' and `other_type_mark', if not Void
569 -- (Note: 'current_system.ancestor_builder' is used on the classes
570 -- whose ancestors need to be built in order to check for conformance.)
571 local
572 other_base_class: ET_CLASS
573 l_ancestor_context: ET_NESTED_TYPE_CONTEXT
574 l_other_type_mark: detachable ET_TYPE_MARK
575 do
576 other_base_class := other.base_class
577 if base_class.is_unknown then
578 -- "*UNKNOWN*" conforms to no type, not even itself.
579 Result := False
580 elseif other = Current and then other_type_mark = a_type_mark and then (other_context = a_context or else not is_generic) then
581 Result := True
582 elseif other_context.attachment_type_conformance_mode and then not (is_type_attached_with_type_mark (a_type_mark, a_context) implies other.is_type_attached_with_type_mark (other_type_mark, other_context)) then
583 Result := False
584 elseif base_class = other_base_class then
585 if is_type_expanded_with_type_mark (a_type_mark, a_context) and not other.is_type_expanded_with_type_mark (other_type_mark, other_context) then
586 Result := False
587 elseif other_context.scoop_mode and then not (other.is_type_separate_with_type_mark (other_type_mark, other_context) implies is_type_separate_with_type_mark (a_type_mark, a_context)) then
588 Result := False
589 elseif not attached other.actual_parameters as l_other_actual_parameters then
590 check other_not_generic: not other.is_generic end
591 Result := not is_generic
592 elseif not attached actual_parameters as l_actual_parameters then
593 check not_generic: not is_generic end
594 Result := l_other_actual_parameters.is_empty
595 else
596 -- DISABLED: Use SmartEiffel agent type conformance semantics, where the conformance
597 -- of the second actual generic parameter is checked in the reverse order.
598 -- if not other_base_class.is_preparsed then
599 -- -- This class is not even preparsed (i.e. we know nothing about it,
600 -- -- not even its filename). Therefore it is impossible to determine
601 -- -- whether it conforms to current type.
602 -- Result := False
603 -- elseif
604 -- other_base_class = other_base_class.current_system.routine_class or
605 -- other_base_class = other_base_class.current_system.procedure_class or
606 -- other_base_class = other_base_class.current_system.function_class or
607 -- other_base_class = other_base_class.current_system.predicate_class
608 -- then
609 -- -- Use SmartEiffel agent type conformance semantics, where the conformance
610 -- -- of the second actual generic parameter is checked in the reverse order.
611 -- Result := l_other_actual_parameters.agent_conforms_to_types (2, l_actual_parameters, a_context, other_context)
612 -- else
613 Result := l_other_actual_parameters.conforms_to_types (l_actual_parameters, a_context, other_context)
614 -- end
615 end
616 elseif not is_type_expanded_with_type_mark (a_type_mark, a_context) then
617 if other_base_class.is_none then
618 -- Class type "NONE" is always detachable regardless of type marks.
619 -- Therefore it conforms to any class type that is not expanded nor attached.
620 Result := True
621 elseif not other_base_class.is_preparsed then
622 -- This class is not even preparsed (i.e. we know nothing about it,
623 -- not even its filename). Therefore it is impossible to determine
624 -- whether it conforms to current type.
625 Result := False
626 else
627 other_base_class.process (other_base_class.current_system.ancestor_builder)
628 -- If there was an error building the ancestors of
629 -- `other_base_class', this error has already been
630 -- reported, so we assume here that everything went
631 -- fine in order to catch other possible errors. Of
632 -- course we might catch errors which are not errors
633 -- but just consequences of the error which occurred
634 -- when building the ancestors, but this is OK.
635 if attached other_base_class.ancestor (Current) as l_ancestor then
636 l_other_type_mark := other.overridden_type_mark (other_type_mark)
637 if (other.is_expanded and then not l_ancestor.is_expanded) and then (l_other_type_mark = Void or else not l_other_type_mark.is_attached_mark) then
638 -- Make sure to cover the case where "INTEGER" conforms to "attached ANY",
639 -- even though "INTEGER" has no explicit type mark (the expandedness is
640 -- declared in class "INTEGER").
641 l_other_type_mark := tokens.implicit_attached_type_mark
642 end
643 if not l_ancestor.is_generic then
644 Result := l_ancestor.conforms_to_type_with_type_marks (Current, a_type_mark, a_context, l_other_type_mark, other_context)
645 else
646 if other_context /= a_context then
647 l_ancestor_context := other_context.as_nested_type_context
648 else
649 l_ancestor_context := other_context.to_nested_type_context
650 end
651 l_ancestor_context.force_last (other)
652 Result := l_ancestor.conforms_to_type_with_type_marks (Current, a_type_mark, a_context, l_other_type_mark, l_ancestor_context)
653 l_ancestor_context.remove_last
654 end
655 elseif base_class.is_system_object_class and then base_class.is_dotnet then
656 -- Under .NET all types are considered to conform to "SYSTEM_OBJECT".
657 Result := True
658 end
659 end
660 end
661 end
662
663 feature -- Type processing
664
665 resolve_unfolded_tuple_actual_parameters_1 (a_universe: ET_UNIVERSE)
666 -- First phase of Tuple-type-unfolding in actual parameters of current class type.
667 -- Perform syntactical transformations only:
668 -- * Resolve cases where the number of actual and formal generic parameters
669 -- are different.
670 -- * Also resolve the use of obsolete routine types (with an extra
671 -- first generic parameter).
672 require
673 a_universe_not_void: a_universe /= Void
674 local
675 l_base_class: ET_CLASS
676 l_tuple_type: ET_TUPLE_TYPE
677 l_actual_sublist: ET_ACTUAL_PARAMETER_SUBLIST
678 l_unfolded_tuple_actuals: ET_UNFOLDED_TUPLE_ACTUAL_PARAMETERS
679 l_tuple_constraint_position: INTEGER
680 do
681 if not tuple_actual_parameters_unfolded_1 then
682 tuple_actual_parameters_unfolded_1 := True
683 -- Not unfolded yet.
684 l_base_class := base_class
685 -- Obsolete routine types.
686 if not attached actual_parameters as l_actual_parameters or else l_actual_parameters.count < 2 then
687 -- Do nothing.
688 elseif not attached l_base_class.formal_parameters as l_formal_parameters then
689 -- Do nothing.
690 elseif a_universe.obsolete_routine_type_mode then
691 if
692 (l_base_class.is_routine_class and then l_formal_parameters.count = 1) or
693 (l_base_class.is_procedure_class and then l_formal_parameters.count = 1) or
694 (l_base_class.is_predicate_class and then l_formal_parameters.count = 1) or
695 (l_base_class.is_function_class and then l_formal_parameters.count = 2)
696 then
697 create l_actual_sublist.make (l_actual_parameters, 2, l_actual_parameters.count)
698 actual_parameters := l_actual_sublist
699 end
700 end
701 -- Tuple-type-unfolding.
702 l_tuple_constraint_position := l_base_class.tuple_constraint_position
703 if l_tuple_constraint_position = 0 then
704 -- Do nothing: not a single-tuple class.
705 -- No need to perform the second phase.
706 tuple_actual_parameters_unfolded_2 := True
707 elseif not attached l_base_class.formal_parameters as l_formal_parameters then
708 -- Should never happen.
709 -- No need to perform the second phase.
710 tuple_actual_parameters_unfolded_2 := True
711 elseif attached actual_parameters as l_actual_parameters then
712 if l_actual_parameters.count = l_formal_parameters.count - 1 then
713 l_tuple_type := a_universe.tuple_type
714 create l_unfolded_tuple_actuals.make (l_actual_parameters, l_tuple_type, l_tuple_constraint_position)
715 actual_parameters := l_unfolded_tuple_actuals
716 -- No need to perform the second phase.
717 tuple_actual_parameters_unfolded_2 := True
718 elseif l_actual_parameters.count > l_formal_parameters.count then
719 create l_actual_sublist.make (l_actual_parameters, l_tuple_constraint_position, l_tuple_constraint_position + l_actual_parameters.count - l_formal_parameters.count)
720 create l_tuple_type.make (tokens.attached_keyword, l_actual_sublist, a_universe.tuple_type.named_base_class)
721 create l_unfolded_tuple_actuals.make (l_actual_parameters, l_tuple_type, l_tuple_constraint_position)
722 actual_parameters := l_unfolded_tuple_actuals
723 -- No need to perform the second phase.
724 tuple_actual_parameters_unfolded_2 := True
725 elseif l_actual_parameters.count /= l_formal_parameters.count then
726 -- No need to perform the second phase.
727 tuple_actual_parameters_unfolded_2 := True
728 end
729 elseif l_formal_parameters.count = 1 then
730 actual_parameters := a_universe.unfolded_empty_tuple_actual_parameters
731 -- No need to perform the second phase.
732 tuple_actual_parameters_unfolded_2 := True
733 else
734 -- No need to perform the second phase.
735 tuple_actual_parameters_unfolded_2 := True
736 end
737 end
738 end
739
740 resolve_unfolded_tuple_actual_parameters_2 (a_context, a_constraint_context: ET_TYPE_CONTEXT)
741 -- Second phase of Tuple-type-unfolding in actual parameters of current class type.
742 -- Perform transformations which require conformance checking:
743 -- * Resolve the case: "FOO [A, B, C]" -> "FOO [A, TUPLE [B], C]".
744 -- `a_context' and `a_constraint_context' are the contexts from which
745 -- the current actual parameter at the tuple constraint position
746 -- and its associated constraint are viewed respectively when
747 -- performing conformance checking.
748 require
749 a_context_not_void: a_context /= Void
750 a_contrainst_context_not_void: a_constraint_context /= Void
751 single_tuple_class: base_class.tuple_constraint_position /= 0
752 same_parameter_count: base_class.formal_parameter_count = actual_parameter_count
753 local
754 l_base_class: ET_CLASS
755 l_unfolded_tuple_actuals: ET_UNFOLDED_TUPLE_ACTUAL_PARAMETERS
756 l_tuple_constraint_position: INTEGER
757 l_tuple_type: ET_TUPLE_TYPE
758 l_actual_sublist: ET_ACTUAL_PARAMETER_SUBLIST
759 l_actual: ET_TYPE
760 do
761 if not tuple_actual_parameters_unfolded_2 then
762 tuple_actual_parameters_unfolded_2 := True
763 -- Not unfolded yet.
764 l_base_class := base_class
765 l_tuple_constraint_position := l_base_class.tuple_constraint_position
766 if not attached l_base_class.formal_parameters as l_formal_parameters then
767 -- Should never happen.
768 elseif attached actual_parameters as l_actual_parameters then
769 if attached l_formal_parameters.formal_parameter (l_tuple_constraint_position).constraint as l_tuple_constraint then
770 l_actual := l_actual_parameters.type (l_tuple_constraint_position)
771 if not l_actual.conforms_to_type (l_tuple_constraint, a_constraint_context, a_context) then
772 create l_actual_sublist.make (l_actual_parameters, l_tuple_constraint_position, l_tuple_constraint_position)
773 create l_tuple_type.make (tokens.attached_keyword, l_actual_sublist, a_context.root_context.base_class.universe.tuple_type.named_base_class)
774 create l_unfolded_tuple_actuals.make (l_actual_parameters, l_tuple_type, l_tuple_constraint_position)
775 actual_parameters := l_unfolded_tuple_actuals
776 end
777 end
778 end
779 end
780 ensure
781 same_parameter_count: actual_parameter_count = old actual_parameter_count
782 end
783
784 resolved_formal_parameters_with_type_mark (a_type_mark: detachable ET_TYPE_MARK; a_parameters: ET_ACTUAL_PARAMETERS): ET_CLASS_TYPE
785 -- Same as `resolved_formal_parameters' except that the type mark status is
786 -- overridden by `a_type_mark', if not Void
787 local
788 l_actual_parameters: like actual_parameters
789 l_resolved_parameters: detachable ET_ACTUAL_PARAMETERS
790 l_type_mark: detachable ET_TYPE_MARK
791 do
792 l_actual_parameters := actual_parameters
793 if l_actual_parameters /= Void then
794 l_resolved_parameters := l_actual_parameters.resolved_formal_parameters (a_parameters)
795 end
796 l_type_mark := overridden_type_mark (a_type_mark)
797 if l_type_mark /= type_mark or l_resolved_parameters /= l_actual_parameters then
798 if l_resolved_parameters /= Void then
799 create {ET_CLASS_TYPE} Result.make_generic (l_type_mark, name, l_resolved_parameters, named_base_class)
800 else
801 create {ET_CLASS_TYPE} Result.make (l_type_mark, name, named_base_class)
802 end
803 else
804 Result := Current
805 end
806 end
807
808 feature -- Output
809
810 append_to_string (a_string: STRING)
811 -- Append textual representation of
812 -- current type to `a_string'.
813 do
814 if attached type_mark as l_type_mark then
815 if l_type_mark.is_implicit_mark then
816 a_string.append_character ('[')
817 end
818 a_string.append_string (l_type_mark.text)
819 if l_type_mark.is_implicit_mark then
820 a_string.append_character (']')
821 end
822 a_string.append_character (' ')
823 end
824 a_string.append_string (name.upper_name)
825 if attached actual_parameters as l_parameters and then not l_parameters.is_empty then
826 a_string.append_character (' ')
827 l_parameters.append_to_string (a_string)
828 end
829 end
830
831 append_unaliased_to_string (a_string: STRING)
832 -- Append textual representation of unaliased
833 -- version of current type to `a_string'.
834 -- An unaliased version if when aliased types such as INTEGER
835 -- are replaced by the associated types such as INTEGER_32.
836 do
837 if attached type_mark as l_type_mark then
838 if l_type_mark.is_implicit_mark then
839 a_string.append_character ('[')
840 end
841 a_string.append_string (l_type_mark.text)
842 if l_type_mark.is_implicit_mark then
843 a_string.append_character (']')
844 end
845 a_string.append_character (' ')
846 end
847 a_string.append_string (base_class.upper_name)
848
849 if attached actual_parameters as l_parameters and then not l_parameters.is_empty then
850 a_string.append_character (' ')
851 l_parameters.append_unaliased_to_string (a_string)
852 end
853 end
854
855 feature -- Processing
856
857 process (a_processor: ET_AST_PROCESSOR)
858 -- Process current node.
859 do
860 a_processor.process_class_type (Current)
861 end
862
863 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23