1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2008 Jean Privat <jean@pryen.org>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Analysis property bodies, statements and expressions
24 redef class MMSrcModule
25 # Walk trough the module and type statments and expressions
26 # Require than supermodules are processed
27 fun do_typing
(tc
: ToolContext)
29 var tv
= new TypingVisitor(tc
, self)
35 # * Associate local variables to nodes
36 # * Distinguish method call and local variable access
37 # * Resolve call and attribute access
38 # * Check type conformance
39 private class TypingVisitor
40 special AbsSyntaxVisitor
43 if n
!= null then n
.accept_typing
(self)
46 # Current knowledge about variables names and types
47 fun variable_ctx
: VariableContext do return _variable_ctx
.as(not null)
48 writable var _variable_ctx
: nullable VariableContext
50 # Non-bypassable knowledge about variables names and types
51 fun base_variable_ctx
: VariableContext do return _base_variable_ctx
.as(not null)
52 writable var _base_variable_ctx
: nullable VariableContext
54 # Current knowledge about escapable blocks
55 readable writable var _escapable_ctx
: EscapableContext = new EscapableContext(self)
57 # The current reciever
58 fun self_var
: ParamVariable do return _self_var
.as(not null)
59 writable var _self_var
: nullable ParamVariable
61 # Block of the current method
62 readable writable var _top_block
: nullable PExpr
64 # List of explicit invocation of constructors of super-classes
65 readable writable var _explicit_super_init_calls
: nullable Array[MMMethod]
67 # Is a other constructor of the same class invoked
68 readable writable var _explicit_other_init_call
: Bool = false
70 # Make the if_true_variable_ctx of the expression effective
71 private fun use_if_true_variable_ctx
(e
: PExpr)
73 var ctx
= e
.if_true_variable_ctx
74 if ctx
!= null then variable_ctx
= ctx
77 # Make the if_false_variable_ctx of the expression effective
78 private fun use_if_false_variable_ctx
(e
: PExpr)
80 var ctx
= e
.if_false_variable_ctx
81 if ctx
!= null then variable_ctx
= ctx
84 # Number of nested once
85 readable writable var _once_count
: Int = 0
87 init(tc
, module) do super
89 private fun get_default_constructor_for
(n
: PNode, c
: MMLocalClass, prop
: MMSrcMethod): nullable MMMethod
92 #var prop = v.local_property
93 #assert prop isa MMMethod
94 var candidates
= new Array[MMMethod]
95 var false_candidates
= new Array[MMMethod]
96 var parity
= prop
.signature
.arity
97 for g
in c
.global_properties
do
98 if not g
.is_init_for
(c
) then continue
100 var gps
= gp
.signature_for
(c
.get_type
)
101 assert gp
isa MMSrcMethod
102 var garity
= gps
.arity
103 if gp
.name
== prop
.name
then
104 if garity
== 0 or (parity
== garity
and prop
.signature
< gps
) then
107 false_candidates
.add
(gp
)
109 else if garity
== 0 and gp
.name
== once
("init".to_symbol
) then
111 false_candidates
.add
(gp
)
113 false_candidates
.add
(gp
)
116 if candidates
.length
== 1 then
117 return candidates
.first
118 else if candidates
.length
> 0 then
119 var a
= new Array[String]
120 for p
in candidates
do
121 a
.add
("{p.full_name}{p.signature}")
123 v
.error
(n
, "Error: Conflicting default constructor to call for {c}: {a.join(", ")}.")
125 else if false_candidates
.length
> 0 then
126 var a
= new Array[String]
127 for p
in false_candidates
do
128 a
.add
("{p.full_name}{p.signature}")
130 v
.error
(n
, "Error: there is no available compatible constrctor in {c}. Discarded candidates are {a.join(", ")}.")
133 v
.error
(n
, "Error: there is no available compatible constrctor in {c}.")
140 ###############################################################################
143 private fun accept_typing
(v
: TypingVisitor)
145 accept_abs_syntax_visitor
(v
)
148 private fun after_typing
(v
: TypingVisitor) do end
151 redef class PClassdef
152 redef fun accept_typing
(v
)
154 v
.self_var
= new ParamVariable("self".to_symbol
, self)
155 v
.self_var
.stype
= local_class
.get_type
160 redef class AAttrPropdef
161 redef fun accept_typing
(v
)
164 if n_expr
!= null then
165 v
.check_conform_expr
(n_expr
.as(not null), prop
.signature
.return_type
.as(not null))
170 redef class AMethPropdef
171 redef fun self_var
do return _self_var
.as(not null)
172 var _self_var
: nullable ParamVariable
173 redef fun accept_typing
(v
)
175 v
.variable_ctx
= new RootVariableContext(v
, self)
176 v
.base_variable_ctx
= v
.variable_ctx
177 _self_var
= v
.self_var
182 redef class AConcreteMethPropdef
183 redef fun accept_typing
(v
)
186 if v
.variable_ctx
.unreash
== false and method
.signature
.return_type
!= null then
187 v
.error
(self, "Control error: Reached end of function (a 'return' with a value was expected).")
192 redef class AConcreteInitPropdef
193 readable var _super_init_calls
: Array[MMMethod] = new Array[MMMethod]
194 readable var _explicit_super_init_calls
: Array[MMMethod] = new Array[MMMethod]
195 redef fun accept_typing
(v
)
197 v
.top_block
= n_block
198 v
.explicit_super_init_calls
= explicit_super_init_calls
199 v
.explicit_other_init_call
= false
201 if v
.explicit_other_init_call
or method
.global
.intro
!= method
then
205 var l
= explicit_super_init_calls
.length
206 var cur_m
: nullable MMMethod = null
207 var cur_c
: nullable MMLocalClass = null
209 cur_m
= explicit_super_init_calls
[i
]
210 cur_c
= cur_m
.global
.intro
.local_class
.for_module
(v
.module)
213 while j
< v
.local_class
.cshe
.direct_greaters
.length
do
214 var c
= v
.local_class
.cshe
.direct_greaters
[j
]
215 if c
.global
.is_interface
or c
.global
.is_universal
or c
.global
.is_mixin
then
217 else if cur_c
!= null and (c
.cshe
<= cur_c
or cur_c
.global
.is_mixin
) then
218 if c
== cur_c
then j
+= 1
219 super_init_calls
.add
(cur_m
.as(not null))
222 cur_m
= explicit_super_init_calls
[i
]
223 cur_c
= cur_m
.global
.intro
.local_class
.for_module
(v
.module)
229 var p
= v
.get_default_constructor_for
(self, c
, method
)
231 super_init_calls
.add
(p
)
241 redef fun after_typing
(v
)
243 v
.variable_ctx
.add
(variable
)
247 redef class AClosureDecl
248 # The corresponding escapable object
249 readable var _escapable
: nullable EscapableBlock
251 redef fun accept_typing
(v
)
253 # Register the closure for ClosureCallExpr
254 v
.variable_ctx
.add
(variable
)
256 var old_var_ctx
= v
.variable_ctx
257 var old_base_var_ctx
= v
.base_variable_ctx
258 v
.base_variable_ctx
= v
.variable_ctx
259 v
.variable_ctx
= v
.variable_ctx
.sub
(self)
261 var escapable
= new EscapableClosure(self, variable
.closure
, null)
262 _escapable
= escapable
263 v
.escapable_ctx
.push
(escapable
)
267 if n_expr
!= null then
268 if v
.variable_ctx
.unreash
== false then
269 if variable
.closure
.signature
.return_type
!= null then
270 v
.error
(self, "Control error: Reached end of block (a 'continue' with a value was expected).")
271 else if variable
.closure
.is_break
then
272 v
.error
(self, "Control error: Reached end of break block (an 'abort' was expected).")
277 old_var_ctx
.merge
(v
.variable_ctx
)
278 v
.variable_ctx
= old_var_ctx
279 v
.base_variable_ctx
= old_base_var_ctx
285 fun stype
: MMType do return _stype
.as(not null)
286 var _stype
: nullable MMType
288 redef fun after_typing
(v
)
290 _stype
= get_stype
(v
)
295 redef readable var _is_typed
: Bool = false
296 redef fun is_statement
: Bool do return _stype
== null
300 print
"{locate}: not is_typed"
304 print
"{locate}: is_statement"
307 return _stype
.as(not null)
309 var _stype
: nullable MMType
311 # Is the expression the implicit receiver
312 fun is_implicit_self
: Bool do return false
314 # Is the expression the current receiver (implicit or explicit)
315 fun is_self
: Bool do return false
317 # The variable accessed is any
318 fun its_variable
: nullable Variable do return null
320 # The variable type information if current boolean expression is true
321 readable private var _if_true_variable_ctx
: nullable VariableContext
323 # The variable type information if current boolean expression is false
324 readable private var _if_false_variable_ctx
: nullable VariableContext
327 redef class AVardeclExpr
328 var _variable
: nullable VarVariable
329 redef fun variable
do return _variable
.as(not null)
331 redef fun after_typing
(v
)
333 var va
= new VarVariable(n_id
.to_symbol
, self)
335 v
.variable_ctx
.add
(va
)
336 if n_expr
!= null then v
.variable_ctx
.mark_is_set
(va
)
338 if n_type
!= null then
339 va
.stype
= n_type
.stype
340 if n_expr
!= null then
341 v
.check_conform_expr
(n_expr
.as(not null), va
.stype
)
344 if not v
.check_expr
(n_expr
.as(not null)) then return
345 va
.stype
= n_expr
.stype
351 redef class ABlockExpr
352 redef fun accept_typing
(v
)
354 var old_var_ctx
= v
.variable_ctx
355 v
.variable_ctx
= v
.variable_ctx
.sub
(self)
358 if v
.variable_ctx
.unreash
and not v
.variable_ctx
.already_unreash
then
359 v
.variable_ctx
.already_unreash
= true
360 v
.warning
(e
, "Warning: unreachable statement.")
365 old_var_ctx
.merge
(v
.variable_ctx
)
366 v
.variable_ctx
= old_var_ctx
371 redef class AReturnExpr
372 redef fun after_typing
(v
)
374 v
.variable_ctx
.unreash
= true
375 var t
= v
.local_property
.signature
.return_type
377 if e
== null and t
!= null then
378 v
.error
(self, "Error: Return without value in a function.")
379 else if e
!= null and t
== null then
380 v
.error
(self, "Error: Return with value in a procedure.")
381 else if e
!= null and t
!= null then
382 v
.check_conform_expr
(e
, t
)
388 redef class AContinueExpr
389 redef fun after_typing
(v
)
391 v
.variable_ctx
.unreash
= true
392 var esc
= compute_escapable_block
(v
.escapable_ctx
)
393 if esc
== null then return
395 if esc
.is_break_block
then
396 v
.error
(self, "Error: 'continue' forbiden in break blocks.")
400 var t
= esc
.continue_stype
401 if n_expr
== null and t
!= null then
402 v
.error
(self, "Error: continue with a value required in this block.")
403 else if n_expr
!= null and t
== null then
404 v
.error
(self, "Error: continue without value required in this block.")
405 else if n_expr
!= null and t
!= null then
406 v
.check_conform_expr
(n_expr
.as(not null), t
)
412 redef class ABreakExpr
413 redef fun after_typing
(v
)
415 v
.variable_ctx
.unreash
= true
416 var esc
= compute_escapable_block
(v
.escapable_ctx
)
417 if esc
== null then return
419 var bl
= esc
.break_list
420 if n_expr
== null and bl
!= null then
421 v
.error
(self, "Error: break with a value required in this block.")
422 else if n_expr
!= null and bl
== null then
423 v
.error
(self, "Error: break without value required in this block.")
424 else if n_expr
!= null and bl
!= null then
425 # Typing check can only be done later
426 bl
.add
(n_expr
.as(not null))
432 redef class AAbortExpr
433 redef fun after_typing
(v
)
435 v
.variable_ctx
.unreash
= true
440 redef fun accept_typing
(v
)
442 var old_var_ctx
= v
.variable_ctx
444 v
.check_conform_expr
(n_expr
, v
.type_bool
)
446 # Prepare 'then' context
447 v
.use_if_true_variable_ctx
(n_expr
)
450 if n_then
!= null then
451 v
.variable_ctx
= v
.variable_ctx
.sub
(n_then
.as(not null))
455 # Remember what appened in the 'then'
456 var then_var_ctx
= v
.variable_ctx
458 # Prepare 'else' context
459 v
.variable_ctx
= old_var_ctx
460 v
.use_if_false_variable_ctx
(n_expr
)
463 if n_else
!= null then
464 v
.variable_ctx
= v
.variable_ctx
.sub
(n_else
.as(not null))
468 # Merge 'then' and 'else' contexts
469 old_var_ctx
.merge2
(then_var_ctx
, v
.variable_ctx
, v
.base_variable_ctx
)
470 v
.variable_ctx
= old_var_ctx
475 redef class AWhileExpr
476 # The corresponding escapable block
477 readable var _escapable
: nullable EscapableBlock
479 redef fun accept_typing
(v
)
481 var escapable
= new EscapableBlock(self)
482 _escapable
= escapable
483 v
.escapable_ctx
.push
(escapable
)
484 var old_var_ctx
= v
.variable_ctx
485 var old_base_var_ctx
= v
.base_variable_ctx
486 v
.base_variable_ctx
= v
.variable_ctx
487 v
.variable_ctx
= v
.variable_ctx
.sub
(self)
491 v
.check_conform_expr
(n_expr
, v
.type_bool
)
493 # Prepare inside context (assert cond)
494 v
.use_if_true_variable_ctx
(n_expr
)
497 if n_block
!= null then
498 v
.variable_ctx
= v
.variable_ctx
.sub
(n_block
.as(not null))
502 v
.variable_ctx
= old_var_ctx
503 v
.base_variable_ctx
= old_base_var_ctx
510 var _variable
: nullable AutoVariable
511 redef fun variable
do return _variable
.as(not null)
513 # The corresponding escapable block
514 readable var _escapable
: nullable EscapableBlock
516 var _meth_iterator
: nullable MMMethod
517 fun meth_iterator
: MMMethod do return _meth_iterator
.as(not null)
518 var _meth_is_ok
: nullable MMMethod
519 fun meth_is_ok
: MMMethod do return _meth_is_ok
.as(not null)
520 var _meth_item
: nullable MMMethod
521 fun meth_item
: MMMethod do return _meth_item
.as(not null)
522 var _meth_next
: nullable MMMethod
523 fun meth_next
: MMMethod do return _meth_next
.as(not null)
524 redef fun accept_typing
(v
)
526 var escapable
= new EscapableBlock(self)
527 _escapable
= escapable
528 v
.escapable_ctx
.push
(escapable
)
530 var old_var_ctx
= v
.variable_ctx
531 var old_base_var_ctx
= v
.base_variable_ctx
532 v
.base_variable_ctx
= v
.variable_ctx
533 v
.variable_ctx
= v
.variable_ctx
.sub
(self)
534 var va
= new AutoVariable(n_id
.to_symbol
, self)
536 v
.variable_ctx
.add
(va
)
540 if not v
.check_conform_expr
(n_expr
, v
.type_collection
) then return
541 var expr_type
= n_expr
.stype
543 _meth_iterator
= expr_type
.local_class
.select_method
(once
("iterator".to_symbol
))
544 if _meth_iterator
== null then
545 v
.error
(self, "Error: Collection MUST have an iterate method")
548 var iter_type
= _meth_iterator
.signature_for
(expr_type
).return_type
.as(not null)
549 _meth_is_ok
= iter_type
.local_class
.select_method
(once
("is_ok".to_symbol
))
550 if _meth_is_ok
== null then
551 v
.error
(self, "Error: {iter_type} MUST have an is_ok method")
554 _meth_item
= iter_type
.local_class
.select_method
(once
("item".to_symbol
))
555 if _meth_item
== null then
556 v
.error
(self, "Error: {iter_type} MUST have an item method")
559 _meth_next
= iter_type
.local_class
.select_method
(once
("next".to_symbol
))
560 if _meth_next
== null then
561 v
.error
(self, "Error: {iter_type} MUST have a next method")
564 var t
= _meth_item
.signature_for
(iter_type
).return_type
565 if not n_expr
.is_self
then t
= t
.not_for_self
568 if n_block
!= null then v
.visit
(n_block
)
571 v
.variable_ctx
= old_var_ctx
572 v
.base_variable_ctx
= old_base_var_ctx
578 redef class AAssertExpr
579 redef fun after_typing
(v
)
581 v
.check_conform_expr
(n_expr
, v
.type_bool
)
582 v
.use_if_true_variable_ctx
(n_expr
)
587 redef class AVarFormExpr
588 var _variable
: nullable Variable
589 redef fun variable
do return _variable
.as(not null)
593 redef fun its_variable
do return variable
595 redef fun after_typing
(v
)
597 v
.variable_ctx
.check_is_set
(self, variable
)
598 _stype
= v
.variable_ctx
.stype
(variable
)
599 _is_typed
= _stype
!= null
603 redef class AVarAssignExpr
604 redef fun after_typing
(v
)
606 v
.variable_ctx
.mark_is_set
(variable
)
607 var t
= v
.variable_ctx
.stype
(variable
)
609 # Check the base type
610 var btype
= v
.base_variable_ctx
.stype
(variable
)
611 if not v
.check_conform_expr
(n_value
, btype
) then return
614 v
.variable_ctx
.stype
(variable
) = n_value
.stype
620 redef class AReassignFormExpr
621 # Compute and check method used through the reassigment operator
622 # On success return the static type of the result of the reassigment operator
623 # Else display an error and return null
624 private fun do_rvalue_typing
(v
: TypingVisitor, type_lvalue
: nullable MMType): nullable MMType
626 if type_lvalue
== null then
629 var name
= n_assign_op
.method_name
630 var lc
= type_lvalue
.local_class
631 if not lc
.has_global_property_by_name
(name
) then
632 v
.error
(self, "Error: Method '{name}' doesn't exists in {type_lvalue}.")
635 var prop
= lc
.select_method
(name
)
636 prop
.global
.check_visibility
(v
, self, v
.module, false)
637 var psig
= prop
.signature_for
(type_lvalue
)
638 _assign_method
= prop
639 if not v
.check_conform_expr
(n_value
, psig
[0].not_for_self
) then return null
640 return psig
.return_type
.not_for_self
643 # Method used through the reassigment operator (once computed)
644 readable var _assign_method
: nullable MMMethod
647 redef class AVarReassignExpr
648 redef fun after_typing
(v
)
650 v
.variable_ctx
.check_is_set
(self, variable
)
651 v
.variable_ctx
.mark_is_set
(variable
)
652 var t
= v
.variable_ctx
.stype
(variable
)
653 var t2
= do_rvalue_typing
(v
, t
)
654 if t2
== null then return
656 # Check the base type
657 var btype
= v
.base_variable_ctx
.stype
(variable
)
658 if not v
.check_conform
(n_value
, t2
, btype
) then return
661 v
.variable_ctx
.stype
(variable
) = t2
667 redef class PAssignOp
668 fun method_name
: Symbol is abstract
670 redef class APlusAssignOp
671 redef fun method_name
do return once
"+".to_symbol
673 redef class AMinusAssignOp
674 redef fun method_name
do return once
"-".to_symbol
677 redef class ASelfExpr
678 var _variable
: nullable ParamVariable
679 redef fun variable
do return _variable
.as(not null)
681 redef fun its_variable
do return variable
683 redef fun after_typing
(v
)
685 _variable
= v
.self_var
686 _stype
= v
.variable_ctx
.stype
(variable
)
690 redef fun is_self
do return true
693 redef class AImplicitSelfExpr
694 redef fun is_implicit_self
do return true
697 redef class AIfexprExpr
698 redef fun accept_typing
(v
)
700 var old_var_ctx
= v
.variable_ctx
703 v
.use_if_true_variable_ctx
(n_expr
)
705 v
.variable_ctx
= old_var_ctx
706 v
.use_if_false_variable_ctx
(n_expr
)
709 v
.check_conform_expr
(n_expr
, v
.type_bool
)
711 _stype
= v
.check_conform_multiexpr
(null, [n_then
, n_else
])
712 _is_typed
= _stype
!= null
716 redef class ABoolExpr
717 redef fun after_typing
(v
)
725 redef fun accept_typing
(v
)
727 var old_var_ctx
= v
.variable_ctx
730 v
.use_if_false_variable_ctx
(n_expr
)
733 if n_expr2
.if_false_variable_ctx
!= null then
734 _if_false_variable_ctx
= n_expr2
.if_false_variable_ctx
736 _if_false_variable_ctx
= v
.variable_ctx
739 v
.variable_ctx
= old_var_ctx
741 v
.check_conform_expr
(n_expr
, v
.type_bool
)
742 v
.check_conform_expr
(n_expr2
, v
.type_bool
)
749 redef fun accept_typing
(v
)
751 var old_var_ctx
= v
.variable_ctx
754 v
.use_if_true_variable_ctx
(n_expr
)
757 if n_expr2
.if_true_variable_ctx
!= null then
758 _if_true_variable_ctx
= n_expr2
.if_true_variable_ctx
760 _if_true_variable_ctx
= v
.variable_ctx
763 v
.variable_ctx
= old_var_ctx
765 v
.check_conform_expr
(n_expr
, v
.type_bool
)
766 v
.check_conform_expr
(n_expr2
, v
.type_bool
)
773 redef fun after_typing
(v
)
775 v
.check_conform_expr
(n_expr
, v
.type_bool
)
777 # Invert if_true/if_false information
778 _if_false_variable_ctx
= n_expr
._if_true_variable_ctx
779 _if_true_variable_ctx
= n_expr
._if_false_variable_ctx
787 redef fun after_typing
(v
)
794 redef class AFloatExpr
795 redef fun after_typing
(v
)
797 _stype
= v
.type_float
802 redef class ACharExpr
803 redef fun after_typing
(v
)
810 redef class AStringFormExpr
811 var _meth_with_native
: nullable MMMethod
812 fun meth_with_native
: MMMethod do return _meth_with_native
.as(not null)
813 redef fun after_typing
(v
)
815 _stype
= v
.type_string
817 _meth_with_native
= _stype
.local_class
.select_method
(once
"with_native".to_symbol
)
818 if _meth_with_native
== null then v
.error
(self, "{_stype} MUST have a with_native method.")
822 redef class ASuperstringExpr
823 fun meth_with_capacity
: MMMethod do return _meth_with_capacity
.as(not null)
824 var _meth_with_capacity
: nullable MMMethod
825 fun meth_add
: MMMethod do return _meth_add
.as(not null)
826 var _meth_add
: nullable MMMethod
827 fun meth_to_s
: MMMethod do return _meth_to_s
.as(not null)
828 var _meth_to_s
: nullable MMMethod
829 readable var _atype
: nullable MMType
830 redef fun after_typing
(v
)
832 var stype
= v
.type_string
834 var atype
= v
.type_array
(stype
)
836 _meth_with_capacity
= atype
.local_class
.select_method
(once
"with_capacity".to_symbol
)
837 if _meth_with_capacity
== null then v
.error
(self, "{_atype} MUST have a with_capacity method.")
838 _meth_add
= atype
.local_class
.select_method
(once
"add".to_symbol
)
839 if _meth_add
== null then v
.error
(self, "{_atype} MUST have an add method.")
840 _meth_to_s
= v
.type_object
.local_class
.select_method
(once
"to_s".to_symbol
)
841 if _meth_to_s
== null then v
.error
(self, "Object MUST have a to_s method.")
846 redef class ANullExpr
847 redef fun after_typing
(v
)
854 redef class AArrayExpr
855 fun meth_with_capacity
: MMMethod do return _meth_with_capacity
.as(not null)
856 var _meth_with_capacity
: nullable MMMethod
857 fun meth_add
: MMMethod do return _meth_add
.as(not null)
858 var _meth_add
: nullable MMMethod
860 redef fun after_typing
(v
)
862 var stype
= v
.check_conform_multiexpr
(null, n_exprs
)
863 if stype
!= null then do_typing
(v
, stype
)
866 private fun do_typing
(v
: TypingVisitor, element_type
: MMType)
868 _stype
= v
.type_array
(element_type
)
870 _meth_with_capacity
= _stype
.local_class
.select_method
(once
"with_capacity".to_symbol
)
871 if _meth_with_capacity
== null then v
.error
(self, "{_stype} MUST have a with_capacity method.")
872 _meth_add
= _stype
.local_class
.select_method
(once
"add".to_symbol
)
873 if _meth_add
== null then v
.error
(self, "{_stype} MUST have an add method.")
879 redef class ARangeExpr
880 fun meth_init
: MMMethod do return _meth_init
.as(not null)
881 var _meth_init
: nullable MMMethod
882 redef fun after_typing
(v
)
884 if not v
.check_expr
(n_expr
) or not v
.check_expr
(n_expr2
) then return
885 var ntype
= n_expr
.stype
886 var ntype2
= n_expr2
.stype
887 if ntype
< ntype2
then
889 else if not ntype2
< ntype
then
890 v
.error
(self, "Type error: {ntype} incompatible with {ntype2}.")
893 var dtype
= v
.type_discrete
894 if not v
.check_conform_expr
(n_expr
, dtype
) or not v
.check_conform_expr
(n_expr2
, dtype
) then return
895 _stype
= v
.type_range
(ntype
)
900 redef class ACrangeExpr
901 redef fun after_typing
(v
)
904 _meth_init
= stype
.local_class
.select_method
(once
"init".to_symbol
)
907 redef class AOrangeExpr
908 redef fun after_typing
(v
)
911 _meth_init
= stype
.local_class
.select_method
(once
"without_last".to_symbol
)
916 redef class ASuperExpr
917 special ASuperInitCall
918 # readable var _prop: MMSrcMethod
919 readable var _init_in_superclass
: nullable MMMethod
920 redef fun after_typing
(v
)
922 var precs
: Array[MMLocalProperty] = v
.local_property
.prhe
.direct_greaters
923 if not precs
.is_empty
then
924 v
.local_property
.need_super
= true
925 else if v
.local_property
.global
.is_init
then
926 var base_precs
= v
.local_class
.super_methods_named
(v
.local_property
.name
)
927 for p
in base_precs
do
928 if not p
.global
.is_init
then
929 v
.error
(self, "Error: {p.local_class}::{p} is not a constructor.")
931 precs
.add
(v
.local_class
[p
.global
])
934 if precs
.is_empty
then
935 v
.error
(self, "Error: No contructor named {v.local_property.name} in superclasses.")
937 else if precs
.length
> 1 then
938 v
.error
(self, "Error: Conflicting contructors named {v.local_property.name} in superclasses: {precs.join(", ")}.")
941 var p
= base_precs
.first
942 assert p
isa MMMethod
943 _init_in_superclass
= p
944 register_super_init_call
(v
, p
)
945 if n_args
.length
> 0 then
946 var signature
= get_signature
(v
, v
.self_var
.stype
.as(not null), p
, true)
947 _arguments
= process_signature
(v
, signature
, p
.name
, n_args
.to_a
)
950 v
.error
(self, "Error: No super method to call for {v.local_property}.")
954 if precs
.first
.signature_for
(v
.self_var
.stype
.as(not null)).return_type
!= null then
955 var stypes
= new Array[MMType]
956 var stype
: nullable MMType = null
958 assert prop
isa MMMethod
959 var t
= prop
.signature_for
(v
.self_var
.stype
.as(not null)).return_type
.for_module
(v
.module).adapt_to
(v
.local_property
.signature
.recv
)
961 if stype
== null or stype
< t
then
966 v
.check_conform
(self, t
, stype
.as(not null))
970 var p
= v
.local_property
971 assert p
isa MMSrcMethod
977 redef class AAttrFormExpr
979 readable var _prop
: nullable MMAttribute
981 # Attribute type of the acceded attribute
982 readable var _attr_type
: nullable MMType
984 # Compute the attribute accessed
985 private fun do_typing
(v
: TypingVisitor)
987 if not v
.check_expr
(n_expr
) then return
988 var type_recv
= n_expr
.stype
989 var name
= n_id
.to_symbol
990 var lc
= type_recv
.local_class
991 if not lc
.has_global_property_by_name
(name
) then
992 v
.error
(self, "Error: Attribute {name} doesn't exists in {type_recv}.")
995 var prop
= lc
.select_attribute
(name
)
996 if v
.module.visibility_for
(prop
.global
.local_class
.module) < 3 then
997 v
.error
(self, "Error: Attribute {name} from {prop.global.local_class.module} is invisible in {v.module}")
1000 var at
= prop
.signature_for
(type_recv
).return_type
1001 if not n_expr
.is_self
then at
= at
.not_for_self
1006 redef class AAttrExpr
1007 redef fun after_typing
(v
)
1010 if prop
== null then return
1016 redef class AAttrAssignExpr
1017 redef fun after_typing
(v
)
1020 if prop
== null then return
1021 if not v
.check_conform_expr
(n_value
, attr_type
) then return
1026 redef class AAttrReassignExpr
1027 redef fun after_typing
(v
)
1030 if prop
== null then return
1031 var t
= do_rvalue_typing
(v
, attr_type
)
1032 if t
== null then return
1033 v
.check_conform
(self, t
, n_value
.stype
)
1038 redef class AIssetAttrExpr
1039 redef fun after_typing
(v
)
1042 if prop
== null then return
1043 if attr_type
.is_nullable
then
1044 v
.error
(self, "Error: isset on a nullable attribute.")
1046 _stype
= v
.type_bool
1051 class AAbsAbsSendExpr
1053 # The signature of the called property
1054 readable var _prop_signature
: nullable MMSignature
1056 # The real arguments used (after star transformation) (once computed)
1057 readable var _arguments
: nullable Array[PExpr]
1059 # Check the conformity of a set of arguments `raw_args' to a signature.
1060 private fun process_signature
(v
: TypingVisitor, psig
: MMSignature, name
: Symbol, raw_args
: nullable Array[PExpr]): nullable Array[PExpr]
1062 var par_vararg
= psig
.vararg_rank
1063 var par_arity
= psig
.arity
1065 if raw_args
== null then raw_arity
= 0 else raw_arity
= raw_args
.length
1066 if par_arity
> raw_arity
or (par_arity
!= raw_arity
and par_vararg
== -1) then
1067 v
.error
(self, "Error: '{name}' arity missmatch.")
1071 var args
= new Array[PExpr]
1072 for par_idx
in [0..par_arity
[ do
1074 var par_type
= psig
[par_idx
]
1075 if par_idx
== par_vararg
then
1076 var star
= new Array[PExpr]
1077 for i
in [0..(raw_arity-par_arity
)] do
1078 a
= raw_args
[arg_idx
]
1079 v
.check_conform_expr
(a
, par_type
)
1081 arg_idx
= arg_idx
+ 1
1083 var aa
= new AArrayExpr.init_aarrayexpr
(star
)
1084 aa
.do_typing
(v
, par_type
)
1087 a
= raw_args
[arg_idx
]
1088 v
.check_conform_expr
(a
, par_type
)
1089 arg_idx
= arg_idx
+ 1
1096 # Check the conformity of a set of defined closures
1097 private fun process_closures
(v
: TypingVisitor, psig
: MMSignature, name
: Symbol, cd
: nullable Array[PClosureDef]): nullable MMType
1099 var t
= psig
.return_type
1100 var cs
= psig
.closures
# Declared closures
1103 if not c
.is_optional
then min_arity
+= 1
1106 if cs
.length
== 0 then
1107 v
.error
(self, "Error: {name} does not require blocks.")
1108 else if cd
.length
> cs
.length
or cd
.length
< min_arity
then
1109 v
.error
(self, "Error: {name} requires {cs.length} blocks, {cd.length} found.")
1111 # Initialize the break list if a value is required for breaks (ie. if the method is a function)
1112 var break_list
: nullable Array[ABreakExpr] = null
1113 if t
!= null then break_list
= new Array[ABreakExpr]
1115 # Process each closure definition
1116 for i
in [0..cd
.length
[ do
1119 var esc
= new EscapableClosure(cdi
, csi
, break_list
)
1120 v
.escapable_ctx
.push
(esc
)
1121 cdi
.accept_typing2
(v
, esc
)
1125 # Check break type conformity
1126 if break_list
!= null then
1127 t
= v
.check_conform_multiexpr
(t
, break_list
)
1130 else if min_arity
!= 0 then
1131 v
.error
(self, "Error: {name} requires {cs.length} blocks.")
1138 special AAbsAbsSendExpr
1139 # Compute the called global property
1140 private fun do_typing
(v
: TypingVisitor, type_recv
: MMType, is_implicit_self
: Bool, recv_is_self
: Bool, name
: Symbol, raw_args
: nullable Array[PExpr], closure_defs
: nullable Array[PClosureDef])
1142 var prop
= get_property
(v
, type_recv
, is_implicit_self
, name
)
1143 if prop
== null then return
1144 var sig
= get_signature
(v
, type_recv
, prop
, recv_is_self
)
1145 var args
= process_signature
(v
, sig
, prop
.name
, raw_args
)
1146 if args
== null then return
1147 var rtype
= process_closures
(v
, sig
, prop
.name
, closure_defs
)
1148 if rtype
== null and sig
.return_type
!= null then return
1150 _prop_signature
= sig
1152 _return_type
= rtype
1155 private fun get_property
(v
: TypingVisitor, type_recv
: MMType, is_implicit_self
: Bool, name
: Symbol): nullable MMMethod
1157 var lc
= type_recv
.local_class
1158 var prop
: nullable MMMethod = null
1159 if lc
.has_global_property_by_name
(name
) then prop
= lc
.select_method
(name
)
1160 if prop
== null and v
.local_property
.global
.is_init
then
1161 var props
= type_recv
.local_class
.super_methods_named
(name
)
1162 if props
.length
> 1 then
1163 v
.error
(self, "Error: Ambigous method name '{name}' for {props.join(", ")}. Use explicit designation.")
1165 else if props
.length
== 1 then
1166 var p
= type_recv
.local_class
[props
.first
.global
]
1167 assert p
isa MMMethod
1172 if prop
== null then
1173 if is_implicit_self
then
1174 v
.error
(self, "Error: Method or variable '{name}' unknown in {type_recv}.")
1176 v
.error
(self, "Error: Method '{name}' doesn't exists in {type_recv}.")
1183 # Get the signature for a local property and a receiver
1184 private fun get_signature
(v
: TypingVisitor, type_recv
: MMType, prop
: MMMethod, recv_is_self
: Bool): MMSignature
1186 prop
.global
.check_visibility
(v
, self, v
.module, recv_is_self
)
1187 var psig
= prop
.signature_for
(type_recv
)
1188 if not recv_is_self
then psig
= psig
.not_for_self
1192 # The invoked method (once computed)
1193 readable var _prop
: nullable MMMethod
1195 # The return type (if any) (once computed)
1196 readable var _return_type
: nullable MMType
1199 # A possible call of constructor in a super class
1200 # Could be an explicit call or with the 'super' keyword
1201 class ASuperInitCall
1202 special AAbsSendExpr
1203 private fun register_super_init_call
(v
: TypingVisitor, property
: MMMethod)
1205 if parent
!= v
.top_block
and self != v
.top_block
then
1206 v
.error
(self, "Error: Constructor invocation {property} must not be in nested block.")
1208 var cla
= v
.module[property
.global
.intro
.local_class
.global
]
1209 var prev_class
: nullable MMLocalClass = null
1210 var esic
= v
.explicit_super_init_calls
.as(not null)
1211 if not esic
.is_empty
then
1212 prev_class
= esic
.last
.global
.intro
.local_class
1214 var order
= v
.local_class
.cshe
.reverse_linear_extension
1215 if cla
== v
.local_class
then
1216 v
.explicit_other_init_call
= true
1217 else if not order
.has
(cla
) then
1218 v
.error
(self, "Error: Constructor of class {cla} must be one in {order.join(", ")}.")
1219 else if cla
== prev_class
then
1220 v
.error
(self, "Error: Only one super constructor invocation of class {cla} is allowed.")
1222 var last_is_found
= prev_class
== null
1224 if c
== prev_class
then
1225 last_is_found
= true
1226 else if c
== cla
then
1227 if not last_is_found
then
1228 v
.error
(self, "Error: Constructor of {c} must be invoked before constructor of {prev_class}")
1239 redef class ANewExpr
1240 special AAbsSendExpr
1241 redef fun after_typing
(v
)
1243 if n_type
._stype
== null then return
1244 var t
= n_type
.stype
1245 if t
.local_class
.global
.is_abstract
then
1246 v
.error
(self, "Error: try to instantiate abstract class {t.local_class}.")
1250 if n_id
== null then
1251 name
= once
"init".to_symbol
1253 name
= n_id
.to_symbol
1256 do_typing
(v
, t
, false, false, name
, n_args
.to_a
, null)
1257 if prop
== null then return
1259 if not prop
.global
.is_init
then
1260 v
.error
(self, "Error: {prop} is not a constructor.")
1269 redef class ASendExpr
1270 special ASuperInitCall
1271 # Name of the invoked property
1272 fun name
: Symbol is abstract
1274 # Raw arguments used (withour star transformation)
1275 fun raw_arguments
: nullable Array[PExpr] is abstract
1277 # Closure definitions
1278 fun closure_defs
: nullable Array[PClosureDef] do return null
1280 redef fun after_typing
(v
)
1285 private fun do_all_typing
(v
: TypingVisitor)
1287 if not v
.check_expr
(n_expr
) then return
1288 do_typing
(v
, n_expr
.stype
, n_expr
.is_implicit_self
, n_expr
.is_self
, name
, raw_arguments
, closure_defs
)
1289 if _prop
== null then return
1290 var prop
= _prop
.as(not null)
1292 if prop
.global
.is_init
then
1293 if not v
.local_property
.global
.is_init
then
1294 v
.error
(self, "Error: try to invoke constructor {prop} in a method.")
1295 else if not n_expr
.is_self
then
1296 v
.error
(self, "Error: constructor {prop} is not invoken on 'self'.")
1298 register_super_init_call
(v
, prop
)
1302 _stype
= return_type
1307 class ASendReassignExpr
1309 special AReassignFormExpr
1310 readable var _read_prop
: nullable MMMethod
1311 redef fun do_all_typing
(v
)
1313 if not v
.check_expr
(n_expr
) then return
1314 var raw_args
= raw_arguments
1315 do_typing
(v
, n_expr
.stype
, n_expr
.is_implicit_self
, n_expr
.is_self
, name
, raw_args
, null)
1317 if prop
== null then return
1318 if prop
.global
.is_init
then
1319 if not v
.local_property
.global
.is_init
then
1320 v
.error
(self, "Error: try to invoke constructor {prop} in a method.")
1321 else if not n_expr
.is_self
then
1322 v
.error
(self, "Error: constructor {prop} is not invoken on 'self'.")
1325 var t
= prop
.signature_for
(n_expr
.stype
).return_type
.as(not null)
1326 if not n_expr
.is_self
then t
= t
.not_for_self
1328 var t2
= do_rvalue_typing
(v
, t
)
1329 if t2
== null then return
1330 v
.check_conform
(self, t2
, n_value
.stype
)
1333 var old_args
= arguments
1334 raw_args
.add
(n_value
)
1336 do_typing
(v
, n_expr
.stype
, n_expr
.is_implicit_self
, n_expr
.is_self
, "{name}=".to_symbol
, raw_args
, null)
1337 if prop
.global
.is_init
then
1338 if not v
.local_property
.global
.is_init
then
1339 v
.error
(self, "Error: try to invoke constructor {prop} in a method.")
1340 else if not n_expr
.is_self
then
1341 v
.error
(self, "Error: constructor {prop} is not invoken on 'self'.")
1345 _arguments
= old_args
# FIXME: What if star parameters do not match betwen the two methods?
1350 redef class ABinopExpr
1351 redef fun raw_arguments
do return [n_expr2
]
1354 redef fun name
do return once
"==".to_symbol
1355 redef fun after_typing
(v
)
1358 if not is_typed
then return
1359 if n_expr
.stype
isa MMTypeNone and not n_expr2
.stype
.is_nullable
or
1360 n_expr2
.stype
isa MMTypeNone and not n_expr
.stype
.is_nullable
then
1361 v
.warning
(self, "Warning: comparaison between null and a non nullable value.")
1364 if n_expr
.stype
isa MMTypeNone then
1365 try_to_isa
(v
, n_expr2
)
1366 else if n_expr2
.stype
isa MMTypeNone then
1367 try_to_isa
(v
, n_expr
)
1371 private fun try_to_isa
(v
: TypingVisitor, n
: PExpr)
1373 var variable
= n
.its_variable
1374 if variable
!= null then
1375 _if_false_variable_ctx
= v
.variable_ctx
.sub_with
(self, variable
, n
.stype
.as_notnull
)
1380 redef fun name
do return once
"!=".to_symbol
1381 redef fun after_typing
(v
)
1384 if not is_typed
then return
1385 if n_expr
.stype
isa MMTypeNone and not n_expr2
.stype
.is_nullable
or
1386 n_expr2
.stype
isa MMTypeNone and not n_expr
.stype
.is_nullable
then
1387 v
.warning
(self, "Warning: comparaison between null and a non nullable value.")
1390 if n_expr
.stype
isa MMTypeNone then
1391 try_to_isa
(v
, n_expr2
)
1392 else if n_expr2
.stype
isa MMTypeNone then
1393 try_to_isa
(v
, n_expr
)
1397 private fun try_to_isa
(v
: TypingVisitor, n
: PExpr)
1399 var variable
= n
.its_variable
1400 if variable
!= null then
1401 _if_true_variable_ctx
= v
.variable_ctx
.sub_with
(self, variable
, n
.stype
.as_notnull
)
1406 redef fun name
do return once
"<".to_symbol
1409 redef fun name
do return once
"<=".to_symbol
1412 redef fun name
do return once
">".to_symbol
1415 redef fun name
do return once
">=".to_symbol
1417 redef class APlusExpr
1418 redef fun name
do return once
"+".to_symbol
1420 redef class AMinusExpr
1421 redef fun name
do return once
"-".to_symbol
1423 redef class AStarshipExpr
1424 redef fun name
do return once
"<=>".to_symbol
1426 redef class AStarExpr
1427 redef fun name
do return once
"*".to_symbol
1429 redef class ASlashExpr
1430 redef fun name
do return once
"/".to_symbol
1432 redef class APercentExpr
1433 redef fun name
do return once
"%".to_symbol
1436 redef class AUminusExpr
1437 redef fun name
do return once
"unary -".to_symbol
1438 redef fun raw_arguments
do return null
1441 redef class ACallFormExpr
1442 redef fun after_typing
(v
)
1444 if n_expr
.is_implicit_self
then
1445 var name
= n_id
.to_symbol
1446 var variable
= v
.variable_ctx
[name
]
1447 if variable
!= null then
1448 if variable
isa ClosureVariable then
1449 var n
= new AClosureCallExpr.init_aclosurecallexpr
(n_id
, n_args
, n_closure_defs
)
1451 n
._variable
= variable
1455 if not n_args
.is_empty
then
1456 v
.error
(self, "Error: {name} is variable, not a function.")
1459 var vform
= variable_create
(variable
)
1460 vform
._variable
= variable
1462 vform
.after_typing
(v
)
1471 redef fun closure_defs
1473 if n_closure_defs
.is_empty
then
1476 return n_closure_defs
.to_a
1480 # Create a variable acces corresponding to the call form
1481 fun variable_create
(variable
: Variable): AVarFormExpr is abstract
1484 redef class ACallExpr
1485 redef fun variable_create
(variable
)
1487 return new AVarExpr.init_avarexpr
(n_id
)
1490 redef fun name
do return n_id
.to_symbol
1491 redef fun raw_arguments
do return n_args
.to_a
1494 redef class ACallAssignExpr
1495 redef fun variable_create
(variable
)
1497 return new AVarAssignExpr.init_avarassignexpr
(n_id
, n_assign
, n_value
)
1500 redef fun name
do return (n_id
.text
+ "=").to_symbol
1501 redef fun raw_arguments
do
1502 var res
= n_args
.to_a
1508 redef class ACallReassignExpr
1509 special ASendReassignExpr
1510 redef fun variable_create
(variable
)
1512 return new AVarReassignExpr.init_avarreassignexpr
(n_id
, n_assign_op
, n_value
)
1515 redef fun name
do return n_id
.to_symbol
1516 redef fun raw_arguments
do return n_args
.to_a
1519 redef class ABraExpr
1520 redef fun name
do return once
"[]".to_symbol
1521 redef fun raw_arguments
do return n_args
.to_a
1524 redef class ABraAssignExpr
1525 redef fun name
do return once
"[]=".to_symbol
1526 redef fun raw_arguments
do
1527 var res
= n_args
.to_a
1533 redef class ABraReassignExpr
1534 special ASendReassignExpr
1535 redef fun name
do return once
"[]".to_symbol
1536 redef fun raw_arguments
do return n_args
.to_a
1539 redef class AInitExpr
1540 redef fun name
do return once
"init".to_symbol
1541 redef fun raw_arguments
do return n_args
.to_a
1544 redef class AClosureCallExpr
1545 special AAbsAbsSendExpr
1546 var _variable
: nullable ClosureVariable
1547 redef fun variable
do return _variable
.as(not null)
1549 redef fun after_typing
(v
)
1552 if va
.closure
.is_break
then v
.variable_ctx
.unreash
= true
1553 var sig
= va
.closure
.signature
1554 var args
= process_signature
(v
, sig
, n_id
.to_symbol
, n_args
.to_a
)
1555 if not n_closure_defs
.is_empty
then
1556 process_closures
(v
, sig
, n_id
.to_symbol
, n_closure_defs
.to_a
)
1558 if args
== null then return
1559 _prop_signature
= sig
1561 _stype
= sig
.return_type
1566 redef class PClosureDef
1567 var _closure
: nullable MMClosure
1568 redef fun closure
do return _closure
.as(not null)
1570 # The corresponding escapable object
1571 readable var _escapable
: nullable EscapableBlock
1573 var _accept_typing2
: Bool = false
1574 redef fun accept_typing
(v
)
1576 # Typing is deferred, wait accept_typing2(v)
1577 if _accept_typing2
then super
1580 private fun accept_typing2
(v
: TypingVisitor, esc
: EscapableClosure) is abstract
1583 redef class AClosureDef
1584 redef fun accept_typing2
(v
, esc
)
1588 var sig
= esc
.closure
.signature
1589 if sig
.arity
!= n_id
.length
then
1590 v
.error
(self, "Error: {sig.arity} automatic variable names expected, {n_id.length} found.")
1594 _closure
= esc
.closure
1596 var old_var_ctx
= v
.variable_ctx
1597 var old_base_var_ctx
= v
.base_variable_ctx
1598 v
.base_variable_ctx
= v
.variable_ctx
1599 v
.variable_ctx
= v
.variable_ctx
.sub
(self)
1600 variables
= new Array[AutoVariable]
1601 for i
in [0..n_id
.length
[ do
1602 var va
= new AutoVariable(n_id
[i
].to_symbol
, self)
1605 v
.variable_ctx
.add
(va
)
1608 _accept_typing2
= true
1611 if v
.variable_ctx
.unreash
== false then
1612 if closure
.signature
.return_type
!= null then
1613 v
.error
(self, "Control error: Reached end of block (a 'continue' with a value was expected).")
1614 else if closure
.is_break
then
1615 v
.error
(self, "Control error: Reached end of break block (a 'break' was expected).")
1618 v
.variable_ctx
= old_var_ctx
1619 v
.base_variable_ctx
= old_base_var_ctx
1623 class ATypeCheckExpr
1625 private fun check_expr_cast
(v
: TypingVisitor, n_expr
: PExpr, n_type
: PType)
1627 if not v
.check_expr
(n_expr
) then return
1628 var etype
= n_expr
.stype
1629 var ttype
= n_type
.stype
1630 if etype
== ttype
then
1631 v
.warning
(self, "Warning: Expression is already a {ttype}.")
1632 else if etype
< ttype
then
1633 v
.warning
(self, "Warning: Expression is already a {ttype} since it is a {etype}.")
1634 else if etype
.is_nullable
and etype
.as_notnull
== ttype
then
1635 if ttype
isa MMTypeFormal and ttype
.bound
.is_nullable
then
1636 # No warning in this case since with
1637 # type T: nullable A
1639 # 'x.as(not null)' != 'x.as(T)'
1640 # 'x != null' != 'x isa T'
1641 else if self isa AIsaExpr then
1642 v
.warning
(self, "Warning: Prefer '!= null'.")
1644 v
.warning
(self, "Warning: Prefer '.as(not null)'.")
1650 redef class AIsaExpr
1651 special ATypeCheckExpr
1652 redef fun after_typing
(v
)
1654 check_expr_cast
(v
, n_expr
, n_type
)
1655 var variable
= n_expr
.its_variable
1656 if variable
!= null then
1657 _if_true_variable_ctx
= v
.variable_ctx
.sub_with
(self, variable
, n_type
.stype
)
1659 _stype
= v
.type_bool
1664 redef class AAsCastExpr
1665 special ATypeCheckExpr
1666 redef fun after_typing
(v
)
1668 check_expr_cast
(v
, n_expr
, n_type
)
1669 _stype
= n_type
.stype
1670 _is_typed
= _stype
!= null
1674 redef class AAsNotnullExpr
1675 redef fun after_typing
(v
)
1677 if not v
.check_expr
(n_expr
) then return
1678 var t
= n_expr
.stype
1679 if t
isa MMTypeNone then
1680 v
.error
(n_expr
, "Type error: 'as(not null)' on 'null' value.")
1682 else if not t
.is_nullable
then
1683 v
.warning
(n_expr
, "Warning: 'as(not null)' on non nullable type.")
1685 _stype
= n_expr
.stype
.as_notnull
1690 redef class AProxyExpr
1691 redef fun after_typing
(v
)
1693 if not n_expr
.is_typed
then return
1695 if n_expr
.is_statement
then return
1696 _stype
= n_expr
.stype
1700 redef class AOnceExpr
1701 redef fun accept_typing
(v
)
1703 if v
.once_count
> 0 then
1704 v
.warning
(self, "Useless once in a once expression.")
1706 v
.once_count
= v
.once_count
+ 1
1710 v
.once_count
= v
.once_count
- 1