diff --git a/AlgebraicDataflowArchitectureModel/models/OnlineBattleGame2.model b/AlgebraicDataflowArchitectureModel/models/OnlineBattleGame2.model index 291c9eb..ccd15a7 100644 --- a/AlgebraicDataflowArchitectureModel/models/OnlineBattleGame2.model +++ b/AlgebraicDataflowArchitectureModel/models/OnlineBattleGame2.model @@ -27,7 +27,7 @@ channel UpdatePoint(rid:Str) { in rooms.{rid}.battle(prevState, updatePoint(hasWon, mid)) = hasWon for EachMember(mno:Int) { - in rooms.{rid}.members.{mno}.id(prevMid:Str, updatePoint(hasWon, mid)) = mid + ref rooms.{rid}.members.{mno}.id(mid:Str, updatePoint(hasWon, mid)) out accounts.{mid}.point(prevPoint:Int, updatePoint(hasWon, mid)) = if(hasWon, prevPoint + 1, prevPoint) } -} +} \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java index 6b327c7..61dbebb 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java @@ -553,11 +553,19 @@ } } ResourcePath insideResPath = insideChMem.getResource(); - while (insideResPath.getParent() != null && (insideResPath.getNumberOfParameters() == 0 || !insideResPath.getLastParam().equals(selExp))) { + while (insideResPath.getParent() != null && (insideResPath.getLastParam() == null || !insideResPath.getLastParam().equals(selExp))) { insideResPath = insideResPath.getParent(); } insideResPath = insideResPath.getParent(); - String parent = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()).toImplementation(new String[] {}); + String parent = null; + if (JerseyCodeGenerator.generatesComponent(insideResPath.getResourceHierarchy())) { + Expression getter = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()); + Term valueGetter = new Term(new Symbol("getValue", 1, Symbol.Type.METHOD)); + valueGetter.addChild(getter); + parent = valueGetter.toImplementation(new String[] {}); + } else { + parent = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()).toImplementation(new String[] {}); + } if (insideResPath != null) { if (selType.equals(DataConstraintModel.typeInt)) { // make a for loop (for a list) for broadcasting. @@ -724,11 +732,19 @@ } } ResourcePath insideResPath = insideChMem.getResource(); - while (insideResPath.getParent() != null && (insideResPath.getNumberOfParameters() == 0 || !insideResPath.getLastParam().equals(selExp))) { + while (insideResPath.getParent() != null && (insideResPath.getLastParam() == null || !insideResPath.getLastParam().equals(selExp))) { insideResPath = insideResPath.getParent(); } insideResPath = insideResPath.getParent(); - String parent = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()).toImplementation(new String[] {}); + String parent = null; + if (JerseyCodeGenerator.generatesComponent(insideResPath.getResourceHierarchy())) { + Expression getter = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()); + Term valueGetter = new Term(new Symbol("getValue", 1, Symbol.Type.METHOD)); + valueGetter.addChild(getter); + parent = valueGetter.toImplementation(new String[] {}); + } else { + parent = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()).toImplementation(new String[] {}); + } if (insideResPath != null) { if (selType.equals(DataConstraintModel.typeInt)) { // make a for loop (for a list) for broadcasting. @@ -857,11 +873,19 @@ } } ResourcePath insideResPath = insideChMem.getResource(); - while (insideResPath.getParent() != null && (insideResPath.getNumberOfParameters() == 0 || !insideResPath.getLastParam().equals(selExp))) { + while (insideResPath.getParent() != null && (insideResPath.getLastParam() == null || !insideResPath.getLastParam().equals(selExp))) { insideResPath = insideResPath.getParent(); } insideResPath = insideResPath.getParent(); - String parent = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()).toImplementation(new String[] {}); + String parent = null; + if (JerseyCodeGenerator.generatesComponent(insideResPath.getResourceHierarchy())) { + Expression parentGetter = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()); + Term valueGetter = new Term(new Symbol("getValue", 1, Symbol.Type.METHOD)); + valueGetter.addChild(parentGetter); + parent = valueGetter.toImplementation(new String[] {}); + } else { + parent = JerseyCodeGenerator.pullAccessor.getDirectStateAccessorFor(insideResPath, src.getPrimaryResourcePath()).toImplementation(new String[] {}); + } if (insideResPath != null) { if (selType.equals(DataConstraintModel.typeInt)) { // make a for loop (for a list) for broadcasting. diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java index b27156b..ad92b74 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/DataTransferModel.java @@ -18,6 +18,9 @@ addResourceToChannelEdges(dataFlowGraph, channel, null, channelLocalResMap); } for (Channel channel: getChannels()) { + addReferenceResources(dataFlowGraph, channel, null, channelLocalResMap); + } + for (Channel channel: getChannels()) { addChannelToResourceEdges(dataFlowGraph, channel, null, channelLocalResMap); } for (Channel channel: getInputChannels()) { @@ -66,6 +69,44 @@ } } + private void addReferenceResources(DataFlowGraph dataFlowGraph, Channel dstChannel, ChannelNode parentChannelNode, + Map>> channelLocalResMap) { + DataTransferChannel dstDfChannel = (DataTransferChannel) dstChannel; + ChannelNode dstChannelNode = dataFlowGraph.addChannelNode(parentChannelNode, dstDfChannel); + for (ResourcePath srcRes: dstDfChannel.getReferenceResources()) { + Map> chLocalResNodes = channelLocalResMap.get(srcRes.getResourceHierarchy()); + if (srcRes.getNumberOfParameters() == 0) { + // ResourcePath without parameter corresponds to a global ResourceNode. + ResourceNode srcResNode = addResourceNodes(dataFlowGraph, srcRes, dstDfChannel, channelLocalResMap, false); + } else { + if (chLocalResNodes == null) { + // There is no channel-local ResourcePath. + // Then, create a new channel-local ResourceNode. + ResourceNode srcResNode = addResourceNodes(dataFlowGraph, srcRes, dstDfChannel, channelLocalResMap, false); + } else { + boolean bExists = false; + for (Channel ch: chLocalResNodes.keySet()) { + Set nodes = chLocalResNodes.get(ch); + for (ResourceNode node: nodes) { + ResourcePath r = node.getOutSideResource((DataTransferChannel) ch); + if (r.toString().equals(srcRes.toString())) { + bExists = true; // There exists the same ResourecPath within some channel. + break; + } + } + } + if (!bExists) { + // Create a new channel-local ResourceNode. + ResourceNode srcResNode = addResourceNodes(dataFlowGraph, srcRes, dstDfChannel, channelLocalResMap, false); + } + } + } + } + for (Channel childChannel: dstDfChannel.getChildren()) { + addReferenceResources(dataFlowGraph, childChannel, dstChannelNode, channelLocalResMap); + } + } + private void addChannelToResourceEdges(DataFlowGraph dataFlowGraph, Channel srcChannel, ChannelNode parentChannelNode, Map>> channelLocalResMap) { DataTransferChannel srcDfChannel = (DataTransferChannel) srcChannel;