diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java index 9f1f26a..ae1da6a 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java @@ -2,14 +2,32 @@ import java.util.ArrayList; -import code.ast.*; -import models.*; -import models.algebra.*; -import models.dataConstraintModel.*; -import models.dataFlowModel.*; +import code.ast.FieldDeclaration; +import code.ast.MethodDeclaration; +import code.ast.TypeDeclaration; +import code.ast.VariableDeclaration; +import models.Edge; +import models.Node; +import models.algebra.Expression; +import models.algebra.Field; +import models.algebra.Parameter; +import models.algebra.Symbol; +import models.algebra.Term; +import models.algebra.Type; +import models.dataConstraintModel.DataConstraintModel; +import models.dataConstraintModel.IdentifierTemplate; +import models.dataFlowModel.DataFlowModel; import models.dataFlowModel.DataflowChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.PushPullAttribute; +import models.dataFlowModel.PushPullValue; +import models.dataFlowModel.ResourceDependency; +import models.dataFlowModel.ResourceDependencyGraph; +import models.dataFlowModel.ResourceNode; +import models.dataFlowModel.StoreAttribute; public class CodeGenerator { + public static final Type typeVoid = new Type("Void", "void"); + static public ArrayList doGenerate(ResourceDependencyGraph graph, DataFlowModel model) { ArrayList codes = new ArrayList<>(); ArrayList resources = StoreResourceCheck(graph); @@ -54,7 +72,7 @@ } } if (flag) - type.addMethod(new MethodDeclaration("update", false, new Type("Void", "void"), vars)); + type.addMethod(new MethodDeclaration("update", false, typeVoid, vars)); if (((StoreAttribute) rn.getAttribute()).isStored()) { type.addField(new FieldDeclaration(rn.getIdentifierTemplate().getResourceStateType(), rn.getIdentifierTemplate().getResourceName())); @@ -63,6 +81,15 @@ rn.getIdentifierTemplate().getResourceStateType())); codes.add(type); } + codes.get(0).addMethod(new MethodDeclaration("input", typeVoid)); + for (Node n : graph.getNodes()) { + ResourceNode rn = (ResourceNode) n; + codes.get(0) + .addMethod(new MethodDeclaration( + "get" + rn.getIdentifierTemplate().getResourceName().substring(0, 1).toUpperCase() + + rn.getIdentifierTemplate().getResourceName().substring(1), + rn.getIdentifierTemplate().getResourceStateType())); + } return codes; } @@ -72,8 +99,10 @@ codes.add("public class " + type.getTypeName() + "{"); for (FieldDeclaration field : type.getFields()) { if (type.getTypeName() != "Main") { - String cons = "\t" + "private " + field.getType().getImplementationTypeName() + " " + field.getName(); - if(field.getType().equals(DataConstraintModel.typeList)) cons += " = new ArrayList<>()"; + String cons = "\t" + "private " + field.getType().getImplementationTypeName() + " " + + field.getName(); + if (field.getType().equals(DataConstraintModel.typeList)) + cons += " = new ArrayList<>()"; cons += ";"; codes.add(cons); } else {