nitc :: ACallrefExpr
&x.foo
or just &foo
is self is captured.Currently, the syntax is analogous to a simple call (recv.foo
) with a prefix &
.
On chains, only the last call is captured (.
has a higher precedence than &
).
The syntax is analogous to a call (except the &), there is always a receiver (including the implicit self or sys) and arguments are accepted by the parser.
TODO There is no clear syntax proposal
Note: The class specializes ASendExpr
(trough ACallFormExpr
) so some behavior of a genuine send expression must be redefined.
nitc :: ACallrefExpr :: defaultinit
nitc $ ACallrefExpr :: SELF
Type of this instance, automatically specialized in every classnitc :: rapid_type_analysis $ ACallrefExpr :: accept_rapid_type_visitor
nitc :: typing $ ACallrefExpr :: accept_typing
nitc :: typing $ ACallrefExpr :: compute_raw_arguments
nitc :: naive_interpreter $ ACallrefExpr :: expr
Evaluate the node as a possible expression.nitc :: abstract_compiler $ ACallrefExpr :: expr
Try to compile self as an expressionnitc :: parser_prod $ ACallrefExpr :: n_args=
The arguments of the callnitc :: parser_prod $ ACallrefExpr :: n_expr=
The receiver of the method invocationnitc :: typing $ ACallrefExpr :: property_name
The name of the propertynitc :: typing $ ACallrefExpr :: property_node
The node identifying the name (id, operator, etc) for messages.nitc :: parser_prod $ ACallrefExpr :: replace_child
Replace a child with an other node in the ASTnitc :: parser_prod $ ACallrefExpr :: visit_all
Visit all nodes in order.nitc :: AExpr :: _after_flow_context
The flow after the full evaluation of the expression/statementnitc :: AExpr :: _comprehension
Is non-null ifself
is a leaf of a comprehension array construction.
nitc :: Prod :: _first_location
Location on the first token after the start of a productionnitc :: Prod :: _first_token
The first token of the production in the ASTnitc :: AExpr :: _implicit_cast_to
If required, the following implicit cast.as(XXX)
nitc :: ANode :: _is_broken
The indication that the node did not pass some semantic verifications.nitc :: Prod :: _last_token
The last token of the production in the ASTnitc :: Prod :: _n_annotations
All the annotations attached directly to the nodenitc :: AExpr :: _vararg_decl
It indicates the number of arguments collected as a vararg.nitc :: AExpr :: _variable_cache
nitc :: ANode :: accept_ast_validation
nitc :: ANode :: accept_auto_super_init
nitc :: AExpr :: accept_explain_assert
Fillv
to explain this node if the parent assert fails
nitc :: ANode :: accept_flow_visitor
nitc :: ANode :: accept_forward_analysis
Apply the forward analysisv
to self
.
nitc :: ANode :: accept_literal
nitc :: ANode :: accept_post_typing
nitc :: ANode :: accept_pretty_printer
Start visit ofself
using a PrettyPrinterVisitor
nitc :: ANode :: accept_reaching_defs
Apply a ReachingDefsAnalysis toself
.
nitc :: ANode :: accept_regex_visitor
nitc :: ANode :: accept_scope_visitor
nitc :: ANode :: accept_simple_misc
nitc :: ANode :: accept_string_finder
nitc :: AExpr :: accept_typing
nitc :: AExpr :: after_flow_context
The flow after the full evaluation of the expression/statementnitc :: AExpr :: after_flow_context=
The flow after the full evaluation of the expression/statementnitc :: ANode :: after_simple_misc
nitc :: AExpr :: allocate_mtype
Make themtype
of the expression live
nitc :: ANode :: bad_expr_message
An additional information message to explain the role of a child expression.nitc :: ANode :: check_callsite
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: ANode :: collect_annotations_by_name
Do a deep search and return an array of node that are annotatednitc :: Prod :: collect_comments
Collect allTComment
contained in the production
nitc :: ANode :: collect_length
Collect the length (inChar
) of the node.
nitc :: ANode :: collect_tokens_by_text
Do a deep search and return an array of tokens that match a given textnitc :: ANode :: common_parent
The most specific common parent betweenself
and other
nitc :: AExpr :: comprehension
Is non-null ifself
is a leaf of a comprehension array construction.
nitc :: AExpr :: comprehension=
Is non-null ifself
is a leaf of a comprehension array construction.
nitc :: ANode :: create_contracts
nitc :: ANode :: decorate_tag
Add aditionnal information on a child-token and return an additionnal HInfoBox on itnitc :: AExpr :: defaultinit
nitc :: ACallFormExpr :: defaultinit
core :: Cloneable :: defaultinit
nitc :: ACallrefExpr :: defaultinit
core :: Object :: defaultinit
nitc :: ASendExpr :: defaultinit
nitc :: ANode :: defaultinit
nitc :: Prod :: defaultinit
nitc :: AExpr :: detach_with_placeholder
Thedetach
method completely remove the node in the parent.
nitc :: ANode :: do_cloneable
nitc :: Prod :: first_location
Location on the first token after the start of a productionnitc :: Prod :: first_location=
Location on the first token after the start of a productionnitc :: Prod :: first_token
The first token of the production in the ASTnitc :: Prod :: first_token=
The first token of the production in the ASTnitc :: ANode :: force_block=
Forceself
to be rendered as a block.
nitc :: ANode :: force_inline=
Forceself
to be rendered as a line.
nitc :: ANode :: full_transform_visitor
nitc :: AExpr :: generate_basic_blocks
Generate recursively basic block for this expressionnitc :: Prod :: get_annotations
Return all its annotations of a given name in the order of their declarationnitc :: Prod :: get_single_annotation
Try to get its single annotation with a given namenitc :: ANode :: hot_location
The location of the important part of the node (identifier or whatever)nitc :: AExpr :: implicit_cast_to
If required, the following implicit cast.as(XXX)
nitc :: AExpr :: implicit_cast_to=
If required, the following implicit cast.as(XXX)
nitc :: ASendExpr :: init_asendexpr
nitc :: ANode :: is_broken=
The indication that the node did not pass some semantic verifications.nitc :: ANode :: is_noserialize
Is this node annotated to not be made serializable?core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
nitc :: ANode :: is_serialize
Is this node annotated to be made serializable?nitc :: ANode :: is_structural
Isself
a token or a pure-structural production like AQId
?
nitc :: Prod :: last_token
The last token of the production in the ASTnitc :: Prod :: last_token=
The last token of the production in the ASTnitc :: AExpr :: make_var_read
Return a new variable read that contains the value of the expressionnitc :: ANode :: must_be_block
Doesself
have to be rendered as a block?
nitc :: ANode :: must_be_inline
Doesself
have be rendered as a line?
nitc :: Prod :: n_annotations
All the annotations attached directly to the nodenitc :: Prod :: n_annotations=
All the annotations attached directly to the nodecore :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: ANode :: parentize_tokens
Visit the AST and computes advanced AST attributes on Tokens and Prodnitc :: ASendExpr :: property_name
The name of the propertynitc :: ASendExpr :: property_node
The node identifying the name (id, operator, etc) for messages.nitc :: ASendExpr :: raw_arguments
An array of all arguments (excluding self)nitc :: ANode :: replace_child
Replace a child with an other node in the ASTnitc :: ANode :: replace_with
Replace itself with an other node in the ASTnitc :: Prod :: start_token
The token where the production really start (skipping ADoc).nitc :: AExpr :: vararg_decl
It indicates the number of arguments collected as a vararg.nitc :: AExpr :: vararg_decl=
It indicates the number of arguments collected as a vararg.nitc :: AExpr :: variable_cache
nitc :: AExpr :: variable_cache=
nitc :: ACallFormExpr :: variable_create
Create a variable access corresponding to the call formnitc :: AExpr :: warn_parentheses
Warn in case of superfluous parenthesesnitc :: ANode :: was_inline
Doesself
was written in one line before transformation?
# A reference to a method with a captured receiver. eg. `&x.foo` or just `&foo` is self is captured.
#
# Currently, the syntax is analogous to a simple call (`recv.foo`) with a prefix `&`.
# On chains, only the last call is captured (`.` has a higher precedence than `&`).
#
# The syntax is analogous to a call (except the &), there is always a receiver (including the implicit self or sys) and arguments are accepted by the parser.
#
# TODO There is no clear syntax proposal
#
# * to avoid the capture of a receiver since a receiver is statically expected to resolve the method name
# * for special method names (setters, brackets and operators)
#
# Note: The class specializes `ASendExpr` (trough `ACallFormExpr`) so some behavior of a genuine send expression must be redefined.
class ACallrefExpr
super ACallFormExpr
# The `&` operator
var n_amp: TAmp is writable, noinit
end
src/parser/parser_nodes.nit:2459,1--2477,3
redef class ACallrefExpr
init init_acallrefexpr (
n_amp: nullable TAmp,
n_expr: nullable AExpr,
n_qid: nullable AQid,
n_args: nullable AExprs
)
do
_n_amp = n_amp.as(not null)
n_amp.parent = self
_n_expr = n_expr.as(not null)
n_expr.parent = self
_n_qid = n_qid.as(not null)
n_qid.parent = self
_n_args = n_args.as(not null)
n_args.parent = self
end
redef fun replace_child(old_child: ANode, new_child: nullable ANode)
do
if _n_amp == old_child then
n_amp = new_child.as(TAmp)
return
end
if _n_expr == old_child then
n_expr = new_child.as(AExpr)
return
end
if _n_qid == old_child then
n_qid = new_child.as(AQid)
return
end
if _n_args == old_child then
n_args = new_child.as(AExprs)
return
end
end
redef fun n_amp=(node)
do
_n_amp = node
node.parent = self
end
redef fun n_expr=(node)
do
_n_expr = node
node.parent = self
end
redef fun n_qid=(node)
do
_n_qid = node
node.parent = self
end
redef fun n_args=(node)
do
_n_args = node
node.parent = self
end
redef fun visit_all(v: Visitor)
do
v.enter_visit(_n_amp)
v.enter_visit(_n_expr)
v.enter_visit(_n_qid)
v.enter_visit(_n_args)
end
end
src/parser/parser_prod.nit:5436,1--5503,3
redef class ACallrefExpr
redef fun property_name do return n_qid.n_id.text
redef fun property_node do return n_qid
redef fun compute_raw_arguments do return n_args.to_a
redef fun accept_typing(v)
do
super # do the job as if it was a real call
var res = callsite.mproperty
var msignature = callsite.mpropdef.msignature
var recv = callsite.recv
assert msignature != null
var arity = msignature.mparameters.length
var routine_type_name = "ProcRef"
if msignature.return_mtype != null then
routine_type_name = "FunRef"
end
var target_routine_class = "{routine_type_name}{arity}"
var routine_mclass = v.get_mclass(self, target_routine_class)
if routine_mclass == null then
v.error(self, "Error: missing functional types, try `import functional`")
return
end
var types_list = new Array[MType]
for param in msignature.mparameters do
if param.is_vararg then
types_list.push(v.mmodule.array_type(param.mtype))
else
types_list.push(param.mtype)
end
end
if msignature.return_mtype != null then
types_list.push(msignature.return_mtype.as(not null))
end
# Why we need an anchor :
#
# ~~~~nitish
# class A[E]
# def toto(x: E) do print "{x}"
# end
#
# var a = new A[Int]
# var f = &a.toto # without anchor : ProcRef1[E]
# # with anchor : ProcRef[Int]
# ~~~~
# However, we can only anchor if we can resolve every formal
# parameter, here's an example where we can't.
# ~~~~nitish
# class A[E]
# fun bar: A[E] do return self
# fun foo: Fun0[A[E]] do return &bar # here we can't anchor
# end
# var f1 = a1.foo # when this expression will be evaluated,
# # `a1` will anchor `&bar` returned by `foo`.
# print f1.call
# ~~~~
var routine_type = routine_mclass.get_mtype(types_list)
if not recv.need_anchor then
routine_type = routine_type.anchor_to(v.mmodule, recv.as(MClassType))
end
is_typed = true
self.mtype = routine_type
end
end
src/semantize/typing.nit:2189,1--2258,3
redef class ACallrefExpr
redef fun accept_rapid_type_visitor(v)
do
super
v.add_type(mtype.as(MClassType))
end
end
src/rapid_type_analysis.nit:707,1--713,3
redef class ACallrefExpr
redef fun expr(v)
do
var recv = v.expr(self.n_expr)
if recv == null then return null
var mtype = self.mtype
assert mtype != null
# In case we are in generic class where formal parameter can not
# be resolved.
var mtype2 = v.unanchor_type(mtype)
var inst = new CallrefInstance(mtype2, recv, callsite.as(not null))
return inst
end
end
src/interpreter/naive_interpreter.nit:2296,1--2309,3