diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java index c27b6b3..3298912 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java @@ -8,9 +8,11 @@ import code.ast.TypeDeclaration; import models.Edge; import models.Node; +import models.algebra.Expression; import models.algebra.InvalidMessage; import models.algebra.ParameterizedIdentifierIsFutureWork; import models.algebra.Symbol; +import models.algebra.Term; import models.algebra.UnificationFailed; import models.algebra.ValueUndefined; import models.dataConstraintModel.ChannelMember; @@ -42,7 +44,7 @@ // Create a map from type names (lower case) to their types. Map typeMap = new HashMap<>(); for (TypeDeclaration type: types) { - typeMap.put(type.getTypeName().toLowerCase(), type); + typeMap.put(type.getTypeName().substring(0,1).toLowerCase() + type.getTypeName().substring(1), type); } // Generate the body of each update or getter method. @@ -61,18 +63,31 @@ if (pushPull.getOptions().get(0) == PushPullValue.PUSH) { // push MethodDeclaration update = getUpdateMethod(dstType); - String curState = d.getChannelGenerator().deriveUpdateExpressionOf(out, CodeGenerator.pushAccessor).toImplementation(); - update.addFirstStatement(dstResourceName + " = " + curState + ";"); + 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); + } MethodDeclaration getter = getGetterMethod(dstType); - getter.addStatement("return " + dstResourceName + ";"); + if (getter.getBody() == null || getter.getBody().getStatements().size() == 0) { + getter.addStatement("return " + dstResourceName + ";"); + } // src side MethodDeclaration srcUpdate = getUpdateMethod(srcType); if (srcUpdate != null) srcUpdate.addStatement(dstResourceName + ".update(" + srcResourceName + ");"); } else { // pull or push/pull MethodDeclaration getter = getGetterMethod(dstType); - String curState = d.getChannelGenerator().deriveUpdateExpressionOf(out, CodeGenerator.pullAccessor).toImplementation(); - getter.addStatement("return " + curState + ";"); + if (getter.getBody() == null || getter.getBody().getStatements().size() == 0) { + String curState = d.getChannelGenerator().deriveUpdateExpressionOf(out, CodeGenerator.pullAccessor).toImplementation(); + getter.addStatement("return " + curState + ";"); + } } } }