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
: MMMethod): 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 MMMethod
74 var garity
= g
.intro
.signature
.arity
75 if prop
!= null and g
.intro
.name
== prop
.name
then
76 if garity
== 0 or garity
== parity
then
79 false_candidates
.add
(gp
)
81 else if garity
== 0 then
83 false_candidates
.add
(gp
)
85 false_candidates
.add
(gp
)
88 if candidates
.length
== 1 then
89 return candidates
.first
90 else if false_candidates
.is_empty
then
91 v
.warning
(n
, "Fatal error: there is no available constrctor in {c}.")
95 v
.error
(n
, "Error: Conflicting default constructor to call for {c}: {false_candidates.join(", ")}.")
101 # Associate symbols to variable and variables to type
103 private class VariableContext
104 # Look for the variable from its name
105 # Return null if nothing found
106 meth
[](s
: Symbol): Variable
108 if _dico
.has_key
(s
) then
115 # Register a new variable with its name
116 meth add
(v
: Variable)
122 # The effective static type of a given variable
123 # May be different from the declaration static type
124 meth stype
(v
: Variable): MMType
129 # Variables by name (in the current context only)
130 attr _dico
: Map[Symbol, Variable]
132 # Build a new VariableContext
133 meth sub
: VariableContext
135 return new SubVariableContext.with
(self, null, null)
138 # Build a nested VariableContext with new variable information
139 meth sub_with
(v
: Variable, t
: MMType): VariableContext
141 return new SubVariableContext.with
(self, v
, t
)
146 _dico
= new HashMap[Symbol, Variable]
150 private class SubVariableContext
151 special VariableContext
152 readable attr _prev
: VariableContext
153 attr _variable
: Variable
154 attr _var_type
: MMType
158 if _dico
.has_key
(s
) then
167 if _variable
== v
then
173 init with
(p
: VariableContext, v
: Variable, t
: MMType)
183 ###############################################################################
186 private meth accept_typing
(v
: TypingVisitor)
188 accept_abs_syntax_visitor
(v
)
191 private meth after_typing
(v
: TypingVisitor) do end
194 redef class PClassdef
195 redef meth accept_typing
(v
)
197 v
.self_type
= local_class
.get_type
202 redef class AAttrPropdef
203 redef meth accept_typing
(v
)
206 if n_expr
!= null then
207 v
.check_conform
(n_expr
, n_expr
.stype
, prop
.signature
.return_type
)
212 redef class AMethPropdef
213 redef meth accept_typing
(v
)
215 v
.variable_ctx
= new VariableContext
220 redef class AConcreteInitPropdef
221 readable attr _super_init_calls
: Array[MMMethod] = new Array[MMMethod]
222 readable attr _explicit_super_init_calls
: Array[MMMethod] = new Array[MMMethod]
223 redef meth accept_typing
(v
)
225 v
.top_block
= n_block
226 v
.explicit_super_init_calls
= explicit_super_init_calls
227 v
.explicit_other_init_call
= false
229 if v
.explicit_other_init_call
then
233 var l
= explicit_super_init_calls
.length
235 var cur_c
: MMLocalClass
237 cur_m
= explicit_super_init_calls
[i
]
238 cur_c
= cur_m
.global
.intro
.local_class
241 while j
< v
.local_class
.cshe
.direct_greaters
.length
do
242 var c
= v
.local_class
.cshe
.direct_greaters
[j
]
243 if cur_c
!= null and c
.cshe
<= cur_c
then
244 if c
== cur_c
then j
+= 1
245 super_init_calls
.add
(cur_m
)
248 cur_m
= explicit_super_init_calls
[i
]
249 cur_c
= cur_m
.global
.intro
.local_class
255 var p
= v
.get_default_constructor_for
(self, c
, method
)
257 super_init_calls
.add
(p
)
267 redef meth after_typing
(v
)
269 if v
.variable_ctx
!= null then
270 v
.variable_ctx
.add
(variable
)
276 readable attr _stype
: MMType
277 redef meth after_typing
(v
)
279 _stype
= get_stype
(v
)
284 redef readable attr _stype
: MMType
286 # Is the expression the implicit receiver
287 meth is_implicit_self
: Bool do return false
289 # Is the expression the current receiver (implicit or explicit)
290 meth is_self
: Bool do return false
292 # Is the expression a variable access
293 meth is_variable
: Bool do return false
295 # The variable type information if current boolean expression is true
296 readable private attr _if_true_variable_ctx
: VariableContext
299 redef class AVardeclExpr
300 # Assiociated local variable
301 readable attr _variable
: Variable
303 redef meth after_typing
(v
)
305 var va
= new Variable(n_id
.to_symbol
, self)
307 v
.variable_ctx
.add
(va
)
309 if n_type
!= null then
310 va
.stype
= n_type
.stype
311 if n_expr
!= null then
312 v
.check_conform
(self, n_expr
.stype
, va
.stype
)
315 va
.stype
= n_expr
.stype
320 redef class ABlockExpr
321 redef meth accept_typing
(v
)
323 var old_var_ctx
= v
.variable_ctx
324 v
.variable_ctx
= v
.variable_ctx
.sub
328 v
.variable_ctx
= old_var_ctx
332 redef class AReturnExpr
333 redef meth after_typing
(v
)
335 var t
= v
.local_property
.signature
.return_type
336 if n_expr
== null and t
!= null then
337 v
.error
(self, "Error: Return without value in a function.")
338 else if n_expr
!= null and t
== null then
339 v
.error
(self, "Error: Return with value in a procedure.")
340 else if n_expr
!= null and t
!= null then
341 v
.check_conform
(self, n_expr
.stype
, t
)
347 redef meth accept_typing
(v
)
349 var old_var_ctx
= v
.variable_ctx
351 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
353 if n_expr
.if_true_variable_ctx
!= null then
354 v
.variable_ctx
= n_expr
.if_true_variable_ctx
358 # Restore variable ctx
359 v
.variable_ctx
= old_var_ctx
361 if n_else
!= null then
363 v
.variable_ctx
= old_var_ctx
368 redef class AWhileExpr
369 redef meth after_typing
(v
)
371 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
376 redef meth after_typing
(v
)
378 # pop context created in AForVardeclExpr
379 var varctx
= v
.variable_ctx
380 assert varctx
isa SubVariableContext
381 v
.variable_ctx
= varctx
.prev
385 redef class AForVardeclExpr
386 # Associated automatic local variable
387 readable attr _variable
: Variable
389 redef meth after_typing
(v
)
391 v
.variable_ctx
= v
.variable_ctx
.sub
392 var variable
= new Variable(n_id
.to_symbol
, self)
394 v
.variable_ctx
.add
(variable
)
396 var expr_type
= n_expr
.stype
397 if not v
.check_conform
(self, expr_type
, v
.type_collection
) then
400 var prop
= expr_type
.select_method
(once
("iterator".to_symbol
))
402 v
.error
(self, "Error: Collection MUST have an iterate method")
405 var iter_type
= prop
.signature
.return_type
406 var prop2
= iter_type
.select_method
(once
("item".to_symbol
))
407 if prop2
== null then
408 v
.error
(self, "Error: {iter_type} MUST have an item method")
411 var t
= prop2
.signature
.return_type
412 if not n_expr
.is_self
then t
= t
.not_for_self
417 redef class AAssertExpr
418 redef meth after_typing
(v
)
420 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
421 if n_expr
.if_true_variable_ctx
!= null then v
.variable_ctx
= n_expr
.if_true_variable_ctx
425 redef class AVarFormExpr
426 # Associated local variable
427 readable writable attr _variable
: Variable
431 redef meth is_variable
do return true
433 redef meth after_typing
(v
)
435 _stype
= v
.variable_ctx
.stype
(variable
)
439 redef class AVarAssignExpr
440 redef meth after_typing
(v
)
442 var t
= v
.variable_ctx
.stype
(variable
)
443 v
.check_conform
(self, n_value
.stype
, t
)
447 redef class AReassignFormExpr
448 # Compute and check method used through the reassigment operator
449 private meth do_lvalue_typing
(v
: TypingVisitor, type_lvalue
: MMType)
451 if type_lvalue
== null then
454 var name
= n_assign_op
.method_name
455 var prop
= type_lvalue
.select_method
(name
)
457 v
.error
(self, "Error: Method '{name}' doesn't exists in {type_lvalue}.")
460 prop
.global
.check_visibility
(v
, self, v
.module, false)
461 var psig
= prop
.signature
462 _assign_method
= prop
463 v
.check_conform
(self, n_value
.stype
, psig
[0].not_for_self
)
464 v
.check_conform
(self, psig
.return_type
.not_for_self
, n_value
.stype
)
467 # Method used through the reassigment operator (once computed)
468 readable attr _assign_method
: MMMethod
471 redef class PAssignOp
472 meth method_name
: Symbol is abstract
474 redef class APlusAssignOp
475 redef meth method_name
do return once
"+".to_symbol
477 redef class AMinusAssignOp
478 redef meth method_name
do return once
"-".to_symbol
481 redef class AVarReassignExpr
482 redef meth after_typing
(v
)
484 var t
= v
.variable_ctx
.stype
(variable
)
485 do_lvalue_typing
(v
, t
)
489 redef class ASelfExpr
490 redef meth after_typing
(v
)
492 assert v
.self_type
!= null
496 redef meth is_self
do return true
499 redef class AImplicitSelfExpr
500 redef meth is_implicit_self
do return true
503 redef class AIfexprExpr
504 redef meth accept_typing
(v
)
506 var old_var_ctx
= v
.variable_ctx
509 if n_expr
.if_true_variable_ctx
!= null then v
.variable_ctx
= n_expr
.if_true_variable_ctx
511 v
.variable_ctx
= old_var_ctx
514 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
517 var te
= n_else
.stype
520 else if not te
< t
then
521 v
.error
(self, "Type error: {te} is not a subtype of {t}.")
529 redef class ABoolExpr
530 redef meth after_typing
(v
)
537 redef meth after_typing
(v
)
539 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
540 v
.check_conform
(self, n_expr2
.stype
, v
.type_bool
)
546 redef meth accept_typing
(v
)
548 var old_var_ctx
= v
.variable_ctx
551 if n_expr
.if_true_variable_ctx
!= null then v
.variable_ctx
= n_expr
.if_true_variable_ctx
554 if n_expr2
.if_true_variable_ctx
!= null then
555 _if_true_variable_ctx
= n_expr2
.if_true_variable_ctx
557 _if_true_variable_ctx
= v
.variable_ctx
560 v
.variable_ctx
= old_var_ctx
562 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
563 v
.check_conform
(self, n_expr2
.stype
, v
.type_bool
)
569 redef meth after_typing
(v
)
571 v
.check_conform
(self, n_expr
.stype
, v
.type_bool
)
577 redef meth after_typing
(v
)
584 redef class AFloatExpr
585 redef meth after_typing
(v
)
587 _stype
= v
.type_float
591 redef class ACharExpr
592 redef meth after_typing
(v
)
598 redef class AStringFormExpr
599 redef meth after_typing
(v
)
601 _stype
= v
.type_string
605 redef class ASuperstringExpr
606 redef meth after_typing
(v
)
608 _stype
= v
.type_string
612 redef class ANullExpr
613 redef meth after_typing
(v
)
619 redef class AArrayExpr
620 private meth stype
=(t
: MMType) do _stype
= t
622 redef meth after_typing
(v
)
627 if stype
== null or (ntype
!= null and stype
< ntype
) then
632 v
.check_conform
(self, n
.stype
, stype
)
634 _stype
= v
.type_array
(stype
)
638 redef class ARangeExpr
639 redef meth after_typing
(v
)
641 var ntype
= n_expr
.stype
642 var ntype2
= n_expr2
.stype
643 if ntype
== null or ntype
== null then
646 if ntype
< ntype2
then
648 else if not ntype2
< ntype
then
649 v
.error
(self, "Type error: {ntype} incompatible with {ntype2}.")
652 var dtype
= v
.type_discrete
653 v
.check_conform
(self, ntype
, dtype
)
654 _stype
= v
.type_range
(ntype
)
658 redef class ASuperExpr
659 special ASuperInitCall
660 # readable attr _prop: MMSrcMethod
661 readable attr _init_in_superclass
: MMMethod
662 redef meth after_typing
(v
)
664 var precs
: Array[MMLocalProperty] = v
.local_property
.cprhe
.direct_greaters
665 if not precs
.is_empty
then
666 v
.local_property
.need_super
= true
667 else if v
.local_property
.global
.is_init
then
668 var base_precs
= v
.local_class
.super_methods_named
(v
.local_property
.name
)
669 for p
in base_precs
do
670 if not p
.global
.is_init
then
671 v
.error
(self, "Error: {p.local_class}::{p} is not a constructor.")
673 precs
.add
(v
.self_type
.select_property
(p
.global
))
676 if precs
.is_empty
then
677 v
.error
(self, "Error: No contructor named {v.local_property.name} in superclasses.")
679 else if precs
.length
> 1 then
680 v
.error
(self, "Error: Conflicting contructors named {v.local_property.name} in superclasses: {precs.join(", ")}.")
683 var p
= base_precs
.first
684 assert p
isa MMMethod
685 _init_in_superclass
= p
686 register_super_init_call
(v
, p
)
687 if n_args
.length
> 0 then
688 _arguments
= process_signature
(v
, p
, true, n_args
.to_a
)
691 v
.error
(self, "Error: No super method to call for {v.local_property}.")
695 if precs
.first
.signature
.return_type
!= null then
696 var stypes
= new Array[MMType]
699 assert prop
isa MMMethod
700 var t
= prop
.signature
.return_type
.for_module
(v
.module).adapt_to
(v
.local_property
.signature
.recv
)
702 if stype
== null or stype
< t
then
707 v
.check_conform
(self, t
, stype
)
711 var p
= v
.local_property
712 assert p
isa MMSrcMethod
717 redef class AAttrFormExpr
719 readable attr _prop
: MMAttribute
721 # Compute the attribute accessed
722 private meth do_typing
(v
: TypingVisitor)
724 var type_recv
= n_expr
.stype
725 if type_recv
== null then
728 var name
= n_id
.to_symbol
729 var prop
= type_recv
.select_attribute
(name
)
731 v
.error
(self, "Error: Attribute {name} doesn't exists in {type_recv}.")
733 else if v
.module.visibility_for
(prop
.global
.local_class
.module) < 3 then
734 v
.error
(self, "Error: Attribute {name} from {prop.global.local_class.module} is invisible in {v.module}")
740 redef class AAttrExpr
741 redef meth after_typing
(v
)
747 var attr_type
= prop
.signature
.return_type
748 if not n_expr
.is_self
then attr_type
= attr_type
.not_for_self
753 redef class AAttrAssignExpr
754 redef meth after_typing
(v
)
760 var attr_type
= prop
.signature
.return_type
761 if not n_expr
.is_self
then attr_type
= attr_type
.not_for_self
762 v
.check_conform
(self, n_value
.stype
, attr_type
)
766 redef class AAttrReassignExpr
767 redef meth after_typing
(v
)
773 var attr_type
= prop
.signature
.return_type
774 if not n_expr
.is_self
then attr_type
= attr_type
.not_for_self
775 do_lvalue_typing
(v
, attr_type
)
781 # Compute the called global property
782 private meth do_typing
(v
: TypingVisitor, type_recv
: MMType, is_implicit_self
: Bool, recv_is_self
: Bool, name
: Symbol, raw_args
: Array[PExpr])
784 var prop
= get_property
(v
, type_recv
, is_implicit_self
, name
)
785 if prop
== null then return
786 var args
= process_signature
(v
, prop
, recv_is_self
, raw_args
)
787 if args
== null then return
792 private meth get_property
(v
: TypingVisitor, type_recv
: MMType, is_implicit_self
: Bool, name
: Symbol): MMMethod
794 if type_recv
== null then return null
795 var prop
= type_recv
.select_method
(name
)
796 if prop
== null and v
.local_property
.global
.is_init
then
797 var props
= type_recv
.local_class
.super_methods_named
(name
)
798 if props
.length
> 1 then
799 v
.error
(self, "Error: Ambigous method name '{name}' for {props.join(", ")}. Use explicit designation.")
801 else if props
.length
== 1 then
802 var p
= type_recv
.select_property
(props
.first
.global
)
803 assert p
isa MMMethod
809 if is_implicit_self
then
810 v
.error
(self, "Error: Method or variable '{name}' unknown in {type_recv}.")
812 v
.error
(self, "Error: Method '{name}' doesn't exists in {type_recv}.")
819 private meth process_signature
(v
: TypingVisitor, prop
: MMMethod, recv_is_self
: Bool, raw_args
: Array[PExpr]): Array[PExpr]
821 prop
.global
.check_visibility
(v
, self, v
.module, recv_is_self
)
822 var psig
= prop
.signature
823 var par_vararg
= psig
.vararg_rank
824 var par_arity
= psig
.arity
826 if raw_args
== null then raw_arity
= 0 else raw_arity
= raw_args
.length
827 if par_arity
> raw_arity
or (par_arity
!= raw_arity
and par_vararg
== -1) then
828 v
.error
(self, "Error: Method '{prop}' arity missmatch.")
832 var args
= new Array[PExpr]
833 for par_idx
in [0..par_arity
[ do
835 var par_type
= psig
[par_idx
]
836 if not recv_is_self
then par_type
= par_type
.not_for_self
837 if par_idx
== par_vararg
then
838 var star
= new Array[PExpr]
839 for i
in [0..(raw_arity-par_arity
)] do
840 a
= raw_args
[arg_idx
]
841 v
.check_conform
(self, a
.stype
, par_type
)
843 arg_idx
= arg_idx
+ 1
845 var aa
= new AArrayExpr.init_aarrayexpr
(star
)
846 aa
.stype
= v
.type_array
(par_type
)
849 a
= raw_args
[arg_idx
]
850 v
.check_conform
(self, a
.stype
, par_type
)
851 arg_idx
= arg_idx
+ 1
858 # The invoked method (once computed)
859 readable attr _prop
: MMMethod
861 # The real arguments used (after star transformation) (once computed)
862 readable attr _arguments
: Array[PExpr]
865 # A possible call of constructor in a super class
866 # Could be an explicit call or with the 'super' keyword
869 private meth register_super_init_call
(v
: TypingVisitor, property
: MMMethod)
871 if parent
!= v
.top_block
and self != v
.top_block
then
872 v
.error
(self, "Error: Constructor invocation {property} must not be in nested block.")
874 var cla
= v
.module[property
.global
.intro
.local_class
.global
]
875 var prev_class
: MMLocalClass
876 if not v
.explicit_super_init_calls
.is_empty
then
877 prev_class
= v
.explicit_super_init_calls
.last
.global
.intro
.local_class
879 var order
= v
.local_class
.cshe
.reverse_linear_extension
880 if cla
== v
.local_class
then
881 v
.explicit_other_init_call
= true
882 else if not order
.has
(cla
) then
883 v
.error
(self, "Error: Constructor of class {cla} must be one in {order.join(", ")}.")
884 else if cla
== prev_class
then
885 v
.error
(self, "Error: Only one super constructor invocation of class {cla} is allowed.")
887 var last_is_found
= prev_class
== null
889 if c
== prev_class
then
891 else if c
== cla
then
892 if not last_is_found
then
893 v
.error
(self, "Error: Constructor of {c} must be invoked before constructor of {prev_class}")
895 v
.explicit_super_init_calls
.add
(property
)
906 redef meth after_typing
(v
)
909 if t
== null then return
910 if t
.local_class
.global
.is_abstract
then
911 v
.error
(self, "Error: try to instantiate abstract class {t.local_class}.")
916 name
= once
"init".to_symbol
918 name
= n_id
.to_symbol
921 do_typing
(v
, t
, false, false, name
, n_args
.to_a
)
922 if not prop
.global
.is_init
then
923 v
.error
(self, "Error: {prop} is not a constructor.")
930 redef class ASendExpr
931 special ASuperInitCall
932 # Name of the invoked property
933 meth name
: Symbol is abstract
935 # Raw arguments used (withour star transformation)
936 meth raw_arguments
: Array[PExpr] is abstract
938 redef meth after_typing
(v
)
943 private meth do_all_typing
(v
: TypingVisitor)
945 do_typing
(v
, n_expr
.stype
, n_expr
.is_implicit_self
, n_expr
.is_self
, name
, raw_arguments
)
946 if prop
== null then return
947 if prop
.global
.is_init
then
948 if not v
.local_property
.global
.is_init
then
949 v
.error
(self, "Error: try to invoke constructor {prop} in a method.")
950 else if not n_expr
.is_self
then
951 v
.error
(self, "Error: constructor {prop} is not invoken on 'self'.")
953 register_super_init_call
(v
, prop
)
956 var t
= prop
.signature
.return_type
957 if t
!= null and not n_expr
.is_self
then t
= t
.not_for_self
962 class ASendReassignExpr
964 special AReassignFormExpr
965 readable attr _read_prop
: MMMethod
966 redef meth do_all_typing
(v
)
968 var raw_args
= raw_arguments
969 do_typing
(v
, n_expr
.stype
, n_expr
.is_implicit_self
, n_expr
.is_self
, name
, raw_args
)
970 if prop
== null then return
971 if prop
.global
.is_init
then
972 if not v
.local_property
.global
.is_init
then
973 v
.error
(self, "Error: try to invoke constructor {prop} in a method.")
974 else if not n_expr
.is_self
then
975 v
.error
(self, "Error: constructor {prop} is not invoken on 'self'.")
978 var t
= prop
.signature
.return_type
979 if not n_expr
.is_self
then t
= t
.not_for_self
981 do_lvalue_typing
(v
, t
)
984 var old_args
= arguments
985 raw_args
.add
(n_value
)
987 do_typing
(v
, n_expr
.stype
, n_expr
.is_implicit_self
, n_expr
.is_self
, "{name}=".to_symbol
, raw_args
)
988 if prop
== null then return
989 if prop
.global
.is_init
then
990 if not v
.local_property
.global
.is_init
then
991 v
.error
(self, "Error: try to invoke constructor {prop} in a method.")
992 else if not n_expr
.is_self
then
993 v
.error
(self, "Error: constructor {prop} is not invoken on 'self'.")
997 _arguments
= old_args
# FIXME: What if star parameters do not match betwen the two methods?
1001 redef class ABinopExpr
1002 redef meth raw_arguments
do return [n_expr2
]
1005 redef meth name
do return once
"==".to_symbol
1008 redef meth name
do return once
"!=".to_symbol
1011 redef meth name
do return once
"<".to_symbol
1014 redef meth name
do return once
"<=".to_symbol
1017 redef meth name
do return once
">".to_symbol
1020 redef meth name
do return once
">=".to_symbol
1022 redef class APlusExpr
1023 redef meth name
do return once
"+".to_symbol
1025 redef class AMinusExpr
1026 redef meth name
do return once
"-".to_symbol
1028 redef class AStarshipExpr
1029 redef meth name
do return once
"<=>".to_symbol
1031 redef class AStarExpr
1032 redef meth name
do return once
"*".to_symbol
1034 redef class ASlashExpr
1035 redef meth name
do return once
"/".to_symbol
1037 redef class APercentExpr
1038 redef meth name
do return once
"%".to_symbol
1041 redef class AUminusExpr
1042 redef meth name
do return once
"unary -".to_symbol
1043 redef meth raw_arguments
do return null
1046 redef class ACallFormExpr
1047 redef meth after_typing
(v
)
1049 if n_expr
.is_implicit_self
then
1050 var name
= n_id
.to_symbol
1051 var variable
= v
.variable_ctx
[name
]
1052 if variable
!= null then
1053 if not n_args
.is_empty
then
1054 v
.error
(self, "Error: {name} is variable, not a function.")
1056 var vform
= variable_create
(variable
)
1057 vform
.variable
= variable
1059 vform
.after_typing
(v
)
1066 # Create a variable acces corresponding to the call form
1067 meth variable_create
(variable
: Variable): AVarFormExpr is abstract
1070 redef class ACallExpr
1071 redef meth variable_create
(variable
)
1073 return new AVarExpr.init_avarexpr
(n_id
)
1076 redef meth name
do return n_id
.to_symbol
1077 redef meth raw_arguments
do return n_args
.to_a
1080 redef class ACallAssignExpr
1081 redef meth variable_create
(variable
)
1083 return new AVarAssignExpr.init_avarassignexpr
(n_id
, n_assign
, n_value
)
1086 redef meth name
do return (n_id
.text
+ "=").to_symbol
1087 redef meth raw_arguments
do
1088 var res
= n_args
.to_a
1094 redef class ACallReassignExpr
1095 special ASendReassignExpr
1096 redef meth variable_create
(variable
)
1098 return new AVarReassignExpr.init_avarreassignexpr
(n_id
, n_assign_op
, n_value
)
1101 redef meth name
do return n_id
.to_symbol
1102 redef meth raw_arguments
do return n_args
.to_a
1105 redef class ABraExpr
1106 redef meth name
do return once
"[]".to_symbol
1107 redef meth raw_arguments
do return n_args
.to_a
1110 redef class ABraAssignExpr
1111 redef meth name
do return once
"[]=".to_symbol
1112 redef meth raw_arguments
do
1113 var res
= n_args
.to_a
1119 redef class ABraReassignExpr
1120 special ASendReassignExpr
1121 redef meth name
do return once
"[]".to_symbol
1122 redef meth raw_arguments
do return n_args
.to_a
1125 redef class AInitExpr
1126 redef meth name
do return once
"init".to_symbol
1127 redef meth raw_arguments
do return n_args
.to_a
1130 redef class AIsaExpr
1131 redef meth after_typing
(v
)
1133 if n_expr
.is_variable
then
1135 assert n
isa AVarExpr
1136 _if_true_variable_ctx
= v
.variable_ctx
.sub_with
(n
.variable
, n_type
.stype
)
1138 _stype
= v
.type_bool
1142 redef class AProxyExpr
1143 redef meth after_typing
(v
)
1145 _stype
= n_expr
.stype