diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java index 5166228..89844c7 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java @@ -25,6 +25,7 @@ import models.dataFlowModel.ResourceDependency; import models.dataFlowModel.ResourceDependencyGraph; import models.dataFlowModel.ResourceNode; +import models.dataFlowModel.StoreAttribute; public class MethodBodyGenerator { public static ArrayList doGenerate(ResourceDependencyGraph graph, DataFlowModel model, ArrayList types) { @@ -65,16 +66,26 @@ if (pushPull.getOptions().get(0) == PushPullValue.PUSH) { // for push data transfer MethodDeclaration update = getUpdateMethod(dstType, srcType); - Expression updateExp = d.getChannelGenerator().deriveUpdateExpressionOf(out, CodeGenerator.pushAccessor); - String curState = updateExp.toImplementation(); - String updateStatement; - if (updateExp instanceof Term && ((Term) updateExp).getSymbol().getImplOperatorType() == Symbol.Type.METHOD_WITH_SIDE_EFFECT) { - updateStatement = curState + ";"; - } else { - updateStatement = dstResourceName + " = " + curState + ";"; + if (((StoreAttribute) dst.getAttribute()).isStored()) { + // update stored state of dst resource (when every incoming edge is in push style) + Expression updateExp = d.getChannelGenerator().deriveUpdateExpressionOf(out, CodeGenerator.pushAccessor); + String curState = updateExp.toImplementation(); + String updateStatement; + if (updateExp instanceof Term && ((Term) updateExp).getSymbol().getImplOperatorType() == Symbol.Type.METHOD_WITH_SIDE_EFFECT) { + updateStatement = curState + ";"; + } else { + updateStatement = dstResourceName + " = " + curState + ";"; + } + if (update.getBody() == null || !update.getBody().getStatements().contains(updateStatement)) { + update.addFirstStatement(updateStatement); + } } - if (update.getBody() == null || !update.getBody().getStatements().contains(updateStatement)) { - update.addFirstStatement(updateStatement); + if (dst.getIndegree() > 1) { + // update a cash of src resource (when incoming edges are multiple) + String cashStatement = "this." + srcResourceName + " = " + srcResourceName + ";"; + if (update.getBody() == null || !update.getBody().getStatements().contains(cashStatement)) { + update.addFirstStatement(cashStatement); + } } MethodDeclaration getter = getGetterMethod(dstType); if (getter.getBody() == null || getter.getBody().getStatements().size() == 0) {