Skip to content

Commit

Permalink
ASTBuilder: use CallSiteBuilder
Browse files Browse the repository at this point in the history
Signed-off-by: Jean Privat <[email protected]>
  • Loading branch information
privat committed Aug 17, 2024
1 parent 606677b commit 1091127
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/astbuilder.nit
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ 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
# FIXME It's not the better solution to call `TypeVisitor` here to build a model entity, but some make need to have a callsite
var type_visitor = new TypeVisitor(modelbuilder, caller_property.mpropdef.as(not null))
var callsite = type_visitor.build_callsite_by_property(caller_property, mproperty.intro_mclassdef.bound_mtype, mproperty, is_self_call)
var recv = mproperty.intro_mclassdef.bound_mtype
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
end
Expand Down
16 changes: 8 additions & 8 deletions src/contracts.nit
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,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 @@ -302,7 +302,7 @@ private class CallSiteVisitor
facet = contract_facet
end

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

Expand Down Expand Up @@ -486,7 +486,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 @@ -578,7 +578,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 @@ -613,7 +613,7 @@ redef class MInvariant

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
# build the call to the contract method
var n_call = v.ast_builder.make_call(n_self, callsite, null)
Expand Down Expand Up @@ -880,7 +880,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 1091127

Please sign in to comment.