From 1091127dadad3a7fd54bbe4936256fd8f4d118e8 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Sat, 17 Aug 2024 16:23:27 -0400 Subject: [PATCH] ASTBuilder: use CallSiteBuilder Signed-off-by: Jean Privat --- src/astbuilder.nit | 8 ++++---- src/contracts.nit | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/astbuilder.nit b/src/astbuilder.nit index 52e84eb1e4..d0602eea2e 100644 --- a/src/astbuilder.nit +++ b/src/astbuilder.nit @@ -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 diff --git a/src/contracts.nit b/src/contracts.nit index 92af83d29f..132be36277 100644 --- a/src/contracts.nit +++ b/src/contracts.nit @@ -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)) @@ -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 @@ -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 @@ -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) @@ -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) @@ -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