| |
---|
| | import models.dataFlowModel.ResolvingMultipleDefinitionIsFutureWork; |
---|
| | import models.dataFlowModel.ResourceDependency; |
---|
| | import models.dataFlowModel.ResourceDependencyGraph; |
---|
| | import models.dataFlowModel.ResourceNode; |
---|
| | import models.dataFlowModel.StoreAttribute; |
---|
| | |
---|
| | public class MethodBodyGenerator { |
---|
| | public static ArrayList<TypeDeclaration> doGenerate(ResourceDependencyGraph graph, DataFlowModel model, ArrayList<TypeDeclaration> types) { |
---|
| | Symbol floor = model.getSymbol("floor"); |
---|
| |
---|
| | if (out.getIdentifierTemplate() == dst.getIdentifierTemplate()) { |
---|
| | 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) { |
---|
| | getter.addStatement("return " + dstResourceName + ";"); |
---|
| |
---|
| | |