diff --git a/AlgebraicDataflowArchitectureModel/models/JumpGame.model b/AlgebraicDataflowArchitectureModel/models/JumpGame.model index baf60d2..83f3e38 100644 --- a/AlgebraicDataflowArchitectureModel/models/JumpGame.model +++ b/AlgebraicDataflowArchitectureModel/models/JumpGame.model @@ -54,7 +54,7 @@ channel C5 { in position(p, update2(p2, g2)) == p2 in ground(g, update2(p2, g2)) == g2 - out onground(o:Bool, update2(p2, g2)) == and(eq(g2, true), le(snd(p), 0.0)) + out onground(o:Bool, update2(p2, g2)) == and(eq(g2, true), le(snd(p2), 0.0)) } channel C6 { diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java index dd7b919..7675b30 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java @@ -26,6 +26,7 @@ import models.dataConstraintModel.DataConstraintModel; import models.dataConstraintModel.IdentifierTemplate; import models.dataFlowModel.DataFlowModel; +import models.dataFlowModel.DataflowChannelGenerator; import models.dataFlowModel.DataflowChannelGenerator.IResourceStateAccessor; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; @@ -96,7 +97,7 @@ // Declare a field to cash the state of the source resource in the type of the destination resource. String cashInitializer = null; Type cashType = ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceStateType(); - if (DataConstraintModel.typeList.isAncestorOf(cashType) || DataConstraintModel.typeTuple.isAncestorOf(cashType)) { + if (DataConstraintModel.typeList.isAncestorOf(cashType)) { cashInitializer = "new " + cashType.getImplementationTypeName() + "()"; } type.addField(new FieldDeclaration( @@ -104,6 +105,20 @@ } } } + Set refs = new HashSet<>(); + for (ChannelGenerator cg : model.getChannelGenerators()) { + DataflowChannelGenerator c = (DataflowChannelGenerator) cg; + if (c.getOutputIdentifierTemplates().contains(rn.getIdentifierTemplate())) { + for (IdentifierTemplate id: c.getReferenceIdentifierTemplates()) { + if (!refs.contains(id)) { + refs.add(id); + String refResName = id.getResourceName(); + fieldInitializer += refResName.toLowerCase() + ","; + f = true; + } + } + } + } if (f) fieldInitializer = fieldInitializer.substring(0, fieldInitializer.length() - 1); fieldInitializer += ")"; @@ -152,6 +167,24 @@ type.addMethod(new MethodDeclaration("update" + srcResName, false, typeVoid, vars)); } } + // Declare a field to refer to the reference resource. + refs = new HashSet<>(); + for (ChannelGenerator cg : model.getChannelGenerators()) { + DataflowChannelGenerator c = (DataflowChannelGenerator) cg; + if (c.getOutputIdentifierTemplates().contains(rn.getIdentifierTemplate())) { + for (IdentifierTemplate id: c.getReferenceIdentifierTemplates()) { + if (!refs.contains(id)) { + refs.add(id); + String refResName = id.getResourceName(); + refResName = refResName.substring(0, 1).toUpperCase() + refResName.substring(1); + type.addField(new FieldDeclaration(new Type(refResName, refResName), id.getResourceName())); + constructor.addParameter(new VariableDeclaration(new Type(refResName, refResName), id.getResourceName())); + block.addStatement("this." + refResName.toLowerCase() + " = " + refResName.toLowerCase() + ";"); + constructor.setBody(block); + } + } + } + } if (constructor.getParameters() != null) type.addMethod(constructor); @@ -193,12 +226,10 @@ // Declare the field to store the state in the type of each resource. if (((StoreAttribute) rn.getAttribute()).isStored()) { - String str = "new " + rn.getIdentifierTemplate().getResourceStateType().getImplementationTypeName() - + "()"; + String initializer = "new " + rn.getIdentifierTemplate().getResourceStateType().getImplementationTypeName() + "()"; Type stateType = rn.getIdentifierTemplate().getResourceStateType(); - if (!DataConstraintModel.typeList.isAncestorOf(stateType) && !DataConstraintModel.typeTuple.isAncestorOf(stateType)) - str = null; - type.addField(new FieldDeclaration(stateType, rn.getIdentifierTemplate().getResourceName(), str)); + if (!DataConstraintModel.typeList.isAncestorOf(stateType)) initializer = null; + type.addField(new FieldDeclaration(stateType, rn.getIdentifierTemplate().getResourceName(), initializer)); } // Declare the getter method to obtain the state in the type of each resource. diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyCodeGenerator.java index 65ae736..18556d6 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyCodeGenerator.java @@ -118,7 +118,7 @@ // Declare a field to cash the state of the source resource in the type of the destination resource. String cashInitializer = null; Type cashType = ((ResourceNode) re.getSource()).getIdentifierTemplate().getResourceStateType(); - if (DataConstraintModel.typeList.isAncestorOf(cashType) || DataConstraintModel.typeTuple.isAncestorOf(cashType)) { + if (DataConstraintModel.typeList.isAncestorOf(cashType)) { cashInitializer = "new " + cashType.getImplementationTypeName() + "()"; } type.addField(new FieldDeclaration(cashType, srcName, cashInitializer)); @@ -158,8 +158,7 @@ if (((StoreAttribute) rn.getAttribute()).isStored()) { String initializer = "new " + rn.getIdentifierTemplate().getResourceStateType().getImplementationTypeName() + "()"; Type stateType = rn.getIdentifierTemplate().getResourceStateType(); - if (!DataConstraintModel.typeList.isAncestorOf(stateType) && !DataConstraintModel.typeTuple.isAncestorOf(stateType)) - initializer = null; + if (!DataConstraintModel.typeList.isAncestorOf(stateType)) initializer = null; type.addField(new FieldDeclaration(stateType, rn.getIdentifierTemplate().getResourceName(), initializer)); } diff --git a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java index 1cd023e..058a2fc 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java @@ -219,7 +219,11 @@ exp = new Constant(symbol); } else { Double d = Double.parseDouble(symbolName); - exp = new Constant(symbolName); + if (symbolName.contains(".")) { + exp = new Constant(symbolName, DataFlowModel.typeDouble); + } else { + exp = new Constant(symbolName, DataFlowModel.typeInt); + } } } catch (NumberFormatException e) { if (stream.checkNext() != null && stream.checkNext().equals(COLON)) {