Skip to content

Commit

Permalink
ASTBuilder::create_callsite simplify API
Browse files Browse the repository at this point in the history
Signed-off-by: Jean Privat <jean@pryen.org>
  • Loading branch information
privat committed Aug 16, 2024
1 parent 5ce7bb8 commit 183495a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/astbuilder.nit
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ class ASTBuilder

# Build a callsite to call the `mproperty` in the current method `caller_method`.
# `is_self_call` indicate if the method caller is a property of `self`
fun create_callsite(modelbuilder: ModelBuilder, caller_property: APropdef, mproperty: MMethod, is_self_call: Bool): CallSite
fun create_callsite(mproperty: MMethod, is_self_call: Bool): CallSite
do
var recv = mproperty.intro_mclassdef.bound_mtype
var builder = new CallSiteBuilder(caller_property.hot_location, recv, self)
var builder = new CallSiteBuilder(mmodule.model.no_location, recv, self)
var callsite = builder.recv_is_self(is_self_call).by_property(mproperty)
assert callsite != null
return callsite
Expand Down
14 changes: 7 additions & 7 deletions src/contracts.nit
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ private class ContractsVisitor
private fun encapsulated_contract_call(visited_method: AMethPropdef, call_to_contracts: Array[ACallExpr]): AIfExpr
do
var sys_property = toolcontext.modelbuilder.model.get_mproperties_by_name("sys").first.as(MMethod)
var callsite_sys = ast_builder.create_callsite(toolcontext.modelbuilder, visited_method, sys_property, true)
var callsite_sys = ast_builder.create_callsite(sys_property, true)

var incontract_attribute = get_incontract

var callsite_get_incontract = ast_builder.create_callsite(toolcontext.modelbuilder, visited_method, incontract_attribute.getter.as(MMethod), false)
var callsite_set_incontract = ast_builder.create_callsite(toolcontext.modelbuilder, visited_method, incontract_attribute.setter.as(MMethod), false)
var callsite_get_incontract = ast_builder.create_callsite(incontract_attribute.getter.as(MMethod), false)
var callsite_set_incontract = ast_builder.create_callsite(incontract_attribute.setter.as(MMethod), false)

var n_condition = ast_builder.make_not(ast_builder.make_call(ast_builder.make_call(new ASelfExpr, callsite_sys, null), callsite_get_incontract, null))

Expand Down Expand Up @@ -244,7 +244,7 @@ private class CallSiteVisitor
if visited_mpropdef isa MContract or visited_mpropdef isa MFacet then return callsite
if visited_mpropdef == null or contract_facet == null then return callsite

return ast_builder.create_callsite(toolcontext.modelbuilder, visited_propdef, contract_facet, callsite.recv_is_self)
return ast_builder.create_callsite(contract_facet, callsite.recv_is_self)
end
end

Expand Down Expand Up @@ -428,7 +428,7 @@ redef class MExpect

redef fun adapt_method_to_contract(v: ContractsVisitor, mfacet: MFacet, n_mpropdef: AMethPropdef)
do
var callsite = v.ast_builder.create_callsite(v.toolcontext.modelbuilder, n_mpropdef, self, true)
var callsite = v.ast_builder.create_callsite(self, true)
var args = n_mpropdef.n_signature.make_parameter_read(v.ast_builder)
var n_callexpect = v.ast_builder.make_call(new ASelfExpr, callsite,args)
# Creation of the new instruction block with the call to expect condition
Expand Down Expand Up @@ -520,7 +520,7 @@ redef class MEnsure

redef fun adapt_method_to_contract(v: ContractsVisitor, mfacet: MFacet, n_mpropdef: AMethPropdef)
do
var callsite = v.ast_builder.create_callsite(v.toolcontext.modelbuilder, n_mpropdef, self, true)
var callsite = v.ast_builder.create_callsite(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)
Expand Down Expand Up @@ -641,7 +641,7 @@ redef class MMethod
var args: Array[AExpr]
args = n_contractdef.n_signature.make_parameter_read(v.ast_builder)

var callsite = v.ast_builder.create_callsite(v.toolcontext.modelbuilder, n_contractdef, called, true)
var callsite = v.ast_builder.create_callsite(called, true)
var n_call = v.ast_builder.make_call(new ASelfExpr, callsite, args)

if self.intro.msignature.return_mtype == null then
Expand Down

0 comments on commit 183495a

Please sign in to comment.