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
22 redef class MMSrcModule
23 # Walk trough the module and type statments and expressions
24 # Require than supermodules are processed
25 meth do_typing
(tc
: ToolContext)
27 var tv
= new TypingVisitor(tc
, self)
33 # * Associate local variables to nodes
34 # * Distinguish method call and local variable access
35 # * Resolve call and attribute access
36 # * Check type conformance
37 private class TypingVisitor
38 special AbsSyntaxVisitor
41 if n
!= null then n
.accept_typing
(self)
44 # Current knowledge about variables names and types
45 readable writable attr _variable_ctx
: VariableContext
47 # Type of the receiver
48 readable writable attr _self_type
: MMType
50 # Block of the current method
51 readable writable attr _top_block
: PExpr
53 # List of explicit invocation of constructors of super-classes
54 readable writable attr _explicit_super_init_calls
: Array[MMMethod]
56 # Is a other constructor of the same class invoked
57 readable writable attr _explicit_other_init_call
: Bool
59 init(tc
, module) do super
61 private meth get_default_constructor_for
(n
: PNode, c
: MMLocalClass, prop
: MMSrcMethod): MMMethod
64 #var prop = v.local_property
65 #assert prop isa MMMethod
66 var candidates
= new Array[MMMethod]
67 var false_candidates
= new Array[MMMethod]
68 var parity
= prop
.signature
.arity
69 for g
in c
.global_properties
do
70 if not g
.is_init
then continue
71 if g
.intro
.local_class
!= c
then continue
73 assert gp
isa MMSrcMethod
74 var garity
= gp
.signature
.arity
75 if prop
!= null and gp
.name
== prop
.name
then
76 if garity
== 0 or (parity
== garity
and prop
.signature
< gp
.signature
) then
79 false_candidates
.add
(gp
)
81 else if garity
== 0 and gp
.name
== once
("init".to_symbol
) then
83 false_candidates
.add
(gp
)
85 false_candidates
.add
(gp
)
88 if candidates
.length
== 1 then
89 return candidates
.first
90 else if candidates
.length
> 0 then
91 v
.error
(n
, "Error: Conflicting default constructor to call for {c}: {candidates.join(", ")}.")
93 else if false_candidates
.length
> 0 then
94 v
.error
(n
, "Error: there is no available compatible constrctor in {c}. discarded candidates are {false_candidates.join(", ")}.")
97 v
.warning
(n
, "Error: there is no available compatible constrctor in {c}.")
103 # Associate symbols to variable and variables to type
105 private class VariableContext
106 # Look for the variable from its name
107 # Return null if nothing found
108 meth
[](s
: Symbol): Variable
110 if _dico
.has_key
(s
) then
117 # Register a new variable with its name
118 meth add
(v
: Variable)
124 # The effective static type of a given variable
125 # May be different from the declaration static type
126 meth stype
(v
: Variable): MMType
131 # Variables by name (in the current context only)
132 attr _dico
: Map[Symbol, Variable]
134 # Build a new VariableContext
135 meth sub
: SubVariableContext
137 return new SubVariableContext.with_prev
(self, null, null)
140 # Build a nested VariableContext with new variable information
141 meth sub_with
(v
: Variable, t
: MMType): SubVariableContext
143 return new SubVariableContext.with_prev
(self, v
, t
)
148 _dico
= new HashMap[Symbol, Variable]
152 private class SubVariableContext
153 special VariableContext
154 readable attr _prev
: VariableContext
155 attr _variable
: Variable
156 attr _var_type
: MMType
160 if _dico
.has_key
(s
) then
169 if _variable
== v
then
175 init with_prev
(p
: VariableContext, v
: Variable, t
: MMType)
185 ###############################################################################
188 private meth accept_typing
(v
: TypingVisitor)
190 accept_abs_syntax_visitor
(v
)
193 private meth after_typing
(v
: TypingVisitor) do end
196 redef class PClassdef
197 redef meth accept_typing
(v
)
199 v
.self_type
= local_class
.get_type
204 redef class AAttrPropdef
205 redef meth accept_typing
(v
)
208 if n_expr
!= null then
209 v
.check_conform
(n_expr
, n_expr
.stype
, prop
.signature
.return_type
)
214 redef class AMethPropdef
215 redef meth accept_typing
(v
)
217 v
.variable_ctx
= new VariableContext
222 redef class AConcreteInitPropdef
223 readable attr _super_init_calls
: Array[MMMethod] = new Array[MMMethod]
224 readable attr _explicit_super_init_calls
: Array[MMMethod] = new Array[MMMethod]
225 redef meth accept_typing
(v
)
227 v
.top_block
= n_block
228 v
.explicit_super_init_calls
= explicit_super_init_calls
229 v
.explicit_other_init_call
= false
231 if v
.explicit_other_init_call
then
235 var l
= explicit_super_init_calls
.length
236 var cur_m
: MMMethod = null
237 var cur_c
: MMLocalClass = null
239 cur_m
= explicit_super_init_calls
[i
]
240 cur_c
= cur_m
.global
.intro
.local_class
243 while j
< v
.local_class
.cshe
.direct_greaters
.length
do
244 var c
= v
.local_class
.cshe
.direct_greaters
[j
]
245 if c
.global
.is_interface
or c
.global
.is_universal
then
247 else if cur_c
!= null and c
.cshe
<= cur_c
then
248 if c
== cur_c
then j
+= 1
249 super_init_calls
.add
(cur_m
)
252 cur_m
= explicit_super_init_calls
[i
]
253 cur_c
= cur_m
.global
.intro
.local_class
259 var p
= v
.get_default_constructor_for
(self, c
, method
)
261 super_init_calls
.add
(p
)
271 redef meth after_typing
(v
)
273 if v
.variable_ctx
!= null then
274 v
.variable_ctx
.add
(variable
)
280 readable attr _stype
: MMType
281 redef meth after_typing
(v
)
283 _stype
= get_stype
(v
)
288 redef readable attr _stype
: MMType
290 # Is the expression the implicit receiver
291 meth is_implicit_self
: Bool do return false
293 # Is the expression the current receiver (implicit or explicit)
294 meth is_self
: Bool do return false
296 # Is the expression a variable access
297 meth is_variable
: Bool do return false
299 # The variable type information if current boolean expression is true
300 readable private attr _if_true_variable_ctx
: VariableContext
303 redef class AVardeclExpr
304 redef meth after_typing
(v
)
306 var va
= new VarVariable(n_id
.to_symbol
, self)
308 v
.variable_ctx
.add
(va
)
310 if n_type
!= null then
311 va
.stype
= n_type
.stype
312 if n_expr
!= null then
313 v
.check_conform
(self, n_expr
.stype
, va
.stype
)
316 va
.stype
= n_expr
.stype
321 redef class ABlockExpr
322 redef meth accept_typing
(v
)
324 var old_var_ctx
= v
.variable_ctx
325 v
.variable_ctx
= v
.variable_ctx
.sub
329 v
.variable_ctx
= old_var_ctx
333 redef class AReturnExpr
334 redef meth after_typing
(v
)
336 var t
= v
.local_property
.signature
.return_type
337 if n_expr
== null and t
!= null then
338 v
.error
(self, "Error: Return without value in a function.")
339 else if n_expr
!= null and t
== null then
340 v
.error
(self, "Error: Return with value in a procedure.")
341 else if n_expr
!= null and t
!= null then
342 v
.check_conform
(self, n_expr
.stype
, t
)
348 redef meth accept_typing
(v
)
350 var old_var_ctx
= v
.variable_ctx
352 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
354 if n_expr
.if_true_variable_ctx
!= null then
355 v
.variable_ctx
= n_expr
.if_true_variable_ctx
359 # Restore variable ctx
360 v
.variable_ctx
= old_var_ctx
362 if n_else
!= null then
364 v
.variable_ctx
= old_var_ctx
369 redef class AWhileExpr
370 redef meth after_typing
(v
)
372 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
377 redef meth after_typing
(v
)
379 # pop context created in AForVardeclExpr
380 var varctx
= v
.variable_ctx
381 assert varctx
isa SubVariableContext
382 v
.variable_ctx
= varctx
.prev
386 redef class AForVardeclExpr
387 redef meth after_typing
(v
)
389 v
.variable_ctx
= v
.variable_ctx
.sub
390 var va
= new AutoVariable(n_id
.to_symbol
, self)
392 v
.variable_ctx
.add
(va
)
394 var expr_type
= n_expr
.stype
395 if not v
.check_conform
(self, expr_type
, v
.type_collection
) then
398 var prop
= expr_type
.local_class
.select_method
(once
("iterator".to_symbol
))
400 v
.error
(self, "Error: Collection MUST have an iterate method")
403 var iter_type
= prop
.signature_for
(expr_type
).return_type
404 var prop2
= iter_type
.local_class
.select_method
(once
("item".to_symbol
))
405 if prop2
== null then
406 v
.error
(self, "Error: {iter_type} MUST have an item method")
409 var t
= prop2
.signature_for
(iter_type
).return_type
410 if not n_expr
.is_self
then t
= t
.not_for_self
415 redef class AAssertExpr
416 redef meth after_typing
(v
)
418 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
419 if n_expr
.if_true_variable_ctx
!= null then v
.variable_ctx
= n_expr
.if_true_variable_ctx
424 redef meth is_variable
do return true
426 redef meth after_typing
(v
)
428 _stype
= v
.variable_ctx
.stype
(variable
)
432 redef class AVarAssignExpr
433 redef meth after_typing
(v
)
435 var t
= v
.variable_ctx
.stype
(variable
)
436 v
.check_conform
(self, n_value
.stype
, t
)
440 redef class AReassignFormExpr
441 # Compute and check method used through the reassigment operator
442 private meth do_lvalue_typing
(v
: TypingVisitor, type_lvalue
: MMType)
444 if type_lvalue
== null then
447 var name
= n_assign_op
.method_name
448 var prop
= type_lvalue
.local_class
.select_method
(name
)
450 v
.error
(self, "Error: Method '{name}' doesn't exists in {type_lvalue}.")
453 prop
.global
.check_visibility
(v
, self, v
.module, false)
454 var psig
= prop
.signature_for
(type_lvalue
)
455 _assign_method
= prop
456 v
.check_conform
(n_value
, n_value
.stype
, psig
[0].not_for_self
)
457 v
.check_conform
(self, psig
.return_type
.not_for_self
, n_value
.stype
)
460 # Method used through the reassigment operator (once computed)
461 readable attr _assign_method
: MMMethod
464 redef class AVarReassignExpr
465 redef meth after_typing
(v
)
467 var t
= v
.variable_ctx
.stype
(variable
)
468 do_lvalue_typing
(v
, t
)
472 redef class PAssignOp
473 meth method_name
: Symbol is abstract
475 redef class APlusAssignOp
476 redef meth method_name
do return once
"+".to_symbol
478 redef class AMinusAssignOp
479 redef meth method_name
do return once
"-".to_symbol
482 redef class ASelfExpr
483 redef meth after_typing
(v
)
485 assert v
.self_type
!= null
489 redef meth is_self
do return true
492 redef class AImplicitSelfExpr
493 redef meth is_implicit_self
do return true
496 redef class AIfexprExpr
497 redef meth accept_typing
(v
)
499 var old_var_ctx
= v
.variable_ctx
502 if n_expr
.if_true_variable_ctx
!= null then v
.variable_ctx
= n_expr
.if_true_variable_ctx
504 v
.variable_ctx
= old_var_ctx
507 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
510 var te
= n_else
.stype
513 else if not te
< t
then
514 v
.error
(self, "Type error: {te} is not a subtype of {t}.")
522 redef class ABoolExpr
523 redef meth after_typing
(v
)
530 redef meth after_typing
(v
)
532 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
533 v
.check_conform
(self, n_expr2
.stype
, v
.type_bool
)
539 redef meth accept_typing
(v
)
541 var old_var_ctx
= v
.variable_ctx
544 if n_expr
.if_true_variable_ctx
!= null then v
.variable_ctx
= n_expr
.if_true_variable_ctx
547 if n_expr2
.if_true_variable_ctx
!= null then
548 _if_true_variable_ctx
= n_expr2
.if_true_variable_ctx
550 _if_true_variable_ctx
= v
.variable_ctx
553 v
.variable_ctx
= old_var_ctx
555 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
556 v
.check_conform
(self, n_expr2
.stype
, v
.type_bool
)
562 redef meth after_typing
(v
)
564 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
570 redef meth after_typing
(v
)
577 redef class AFloatExpr
578 redef meth after_typing
(v
)
580 _stype
= v
.type_float
584 redef class ACharExpr
585 redef meth after_typing
(v
)
591 redef class AStringFormExpr
592 redef meth after_typing
(v
)
594 _stype
= v
.type_string
598 redef class ASuperstringExpr
599 redef meth after_typing
(v
)
601 _stype
= v
.type_string
605 redef class ANullExpr
606 redef meth after_typing
(v
)
612 redef class AArrayExpr
613 private meth stype
=(t
: MMType) do _stype
= t
615 redef meth after_typing
(v
)
617 var stype
: MMType = null
620 if stype
== null or (ntype
!= null and stype
< ntype
) then
625 v
.check_conform
(self, n
.stype
, stype
)
627 _stype
= v
.type_array
(stype
)
631 redef class ARangeExpr
632 redef meth after_typing
(v
)
634 var ntype
= n_expr
.stype
635 var ntype2
= n_expr2
.stype
636 if ntype
== null or ntype
== null then
639 if ntype
< ntype2
then
641 else if not ntype2
< ntype
then
642 v
.error
(self, "Type error: {ntype} incompatible with {ntype2}.")
645 var dtype
= v
.type_discrete
646 v
.check_conform
(self, ntype
, dtype
)
647 _stype
= v
.type_range
(ntype
)
651 redef class ASuperExpr
652 special ASuperInitCall
653 # readable attr _prop: MMSrcMethod
654 readable attr _init_in_superclass
: MMMethod
655 redef meth after_typing
(v
)
657 var precs
: Array[MMLocalProperty] = v
.local_property
.prhe
.direct_greaters
658 if not precs
.is_empty
then
659 v
.local_property
.need_super
= true
660 else if v
.local_property
.global
.is_init
then
661 var base_precs
= v
.local_class
.super_methods_named
(v
.local_property
.name
)
662 for p
in base_precs
do
663 if not p
.global
.is_init
then
664 v
.error
(self, "Error: {p.local_class}::{p} is not a constructor.")
666 precs
.add
(v
.local_class
[p
.global
])
669 if precs
.is_empty
then
670 v
.error
(self, "Error: No contructor named {v.local_property.name} in superclasses.")
672 else if precs
.length
> 1 then
673 v
.error
(self, "Error: Conflicting contructors named {v.local_property.name} in superclasses: {precs.join(", ")}.")
676 var p
= base_precs
.first
677 assert p
isa MMMethod
678 _init_in_superclass
= p
679 register_super_init_call
(v
, p
)
680 if n_args
.length
> 0 then
681 _arguments
= process_signature
(v
, v
.self_type
, p
, true, n_args
.to_a
)
684 v
.error
(self, "Error: No super method to call for {v.local_property}.")
688 if precs
.first
.signature_for
(v
.self_type
).return_type
!= null then
689 var stypes
= new Array[MMType]
690 var stype
: MMType = null
692 assert prop
isa MMMethod
693 var t
= prop
.signature_for
(v
.self_type
).return_type
.for_module
(v
.module).adapt_to
(v
.local_property
.signature
.recv
)
695 if stype
== null or stype
< t
then
700 v
.check_conform
(self, t
, stype
)
704 var p
= v
.local_property
705 assert p
isa MMSrcMethod
710 redef class AAttrFormExpr
712 readable attr _prop
: MMAttribute
714 # Attribute type of the acceded attribute
715 readable attr _attr_type
: MMType
717 # Compute the attribute accessed
718 private meth do_typing
(v
: TypingVisitor)
720 var type_recv
= n_expr
.stype
721 if type_recv
== null then
724 var name
= n_id
.to_symbol
725 var prop
= type_recv
.local_class
.select_attribute
(name
)
727 v
.error
(self, "Error: Attribute {name} doesn't exists in {type_recv}.")
729 else if v
.module.visibility_for
(prop
.global
.local_class
.module) < 3 then
730 v
.error
(self, "Error: Attribute {name} from {prop.global.local_class.module} is invisible in {v.module}")
733 var at
= prop
.signature_for
(type_recv
).return_type
734 if not n_expr
.is_self
then at
= at
.not_for_self
739 redef class AAttrExpr
740 redef meth after_typing
(v
)
750 redef class AAttrAssignExpr
751 redef meth after_typing
(v
)
757 v
.check_conform
(self, n_value
.stype
, attr_type
)
761 redef class AAttrReassignExpr
762 redef meth after_typing
(v
)
768 do_lvalue_typing
(v
, attr_type
)
774 # Compute the called global property
775 private meth do_typing
(v
: TypingVisitor, type_recv
: MMType, is_implicit_self
: Bool, recv_is_self
: Bool, name
: Symbol, raw_args
: Array[PExpr])
777 var prop
= get_property
(v
, type_recv
, is_implicit_self
, name
)
778 if prop
== null then return
779 var args
= process_signature
(v
, type_recv
, prop
, recv_is_self
, raw_args
)
780 if args
== null then return
785 private meth get_property
(v
: TypingVisitor, type_recv
: MMType, is_implicit_self
: Bool, name
: Symbol): MMMethod
787 if type_recv
== null then return null
788 var prop
= type_recv
.local_class
.select_method
(name
)
789 if prop
== null and v
.local_property
.global
.is_init
then
790 var props
= type_recv
.local_class
.super_methods_named
(name
)
791 if props
.length
> 1 then
792 v
.error
(self, "Error: Ambigous method name '{name}' for {props.join(", ")}. Use explicit designation.")
794 else if props
.length
== 1 then
795 var p
= type_recv
.local_class
[props
.first
.global
]
796 assert p
isa MMMethod
802 if is_implicit_self
then
803 v
.error
(self, "Error: Method or variable '{name}' unknown in {type_recv}.")
805 v
.error
(self, "Error: Method '{name}' doesn't exists in {type_recv}.")
812 private meth process_signature
(v
: TypingVisitor, type_recv
: MMType, prop
: MMMethod, recv_is_self
: Bool, raw_args
: Array[PExpr]): Array[PExpr]
814 prop
.global
.check_visibility
(v
, self, v
.module, recv_is_self
)
815 var psig
= prop
.signature_for
(type_recv
)
816 var par_vararg
= psig
.vararg_rank
817 var par_arity
= psig
.arity
819 if raw_args
== null then raw_arity
= 0 else raw_arity
= raw_args
.length
820 if par_arity
> raw_arity
or (par_arity
!= raw_arity
and par_vararg
== -1) then
821 v
.error
(self, "Error: Method '{prop}' arity missmatch.")
825 var args
= new Array[PExpr]
826 for par_idx
in [0..par_arity
[ do
828 var par_type
= psig
[par_idx
]
829 if not recv_is_self
then par_type
= par_type
.not_for_self
830 if par_idx
== par_vararg
then
831 var star
= new Array[PExpr]
832 for i
in [0..(raw_arity-par_arity
)] do
833 a
= raw_args
[arg_idx
]
834 v
.check_conform
(self, a
.stype
, par_type
)
836 arg_idx
= arg_idx
+ 1
838 var aa
= new AArrayExpr.init_aarrayexpr
(star
)
839 aa
.stype
= v
.type_array
(par_type
)
842 a
= raw_args
[arg_idx
]
843 v
.check_conform
(self, a
.stype
, par_type
)
844 arg_idx
= arg_idx
+ 1
851 # The invoked method (once computed)
852 readable attr _prop
: MMMethod
854 # The real arguments used (after star transformation) (once computed)
855 readable attr _arguments
: Array[PExpr]
858 # A possible call of constructor in a super class
859 # Could be an explicit call or with the 'super' keyword
862 private meth register_super_init_call
(v
: TypingVisitor, property
: MMMethod)
864 if parent
!= v
.top_block
and self != v
.top_block
then
865 v
.error
(self, "Error: Constructor invocation {property} must not be in nested block.")
867 var cla
= v
.module[property
.global
.intro
.local_class
.global
]
868 var prev_class
: MMLocalClass = null
869 if not v
.explicit_super_init_calls
.is_empty
then
870 prev_class
= v
.explicit_super_init_calls
.last
.global
.intro
.local_class
872 var order
= v
.local_class
.cshe
.reverse_linear_extension
873 if cla
== v
.local_class
then
874 v
.explicit_other_init_call
= true
875 else if not order
.has
(cla
) then
876 v
.error
(self, "Error: Constructor of class {cla} must be one in {order.join(", ")}.")
877 else if cla
== prev_class
then
878 v
.error
(self, "Error: Only one super constructor invocation of class {cla} is allowed.")
880 var last_is_found
= prev_class
== null
882 if c
== prev_class
then
884 else if c
== cla
then
885 if not last_is_found
then
886 v
.error
(self, "Error: Constructor of {c} must be invoked before constructor of {prev_class}")
888 v
.explicit_super_init_calls
.add
(property
)
899 redef meth after_typing
(v
)
902 if t
== null then return
903 if t
.local_class
.global
.is_abstract
then
904 v
.error
(self, "Error: try to instantiate abstract class {t.local_class}.")
909 name
= once
"init".to_symbol
911 name
= n_id
.to_symbol
914 do_typing
(v
, t
, false, false, name
, n_args
.to_a
)
915 if prop
== null then return
917 if not prop
.global
.is_init
then
918 v
.error
(self, "Error: {prop} is not a constructor.")
925 redef class ASendExpr
926 special ASuperInitCall
927 # Name of the invoked property
928 meth name
: Symbol is abstract
930 # Raw arguments used (withour star transformation)
931 meth raw_arguments
: Array[PExpr] is abstract
933 redef meth after_typing
(v
)
938 private meth do_all_typing
(v
: TypingVisitor)
940 do_typing
(v
, n_expr
.stype
, n_expr
.is_implicit_self
, n_expr
.is_self
, name
, raw_arguments
)
941 if prop
== null then return
942 if prop
.global
.is_init
then
943 if not v
.local_property
.global
.is_init
then
944 v
.error
(self, "Error: try to invoke constructor {prop} in a method.")
945 else if not n_expr
.is_self
then
946 v
.error
(self, "Error: constructor {prop} is not invoken on 'self'.")
948 register_super_init_call
(v
, prop
)
951 var t
= prop
.signature_for
(n_expr
.stype
).return_type
952 if t
!= null and not n_expr
.is_self
then t
= t
.not_for_self
957 class ASendReassignExpr
959 special AReassignFormExpr
960 readable attr _read_prop
: MMMethod
961 redef meth do_all_typing
(v
)
963 var raw_args
= raw_arguments
964 do_typing
(v
, n_expr
.stype
, n_expr
.is_implicit_self
, n_expr
.is_self
, name
, raw_args
)
965 if prop
== null then return
966 if prop
.global
.is_init
then
967 if not v
.local_property
.global
.is_init
then
968 v
.error
(self, "Error: try to invoke constructor {prop} in a method.")
969 else if not n_expr
.is_self
then
970 v
.error
(self, "Error: constructor {prop} is not invoken on 'self'.")
973 var t
= prop
.signature_for
(n_expr
.stype
).return_type
974 if not n_expr
.is_self
then t
= t
.not_for_self
976 do_lvalue_typing
(v
, t
)
979 var old_args
= arguments
980 raw_args
.add
(n_value
)
982 do_typing
(v
, n_expr
.stype
, n_expr
.is_implicit_self
, n_expr
.is_self
, "{name}=".to_symbol
, raw_args
)
983 if prop
== null then return
984 if prop
.global
.is_init
then
985 if not v
.local_property
.global
.is_init
then
986 v
.error
(self, "Error: try to invoke constructor {prop} in a method.")
987 else if not n_expr
.is_self
then
988 v
.error
(self, "Error: constructor {prop} is not invoken on 'self'.")
992 _arguments
= old_args
# FIXME: What if star parameters do not match betwen the two methods?
996 redef class ABinopExpr
997 redef meth raw_arguments
do return [n_expr2
]
1000 redef meth name
do return once
"==".to_symbol
1003 redef meth name
do return once
"!=".to_symbol
1006 redef meth name
do return once
"<".to_symbol
1009 redef meth name
do return once
"<=".to_symbol
1012 redef meth name
do return once
">".to_symbol
1015 redef meth name
do return once
">=".to_symbol
1017 redef class APlusExpr
1018 redef meth name
do return once
"+".to_symbol
1020 redef class AMinusExpr
1021 redef meth name
do return once
"-".to_symbol
1023 redef class AStarshipExpr
1024 redef meth name
do return once
"<=>".to_symbol
1026 redef class AStarExpr
1027 redef meth name
do return once
"*".to_symbol
1029 redef class ASlashExpr
1030 redef meth name
do return once
"/".to_symbol
1032 redef class APercentExpr
1033 redef meth name
do return once
"%".to_symbol
1036 redef class AUminusExpr
1037 redef meth name
do return once
"unary -".to_symbol
1038 redef meth raw_arguments
do return null
1041 redef class ACallFormExpr
1042 redef meth after_typing
(v
)
1044 if n_expr
.is_implicit_self
then
1045 var name
= n_id
.to_symbol
1046 var variable
= v
.variable_ctx
[name
]
1047 if variable
!= null then
1048 if not n_args
.is_empty
then
1049 v
.error
(self, "Error: {name} is variable, not a function.")
1051 var vform
= variable_create
(variable
)
1052 vform
.variable
= variable
1054 vform
.after_typing
(v
)
1061 # Create a variable acces corresponding to the call form
1062 meth variable_create
(variable
: Variable): AVarFormExpr is abstract
1065 redef class ACallExpr
1066 redef meth variable_create
(variable
)
1068 return new AVarExpr.init_avarexpr
(n_id
)
1071 redef meth name
do return n_id
.to_symbol
1072 redef meth raw_arguments
do return n_args
.to_a
1075 redef class ACallAssignExpr
1076 redef meth variable_create
(variable
)
1078 return new AVarAssignExpr.init_avarassignexpr
(n_id
, n_assign
, n_value
)
1081 redef meth name
do return (n_id
.text
+ "=").to_symbol
1082 redef meth raw_arguments
do
1083 var res
= n_args
.to_a
1089 redef class ACallReassignExpr
1090 special ASendReassignExpr
1091 redef meth variable_create
(variable
)
1093 return new AVarReassignExpr.init_avarreassignexpr
(n_id
, n_assign_op
, n_value
)
1096 redef meth name
do return n_id
.to_symbol
1097 redef meth raw_arguments
do return n_args
.to_a
1100 redef class ABraExpr
1101 redef meth name
do return once
"[]".to_symbol
1102 redef meth raw_arguments
do return n_args
.to_a
1105 redef class ABraAssignExpr
1106 redef meth name
do return once
"[]=".to_symbol
1107 redef meth raw_arguments
do
1108 var res
= n_args
.to_a
1114 redef class ABraReassignExpr
1115 special ASendReassignExpr
1116 redef meth name
do return once
"[]".to_symbol
1117 redef meth raw_arguments
do return n_args
.to_a
1120 redef class AInitExpr
1121 redef meth name
do return once
"init".to_symbol
1122 redef meth raw_arguments
do return n_args
.to_a
1125 redef class AIsaExpr
1126 redef meth after_typing
(v
)
1128 if n_expr
.is_variable
then
1130 assert n
isa AVarExpr
1131 _if_true_variable_ctx
= v
.variable_ctx
.sub_with
(n
.variable
, n_type
.stype
)
1133 _stype
= v
.type_bool
1137 redef class AAsCastExpr
1138 redef meth after_typing
(v
)
1140 _stype
= n_type
.stype
1141 var et
= n_expr
.stype
1145 redef class AProxyExpr
1146 redef meth after_typing
(v
)
1148 _stype
= n_expr
.stype