diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java index 2e783b2..c27b6b3 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/MethodBodyGenerator.java @@ -10,6 +10,7 @@ import models.Node; import models.algebra.InvalidMessage; import models.algebra.ParameterizedIdentifierIsFutureWork; +import models.algebra.Symbol; import models.algebra.UnificationFailed; import models.algebra.ValueUndefined; import models.dataConstraintModel.ChannelMember; @@ -23,6 +24,21 @@ public class MethodBodyGenerator { public static ArrayList doGenerate(ResourceDependencyGraph graph, DataFlowModel model, ArrayList types) { + Symbol floor = model.getSymbol("floor"); + Symbol.Memento floorMem = null; + if (floor != null) { + floorMem = floor.createMemento(); + floor.setImplName("(int)Math.floor"); + floor.setImplOperatorType(Symbol.Type.PREFIX); + } + Symbol sum = model.getSymbol("sum"); + Symbol.Memento sumMem = null; + if (sum != null) { + sumMem = sum.createMemento(); + sum.setImplName("stream().mapToInt(x->x).sum"); + sum.setImplOperatorType(Symbol.Type.METHOD); + } + // Create a map from type names (lower case) to their types. Map typeMap = new HashMap<>(); for (TypeDeclaration type: types) { @@ -73,6 +89,9 @@ | InvalidMessage | UnificationFailed | ValueUndefined e1) { e1.printStackTrace(); } + + if (floor != null) floor.setMemento(floorMem); + if (sum != null) sum.setMemento(sumMem); return types; } diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java index 1192085..37f32d7 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java @@ -56,6 +56,10 @@ public String getName() { return name; } + + public Type getOperatorType() { + return operatorType; + } public boolean isInfix() { return (operatorType == Type.INFIX); @@ -85,6 +89,10 @@ return implName; } + public void setImplName(String implName) { + this.implName = implName; + } + public Type getImplOperatorType() { return implOperatorType; } @@ -96,6 +104,10 @@ public boolean isImplMethod() { return (implOperatorType == Type.METHOD); } + + public void setImplOperatorType(Type implOperatorType) { + this.implOperatorType = implOperatorType; + } public int[] getImplParamOrder() { return implParamOrder; @@ -124,4 +136,23 @@ INFIX, METHOD } + + public Memento createMemento() { + return new Memento(implName, implOperatorType); + } + + public void setMemento(Memento memento) { + this.implName = memento.implName; + this.implOperatorType = memento.implOperatorType; + } + + public static class Memento { + private String implName; + private Type implOperatorType = Type.PREFIX; + + public Memento(String implName, Type implOperatorType) { + this.implName = implName; + this.implOperatorType = implOperatorType; + } + } }