diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java index 8050a97..87f7f8a 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/CodeGenerator.java @@ -18,8 +18,32 @@ for (ResourceNode rn : resources) { String name = rn.getIdentifierTemplate().getResourceName().substring(0, 1).toUpperCase() + rn.getIdentifierTemplate().getResourceName().substring(1); - codes.get(0).addField(new FieldDeclaration(new Type(name, name), rn.getIdentifierTemplate().getResourceName())); - codes.add(new TypeDeclaration(name)); + FieldDeclaration field = new FieldDeclaration(new Type(name, name), + rn.getIdentifierTemplate().getResourceName()); + TypeDeclaration type = new TypeDeclaration(name); + codes.get(0).addField(field); + for (Edge e : rn.getOutEdges()) { + ResourceDependency re = (ResourceDependency) e; + String rename = ((ResourceNode) re.getDestination()).getIdentifierTemplate().getResourceName() + .substring(0, 1).toUpperCase() + + ((ResourceNode) re.getDestination()).getIdentifierTemplate().getResourceName().substring(1); + if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) + type.addField(new FieldDeclaration(new Type(rename, rename), + ((ResourceNode) re.getDestination()).getIdentifierTemplate().getResourceName())); + } + for (Edge e : rn.getInEdges()) { + ResourceDependency re = (ResourceDependency) e; + String rename = ((ResourceNode) re.getDestination()).getIdentifierTemplate().getResourceName() + .substring(0, 1).toUpperCase() + + ((ResourceNode) re.getDestination()).getIdentifierTemplate().getResourceName().substring(1); + if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) != PushPullValue.PUSH) + type.addField(new FieldDeclaration(new Type(rename, rename), + ((ResourceNode) re.getDestination()).getIdentifierTemplate().getResourceName())); + } + if (((StoreAttribute) rn.getAttribute()).isStored()) + type.addField(new FieldDeclaration(DataConstraintModel.typeInt, + rn.getIdentifierTemplate().getResourceName())); + codes.add(type); } return codes; diff --git a/AlgebraicDataflowArchitectureModel/src/tests/CodeGeneratorTest.java b/AlgebraicDataflowArchitectureModel/src/tests/CodeGeneratorTest.java index b8a9afc..3e8c1e9 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/CodeGeneratorTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/CodeGeneratorTest.java @@ -6,21 +6,32 @@ import java.io.FileReader; import algorithms.*; +import code.ast.FieldDeclaration; +import code.ast.MethodDeclaration; +import code.ast.TypeDeclaration; import models.dataFlowModel.*; import parser.*; public class CodeGeneratorTest { public static void main(String[] args) { - File file = new File("models/POS2.model"); + File file = new File("models/POS.model"); try { Parser parser = new Parser(new BufferedReader(new FileReader(file))); DataFlowModel model; try { model = parser.doParse(); - System.out.println(model); ResourceDependencyGraph graph = DataStorageNecessity.run(model); EdgeTransitionSelectable.run(graph); DataStorageDecision.run(graph); + for(TypeDeclaration str:CodeGenerator.doGenerate(graph, model)) { + System.out.println(str.getTypeName()); + for(FieldDeclaration field:str.getFields()) { + System.out.println("-" + field.getType().getTypeName() + " " + field.getName()); + } + for(MethodDeclaration method:str.getMethods()) { + System.out.println("-" + method.getReturnType() + " " + method.getName()); + } + } } catch (ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutKeyword | ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression | WrongRHSExpression | ExpectedRightBracket e) {