nitc :: AbstractCompilerVisitor :: expr
mtype
is the expected return type, pass null if no specific type is expected.
# Compile an expression an return its result
# `mtype` is the expected return type, pass null if no specific type is expected.
fun expr(nexpr: AExpr, mtype: nullable MType): RuntimeVariable
do
var old = self.current_node
self.current_node = nexpr
var res = null
if nexpr.mtype != null then
res = nexpr.expr(self)
end
if res == null then
# Untyped expression.
# Might mean dead code or invalid code.
# so aborts
add_abort("FATAL: bad expression executed.")
# and return a placebo result to please the C compiler
if mtype == null then mtype = compiler.mainmodule.object_type
res = new_var(mtype)
self.current_node = old
return res
end
if mtype != null then
mtype = self.anchor(mtype)
res = self.autobox(res, mtype)
end
res = autoadapt(res, nexpr.mtype.as(not null))
var implicit_cast_to = nexpr.implicit_cast_to
if implicit_cast_to != null and not self.compiler.modelbuilder.toolcontext.opt_no_check_autocast.value then
add_cast(res, implicit_cast_to, "auto")
res = autoadapt(res, implicit_cast_to)
end
self.current_node = old
return res
end
src/compiler/abstract_compiler.nit:2001,2--2038,4