n_mpropdef.n_block
to the contract
# Method to adapt the `n_mpropdef.n_block` to the contract
private fun adapt_block_to_contract(v: ContractsVisitor, n_mpropdef: AMethPropdef) is abstract
src/contracts.nit:320,2--321,95
redef fun adapt_block_to_contract(v: ContractsVisitor, n_mpropdef: AMethPropdef)
do
var callsite = v.ast_builder.create_callsite(v.toolcontext.modelbuilder, n_mpropdef, self, true)
var n_self = new ASelfExpr
var args = n_mpropdef.n_signature.make_parameter_read(v.ast_builder)
var n_callexpect = v.ast_builder.make_call(n_self,callsite,args)
# Creation of the new instruction block with the call to expect condition
var actual_expr = n_mpropdef.n_block
var new_block = new ABlockExpr
new_block.n_expr.push n_callexpect
if actual_expr isa ABlockExpr then
new_block.n_expr.add_all(actual_expr.n_expr)
else if actual_expr != null then
new_block.n_expr.push(actual_expr)
end
n_mpropdef.n_block = new_block
end
src/contracts.nit:446,2--462,4
redef fun adapt_block_to_contract(v: ContractsVisitor, n_mpropdef: AMethPropdef)
do
var callsite = v.ast_builder.create_callsite(v.toolcontext.modelbuilder, n_mpropdef, self, true)
var n_self = new ASelfExpr
# argument to call the contract method
var args = n_mpropdef.n_signature.make_parameter_read(v.ast_builder)
# Inject the variable result
# The cast is always safe because the online adapted method is the contract facet
var actual_block = n_mpropdef.n_block
# never happen. If it's the case the problem is in the contract facet building
assert actual_block isa ABlockExpr
var ret_type = n_mpropdef.mpropdef.mproperty.intro.msignature.return_mtype
if ret_type != null then
var result_var = inject_result(v, n_mpropdef, ret_type)
# Expr to read the result variable
var read_result = v.ast_builder.make_var_read(result_var, ret_type)
var return_expr = actual_block.n_expr.pop
# Adding the read return to argument
args.add(read_result)
var n_callcontract = v.ast_builder.make_call(n_self,callsite,args)
actual_block.add_all([n_callcontract,return_expr])
else
# build the call to the contract method
var n_callcontract = v.ast_builder.make_call(n_self,callsite,args)
actual_block.add n_callcontract
end
end
src/contracts.nit:545,2--573,4