diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/DataTransferModelAnalyzer.java b/AlgebraicDataflowArchitectureModel/src/algorithms/DataTransferModelAnalyzer.java index 07afdf1..836227a 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/DataTransferModelAnalyzer.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/DataTransferModelAnalyzer.java @@ -24,22 +24,22 @@ */ static public DataFlowGraph createDataFlowGraphWithStateStoringAttribute(DataTransferModel model) { DataFlowGraph graph = model.getDataFlowGraph(); - Collection channels = new HashSet<>(model.getIOChannelGenerators()); - channels.addAll(model.getChannelGenerators()); - for (ChannelGenerator generator: channels) { - for (ChannelMember member: ((DataTransferChannelGenerator) generator).getOutputChannelMembers()) { + Collection channels = new HashSet<>(model.getIOChannels()); + channels.addAll(model.getChannels()); + for (Channel channel: channels) { + for (ChannelMember member: ((DataTransferChannel) channel).getOutputChannelMembers()) { boolean flag = !member.getStateTransition().isRightUnary(); // The state does not need to be stored if the state transition function is right unary. for (Node node : graph.getNodes()) { - if (((ResourceNode) node).getIdentifierTemplate().equals(member.getIdentifierTemplate())) { + if (((ResourceNode) node).getResource().equals(member.getResource())) { setStoreAttribute(flag, (ResourceNode) node); } } } } for (Node node : graph.getNodes()) { - HashSet inChannels = new HashSet<>(); + HashSet inChannels = new HashSet<>(); for(Edge pre : ((ResourceNode) node).getInEdges()) { - inChannels.add(((DataFlowEdge) pre).getChannelGenerator()); + inChannels.add(((DataFlowEdge) pre).getChannel()); } if ((inChannels.size() > 1)) { setStoreAttribute(true, (ResourceNode) node); diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java b/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java index fb48b10..d29070d 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java @@ -19,10 +19,10 @@ import models.algebra.Term; import models.algebra.Type; import models.algebra.Variable; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataConstraintModel.StateTransition; import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.ResourceNode; @@ -84,9 +84,9 @@ } static public void infer(DataTransferModel model) { - Map> resources = new HashMap<>(); + Map> resources = new HashMap<>(); Map variables = new HashMap<>(); - Map, Type>>> messages = new HashMap<>(); + Map, Type>>> messages = new HashMap<>(); Map consOrSet = new HashMap<>(); Map tuple = new HashMap<>(); Map pair = new HashMap<>(); @@ -123,12 +123,12 @@ mapComponentTypes.put(DataConstraintModel.typeMap, Arrays.asList(new Type[] { null, null })); // 1. Collect type information from the architecture model. - Collection channels = new HashSet<>(model.getIOChannelGenerators()); - channels.addAll(model.getChannelGenerators()); - for (ChannelGenerator c : channels) { + Collection channels = new HashSet<>(model.getIOChannels()); + channels.addAll(model.getChannels()); + for (Channel c : channels) { for (ChannelMember cm : c.getChannelMembers()) { StateTransition st = cm.getStateTransition(); - IdentifierTemplate id = cm.getIdentifierTemplate(); + ResourcePath id = cm.getResource(); // 1.1 Group expressions by resources. List sameResource = resources.get(id); @@ -1056,11 +1056,11 @@ } } - private static void updateResourceTypes(Expression exp, Map> resources, + private static void updateResourceTypes(Expression exp, Map> resources, Map> expToResource, Map> updateFromResource) { List sameResource = expToResource.get(System.identityHashCode(exp)); if (sameResource == null) return; - for (IdentifierTemplate id : resources.keySet()) { + for (ResourcePath id : resources.keySet()) { if (resources.get(id) == sameResource) { Type resType = id.getResourceStateType(); Type newResType = getExpTypeIfUpdatable(resType, exp); @@ -1124,13 +1124,13 @@ } private static void updateMessageTypes(Expression exp, - Map, Type>>> messages, + Map, Type>>> messages, Map> expToMessage, Map> updateFromMessage) { List messageExps = expToMessage.get(System.identityHashCode(exp)); if (messageExps == null) return; Type msgType = null; Map.Entry, Type> expsAndType = null; - for (ChannelGenerator c : messages.keySet()) { + for (Channel c : messages.keySet()) { for (int i : messages.get(c).keySet()) { expsAndType = messages.get(c).get(i); if (expsAndType.getKey() == messageExps) { diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/JavaPrototypeGenerateAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/JavaPrototypeGenerateAction.java index a56f615..074a336 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/JavaPrototypeGenerateAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/JavaPrototypeGenerateAction.java @@ -21,7 +21,7 @@ import generators.JavaMethodBodyGenerator; import generators.JavaSpecific; import models.controlFlowModel.ControlFlowGraph; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.ModelExtension; import models.dataFlowModel.DataFlowGraph; @@ -54,7 +54,7 @@ if (fileName == null) fileName = "Main"; String mainTypeName = fileName.split("\\.")[0]; boolean exist = false; - for (IdentifierTemplate id: model.getIdentifierTemplates()) { + for (ResourcePath id: model.getResourcePaths()) { String resourceName = id.getResourceName().substring(0, 1).toUpperCase() + id.getResourceName().substring(1); if (mainTypeName.equals(resourceName)) { exist = true; diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/JerseyPrototypeGenerateAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/JerseyPrototypeGenerateAction.java index 25986ec..d1a8031 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/JerseyPrototypeGenerateAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/JerseyPrototypeGenerateAction.java @@ -17,7 +17,7 @@ import generators.JerseyCodeGenerator; import generators.JerseyMethodBodyGenerator; import models.algebra.Type; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.ModelExtension; import models.dataFlowModel.DataFlowGraph; @@ -50,7 +50,7 @@ if (fileName == null) fileName = "Main"; String mainTypeName = fileName.split("\\.")[0]; boolean exist = false; - for (IdentifierTemplate id: model.getIdentifierTemplates()) { + for (ResourcePath id: model.getResourcePaths()) { String resourceName = id.getResourceName().substring(0, 1).toUpperCase() + id.getResourceName().substring(1); if (mainTypeName.equals(resourceName)) { exist = true; diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewChannelAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewChannelAction.java index e8148f5..6ee664c 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/NewChannelAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewChannelAction.java @@ -5,7 +5,7 @@ import javax.swing.JOptionPane; import application.editor.Editor; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; public class NewChannelAction extends AbstractEditorAction { @@ -22,7 +22,7 @@ public void actionPerformed(ActionEvent e) { String channelName = JOptionPane.showInputDialog("Channel Name:"); if (channelName == null) return; - editor.addChannelGenerator(new DataTransferChannelGenerator(channelName)); + editor.addChannel(new DataTransferChannel(channelName)); } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewFormulaChannelAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewFormulaChannelAction.java index d26d8a8..068c758 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/NewFormulaChannelAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewFormulaChannelAction.java @@ -19,7 +19,7 @@ import application.ApplicationWindow; import application.editor.Editor; -import models.visualModel.FormulaChannelGenerator; +import models.visualModel.FormulaChannel; public class NewFormulaChannelAction extends AbstractEditorAction implements ActionListener { @@ -47,16 +47,16 @@ panel.add(symbolText); int r = JOptionPane.showConfirmDialog( - null, // �I�[�i�[�E�B���h�E - panel, // ���b�Z�[�W - "New Formula Channel", // �E�B���h�E�^�C�g�� - JOptionPane.OK_CANCEL_OPTION, // �I�v�V�����i�{�^���̎�ށj - JOptionPane.QUESTION_MESSAGE); // ���b�Z�[�W�^�C�v�i�A�C�R���̎�ށj + null, + panel, + "New Formula Channel", + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE); String channelName = channelText.getText(); String symbol = symbolText.getText(); if(r == JOptionPane.OK_OPTION) { - editor.addFormulaChannelGenerator(new FormulaChannelGenerator(channelName, editor.getModel().getSymbol(symbol))); + editor.addFormulaChannel(new FormulaChannel(channelName, editor.getModel().getSymbol(symbol))); } } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewIOChannelAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewIOChannelAction.java index 8d819d8..85e48de 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/NewIOChannelAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewIOChannelAction.java @@ -5,7 +5,7 @@ import javax.swing.JOptionPane; import application.editor.Editor; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; public class NewIOChannelAction extends AbstractEditorAction { @@ -22,7 +22,7 @@ public void actionPerformed(ActionEvent e) { String channelName = JOptionPane.showInputDialog("I/O Channel Name:"); if (channelName == null) return; - editor.addIOChannelGenerator(new DataTransferChannelGenerator(channelName)); + editor.addIOChannel(new DataTransferChannel(channelName)); } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java index 5c230f7..50b1512 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/NewResourceAction.java @@ -5,7 +5,7 @@ import javax.swing.JOptionPane; import application.editor.Editor; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; public class NewResourceAction extends AbstractEditorAction { @@ -22,7 +22,7 @@ public void actionPerformed(ActionEvent e) { String resName = JOptionPane.showInputDialog("Resourece Name:"); if (resName == null) return; - editor.addIdentifierTemplate(new IdentifierTemplate(resName, 0)); + editor.addResourcePath(new ResourcePath(resName, 0)); } } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index ff8dc0d..ba453b8 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -27,12 +27,12 @@ import code.ast.CompilationUnit; import models.EdgeAttribute; import models.controlFlowModel.ControlFlowGraph; -import models.dataConstraintModel.ChannelGenerator; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.Channel; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.DataFlowGraph; -import models.visualModel.FormulaChannelGenerator; +import models.visualModel.FormulaChannel; import parser.Parser; import parser.exceptions.ExpectedAssignment; import parser.exceptions.ExpectedChannel; @@ -367,13 +367,13 @@ int w = (int) state.getWidth(); int h = (int) state.getHeight(); - for (IdentifierTemplate res: model.getIdentifierTemplates()){ - if(res instanceof IdentifierTemplate && state.getLabel().equals(res.getResourceName())) + for (ResourcePath res: model.getResourcePaths()){ + if(res instanceof ResourcePath && state.getLabel().equals(res.getResourceName())) fileString += "\tnode r " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h + "\n"; } - for (ChannelGenerator ioC: model.getIOChannelGenerators()) { - if(ioC instanceof ChannelGenerator && state.getLabel().equals(ioC.getChannelName())) { + for (Channel ioC: model.getIOChannels()) { + if(ioC instanceof Channel && state.getLabel().equals(ioC.getChannelName())) { fileString += "\tnode ioc " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h + "\n"; } } @@ -389,10 +389,10 @@ int w = (int) state.getWidth(); int h = (int) state.getHeight(); - for(ChannelGenerator ch: model.getChannelGenerators()) { - if(ch instanceof FormulaChannelGenerator && state.getLabel().equals(ch.getChannelName())) { + for(Channel ch: model.getChannels()) { + if(ch instanceof FormulaChannel && state.getLabel().equals(ch.getChannelName())) { fileString += "\tnode fc " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h+"\n"; - } else if(ch instanceof ChannelGenerator && state.getLabel().equals(ch.getChannelName())) { + } else if(ch instanceof Channel && state.getLabel().equals(ch.getChannelName())) { fileString +="\tnode c " + state.getLabel() + ":" + x + "," + y + "," + w + "," + h+"\n"; } } @@ -447,40 +447,40 @@ } } - public void addIdentifierTemplate(IdentifierTemplate res) { + public void addResourcePath(ResourcePath res) { // Force to change to the data-flow modeling stage. boolean stageChanged = changeStage(STAGE_DATA_FLOW_MODELING); if (!stageChanged) return; - ((DataFlowModelingStage) curStage).addIdentifierTemplate(res); + ((DataFlowModelingStage) curStage).addResourcePath(res); model = ((DataFlowModelingStage) curStage).getModel(); } - public void addChannelGenerator(DataTransferChannelGenerator channelGen) { + public void addChannel(DataTransferChannel channel) { // Force to change to the data-flow modeling stage. boolean stageChanged = changeStage(STAGE_DATA_FLOW_MODELING); if (!stageChanged) return; - ((DataFlowModelingStage) curStage).addChannelGenerator(channelGen); + ((DataFlowModelingStage) curStage).addChannel(channel); model = ((DataFlowModelingStage) curStage).getModel(); } - public void addIOChannelGenerator(DataTransferChannelGenerator ioChannelGen) { + public void addIOChannel(DataTransferChannel ioChannel) { // Force to change to the data-flow modeling stage. boolean stageChanged = changeStage(STAGE_DATA_FLOW_MODELING); if (!stageChanged) return; - ((DataFlowModelingStage) curStage).addIOChannelGenerator(ioChannelGen); + ((DataFlowModelingStage) curStage).addIOChannel(ioChannel); model = ((DataFlowModelingStage) curStage).getModel(); } - public void addFormulaChannelGenerator(FormulaChannelGenerator formulaChannelGen) { + public void addFormulaChannel(FormulaChannel formulaChannel) { // Force to change to the data-flow modeling stage. boolean stageChanged = changeStage(STAGE_DATA_FLOW_MODELING); if (!stageChanged) return; - ((DataFlowModelingStage) curStage).addFormulaChannelGenerator(formulaChannelGen); + ((DataFlowModelingStage) curStage).addFormulaChannel(formulaChannel); model = ((DataFlowModelingStage) curStage).getModel(); } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java index 5a60a80..bf0b201 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/ControlFlowDelegationStage.java @@ -524,7 +524,7 @@ for(int i = 0; i < dataFlowLayerCell.getChildCount(); i++) { mxCell channelCell =(mxCell)dataFlowLayerCell.getChildAt(i); - String entryPointObjNodeName = entryPointObjNode.getIoChannelGenerator().getChannelName(); + String entryPointObjNodeName = entryPointObjNode.getIOChannel().getChannelName(); String channelCellName = ""; if(channelCell.getValue() instanceof String) channelCellName = (String) channelCell.getValue(); else continue; diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowCellEditor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowCellEditor.java index f05c14c..117067f 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowCellEditor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowCellEditor.java @@ -26,10 +26,10 @@ import application.editor.FlowCellEditor; import models.algebra.Expression; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; -import models.visualModel.FormulaChannelGenerator; +import models.visualModel.FormulaChannel; import parser.Parser; import parser.Parser.TokenStream; import parser.exceptions.ExpectedRightBracket; @@ -62,16 +62,16 @@ } if (!graphComponent.getGraph().getModel().isEdge(cellObj)) { - DataTransferChannelGenerator ch = (DataTransferChannelGenerator) stage.getModel().getChannelGenerator((String) ((mxCell) cellObj).getValue()); + DataTransferChannel ch = (DataTransferChannel) stage.getModel().getChannel((String) ((mxCell) cellObj).getValue()); if (ch == null) { - ch = (DataTransferChannelGenerator) stage.getModel().getIOChannelGenerator((String) ((mxCell) cellObj).getValue()); + ch = (DataTransferChannel) stage.getModel().getIOChannel((String) ((mxCell) cellObj).getValue()); if(ch == null) { //resource return; } } - if (ch instanceof FormulaChannelGenerator) { + if (ch instanceof FormulaChannel) { JPanel panel = new JPanel(); JLabel label1 = new JLabel("Formula: "); @@ -87,7 +87,7 @@ gbc.gridx = 1; gbc.gridy = 0; - JTextField formulaText = new JTextField(((FormulaChannelGenerator) ch).getFormula(),15); + JTextField formulaText = new JTextField(((FormulaChannel) ch).getFormula(),15); layout.setConstraints(formulaText, gbc); panel.add(formulaText); @@ -118,8 +118,8 @@ try { Expression exp = parser.parseTerm(stream, stage.getModel()); - ((FormulaChannelGenerator) ch).setFormula(formula); - ((FormulaChannelGenerator) ch).setFormulaTerm(exp); + ((FormulaChannel) ch).setFormula(formula); + ((FormulaChannel) ch).setFormulaTerm(exp); } catch (ExpectedRightBracket e) { e.printStackTrace(); } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java index 0906962..b722f1b 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/DataFlowModelingStage.java @@ -20,13 +20,13 @@ import application.editor.Editor.SrcDstAttribute; import application.editor.FlowCellEditor; import application.editor.Stage; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; -import models.dataConstraintModel.IdentifierTemplate; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataConstraintModel.ResourcePath; +import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.ResourceNodeAttribute; -import models.visualModel.FormulaChannelGenerator; +import models.visualModel.FormulaChannel; import parser.Parser; import parser.Parser.TokenStream; import parser.exceptions.ExpectedAssignment; @@ -187,13 +187,13 @@ geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS)); geo2.setRelative(true); - Map channelsIn = new HashMap<>(); - Map channelsOut = new HashMap<>(); - Map resources = new HashMap<>(); + Map channelsIn = new HashMap<>(); + Map channelsOut = new HashMap<>(); + Map resources = new HashMap<>(); // create channel vertices - for (ChannelGenerator c: model.getChannelGenerators()) { - DataTransferChannelGenerator channelGen = (DataTransferChannelGenerator) c; + for (Channel c: model.getChannels()) { + DataTransferChannel channelGen = (DataTransferChannel) c; if (channelsIn.get(channelGen) == null || channelsOut.get(channelGen) == null) { Object channel = graph.insertVertex(dataFlowLayer, null, channelGen.getChannelName(), 150, 20, 30, 30); // insert a channel as a vertex mxCell port_in = new mxCell(null, geo1, "shape=ellipse;perimter=ellipsePerimeter"); @@ -208,7 +208,7 @@ } // create resource vertices - for (IdentifierTemplate res: model.getIdentifierTemplates()) { + for (ResourcePath res: model.getResourcePaths()) { // insert a resource as a vertex ResourceNodeAttribute resNodeAttr = new ResourceNodeAttribute(model.getDataFlowGraph().getResouceNode(res)); Object resource = graph.insertVertex( @@ -220,31 +220,31 @@ } // add input, output and reference edges - for (ChannelGenerator ch: model.getChannelGenerators()) { - DataTransferChannelGenerator channelGen = (DataTransferChannelGenerator) ch; + for (Channel ch: model.getChannels()) { + DataTransferChannel channel = (DataTransferChannel) ch; // input edge - for (IdentifierTemplate srcRes: channelGen.getInputIdentifierTemplates()) { - graph.insertEdge(dataFlowLayer, null, new SrcDstAttribute(srcRes, channelGen), resources.get(srcRes), channelsIn.get(channelGen), "movable=false;strokeColor=#FF0000"); + for (ResourcePath srcRes: channel.getInputResources()) { + graph.insertEdge(dataFlowLayer, null, new SrcDstAttribute(srcRes, channel), resources.get(srcRes), channelsIn.get(channel), "movable=false;strokeColor=#FF0000"); } // output edge - for (IdentifierTemplate dstRes: channelGen.getOutputIdentifierTemplates()) { - graph.insertEdge(dataFlowLayer, null, new SrcDstAttribute(channelGen, dstRes), channelsOut.get(channelGen), resources.get(dstRes), "movable=false;strokeColor=#FF0000"); + for (ResourcePath dstRes: channel.getOutputResources()) { + graph.insertEdge(dataFlowLayer, null, new SrcDstAttribute(channel, dstRes), channelsOut.get(channel), resources.get(dstRes), "movable=false;strokeColor=#FF0000"); } // reference edges - for (IdentifierTemplate refRes: channelGen.getReferenceIdentifierTemplates()) { - graph.insertEdge(dataFlowLayer, null, null, resources.get(refRes), channelsIn.get(channelGen), "dashed=true;movable=false;strokeColor=#FF0000"); + for (ResourcePath refRes: channel.getReferenceResources()) { + graph.insertEdge(dataFlowLayer, null, null, resources.get(refRes), channelsIn.get(channel), "dashed=true;movable=false;strokeColor=#FF0000"); } } - for (ChannelGenerator ioChannelGen: model.getIOChannelGenerators()) { - if (channelsOut.get(ioChannelGen) == null) { - Object channel = graph.insertVertex(nodeLayer, null, ioChannelGen.getChannelName(), 150, 20, 30, 30); // insert an I/O channel as a vertex + for (Channel ioChannel: model.getIOChannels()) { + if (channelsOut.get(ioChannel) == null) { + Object channel = graph.insertVertex(nodeLayer, null, ioChannel.getChannelName(), 150, 20, 30, 30); // insert an I/O channel as a vertex mxCell port_out = new mxCell(null, geo2, "shape=ellipse;perimter=ellipsePerimeter"); port_out.setVertex(true); graph.addCell(port_out, channel); // insert the output port of a channel - channelsOut.put((DataTransferChannelGenerator) ioChannelGen, port_out); + channelsOut.put((DataTransferChannel) ioChannel, port_out); - for (IdentifierTemplate outRes: ((DataTransferChannelGenerator) ioChannelGen).getOutputIdentifierTemplates()) { + for (ResourcePath outRes: ((DataTransferChannel) ioChannel).getOutputResources()) { graph.insertEdge(dataFlowLayer, null, null, port_out, resources.get(outRes), "movable=false;strokeColor=#FF0000"); } @@ -260,8 +260,8 @@ /************************************************************* * */ - public void addIdentifierTemplate(IdentifierTemplate res) { - getModel().addIdentifierTemplate(res); + public void addResourcePath(ResourcePath res) { + getModel().addResourcePath(res); graph.getModel().beginUpdate(); mxCell root = (mxCell) graph.getDefaultParent(); mxCell layer = (mxCell) root.getChildAt(NODE_LAYER); @@ -276,8 +276,8 @@ /************************************************************* * */ - public void addChannelGenerator(DataTransferChannelGenerator channelGen) { - getModel().addChannelGenerator(channelGen); + public void addChannel(DataTransferChannel channelGen) { + getModel().addChannel(channelGen); graph.getModel().beginUpdate(); mxCell root = (mxCell) graph.getDefaultParent(); mxCell layer = (mxCell) root.getChildAt(DATA_FLOW_LAYER); @@ -305,8 +305,8 @@ /************************************************************* * */ - public void addIOChannelGenerator(DataTransferChannelGenerator ioChannelGen) { - getModel().addIOChannelGenerator(ioChannelGen); + public void addIOChannel(DataTransferChannel ioChannelGen) { + getModel().addIOChannel(ioChannelGen); graph.getModel().beginUpdate(); mxCell root = (mxCell) graph.getDefaultParent(); mxCell layer = (mxCell) root.getChildAt(NODE_LAYER); @@ -324,8 +324,8 @@ } } - public void addFormulaChannelGenerator(FormulaChannelGenerator formulaChannelGen) { - getModel().addChannelGenerator(formulaChannelGen); + public void addFormulaChannel(FormulaChannel formulaChannelGen) { + getModel().addChannel(formulaChannelGen); graph.getModel().beginUpdate(); mxCell root = (mxCell) graph.getDefaultParent(); mxCell layer = (mxCell) root.getChildAt(DATA_FLOW_LAYER); @@ -352,25 +352,25 @@ public boolean connectEdge(mxCell edge, mxCell src, mxCell dst) { DataTransferModel model = getModel(); - ChannelGenerator srcCh = model.getChannelGenerator((String) src.getValue()); + Channel srcCh = model.getChannel((String) src.getValue()); if (srcCh == null) { - srcCh = model.getIOChannelGenerator((String) src.getValue()); + srcCh = model.getIOChannel((String) src.getValue()); if (srcCh == null) { - IdentifierTemplate srcRes = model.getIdentifierTemplate((String) src.getValue()); - ChannelGenerator dstCh = model.getChannelGenerator((String) dst.getValue()); + ResourcePath srcRes = model.getResourcePath((String) src.getValue()); + Channel dstCh = model.getChannel((String) dst.getValue()); if (srcRes == null || dstCh == null) return false; // resource to channel edge ChannelMember srcCm = new ChannelMember(srcRes); - ((DataTransferChannelGenerator ) dstCh).addChannelMemberAsInput(srcCm); + ((DataTransferChannel ) dstCh).addChannelMemberAsInput(srcCm); edge.setValue(new SrcDstAttribute(srcRes, dstCh)); return true; } } - IdentifierTemplate dstRes = model.getIdentifierTemplate((String) dst.getValue()); + ResourcePath dstRes = model.getResourcePath((String) dst.getValue()); if (dstRes == null) return false; // channel to resource edge ChannelMember dstCm = new ChannelMember(dstRes); - ((DataTransferChannelGenerator) srcCh).addChannelMemberAsOutput(dstCm); + ((DataTransferChannel) srcCh).addChannelMemberAsOutput(dstCm); edge.setValue(new SrcDstAttribute(srcCh, dstRes)); return true; } @@ -384,26 +384,26 @@ if (cell.isEdge()) { String srcName = (String) cell.getSource().getValue(); String dstName = (String) cell.getTarget().getValue(); - if (model.getIdentifierTemplate(srcName) != null) { + if (model.getResourcePath(srcName) != null) { // resource to channel edge - ChannelGenerator ch = model.getChannelGenerator(dstName); - ch.removeChannelMember(model.getIdentifierTemplate(srcName)); - } else if (model.getIdentifierTemplate(dstName) != null) { + Channel ch = model.getChannel(dstName); + ch.removeChannelMember(model.getResourcePath(srcName)); + } else if (model.getResourcePath(dstName) != null) { // channel to resource edge - ChannelGenerator ch = model.getChannelGenerator(srcName); + Channel ch = model.getChannel(srcName); if (ch == null) { - ch = model.getIOChannelGenerator(srcName); + ch = model.getIOChannel(srcName); } - ch.removeChannelMember(model.getIdentifierTemplate(dstName)); + ch.removeChannelMember(model.getResourcePath(dstName)); } } else if (cell.isVertex()) { String name = (String) cell.getValue(); - if (model.getChannelGenerator(name) != null) { - model.removeChannelGenerator(name); - } else if (model.getIOChannelGenerator(name) != null) { - model.removeIOChannelGenerator(name); - } else if (model.getIdentifierTemplate(name) != null) { - model.removeIdentifierTemplate(name); + if (model.getChannel(name) != null) { + model.removeChannel(name); + } else if (model.getIOChannel(name) != null) { + model.removeIOChannel(name); + } else if (model.getResourcePath(name) != null) { + model.removeResourcePath(name); } } } @@ -413,7 +413,7 @@ /************************************************************* * */ - public void setChannelCode(DataTransferChannelGenerator ch, String code) { + public void setChannelCode(DataTransferChannel ch, String code) { ch.setSourceText(code); TokenStream stream = new TokenStream(); Parser parser = new Parser(stream); @@ -422,10 +422,10 @@ stream.addLine(line); } try { - DataTransferChannelGenerator ch2 = parser.parseChannel(getModel()); + DataTransferChannel ch2 = parser.parseChannel(getModel()); for (ChannelMember chm2: ch2.getInputChannelMembers()) { for (ChannelMember chm: ch.getInputChannelMembers()) { - if (chm2.getIdentifierTemplate() == chm.getIdentifierTemplate()) { + if (chm2.getResource() == chm.getResource()) { chm.setStateTransition(chm2.getStateTransition()); break; } @@ -433,7 +433,7 @@ } for (ChannelMember chm2: ch2.getOutputChannelMembers()) { for (ChannelMember chm: ch.getOutputChannelMembers()) { - if (chm2.getIdentifierTemplate() == chm.getIdentifierTemplate()) { + if (chm2.getResource() == chm.getResource()) { chm.setStateTransition(chm2.getStateTransition()); break; } @@ -441,7 +441,7 @@ } for (ChannelMember chm2: ch2.getReferenceChannelMembers()) { for (ChannelMember chm: ch.getReferenceChannelMembers()) { - if (chm2.getIdentifierTemplate() == chm.getIdentifierTemplate()) { + if (chm2.getResource() == chm.getResource()) { chm.setStateTransition(chm2.getStateTransition()); break; } diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java index 0e14d32..0889be8 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/stages/PushPullSelectionStage.java @@ -21,7 +21,7 @@ import models.Edge; import models.dataFlowModel.DataFlowEdge; import models.dataFlowModel.DataFlowGraph; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.ResourceNode; @@ -110,18 +110,18 @@ for (Edge e : dataFlowGraph.getEdges()) { if (e instanceof DataFlowEdge) { DataFlowEdge dataFlow = (DataFlowEdge) e; - DataTransferChannelGenerator channelGen = dataFlow.getChannelGenerator(); + DataTransferChannel channel = dataFlow.getChannel(); ResourceNode srcRes = (ResourceNode) dataFlow.getSource(); ResourceNode dstRes = (ResourceNode) dataFlow.getDestination(); for (Object edge: graph.getChildEdges(layer)) { mxCell edgeCell = (mxCell) edge; if (edgeCell.getValue() instanceof SrcDstAttribute) { SrcDstAttribute edgeAttr = (SrcDstAttribute) edgeCell.getValue(); - if (edgeAttr.getSrouce() == srcRes.getIdentifierTemplate() && edgeAttr.getDestination() == channelGen) { + if (edgeAttr.getSrouce() == srcRes.getResource() && edgeAttr.getDestination() == channel) { // input edge edgeCell.setValue(new InEdgeAttribute((PushPullAttribute) dataFlow.getAttribute(), srcRes)); break; - } else if (edgeAttr.getSrouce() == channelGen && edgeAttr.getDestination() == dstRes.getIdentifierTemplate()) { + } else if (edgeAttr.getSrouce() == channel && edgeAttr.getDestination() == dstRes.getResource()) { // output edge edgeCell.setValue(new OutEdgeAttribute(edgeAttr, dstRes)); break; diff --git a/AlgebraicDataflowArchitectureModel/src/application/layouts/DAGLayout.java b/AlgebraicDataflowArchitectureModel/src/application/layouts/DAGLayout.java index 23ae67e..ed9181a 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/layouts/DAGLayout.java +++ b/AlgebraicDataflowArchitectureModel/src/application/layouts/DAGLayout.java @@ -16,30 +16,16 @@ import com.mxgraph.view.mxGraphView; import models.controlFlowModel.ObjectNodeAttribute; -import models.dataConstraintModel.ChannelGenerator; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.Channel; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.ResourceNodeAttribute; -/************************************************************* - * DAG-Layout sorting algorithm. - */ public class DAGLayout extends mxGraphLayout { - /************************************************************* - * [ *constructor] - /************************************************************* - * - * @param graph - */ public DAGLayout(mxGraph graph) { super(graph); } - /************************************************************* - * [ *public ] - /************************************************************* - * Executing a layout sorting algorithm. - */ @Override public void execute(Object parent) { mxIGraphModel model = graph.getModel(); diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java index 78af141..a61be75 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java @@ -25,18 +25,18 @@ import models.controlFlowModel.EntryPointObjectNode; import models.controlFlowModel.ObjectNode; import models.controlFlowModel.StatefulObjectNode; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataFlowEdge; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.IFlowGraph; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.ResourceNode; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; /** * Common generator for prototypes @@ -142,9 +142,9 @@ } if (rn != null) { for (Edge e: rn.getOutEdges()) { - DataTransferChannelGenerator ch = ((DataFlowEdge) e).getChannelGenerator(); + DataTransferChannel ch = ((DataFlowEdge) e).getChannel(); for (ChannelMember m: ch.getReferenceChannelMembers()) { - if (m.getIdentifierTemplate() == cn.getIdentifierTemplate()) { + if (m.getResource() == cn.getResource()) { topologicalSort(allNodes, n, visited, orderedList); } } @@ -156,13 +156,13 @@ } protected void updateMainComponent(DataTransferModel model, TypeDeclaration mainType, MethodDeclaration mainConstructor, Node componentNode, - final List depends, ILanguageSpecific langSpec) { + final List depends, ILanguageSpecific langSpec) { // Declare the field to refer to each object in the main type. ResourceNode resNode = null; String nodeName = null; if (componentNode instanceof ResourceNode) { resNode = (ResourceNode) componentNode; - nodeName = resNode.getIdentifierTemplate().getResourceName(); + nodeName = resNode.getResource().getResourceName(); } else if (componentNode instanceof ObjectNode) { nodeName = ((ObjectNode) componentNode).getName(); if (componentNode instanceof StatefulObjectNode) { @@ -177,17 +177,17 @@ } // Add a statement to instantiate each object to the main constructor. List parameters = new ArrayList<>(); - for (IdentifierTemplate id: depends) { + for (ResourcePath id: depends) { // For the callee objects (the destination resource of push transfer or the source resource of pull transfer). parameters.add(id.getResourceName()); } // For the refs. if (resNode != null) { - Set refs = new HashSet<>(); - for (ChannelGenerator cg : model.getChannelGenerators()) { - DataTransferChannelGenerator ch = (DataTransferChannelGenerator) cg; - if (ch.getInputIdentifierTemplates().contains(resNode.getIdentifierTemplate())) { - for (IdentifierTemplate id: ch.getReferenceIdentifierTemplates()) { + Set refs = new HashSet<>(); + for (Channel cg : model.getChannels()) { + DataTransferChannel ch = (DataTransferChannel) cg; + if (ch.getInputResources().contains(resNode.getResource())) { + for (ResourcePath id: ch.getReferenceResources()) { if (!refs.contains(id) && !depends.contains(id)) { refs.add(id); String refResName = id.getResourceName(); @@ -209,7 +209,7 @@ protected void addReference(TypeDeclaration component, MethodDeclaration constructor, Node dstNode, ILanguageSpecific langSpec) { String dstNodeName = null; if (dstNode instanceof ResourceNode) { - dstNodeName = ((ResourceNode) dstNode).getIdentifierTemplate().getResourceName(); + dstNodeName = ((ResourceNode) dstNode).getResource().getResourceName(); } else if (dstNode instanceof ObjectNode) { dstNodeName = ((ObjectNode) dstNode).getName(); } @@ -245,7 +245,7 @@ } } - protected void declareAccessorInMainComponent(TypeDeclaration mainComponent, IdentifierTemplate accessResId, ILanguageSpecific langSpec) { + protected void declareAccessorInMainComponent(TypeDeclaration mainComponent, ResourcePath accessResId, ILanguageSpecific langSpec) { MethodDeclaration getter = new MethodDeclaration("get" + langSpec.toComponentName(accessResId.getResourceName()), accessResId.getResourceStateType()); Block block = new Block(); block.addStatement(langSpec.getReturnStatement(langSpec.getMethodInvocation(accessResId.getResourceName(), getterOfResourceState)) + langSpec.getStatementDelimiter()); @@ -254,12 +254,12 @@ } protected void declareFieldsToReferenceResources(DataTransferModel model, ResourceNode resourceNode, TypeDeclaration component, MethodDeclaration constructor, - final List depends, ILanguageSpecific langSpec) { - Set refs = new HashSet<>(); - for (ChannelGenerator ch : model.getChannelGenerators()) { - DataTransferChannelGenerator c = (DataTransferChannelGenerator) ch; - if (c.getInputIdentifierTemplates().contains(resourceNode.getIdentifierTemplate())) { - for (IdentifierTemplate id: c.getReferenceIdentifierTemplates()) { + final List depends, ILanguageSpecific langSpec) { + Set refs = new HashSet<>(); + for (Channel ch : model.getChannels()) { + DataTransferChannel c = (DataTransferChannel) ch; + if (c.getInputResources().contains(resourceNode.getResource())) { + for (ResourcePath id: c.getReferenceResources()) { if (!refs.contains(id) && !depends.contains(id)) { refs.add(id); String refResName = langSpec.toComponentName(id.getResourceName()); @@ -277,16 +277,16 @@ List passedResoueces = dataFlowInform.get(inEdge).get(PushPullValue.PUSH); String methodName = updateMethodName; for (ResourceNode rn: passedResoueces) { - IdentifierTemplate rId = rn.getIdentifierTemplate(); + ResourcePath rId = rn.getResource(); methodName += langSpec.toComponentName(rId.getResourceName()); } return getMethod(component, methodName); } - protected MethodDeclaration getInputMethod(ResourceNode resourceNode, DataTransferChannelGenerator ch, TypeDeclaration component) { + protected MethodDeclaration getInputMethod(ResourceNode resourceNode, DataTransferChannel ch, TypeDeclaration component) { MethodDeclaration input = null; for (ChannelMember out : ch.getOutputChannelMembers()) { - if (out.getIdentifierTemplate().equals(resourceNode.getIdentifierTemplate())) { + if (out.getResource().equals(resourceNode.getResource())) { Expression message = out.getStateTransition().getMessageExpression(); if (message instanceof Term) { input = getMethod(component, ((Term) message).getSymbol().getImplName()); @@ -310,7 +310,7 @@ protected IResourceStateAccessor getPushAccessor() { return new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { return new Field(fieldOfResourceState, target.getResourceStateType() != null ? target.getResourceStateType() @@ -323,7 +323,7 @@ } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { return new Parameter(target.getResourceName(), target.getResourceStateType() != null ? target.getResourceStateType() : DataConstraintModel.typeInt); @@ -334,7 +334,7 @@ protected IResourceStateAccessor getPullAccessor() { return new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { return new Field(fieldOfResourceState, target.getResourceStateType() != null ? target.getResourceStateType() @@ -347,7 +347,7 @@ } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { Term getter = new Term(new Symbol(getterOfResourceState, 1, Symbol.Type.METHOD)); getter.addChild(new Field(target.getResourceName(), target.getResourceStateType())); return getter; diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromControlFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromControlFlowGraph.java index 9fa066a..9251787 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromControlFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromControlFlowGraph.java @@ -33,9 +33,9 @@ import models.controlFlowModel.StatefulObjectNode; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataFlowEdge; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.IFlowGraph; import models.dataFlowModel.PushPullAttribute; @@ -43,7 +43,7 @@ import models.dataFlowModel.ResolvingMultipleDefinitionIsFutureWork; import models.dataFlowModel.ResourceNode; import models.dataFlowModel.StoreAttribute; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; public class CodeGeneratorFromControlFlowGraph extends CodeGenerator { @@ -73,13 +73,13 @@ componentMap.put(componentNode, component); // Declare the constructor and the fields to refer to the callee components. - List depends = new ArrayList<>(); + List depends = new ArrayList<>(); MethodDeclaration constructor = declareConstructorAndFieldsToCalleeComponents((ObjectNode) componentNode, component, depends, langSpec); if (componentNode instanceof StatefulObjectNode) { // For this resource. ResourceNode resourceNode = ((StatefulObjectNode) componentNode).getResource(); - IdentifierTemplate resId = resourceNode.getIdentifierTemplate(); + ResourcePath resId = resourceNode.getResource(); Type resStateType = resId.getResourceStateType(); // Declare the field in this resource to store the state. @@ -111,12 +111,12 @@ TypeDeclaration component = componentMap.get(node); if (node instanceof StatefulObjectNode) { ResourceNode resourceNode = ((StatefulObjectNode) node).getResource(); - Type resStateType = resourceNode.getIdentifierTemplate().getResourceStateType(); + Type resStateType = resourceNode.getResource().getResourceStateType(); if (((StoreAttribute) resourceNode.getAttribute()).isStored()) { // Declare the getter method in this resource to obtain the state. MethodDeclaration getter = langSpec.newMethodDeclaration(getterOfResourceState, resStateType); component.addMethod(getter); - fillGetterMethodToReturnStateField(getter, resourceNode.getIdentifierTemplate().getResourceStateType(), langSpec); // return this.value; + fillGetterMethodToReturnStateField(getter, resourceNode.getResource().getResourceStateType(), langSpec); // return this.value; } } } @@ -243,7 +243,7 @@ } private MethodDeclaration declareConstructorAndFieldsToCalleeComponents(ObjectNode componentNode, TypeDeclaration component, - List depends, ILanguageSpecific langSpec) { + List depends, ILanguageSpecific langSpec) { // Declare a constructor in each component. MethodDeclaration constructor = component.createConstructor(); Block block = new Block(); @@ -254,7 +254,7 @@ ObjectNode dstNode = (ObjectNode) e.getDestination(); addReference(component, constructor, dstNode, langSpec); if (dstNode instanceof StatefulObjectNode) { - IdentifierTemplate dstId = ((StatefulObjectNode) dstNode).getResource().getIdentifierTemplate(); + ResourcePath dstId = ((StatefulObjectNode) dstNode).getResource().getResource(); if (!depends.contains(dstId)) depends.add(dstId); } } @@ -272,7 +272,7 @@ } if (node instanceof StatefulObjectNode) { ResourceNode resourceNode = ((StatefulObjectNode) node).getResource(); - Type resStateType = resourceNode.getIdentifierTemplate().getResourceStateType(); + Type resStateType = resourceNode.getResource().getResourceStateType(); MethodDeclaration getter = langSpec.newMethodDeclaration(getterOfResourceState, resStateType); MethodDeclaration getter2 = getMethod(component, getter.getName()); if (getter2 == null) { @@ -283,19 +283,19 @@ if (((StoreAttribute) resourceNode.getAttribute()).isStored()) { if (getter2 == null) { // Declare the getter method in this resource to obtain the state. - fillGetterMethodToReturnStateField(getter, resourceNode.getIdentifierTemplate().getResourceStateType(), langSpec); // return this.value; + fillGetterMethodToReturnStateField(getter, resourceNode.getResource().getResourceStateType(), langSpec); // return this.value; } } else { // Invocations to other getter methods when at least one incoming data-flow edges is PULL-style. boolean isContainedPush = false; - DataTransferChannelGenerator ch = null; - HashMap inputIdentifierToStateAccessor = new HashMap<>(); + DataTransferChannel ch = null; + HashMap inputResourceToStateAccessor = new HashMap<>(); for (Edge eIn: resourceNode.getInEdges()) { DataFlowEdge dIn = (DataFlowEdge) eIn; if (((PushPullAttribute) dIn.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { // PUSH data transfer isContainedPush = true; - inputIdentifierToStateAccessor.put(((ResourceNode) dIn.getSource()).getIdentifierTemplate(), getPushAccessor()); + inputResourceToStateAccessor.put(((ResourceNode) dIn.getSource()).getResource(), getPushAccessor()); } else { // PULL data transfer for (Edge outEdge: node.getOutEdges()) { @@ -305,35 +305,35 @@ if (returnedResources.contains((ResourceNode) dIn.getSource())) { if (returnedResources.size() == 1) { MethodDeclaration nextGetter = declareAndFillGetterMethods(dstNode, outEdge, dataFlowInform, componentMap, langSpec); - inputIdentifierToStateAccessor.put(((ResourceNode) dIn.getSource()).getIdentifierTemplate(), getPullAccessor(dstNode.getName(), nextGetter.getName())); + inputResourceToStateAccessor.put(((ResourceNode) dIn.getSource()).getResource(), getPullAccessor(dstNode.getName(), nextGetter.getName())); break; } else { MethodDeclaration nextGetter = declareAndFillGetterMethods(dstNode, outEdge, dataFlowInform, componentMap, langSpec); int idx = returnedResources.indexOf((ResourceNode) dIn.getSource()); int len = returnedResources.size(); - inputIdentifierToStateAccessor.put(((ResourceNode) dIn.getSource()).getIdentifierTemplate(), + inputResourceToStateAccessor.put(((ResourceNode) dIn.getSource()).getResource(), getPullAccessor(langSpec.getTupleGet(langSpec.getMethodInvocation(langSpec.getFieldAccessor(dstNode.getName()), nextGetter.getName()), idx, len))); break; } } } - ch = dIn.getChannelGenerator(); // Always unique. + ch = dIn.getChannel(); // Always unique. } } // For reference channel members. for (ChannelMember c: ch.getReferenceChannelMembers()) { - inputIdentifierToStateAccessor.put(c.getIdentifierTemplate(), getPullAccessor()); // by pull data transfer + inputResourceToStateAccessor.put(c.getResource(), getPullAccessor()); // by pull data transfer } // Add a return statement. try { for (ChannelMember out: ch.getOutputChannelMembers()) { - if (out.getIdentifierTemplate() == resourceNode.getIdentifierTemplate()) { + if (out.getResource() == resourceNode.getResource()) { String[] sideEffects = new String[] {""}; // The following process is common to the cases of 1) and 2). // 1) All incoming edges are in PULL-style. // 2) At least one incoming edge is in PUSH-style. - String curState = ch.deriveUpdateExpressionOf(out, getPullAccessor(), inputIdentifierToStateAccessor).toImplementation(sideEffects); + String curState = ch.deriveUpdateExpressionOf(out, getPullAccessor(), inputResourceToStateAccessor).toImplementation(sideEffects); getter.addStatement(sideEffects[0] + langSpec.getReturnStatement(curState) + langSpec.getStatementDelimiter()); break; } @@ -353,8 +353,8 @@ } else { // Unexpected. } - getterMethodName += langSpec.toComponentName(returnedRes.getIdentifierTemplate().getResourceName()) + "Value"; - MethodDeclaration mediateGetter = langSpec.newMethodDeclaration(getterMethodName, returnedRes.getIdentifierTemplate().getResourceStateType()); + getterMethodName += langSpec.toComponentName(returnedRes.getResource().getResourceName()) + "Value"; + MethodDeclaration mediateGetter = langSpec.newMethodDeclaration(getterMethodName, returnedRes.getResource().getResourceStateType()); component.addMethod(mediateGetter); // Add a return statement. @@ -373,7 +373,7 @@ // Declare a mediate getter method to return multiple values. String getterMethodName = "get"; for (ResourceNode rn: resourcesToReturn) { - getterMethodName += langSpec.toComponentName(rn.getIdentifierTemplate().getResourceName()); + getterMethodName += langSpec.toComponentName(rn.getResource().getResourceName()); } getterMethodName += "Values"; Type returnType = createReturnType(resourcesToReturn, langSpec); @@ -392,7 +392,7 @@ } else { List params = new ArrayList<>(); for (ResourceNode rn: resourcesToReturn) { - IdentifierTemplate rId = rn.getIdentifierTemplate(); + ResourcePath rId = rn.getResource(); if (rId.getResourceName().equals(((ObjectNode) node).getName())) { params.add(langSpec.getMethodInvocation(getterOfResourceState)); } else { @@ -441,7 +441,7 @@ // Declare an update method. updateOrInput = declareUpdateMethod(node, inEdge, component, dataFlowInform, langSpec); } else { - DataTransferChannelGenerator ch = ((EntryPointObjectNode) prevResNode).getIoChannelGenerator(); + DataTransferChannel ch = ((EntryPointObjectNode) prevResNode).getIOChannel(); updateOrInput = getInputMethod(resourceNode, ch, component); if (updateOrInput != null) return updateOrInput; // Declare an input method. @@ -459,7 +459,7 @@ String varName = addInvocationInResourceUpdate(node, updateOrInput, calleeMethod, ((ObjectNode) dstNode).getName(), returnedResources, langSpec); if (varName != null && returnedResources != null) { for (ResourceNode rn: returnedResources) { - String resName = rn.getIdentifierTemplate().getResourceName(); + String resName = rn.getResource().getResourceName(); resToVar.put(rn, resName); varToRes.put(resName, Arrays.asList(new ResourceNode[] {rn})); } @@ -548,7 +548,7 @@ String varName = addInvocationInMediatorUpdate(updateOrInput, calleeMethod, ((ObjectNode) dstNode).getName(), returnedResources, langSpec); if (varName != null && returnedResources != null) { for (ResourceNode rn: returnedResources) { - String resName = rn.getIdentifierTemplate().getResourceName(); + String resName = rn.getResource().getResourceName(); resToVar.put(rn, resName); varToRes.put(resName, Arrays.asList(new ResourceNode[] {rn})); } @@ -576,10 +576,10 @@ // Declare an update method in the component. ArrayList vars = new ArrayList<>(); List passedResoueces = dataFlowInform.get(inEdge).get(PushPullValue.PUSH); - Set passedIds = new HashSet<>(); + Set passedIds = new HashSet<>(); String methodName = updateMethodName; for (ResourceNode rn: passedResoueces) { - IdentifierTemplate rId = rn.getIdentifierTemplate(); + ResourcePath rId = rn.getResource(); passedIds.add(rId); methodName += langSpec.toComponentName(rId.getResourceName()); vars.add(langSpec.newVariableDeclaration(rId.getResourceStateType(), rId.getResourceName())); @@ -593,11 +593,11 @@ try { for (Edge e: resourceNode.getInEdges()) { DataFlowEdge re = (DataFlowEdge) e; - for (ChannelMember in: re.getChannelGenerator().getInputChannelMembers()) { - if (passedIds.contains(in.getIdentifierTemplate())) { - for (ChannelMember out: re.getChannelGenerator().getOutputChannelMembers()) { - if (out.getIdentifierTemplate() == resourceNode.getIdentifierTemplate()) { - Expression updateExp = re.getChannelGenerator().deriveUpdateExpressionOf(out, getPushAccessor()); + for (ChannelMember in: re.getChannel().getInputChannelMembers()) { + if (passedIds.contains(in.getResource())) { + for (ChannelMember out: re.getChannel().getOutputChannelMembers()) { + if (out.getResource() == resourceNode.getResource()) { + Expression updateExp = re.getChannel().deriveUpdateExpressionOf(out, getPushAccessor()); String[] sideEffects = new String[] {""}; String curState = updateExp.toImplementation(sideEffects); String updateStatement; @@ -622,7 +622,7 @@ // Declare the field to cache the state of the source resource in the type of the destination resource. if (node.getIndegree() > 1) { // If incoming edges are multiple - for (IdentifierTemplate srcRes: passedIds) { + for (ResourcePath srcRes: passedIds) { String srcResName = srcRes.getResourceName(); if (langSpec.declareField()) { // Declare the cache field. @@ -642,10 +642,10 @@ return update; } - private MethodDeclaration declareInputMethod(ResourceNode resourceNode, DataTransferChannelGenerator ch, ILanguageSpecific langSpec) { + private MethodDeclaration declareInputMethod(ResourceNode resourceNode, DataTransferChannel ch, ILanguageSpecific langSpec) { MethodDeclaration input = null; for (ChannelMember out : ch.getOutputChannelMembers()) { - if (out.getIdentifierTemplate().equals(resourceNode.getIdentifierTemplate())) { + if (out.getResource().equals(resourceNode.getResource())) { Expression message = out.getStateTransition().getMessageExpression(); if (message instanceof Term) { // Declare an input method in this component. @@ -687,7 +687,7 @@ private String createReturnValue(List resourcesToReturn, Node node, Type returnType, Map resToVar, Map> varToRes, ILanguageSpecific langSpec) { List params = new ArrayList<>(); for (ResourceNode rn: resourcesToReturn) { - IdentifierTemplate rId = rn.getIdentifierTemplate(); + ResourcePath rId = rn.getResource(); if (rId.getResourceName().equals(((ObjectNode) node).getName())) { params.add(langSpec.getFieldAccessor(fieldOfResourceState)); } else { @@ -708,11 +708,11 @@ private Type createReturnType(List resourcesToReturn, ILanguageSpecific langSpec) { if (resourcesToReturn.size() == 1) { - return resourcesToReturn.iterator().next().getIdentifierTemplate().getResourceStateType(); + return resourcesToReturn.iterator().next().getResource().getResourceStateType(); } List compTypes = new ArrayList<>(); for (ResourceNode rn: resourcesToReturn) { - IdentifierTemplate rId = rn.getIdentifierTemplate(); + ResourcePath rId = rn.getResource(); compTypes.add(rId.getResourceStateType()); } Type returnType = langSpec.newTupleType(compTypes); @@ -759,7 +759,7 @@ String targetVarName = null; if (returnResources.size() == 1) { ResourceNode targetNode = returnResources.get(0); - targetVarName = targetNode.getIdentifierTemplate().getResourceName(); + targetVarName = targetNode.getResource().getResourceName(); resourceUpdateMethod.addStatement( langSpec.getVariableDeclaration(calleeMethod.getReturnType().getInterfaceTypeName(), targetVarName) + langSpec.getAssignment() @@ -771,7 +771,7 @@ VariableDeclaration targetVar = langSpec.newVariableDeclaration(calleeMethod.getReturnType(), targetVarName); List vars = new ArrayList<>(); for (ResourceNode rn: returnResources) { - IdentifierTemplate rId = rn.getIdentifierTemplate(); + ResourcePath rId = rn.getResource(); vars.add(langSpec.newVariableDeclaration(rId.getResourceStateType(), rId.getResourceName())); } resourceUpdateMethod.addStatement( @@ -800,7 +800,7 @@ String targetVarName = null; if (returnResources.size() == 1) { ResourceNode targetNode = returnResources.get(0); - targetVarName = targetNode.getIdentifierTemplate().getResourceName(); + targetVarName = targetNode.getResource().getResourceName(); resourceUpdateMethod.addStatement( langSpec.getVariableDeclaration(calleeMethod.getReturnType().getInterfaceTypeName(), targetVarName) + langSpec.getAssignment() @@ -812,7 +812,7 @@ VariableDeclaration targetVar = langSpec.newVariableDeclaration(calleeMethod.getReturnType(), targetVarName); List vars = new ArrayList<>(); for (ResourceNode rn: returnResources) { - IdentifierTemplate rId = rn.getIdentifierTemplate(); + ResourcePath rId = rn.getResource(); vars.add(langSpec.newVariableDeclaration(rId.getResourceStateType(), rId.getResourceName())); } resourceUpdateMethod.addStatement( @@ -829,9 +829,9 @@ String varName = null; for (ResourceNode rn: resources) { if (varName == null) { - varName = rn.getIdentifierTemplate().getResourceName(); + varName = rn.getResource().getResourceName(); } else { - varName += langSpec.toComponentName(rn.getIdentifierTemplate().getResourceName()); + varName += langSpec.toComponentName(rn.getResource().getResourceName()); } } return varName; @@ -850,7 +850,7 @@ protected IResourceStateAccessor getPullAccessor(final String receiverName, final String getterOfResourceState) { return new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { return new Field(fieldOfResourceState, target.getResourceStateType() != null ? target.getResourceStateType() @@ -863,7 +863,7 @@ } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { Term getter = new Term(new Symbol(getterOfResourceState, 1, Symbol.Type.METHOD)); getter.addChild(new Field(receiverName, target.getResourceStateType())); return getter; @@ -874,7 +874,7 @@ protected IResourceStateAccessor getPullAccessor(final String resourceAccessor) { return new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { return new Field(fieldOfResourceState, target.getResourceStateType() != null ? target.getResourceStateType() @@ -887,7 +887,7 @@ } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { return new Constant(resourceAccessor); } }; diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java index 94fce58..85a503f 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java @@ -23,11 +23,11 @@ import models.algebra.UnificationFailed; import models.algebra.ValueUndefined; import models.algebra.Variable; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataFlowEdge; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.IFlowGraph; import models.dataFlowModel.PushPullAttribute; @@ -35,7 +35,7 @@ import models.dataFlowModel.ResolvingMultipleDefinitionIsFutureWork; import models.dataFlowModel.ResourceNode; import models.dataFlowModel.StoreAttribute; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; public class CodeGeneratorFromDataFlowGraph extends CodeGenerator { @@ -45,17 +45,17 @@ for (Node componentNode: components) { // Declare this resource. ResourceNode resourceNode = (ResourceNode) componentNode; - String resourceName = langSpec.toComponentName(resourceNode.getIdentifierTemplate().getResourceName()); + String resourceName = langSpec.toComponentName(resourceNode.getResource().getResourceName()); TypeDeclaration component = langSpec.newTypeDeclaration(resourceName); // Declare the constructor and the fields to refer to other resources. - List depends = new ArrayList<>(); + List depends = new ArrayList<>(); MethodDeclaration constructor = declareConstructorAndFieldsToReferToResources(resourceNode, component, depends, langSpec); // Update the main component for this component. updateMainComponent(model, mainComponent, mainConstructor, componentNode, depends, langSpec); - IdentifierTemplate resId = resourceNode.getIdentifierTemplate(); + ResourcePath resId = resourceNode.getResource(); Type resStateType = resId.getResourceStateType(); // Declare the field in this resource to store the state. @@ -90,7 +90,7 @@ } private MethodDeclaration declareConstructorAndFieldsToReferToResources(ResourceNode resourceNode, TypeDeclaration component, - List depends, ILanguageSpecific langSpec) { + List depends, ILanguageSpecific langSpec) { // Declare a constructor in each component. MethodDeclaration constructor = component.createConstructor(); Block block = new Block(); @@ -101,7 +101,7 @@ if (((PushPullAttribute) ((DataFlowEdge) e).getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { // for PUSH transfer addReference(component, constructor, e.getDestination(), langSpec); - IdentifierTemplate dstId = ((ResourceNode) e.getDestination()).getIdentifierTemplate(); + ResourcePath dstId = ((ResourceNode) e.getDestination()).getResource(); if (!depends.contains(dstId)) depends.add(dstId); } } @@ -109,7 +109,7 @@ if (((PushPullAttribute) ((DataFlowEdge) e).getAttribute()).getOptions().get(0) != PushPullValue.PUSH) { // for PULL transfer addReference(component, constructor, e.getSource(), langSpec); - IdentifierTemplate srcId = ((ResourceNode) e.getSource()).getIdentifierTemplate(); + ResourcePath srcId = ((ResourceNode) e.getSource()).getResource(); if (!depends.contains(srcId)) depends.add(srcId); } } @@ -126,29 +126,29 @@ } else { // invocations to other getter methods when at least one incoming data-flow edges is PULL-style. boolean isContainedPush = false; - DataTransferChannelGenerator ch = null; - HashMap inputIdentifierToStateAccessor = new HashMap<>(); + DataTransferChannel ch = null; + HashMap inputResourceToStateAccessor = new HashMap<>(); for (Edge eIn: resourceNode.getInEdges()) { DataFlowEdge dIn = (DataFlowEdge) eIn; if (((PushPullAttribute) dIn.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { // PUSH transfer isContainedPush = true; - inputIdentifierToStateAccessor.put(((ResourceNode) dIn.getSource()).getIdentifierTemplate(), getPushAccessor()); + inputResourceToStateAccessor.put(((ResourceNode) dIn.getSource()).getResource(), getPushAccessor()); } else { // PULL transfer - inputIdentifierToStateAccessor.put(((ResourceNode) dIn.getSource()).getIdentifierTemplate(), getPullAccessor()); - ch = dIn.getChannelGenerator(); + inputResourceToStateAccessor.put(((ResourceNode) dIn.getSource()).getResource(), getPullAccessor()); + ch = dIn.getChannel(); } } // for reference channel members. for (ChannelMember c: ch.getReferenceChannelMembers()) { - inputIdentifierToStateAccessor.put(c.getIdentifierTemplate(), getPullAccessor()); // by pull data transfer + inputResourceToStateAccessor.put(c.getResource(), getPullAccessor()); // by pull data transfer } // generate a return statement. try { for (ChannelMember out: ch.getOutputChannelMembers()) { - if (out.getIdentifierTemplate() == resourceNode.getIdentifierTemplate()) { + if (out.getResource() == resourceNode.getResource()) { String[] sideEffects = new String[] {""}; if (!isContainedPush) { // All incoming edges are in PULL-style. @@ -156,7 +156,7 @@ getter.addStatement(sideEffects[0] + langSpec.getReturnStatement(curState) + langSpec.getStatementDelimiter()); } else { // At least one incoming edge is in PUSH-style. - String curState = ch.deriveUpdateExpressionOf(out, getPullAccessor(), inputIdentifierToStateAccessor).toImplementation(sideEffects); + String curState = ch.deriveUpdateExpressionOf(out, getPullAccessor(), inputResourceToStateAccessor).toImplementation(sideEffects); getter.addStatement(sideEffects[0] + langSpec.getReturnStatement(curState) + langSpec.getStatementDelimiter()); } break; @@ -173,11 +173,11 @@ private List declareCacheFieldsAndUpdateMethods(ResourceNode resourceNode, TypeDeclaration component, ILanguageSpecific langSpec) { // Declare cash fields and update methods in the component. - String resComponentName = langSpec.toComponentName(resourceNode.getIdentifierTemplate().getResourceName()); + String resComponentName = langSpec.toComponentName(resourceNode.getResource().getResourceName()); List updateMethods = new ArrayList<>(); for (Edge e: resourceNode.getInEdges()) { DataFlowEdge re = (DataFlowEdge) e; - IdentifierTemplate srcRes = ((ResourceNode) re.getSource()).getIdentifierTemplate(); + ResourcePath srcRes = ((ResourceNode) re.getSource()).getResource(); String srcResName = srcRes.getResourceName(); String srcResComponentName = langSpec.toComponentName(srcResName); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { @@ -187,9 +187,9 @@ ArrayList vars = new ArrayList<>(); vars.add(langSpec.newVariableDeclaration(srcRes.getResourceStateType(), srcRes.getResourceName())); // For the refs. - DataTransferChannelGenerator ch = (DataTransferChannelGenerator) re.getChannelGenerator(); - for (IdentifierTemplate ref: ch.getReferenceIdentifierTemplates()) { - if (ref != resourceNode.getIdentifierTemplate()) { + DataTransferChannel ch = (DataTransferChannel) re.getChannel(); + for (ResourcePath ref: ch.getReferenceResources()) { + if (ref != resourceNode.getResource()) { vars.add(langSpec.newVariableDeclaration(ref.getResourceStateType(), ref.getResourceName())); } } @@ -200,9 +200,9 @@ // Add a statement to update the state field if (((StoreAttribute) resourceNode.getAttribute()).isStored()) { try { - for (ChannelMember out: re.getChannelGenerator().getOutputChannelMembers()) { - if (out.getIdentifierTemplate() == resourceNode.getIdentifierTemplate()) { - Expression updateExp = re.getChannelGenerator().deriveUpdateExpressionOf(out, getPushAccessor()); + for (ChannelMember out: re.getChannel().getOutputChannelMembers()) { + if (out.getResource() == resourceNode.getResource()) { + Expression updateExp = re.getChannel().deriveUpdateExpressionOf(out, getPushAccessor()); String[] sideEffects = new String[] {""}; String curState = updateExp.toImplementation(sideEffects); String updateStatement; @@ -247,22 +247,22 @@ DataFlowEdge dOut = (DataFlowEdge) eOut; if (((PushPullAttribute) dOut.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { // PUSH transfer - Map> referredResources = new HashMap<>(); + Map> referredResources = new HashMap<>(); List params = new ArrayList<>(); params.add(langSpec.getFieldAccessor(fieldOfResourceState)); - Set referredSet = referredResources.get(update); - for (ChannelMember rc: re.getChannelGenerator().getReferenceChannelMembers()) { + Set referredSet = referredResources.get(update); + for (ChannelMember rc: re.getChannel().getReferenceChannelMembers()) { // to get the value of reference member. - IdentifierTemplate ref = rc.getIdentifierTemplate(); + ResourcePath ref = rc.getResource(); if (referredSet == null) { referredSet = new HashSet<>(); referredResources.put(update, referredSet); } - if (ref != resourceNode.getIdentifierTemplate()) { + if (ref != resourceNode.getResource()) { String refVarName = ref.getResourceName(); if (!referredSet.contains(ref)) { referredSet.add(ref); - Expression refGetter = getPullAccessor().getCurrentStateAccessorFor(ref, ((ResourceNode) dOut.getSource()).getIdentifierTemplate()); + Expression refGetter = getPullAccessor().getCurrentStateAccessorFor(ref, ((ResourceNode) dOut.getSource()).getResource()); String[] sideEffects = new String[] {""}; String refExp = refGetter.toImplementation(sideEffects); String refTypeName = ref.getResourceStateType().getInterfaceTypeName(); @@ -271,7 +271,7 @@ params.add(refVarName); } } - update.addStatement(langSpec.getMethodInvocation(langSpec.getFieldAccessor(((ResourceNode) dOut.getDestination()).getIdentifierTemplate().getResourceName()), + update.addStatement(langSpec.getMethodInvocation(langSpec.getFieldAccessor(((ResourceNode) dOut.getDestination()).getResource().getResourceName()), updateMethodName + resComponentName, params) + langSpec.getStatementDelimiter()); // this.dst.updateSrc(value, refParams); } @@ -284,12 +284,12 @@ private List declareInputMethodsInThisAndMainComponents(ResourceNode resourceNode, TypeDeclaration component, TypeDeclaration mainComponent, DataTransferModel model, ILanguageSpecific langSpec) { // Declare input methods. - String resName = resourceNode.getIdentifierTemplate().getResourceName(); + String resName = resourceNode.getResource().getResourceName(); String resComponentName = langSpec.toComponentName(resName); List inputMethods = new ArrayList<>(); - for (ChannelGenerator ch : model.getIOChannelGenerators()) { - for (ChannelMember out : ((DataTransferChannelGenerator) ch).getOutputChannelMembers()) { - if (out.getIdentifierTemplate().equals(resourceNode.getIdentifierTemplate())) { + for (Channel ch : model.getIOChannels()) { + for (ChannelMember out : ((DataTransferChannel) ch).getOutputChannelMembers()) { + if (out.getResource().equals(resourceNode.getResource())) { Expression message = out.getStateTransition().getMessageExpression(); MethodDeclaration input = null; MethodDeclaration mainInput = null; @@ -354,7 +354,7 @@ try { String[] sideEffects = new String[] {""}; Expression updateExp; - updateExp = ((DataTransferChannelGenerator) ch).deriveUpdateExpressionOf(out, getPullAccessor()); + updateExp = ((DataTransferChannel) ch).deriveUpdateExpressionOf(out, getPullAccessor()); String newState = updateExp.toImplementation(sideEffects); String updateStatement; if (updateExp instanceof Term && ((Term) updateExp).getSymbol().isImplWithSideEffect()) { @@ -373,22 +373,22 @@ DataFlowEdge dOut = (DataFlowEdge) eOut; if (((PushPullAttribute) dOut.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { // PUSH transfer - Map> referredResources = new HashMap<>(); + Map> referredResources = new HashMap<>(); List params = new ArrayList<>(); params.add(langSpec.getFieldAccessor(fieldOfResourceState)); - Set referredSet = referredResources.get(input); - for (ChannelMember rc: ((DataTransferChannelGenerator) ch).getReferenceChannelMembers()) { + Set referredSet = referredResources.get(input); + for (ChannelMember rc: ((DataTransferChannel) ch).getReferenceChannelMembers()) { // to get the value of reference member. - IdentifierTemplate ref = rc.getIdentifierTemplate(); + ResourcePath ref = rc.getResource(); if (referredSet == null) { referredSet = new HashSet<>(); referredResources.put(input, referredSet); } - if (ref != resourceNode.getIdentifierTemplate()) { + if (ref != resourceNode.getResource()) { String refVarName = ref.getResourceName(); if (!referredSet.contains(ref)) { referredSet.add(ref); - Expression refGetter = getPullAccessor().getCurrentStateAccessorFor(ref, ((ResourceNode) dOut.getSource()).getIdentifierTemplate()); + Expression refGetter = getPullAccessor().getCurrentStateAccessorFor(ref, ((ResourceNode) dOut.getSource()).getResource()); String[] sideEffects = new String[] {""}; String refExp = refGetter.toImplementation(sideEffects); String refTypeName = ref.getResourceStateType().getInterfaceTypeName(); @@ -397,7 +397,7 @@ params.add(refVarName); } } - input.addStatement(langSpec.getMethodInvocation(langSpec.getFieldAccessor(((ResourceNode) dOut.getDestination()).getIdentifierTemplate().getResourceName()), + input.addStatement(langSpec.getMethodInvocation(langSpec.getFieldAccessor(((ResourceNode) dOut.getDestination()).getResource().getResourceName()), updateMethodName + resComponentName, params) + langSpec.getStatementDelimiter()); // this.dst.updateSrc(value, refParams); } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/ILanguageSpecific.java b/AlgebraicDataflowArchitectureModel/src/generators/ILanguageSpecific.java index 40d2f25..38e4e0a 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/ILanguageSpecific.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/ILanguageSpecific.java @@ -10,7 +10,7 @@ import code.ast.VariableDeclaration; import models.algebra.Expression; import models.algebra.Type; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; public interface ILanguageSpecific { CompilationUnit newCompilationUnit(TypeDeclaration component); diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java index 5af38f1..b18f79b 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaCodeGenerator.java @@ -23,13 +23,13 @@ import models.algebra.Term; import models.algebra.Type; import models.algebra.Variable; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.DataFlowEdge; @@ -76,15 +76,15 @@ // For each resource. for (ResourceNode rn: resources) { boolean f = false; - String resourceName = toTypeName(rn.getIdentifierTemplate().getResourceName()); + String resourceName = toTypeName(rn.getResource().getResourceName()); TypeDeclaration type = new TypeDeclaration(resourceName); // Declare the field to refer to each resource in the main type. String fieldInitializer = "new " + resourceName + "("; - Set depends = new HashSet<>(); + Set depends = new HashSet<>(); for (Edge e : rn.getOutEdges()) { DataFlowEdge re = (DataFlowEdge) e; - IdentifierTemplate dstRes = ((ResourceNode) re.getDestination()).getIdentifierTemplate(); + ResourcePath dstRes = ((ResourceNode) re.getDestination()).getResource(); String resName = toTypeName(dstRes.getResourceName()); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { depends.add(dstRes); @@ -94,7 +94,7 @@ } for (Edge e : rn.getInEdges()) { DataFlowEdge re = (DataFlowEdge) e; - IdentifierTemplate srcRes = ((ResourceNode) re.getSource()).getIdentifierTemplate(); + ResourcePath srcRes = ((ResourceNode) re.getSource()).getResource(); String resName = toTypeName(srcRes.getResourceName()); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) != PushPullValue.PUSH) { depends.add(srcRes); @@ -103,16 +103,16 @@ } else { if (rn.getIndegree() > 1) { // Declare a field to cache the state of the source resource in the type of the destination resource. - IdentifierTemplate cacheResId = ((ResourceNode) re.getSource()).getIdentifierTemplate(); + ResourcePath cacheResId = ((ResourceNode) re.getSource()).getResource(); type.addField(new FieldDeclaration(cacheResId.getResourceStateType(), cacheResId.getResourceName(), getInitializer(cacheResId))); } } } - Set refs = new HashSet<>(); - for (ChannelGenerator cg : model.getChannelGenerators()) { - DataTransferChannelGenerator c = (DataTransferChannelGenerator) cg; - if (c.getInputIdentifierTemplates().contains(rn.getIdentifierTemplate())) { - for (IdentifierTemplate id: c.getReferenceIdentifierTemplates()) { + Set refs = new HashSet<>(); + for (Channel cg : model.getChannels()) { + DataTransferChannel c = (DataTransferChannel) cg; + if (c.getInputResources().contains(rn.getResource())) { + for (ResourcePath id: c.getReferenceResources()) { if (!refs.contains(id) && !depends.contains(id)) { refs.add(id); String refResName = id.getResourceName(); @@ -124,7 +124,7 @@ } if (f) fieldInitializer = fieldInitializer.substring(0, fieldInitializer.length() - 1); fieldInitializer += ")"; - FieldDeclaration field = new FieldDeclaration(new Type(resourceName, resourceName), rn.getIdentifierTemplate().getResourceName()); + FieldDeclaration field = new FieldDeclaration(new Type(resourceName, resourceName), rn.getResource().getResourceName()); mainType.addField(field); // Add a statement to instantiate each object to the main constructor. @@ -133,7 +133,7 @@ mainConstructorBody = new Block(); mainConstructor.setBody(mainConstructorBody); } - mainConstructorBody.addStatement(rn.getIdentifierTemplate().getResourceName() + " = " + fieldInitializer + ";"); + mainConstructorBody.addStatement(rn.getResource().getResourceName() + " = " + fieldInitializer + ";"); // Declare a constructor, fields and update methods in the type of each resource. MethodDeclaration constructor = new MethodDeclaration(resourceName, true); @@ -141,7 +141,7 @@ depends = new HashSet<>(); for (Edge e : rn.getOutEdges()) { DataFlowEdge re = (DataFlowEdge) e; - IdentifierTemplate dstRes = ((ResourceNode) re.getDestination()).getIdentifierTemplate(); + ResourcePath dstRes = ((ResourceNode) re.getDestination()).getResource(); String dstResName = toTypeName(dstRes.getResourceName()); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { // Declare a field to refer to the destination resource of push transfer. @@ -153,7 +153,7 @@ } for (Edge e : rn.getInEdges()) { DataFlowEdge re = (DataFlowEdge) e; - IdentifierTemplate srcRes = ((ResourceNode) re.getSource()).getIdentifierTemplate(); + ResourcePath srcRes = ((ResourceNode) re.getSource()).getResource(); String srcResName = toTypeName(srcRes.getResourceName()); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) != PushPullValue.PUSH) { // Declare a field to refer to the source resource of pull transfer. @@ -165,9 +165,9 @@ // Declare an update method in the type of the destination resource. ArrayList vars = new ArrayList<>(); vars.add(new VariableDeclaration(srcRes.getResourceStateType(), srcRes.getResourceName())); - DataTransferChannelGenerator c = (DataTransferChannelGenerator) re.getChannelGenerator(); - for (IdentifierTemplate ref: c.getReferenceIdentifierTemplates()) { - if (ref != rn.getIdentifierTemplate()) { + DataTransferChannel c = (DataTransferChannel) re.getChannel(); + for (ResourcePath ref: c.getReferenceResources()) { + if (ref != rn.getResource()) { vars.add(new VariableDeclaration(ref.getResourceStateType(), ref.getResourceName())); } } @@ -176,10 +176,10 @@ } // Declare a field to refer to the reference resource. refs = new HashSet<>(); - for (ChannelGenerator cg : model.getChannelGenerators()) { - DataTransferChannelGenerator c = (DataTransferChannelGenerator) cg; - if (c.getInputIdentifierTemplates().contains(rn.getIdentifierTemplate())) { - for (IdentifierTemplate id: c.getReferenceIdentifierTemplates()) { + for (Channel cg : model.getChannels()) { + DataTransferChannel c = (DataTransferChannel) cg; + if (c.getInputResources().contains(rn.getResource())) { + for (ResourcePath id: c.getReferenceResources()) { if (!refs.contains(id) && !depends.contains(id)) { refs.add(id); String refResName = id.getResourceName(); @@ -196,9 +196,9 @@ type.addMethod(constructor); // Declare input methods in resources and the main type. - for (ChannelGenerator cg : model.getIOChannelGenerators()) { - for (ChannelMember cm : ((DataTransferChannelGenerator) cg).getOutputChannelMembers()) { - if (cm.getIdentifierTemplate().equals(rn.getIdentifierTemplate())) { + for (Channel cg : model.getIOChannels()) { + for (ChannelMember cm : ((DataTransferChannel) cg).getOutputChannelMembers()) { + if (cm.getResource().equals(rn.getResource())) { Expression message = cm.getStateTransition().getMessageExpression(); if (message instanceof Term) { ArrayList params = new ArrayList<>(); @@ -242,13 +242,13 @@ // Declare the field to store the state in the type of each resource. if (((StoreAttribute) rn.getAttribute()).isStored()) { - IdentifierTemplate resId = rn.getIdentifierTemplate(); + ResourcePath resId = rn.getResource(); type.addField(new FieldDeclaration(resId.getResourceStateType(), "value", getInitializer(resId))); } // Declare the getter method to obtain the state in the type of each resource. type.addMethod(new MethodDeclaration("getValue", - rn.getIdentifierTemplate().getResourceStateType())); + rn.getResource().getResourceStateType())); // Add compilation unit for each resource. CompilationUnit cu = new CompilationUnit(type); @@ -260,7 +260,7 @@ boolean isCreatedPair = false; for(ResourceNode rn : resources) { if(isCreatedPair) continue; - if(model.getType("Pair").isAncestorOf(rn.getIdentifierTemplate().getResourceStateType())) { + if(model.getType("Pair").isAncestorOf(rn.getResource().getResourceStateType())) { TypeDeclaration type = new TypeDeclaration("Pair"); type.addField(new FieldDeclaration(new Type("Double", "T"), "left")); type.addField(new FieldDeclaration(new Type("Double", "T"), "right")); @@ -295,11 +295,11 @@ for (Node n : graph.getNodes()) { ResourceNode rn = (ResourceNode) n; MethodDeclaration getter = new MethodDeclaration( - "get" + toTypeName(rn.getIdentifierTemplate().getResourceName()), - rn.getIdentifierTemplate().getResourceStateType()); + "get" + toTypeName(rn.getResource().getResourceName()), + rn.getResource().getResourceStateType()); getter.setBody(new Block()); getter.getBody().addStatement( - "return " + rn.getIdentifierTemplate().getResourceName() + ".getValue();"); + "return " + rn.getResource().getResourceName() + ".getValue();"); mainType.addMethod(getter); } @@ -324,7 +324,7 @@ return resName.substring(0, 1).toUpperCase() + resName.substring(1); } - static private String getInitializer(IdentifierTemplate resId) { + static private String getInitializer(ResourcePath resId) { Type stateType = resId.getResourceStateType(); String initializer = null; if (resId.getInitialValue() != null) { @@ -413,8 +413,8 @@ ResourceNode rn = (ResourceNode) n; for (Edge e : rn.getOutEdges()) { DataFlowEdge re = (DataFlowEdge) e; - for (ChannelMember m: re.getChannelGenerator().getReferenceChannelMembers()) { - if (m.getIdentifierTemplate() == curNode.getIdentifierTemplate()) { + for (ChannelMember m: re.getChannel().getReferenceChannelMembers()) { + if (m.getResource() == curNode.getResource()) { topologicalSort(graph, rn, visited, orderedList); } } @@ -432,7 +432,7 @@ static public IResourceStateAccessor pushAccessor = new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { return new Field("value", target.getResourceStateType() != null ? target.getResourceStateType() @@ -445,7 +445,7 @@ } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { return new Parameter(target.getResourceName(), target.getResourceStateType() != null ? target.getResourceStateType() : DataConstraintModel.typeInt); @@ -453,7 +453,7 @@ }; static public IResourceStateAccessor pullAccessor = new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { return new Field("value", target.getResourceStateType() != null ? target.getResourceStateType() @@ -466,7 +466,7 @@ } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { Term getter = new Term(new Symbol("getValue", 1, Symbol.Type.METHOD)); getter.addChild(new Field(target.getResourceName(), target.getResourceStateType())); return getter; diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java index a6f7dd8..ac8ef20 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java @@ -21,13 +21,13 @@ import models.algebra.UnificationFailed; import models.algebra.ValueUndefined; import models.algebra.Variable; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.ResolvingMultipleDefinitionIsFutureWork; @@ -48,24 +48,24 @@ // Generate the body of each update or getter method. try { - Map> referredResources = new HashMap<>(); + Map> referredResources = new HashMap<>(); for (Edge e: graph.getEdges()) { DataFlowEdge d = (DataFlowEdge) e; PushPullAttribute pushPull = (PushPullAttribute) d.getAttribute(); ResourceNode src = (ResourceNode) d.getSource(); ResourceNode dst = (ResourceNode) d.getDestination(); - String srcResourceName = src.getIdentifierTemplate().getResourceName(); - String dstResourceName = dst.getIdentifierTemplate().getResourceName(); + String srcResourceName = src.getResource().getResourceName(); + String dstResourceName = dst.getResource().getResourceName(); TypeDeclaration srcType = typeMap.get(srcResourceName); TypeDeclaration dstType = typeMap.get(dstResourceName); - for (ChannelMember out: d.getChannelGenerator().getOutputChannelMembers()) { - if (out.getIdentifierTemplate() == dst.getIdentifierTemplate()) { + for (ChannelMember out: d.getChannel().getOutputChannelMembers()) { + if (out.getResource() == dst.getResource()) { if (pushPull.getOptions().get(0) == PushPullValue.PUSH && srcType != null) { // for push data transfer MethodDeclaration update = getUpdateMethod(dstType, srcType); if (((StoreAttribute) dst.getAttribute()).isStored()) { // update stored state of dst side resource (when every incoming edge is in push style) - Expression updateExp = d.getChannelGenerator().deriveUpdateExpressionOf(out, JavaCodeGenerator.pushAccessor); + Expression updateExp = d.getChannel().deriveUpdateExpressionOf(out, JavaCodeGenerator.pushAccessor); String[] sideEffects = new String[] {""}; String curState = updateExp.toImplementation(sideEffects); String updateStatement; @@ -89,7 +89,7 @@ if (((StoreAttribute) dst.getAttribute()).isStored()) { // returns the current state stored in a field. if (getter.getBody() == null || getter.getBody().getStatements().size() == 0) { - Type resourceType = dst.getIdentifierTemplate().getResourceStateType(); + Type resourceType = dst.getResource().getResourceStateType(); if (model.isPrimitiveType(resourceType)) { getter.addStatement("return value;"); } else { @@ -111,19 +111,19 @@ // src side (for a chain of update method invocations) for (MethodDeclaration srcUpdate: getUpdateMethods(srcType)) { String refParams = ""; - Set referredSet = referredResources.get(srcUpdate); - for (ChannelMember rc: d.getChannelGenerator().getReferenceChannelMembers()) { + Set referredSet = referredResources.get(srcUpdate); + for (ChannelMember rc: d.getChannel().getReferenceChannelMembers()) { // to get the value of reference member. - IdentifierTemplate ref = rc.getIdentifierTemplate(); + ResourcePath ref = rc.getResource(); if (referredSet == null) { referredSet = new HashSet<>(); referredResources.put(srcUpdate, referredSet); } - if (ref != dst.getIdentifierTemplate()) { + if (ref != dst.getResource()) { String refVarName = ref.getResourceName(); if (!referredSet.contains(ref)) { referredSet.add(ref); - Expression refGetter = JavaCodeGenerator.pullAccessor.getCurrentStateAccessorFor(ref, src.getIdentifierTemplate()); + Expression refGetter = JavaCodeGenerator.pullAccessor.getCurrentStateAccessorFor(ref, src.getResource()); String[] sideEffects = new String[] {""}; String refExp = refGetter.toImplementation(sideEffects); String refTypeName = ref.getResourceStateType().getInterfaceTypeName(); @@ -136,19 +136,19 @@ } for (MethodDeclaration srcInput: getInputMethods(srcType, src, model)) { String refParams = ""; - Set referredSet = referredResources.get(srcInput); - for (ChannelMember rc: d.getChannelGenerator().getReferenceChannelMembers()) { + Set referredSet = referredResources.get(srcInput); + for (ChannelMember rc: d.getChannel().getReferenceChannelMembers()) { // to get the value of reference member. - IdentifierTemplate ref = rc.getIdentifierTemplate(); + ResourcePath ref = rc.getResource(); if (referredSet == null) { referredSet = new HashSet<>(); referredResources.put(srcInput, referredSet); } - if (ref != dst.getIdentifierTemplate()) { + if (ref != dst.getResource()) { String refVarName = ref.getResourceName(); if (!referredSet.contains(ref)) { referredSet.add(ref); - Expression refGetter = JavaCodeGenerator.pullAccessor.getCurrentStateAccessorFor(ref, src.getIdentifierTemplate()); + Expression refGetter = JavaCodeGenerator.pullAccessor.getCurrentStateAccessorFor(ref, src.getResource()); String[] sideEffects = new String[] {""}; String refExp = refGetter.toImplementation(sideEffects); String refTypeName = ref.getResourceStateType().getInterfaceTypeName(); @@ -164,29 +164,29 @@ MethodDeclaration getter = getGetterMethod(dstType); if (getter.getBody() == null || getter.getBody().getStatements().size() == 0) { boolean isContainedPush = false; - HashMap inputIdentifierToStateAccessor = new HashMap<>(); + HashMap inputResourceToStateAccessor = new HashMap<>(); for (Edge eIn: dst.getInEdges()) { DataFlowEdge dIn = (DataFlowEdge) eIn; if (((PushPullAttribute) dIn.getAttribute()).getOptions().get(0) == PushPullValue.PUSH) { isContainedPush = true; - inputIdentifierToStateAccessor.put(((ResourceNode) dIn.getSource()).getIdentifierTemplate(), JavaCodeGenerator.pushAccessor); + inputResourceToStateAccessor.put(((ResourceNode) dIn.getSource()).getResource(), JavaCodeGenerator.pushAccessor); } else { - inputIdentifierToStateAccessor.put(((ResourceNode) dIn.getSource()).getIdentifierTemplate(), JavaCodeGenerator.pullAccessor); + inputResourceToStateAccessor.put(((ResourceNode) dIn.getSource()).getResource(), JavaCodeGenerator.pullAccessor); } } // for reference channel members - for (ChannelMember c: d.getChannelGenerator().getReferenceChannelMembers()) { - inputIdentifierToStateAccessor.put(c.getIdentifierTemplate(), JavaCodeGenerator.pullAccessor); // by pull data transfer + for (ChannelMember c: d.getChannel().getReferenceChannelMembers()) { + inputResourceToStateAccessor.put(c.getResource(), JavaCodeGenerator.pullAccessor); // by pull data transfer } String[] sideEffects = new String[] {""}; // generate a return statement. if (!isContainedPush) { // All incoming edges are in PULL style. - String curState = d.getChannelGenerator().deriveUpdateExpressionOf(out, JavaCodeGenerator.pullAccessor).toImplementation(sideEffects); + String curState = d.getChannel().deriveUpdateExpressionOf(out, JavaCodeGenerator.pullAccessor).toImplementation(sideEffects); getter.addStatement(sideEffects[0] + "return " + curState + ";"); } else { // At least one incoming edge is in PUSH style. - String curState = d.getChannelGenerator().deriveUpdateExpressionOf(out, JavaCodeGenerator.pullAccessor, inputIdentifierToStateAccessor).toImplementation(sideEffects); + String curState = d.getChannel().deriveUpdateExpressionOf(out, JavaCodeGenerator.pullAccessor, inputResourceToStateAccessor).toImplementation(sideEffects); getter.addStatement(sideEffects[0] + "return " + curState + ";"); } } @@ -199,13 +199,13 @@ TypeDeclaration mainType = typeMap.get(mainTypeName); for (Node n: graph.getNodes()) { ResourceNode resource = (ResourceNode) n; - String resourceName = resource.getIdentifierTemplate().getResourceName(); + String resourceName = resource.getResource().getResourceName(); TypeDeclaration type = typeMap.get(resourceName); if (type != null) { // getter method MethodDeclaration getter = getGetterMethod(type); if (getter.getBody() == null || getter.getBody().getStatements().size() == 0) { - Type resourceType = resource.getIdentifierTemplate().getResourceStateType(); + Type resourceType = resource.getResource().getResourceStateType(); if (model.isPrimitiveType(resourceType)) { getter.addStatement("return value;"); } else { @@ -224,8 +224,8 @@ } } // methods for input events - Map> ioChannelsAndMembers = getIOChannelsAndMembers(resource, model); - for (Map.Entry> entry: ioChannelsAndMembers.entrySet()) { + Map> ioChannelsAndMembers = getIOChannelsAndMembers(resource, model); + for (Map.Entry> entry: ioChannelsAndMembers.entrySet()) { Set outs = entry.getValue(); for (ChannelMember out: outs) { MethodDeclaration input = getInputMethod(type, out); @@ -293,13 +293,13 @@ return null; } - private static Map> getIOChannelsAndMembers(ResourceNode resource, DataTransferModel model) { - Map> ioChannelsAndMembers = new HashMap<>(); - for (ChannelGenerator c: model.getIOChannelGenerators()) { - DataTransferChannelGenerator ch = (DataTransferChannelGenerator) c; + private static Map> getIOChannelsAndMembers(ResourceNode resource, DataTransferModel model) { + Map> ioChannelsAndMembers = new HashMap<>(); + for (Channel c: model.getIOChannels()) { + DataTransferChannel ch = (DataTransferChannel) c; // I/O channel for (ChannelMember out: ch.getOutputChannelMembers()) { - if (out.getIdentifierTemplate().equals(resource.getIdentifierTemplate())) { + if (out.getResource().equals(resource.getResource())) { if (out.getStateTransition().getMessageExpression() instanceof Term || out.getStateTransition().getMessageExpression() instanceof Variable) { Set channelMembers = ioChannelsAndMembers.get(ch); if (channelMembers == null) { @@ -316,11 +316,11 @@ private static List getInputMethods(TypeDeclaration type, ResourceNode resource, DataTransferModel model) { List inputs = new ArrayList<>(); - for (ChannelGenerator c: model.getIOChannelGenerators()) { - DataTransferChannelGenerator channel = (DataTransferChannelGenerator) c; + for (Channel c: model.getIOChannels()) { + DataTransferChannel channel = (DataTransferChannel) c; // I/O channel for (ChannelMember out: channel.getOutputChannelMembers()) { - if (out.getIdentifierTemplate().equals(resource.getIdentifierTemplate())) { + if (out.getResource().equals(resource.getResource())) { MethodDeclaration input = getInputMethod(type, out); inputs.add(input); } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java index dcbd48f..dbd0b45 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyCodeGenerator.java @@ -21,13 +21,13 @@ import models.algebra.Term; import models.algebra.Type; import models.algebra.Variable; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.DataFlowEdge; @@ -66,13 +66,13 @@ for (Node n : resources) { ResourceNode rn = (ResourceNode) n; - String resourceName = rn.getIdentifierTemplate().getResourceName().substring(0, 1).toUpperCase() - + rn.getIdentifierTemplate().getResourceName().substring(1); + String resourceName = rn.getResource().getResourceName().substring(0, 1).toUpperCase() + + rn.getResource().getResourceName().substring(1); // Declare the field to refer each resource in the main type. TypeDeclaration type = new TypeDeclaration(resourceName); type.addAnnotation(new Annotation("Component")); - type.addAnnotation(new Annotation("Path", "\"/" + rn.getIdentifierTemplate().getResourceName() + "\"")); + type.addAnnotation(new Annotation("Path", "\"/" + rn.getResource().getResourceName() + "\"")); // Declare a client field and update methods from other resources. boolean bDeclareClientField = false; @@ -86,7 +86,7 @@ } for (Edge e : rn.getInEdges()) { DataFlowEdge re = (DataFlowEdge) e; - IdentifierTemplate srcRes = ((ResourceNode) re.getSource()).getIdentifierTemplate(); + ResourcePath srcRes = ((ResourceNode) re.getSource()).getResource(); String srcResName = srcRes.getResourceName().substring(0, 1).toUpperCase() + srcRes.getResourceName().substring(1); if (((PushPullAttribute) re.getAttribute()).getOptions().get(0) != PushPullValue.PUSH) { if (!bDeclareClientField) { @@ -102,16 +102,16 @@ VariableDeclaration param = new VariableDeclaration(srcType, srcName); param.addAnnotation(new Annotation("FormParam", "\"" + srcName + "\"")); vars.add(param); - for (IdentifierTemplate refRes: re.getChannelGenerator().getReferenceIdentifierTemplates()) { - if (refRes != rn.getIdentifierTemplate()) { + for (ResourcePath refRes: re.getChannel().getReferenceResources()) { + if (refRes != rn.getResource()) { param = new VariableDeclaration(refRes.getResourceStateType(), refRes.getResourceName()); param.addAnnotation(new Annotation("FormParam", "\"" + refRes.getResourceName() + "\"")); vars.add(param); } } MethodDeclaration update = new MethodDeclaration("update" + srcResName, false, typeVoid, vars); - for (ChannelMember cm: re.getChannelGenerator().getOutputChannelMembers()) { - if (cm.getIdentifierTemplate() == rn.getIdentifierTemplate()) { + for (ChannelMember cm: re.getChannel().getOutputChannelMembers()) { + if (cm.getResource() == rn.getResource()) { if (cm.getStateTransition().isRightUnary()) { update.addAnnotation(new Annotation("PUT")); } else { @@ -123,7 +123,7 @@ // For each source resource, a child resource is defined in the destination resource so that its state can be updated separately. update.addAnnotation(new Annotation("Path", "\"/" + srcName + "\"")); // Declare a field to cash the state of the source resource in the type of the destination resource. - IdentifierTemplate cashResId = ((ResourceNode) re.getSource()).getIdentifierTemplate(); + ResourcePath cashResId = ((ResourceNode) re.getSource()).getResource(); type.addField(new FieldDeclaration(cashResId.getResourceStateType(), srcName, getInitializer(cashResId))); } type.addMethod(update); @@ -149,9 +149,9 @@ // } // Declare input methods in resources. - for (ChannelGenerator cg : model.getIOChannelGenerators()) { - for (ChannelMember cm : ((DataTransferChannelGenerator) cg).getOutputChannelMembers()) { - if (cm.getIdentifierTemplate().equals(rn.getIdentifierTemplate())) { + for (Channel cg : model.getIOChannels()) { + for (ChannelMember cm : ((DataTransferChannel) cg).getOutputChannelMembers()) { + if (cm.getResource().equals(rn.getResource())) { Expression message = cm.getStateTransition().getMessageExpression(); if (message.getClass() == Term.class) { ArrayList params = new ArrayList<>(); @@ -187,12 +187,12 @@ // Declare the field to store the state in the type of each resource. if (((StoreAttribute) rn.getAttribute()).isStored()) { - IdentifierTemplate resId = rn.getIdentifierTemplate(); + ResourcePath resId = rn.getResource(); type.addField(new FieldDeclaration(resId.getResourceStateType(), "value", getInitializer(resId))); } // Declare the getter method to obtain the state in the type of each resource. - MethodDeclaration getter = new MethodDeclaration("getValue", rn.getIdentifierTemplate().getResourceStateType()); + MethodDeclaration getter = new MethodDeclaration("getValue", rn.getResource().getResourceStateType()); getter.addAnnotation(new Annotation("Produces", "MediaType.APPLICATION_JSON")); getter.addAnnotation(new Annotation("GET")); type.addMethod(getter); @@ -214,7 +214,7 @@ for(Node n : resources) { ResourceNode rn = (ResourceNode) n; if(isCreatedPair) continue; - if(model.getType("Pair").isAncestorOf(rn.getIdentifierTemplate().getResourceStateType())) { + if(model.getType("Pair").isAncestorOf(rn.getResource().getResourceStateType())) { TypeDeclaration type = new TypeDeclaration("Pair"); type.addField(new FieldDeclaration(new Type("Double", "T"), "left")); type.addField(new FieldDeclaration(new Type("Double", "T"), "right")); @@ -254,7 +254,7 @@ return codes; } - private static String getInitializer(IdentifierTemplate resId) { + private static String getInitializer(ResourcePath resId) { Type stateType = resId.getResourceStateType(); String initializer = null; if (resId.getInitialValue() != null) { @@ -316,7 +316,7 @@ static public IResourceStateAccessor pushAccessor = new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { return new Field("value", target.getResourceStateType() != null ? target.getResourceStateType() @@ -326,7 +326,7 @@ } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { return new Parameter(target.getResourceName(), target.getResourceStateType() != null ? target.getResourceStateType() : DataConstraintModel.typeInt); @@ -334,7 +334,7 @@ }; static public IResourceStateAccessor pullAccessor = new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { return new Field("value", target.getResourceStateType() != null ? target.getResourceStateType() @@ -347,7 +347,7 @@ } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { return new Parameter(target.getResourceName(), target.getResourceStateType() != null ? target.getResourceStateType() : DataConstraintModel.typeInt); diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java index 6fe0efd..cdaf898 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java @@ -24,12 +24,12 @@ import models.algebra.UnificationFailed; import models.algebra.ValueUndefined; import models.algebra.Variable; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.PushPullAttribute; import models.dataFlowModel.PushPullValue; import models.dataFlowModel.ResolvingMultipleDefinitionIsFutureWork; @@ -37,7 +37,7 @@ import models.dataFlowModel.DataFlowGraph; import models.dataFlowModel.ResourceNode; import models.dataFlowModel.StoreAttribute; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; public class JerseyMethodBodyGenerator { private static String baseURL = "http://localhost:8080"; @@ -54,37 +54,37 @@ // Generate the body of each update or getter method. try { Set chainedCalls = new HashSet<>(); - Map> referredResources = new HashMap<>(); + Map> referredResources = new HashMap<>(); for (Edge e: graph.getEdges()) { DataFlowEdge d = (DataFlowEdge) e; PushPullAttribute pushPull = (PushPullAttribute) d.getAttribute(); ResourceNode src = (ResourceNode) d.getSource(); ResourceNode dst = (ResourceNode) d.getDestination(); - String srcResourceName = src.getIdentifierTemplate().getResourceName(); - String dstResourceName = dst.getIdentifierTemplate().getResourceName(); + String srcResourceName = src.getResource().getResourceName(); + String dstResourceName = dst.getResource().getResourceName(); TypeDeclaration srcType = typeMap.get(srcResourceName); TypeDeclaration dstType = typeMap.get(dstResourceName); - for (ChannelMember out: d.getChannelGenerator().getOutputChannelMembers()) { - if (out.getIdentifierTemplate() == dst.getIdentifierTemplate()) { + for (ChannelMember out: d.getChannel().getOutputChannelMembers()) { + if (out.getResource() == dst.getResource()) { if (pushPull.getOptions().get(0) == PushPullValue.PUSH && srcType != null) { // for push data transfer MethodDeclaration update = getUpdateMethod(dstType, srcType); if (((StoreAttribute) dst.getAttribute()).isStored()) { // update stored state of dst side resource (when every incoming edge is in push style) Expression updateExp = null; - if (d.getChannelGenerator().getReferenceChannelMembers().size() == 0) { - updateExp = d.getChannelGenerator().deriveUpdateExpressionOf(out, JerseyCodeGenerator.pushAccessor); + if (d.getChannel().getReferenceChannelMembers().size() == 0) { + updateExp = d.getChannel().deriveUpdateExpressionOf(out, JerseyCodeGenerator.pushAccessor); } else { // if there exists one or more reference channel member. - HashMap inputIdentifierToStateAccessor = new HashMap<>(); + HashMap inputResourceToStateAccessor = new HashMap<>(); for (Edge eIn: dst.getInEdges()) { DataFlowEdge dIn = (DataFlowEdge) eIn; - inputIdentifierToStateAccessor.put(((ResourceNode) dIn.getSource()).getIdentifierTemplate(), JerseyCodeGenerator.pushAccessor); + inputResourceToStateAccessor.put(((ResourceNode) dIn.getSource()).getResource(), JerseyCodeGenerator.pushAccessor); } - for (ChannelMember c: d.getChannelGenerator().getReferenceChannelMembers()) { - inputIdentifierToStateAccessor.put(c.getIdentifierTemplate(), JerseyCodeGenerator.pullAccessor); + for (ChannelMember c: d.getChannel().getReferenceChannelMembers()) { + inputResourceToStateAccessor.put(c.getResource(), JerseyCodeGenerator.pullAccessor); } - updateExp = d.getChannelGenerator().deriveUpdateExpressionOf(out, JerseyCodeGenerator.pushAccessor, inputIdentifierToStateAccessor); + updateExp = d.getChannel().deriveUpdateExpressionOf(out, JerseyCodeGenerator.pushAccessor, inputResourceToStateAccessor); } String[] sideEffects = new String[] {""}; String curState = updateExp.toImplementation(sideEffects); @@ -187,16 +187,16 @@ for (MethodDeclaration srcUpdate: getUpdateMethods(srcType)) { if (srcUpdate != null) { List>> params = new ArrayList<>(); - Set referredSet = referredResources.get(srcUpdate); - if (d.getChannelGenerator().getReferenceChannelMembers().size() > 0) { - for (ChannelMember rc: d.getChannelGenerator().getReferenceChannelMembers()) { + Set referredSet = referredResources.get(srcUpdate); + if (d.getChannel().getReferenceChannelMembers().size() > 0) { + for (ChannelMember rc: d.getChannel().getReferenceChannelMembers()) { // For each reference channel member, get the current state of the reference side resource by pull data transfer. - IdentifierTemplate ref = rc.getIdentifierTemplate(); + ResourcePath ref = rc.getResource(); if (referredSet == null) { referredSet = new HashSet<>(); referredResources.put(srcUpdate, referredSet); } - if (ref != dst.getIdentifierTemplate()) { + if (ref != dst.getResource()) { String refResourceName = ref.getResourceName(); Type refResourceType = ref.getResourceStateType(); if (!referredSet.contains(ref)) { @@ -215,14 +215,14 @@ if (!chainedCalls.contains(srcUpdate)) { // The first call to an update method in this method // Value of the source side (input side) resource. - params.add(0, new AbstractMap.SimpleEntry<>(src.getIdentifierTemplate().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); + params.add(0, new AbstractMap.SimpleEntry<>(src.getResource().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); srcUpdate.addStatement(getHttpMethodParamsStatement(srcType.getTypeName(), params, true)); srcUpdate.addStatement("String result = " + getHttpMethodCallStatement(baseURL, dstResourceName, srcResName, httpMethod)); chainedCalls.add(srcUpdate); } else { // After the second time of call to update methods in this method // Value of the source side (input side) resource. - params.add(0, new AbstractMap.SimpleEntry<>(src.getIdentifierTemplate().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); + params.add(0, new AbstractMap.SimpleEntry<>(src.getResource().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); srcUpdate.addStatement(getHttpMethodParamsStatement(srcType.getTypeName(), params, false)); srcUpdate.addStatement("result = " + getHttpMethodCallStatement(baseURL, dstResourceName, srcResName, httpMethod)); } @@ -231,15 +231,15 @@ } for (MethodDeclaration srcInput: getInputMethods(srcType, src, model)) { List>> params = new ArrayList<>(); - Set referredSet = referredResources.get(srcInput); - for (ChannelMember rc: d.getChannelGenerator().getReferenceChannelMembers()) { + Set referredSet = referredResources.get(srcInput); + for (ChannelMember rc: d.getChannel().getReferenceChannelMembers()) { // For each reference channel member, get the current state of the reference side resource by pull data transfer. - IdentifierTemplate ref = rc.getIdentifierTemplate(); + ResourcePath ref = rc.getResource(); if (referredSet == null) { referredSet = new HashSet<>(); referredResources.put(srcInput, referredSet); } - if (ref != dst.getIdentifierTemplate()) { + if (ref != dst.getResource()) { String refResourceName = ref.getResourceName(); Type refResourceType = ref.getResourceStateType(); if (!referredSet.contains(ref)) { @@ -257,14 +257,14 @@ if (!chainedCalls.contains(srcInput)) { // First call to an update method in this method // Value of the source side (input side) resource. - params.add(0, new AbstractMap.SimpleEntry<>(src.getIdentifierTemplate().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); + params.add(0, new AbstractMap.SimpleEntry<>(src.getResource().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); srcInput.addStatement(getHttpMethodParamsStatement(srcType.getTypeName(), params, true)); srcInput.addStatement("String result = " + getHttpMethodCallStatement(baseURL, dstResourceName, srcResName, httpMethod)); chainedCalls.add(srcInput); } else { // After the second time of call to update methods in this method // Value of the source side (input side) resource. - params.add(0, new AbstractMap.SimpleEntry<>(src.getIdentifierTemplate().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); + params.add(0, new AbstractMap.SimpleEntry<>(src.getResource().getResourceStateType(), new AbstractMap.SimpleEntry<>(srcResourceName, "this.value"))); srcInput.addStatement(getHttpMethodParamsStatement(srcType.getTypeName(), params, false)); srcInput.addStatement("result = " + getHttpMethodCallStatement(baseURL, dstResourceName, srcResName, httpMethod)); } @@ -276,17 +276,17 @@ if (getter.getBody() == null || getter.getBody().getStatements().size() == 0) { // generate a return statement. String[] sideEffects = new String[] {""}; - String curState = d.getChannelGenerator().deriveUpdateExpressionOf(out, JerseyCodeGenerator.pullAccessor).toImplementation(sideEffects); // no pull data transfer is included. + String curState = d.getChannel().deriveUpdateExpressionOf(out, JerseyCodeGenerator.pullAccessor).toImplementation(sideEffects); // no pull data transfer is included. getter.addStatement(sideEffects[0] + "return " + curState + ";"); // For each reference channel member, get the current state of the reference side resource by pull data transfer. - for (ChannelMember c: d.getChannelGenerator().getReferenceChannelMembers()) { - String refResourceName = c.getIdentifierTemplate().getResourceName(); - Type refResourceType = c.getIdentifierTemplate().getResourceStateType(); + for (ChannelMember c: d.getChannel().getReferenceChannelMembers()) { + String refResourceName = c.getResource().getResourceName(); + Type refResourceType = c.getResource().getResourceStateType(); generatePullDataTransfer(getter, refResourceName, refResourceType); } } // get src side resource state by pull data transfer. - Type srcResourceType = src.getIdentifierTemplate().getResourceStateType(); + Type srcResourceType = src.getResource().getResourceStateType(); generatePullDataTransfer(getter, srcResourceName, srcResourceType); } } @@ -295,7 +295,7 @@ // for source nodes for (Node n: graph.getNodes()) { ResourceNode resource = (ResourceNode) n; - String resourceName = resource.getIdentifierTemplate().getResourceName(); + String resourceName = resource.getResource().getResourceName(); TypeDeclaration type = typeMap.get(resourceName); if (type != null) { // getter method @@ -304,8 +304,8 @@ getter.addStatement("return value;"); } // methods for input events - Map> ioChannelsAndMembers = getIOChannelsAndMembers(resource, model); - for (Map.Entry> entry: ioChannelsAndMembers.entrySet()) { + Map> ioChannelsAndMembers = getIOChannelsAndMembers(resource, model); + for (Map.Entry> entry: ioChannelsAndMembers.entrySet()) { Set outs = entry.getValue(); for (ChannelMember out: outs) { MethodDeclaration input = getInputMethod(type, out); @@ -540,13 +540,13 @@ return null; } - private static Map> getIOChannelsAndMembers(ResourceNode resource, DataTransferModel model) { - Map> ioChannelsAndMembers = new HashMap<>(); - for (ChannelGenerator c: model.getIOChannelGenerators()) { - DataTransferChannelGenerator ch = (DataTransferChannelGenerator) c; + private static Map> getIOChannelsAndMembers(ResourceNode resource, DataTransferModel model) { + Map> ioChannelsAndMembers = new HashMap<>(); + for (Channel c: model.getIOChannels()) { + DataTransferChannel ch = (DataTransferChannel) c; // I/O channel for (ChannelMember out: ch.getOutputChannelMembers()) { - if (out.getIdentifierTemplate().equals(resource.getIdentifierTemplate())) { + if (out.getResource().equals(resource.getResource())) { if (out.getStateTransition().getMessageExpression() instanceof Term || out.getStateTransition().getMessageExpression() instanceof Variable) { Set channelMembers = ioChannelsAndMembers.get(ch); if (channelMembers == null) { @@ -563,11 +563,11 @@ private static List getInputMethods(TypeDeclaration type, ResourceNode resource, DataTransferModel model) { List inputs = new ArrayList<>(); - for (ChannelGenerator c: model.getIOChannelGenerators()) { - DataTransferChannelGenerator channel = (DataTransferChannelGenerator) c; + for (Channel c: model.getIOChannels()) { + DataTransferChannel channel = (DataTransferChannel) c; // I/O channel for (ChannelMember out: channel.getOutputChannelMembers()) { - if (out.getIdentifierTemplate().equals(resource.getIdentifierTemplate())) { + if (out.getResource().equals(resource.getResource())) { MethodDeclaration input = getInputMethod(type, out); inputs.add(input); } diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Position.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Position.java index a11aa71..0a7c10b 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Position.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Position.java @@ -3,8 +3,6 @@ import java.util.ArrayList; import java.util.List; -import models.dataConstraintModel.IdentifierTemplate; - public class Position implements Cloneable { private ArrayList orders = new ArrayList(); diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java index be1d510..2913494 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ControlFlowGraph.java @@ -8,11 +8,11 @@ import models.algebra.Expression; import models.algebra.Term; import models.algebra.Variable; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataFlowModel.DataFlowEdge; import models.dataFlowModel.DataFlowGraph; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; import models.dataFlowModel.DataTransferModel; import models.dataFlowModel.IFlowGraph; import models.dataFlowModel.PushPullAttribute; @@ -40,8 +40,8 @@ pullCallGraph.addEdge(dstNode, srcNode, PushPullValue.PULL); } } - for (ChannelGenerator ch: model.getIOChannelGenerators()) { - DataTransferChannelGenerator cio = (DataTransferChannelGenerator) ch; + for (Channel ch: model.getIOChannels()) { + DataTransferChannel cio = (DataTransferChannel) ch; EntryPointObjectNode srcNode = new EntryPointObjectNode(cio); for (ChannelMember cm: cio.getChannelMembers()) { if (srcNode.getName() == null) { @@ -52,7 +52,7 @@ srcNode.setName(((Variable) exp).getName()); } } - ResourceNode dstResNode = dataFlowGraph.getResouceNode(cm.getIdentifierTemplate()); + ResourceNode dstResNode = dataFlowGraph.getResouceNode(cm.getResource()); StatefulObjectNode dstNode = pushCallGraph.getStatefulObjectNode(dstResNode); if (dstNode == null) { pushCallGraph.addNode(dstResNode); diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/EntryPointObjectNode.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/EntryPointObjectNode.java index f200312..8100090 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/EntryPointObjectNode.java +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/EntryPointObjectNode.java @@ -1,27 +1,27 @@ package models.controlFlowModel; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; /************************************************************* * An object is mapped to I/O channel. * ToDo: Fecthing name from in Data-Flow-Graph */ public class EntryPointObjectNode extends ObjectNode { - DataTransferChannelGenerator ioChannelGenerator = null; + DataTransferChannel ioChannel = null; /************************************************************* * [ *constructor ] /************************************************************* * */ - public EntryPointObjectNode(DataTransferChannelGenerator ioChannelGenerator) { + public EntryPointObjectNode(DataTransferChannel ioChannel) { super(null); - this.ioChannelGenerator = ioChannelGenerator; + this.ioChannel = ioChannel; } - public EntryPointObjectNode(String name, DataTransferChannelGenerator ioChannelGenerator) { + public EntryPointObjectNode(String name, DataTransferChannel ioChannel) { super(name); - this.ioChannelGenerator = ioChannelGenerator; + this.ioChannel = ioChannel; } /************************************************************* @@ -29,12 +29,12 @@ /************************************************************* * */ - public DataTransferChannelGenerator getIoChannelGenerator() { - return ioChannelGenerator; + public DataTransferChannel getIOChannel() { + return ioChannel; } - public void setIoChannelGenerator(DataTransferChannelGenerator ioChannelGenerator) { - this.ioChannelGenerator = ioChannelGenerator; + public void setIOChannel(DataTransferChannel ioChannel) { + this.ioChannel = ioChannel; } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ObjectNodeAttribute.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ObjectNodeAttribute.java index da80d92..5ac52e2 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ObjectNodeAttribute.java +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/ObjectNodeAttribute.java @@ -106,7 +106,7 @@ @Override public String toString() { return objectNode instanceof StatefulObjectNode - ? ((StatefulObjectNode) objectNode).getResource().getIdentifierTemplate().getResourceName() + ? ((StatefulObjectNode) objectNode).getResource().getResource().getResourceName() : objectNode.getName(); } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/StatefulObjectNode.java b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/StatefulObjectNode.java index 184774d..b627259 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/StatefulObjectNode.java +++ b/AlgebraicDataflowArchitectureModel/src/models/controlFlowModel/StatefulObjectNode.java @@ -6,7 +6,7 @@ private ResourceNode resource; public StatefulObjectNode(ResourceNode resource) { - super(resource.getIdentifierTemplate().getResourceName()); + super(resource.getResource().getResourceName()); this.resource = resource; } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Channel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Channel.java new file mode 100644 index 0000000..8bf74da --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Channel.java @@ -0,0 +1,96 @@ +package models.dataConstraintModel; + +import java.util.HashSet; +import java.util.Set; + +import models.algebra.Variable; + +public class Channel { + protected String channelName; + protected Set selectors = null; + protected Set channelMembers = null; + protected String sourceText = null; + + public Channel(String channelName) { + this.channelName = channelName; + selectors = new HashSet<>(); + channelMembers = new HashSet<>(); + } + + public Channel(String channelName, Set variables) { + this.channelName = channelName; + selectors = new HashSet<>(); + for (Variable var: variables) { + selectors.add(new Selector(var)); + } + channelMembers = new HashSet<>(); + } + + public String getChannelName() { + return channelName; + } + + public Set getChannelSelectors() { + return selectors; + } + + public void setChannelSelectors(Set selectors) { + this.selectors = selectors; + } + + public void addSelector(Selector selector) { + selectors.add(selector); + } + + public Set getChannelMembers() { + return channelMembers; + } + + public void setChannelMembers(Set channelMembers) { + this.channelMembers = channelMembers; + for (ChannelMember channelMember: channelMembers) { + for (Selector selector: channelMember.getSelectors()) { + addSelector(selector); + } + } + } + + public void addChannelMember(ChannelMember channelMember) { + channelMembers.add(channelMember); + for (Selector selector: channelMember.getSelectors()) { + addSelector(selector); + } + } + + public void removeChannelMember(ResourcePath id) { + for (ChannelMember cm: channelMembers) { + if (cm.getResource() == id) { + channelMembers.remove(cm); + break; + } + } + } + + public Set getResources() { + Set resources = new HashSet<>(); + for (ChannelMember member: channelMembers) { + resources.add(member.getResource()); + } + return resources; + } + + public String toString() { + return channelName; + } + + public void setSourceText(String sourceText) { + this.sourceText = sourceText; + } + + public String getSourceText() { + if (sourceText == null) { + return toString(); + } + return sourceText; + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelGenerator.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelGenerator.java deleted file mode 100644 index 8a9bd1f..0000000 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelGenerator.java +++ /dev/null @@ -1,107 +0,0 @@ -package models.dataConstraintModel; - -import java.util.HashSet; -import java.util.Set; - -public class ChannelGenerator { - protected String channelName; - protected Set groupSelectors = null; - protected Set channelSelectors = null; - protected Set channelMembers = null; - protected String sourceText = null; - - public ChannelGenerator(String channelName) { - this.channelName = channelName; - groupSelectors = new HashSet<>(); - channelSelectors = new HashSet<>(); - channelMembers = new HashSet<>(); - } - - public String getChannelName() { - return channelName; - } - - public Set getGroupSelectors() { - return groupSelectors; - } - - public void setGroupSelectors(Set groupSelectors) { - this.groupSelectors = groupSelectors; - } - - public void addGroupSelector(GroupSelector groupSelector) { - groupSelectors.add(groupSelector); - } - - public Set getChannelSelectors() { - return channelSelectors; - } - - public void setChannelSelectors(Set channelSelectors) { - this.channelSelectors = channelSelectors; - } - - public void addChannelSelector(ChannelSelector channelSelector) { - channelSelectors.add(channelSelector); - } - - public void addSelector(Selector selector) { - if (selector instanceof GroupSelector) { - groupSelectors.add((GroupSelector)selector); - } else if (selector instanceof ChannelSelector) { - channelSelectors.add((ChannelSelector)selector); - } - } - - public Set getChannelMembers() { - return channelMembers; - } - - public void setChannelMembers(Set channelMembers) { - this.channelMembers = channelMembers; - for (ChannelMember channelMember: channelMembers) { - for (Selector selector: channelMember.getSelectors()) { - addSelector(selector); - } - } - } - - public void addChannelMember(ChannelMember channelMember) { - channelMembers.add(channelMember); - for (Selector selector: channelMember.getSelectors()) { - addSelector(selector); - } - } - - public void removeChannelMember(IdentifierTemplate id) { - for (ChannelMember cm: channelMembers) { - if (cm.getIdentifierTemplate() == id) { - channelMembers.remove(cm); - break; - } - } - } - - public Set getIdentifierTemplates() { - Set identifierTemplates = new HashSet<>(); - for (ChannelMember member: channelMembers) { - identifierTemplates.add(member.getIdentifierTemplate()); - } - return identifierTemplates; - } - - public String toString() { - return channelName; - } - - public void setSourceText(String sourceText) { - this.sourceText = sourceText; - } - - public String getSourceText() { - if (sourceText == null) { - return toString(); - } - return sourceText; - } -} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java index 8c2f210..190a49f 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelMember.java @@ -4,22 +4,22 @@ import java.util.List; public class ChannelMember { - private IdentifierTemplate identifierTemplate = null; + private ResourcePath resourcePath = null; private List selectors = null; private StateTransition stateTransition = null; - public ChannelMember(IdentifierTemplate identifierTemplate) { - this.identifierTemplate = identifierTemplate; + public ChannelMember(ResourcePath resourcePath) { + this.resourcePath = resourcePath; selectors = new ArrayList<>(); stateTransition = new StateTransition(); } - public IdentifierTemplate getIdentifierTemplate() { - return identifierTemplate; + public ResourcePath getResource() { + return resourcePath; } - public void setIdentifierTemplate(IdentifierTemplate identifierTemplate) { - this.identifierTemplate = identifierTemplate; + public void setResource(ResourcePath resourcePath) { + this.resourcePath = resourcePath; } public List getSelectors() { @@ -46,11 +46,11 @@ @Override public String toString() { if (stateTransition.getNextStateExpression() == null) { - return identifierTemplate.getResourceName() + "(" + return resourcePath.getResourceName() + "(" + stateTransition.getCurStateExpression() + "," + stateTransition.getMessageExpression() + ")"; } - return identifierTemplate.getResourceName() + "(" + return resourcePath.getResourceName() + "(" + stateTransition.getCurStateExpression() + "," + stateTransition.getMessageExpression() + ")" + " == " + stateTransition.getNextStateExpression(); diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelSelector.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelSelector.java deleted file mode 100644 index daa5ec5..0000000 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ChannelSelector.java +++ /dev/null @@ -1,5 +0,0 @@ -package models.dataConstraintModel; - -public class ChannelSelector extends Selector { - -} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index c6fb2ea..35b2aa7 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -8,9 +8,9 @@ import parser.Parser; public class DataConstraintModel { - protected HashMap identifierTemplates = null; - protected HashMap channelGenerators = null; - protected HashMap ioChannelGenerators = null; + protected HashMap resourcePaths = null; + protected HashMap channels = null; + protected HashMap ioChannels = null; protected HashMap types = null; protected HashMap symbols = null; public static final Type typeInt = new Type("Int", "int"); @@ -182,9 +182,9 @@ } public DataConstraintModel() { - identifierTemplates = new HashMap<>(); - channelGenerators = new HashMap<>(); - ioChannelGenerators = new HashMap<>(); + resourcePaths = new HashMap<>(); + channels = new HashMap<>(); + ioChannels = new HashMap<>(); types = new HashMap<>(); addType(typeInt); addType(typeLong); @@ -234,87 +234,87 @@ addSymbol(lookup); } - public Collection getIdentifierTemplates() { - return identifierTemplates.values(); + public Collection getResourcePaths() { + return resourcePaths.values(); } - public IdentifierTemplate getIdentifierTemplate(String resourceName) { - return identifierTemplates.get(resourceName); + public ResourcePath getResourcePath(String resourceName) { + return resourcePaths.get(resourceName); } - public void addIdentifierTemplate(IdentifierTemplate identifierTemplate) { - identifierTemplates.put(identifierTemplate.getResourceName(), identifierTemplate); + public void addResourcePath(ResourcePath resourcePath) { + resourcePaths.put(resourcePath.getResourceName(), resourcePath); } - public void setIdentifierTemplates(HashMap identifierTemplates) { - this.identifierTemplates = identifierTemplates; + public void setResourcePaths(HashMap resourcePaths) { + this.resourcePaths = resourcePaths; } - public void removeIdentifierTemplate(String resourceName) { - IdentifierTemplate id = identifierTemplates.get(resourceName); - identifierTemplates.remove(resourceName); - for (ChannelGenerator ch: channelGenerators.values()) { + public void removeResourcePath(String resourceName) { + ResourcePath id = resourcePaths.get(resourceName); + resourcePaths.remove(resourceName); + for (Channel ch: channels.values()) { ch.removeChannelMember(id); } - for (ChannelGenerator ch: ioChannelGenerators.values()) { + for (Channel ch: ioChannels.values()) { ch.removeChannelMember(id); } } - public Collection getChannelGenerators() { - return channelGenerators.values(); + public Collection getChannels() { + return channels.values(); } - public ChannelGenerator getChannelGenerator(String channelName) { - return channelGenerators.get(channelName); + public Channel getChannel(String channelName) { + return channels.get(channelName); } - public void setChannelGenerators(HashMap channelGenerators) { - this.channelGenerators = channelGenerators; - for (ChannelGenerator g: channelGenerators.values()) { - for (IdentifierTemplate id: g.getIdentifierTemplates()) { - identifierTemplates.put(id.getResourceName(), id); + public void setChannels(HashMap channels) { + this.channels = channels; + for (Channel g: channels.values()) { + for (ResourcePath id: g.getResources()) { + resourcePaths.put(id.getResourceName(), id); } } } - public void addChannelGenerator(ChannelGenerator channelGenerator) { - channelGenerators.put(channelGenerator.getChannelName(), channelGenerator); - for (IdentifierTemplate id: channelGenerator.getIdentifierTemplates()) { - identifierTemplates.put(id.getResourceName(), id); + public void addChannel(Channel channel) { + channels.put(channel.getChannelName(), channel); + for (ResourcePath id: channel.getResources()) { + resourcePaths.put(id.getResourceName(), id); } } - public void removeChannelGenerator(String channelName) { - channelGenerators.remove(channelName); + public void removeChannel(String channelName) { + channels.remove(channelName); } - public Collection getIOChannelGenerators() { - return ioChannelGenerators.values(); + public Collection getIOChannels() { + return ioChannels.values(); } - public ChannelGenerator getIOChannelGenerator(String channelName) { - return ioChannelGenerators.get(channelName); + public Channel getIOChannel(String channelName) { + return ioChannels.get(channelName); } - public void setIOChannelGenerators(HashMap ioChannelGenerators) { - this.ioChannelGenerators = ioChannelGenerators; - for (ChannelGenerator g: ioChannelGenerators.values()) { - for (IdentifierTemplate id: g.getIdentifierTemplates()) { - identifierTemplates.put(id.getResourceName(), id); + public void setIOChannels(HashMap ioChannels) { + this.ioChannels = ioChannels; + for (Channel g: ioChannels.values()) { + for (ResourcePath id: g.getResources()) { + resourcePaths.put(id.getResourceName(), id); } } } - public void addIOChannelGenerator(ChannelGenerator ioChannelGenerator) { - ioChannelGenerators.put(ioChannelGenerator.getChannelName(), ioChannelGenerator); - for (IdentifierTemplate id: ioChannelGenerator.getIdentifierTemplates()) { - identifierTemplates.put(id.getResourceName(), id); + public void addIOChannel(Channel ioChannel) { + ioChannels.put(ioChannel.getChannelName(), ioChannel); + for (ResourcePath id: ioChannel.getResources()) { + resourcePaths.put(id.getResourceName(), id); } } - public void removeIOChannelGenerator(String ioChannelName) { - ioChannelGenerators.remove(ioChannelName); + public void removeIOChannel(String ioChannelName) { + ioChannels.remove(ioChannelName); } public void addType(Type type) { @@ -383,11 +383,11 @@ @Override public String toString() { String out = ""; - for (ChannelGenerator channelGenerator: ioChannelGenerators.values()) { - out += channelGenerator.toString(); + for (Channel channel: ioChannels.values()) { + out += channel.toString(); } - for (ChannelGenerator channelGenerator: channelGenerators.values()) { - out += channelGenerator.toString(); + for (Channel channel: channels.values()) { + out += channel.toString(); } return out; } @@ -395,8 +395,8 @@ public String getSourceText() { String out = ""; String init = ""; - for (IdentifierTemplate identifierTemplate: identifierTemplates.values()) { - String initializer = identifierTemplate.getInitText(); + for (ResourcePath resource: resourcePaths.values()) { + String initializer = resource.getInitText(); if (initializer != null) { init += initializer; } @@ -404,11 +404,11 @@ if (init.length() > 0) { out += "init {\n" + init + "}\n"; } - for (ChannelGenerator channelGenerator: ioChannelGenerators.values()) { - out += channelGenerator.getSourceText(); + for (Channel channel: ioChannels.values()) { + out += channel.getSourceText(); } - for (ChannelGenerator channelGenerator: channelGenerators.values()) { - out += channelGenerator.getSourceText(); + for (Channel channel: channels.values()) { + out += channel.getSourceText(); } return out; } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/GroupSelector.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/GroupSelector.java deleted file mode 100644 index 66e5731..0000000 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/GroupSelector.java +++ /dev/null @@ -1,5 +0,0 @@ -package models.dataConstraintModel; - -public class GroupSelector extends Selector { - -} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/IdentifierTemplate.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/IdentifierTemplate.java deleted file mode 100644 index d91355c..0000000 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/IdentifierTemplate.java +++ /dev/null @@ -1,70 +0,0 @@ -package models.dataConstraintModel; - -import models.algebra.Expression; -import models.algebra.Term; -import models.algebra.Type; - -public class IdentifierTemplate { - private String resourceName = null; - private Type resourceStateType = null; - private int numParameters = 0; - private Expression initialValue = null; - protected String initText = null; - - 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; - } - - public int getNumberOfParameters() { - return numParameters; - } - - public Type getResourceStateType() { - return resourceStateType; - } - - public void setResourceStateType(Type resourceStateType) { - this.resourceStateType = resourceStateType; - if (initialValue != null) { - if (initialValue instanceof Term) { - ((Term) initialValue).setType(resourceStateType); - } - } - } - - public Expression getInitialValue() { - return initialValue; - } - - public void setInitialValue(Expression initialValue) { - this.initialValue = initialValue; - } - - public void setInitText(String initText) { - this.initText = initText; - } - - public String getInitText() { - return initText; - } - - public boolean equals(Object another) { - if (!(another instanceof IdentifierTemplate)) return false; - return resourceName.equals(((IdentifierTemplate) another).resourceName); - } - - public int hashCode() { - return resourceName.hashCode(); - } -} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourcePath.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourcePath.java new file mode 100644 index 0000000..e530016 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/ResourcePath.java @@ -0,0 +1,70 @@ +package models.dataConstraintModel; + +import models.algebra.Expression; +import models.algebra.Term; +import models.algebra.Type; + +public class ResourcePath { + private String resourceName = null; + private Type resourceStateType = null; + private int numParameters = 0; + private Expression initialValue = null; + protected String initText = null; + + public ResourcePath(String resourceName, int numParameters) { + this.resourceName = resourceName; + this.numParameters = numParameters; + } + + public ResourcePath(String resourceName, Type resourceStateType, int numParameters) { + this.resourceName = resourceName; + this.resourceStateType = resourceStateType; + this.numParameters = numParameters; + } + + public String getResourceName() { + return resourceName; + } + + public int getNumberOfParameters() { + return numParameters; + } + + public Type getResourceStateType() { + return resourceStateType; + } + + public void setResourceStateType(Type resourceStateType) { + this.resourceStateType = resourceStateType; + if (initialValue != null) { + if (initialValue instanceof Term) { + ((Term) initialValue).setType(resourceStateType); + } + } + } + + public Expression getInitialValue() { + return initialValue; + } + + public void setInitialValue(Expression initialValue) { + this.initialValue = initialValue; + } + + public void setInitText(String initText) { + this.initText = initText; + } + + public String getInitText() { + return initText; + } + + public boolean equals(Object another) { + if (!(another instanceof ResourcePath)) return false; + return resourceName.equals(((ResourcePath) another).resourceName); + } + + public int hashCode() { + return resourceName.hashCode(); + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Selector.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Selector.java index 1794428..a29f8e3 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Selector.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/Selector.java @@ -1,5 +1,19 @@ package models.dataConstraintModel; -abstract public class Selector { +import models.algebra.Variable; +public class Selector { + private Variable variable = null; + + public Selector(Variable variable) { + this.setVariable(variable); + } + + public Variable getVariable() { + return variable; + } + + public void setVariable(Variable variable) { + this.variable = variable; + } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowEdge.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowEdge.java index 3c3b25f..9de9359 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowEdge.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowEdge.java @@ -3,18 +3,18 @@ import models.*; public class DataFlowEdge extends Edge { - protected DataTransferChannelGenerator channelGenerator = null; + protected DataTransferChannel channel = null; - public DataFlowEdge(ResourceNode src, ResourceNode dst, DataTransferChannelGenerator channelGenerator) { + public DataFlowEdge(ResourceNode src, ResourceNode dst, DataTransferChannel channel) { super(src, dst); - this.channelGenerator = channelGenerator; + this.channel = channel; } - public DataTransferChannelGenerator getChannelGenerator() { - return channelGenerator; + public DataTransferChannel getChannel() { + return channel; } public String toString() { - return channelGenerator.getChannelName(); + return channel.getChannelName(); } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java index 97fe74a..2a7660d 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataFlowGraph.java @@ -7,17 +7,17 @@ import models.DirectedGraph; import models.Node; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; public class DataFlowGraph extends DirectedGraph implements IFlowGraph { - protected Map nodeMap = null; + protected Map nodeMap = null; public DataFlowGraph() { super(); nodeMap = new HashMap<>(); } - public void addNode(IdentifierTemplate id) { + public void addNode(ResourcePath id) { if (nodeMap.get(id) == null) { ResourceNode node = new ResourceNode(id); addNode(node); @@ -25,7 +25,7 @@ } } - public void addEdge(IdentifierTemplate in, IdentifierTemplate out, DataTransferChannelGenerator dfChannelGen) { + public void addEdge(ResourcePath in, ResourcePath out, DataTransferChannel dfChannel) { ResourceNode srcNode = nodeMap.get(in); if (srcNode == null) { srcNode = new ResourceNode(in); @@ -38,16 +38,16 @@ addNode(dstNode); nodeMap.put(out, dstNode); } - addEdge(new DataFlowEdge(srcNode, dstNode, dfChannelGen)); + addEdge(new DataFlowEdge(srcNode, dstNode, dfChannel)); } public Collection getResouceNodes(){ return nodeMap.values(); } - public ResourceNode getResouceNode(IdentifierTemplate identifierTemplate) { + public ResourceNode getResouceNode(ResourcePath resourcePath) { // if(nodeMap.get(identifierTemplate) == null) throw new NullPointerException(identifierTemplate.getResourceName() + " was not found."); // Because with this statement, the original JumpGame.model cannot be read. - return nodeMap.get(identifierTemplate); + return nodeMap.get(resourcePath); } @Override diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java new file mode 100644 index 0000000..b3f3bf0 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannel.java @@ -0,0 +1,273 @@ +package models.dataFlowModel; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +import models.algebra.Expression; +import models.algebra.InvalidMessage; +import models.algebra.Parameter; +import models.algebra.ParameterizedIdentifierIsFutureWork; +import models.algebra.Position; +import models.algebra.Term; +import models.algebra.UnificationFailed; +import models.algebra.ValueUndefined; +import models.algebra.Variable; +import models.dataConstraintModel.*; + +public class DataTransferChannel extends Channel { + protected Set inputChannelMembers = null; + protected Set outputChannelMembers = null; + protected Set referenceChannelMembers = null; + + public DataTransferChannel(String channelName) { + super(channelName); + inputChannelMembers = new HashSet<>(); + outputChannelMembers = new HashSet<>(); + referenceChannelMembers = new HashSet<>(); + } + + public Set getInputChannelMembers() { + return inputChannelMembers; + } + + public void setInputChannelMembers(Set inputChannelMembers) { + this.inputChannelMembers = inputChannelMembers; + } + + public void addInputChannelMember(ChannelMember inputChannelMember) { + inputChannelMembers.add(inputChannelMember); + } + + public Set getOutputChannelMembers() { + return outputChannelMembers; + } + + public void setOutputChannelMembers(Set outputChannelMembers) { + this.outputChannelMembers = outputChannelMembers; + } + + public void addOutputChannelMember(ChannelMember outputChannelMember) { + outputChannelMembers.add(outputChannelMember); + } + + public Set getReferenceChannelMembers() { + return referenceChannelMembers; + } + + public void setReferenceChannelMembers(Set referenceChannelMembers) { + this.referenceChannelMembers = referenceChannelMembers; + } + + public void addReferenceChannelMember(ChannelMember referenceChannelMember) { + referenceChannelMembers.add(referenceChannelMember); + } + + public void addChannelMemberAsInput(ChannelMember groupDependentResource) { + addChannelMember(groupDependentResource); + addInputChannelMember(groupDependentResource); + } + + public void addChannelMemberAsOutput(ChannelMember groupDependentResource) { + addChannelMember(groupDependentResource); + addOutputChannelMember(groupDependentResource); + } + + public void addChannelMemberAsReference(ChannelMember groupDependentResource) { + addChannelMember(groupDependentResource); + addReferenceChannelMember(groupDependentResource); + } + + public void removeChannelMember(ResourcePath id) { + for (ChannelMember cm: inputChannelMembers) { + if (cm.getResource() == id) { + inputChannelMembers.remove(cm); + super.removeChannelMember(id); + return; + } + } + for (ChannelMember cm: outputChannelMembers) { + if (cm.getResource() == id) { + outputChannelMembers.remove(cm); + super.removeChannelMember(id); + return; + } + } + for (ChannelMember cm: referenceChannelMembers) { + if (cm.getResource() == id) { + referenceChannelMembers.remove(cm); + super.removeChannelMember(id); + return; + } + } + } + + public Set getInputResources() { + Set inputResources = new HashSet<>(); + for (ChannelMember member: inputChannelMembers) { + inputResources.add(member.getResource()); + } + return inputResources; + } + + public Set getOutputResources() { + Set outputResources = new HashSet<>(); + for (ChannelMember member: outputChannelMembers) { + outputResources.add(member.getResource()); + } + return outputResources; + } + + public Set getReferenceResources() { + Set referenceResources = new HashSet<>(); + for (ChannelMember member: referenceChannelMembers) { + referenceResources.add(member.getResource()); + } + return referenceResources; + } + + /** + * Derive the update expression of the state of the target channel member. + * @param targetMember a channel member whose state is to be updated + * @return the derived update expression + * @throws ParameterizedIdentifierIsFutureWork + * @throws ResolvingMultipleDefinitionIsFutureWork + * @throws InvalidMessage + * @throws UnificationFailed + * @throws ValueUndefined + */ + public Expression deriveUpdateExpressionOf(ChannelMember targetMember) throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { + IResourceStateAccessor defaultStateAccessor = new IResourceStateAccessor() { + HashMap curStateParams = new HashMap<>(); + HashMap nextStateParams = new HashMap<>(); + + @Override + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { + String resource = target.getResourceName(); + Parameter curStateParam = curStateParams.get(resource); + if (curStateParam == null) { + curStateParam = new Parameter("cur" + resource); + curStateParams.put(resource, curStateParam); + } + return curStateParam; + } + + @Override + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { + String resource = target.getResourceName(); + Parameter nextStateParam = nextStateParams.get(resource); + if (nextStateParam == null) { + nextStateParam = new Parameter("next" + resource); + nextStateParams.put(resource, nextStateParam); + } + return nextStateParam; + } + }; + return deriveUpdateExpressionOf(targetMember, defaultStateAccessor); + } + + /** + * Derive the update expression of the state of the target channel member with a given resource state accessor. + * @param targetMember a channel member whose state is to be updated + * @param stateAccessor a resource state accessor + * @return the derived update expression + * @throws ParameterizedIdentifierIsFutureWork + * @throws ResolvingMultipleDefinitionIsFutureWork + * @throws InvalidMessage + * @throws UnificationFailed + * @throws ValueUndefined + */ + public Expression deriveUpdateExpressionOf(ChannelMember targetMember, IResourceStateAccessor stateAccessor) + throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { + return deriveUpdateExpressionOf(targetMember, stateAccessor, null); + } + + public Expression deriveUpdateExpressionOf(ChannelMember targetMember, IResourceStateAccessor stateAccessor, HashMap inputResourceToStateAccessor) + throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { + if (!getOutputChannelMembers().contains(targetMember)) return null; + HashSet messageConstraints = new HashSet<>(); + + // Calculate message constraints from input state transitions + for (ChannelMember inputMember: getInputChannelMembers()) { + ResourcePath inputResource = inputMember.getResource(); + if (inputResource.getNumberOfParameters() > 0) { + throw new ParameterizedIdentifierIsFutureWork(); + } + Expression curInputStateAccessor = null; + Expression nextInputStateAccessor = null; + if (inputResourceToStateAccessor == null) { + curInputStateAccessor = stateAccessor.getCurrentStateAccessorFor(inputResource, targetMember.getResource()); + nextInputStateAccessor = stateAccessor.getNextStateAccessorFor(inputResource, targetMember.getResource()); + } else { + curInputStateAccessor = inputResourceToStateAccessor.get(inputResource).getCurrentStateAccessorFor(inputResource, targetMember.getResource()); + nextInputStateAccessor = inputResourceToStateAccessor.get(inputResource).getNextStateAccessorFor(inputResource, targetMember.getResource()); + } + Expression messageConstraintByInput = inputMember.getStateTransition().deriveMessageConstraintFor(curInputStateAccessor, nextInputStateAccessor); + messageConstraints.add((Term) messageConstraintByInput); + } + + // Calculate message constraints from reference state transitions + for (ChannelMember referenceMember: getReferenceChannelMembers()) { + ResourcePath referenceResource = referenceMember.getResource(); + if (referenceResource.getNumberOfParameters() > 0) { + throw new ParameterizedIdentifierIsFutureWork(); + } + Expression curInputStateAccessor = null; + if (inputResourceToStateAccessor == null) { + curInputStateAccessor = stateAccessor.getCurrentStateAccessorFor(referenceResource, targetMember.getResource()); + } else { + curInputStateAccessor = inputResourceToStateAccessor.get(referenceResource).getCurrentStateAccessorFor(referenceResource, targetMember.getResource()); + } + Expression messageConstraintByReference = referenceMember.getStateTransition().deriveMessageConstraintFor(curInputStateAccessor); + messageConstraints.add((Term) messageConstraintByReference); + } + + // Unify message constraints + Term unifiedMessage = null; + for (Term messageContraint: messageConstraints) { + if (unifiedMessage == null) { + unifiedMessage = messageContraint; + } else { + unifiedMessage = (Term) unifiedMessage.unify(messageContraint); + if (unifiedMessage == null) { + throw new UnificationFailed(); + } + } + } + + // Calculate the next state of target resource from the unified message and the current resource state + ResourcePath targetResource = targetMember.getResource(); + if (targetResource.getNumberOfParameters() > 0) { + throw new ParameterizedIdentifierIsFutureWork(); + } + Expression curOutputStateAccessor = stateAccessor.getCurrentStateAccessorFor(targetResource, targetResource); + if (unifiedMessage == null) { + // for IOChannel + if (targetMember.getStateTransition().getMessageExpression() instanceof Term) { + unifiedMessage = (Term) targetMember.getStateTransition().getMessageExpression(); + } + } + return targetMember.getStateTransition().deriveNextStateExpressionFor(curOutputStateAccessor, unifiedMessage); + } + + @Override + public String toString() { + String channelSource = "channel " + getChannelName() + " {\n"; + for (ChannelMember inputMember: inputChannelMembers) { + channelSource += "\t in " + inputMember + "\n"; + } + for (ChannelMember refMember: referenceChannelMembers) { + channelSource += "\t ref " + refMember + "\n"; + } + for (ChannelMember outputMember: outputChannelMembers) { + channelSource += "\t out " + outputMember + "\n"; + } + channelSource += "}\n"; + return channelSource; + } + + public interface IResourceStateAccessor { + Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from); + Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from); + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannelGenerator.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannelGenerator.java deleted file mode 100644 index 1426ac7..0000000 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferChannelGenerator.java +++ /dev/null @@ -1,273 +0,0 @@ -package models.dataFlowModel; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; - -import models.algebra.Expression; -import models.algebra.InvalidMessage; -import models.algebra.Parameter; -import models.algebra.ParameterizedIdentifierIsFutureWork; -import models.algebra.Position; -import models.algebra.Term; -import models.algebra.UnificationFailed; -import models.algebra.ValueUndefined; -import models.algebra.Variable; -import models.dataConstraintModel.*; - -public class DataTransferChannelGenerator extends ChannelGenerator { - protected Set inputChannelMembers = null; - protected Set outputChannelMembers = null; - protected Set referenceChannelMembers = null; - - public DataTransferChannelGenerator(String channelName) { - super(channelName); - inputChannelMembers = new HashSet<>(); - outputChannelMembers = new HashSet<>(); - referenceChannelMembers = new HashSet<>(); - } - - public Set getInputChannelMembers() { - return inputChannelMembers; - } - - public void setInputChannelMembers(Set inputChannelMembers) { - this.inputChannelMembers = inputChannelMembers; - } - - public void addInputChannelMember(ChannelMember inputChannelMember) { - inputChannelMembers.add(inputChannelMember); - } - - public Set getOutputChannelMembers() { - return outputChannelMembers; - } - - public void setOutputChannelMembers(Set outputChannelMembers) { - this.outputChannelMembers = outputChannelMembers; - } - - public void addOutputChannelMember(ChannelMember outputChannelMember) { - outputChannelMembers.add(outputChannelMember); - } - - public Set getReferenceChannelMembers() { - return referenceChannelMembers; - } - - public void setReferenceChannelMembers(Set referenceChannelMembers) { - this.referenceChannelMembers = referenceChannelMembers; - } - - public void addReferenceChannelMember(ChannelMember referenceChannelMember) { - referenceChannelMembers.add(referenceChannelMember); - } - - public void addChannelMemberAsInput(ChannelMember groupDependentResource) { - addChannelMember(groupDependentResource); - addInputChannelMember(groupDependentResource); - } - - public void addChannelMemberAsOutput(ChannelMember groupDependentResource) { - addChannelMember(groupDependentResource); - addOutputChannelMember(groupDependentResource); - } - - public void addChannelMemberAsReference(ChannelMember groupDependentResource) { - addChannelMember(groupDependentResource); - addReferenceChannelMember(groupDependentResource); - } - - public void removeChannelMember(IdentifierTemplate id) { - for (ChannelMember cm: inputChannelMembers) { - if (cm.getIdentifierTemplate() == id) { - inputChannelMembers.remove(cm); - super.removeChannelMember(id); - return; - } - } - for (ChannelMember cm: outputChannelMembers) { - if (cm.getIdentifierTemplate() == id) { - outputChannelMembers.remove(cm); - super.removeChannelMember(id); - return; - } - } - for (ChannelMember cm: referenceChannelMembers) { - if (cm.getIdentifierTemplate() == id) { - referenceChannelMembers.remove(cm); - super.removeChannelMember(id); - return; - } - } - } - - public Set getInputIdentifierTemplates() { - Set inputIdentifierTemplates = new HashSet<>(); - for (ChannelMember member: inputChannelMembers) { - inputIdentifierTemplates.add(member.getIdentifierTemplate()); - } - return inputIdentifierTemplates; - } - - public Set getOutputIdentifierTemplates() { - Set outputIdentifierTemplates = new HashSet<>(); - for (ChannelMember member: outputChannelMembers) { - outputIdentifierTemplates.add(member.getIdentifierTemplate()); - } - return outputIdentifierTemplates; - } - - public Set getReferenceIdentifierTemplates() { - Set referenceIdentifierTemplates = new HashSet<>(); - for (ChannelMember member: referenceChannelMembers) { - referenceIdentifierTemplates.add(member.getIdentifierTemplate()); - } - return referenceIdentifierTemplates; - } - - /** - * Derive the update expression of the state of the target channel member. - * @param targetMember a channel member whose state is to be updated - * @return the derived update expression - * @throws ParameterizedIdentifierIsFutureWork - * @throws ResolvingMultipleDefinitionIsFutureWork - * @throws InvalidMessage - * @throws UnificationFailed - * @throws ValueUndefined - */ - public Expression deriveUpdateExpressionOf(ChannelMember targetMember) throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { - IResourceStateAccessor defaultStateAccessor = new IResourceStateAccessor() { - HashMap curStateParams = new HashMap<>(); - HashMap nextStateParams = new HashMap<>(); - - @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { - String resource = target.getResourceName(); - Parameter curStateParam = curStateParams.get(resource); - if (curStateParam == null) { - curStateParam = new Parameter("cur" + resource); - curStateParams.put(resource, curStateParam); - } - return curStateParam; - } - - @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { - String resource = target.getResourceName(); - Parameter nextStateParam = nextStateParams.get(resource); - if (nextStateParam == null) { - nextStateParam = new Parameter("next" + resource); - nextStateParams.put(resource, nextStateParam); - } - return nextStateParam; - } - }; - return deriveUpdateExpressionOf(targetMember, defaultStateAccessor); - } - - /** - * Derive the update expression of the state of the target channel member with a given resource state accessor. - * @param targetMember a channel member whose state is to be updated - * @param stateAccessor a resource state accessor - * @return the derived update expression - * @throws ParameterizedIdentifierIsFutureWork - * @throws ResolvingMultipleDefinitionIsFutureWork - * @throws InvalidMessage - * @throws UnificationFailed - * @throws ValueUndefined - */ - public Expression deriveUpdateExpressionOf(ChannelMember targetMember, IResourceStateAccessor stateAccessor) - throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { - return deriveUpdateExpressionOf(targetMember, stateAccessor, null); - } - - public Expression deriveUpdateExpressionOf(ChannelMember targetMember, IResourceStateAccessor stateAccessor, HashMap inputIdentifierToStateAccessor) - throws ParameterizedIdentifierIsFutureWork, ResolvingMultipleDefinitionIsFutureWork, InvalidMessage, UnificationFailed, ValueUndefined { - if (!getOutputChannelMembers().contains(targetMember)) return null; - HashSet messageConstraints = new HashSet<>(); - - // Calculate message constraints from input state transitions - for (ChannelMember inputMember: getInputChannelMembers()) { - IdentifierTemplate inputIdentifier = inputMember.getIdentifierTemplate(); - if (inputIdentifier.getNumberOfParameters() > 0) { - throw new ParameterizedIdentifierIsFutureWork(); - } - Expression curInputStateAccessor = null; - Expression nextInputStateAccessor = null; - if (inputIdentifierToStateAccessor == null) { - curInputStateAccessor = stateAccessor.getCurrentStateAccessorFor(inputIdentifier, targetMember.getIdentifierTemplate()); - nextInputStateAccessor = stateAccessor.getNextStateAccessorFor(inputIdentifier, targetMember.getIdentifierTemplate()); - } else { - curInputStateAccessor = inputIdentifierToStateAccessor.get(inputIdentifier).getCurrentStateAccessorFor(inputIdentifier, targetMember.getIdentifierTemplate()); - nextInputStateAccessor = inputIdentifierToStateAccessor.get(inputIdentifier).getNextStateAccessorFor(inputIdentifier, targetMember.getIdentifierTemplate()); - } - Expression messageConstraintByInput = inputMember.getStateTransition().deriveMessageConstraintFor(curInputStateAccessor, nextInputStateAccessor); - messageConstraints.add((Term) messageConstraintByInput); - } - - // Calculate message constraints from reference state transitions - for (ChannelMember referenceMember: getReferenceChannelMembers()) { - IdentifierTemplate referenceIdentifier = referenceMember.getIdentifierTemplate(); - if (referenceIdentifier.getNumberOfParameters() > 0) { - throw new ParameterizedIdentifierIsFutureWork(); - } - Expression curInputStateAccessor = null; - if (inputIdentifierToStateAccessor == null) { - curInputStateAccessor = stateAccessor.getCurrentStateAccessorFor(referenceIdentifier, targetMember.getIdentifierTemplate()); - } else { - curInputStateAccessor = inputIdentifierToStateAccessor.get(referenceIdentifier).getCurrentStateAccessorFor(referenceIdentifier, targetMember.getIdentifierTemplate()); - } - Expression messageConstraintByReference = referenceMember.getStateTransition().deriveMessageConstraintFor(curInputStateAccessor); - messageConstraints.add((Term) messageConstraintByReference); - } - - // Unify message constraints - Term unifiedMessage = null; - for (Term messageContraint: messageConstraints) { - if (unifiedMessage == null) { - unifiedMessage = messageContraint; - } else { - unifiedMessage = (Term) unifiedMessage.unify(messageContraint); - if (unifiedMessage == null) { - throw new UnificationFailed(); - } - } - } - - // Calculate the next state of target resource from the unified message and the current resource state - IdentifierTemplate targetIdentifier = targetMember.getIdentifierTemplate(); - if (targetIdentifier.getNumberOfParameters() > 0) { - throw new ParameterizedIdentifierIsFutureWork(); - } - Expression curOutputStateAccessor = stateAccessor.getCurrentStateAccessorFor(targetIdentifier, targetIdentifier); - if (unifiedMessage == null) { - // for IOChannel - if (targetMember.getStateTransition().getMessageExpression() instanceof Term) { - unifiedMessage = (Term) targetMember.getStateTransition().getMessageExpression(); - } - } - return targetMember.getStateTransition().deriveNextStateExpressionFor(curOutputStateAccessor, unifiedMessage); - } - - @Override - public String toString() { - String channelSource = "channel " + getChannelName() + " {\n"; - for (ChannelMember inputMember: inputChannelMembers) { - channelSource += "\t in " + inputMember + "\n"; - } - for (ChannelMember refMember: referenceChannelMembers) { - channelSource += "\t ref " + refMember + "\n"; - } - for (ChannelMember outputMember: outputChannelMembers) { - channelSource += "\t out " + outputMember + "\n"; - } - channelSource += "}\n"; - return channelSource; - } - - public interface IResourceStateAccessor { - Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from); - Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from); - } -} diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java index 364a646..1e67efb 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java @@ -2,27 +2,27 @@ import java.util.Set; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; public class DataTransferModel extends DataConstraintModel { public DataFlowGraph getDataFlowGraph() { DataFlowGraph dataFlowGraph = new DataFlowGraph(); - for (ChannelGenerator channelGen: getChannelGenerators()) { - DataTransferChannelGenerator dfChannelGen = (DataTransferChannelGenerator)channelGen; - Set inputResources = dfChannelGen.getInputIdentifierTemplates(); - Set outputResources = dfChannelGen.getOutputIdentifierTemplates(); - for (IdentifierTemplate in: inputResources) { - for (IdentifierTemplate out: outputResources) { + for (Channel channel: getChannels()) { + DataTransferChannel dfChannelGen = (DataTransferChannel)channel; + Set inputResources = dfChannelGen.getInputResources(); + Set outputResources = dfChannelGen.getOutputResources(); + for (ResourcePath in: inputResources) { + for (ResourcePath out: outputResources) { dataFlowGraph.addEdge(in ,out, dfChannelGen); } } } - for (ChannelGenerator channelGen: getIOChannelGenerators()) { - DataTransferChannelGenerator dfChannelGen = (DataTransferChannelGenerator)channelGen; - Set outputResources = dfChannelGen.getOutputIdentifierTemplates(); - for (IdentifierTemplate out: outputResources) { + for (Channel channel: getIOChannels()) { + DataTransferChannel dfChannel = (DataTransferChannel)channel; + Set outputResources = dfChannel.getOutputResources(); + for (ResourcePath out: outputResources) { dataFlowGraph.addNode(out); } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java index 698eac3..ef286af 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNode.java @@ -1,30 +1,30 @@ package models.dataFlowModel; import models.Node; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; public class ResourceNode extends Node { - protected IdentifierTemplate identifierTemplate = null; + protected ResourcePath resourcePath = null; - public ResourceNode(IdentifierTemplate identifierTemplate) { - this.identifierTemplate = identifierTemplate; + public ResourceNode(ResourcePath resourcePath) { + this.resourcePath = resourcePath; } - public IdentifierTemplate getIdentifierTemplate() { - return identifierTemplate; + public ResourcePath getResource() { + return resourcePath; } public boolean equals(Object another) { if (this == another) return true; if (!(another instanceof ResourceNode)) return false; - return identifierTemplate.equals(((ResourceNode)another).identifierTemplate); + return resourcePath.equals(((ResourceNode)another).resourcePath); } public int hashCode() { - return identifierTemplate.hashCode(); + return resourcePath.hashCode(); } public String toString() { - return identifierTemplate.getResourceName(); + return resourcePath.getResourceName(); } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNodeAttribute.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNodeAttribute.java index d03c305..a1f8615 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNodeAttribute.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ResourceNodeAttribute.java @@ -36,7 +36,7 @@ * */ public String getResourceName() { - return resourceNode.getIdentifierTemplate().getResourceName(); + return resourceNode.getResource().getResourceName(); } /************************************************************* @@ -58,6 +58,6 @@ */ @Override public String toString() { - return resourceNode.getIdentifierTemplate().getResourceName(); + return resourceNode.getResource().getResourceName(); } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannel.java b/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannel.java new file mode 100644 index 0000000..581d31e --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannel.java @@ -0,0 +1,161 @@ +package models.visualModel; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import models.algebra.Expression; +import models.algebra.Symbol; +import models.algebra.Term; +import models.algebra.Variable; +import models.dataConstraintModel.ChannelMember; +import models.dataConstraintModel.DataConstraintModel; +import models.dataConstraintModel.ResourcePath; +import models.dataConstraintModel.StateTransition; +import models.dataFlowModel.DataTransferChannel; + +public class FormulaChannel extends DataTransferChannel { + private Symbol defaultOperator = null; + private String formula = null; + private Expression formulaRhs = null; + + public FormulaChannel(String channelName, Symbol defaultOperator) { + super(channelName); + this.defaultOperator = defaultOperator; + } + + public void addChannelMemberAsInput(ChannelMember channelMember) { +// StateTransition st = new StateTransition(); +// st.setCurStateExpression(new Variable(channelMember.getIdentifierTemplate().getResourceName() + "1")); +// st.setNextStateExpression(new Variable(channelMember.getIdentifierTemplate().getResourceName() + "2")); +// channelMember.setStateTransition(st); + super.addChannelMemberAsInput(channelMember); + if (formula != null && getInputChannelMembers().size() > 1) { + formula += " " + defaultOperator + " " + channelMember.getResource().getResourceName(); + if (formulaRhs != null) { + if (formulaRhs instanceof Variable) { + Term newTerm = new Term(defaultOperator); + newTerm.addChild(formulaRhs); + newTerm.addChild(new Variable(channelMember.getResource().getResourceName()), true); + formulaRhs = newTerm; + } else if (formulaRhs instanceof Term) { + Term newTerm = new Term(defaultOperator); + newTerm.addChild(formulaRhs); + newTerm.addChild(new Variable(channelMember.getResource().getResourceName())); + formulaRhs = newTerm; + } + } + } else { + if (formula == null) formula = ""; + formula += channelMember.getResource().getResourceName(); + formulaRhs = new Variable(channelMember.getResource().getResourceName()); + } + if (formulaRhs != null) { + setFormulaTerm(formulaRhs); + } + } + + public void addChannelMemberAsOutput(ChannelMember channelMember) { +// StateTransition st = new StateTransition(); +// st.setCurStateExpression(new Variable(channelMember.getIdentifierTemplate().getResourceName() + "1")); +// channelMember.setStateTransition(st); + super.addChannelMemberAsOutput(channelMember); + if (getOutputChannelMembers().size() == 1) { + if (formula == null) formula = ""; + if (!formula.contains("==")) { + formula = channelMember.getResource().getResourceName() + " == " + formula; + } + } + if (formulaRhs != null) { + setFormulaTerm(formulaRhs); + } + } + + public Symbol getDefaultOperator() { + return defaultOperator; + } + + public void setDefaultOperator(Symbol defaultOperator) { + this.defaultOperator = defaultOperator; + } + + public void setFormulaTerm(Expression rhs) { + formulaRhs = rhs; + Collection variables; + if (rhs instanceof Variable) { + variables = new ArrayList<>(); + variables.add((Variable) rhs); + } else if (rhs instanceof Term) { + variables = ((Term) rhs).getVariables().values(); + } else { + return; + } + Map curStates = new HashMap<>(); + Map nextStates = new HashMap<>(); + Map resToNextVar = new HashMap<>(); + for (ChannelMember cm: this.getInputChannelMembers()) { + ResourcePath id = cm.getResource(); + String resName = id.getResourceName(); + Variable curVar = new Variable(resName + "1"); + Variable nextVar = new Variable(resName + "2"); + curStates.put(id, curVar); + nextStates.put(id, nextVar); + for (Variable var: variables) { + if (var.getName().equals(resName)) { + resToNextVar.put(var, nextVar); + break; + } + } + } + Symbol update = new Symbol("update"); + update.setArity(resToNextVar.keySet().size()); + for (ChannelMember cm: getInputChannelMembers()) { + ResourcePath id = cm.getResource(); + StateTransition st = new StateTransition(); + st.setCurStateExpression(curStates.get(id)); + st.setNextStateExpression(nextStates.get(id)); + Term message = new Term(update); + for (Variable var: resToNextVar.values()) { + message.addChild(var); + } + st.setMessageExpression(message); + cm.setStateTransition(st); + } + + if (rhs instanceof Variable) { + rhs = resToNextVar.get((Variable) rhs); + } else if (rhs instanceof Term) { + formulaRhs = rhs; + for (Variable var: resToNextVar.keySet()) { + rhs = ((Term) rhs).substitute(var, resToNextVar.get(var)); + } + } + for (ChannelMember cm: getOutputChannelMembers()) { + ResourcePath id = cm.getResource(); + StateTransition st = new StateTransition(); + String resName = id.getResourceName(); + Variable curVar = new Variable(resName + "1"); + st.setCurStateExpression(curVar); + st.setNextStateExpression(rhs); + Term message = new Term(update); + for (Variable var: resToNextVar.values()) { + message.addChild(var); + } + st.setMessageExpression(message); + cm.setStateTransition(st); + } + } + + public Expression getFormulaTerm() { + return formulaRhs; + } + + public void setFormula(String formula) { + this.formula = formula; + } + + public String getFormula() { + return formula; + } +} diff --git a/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannelGenerator.java b/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannelGenerator.java deleted file mode 100644 index 4bbfe7e..0000000 --- a/AlgebraicDataflowArchitectureModel/src/models/visualModel/FormulaChannelGenerator.java +++ /dev/null @@ -1,161 +0,0 @@ -package models.visualModel; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import models.algebra.Expression; -import models.algebra.Symbol; -import models.algebra.Term; -import models.algebra.Variable; -import models.dataConstraintModel.ChannelMember; -import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; -import models.dataConstraintModel.StateTransition; -import models.dataFlowModel.DataTransferChannelGenerator; - -public class FormulaChannelGenerator extends DataTransferChannelGenerator { - private Symbol defaultOperator = null; - private String formula = null; - private Expression formulaRhs = null; - - public FormulaChannelGenerator(String channelName, Symbol defaultOperator) { - super(channelName); - this.defaultOperator = defaultOperator; - } - - public void addChannelMemberAsInput(ChannelMember channelMember) { -// StateTransition st = new StateTransition(); -// st.setCurStateExpression(new Variable(channelMember.getIdentifierTemplate().getResourceName() + "1")); -// st.setNextStateExpression(new Variable(channelMember.getIdentifierTemplate().getResourceName() + "2")); -// channelMember.setStateTransition(st); - super.addChannelMemberAsInput(channelMember); - if (formula != null && getInputChannelMembers().size() > 1) { - formula += " " + defaultOperator + " " + channelMember.getIdentifierTemplate().getResourceName(); - if (formulaRhs != null) { - if (formulaRhs instanceof Variable) { - Term newTerm = new Term(defaultOperator); - newTerm.addChild(formulaRhs); - newTerm.addChild(new Variable(channelMember.getIdentifierTemplate().getResourceName()), true); - formulaRhs = newTerm; - } else if (formulaRhs instanceof Term) { - Term newTerm = new Term(defaultOperator); - newTerm.addChild(formulaRhs); - newTerm.addChild(new Variable(channelMember.getIdentifierTemplate().getResourceName())); - formulaRhs = newTerm; - } - } - } else { - if (formula == null) formula = ""; - formula += channelMember.getIdentifierTemplate().getResourceName(); - formulaRhs = new Variable(channelMember.getIdentifierTemplate().getResourceName()); - } - if (formulaRhs != null) { - setFormulaTerm(formulaRhs); - } - } - - public void addChannelMemberAsOutput(ChannelMember channelMember) { -// StateTransition st = new StateTransition(); -// st.setCurStateExpression(new Variable(channelMember.getIdentifierTemplate().getResourceName() + "1")); -// channelMember.setStateTransition(st); - super.addChannelMemberAsOutput(channelMember); - if (getOutputChannelMembers().size() == 1) { - if (formula == null) formula = ""; - if (!formula.contains("==")) { - formula = channelMember.getIdentifierTemplate().getResourceName() + " == " + formula; - } - } - if (formulaRhs != null) { - setFormulaTerm(formulaRhs); - } - } - - public Symbol getDefaultOperator() { - return defaultOperator; - } - - public void setDefaultOperator(Symbol defaultOperator) { - this.defaultOperator = defaultOperator; - } - - public void setFormulaTerm(Expression rhs) { - formulaRhs = rhs; - Collection variables; - if (rhs instanceof Variable) { - variables = new ArrayList<>(); - variables.add((Variable) rhs); - } else if (rhs instanceof Term) { - variables = ((Term) rhs).getVariables().values(); - } else { - return; - } - Map curStates = new HashMap<>(); - Map nextStates = new HashMap<>(); - Map resToNextVar = new HashMap<>(); - for (ChannelMember cm: this.getInputChannelMembers()) { - IdentifierTemplate id = cm.getIdentifierTemplate(); - String resName = id.getResourceName(); - Variable curVar = new Variable(resName + "1"); - Variable nextVar = new Variable(resName + "2"); - curStates.put(id, curVar); - nextStates.put(id, nextVar); - for (Variable var: variables) { - if (var.getName().equals(resName)) { - resToNextVar.put(var, nextVar); - break; - } - } - } - Symbol update = new Symbol("update"); - update.setArity(resToNextVar.keySet().size()); - for (ChannelMember cm: getInputChannelMembers()) { - IdentifierTemplate id = cm.getIdentifierTemplate(); - StateTransition st = new StateTransition(); - st.setCurStateExpression(curStates.get(id)); - st.setNextStateExpression(nextStates.get(id)); - Term message = new Term(update); - for (Variable var: resToNextVar.values()) { - message.addChild(var); - } - st.setMessageExpression(message); - cm.setStateTransition(st); - } - - if (rhs instanceof Variable) { - rhs = resToNextVar.get((Variable) rhs); - } else if (rhs instanceof Term) { - formulaRhs = rhs; - for (Variable var: resToNextVar.keySet()) { - rhs = ((Term) rhs).substitute(var, resToNextVar.get(var)); - } - } - for (ChannelMember cm: getOutputChannelMembers()) { - IdentifierTemplate id = cm.getIdentifierTemplate(); - StateTransition st = new StateTransition(); - String resName = id.getResourceName(); - Variable curVar = new Variable(resName + "1"); - st.setCurStateExpression(curVar); - st.setNextStateExpression(rhs); - Term message = new Term(update); - for (Variable var: resToNextVar.values()) { - message.addChild(var); - } - st.setMessageExpression(message); - cm.setStateTransition(st); - } - } - - public Expression getFormulaTerm() { - return formulaRhs; - } - - public void setFormula(String formula) { - this.formula = formula; - } - - public String getFormula() { - return formula; - } -} diff --git a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java index ed9aaf9..3713e9a 100644 --- a/AlgebraicDataflowArchitectureModel/src/parser/Parser.java +++ b/AlgebraicDataflowArchitectureModel/src/parser/Parser.java @@ -14,10 +14,10 @@ import models.algebra.Type; import models.algebra.Variable; import models.dataConstraintModel.ChannelMember; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataConstraintModel.StateTransition; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; +import models.dataFlowModel.DataTransferChannel; import parser.exceptions.ExpectedAssignment; import parser.exceptions.ExpectedChannel; import parser.exceptions.ExpectedChannelName; @@ -86,18 +86,18 @@ public DataTransferModel parseDataFlowModel() throws ExpectedRightBracket, ExpectedChannel, ExpectedChannelName, ExpectedLeftCurlyBracket, ExpectedInOrOutOrRefKeyword, ExpectedStateTransition, ExpectedEquals, ExpectedRHSExpression, WrongLHSExpression, WrongRHSExpression, ExpectedAssignment { DataTransferModel model = new DataTransferModel(); - DataTransferChannelGenerator channel; + DataTransferChannel channel; while ((channel = parseChannel(model)) != null) { if (channel.getInputChannelMembers().size() == 0) { - model.addIOChannelGenerator(channel); + model.addIOChannel(channel); } else { - model.addChannelGenerator(channel); + model.addChannel(channel); } } return model; } - public DataTransferChannelGenerator parseChannel(DataTransferModel model) + public DataTransferChannel parseChannel(DataTransferModel model) throws ExpectedLeftCurlyBracket, ExpectedRightBracket, ExpectedAssignment, ExpectedRHSExpression, WrongLHSExpression, WrongRHSExpression, @@ -119,7 +119,7 @@ if (channelName.equals(LEFT_CURLY_BRACKET)) throw new ExpectedChannelName(stream.getLine()); int fromLine = stream.getLine(); - DataTransferChannelGenerator channel = new DataTransferChannelGenerator(channelName); + DataTransferChannel channel = new DataTransferChannel(channelName); String leftBracket = stream.next(); if (!leftBracket.equals(LEFT_CURLY_BRACKET)) throw new ExpectedLeftCurlyBracket(stream.getLine()); @@ -159,10 +159,10 @@ String resourceName = null; while (stream.hasNext() && !(resourceName = stream.next()).equals(RIGHT_CURLY_BRACKET)) { int fromLine = stream.getLine(); - IdentifierTemplate identifier = model.getIdentifierTemplate(resourceName); - if (identifier == null) { - identifier = new IdentifierTemplate(resourceName, 0); - model.addIdentifierTemplate(identifier); + ResourcePath resource = model.getResourcePath(resourceName); + if (resource == null) { + resource = new ResourcePath(resourceName, 0); + model.addResourcePath(resource); } if (!stream.hasNext()) throw new ExpectedAssignment(stream.getLine()); @@ -178,8 +178,8 @@ rightTerm = parseTerm(stream, model); if (rightTerm == null) throw new WrongRHSExpression(stream.getLine()); - identifier.setInitialValue(rightTerm); - identifier.setInitText(stream.getSourceText(fromLine, toLine)); + resource.setInitialValue(rightTerm); + resource.setInitText(stream.getSourceText(fromLine, toLine)); } } @@ -204,22 +204,22 @@ } String resourceName = ((Term) leftTerm).getSymbol().getName(); - IdentifierTemplate identifier = model.getIdentifierTemplate(resourceName); - if (identifier == null) { - identifier = new IdentifierTemplate(resourceName, 0); - model.addIdentifierTemplate(identifier); + ResourcePath resource = model.getResourcePath(resourceName); + if (resource == null) { + resource = new ResourcePath(resourceName, 0); + model.addResourcePath(resource); } - ChannelMember channelMember = new ChannelMember(identifier); + ChannelMember channelMember = new ChannelMember(resource); StateTransition stateTransition = new StateTransition(); stateTransition.setCurStateExpression(((Term) leftTerm).getChild(0)); stateTransition.setMessageExpression(((Term) leftTerm).getChild(1)); if (!inOrOutOrRef.equals(REF)) stateTransition.setNextStateExpression(rightTerm); channelMember.setStateTransition(stateTransition); // for type definition - if (identifier.getResourceStateType() == null && ((Term) leftTerm).getChild(0) instanceof Variable) { + if (resource.getResourceStateType() == null && ((Term) leftTerm).getChild(0) instanceof Variable) { Variable stateVar = (Variable) ((Term) leftTerm).getChild(0); if (stateVar.getType() != null) { - identifier.setResourceStateType(stateVar.getType()); + resource.setResourceStateType(stateVar.getType()); } } if (((Term) leftTerm).getChild(1) instanceof Term) { diff --git a/AlgebraicDataflowArchitectureModel/src/tests/DataConstraintModelTest.java b/AlgebraicDataflowArchitectureModel/src/tests/DataConstraintModelTest.java index 5719cac..e621180 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/DataConstraintModelTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/DataConstraintModelTest.java @@ -12,33 +12,33 @@ public void test() { // Construct a data constraint architecture model. DataConstraintModel model = new DataConstraintModel(); - IdentifierTemplate customer_off = new IdentifierTemplate("customers.{customer_id}.off", 1); - IdentifierTemplate customer_add = new IdentifierTemplate("customers.{customer_id}.add", 1); - IdentifierTemplate company_add = new IdentifierTemplate("companies.{company_id}.add", 1); + ResourcePath customer_off = new ResourcePath("customers.{customer_id}.off", 1); + ResourcePath customer_add = new ResourcePath("customers.{customer_id}.add", 1); + ResourcePath company_add = new ResourcePath("companies.{company_id}.add", 1); - ChannelGenerator gin_1 = new ChannelGenerator("gin_1"); // set customer's office - GroupSelector x1 = new GroupSelector(); + Channel gin_1 = new Channel("gin_1"); // set customer's office +// GroupSelector x1 = new GroupSelector(); ChannelMember customer_off_1 = new ChannelMember(customer_off); - customer_off_1.addSelector(x1); +// customer_off_1.addSelector(x1); gin_1.addChannelMember(customer_off_1); assertEquals(customer_off.getNumberOfParameters(), customer_off_1.getSelectors().size()); - ChannelGenerator gin_2 = new ChannelGenerator("gin_2"); // set companie's address - GroupSelector x2 = new GroupSelector(); + Channel gin_2 = new Channel("gin_2"); // set companie's address +// GroupSelector x2 = new GroupSelector(); ChannelMember company_add_1 = new ChannelMember(company_add); - company_add_1.addSelector(x2); +// company_add_1.addSelector(x2); gin_2.addChannelMember(company_add_1); assertEquals(company_add.getNumberOfParameters(), company_add_1.getSelectors().size()); - ChannelGenerator g = new ChannelGenerator("g"); // update customer's address - GroupSelector x3 = new GroupSelector(); - ChannelSelector y = new ChannelSelector(); + Channel g = new Channel("g"); // update customer's address +// GroupSelector x3 = new GroupSelector(); +// ChannelSelector y = new ChannelSelector(); ChannelMember customer_off_2 = new ChannelMember(customer_off); ChannelMember company_add_2 = new ChannelMember(company_add); ChannelMember customer_add_2 = new ChannelMember(customer_add); - customer_off_2.addSelector(x3); - company_add_2.addSelector(y); - customer_add_2.addSelector(x3); +// customer_off_2.addSelector(x3); +// company_add_2.addSelector(y); +// customer_add_2.addSelector(x3); g.addChannelMember(customer_off_2); g.addChannelMember(customer_add_2); g.addChannelMember(company_add_2); @@ -46,14 +46,14 @@ assertEquals(customer_add.getNumberOfParameters(), customer_add_2.getSelectors().size()); assertEquals(company_add.getNumberOfParameters(), company_add_2.getSelectors().size()); - model.addIOChannelGenerator(gin_1); - model.addIOChannelGenerator(gin_2); - model.addChannelGenerator(g); + model.addIOChannel(gin_1); + model.addIOChannel(gin_2); + model.addChannel(g); // Check the model. - assertEquals(3, model.getIdentifierTemplates().size()); - assertEquals(2, model.getIOChannelGenerators().size()); - assertEquals(1, model.getChannelGenerators().size()); + assertEquals(3, model.getResourcePaths().size()); + assertEquals(2, model.getIOChannels().size()); + assertEquals(1, model.getChannels().size()); } } diff --git a/AlgebraicDataflowArchitectureModel/src/tests/DataFlowModelTest.java b/AlgebraicDataflowArchitectureModel/src/tests/DataFlowModelTest.java index 6065992..cea2cee 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/DataFlowModelTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/DataFlowModelTest.java @@ -14,19 +14,19 @@ public void test() { // Construct a data-flow architecture model. DataTransferModel model = new DataTransferModel(); - IdentifierTemplate customer_off = new IdentifierTemplate("customers.{x1}.off", 1); // an identifier template to specify a customer's office resource - IdentifierTemplate company_add = new IdentifierTemplate("companies.{x2}.add", 1); // an identifier template to specify a companie's address resource - IdentifierTemplate customer_add = new IdentifierTemplate("customers.{x1}.add", 1); // an identifier template to specify a customer's address resource + ResourcePath customer_off = new ResourcePath("customers.{x1}.off", 1); // an identifier template to specify a customer's office resource + ResourcePath company_add = new ResourcePath("companies.{x2}.add", 1); // an identifier template to specify a companie's address resource + ResourcePath customer_add = new ResourcePath("customers.{x1}.add", 1); // an identifier template to specify a customer's address resource // === gin_1 === // // customers.{x1}.off(c, set(x)) == x // customers.{x1}.off(c, e) == c // - DataTransferChannelGenerator gin_1 = new DataTransferChannelGenerator("gin_1"); // set customer's office (an input channel) - GroupSelector x1 = new GroupSelector(); + DataTransferChannel gin_1 = new DataTransferChannel("gin_1"); // set customer's office (an input channel) +// GroupSelector x1 = new GroupSelector(); ChannelMember customer_off_1 = new ChannelMember(customer_off); - customer_off_1.addSelector(x1); // x1 is determined by the path parameter in customer's office template, and serves as a group selector in this channel +// customer_off_1.addSelector(x1); // x1 is determined by the path parameter in customer's office template, and serves as a group selector in this channel gin_1.addChannelMember(customer_off_1); assertEquals(customer_off.getNumberOfParameters(), customer_off_1.getSelectors().size()); @@ -35,10 +35,10 @@ // companies.{x2}.add(a, set(y)) == y // companies.{x2}.add(a, e) == a // - DataTransferChannelGenerator gin_2 = new DataTransferChannelGenerator("gin_2"); // set companie's address (an input channel) - GroupSelector x2 = new GroupSelector(); + DataTransferChannel gin_2 = new DataTransferChannel("gin_2"); // set companie's address (an input channel) +// GroupSelector x2 = new GroupSelector(); ChannelMember company_add_1 = new ChannelMember(company_add); - company_add_1.addSelector(x2); // x2 is determined by the path parameter in companie's address template, and serves as a group selector in this channel +// company_add_1.addSelector(x2); // x2 is determined by the path parameter in companie's address template, and serves as a group selector in this channel gin_2.addChannelMember(company_add_1); assertEquals(company_add.getNumberOfParameters(), company_add_1.getSelectors().size()); @@ -48,15 +48,15 @@ // companies.{y}.add( a1, update(y, z)) == z // customers.{x3}.add(a2, update(y, z)) == z // - DataTransferChannelGenerator g = new DataTransferChannelGenerator("g"); // update customer's address - GroupSelector x3 = new GroupSelector(); - ChannelSelector y = new ChannelSelector(); + DataTransferChannel g = new DataTransferChannel("g"); // update customer's address +// GroupSelector x3 = new GroupSelector(); +// ChannelSelector y = new ChannelSelector(); ChannelMember customer_off_2 = new ChannelMember(customer_off); ChannelMember company_add_2 = new ChannelMember(company_add); ChannelMember customer_add_2 = new ChannelMember(customer_add); - customer_off_2.addSelector(x3); // x3 is determined by the path parameter in customer's office template, and serves as a group selector in this channel - company_add_2.addSelector(y); // y is determined by the value of the customer's office resource, and serves as a channel selector in this channel - customer_add_2.addSelector(x3); // x3 determines the path parameter in customer's address template to update +// customer_off_2.addSelector(x3); // x3 is determined by the path parameter in customer's office template, and serves as a group selector in this channel +// company_add_2.addSelector(y); // y is determined by the value of the customer's office resource, and serves as a channel selector in this channel +// customer_add_2.addSelector(x3); // x3 determines the path parameter in customer's address template to update g.addChannelMemberAsInput(customer_off_2); g.addChannelMemberAsInput(customer_add_2); g.addChannelMemberAsOutput(company_add_2); @@ -65,14 +65,14 @@ assertEquals(company_add.getNumberOfParameters(), company_add_2.getSelectors().size()); // Construct a data-flow architecture model. - model.addIOChannelGenerator(gin_1); - model.addIOChannelGenerator(gin_2); - model.addChannelGenerator(g); + model.addIOChannel(gin_1); + model.addIOChannel(gin_2); + model.addChannel(g); // Check the model. - assertEquals(3, model.getIdentifierTemplates().size()); - assertEquals(2, model.getIOChannelGenerators().size()); - assertEquals(1, model.getChannelGenerators().size()); + assertEquals(3, model.getResourcePaths().size()); + assertEquals(2, model.getIOChannels().size()); + assertEquals(1, model.getChannels().size()); // Extract the resource dependency graph. DataFlowGraph resourceDependencyGraph = model.getDataFlowGraph(); diff --git a/AlgebraicDataflowArchitectureModel/src/tests/DataStorageDecisionTest.java b/AlgebraicDataflowArchitectureModel/src/tests/DataStorageDecisionTest.java index 67a1a2a..9d28936 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/DataStorageDecisionTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/DataStorageDecisionTest.java @@ -35,7 +35,7 @@ DataTransferModelAnalyzer.annotateWithSelectableDataTransferAttiribute(graph); DataTransferMethodAnalyzer.decideToStoreResourceStates(graph); for(Node n:graph.getNodes()) { - System.out.println(((ResourceNode) n).getIdentifierTemplate().getResourceName() + ":" + ((StoreAttribute) ((ResourceNode) n).getAttribute()).isStored()); + System.out.println(((ResourceNode) n).getResource().getResourceName() + ":" + ((StoreAttribute) ((ResourceNode) n).getAttribute()).isStored()); } } catch (ExpectedChannel | ExpectedChannelName | ExpectedLeftCurlyBracket | ExpectedInOrOutOrRefKeyword | ExpectedStateTransition | ExpectedEquals | ExpectedRHSExpression | WrongLHSExpression diff --git a/AlgebraicDataflowArchitectureModel/src/tests/FormulaChannelTest.java b/AlgebraicDataflowArchitectureModel/src/tests/FormulaChannelTest.java index 2cf2b37..a8f3503 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/FormulaChannelTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/FormulaChannelTest.java @@ -5,18 +5,18 @@ import models.algebra.Symbol; import models.dataConstraintModel.ChannelMember; import models.dataConstraintModel.DataConstraintModel; -import models.dataConstraintModel.IdentifierTemplate; -import models.visualModel.FormulaChannelGenerator; +import models.dataConstraintModel.ResourcePath; +import models.visualModel.FormulaChannel; public class FormulaChannelTest { @Test public void test() { - IdentifierTemplate id1 = new IdentifierTemplate("r1", 0); - IdentifierTemplate id2 = new IdentifierTemplate("r2", 0); - IdentifierTemplate id3 = new IdentifierTemplate("r3", 0); + ResourcePath id1 = new ResourcePath("r1", 0); + ResourcePath id2 = new ResourcePath("r2", 0); + ResourcePath id3 = new ResourcePath("r3", 0); - FormulaChannelGenerator ch1 = new FormulaChannelGenerator("ch1", DataConstraintModel.add); + FormulaChannel ch1 = new FormulaChannel("ch1", DataConstraintModel.add); System.out.println(ch1.getFormula()); System.out.println(ch1.getFormulaTerm()); System.out.println(ch1.getSourceText()); @@ -33,7 +33,7 @@ System.out.println(ch1.getFormulaTerm()); System.out.println(ch1.getSourceText()); - FormulaChannelGenerator ch2 = new FormulaChannelGenerator("ch2", DataConstraintModel.mul); + FormulaChannel ch2 = new FormulaChannel("ch2", DataConstraintModel.mul); System.out.println(ch2.getFormula()); System.out.println(ch2.getFormulaTerm()); System.out.println(ch2.getSourceText()); diff --git a/AlgebraicDataflowArchitectureModel/src/tests/SimplifiedDataFlowModelTest.java b/AlgebraicDataflowArchitectureModel/src/tests/SimplifiedDataFlowModelTest.java index ff262b2..acb5333 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/SimplifiedDataFlowModelTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/SimplifiedDataFlowModelTest.java @@ -14,16 +14,16 @@ public void test() { // Construct a data-flow architecture model. DataTransferModel model = new DataTransferModel(); - 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 + ResourcePath payment = new ResourcePath("payment", 0); // a resource to specify the payment resource + ResourcePath loyalty = new ResourcePath("loyalty", 0); // a resource to specify the loyalty resource + ResourcePath history = new ResourcePath("history", 0); // a resource to specify the payment history resource + ResourcePath total = new ResourcePath("total", 0); // a resource to specify the total payment resource // === cin === // // payment(p1, purchase(x)) == x // - DataTransferChannelGenerator cin = new DataTransferChannelGenerator("cin"); + DataTransferChannel cin = new DataTransferChannel("cin"); ChannelMember cin_payment = new ChannelMember(payment); cin.addChannelMember(cin_payment); assertEquals(cin.getChannelMembers().size(), 1); @@ -33,7 +33,7 @@ // payment(p1, update1(y)) == y // loyalty(l, update1(y)) == floor(y * 0.05) // - DataTransferChannelGenerator c1 = new DataTransferChannelGenerator("c1"); + DataTransferChannel c1 = new DataTransferChannel("c1"); ChannelMember c1_payment = new ChannelMember(payment); ChannelMember c1_loyalty = new ChannelMember(loyalty); c1.addChannelMemberAsInput(c1_payment); @@ -47,7 +47,7 @@ // payment(p1, update2(z)) == z // history(h, update2(z)) == cons(z, h) // - DataTransferChannelGenerator c2 = new DataTransferChannelGenerator("c2"); + DataTransferChannel c2 = new DataTransferChannel("c2"); ChannelMember c2_payment = new ChannelMember(payment); ChannelMember c2_history = new ChannelMember(history); c2.addChannelMemberAsInput(c2_payment); @@ -61,7 +61,7 @@ // history(h, update3(u)) == u // total(t, update3(u)) == sum(u) // - DataTransferChannelGenerator c3 = new DataTransferChannelGenerator("c3"); + DataTransferChannel c3 = new DataTransferChannel("c3"); ChannelMember c3_history = new ChannelMember(history); ChannelMember c3_total = new ChannelMember(total); c3.addChannelMemberAsInput(c3_history); @@ -71,15 +71,15 @@ assertEquals(c3.getOutputChannelMembers().size(), 1); // Construct a data-flow architecture model. - model.addIOChannelGenerator(cin); - model.addChannelGenerator(c1); - model.addChannelGenerator(c2); - model.addChannelGenerator(c3); + model.addIOChannel(cin); + model.addChannel(c1); + model.addChannel(c2); + model.addChannel(c3); // Check the model. - assertEquals(4, model.getIdentifierTemplates().size()); - assertEquals(1, model.getIOChannelGenerators().size()); - assertEquals(3, model.getChannelGenerators().size()); + assertEquals(4, model.getResourcePaths().size()); + assertEquals(1, model.getIOChannels().size()); + assertEquals(3, model.getChannels().size()); // Extract the resource dependency graph. DataFlowGraph resourceDependencyGraph = model.getDataFlowGraph(); diff --git a/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java b/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java index cfd510c..69a5b1f 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/UpdateCodeGenerationTest.java @@ -13,8 +13,8 @@ import models.algebra.Variable; import models.dataConstraintModel.*; import models.dataFlowModel.DataTransferModel; -import models.dataFlowModel.DataTransferChannelGenerator; -import models.dataFlowModel.DataTransferChannelGenerator.IResourceStateAccessor; +import models.dataFlowModel.DataTransferChannel; +import models.dataFlowModel.DataTransferChannel.IResourceStateAccessor; import models.dataFlowModel.ResolvingMultipleDefinitionIsFutureWork; public class UpdateCodeGenerationTest { @@ -25,10 +25,10 @@ Symbol sum = new Symbol("sum", 1, Symbol.Type.PREFIX, "stream().mapToInt(x->x).sum", Symbol.Type.METHOD); // resources - 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 + ResourcePath payment = new ResourcePath("payment", DataConstraintModel.typeInt, 0); // a resource to specify the payment resource + ResourcePath loyalty = new ResourcePath("loyalty", DataConstraintModel.typeInt, 0); // a resource to specify the loyalty resource + ResourcePath history = new ResourcePath("history", DataConstraintModel.typeList, 0);// a resource to specify the payment history resource + ResourcePath total = new ResourcePath("total", DataConstraintModel.typeInt, 0); // a resource to specify the total payment resource // fields in the Java program final Field fPayment = new Field("payment", DataConstraintModel.typeInt); @@ -42,7 +42,7 @@ final Parameter pTotal = new Parameter("total", DataConstraintModel.typeInt); IResourceStateAccessor pushAccessor = new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { if (target.equals(payment)) return fPayment; if (target.equals(loyalty)) return fLoyalty; @@ -52,7 +52,7 @@ return null; } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(payment)) return pPayment; if (target.equals(loyalty)) return pLoyalty; if (target.equals(history)) return pHistory; @@ -68,7 +68,7 @@ final Symbol totalGetter = new Symbol("getTotal", 1, Symbol.Type.METHOD); IResourceStateAccessor pullAccessor = new IResourceStateAccessor() { @Override - public Expression getCurrentStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getCurrentStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(from)) { if (target.equals(payment)) return fPayment; if (target.equals(loyalty)) return fLoyalty; @@ -78,7 +78,7 @@ return null; } @Override - public Expression getNextStateAccessorFor(IdentifierTemplate target, IdentifierTemplate from) { + public Expression getNextStateAccessorFor(ResourcePath target, ResourcePath from) { if (target.equals(payment)) { Term getter = new Term(paymentGetter); getter.addChild(fPayment); @@ -108,7 +108,7 @@ // payment(p1, update1(y)) == y // loyalty(l, update1(y)) == floor(y * 0.05) // - DataTransferChannelGenerator c1 = new DataTransferChannelGenerator("c1"); + DataTransferChannel c1 = new DataTransferChannel("c1"); ChannelMember c1_payment = new ChannelMember(payment); ChannelMember c1_loyalty = new ChannelMember(loyalty); c1.addChannelMemberAsInput(c1_payment); @@ -175,7 +175,7 @@ // payment(p1, update2(z)) == z // history(h, update2(z)) == cons(z, h) // - DataTransferChannelGenerator c2 = new DataTransferChannelGenerator("c2"); + DataTransferChannel c2 = new DataTransferChannel("c2"); ChannelMember c2_payment = new ChannelMember(payment); ChannelMember c2_history = new ChannelMember(history); c2.addChannelMemberAsInput(c2_payment); @@ -238,7 +238,7 @@ // history(h, update3(u)) = u // total(t, update3(u)) = sum(u) // - DataTransferChannelGenerator c3 = new DataTransferChannelGenerator("c3"); + DataTransferChannel c3 = new DataTransferChannel("c3"); ChannelMember c3_history = new ChannelMember(history); ChannelMember c3_total = new ChannelMember(total); c3.addChannelMemberAsInput(c3_history); diff --git a/AlgebraicDataflowArchitectureModel/src/tests/controlFlowModel/ControlFlowDelegatorTest.java b/AlgebraicDataflowArchitectureModel/src/tests/controlFlowModel/ControlFlowDelegatorTest.java index c29e7fe..57e4351 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/controlFlowModel/ControlFlowDelegatorTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/controlFlowModel/ControlFlowDelegatorTest.java @@ -2,7 +2,7 @@ import org.junit.Test; -import models.dataConstraintModel.IdentifierTemplate; +import models.dataConstraintModel.ResourcePath; import models.dataFlowModel.DataTransferModel; import static org.junit.Assert.*; @@ -16,9 +16,9 @@ public void test() { // Construct a data-flow architecture model. DataTransferModel model = new DataTransferModel(); - IdentifierTemplate customer_off = new IdentifierTemplate("customers.{x1}.off", 1); // an identifier template to specify a customer's office resource - IdentifierTemplate company_add = new IdentifierTemplate("companies.{x2}.add", 1); // an identifier template to specify a companie's address resource - IdentifierTemplate customer_add = new IdentifierTemplate("customers.{x1}.add", 1); // an identifier template to specify a customer's address resource + ResourcePath customer_off = new ResourcePath("customers.{x1}.off", 1); // a resource to specify a customer's office resource + ResourcePath company_add = new ResourcePath("companies.{x2}.add", 1); // a resource to specify a companie's address resource + ResourcePath customer_add = new ResourcePath("customers.{x1}.add", 1); // a resource to specify a customer's address resource diff --git a/AlgebraicDataflowArchitectureModel/src/tests/parser/ParseTest.java b/AlgebraicDataflowArchitectureModel/src/tests/parser/ParseTest.java index 008d004..a1ea0a3 100644 --- a/AlgebraicDataflowArchitectureModel/src/tests/parser/ParseTest.java +++ b/AlgebraicDataflowArchitectureModel/src/tests/parser/ParseTest.java @@ -10,7 +10,7 @@ import models.algebra.ParameterizedIdentifierIsFutureWork; import models.algebra.UnificationFailed; import models.algebra.ValueUndefined; -import models.dataConstraintModel.ChannelGenerator; +import models.dataConstraintModel.Channel; import models.dataConstraintModel.ChannelMember; import models.dataFlowModel.*; import parser.Parser; @@ -37,10 +37,10 @@ model = parser.doParse(); System.out.println(model); - for (ChannelGenerator c: model.getChannelGenerators()) { - for (ChannelMember out: ((DataTransferChannelGenerator) c).getOutputChannelMembers()) { + for (Channel c: model.getChannels()) { + for (ChannelMember out: ((DataTransferChannel) c).getOutputChannelMembers()) { String[] sideEffects = new String[] {""}; - System.out.println("next" + out.getIdentifierTemplate().getResourceName() + " = " + ((DataTransferChannelGenerator) c).deriveUpdateExpressionOf(out).toImplementation(sideEffects)); + System.out.println("next" + out.getResource().getResourceName() + " = " + ((DataTransferChannel) c).deriveUpdateExpressionOf(out).toImplementation(sideEffects)); } }