diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java index 285af81..67ea910 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java @@ -18,6 +18,7 @@ import models.algebra.Expression; import models.algebra.InvalidMessage; import models.algebra.ParameterizedIdentifierIsFutureWork; +import models.algebra.Position; import models.algebra.Term; import models.algebra.Type; import models.algebra.UnificationFailed; @@ -312,8 +313,25 @@ if (message instanceof Term) { // Declare an input method in this component. ArrayList params = new ArrayList<>(); - for (Variable var: message.getVariables().values()) { - params.add(langSpec.newVariableDeclaration(var.getType(), var.getName())); + for (Map.Entry varEnt: message.getVariables().entrySet()) { + Variable var = varEnt.getValue(); + String refVarName = null; + for (ChannelMember refCm: ((DataTransferChannel) ch).getReferenceChannelMembers()) { + Expression varExp = refCm.getStateTransition().getMessageExpression().getSubTerm(varEnt.getKey()); + if (varExp != null && varExp instanceof Variable) { + if (refCm.getStateTransition().getCurStateExpression().contains(varExp)) { + refVarName = refCm.getResource().getResourceName(); + break; + } + } + } + if (refVarName != null) { + // var has come from a reference resource. + params.add(langSpec.newVariableDeclaration(var.getType(), refVarName)); + } else { + // var has not come from reference resource. + params.add(langSpec.newVariableDeclaration(var.getType(), var.getName())); + } } input = langSpec.newMethodDeclaration(((Term) message).getSymbol().getImplName(), false, null, params); component.addMethod(input); @@ -358,8 +376,20 @@ if (mainInput != null) { List args = new ArrayList<>(); if (message instanceof Term) { - for (Variable var: message.getVariables().values()) { - args.add(var.getName()); + for (Map.Entry varEnt: message.getVariables().entrySet()) { + String refVarName = null; + for (ChannelMember rc: ((DataTransferChannel) ch).getReferenceChannelMembers()) { + Expression varExp = rc.getStateTransition().getMessageExpression().getSubTerm(varEnt.getKey()); + if (varExp != null && rc.getStateTransition().getCurStateExpression().contains(varExp)) { + refVarName = rc.getResource().getResourceName(); + break; + } + } + if (refVarName != null) { + args.add(refVarName); + } else { + args.add(varEnt.getValue().getName()); + } } } mainInput.addStatement(langSpec.getMethodInvocation(langSpec.getFieldAccessor(resName), input.getName(), args) + langSpec.getStatementDelimiter()); @@ -370,7 +400,7 @@ try { String[] sideEffects = new String[] {""}; Expression updateExp; - updateExp = ((DataTransferChannel) ch).deriveUpdateExpressionOf(out, getPullAccessor()); + updateExp = ((DataTransferChannel) ch).deriveUpdateExpressionOf(out, getRefAccessor()); String newState = updateExp.toImplementation(sideEffects); String updateStatement; if (updateExp instanceof Term && ((Term) updateExp).getSymbol().isImplWithSideEffect()) {