diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java index f4f29ce..8204dea 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Symbol.java @@ -4,7 +4,8 @@ private String name; private int arity = 0; private Type operatorType = Type.PREFIX; - private Symbol inverses[] = null; + private Symbol[] inverses = null; + private Type[] signature = null; public Symbol(String name) { this.name = name; @@ -50,6 +51,14 @@ this.inverses = inverses; } + public Type[] getSignature() { + return signature; + } + + public void setSignature(Type[] signature) { + this.signature = signature; + } + public boolean equals(Object another) { if (!(another instanceof Symbol)) return false; return name.equals(((Symbol) another).name) && arity == ((Symbol) another).arity; diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Type.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Type.java new file mode 100644 index 0000000..53e4b2a --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Type.java @@ -0,0 +1,27 @@ +package models.algebra; + +public class Type { + private String typeName; + private String implementastionTypeName; + + public Type(String typeName, String implementastionTypeName) { + this.typeName = typeName; + this.implementastionTypeName = implementastionTypeName; + } + + public String getTypeName() { + return typeName; + } + + public void setTypeName(String typeName) { + this.typeName = typeName; + } + + public String getImplementastionTypeName() { + return implementastionTypeName; + } + + public void setImplementastionTypeName(String implementastionTypeName) { + this.implementastionTypeName = implementastionTypeName; + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Variable.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Variable.java index 14bda66..935503b 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Variable.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Variable.java @@ -4,16 +4,31 @@ public class Variable extends Expression { private String name; + private Type type = null; public Variable(String name) { super(); this.name = name; } + public Variable(String name, Type type) { + super(); + this.name = name; + this.type = type; + } + public String getName() { return name; } + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } + @Override public HashMap getVariables() { HashMap variables = new HashMap<>(); @@ -56,7 +71,7 @@ @Override public Object clone() { - return new Variable(name); + return new Variable(name, type); } public String toString() { diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index aaa3d6f..411eb5e 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -6,6 +6,7 @@ import java.util.Set; import models.algebra.Symbol; +import models.algebra.Type; import parser.Parser; public class DataConstraintModel { @@ -21,6 +22,10 @@ public static final Symbol cons = new Symbol("cons", 2); public static final Symbol head = new Symbol("head", 1); public static final Symbol body = new Symbol("body", 1); + public static final Type typeInt = new Type("Int", "int"); + public static final Type typeFloat = new Type("Float", "float"); + public static final Type typeDouble = new Type("Double", "double"); + public static final Type typeList = new Type("List", "List"); static { add.setInverses(new Symbol[] {sub, sub}); diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/IdentifierTemplate.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/IdentifierTemplate.java index c30b091..0ea7b6a 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/IdentifierTemplate.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/IdentifierTemplate.java @@ -1,14 +1,23 @@ package models.dataConstraintModel; +import models.algebra.Type; + public class IdentifierTemplate { - String resourceName = null; - int numParameters = 0; + private String resourceName = null; + private Type resourceStateType = null; + private int numParameters = 0; public IdentifierTemplate(String resourceName, int numParameters) { this.resourceName = resourceName; this.numParameters =numParameters; } + public IdentifierTemplate(String resourceName, Type resourceStateType, int numParameters) { + this.resourceName = resourceName; + this.resourceStateType = resourceStateType; + this.numParameters = numParameters; + } + public String getResourceName() { return resourceName; } @@ -16,4 +25,12 @@ public int getNumberOfParameters() { return numParameters; } + + public Type getResourceStateType() { + return resourceStateType; + } + + public void setResourceStateType(Type resourceStateType) { + this.resourceStateType = resourceStateType; + } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/StateTransition.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/StateTransition.java index 250a560..06ca47b 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/StateTransition.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/StateTransition.java @@ -60,7 +60,16 @@ } } - Expression nextStateTerm = getNextStateExpression(); + Expression nextStateTerm = (Expression) getNextStateExpression().clone(); + for (Variable var: bindings.keySet()) { + HashMap vars2 = nextStateTerm.getVariables(); + for (Variable var2: vars2.values()) { + if (var.equals(var2) && bindings.get(var).size() == 1) { + nextStateTerm = ((Term) nextStateTerm).substitute(var, bindings.get(var).get(0)); + } + } + } + HashMap nextStateVars = nextStateTerm.getVariables(); for (Entry nextStateVarEnt: nextStateVars.entrySet()) { Variable var = nextStateVarEnt.getValue(); diff --git a/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java b/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java index 7e60de3..a10c032 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java @@ -30,21 +30,21 @@ // Pre-defined symbols Symbol floor = new Symbol("floor", 1); - IdentifierTemplate payment = new IdentifierTemplate("payment", 0); // an identifier template to specify the payment resource - IdentifierTemplate loyalty = new IdentifierTemplate("loyalty", 0); // an identifier template to specify the loyalty resource - IdentifierTemplate history = new IdentifierTemplate("history", 0); // an identifier template to specify the payment history resource - IdentifierTemplate total = new IdentifierTemplate("total", 0); // an identifier template to specify the total payment resource + IdentifierTemplate payment = new IdentifierTemplate("payment", DataConstraintModel.typeInt, 0); // an identifier template to specify the payment resource + IdentifierTemplate loyalty = new IdentifierTemplate("loyalty", DataConstraintModel.typeInt, 0); // an identifier template to specify the loyalty resource + IdentifierTemplate history = new IdentifierTemplate("history", DataConstraintModel.typeList, 0);// an identifier template to specify the payment history resource + IdentifierTemplate total = new IdentifierTemplate("total", DataConstraintModel.typeInt, 0); // an identifier template to specify the total payment resource // fields - final Variable fPayment = new Variable("payment"); - final Variable fLoyalty = new Variable("loyalty"); - final Variable fHistory = new Variable("history"); - final Variable fTotal = new Variable("total"); + final Variable fPayment = new Variable("fPayment", DataConstraintModel.typeInt); + final Variable fLoyalty = new Variable("fLoyalty", DataConstraintModel.typeInt); + final Variable fHistory = new Variable("fHistory", DataConstraintModel.typeList); + final Variable fTotal = new Variable("fTotal", DataConstraintModel.typeInt); // arguments - final Variable aPayment = new Variable("payment"); - final Variable aLoyalty = new Variable("loyalty"); - final Variable aHistory = new Variable("history"); - final Variable aTotal = new Variable("total"); + final Variable aPayment = new Variable("payment", DataConstraintModel.typeInt); + final Variable aLoyalty = new Variable("loyalty", DataConstraintModel.typeInt); + final Variable aHistory = new Variable("history", DataConstraintModel.typeList); + final Variable aTotal = new Variable("total", DataConstraintModel.typeInt); IResourceStateAccessor pushAccessor = new IResourceStateAccessor() { @Override public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { @@ -158,12 +158,12 @@ break; } } - System.out.println("void update(" + arg + ") {"); + System.out.println("void update(" + arg.getType().getImplementastionTypeName() + " " + arg + ") {"); System.out.println("\t" + fLoyalty + " = " + loyaltyPushUpdate + ";"); System.out.println("}"); System.out.println("-- PULL --"); - System.out.println("int " + loyltyGetter + "() {"); + System.out.println(loyalty.getResourceStateType().getImplementastionTypeName() + " " + loyltyGetter + "() {"); System.out.println("\t return " + c1.deriveUpdateExpressionOf(c1_loyalty, pullAccessor) + ";"); System.out.println("}"); } catch (ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork | InvalidMessage @@ -220,12 +220,12 @@ break; } } - System.out.println("void update(" + arg + ") {"); + System.out.println("void update(" + arg.getType().getImplementastionTypeName() + " " + arg + ") {"); System.out.println("\t" + fHistory + " = " + historyPushUpdate + ";"); System.out.println("}"); System.out.println("-- PULL --"); - System.out.println("List " + historyGetter + "() {"); + System.out.println(history.getResourceStateType().getImplementastionTypeName() + " " + historyGetter + "() {"); System.out.println("\t return " + c2.deriveUpdateExpressionOf(c2_history, pullAccessor) + ";"); System.out.println("}"); } catch (ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork | InvalidMessage @@ -282,12 +282,12 @@ break; } } - System.out.println("void update(" + arg + ") {"); + System.out.println("void update(" + arg.getType().getImplementastionTypeName() + " " + arg + ") {"); System.out.println("\t" + fTotal + " = " + totalPushUpdate + ";"); System.out.println("}"); System.out.println("-- PULL --"); - System.out.println("int " + totalGetter + "() {"); + System.out.println(total.getResourceStateType().getImplementastionTypeName() + " " + totalGetter + "() {"); System.out.println("\t return " + c3.deriveUpdateExpressionOf(c3_total, pullAccessor) + ";"); System.out.println("}"); } catch (ParameterizedIdentifierIsFutureWork | ResolvingMultipleDefinitionIsFutureWork | InvalidMessage