diff --git a/AlgebraicDataflowArchitectureModel/models/Map.dtram b/AlgebraicDataflowArchitectureModel/models/Map.dtram new file mode 100644 index 0000000..b1fe577 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/models/Map.dtram @@ -0,0 +1,23 @@ +model { + channel GPS_In { + out longitude(prev_long: Double, updateGPS(cur_long, cur_lat)) == cur_long + out latitude(prev_lat: Double, updateGPS(cur_long, cur_lat)) == cur_lat + } + channel LongUpdate { + in longitude(prev_long, updateLong(cur_long)) == cur_long + out mapLongitude(prev_mapLong, updateLong(cur_long)) == cur_long + } + channel LatUpdate { + in latitude(prev_lat, updateLat(cur_lat)) == cur_lat + out mapLatitude(prev_mapLat, updateLat(cur_lat)) == cur_lat + } +} +geometry { + node r mapLatitude:580,310,80,30 + node r latitude:190,310,80,30 + node r mapLongitude:580,170,80,30 + node r longitude:190,170,80,30 + node ioc GPS_In:40,60,30,30 + node c LongUpdate:410,170,30,30 + node c LatUpdate:410,310,30,30 +} diff --git a/AlgebraicDataflowArchitectureModel/models/Map.model b/AlgebraicDataflowArchitectureModel/models/Map.model new file mode 100644 index 0000000..2ea85ff --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/models/Map.model @@ -0,0 +1,14 @@ +channel GPS_In { + out longitude(prev_long: Double, updateGPS(cur_long, cur_lat)) == cur_long + out latitude(prev_lat: Double, updateGPS(cur_long, cur_lat)) == cur_lat +} + +channel LongUpdate { + in longitude(prev_long, updateLong(cur_long)) == cur_long + out mapLongitude(prev_mapLong, updateLong(cur_long)) == cur_long +} + +channel LatUpdate { + in latitude(prev_lat, updateLat(cur_lat)) == cur_lat + out mapLatitude(prev_mapLat, updateLat(cur_lat)) == cur_lat +} diff --git a/AlgebraicDataflowArchitectureModel/models/SSDStore.dtram b/AlgebraicDataflowArchitectureModel/models/SSDStore.dtram new file mode 100644 index 0000000..0b7aeb1 --- /dev/null +++ b/AlgebraicDataflowArchitectureModel/models/SSDStore.dtram @@ -0,0 +1,33 @@ +model { + channel capacity_In { + out capacity(prev_capacity:Int, setCapacity(cur_capacity)) == cur_capacity + } + channel price_In { + out price(prev_price:Int, setPrice(cur_price)) == cur_price + } + channel siteA_Add { + out siteA(prev_products:List, addProduct(price:Int, capacity:Int)) == cons({"price": price, "capacity": capacity}, prev_products) + } + channel capacity_Update { + in siteA(prev_products:List, updateList(cur_products, cur_capacity)) == cur_products + in capacity(prev_capacity:Int, updateList(cur_products, cur_capacity)) == cur_capacity + out itemsByCapacity(prev_items:List, updateList(cur_products, cur_capacity)) == selectGE(cur_products, "capacity", cur_capacity) + } + channel price_Update { + in siteA(prev_products:List, updateList(cur_products, cur_price)) == cur_products + in price(prev_price:Int, updateList(cur_products, cur_price)) == cur_price + out itemsByPrice(prev_items:List, updateList(cur_products, cur_price)) == selectLE(cur_products, "price", cur_price) + } +} +geometry { + node r price:250,40,80,30 + node r itemsByPrice:650,110,80,30 + node r itemsByCapacity:650,280,80,30 + node r siteA:250,200,80,30 + node r capacity:250,370,80,30 + node ioc capacity_In:100,370,30,30 + node ioc price_In:100,40,30,30 + node ioc siteA_Add:100,200,30,30 + node c capacity_Update:500,280,30,30 + node c price_Update:500,110,30,30 +} diff --git a/AlgebraicDataflowArchitectureModel/models/SSDStore.model b/AlgebraicDataflowArchitectureModel/models/SSDStore.model index ced0165..a8a0bbf 100644 --- a/AlgebraicDataflowArchitectureModel/models/SSDStore.model +++ b/AlgebraicDataflowArchitectureModel/models/SSDStore.model @@ -1,23 +1,23 @@ -channel capacityIn { - out capacity(cap:int, setCapacity(cap2)) == cap2 +channel capacity_In { + out capacity(prev_capacity:Int, setCapacity(cur_capacity)) == cur_capacity } -channel priceIn { - out price(pri:int, setPrice(pri2)) == pri2 +channel price_In { + out price(prev_price:Int, setPrice(cur_price)) == cur_price } -channel siteAIn { - out siteAProducts(pro:List, addProduct(price:Int, capacity:Int)) == cons({"price": price, "capacity": capacity}, pro) +channel siteA_Add { + out siteA(prev_products:List, addProduct(price:Int, capacity:Int)) == cons({"price": price, "capacity": capacity}, prev_products) } -channel capacityUpdate { - in siteAProducts(pro:List, updateList(pro2, cap2)) == pro2 - in capacity(cap:int, updateList(pro2, cap2)) == cap2 - out itemsByCapacity(items:List, updateList(pro2, cap2)) == selectGE(pro2, "capacity", cap2) +channel capacity_Update { + in siteA(prev_products:List, updateList(cur_products, cur_capacity)) == cur_products + in capacity(prev_capacity:Int, updateList(cur_products, cur_capacity)) == cur_capacity + out itemsByCapacity(prev_items:List, updateList(cur_products, cur_capacity)) == selectGE(cur_products, "capacity", cur_capacity) } -channel priceUpdate { - in siteAProducts(pro:List, updateList(pro2, pri2)) == pro2 - in price(pri:int, updateList(pro2, pri2)) == pri2 - out itemsByPrice(items:List, updateList(pro2, pri2)) == selectLE(pro2, "price", pri2) +channel price_Update { + in siteA(prev_products:List, updateList(cur_products, cur_price)) == cur_products + in price(prev_price:Int, updateList(cur_products, cur_price)) == cur_price + out itemsByPrice(prev_items:List, updateList(cur_products, cur_price)) == selectLE(cur_products, "price", cur_price) } \ No newline at end of file diff --git a/AlgebraicDataflowArchitectureModel/resources/locales/en.properties b/AlgebraicDataflowArchitectureModel/resources/locales/en.properties index 674af3e..93ea088 100644 --- a/AlgebraicDataflowArchitectureModel/resources/locales/en.properties +++ b/AlgebraicDataflowArchitectureModel/resources/locales/en.properties @@ -40,5 +40,5 @@ # PopUp Actions changeCallOrder=Change Call Order -insertMediator=Produce Mediator +insertMediator=Introduce Mediator dependsOnMediator=Depends On Mediator diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java b/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java index a18b3c1..9b3ca65 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java @@ -848,7 +848,7 @@ newJsonType = createNewJsonType(newMemberTypes, DataConstraintModel.typeJson); } } - if (jsonType != newJsonType && newJsonType != null) { + if (jsonType != newJsonType && newJsonType != null && !newJsonType.isAncestorOf(jsonType)) { // Update the type of the json term and record the updated expression. t.setType(newJsonType); jsonType = newJsonType; @@ -888,7 +888,7 @@ newJsonType = createNewJsonType(newMemberTypes, DataConstraintModel.typeJson); } } - if (jsonType != newJsonType && newJsonType != null) { + if (jsonType != newJsonType && newJsonType != null && !newJsonType.isAncestorOf(jsonType)) { // Update the type of the json argument and record the updated expression. if (jsonArg instanceof Variable) { ((Variable) jsonArg).setType(newJsonType); @@ -946,7 +946,7 @@ } } } - if (jsonType != newJsonType && newJsonType != null) { + if (jsonType != newJsonType && newJsonType != null && !newJsonType.isAncestorOf(jsonType)) { // Update the type of the json argument and record the updated expression. if (jsonArg instanceof Variable) { ((Variable) jsonArg).setType(newJsonType); diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java index 315a158..4ccaf6d 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGenerator.java @@ -14,6 +14,7 @@ import code.ast.FieldDeclaration; import code.ast.MethodDeclaration; import code.ast.TypeDeclaration; +import code.ast.VariableDeclaration; import models.Edge; import models.Node; import models.algebra.Expression; @@ -182,8 +183,8 @@ orderedList.add(0, curNodeSet); } - protected void updateMainComponent(DataTransferModel model, TypeDeclaration mainType, MethodDeclaration mainConstructor, Node componentNode, - final List depends, ILanguageSpecific langSpec) { + protected void updateMainComponent(TypeDeclaration mainType, MethodDeclaration mainConstructor, Node componentNode, + MethodDeclaration constructor, ILanguageSpecific langSpec) { // Declare the field to refer to each object in the main type. ResourceNode resNode = null; String nodeName = null; @@ -204,24 +205,9 @@ } // Add a statement to instantiate each object to the main constructor. List parameters = new ArrayList<>(); - 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 (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(); - parameters.add(refResName); - } - } - } + if (constructor.getParameters() != null) { + for (VariableDeclaration var: constructor.getParameters()) { + parameters.add(var.getName()); } } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromControlFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromControlFlowGraph.java index 261e4dc..16c59be 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromControlFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromControlFlowGraph.java @@ -99,7 +99,7 @@ } // Update the main component for this component. - updateMainComponent(model, mainComponent, mainConstructor, componentNode, depends, langSpec); + updateMainComponent(mainComponent, mainConstructor, componentNode, constructor, langSpec); if (constructor.getParameters() == null) { component.removeMethod(constructor); } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java index 4de8146..ce5ab0c 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java @@ -54,7 +54,7 @@ MethodDeclaration constructor = declareConstructorAndFieldsToReferToResources(resourceNode, component, depends, langSpec); // Update the main component for this component. - updateMainComponent(model, mainComponent, mainConstructor, componentNode, depends, langSpec); + updateMainComponent(mainComponent, mainConstructor, componentNode, constructor, langSpec); ResourcePath res = resourceNode.getResource(); Type resStateType = res.getResourceStateType(); diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ModelExtension.java b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ModelExtension.java index d8aa4af..54a5c98 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ModelExtension.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataFlowModel/ModelExtension.java @@ -10,6 +10,8 @@ private static Symbol.Memento mergeMem; private static Symbol.Memento extractFaceDownMem; private static Symbol.Memento sortByKeyMem; + private static Symbol.Memento selectGEMem; + private static Symbol.Memento selectLEMem; public static void extendModel(DataTransferModel model) { Symbol floor = model.getSymbol("floor"); @@ -57,7 +59,7 @@ merge.setGenerator(new Symbol.IImplGenerator() { @Override public String generate(Type type, String[] childrenImpl, String[] childrenSideEffects, String[] sideEffect) { - String implType = "Arrayist<>"; + String implType = "ArrayList<>"; String interfaceType = "List"; String compType = "Integer"; if (type != null) { @@ -119,7 +121,7 @@ Symbol sortByKey = model.getSymbol("sortByKey"); sortByKeyMem = null; - if(sortByKey != null) { + if (sortByKey != null) { sortByKeyMem = sortByKey.createMemento(); sortByKey.setArity(1); sortByKey.setGenerator(new Symbol.IImplGenerator() { @@ -148,6 +150,64 @@ sortByKey.setSignature(new Type[] {DataConstraintModel.typeList, DataConstraintModel.typeList}); sortByKey.setImplOperatorType(Symbol.Type.GENERATIVE); } + + Symbol selectGE = model.getSymbol("selectGE"); + selectGEMem = null; + if (selectGE != null) { + final int[] count = new int[] {0}; + selectGE.setArity(3); + selectGEMem = selectGE.createMemento(); + selectGE.setGenerator(new Symbol.IImplGenerator() { + @Override + public String generate(Type type, String[] childrenImpl, String[] childrenSideEffects, String[] sideEffect) { + String implType = "ArrayList<>"; + String interfaceType = "List>"; + count[0]++; + String impl = ""; + impl += "" + interfaceType + " temp_l" + count[0] + " = new " + implType + "();\n"; + impl += "{\n"; + impl += "\tfor (Map item: " + childrenImpl[0] + ") {\n"; + impl += "\t\tif ((Integer) item.get(" + childrenImpl[1] + ") >= " + childrenImpl[2] + ") {\n"; + impl += "\t\t\ttemp_l" + count[0] + ".add(item);\n"; + impl += "\t\t}\n"; + impl += "\t}\n"; + impl += "}\n"; + sideEffect[0] = sideEffect[0] + impl; + return "temp_l" + count[0]; + } + }); + selectGE.setSignature(new Type[] {DataConstraintModel.typeList, DataConstraintModel.typeList, DataConstraintModel.typeString, DataConstraintModel.typeInt}); + selectGE.setImplOperatorType(Symbol.Type.GENERATIVE); + } + + Symbol selectLE = model.getSymbol("selectLE"); + selectLEMem = null; + if (selectLE != null) { + final int[] count = new int[] {0}; + selectLE.setArity(3); + selectLEMem = selectLE.createMemento(); + selectLE.setGenerator(new Symbol.IImplGenerator() { + @Override + public String generate(Type type, String[] childrenImpl, String[] childrenSideEffects, String[] sideEffect) { + String implType = "ArrayList<>"; + String interfaceType = "List>"; + count[0]++; + String impl = ""; + impl += "" + interfaceType + " temp_l" + count[0] + " = new " + implType + "();\n"; + impl += "{\n"; + impl += "\tfor (Map item: " + childrenImpl[0] + ") {\n"; + impl += "\t\tif ((Integer) item.get(" + childrenImpl[1] + ") <= " + childrenImpl[2] + ") {\n"; + impl += "\t\t\ttemp_l" + count[0] + ".add(item);\n"; + impl += "\t\t}\n"; + impl += "\t}\n"; + impl += "}\n"; + sideEffect[0] = sideEffect[0] + impl; + return "temp_l" + count[0]; + } + }); + selectLE.setSignature(new Type[] {DataConstraintModel.typeList, DataConstraintModel.typeList, DataConstraintModel.typeString, DataConstraintModel.typeInt}); + selectLE.setImplOperatorType(Symbol.Type.GENERATIVE); + } } public static void recoverModel(DataTransferModel model) { @@ -161,5 +221,9 @@ if (extractFaceDown != null) extractFaceDown.setMemento(extractFaceDownMem); Symbol sortByKey = model.getSymbol("sortByKey"); if (sortByKey != null) sortByKey.setMemento(sortByKeyMem); + Symbol selectGE = model.getSymbol("selectGE"); + if (selectGE != null) selectGE.setMemento(selectGEMem); + Symbol selectLE = model.getSymbol("selectLE"); + if (selectLE != null) selectLE.setMemento(selectLEMem); } }