diff --git a/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java b/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java index 1b19ac6..3fb236f 100644 --- a/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java +++ b/AlgebraicDataflowArchitectureModel/src/simulator/SystemState.java @@ -283,6 +283,7 @@ } } ((ListResourceState) state).removeChildState(Integer.parseInt(childIdxExp.toString())); + createdResources.add(resourceIdentifier); return createdResources; } } @@ -322,27 +323,31 @@ MapTerm mapValue = (MapTerm) resNextStateVal; Resource res = getResource(resourceIdentifier); ResourceState state = res.getState(); - List createdResources = new ArrayList<>(); - for (String key: mapValue.keySet()) { - Expression childExp = new Constant(key, DataConstraintModel.typeString); - ResourceHierarchy childResourceHierarchy = null; - if (resourceIdentifier.getResourceHierarchy().getChildren() != null && resourceIdentifier.getResourceHierarchy().getChildren().size() > 0) { - childResourceHierarchy = resourceIdentifier.getResourceHierarchy().getChildren().iterator().next(); - } else { - Type childResType = null; - if (mapValue.get(key) instanceof Variable) { - childResType = ((Variable) mapValue.get(key)).getType(); - } else if (mapValue.get(key) instanceof Term) { - childResType = ((Term) mapValue.get(key)).getType(); + if (state instanceof MapResourceState) { + ((MapResourceState) state).clearChildStates(); + List createdResources = new ArrayList<>(); + for (String key: mapValue.keySet()) { + Expression childExp = new Constant(key, DataConstraintModel.typeString); + ResourceHierarchy childResourceHierarchy = null; + if (resourceIdentifier.getResourceHierarchy().getChildren() != null && resourceIdentifier.getResourceHierarchy().getChildren().size() > 0) { + childResourceHierarchy = resourceIdentifier.getResourceHierarchy().getChildren().iterator().next(); + } else { + Type childResType = null; + if (mapValue.get(key) instanceof Variable) { + childResType = ((Variable) mapValue.get(key)).getType(); + } else if (mapValue.get(key) instanceof Term) { + childResType = ((Term) mapValue.get(key)).getType(); + } + childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1, childResType); } - childResourceHierarchy = new ResourceHierarchy(resourceIdentifier.getResourceHierarchy(), 1, childResType); + ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); + Map.Entry> childInfo = createResourceState(childResourceIdentifier, curResVar, resCurStateVal, mapValue.get(key)); + ((MapResourceState) state).addChildState(key, childInfo.getKey()); + createdResources.addAll(childInfo.getValue()); } - ResourceIdentifier childResourceIdentifier = new ResourceIdentifier(resourceIdentifier, childExp, childResourceHierarchy); - Map.Entry> childInfo = createResourceState(childResourceIdentifier, curResVar, resCurStateVal, mapValue.get(key)); - ((MapResourceState) state).addChildState(key, childInfo.getKey()); - createdResources.addAll(childInfo.getValue()); + return createdResources; } - return createdResources; + return null; } else if (resNextStateVal instanceof Term) { Term mapValue = (Term) resNextStateVal; if (mapValue.getSymbol().equals(DataConstraintModel.insert)) { @@ -442,6 +447,7 @@ } String childId = (String) ((Constant) childKeyExp).getValue(); ((MapResourceState) state).removeChildState(childId); + createdResources.add(resourceIdentifier); return createdResources; } }