diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java index 5c7a65b..3f8105c 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java @@ -973,28 +973,39 @@ DataTransferChannel ch2 = ((ChannelNode) resToCh2.getDestination()).getChannel(); // Check if the input resource is outside of the channel scope. boolean outsideInputResource2 = false; + ChannelMember in = null; Set outsideInputMembers2 = new HashSet<>(); for (ChannelMember cm: ch2.getInputChannelMembers()) { - if (cm.isOutside()) { - outsideInputMembers2.add(cm); - if (cm.getResource().equals(resourceNode.getOutSideResource())) { + if (cm.getResource().equals(resourceNode.getOutSideResource())) { + if (cm.isOutside()) { outsideInputResource2 = true; // Regarded as pull transfer. } + in = cm; + } + if (cm.isOutside()) { + outsideInputMembers2.add(cm); } } - if (((PushPullAttribute) dOut.getAttribute()).getOptions().get(0) == PushPullValue.PUSH && !outsideInputResource2) { - for (Edge chToRes2: resToCh2.getDestination().getOutEdges()) { - // PUSH transfer - ChannelMember in = null; - for (ChannelMember cm: ch2.getInputChannelMembers()) { - if (cm.getResource().equals(resourceNode.getOutSideResource())) { - in = cm; - break; - } + for (Edge chToRes2: resToCh2.getDestination().getOutEdges()) { + ResourceNode dstNode = ((ResourceNode) chToRes2.getDestination()); + // Check if the output resource is outside of the channel scope. + boolean outsideOutputResource2 = false; + for (ChannelMember cm: ch2.getOutputChannelMembers()) { + if (dstNode.getInSideResources().contains(cm.getResource()) && cm.isOutside()) { + outsideOutputResource2 = true; } + } + if ((((PushPullAttribute) dOut.getAttribute()).getOptions().get(0) == PushPullValue.PUSH && !outsideInputResource2) || outsideOutputResource2) { + // PUSH transfer Map> referredResources = new HashMap<>(); List params = new ArrayList<>(); - params.add(langSpec.getFieldAccessor(fieldOfResourceState)); + ResourceHierarchy srcRes2 = resourceNode.getResourceHierarchy(); + if (generatesComponent(srcRes2)) { + params.add(langSpec.getFieldAccessor(fieldOfResourceState)); + } else { + params.add(langSpec.getFieldAccessor(langSpec.toVariableName(srcRes2.getResourceName()))); + srcRes2 = srcRes2.getParent(); + } Set referredSet = referredResources.get(update); for (ChannelMember rc: ch2.getReferenceChannelMembers()) { // to get the value of reference member. @@ -1016,12 +1027,8 @@ params.add(refVarName); } } - ResourceHierarchy srcRes2 = resourceNode.getResourceHierarchy(); - if (!generatesComponent(srcRes2)) { - srcRes2 = srcRes2.getParent(); - } String updateMethodName = null; - ResourceHierarchy dstRes = ((ResourceNode) chToRes2.getDestination()).getResourceHierarchy(); + ResourceHierarchy dstRes = dstNode.getResourceHierarchy(); if (!generatesComponent(dstRes)) { updateMethodName = updateMethodPrefix + getComponentName(dstRes, langSpec) + from + resComponentName; dstRes = dstRes.getParent(); @@ -1029,12 +1036,19 @@ updateMethodName = updateMethodPrefix + from + resComponentName; } String dstCompName = langSpec.toVariableName(getComponentName(dstRes, langSpec)); - if (srcRes2 != dstRes) { + if (!outsideOutputResource2) { + // The destination resource is not outside. + if (srcRes2 != dstRes) { + update.addStatement(langSpec.getMethodInvocation(langSpec.getFieldAccessor(dstCompName), updateMethodName, params) + + langSpec.getStatementDelimiter()); // this.dst.updateDstFromSrc(value, refParams); + } else { + update.addStatement(langSpec.getMethodInvocation(updateMethodName, params) + + langSpec.getStatementDelimiter()); // this.updateDstFromSrc(value, refParams); + } + } else { + // Use the reference field to refer to outside destination resource. update.addStatement(langSpec.getMethodInvocation(langSpec.getFieldAccessor(dstCompName), updateMethodName, params) + langSpec.getStatementDelimiter()); // this.dst.updateDstFromSrc(value, refParams); - } else { - update.addStatement(langSpec.getMethodInvocation(updateMethodName, params) - + langSpec.getStatementDelimiter()); // this.updateDstFromSrc(value, refParams); } } } @@ -1419,29 +1433,41 @@ for (Edge resToCh: resourceNode.getOutEdges()) { DataFlowEdge dOut = (DataFlowEdge) resToCh; DataTransferChannel ch2 = ((ChannelNode) resToCh.getDestination()).getChannel(); + // Check if the input resource is outside of the channel scope. boolean outsideInputResource2 = false; + ChannelMember in = null; Set outsideInputMembers2 = new HashSet<>(); for (ChannelMember cm: ch2.getInputChannelMembers()) { - if (cm.isOutside()) { - outsideInputMembers2.add(cm); - if (cm.getResource().equals(resourceNode.getOutSideResource())) { + if (cm.getResource().equals(resourceNode.getOutSideResource())) { + if (cm.isOutside()) { outsideInputResource2 = true; // Regarded as pull transfer. } + in = cm; + } + if (cm.isOutside()) { + outsideInputMembers2.add(cm); } } - if (((PushPullAttribute) dOut.getAttribute()).getOptions().get(0) == PushPullValue.PUSH && !outsideInputResource2) { - for (Edge chToRes: resToCh.getDestination().getOutEdges()) { - // PUSH transfer - ChannelMember in = null; - for (ChannelMember cm: ch2.getInputChannelMembers()) { - if (cm.getResource().equals(resourceNode.getOutSideResource())) { - in = cm; - break; - } + for (Edge chToRes: resToCh.getDestination().getOutEdges()) { + ResourceNode dstNode = ((ResourceNode) chToRes.getDestination()); + // Check if the output resource is outside of the channel scope. + boolean outsideOutputResource2 = false; + for (ChannelMember cm: ch2.getOutputChannelMembers()) { + if (dstNode.getInSideResources().contains(cm.getResource()) && cm.isOutside()) { + outsideOutputResource2 = true; } + } + if ((((PushPullAttribute) dOut.getAttribute()).getOptions().get(0) == PushPullValue.PUSH && !outsideInputResource2) || outsideOutputResource2) { + // PUSH transfer Map> referredResources = new HashMap<>(); List params = new ArrayList<>(); - params.add(langSpec.getFieldAccessor(fieldOfResourceState)); + ResourceHierarchy srcRes = resourceNode.getResourceHierarchy(); + if (generatesComponent(srcRes)) { + params.add(langSpec.getFieldAccessor(fieldOfResourceState)); + } else { + params.add(langSpec.getFieldAccessor(langSpec.toVariableName(srcRes.getResourceName()))); + srcRes = srcRes.getParent(); + } Set referredSet = referredResources.get(input); for (ChannelMember rc: ch2.getReferenceChannelMembers()) { // to get the value of reference member. @@ -1463,12 +1489,8 @@ params.add(refVarName); } } - ResourceHierarchy srcRes = resourceNode.getResourceHierarchy(); - if (!generatesComponent(srcRes)) { - srcRes = srcRes.getParent(); - } String updateMethodName = null; - ResourceHierarchy dstRes = ((ResourceNode) chToRes.getDestination()).getResourceHierarchy(); + ResourceHierarchy dstRes = dstNode.getResourceHierarchy(); if (!generatesComponent(dstRes)) { updateMethodName = updateMethodPrefix + getComponentName(dstRes, langSpec) + from + resComponentName; dstRes = dstRes.getParent(); @@ -1476,12 +1498,19 @@ updateMethodName = updateMethodPrefix + from + resComponentName; } String dstCompName = langSpec.toVariableName(getComponentName(dstRes, langSpec)); - if (srcRes != dstRes) { + if (!outsideOutputResource2) { + // The destination resource is not outside. + if (srcRes != dstRes) { + input.addStatement(langSpec.getMethodInvocation(langSpec.getFieldAccessor(dstCompName), updateMethodName, params) + + langSpec.getStatementDelimiter()); // this.dst.updateDstFromSrc(value, refParams); + } else { + input.addStatement(langSpec.getMethodInvocation(updateMethodName, params) + + langSpec.getStatementDelimiter()); // this.updateDstFromSrc(value, refParams); + } + } else { + // Use the reference field to refer to outside destination resource. input.addStatement(langSpec.getMethodInvocation(langSpec.getFieldAccessor(dstCompName), updateMethodName, params) + langSpec.getStatementDelimiter()); // this.dst.updateDstFromSrc(value, refParams); - } else { - input.addStatement(langSpec.getMethodInvocation(updateMethodName, params) - + langSpec.getStatementDelimiter()); // this.updateDstFromSrc(value, refParams); } } }