/[eiffelstudio]/vendor/gobosoft.com/gobo/4.0d/library/tools/src/eiffel/compilation/et_type_checker.e
ViewVC logotype

Contents of /vendor/gobosoft.com/gobo/4.0d/library/tools/src/eiffel/compilation/et_type_checker.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: 36022 byte(s)
Update 4.0d version with changes in Gobo from 2016/05/09

1 note
2
3 description:
4
5 "Eiffel type checkers"
6
7 library: "Gobo Eiffel Tools Library"
8 copyright: "Copyright (c) 2003-2016, Eric Bezault and others"
9 license: "MIT License"
10 date: "$Date$"
11 revision: "$Revision$"
12
13 class ET_TYPE_CHECKER
14
15 inherit
16
17 ET_CLASS_SUBPROCESSOR
18 redefine
19 make
20 end
21
22 ET_AST_NULL_PROCESSOR
23 undefine
24 make
25 redefine
26 process_class,
27 process_class_type,
28 process_like_current,
29 process_like_feature,
30 process_qualified_like_braced_type,
31 process_qualified_like_type,
32 process_tuple_type
33 end
34
35 UT_SHARED_ISE_VERSIONS
36 export {NONE} all end
37
38 create
39
40 make
41
42 feature {NONE} -- Initialization
43
44 make
45 -- Create a new type checker.
46 do
47 precursor {ET_CLASS_SUBPROCESSOR}
48 current_context := tokens.unknown_class
49 current_class_impl := tokens.unknown_class
50 current_feature_impl := dummy_feature
51 create constraint_context.make_with_capacity (current_class, 1)
52 end
53
54 feature -- Validity checking
55
56 check_type_validity (a_type: ET_TYPE; a_current_feature_impl: ET_CLOSURE; a_current_class_impl: ET_CLASS; a_current_context: ET_TYPE_CONTEXT)
57 -- Check validity of `a_type' written in `a_current_feature_impl' in
58 -- `a_current_class_impl' viewed from `a_current_context'. Resolve
59 -- identifiers (such as 'like identifier', 'like {A}.identifier
60 -- or 'like a.identifier') in type `a_type' if not already done.
61 -- Set `has_fatal_error' if a fatal error occurred.
62 require
63 a_type_not_void: a_type /= Void
64 a_current_feature_impl_not_void: a_current_feature_impl /= Void
65 a_current_class_impl_not_void: a_current_class_impl /= Void
66 a_current_context_not_void: a_current_context /= Void
67 a_current_context_valid: a_current_context.is_valid_context
68 a_current_context_root_context: a_current_context.is_root_context
69 a_current_class_preparsed: a_current_context.base_class.is_preparsed
70 -- no_cycle: no cycle in anchored types involved.
71 local
72 old_feature_impl: ET_CLOSURE
73 old_context: ET_TYPE_CONTEXT
74 old_class: ET_CLASS
75 old_class_impl: ET_CLASS
76 do
77 has_fatal_error := False
78 old_feature_impl := current_feature_impl
79 current_feature_impl := a_current_feature_impl
80 old_context := current_context
81 current_context := a_current_context
82 old_class := current_class
83 current_class := current_context.root_context.base_class
84 old_class_impl := current_class_impl
85 current_class_impl := a_current_class_impl
86 a_type.process (Current)
87 current_class_impl := old_class_impl
88 current_class := old_class
89 current_context := old_context
90 current_feature_impl := old_feature_impl
91 end
92
93 check_creation_type_validity (a_type: ET_CLASS_TYPE; a_current_class_impl: ET_CLASS; a_current_context: ET_TYPE_CONTEXT; a_position: ET_POSITION)
94 -- Check validity of `a_type' as a creation type written in `a_current_class_impl'
95 -- and viewed from `a_current_context'. Note that `a_type' should already be a valid
96 -- type by itself (call `check_type_validity' for that).
97 -- Set `has_fatal_error' if an error occurred.
98 require
99 a_type_not_void: a_type /= Void
100 a_current_class_impl_not_void: a_current_class_impl /= Void
101 a_current_context_not_void: a_current_context /= Void
102 a_current_context_valid: a_current_context.is_valid_context
103 a_current_context_root_context: a_current_context.is_root_context
104 a_current_class_preparsed: a_current_context.base_class.is_preparsed
105 a_position_not_void: a_position /= Void
106 local
107 a_type_class: ET_CLASS
108 a_base_class: ET_CLASS
109 an_actuals: detachable ET_ACTUAL_PARAMETERS
110 an_actual: ET_TYPE
111 a_named_actual: ET_NAMED_TYPE
112 a_formals: detachable ET_FORMAL_PARAMETER_LIST
113 a_formal: ET_FORMAL_PARAMETER
114 a_creator: detachable ET_CONSTRAINT_CREATOR
115 a_name: ET_FEATURE_NAME
116 a_seed: INTEGER
117 a_creation_procedure: detachable ET_PROCEDURE
118 an_index: INTEGER
119 a_formal_parameters: detachable ET_FORMAL_PARAMETER_LIST
120 a_formal_parameter: detachable ET_FORMAL_PARAMETER
121 a_formal_creator: detachable ET_CONSTRAINT_CREATOR
122 a_formal_type: detachable ET_FORMAL_PARAMETER_TYPE
123 has_formal_type_error: BOOLEAN
124 i, nb: INTEGER
125 j, nb2: INTEGER
126 had_error: BOOLEAN
127 old_context: ET_TYPE_CONTEXT
128 old_class: ET_CLASS
129 old_class_impl: ET_CLASS
130 do
131 has_fatal_error := False
132 old_context := current_context
133 current_context := a_current_context
134 old_class := current_class
135 current_class := current_context.root_context.base_class
136 old_class_impl := current_class_impl
137 current_class_impl := a_current_class_impl
138 an_actuals := a_type.actual_parameters
139 a_type_class := a_type.base_class
140 a_type_class.process (current_system.interface_checker)
141 if not a_type_class.interface_checked or else a_type_class.has_interface_error then
142 set_fatal_error
143 elseif an_actuals /= Void and then not an_actuals.is_empty then
144 a_formals := a_type_class.formal_parameters
145 nb := an_actuals.count
146 if a_formals = Void or else a_formals.count /= nb then
147 -- Internal error: `a_type' is supposed to be a valid type.
148 set_fatal_error
149 error_handler.report_giaaa_error
150 else
151 a_formal_parameters := current_class.formal_parameters
152 from i := 1 until i > nb loop
153 an_actual := an_actuals.type (i)
154 a_named_actual := an_actual.shallow_named_type (current_context)
155 a_formal := a_formals.formal_parameter (i)
156 a_creator := a_formal.creation_procedures
157 if a_creator /= Void and then not a_creator.is_empty then
158 a_base_class := a_named_actual.base_class (current_context)
159 if attached {ET_FORMAL_PARAMETER_TYPE} a_named_actual as l_attached_formal_type then
160 a_formal_type := l_attached_formal_type
161 an_index := a_formal_type.index
162 if a_formal_parameters = Void or else an_index > a_formal_parameters.count then
163 -- Internal error: `a_formal_parameter' is supposed to be
164 -- a formal parameter of `current_context''s base class.
165 has_formal_type_error := True
166 set_fatal_error
167 error_handler.report_giaaa_error
168 else
169 has_formal_type_error := False
170 a_formal_parameter := a_formal_parameters.formal_parameter (an_index)
171 a_formal_creator := a_formal_parameter.creation_procedures
172 end
173 end
174 nb2 := a_creator.count
175 if nb2 > 0 then
176 a_base_class.process (current_system.interface_checker)
177 if not a_base_class.interface_checked or else a_base_class.has_interface_error then
178 set_fatal_error
179 else
180 from j := 1 until j > nb2 loop
181 a_name := a_creator.feature_name (j)
182 a_seed := a_name.seed
183 a_creation_procedure := a_base_class.seeded_procedure (a_seed)
184 if a_creation_procedure = Void then
185 -- Internal error: `a_type' is supposed to be a valid type.
186 set_fatal_error
187 error_handler.report_giaaa_error
188 elseif a_formal_type /= Void then
189 if not has_formal_type_error and a_formal_parameter /= Void then
190 if a_formal_creator = Void or else not a_formal_creator.has_feature (a_creation_procedure) then
191 set_fatal_error
192 if not class_interface_error_only then
193 error_handler.report_vtcg4b_error (current_class, current_class_impl, a_position, i, a_name, a_formal_parameter, a_type_class)
194 end
195 end
196 end
197 elseif not a_creation_procedure.is_creation_exported_to (a_type_class, a_base_class) then
198 if current_system.is_ise and then (current_class.is_deferred and an_actual.is_like_current) then
199 -- ISE accepts code of the form:
200 --
201 -- class A [G -> B create default_create end]
202 -- feature
203 -- f
204 -- local
205 -- b: G
206 -- do
207 -- create b
208 -- print (b.generating_type)
209 -- end
210 -- end
211 --
212 -- deferred class B
213 -- feature
214 -- f
215 -- local
216 -- a: A [like Current]
217 -- do
218 -- create a
219 -- a.f
220 -- end
221 -- end
222 --
223 -- This is indeed safe (i.e. no possible creation of instances of
224 -- a deferred class), provided that non-deferred descendants of
225 -- class B make their version of 'default_create' available for
226 -- creation to class A.
227 -- The following case is also accepted:
228 --
229 -- deferred class B
230 -- feature
231 -- f
232 -- local
233 -- a: like a1
234 -- do
235 -- create a
236 -- a.f
237 -- end
238 -- a1: A [like Current]
239 -- end
240 --
241 -- However, note that it rejects this one:
242 --
243 -- deferred class B
244 -- feature
245 -- f
246 -- local
247 -- a: A [like b]
248 -- do
249 -- create a
250 -- a.f
251 -- end
252 -- b: like Current
253 -- end
254 --
255 -- which was nevertheless not more unsafe than the other cases above.
256 elseif
257 (current_system.is_ise and then attached current_system.ise_version as l_ise_version and then l_ise_version < ise_6_0_6_7358) and then
258 (a_base_class.is_deferred and a_creation_procedure.has_seed (current_system.default_create_seed))
259 then
260 -- ISE started to report this VTCG error with version 6.0.6.7358.
261 -- However we report it anyway, except when the creation procedure
262 -- is the version of 'default_create' in a deferred class. There is
263 -- no occurrence of the other cases in the code at AXA Rosenberg,
264 -- and we don't want new occurrences to appear because it is dangerous
265 -- at run-time (we may end up creating instances of deferred classes).
266 else
267 set_fatal_error
268 if not class_interface_error_only then
269 error_handler.report_vtcg4a_error (current_class, current_class_impl, a_position, i, a_name, a_base_class, a_type_class)
270 end
271 end
272 end
273 j := j + 1
274 end
275 end
276 end
277 -- Since the corresponding formal generic parameter
278 -- has creation procedures associated with it, it
279 -- is possible to create instances of `an_actual'
280 -- through that means. So we need to check recursively
281 -- its validity as a creation type.
282 if attached {ET_CLASS_TYPE} a_named_actual as l_class_type then
283 had_error := has_fatal_error
284 check_creation_type_validity (l_class_type, current_class_impl, current_context, a_position)
285 if had_error then
286 set_fatal_error
287 end
288 end
289 else
290 -- We need to check whether `an_actual' is expanded.
291 -- In that case the creation of an instance of that
292 -- type will be implicit, so we need to check recursively
293 -- its validity as a creation type.
294 if attached {ET_CLASS_TYPE} a_named_actual as l_class_type and then l_class_type.is_expanded then
295 had_error := has_fatal_error
296 check_creation_type_validity (l_class_type, current_class_impl, current_context, a_position)
297 if had_error then
298 set_fatal_error
299 end
300 end
301 end
302 i := i + 1
303 end
304 end
305 end
306 current_class_impl := old_class_impl
307 current_class := old_class
308 current_context := old_context
309 end
310
311 feature -- Type conversion
312
313 convert_feature (a_source_type: ET_TYPE_CONTEXT; a_target_type: ET_TYPE_CONTEXT): detachable ET_CONVERT_FEATURE
314 -- Feature to convert `a_source_type' to `a_target_type';
315 -- Void if no such feature
316 require
317 a_source_type_not_void: a_source_type /= Void
318 a_source_context_valid: a_source_type.is_valid_context
319 a_target_type_not_void: a_target_type /= Void
320 a_target_context_valid: a_target_type.is_valid_context
321 -- no_cycle: no cycle in anchored types involved.
322 local
323 a_source_base_class: ET_CLASS
324 a_target_base_class: ET_CLASS
325 a_source_named_type: ET_NAMED_TYPE
326 do
327 a_source_base_class := a_source_type.base_class
328 -- Make sure that the class has been parsed before
329 -- asking for its conversion features.
330 if a_source_base_class.is_preparsed then
331 a_source_base_class.process (a_source_base_class.current_system.eiffel_parser)
332 end
333 Result := a_source_base_class.convert_to_feature (a_target_type, a_source_type)
334 if Result = Void then
335 a_target_base_class := a_target_type.base_class
336 -- Make sure that the class has been parsed before
337 -- asking for its conversion features.
338 if a_target_base_class.is_preparsed then
339 a_target_base_class.process (a_target_base_class.current_system.eiffel_parser)
340 end
341 Result := a_target_base_class.convert_from_feature (a_source_type, a_target_type)
342 if Result = Void then
343 a_source_named_type := a_source_type.named_type
344 if a_target_base_class.is_preparsed and then a_target_base_class.is_dotnet and a_target_base_class.is_system_object_class then
345 -- Needed for Eiffel for .NET.
346 create {ET_BUILTIN_CONVERT_FEATURE} Result.make (a_source_named_type)
347 end
348 end
349 end
350 end
351
352 feature {NONE} -- Validity checking
353
354 check_class_type_validity (a_type: ET_CLASS_TYPE)
355 -- Check validity of `a_type'.
356 -- Set `has_fatal_error' if a fatal error occurred.
357 require
358 a_type_not_void: a_type /= Void
359 -- no_cycle: no cycle in anchored types involved.
360 local
361 i, nb: INTEGER
362 an_actual: ET_TYPE
363 l_actuals: detachable ET_ACTUAL_PARAMETERS
364 a_formal: ET_FORMAL_PARAMETER
365 a_constraint: detachable ET_TYPE
366 a_class: ET_CLASS
367 had_error: BOOLEAN
368 l_conforms: BOOLEAN
369 do
370 has_fatal_error := False
371 a_class := a_type.base_class
372 if a_class.is_none then
373 if a_type.is_generic then
374 set_fatal_error
375 if not class_interface_error_only then
376 if current_class = current_class_impl then
377 error_handler.report_vtug1a_error (current_class, a_type)
378 else
379 -- TODO: this error should have already been reported when processing `current_class_impl'.
380 error_handler.report_vtug1a_error (current_class_impl, a_type)
381 end
382 end
383 end
384 elseif a_class.is_unknown then
385 set_fatal_error
386 if not class_interface_error_only then
387 if current_class = current_class_impl then
388 error_handler.report_vtct0a_error (current_class, a_type)
389 else
390 -- TODO: this error should have already been reported when processing `current_class_impl'.
391 error_handler.report_vtct0a_error (current_class_impl, a_type)
392 end
393 end
394 else
395 a_class.process (current_system.interface_checker)
396 if not a_class.interface_checked then
397 set_fatal_error
398 elseif a_class.has_interface_error then
399 -- Error should already have been
400 -- reported somewhere else.
401 set_fatal_error
402 elseif not a_class.is_generic then
403 if a_type.is_generic then
404 set_fatal_error
405 if not class_interface_error_only then
406 if current_class = current_class_impl then
407 error_handler.report_vtug1a_error (current_class, a_type)
408 else
409 -- TODO: this error should have already been reported when processing `current_class_impl'.
410 error_handler.report_vtug1a_error (current_class_impl, a_type)
411 end
412 end
413 end
414 else
415 if current_class = current_class_impl then
416 a_type.resolve_unfolded_tuple_actual_parameters_1 (current_universe)
417 end
418 l_actuals := a_type.actual_parameters
419 if not a_type.is_generic then
420 set_fatal_error
421 if not class_interface_error_only then
422 if current_class = current_class_impl then
423 error_handler.report_vtug2a_error (current_class, a_type)
424 else
425 -- TODO: this error should have already been reported when processing `current_class_impl'.
426 error_handler.report_vtug2a_error (current_class_impl, a_type)
427 end
428 end
429 elseif not attached a_class.formal_parameters as a_formals then
430 -- Internal error: `a_class' is generic.
431 set_fatal_error
432 error_handler.report_giaaa_error
433 elseif l_actuals = Void then
434 -- Internal error: `a_type' is generic.
435 set_fatal_error
436 error_handler.report_giaaa_error
437 else
438 if l_actuals.count /= a_formals.count then
439 set_fatal_error
440 if not class_interface_error_only then
441 if current_class = current_class_impl then
442 error_handler.report_vtug2a_error (current_class, a_type)
443 else
444 -- TODO: this error should have already been reported when processing `current_class_impl'.
445 error_handler.report_vtug2a_error (current_class_impl, a_type)
446 end
447 end
448 else
449 nb := l_actuals.count
450 -- We need to process all actual parameters (and hence finish performing
451 -- all Tuple-type-unfolding) before trying to run the second phase of
452 -- Tuple-type-unfolding. Indeed, we might have a case like
453 -- that:
454 --
455 -- class AA [G -> TUPLE [H], H]
456 --
457 -- a: AA [TUPLE [PROCEDURE [TUPLE [BB]]], PROCEDURE [BB]]
458 --
459 -- This should be resolved as:
460 --
461 -- a: AA [TUPLE [PROCEDURE [TUPLE [BB]]], PROCEDURE [TUPLE [BB]]]
462 --
463 -- But if we had not processed the second actual parameter of AA beforehand,
464 -- we would have ended up with this erroneously resolved type:
465 --
466 -- a: AA [TUPLE [TUPLE [PROCEDURE [TUPLE [BB]]]], PROCEDURE [TUPLE [BB]]]
467 --
468 -- which is not valid. Hence the two loops below.
469 from i := 1 until i > nb loop
470 an_actual := l_actuals.type (i)
471 had_error := has_fatal_error
472 an_actual.process (Current)
473 reset_fatal_error (has_fatal_error or had_error)
474 i := i + 1
475 end
476 from i := 1 until i > nb loop
477 an_actual := l_actuals.type (i)
478 a_formal := a_formals.formal_parameter (i)
479 if a_formal.is_expanded then
480 if not an_actual.is_type_expanded (current_context) then
481 set_fatal_error
482 if not class_interface_error_only then
483 error_handler.report_gvtcg5b_error (current_class, current_class_impl, a_type, an_actual, a_formal)
484 end
485 end
486 elseif a_formal.is_reference then
487 if not an_actual.is_type_reference (current_context) then
488 set_fatal_error
489 if not class_interface_error_only then
490 error_handler.report_gvtcg5a_error (current_class, current_class_impl, a_type, an_actual, a_formal)
491 end
492 end
493 end
494 a_constraint := a_formal.constraint
495 if a_constraint = Void then
496 a_constraint := current_system.detachable_any_type
497 end
498 -- If we have:
499 --
500 -- class A [G, H -> LIST [G]] ...
501 -- class X feature foo: A [ANY, LIST [STRING]] ...
502 --
503 -- we need to check that "LIST [STRING]" conforms to
504 -- "LIST [ANY]", not just "LIST [G]".
505 -- Likewise if we have:
506 --
507 -- class A [G -> LIST [G]] ...
508 -- class X feature foo: A [LIST [FOO]] ...
509 --
510 -- we need to check that "LIST [FOO]" conforms to
511 -- "LIST [LIST [FOO]]", not just "LIST [G]".
512 constraint_context.set (a_type, current_context.root_context)
513 l_conforms := an_actual.conforms_to_type (a_constraint, constraint_context, current_context)
514 if not l_conforms then
515 if current_class = current_class_impl and then a_class.tuple_constraint_position = i then
516 a_type.resolve_unfolded_tuple_actual_parameters_2 (current_context, constraint_context)
517 if attached a_type.actual_parameters as l_actual_parameters and then l_actual_parameters /= l_actuals then
518 l_actuals := l_actual_parameters
519 an_actual := l_actuals.type (i)
520 l_conforms := an_actual.conforms_to_type (a_constraint, constraint_context, current_context)
521 end
522 end
523 end
524 if not l_conforms then
525 -- The actual parameter does not conform to the
526 -- constraint of its corresponding formal parameter.
527 --
528 -- Note that it is possible that the actual paramater conforms
529 -- to the constraint in `current_class_impl' but not in `current_class'.
530 -- Here is an example:
531 --
532 -- class A
533 -- feature
534 -- y: Y [like Current, X [A]]
535 -- end
536 --
537 -- class B
538 -- inherit
539 -- A
540 -- end
541 --
542 -- class X
543 -- end
544 --
545 -- class Y [G, H -> X [G]]
546 -- end
547 --
548 -- In class B the actual generic parameter 'X [A]' does not conform
549 -- to its constraint 'X [like Current]'.
550 set_fatal_error
551 if not class_interface_error_only then
552 error_handler.report_vtcg3a_error (current_class, current_class_impl, a_type, an_actual, a_constraint)
553 end
554 end
555 i := i + 1
556 end
557 end
558 end
559 end
560 end
561 end
562
563 check_like_current_validity (a_type: ET_LIKE_CURRENT)
564 -- Check validity of `a_type'.
565 -- Set `has_fatal_error' if a fatal error occurred.
566 require
567 a_type_not_void: a_type /= Void
568 -- no_cycle: no cycle in anchored types involved.
569 do
570 has_fatal_error := False
571 -- No validity rule to be checked.
572 end
573
574 check_like_feature_validity (a_type: ET_LIKE_FEATURE)
575 -- Check validity of `a_type'.
576 -- Resolve identifer in 'like identifier' if not already done.
577 -- Set `has_fatal_error' if a fatal error occurred.
578 require
579 a_type_not_void: a_type /= Void
580 -- no_cycle: no cycle in anchored types involved.
581 local
582 l_seed: INTEGER
583 l_name: ET_FEATURE_NAME
584 args: detachable ET_FORMAL_ARGUMENT_LIST
585 l_index: INTEGER
586 resolved: BOOLEAN
587 do
588 has_fatal_error := False
589 l_seed := a_type.seed
590 if l_seed = 0 then
591 -- Not resolved yet. It needs to be resolved
592 -- in the implementation class first.
593 if current_class /= current_class_impl then
594 -- Internal error: it should have been resolved in
595 -- the implementation class.
596 set_fatal_error
597 error_handler.report_giaaa_error
598 else
599 current_class.process (current_system.interface_checker)
600 if not current_class.interface_checked or else current_class.has_interface_error then
601 set_fatal_error
602 else
603 l_name := a_type.name
604 if attached current_class.named_query (l_name) as l_query then
605 -- This is a 'like feature'.
606 a_type.resolve_like_feature (l_query)
607 if in_qualified_anchored_type then
608 if current_system.qualified_anchored_types_cycle_detection_enabled then
609 if l_query.type.depends_on_qualified_anchored_type (current_class) then
610 -- Error: the type of the anchor appearing in a qualified
611 -- anchored type should not depend on a qualified anchored type.
612 -- This is a way to avoid cycles in qualified anchored types.
613 set_fatal_error
614 if not class_interface_error_only then
615 error_handler.report_vtat2b_error (current_class, current_class_impl, a_type)
616 end
617 end
618 end
619 end
620 else
621 -- This has to be a 'like argument', otherwise this is an error.
622 -- Note that 'like argument' is not a valid construct in ECMA Eiffel.
623 -- This is supported here for backward compatibility.
624 if attached {ET_FEATURE} current_feature_impl as l_feature then
625 if attached {ET_IDENTIFIER} l_name as l_argument_name then
626 args := l_feature.arguments
627 if args /= Void then
628 l_index := args.index_of (l_argument_name)
629 if l_index /= 0 then
630 l_argument_name.set_seed (l_index)
631 l_argument_name.set_argument (True)
632 a_type.resolve_like_argument (l_feature)
633 resolved := True
634 if in_qualified_anchored_type then
635 if current_system.qualified_anchored_types_cycle_detection_enabled then
636 if args.item (l_index).type.depends_on_qualified_anchored_type (current_class) then
637 -- Error: the type of the anchor appearing in a qualified
638 -- anchored type should not depend on a qualified anchored type.
639 -- This is a way to avoid cycles in qualified anchored types.
640 set_fatal_error
641 if not class_interface_error_only then
642 error_handler.report_vtat2b_error (current_class, current_class_impl, a_type)
643 end
644 end
645 end
646 end
647 end
648 end
649 end
650 if not resolved then
651 set_fatal_error
652 if not class_interface_error_only then
653 error_handler.report_vtat1b_error (current_class, l_feature, a_type)
654 end
655 end
656 else
657 -- 'like argument' not valid in inline agents and invariants.
658 set_fatal_error
659 if not class_interface_error_only then
660 error_handler.report_vtat1a_error (current_class, a_type)
661 end
662 end
663 end
664 end
665 end
666 elseif in_qualified_anchored_type then
667 if l_seed /= 0 then
668 -- Anchored type already resolved.
669 if a_type.is_like_argument then
670 if attached current_class.seeded_feature (l_seed) as l_feature then
671 args := l_feature.arguments
672 l_index := a_type.index
673 if args /= Void and then l_index <= args.count then
674 if current_system.qualified_anchored_types_cycle_detection_enabled then
675 if args.item (l_index).type.depends_on_qualified_anchored_type (current_class) then
676 -- Error: the type of the anchor appearing in a qualified
677 -- anchored type should not depend on a qualified anchored type.
678 -- This is a way to avoid cycles in qualified anchored types.
679 set_fatal_error
680 if not class_interface_error_only then
681 error_handler.report_vtat2b_error (current_class, current_class_impl, a_type)
682 end
683 end
684 end
685 else
686 -- Internal error: it was already checked in previous compilation
687 -- pass that we had enough arguments. Even if this is a redeclaration,
688 -- signature conformance of the redeclaration imposes that the
689 -- number of arguments does not change.
690 set_fatal_error
691 error_handler.report_giaaa_error
692 end
693 else
694 -- Internal error: if we got a seed, then `l_feature' should not be void.
695 set_fatal_error
696 error_handler.report_giaaa_error
697 end
698 else
699 if attached current_class.seeded_query (l_seed) as l_query then
700 if current_system.qualified_anchored_types_cycle_detection_enabled then
701 if l_query.type.depends_on_qualified_anchored_type (current_class) then
702 -- Error: the type of the anchor appearing in a qualified
703 -- anchored type should not depend on a qualified anchored type.
704 -- This is a way to avoid cycles in qualified anchored types.
705 set_fatal_error
706 if not class_interface_error_only then
707 error_handler.report_vtat2b_error (current_class, current_class_impl, a_type)
708 end
709 end
710 end
711 else
712 -- Internal error: if we got a seed, then `l_query' should not be void.
713 set_fatal_error
714 error_handler.report_giaaa_error
715 end
716 end
717 else
718 -- Internal error: the anchored type should have been resolved by the feature flattener.
719 set_fatal_error
720 error_handler.report_giaaa_error
721 end
722 end
723 end
724
725 check_qualified_like_identifier_validity (a_type: ET_QUALIFIED_LIKE_IDENTIFIER)
726 -- Check validity of `a_type'.
727 -- Resolve 'identifier' in 'like identifier.b', 'like a.identifier'
728 -- or 'like {A}.identifier' if not already done.
729 -- Set `has_fatal_error' if a fatal error occurred.
730 require
731 a_type_not_void: a_type /= Void
732 -- no_cycle: no cycle in anchored types involved.
733 local
734 l_seed: INTEGER
735 l_target_type: ET_TYPE
736 l_class: ET_CLASS
737 old_in_qualified_anchored_type: BOOLEAN
738 do
739 has_fatal_error := False
740 old_in_qualified_anchored_type := in_qualified_anchored_type
741 in_qualified_anchored_type := True
742 l_target_type := a_type.target_type
743 l_target_type.process (Current)
744 if not has_fatal_error then
745 report_qualified_anchored_type_supplier (l_target_type, current_context.root_context)
746 l_seed := a_type.seed
747 if l_seed = 0 then
748 -- Not resolved yet. It needs to be resolved
749 -- in the implementation class first.
750 if current_class /= current_class_impl then
751 -- Internal error: it should have been resolved in
752 -- the implementation class.
753 set_fatal_error
754 error_handler.report_giaaa_error
755 else
756 l_class := l_target_type.base_class (current_context)
757 l_class.process (current_system.interface_checker)
758 if not l_class.interface_checked or else l_class.has_interface_error then
759 set_fatal_error
760 else
761 if attached l_class.named_query (a_type.name) as l_query then
762 a_type.resolve_identifier_type (l_query.first_seed)
763 -- TODO: check that `l_query' is exported to `current_class'.
764 if current_system.qualified_anchored_types_cycle_detection_enabled then
765 if l_query.type.depends_on_qualified_anchored_type (l_class) then
766 -- Error: the type of the anchor appearing in a qualified
767 -- anchored type should not depend on a qualified anchored type.
768 -- This is a way to avoid cycles in qualified anchored types.
769 set_fatal_error
770 if not class_interface_error_only then
771 error_handler.report_vtat2b_error (current_class, current_class_impl, a_type)
772 end
773 end
774 end
775 else
776 -- Error: there is no query with this final name.
777 set_fatal_error
778 if not class_interface_error_only then
779 error_handler.report_vtat1c_error (current_class, a_type, l_class)
780 end
781 end
782 end
783 end
784 else
785 l_class := l_target_type.base_class (current_context)
786 l_class.process (current_system.interface_checker)
787 if not l_class.interface_checked or else l_class.has_interface_error then
788 set_fatal_error
789 else
790 if attached l_class.seeded_query (l_seed) as l_query then
791 -- TODO: check that `l_query' is exported to `current_class'.
792 if current_system.qualified_anchored_types_cycle_detection_enabled then
793 if l_query.type.depends_on_qualified_anchored_type (l_class) then
794 -- Error: the type of the anchor appearing in a qualified
795 -- anchored type should not depend on a qualified anchored type.
796 -- This is a way to avoid cycles in qualified anchored types.
797 set_fatal_error
798 if not class_interface_error_only then
799 error_handler.report_vtat2b_error (current_class, current_class_impl, a_type)
800 end
801 end
802 end
803 else
804 -- Internal error: if we got a seed, then `l_query' should not be void.
805 set_fatal_error
806 error_handler.report_giaaa_error
807 end
808 end
809 end
810 end
811 in_qualified_anchored_type := old_in_qualified_anchored_type
812 end
813
814 check_tuple_type_validity (a_type: ET_TUPLE_TYPE)
815 -- Check validity of `a_type'.
816 -- Set `has_fatal_error' if a fatal error occurred.
817 require
818 a_type_not_void: a_type /= Void
819 -- no_cycle: no cycle in anchored types involved.
820 local
821 i, nb: INTEGER
822 had_error: BOOLEAN
823 do
824 has_fatal_error := False
825 -- TODO: should we check whether class TUPLE is in the universe or not?
826 if attached a_type.actual_parameters as a_parameters then
827 nb := a_parameters.count
828 from i := 1 until i > nb loop
829 a_parameters.type (i).process (Current)
830 if has_fatal_error then
831 had_error := True
832 end
833 i := i + 1
834 end
835 end
836 reset_fatal_error (had_error)
837 end
838
839 feature -- Error reporting
840
841 class_interface_error_only: BOOLEAN
842 -- Should only the errors found when checking class interface (and before) be reported?
843
844 set_class_interface_error_only (b: BOOLEAN)
845 -- Set `class_interface_error_only' to `b'.
846 do
847 class_interface_error_only := b
848 ensure
849 class_interface_error_only_set: class_interface_error_only = b
850 end
851
852 feature -- Client/Supplier relationship
853
854 supplier_handler: detachable ET_SUPPLIER_HANDLER
855 -- Supplier handler
856
857 set_supplier_handler (a_handler: like supplier_handler)
858 -- Set `supplier_handler' to `a_handler'.
859 do
860 supplier_handler := a_handler
861 ensure
862 supplier_handler_set: supplier_handler = a_handler
863 end
864
865 feature {NONE} -- Client/Supplier relationship
866
867 report_qualified_anchored_type_supplier (a_supplier: ET_TYPE; a_client: ET_BASE_TYPE)
868 -- Report the fact that `a_supplier' is the target type of a
869 -- qualified anchored type in a feature or invariant in type `a_client'.
870 -- (Note that `a_supplier' is assumed to be interpreted in
871 -- the context of `a_client'.)
872 require
873 a_supplier_not_void: a_supplier /= Void
874 a_client_not_void: a_client /= Void
875 a_client_valid: a_client.is_valid_context
876 do
877 if attached supplier_handler as l_supplier_handler then
878 l_supplier_handler.report_qualified_anchored_type_supplier (a_supplier, a_client)
879 end
880 end
881
882 feature {ET_AST_NODE} -- Type processing
883
884 process_class (a_type: ET_CLASS)
885 -- Process `a_type'.
886 do
887 process_class_type (a_type)
888 end
889
890 process_class_type (a_type: ET_CLASS_TYPE)
891 -- Process `a_type'.
892 do
893 check_class_type_validity (a_type)
894 end
895
896 process_like_current (a_type: ET_LIKE_CURRENT)
897 -- Process `a_type'.
898 do
899 check_like_current_validity (a_type)
900 end
901
902 process_like_feature (a_type: ET_LIKE_FEATURE)
903 -- Process `a_type'.
904 do
905 check_like_feature_validity (a_type)
906 end
907
908 process_qualified_like_braced_type (a_type: ET_QUALIFIED_LIKE_BRACED_TYPE)
909 -- Process `a_type'.
910 do
911 check_qualified_like_identifier_validity (a_type)
912 end
913
914 process_qualified_like_type (a_type: ET_QUALIFIED_LIKE_TYPE)
915 -- Process `a_type'.
916 do
917 check_qualified_like_identifier_validity (a_type)
918 end
919
920 process_tuple_type (a_type: ET_TUPLE_TYPE)
921 -- Process `a_type'.
922 do
923 check_tuple_type_validity (a_type)
924 end
925
926 feature {NONE} -- Access
927
928 current_feature_impl: ET_CLOSURE
929 -- Feature/invariant/inline agent where the type has been written
930
931 current_class_impl: ET_CLASS
932 -- Class where the type has been written
933 -- (May be different from `current_class' when the
934 -- code has been inherited from an ancestor)
935
936 current_context: ET_TYPE_CONTEXT
937 -- Context for the type being processed
938
939 in_qualified_anchored_type: BOOLEAN
940 -- Is the type being checked contained in a qualified anchored type?
941
942 feature {NONE} -- Implementation
943
944 constraint_context: ET_NESTED_TYPE_CONTEXT
945 -- Constraint context for type conformance checking
946
947 dummy_feature: ET_FEATURE
948 -- Dummy feature
949 local
950 a_name: ET_FEATURE_NAME
951 once
952 create {ET_IDENTIFIER} a_name.make ("**dummy**")
953 create {ET_DEFERRED_PROCEDURE} Result.make (a_name, Void, current_class)
954 ensure
955 dummy_feature_not_void: Result /= Void
956 end
957
958 invariant
959
960 current_class_impl_not_void: current_class_impl /= Void
961 current_context_not_void: current_context /= Void
962 valid_current_context: current_context.is_valid_context
963 current_context_root_context: current_context.is_root_context
964 current_class_definition: current_class = current_context.base_class
965 current_feature_impl_not_void: current_feature_impl /= Void
966 constraint_context_not_void: constraint_context /= Void
967
968 end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23