diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java index 7e4df1b..f944c69 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaCodeGenerator.java @@ -197,7 +197,7 @@ // Declare input methods in resources and the main type. for (ChannelGenerator cg : model.getIOChannelGenerators()) { - for (ChannelMember cm : cg.getChannelMembers()) { + for (ChannelMember cm : ((DataflowChannelGenerator) cg).getOutputChannelMembers()) { if (cm.getIdentifierTemplate().equals(rn.getIdentifierTemplate())) { Expression message = cm.getStateTransition().getMessageExpression(); if (message.getClass() == Term.class) { diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaMethodBodyGenerator.java index b36ae42..2ffc04f 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/JavaMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/JavaMethodBodyGenerator.java @@ -109,7 +109,7 @@ String[] sideEffects = new String[] {""}; String refExp = refGetter.toImplementation(sideEffects); String refTypeName = ref.getResourceStateType().getInterfaceTypeName(); - srcUpdate.addStatement(sideEffects[0] + refTypeName + " " + refVarName + " = " + refExp + ";"); + srcUpdate.addFirstStatement(sideEffects[0] + refTypeName + " " + refVarName + " = " + refExp + ";"); } refParams += ", " + refVarName; } @@ -134,7 +134,7 @@ String[] sideEffects = new String[] {""}; String refExp = refGetter.toImplementation(sideEffects); String refTypeName = ref.getResourceStateType().getInterfaceTypeName(); - srcInput.addStatement(sideEffects[0] + refTypeName + " " + refVarName + " = " + refExp + ";"); + srcInput.addFirstStatement(sideEffects[0] + refTypeName + " " + refVarName + " = " + refExp + ";"); } refParams += ", " + refVarName; } diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyCodeGenerator.java b/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyCodeGenerator.java index b6d8f0f..6c4fa72 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyCodeGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/JerseyCodeGenerator.java @@ -150,7 +150,7 @@ // Declare input methods in resources. for (ChannelGenerator cg : model.getIOChannelGenerators()) { - for (ChannelMember cm : cg.getChannelMembers()) { + for (ChannelMember cm : ((DataflowChannelGenerator) cg).getOutputChannelMembers()) { if (cm.getIdentifierTemplate().equals(rn.getIdentifierTemplate())) { Expression message = cm.getStateTransition().getMessageExpression(); if (message.getClass() == Term.class) { diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java b/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java index 706841f..e2be926 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java @@ -83,6 +83,7 @@ Map variables = new HashMap<>(); Map, Type>>> messages = new HashMap<>(); Map cons = new HashMap<>(); + Map get = new HashMap<>(); Map tuple = new HashMap<>(); Map pair = new HashMap<>(); Map map = new HashMap<>(); @@ -90,6 +91,7 @@ Map> expToVariable = new HashMap<>(); Map> expToMessage = new HashMap<>(); Map>> expToCons = new HashMap<>(); + Map>> expToGet = new HashMap<>(); Map>> expToTuple = new HashMap<>(); Map>> expToPair = new HashMap<>(); Map>> expToMap = new HashMap<>(); @@ -340,14 +342,25 @@ } for (Term t : terms) { Symbol symbol = t.getSymbol(); - if (symbol.equals(DataConstraintModel.cons)) { - // If the root symbol of the term is cons. + if (symbol.equals(DataConstraintModel.cons) || symbol.equals(DataConstraintModel.set)) { + // If the root symbol of the term is cons or set. List consExps = new ArrayList<>(); consExps.add(t); updateExpressionBelonging(expToCons, t, consExps); - for (Expression e : t.getChildren()) { + if (symbol.equals(DataConstraintModel.cons)) { + // If the root symbol of the term is cons. + for (Expression e : t.getChildren()) { + consExps.add(e); + updateExpressionBelonging(expToCons, e, consExps); + } + } else { + // If the root symbol of the term is set. + Expression e = t.getChildren().get(2); consExps.add(e); updateExpressionBelonging(expToCons, e, consExps); + e = t.getChildren().get(0); + consExps.add(e); + updateExpressionBelonging(expToCons, e, consExps); } Type newType = getExpTypeIfUpdatable(t.getType(), consExps.get(2)); if (newType != null) { @@ -399,6 +412,40 @@ } } cons.put(System.identityHashCode(consExps), t.getType()); + } else if (symbol.equals(DataConstraintModel.head) || symbol.equals(DataConstraintModel.get)) { + // If the root symbol of the term is head or get. + List consExps = new ArrayList<>(); + Expression e = t.getChildren().get(0); + consExps.add(e); + updateExpressionBelonging(expToCons, e, consExps); + consExps.add(t); + updateExpressionBelonging(expToCons, t, consExps); + consExps.add(null); + Type listType = listTypes.get(t.getType()); + if (listType == null) { + // Create a new list type. + listType = createNewListType(t.getType(), DataConstraintModel.typeList); + } + Type newListType = getExpTypeIfUpdatable(listType, consExps.get(0)); + if (newListType != null) { + // If the type of the component of the first argument is more concrete than the type of the term. + Type newCompType = listComponentTypes.get(newListType); + t.setType(newCompType); + Map updateCons = getUpdateSet(updateFromCons, consExps); + updateCons.put(System.identityHashCode(t), t); + } else { + // If the type of the term is more concrete than the type of the component of the first argument. + if (consExps.get(0) != null && consExps.get(0) instanceof Variable) { + ((Variable) consExps.get(0)).setType(listType); + Map updateCons = getUpdateSet(updateFromCons, consExps); + updateCons.put(System.identityHashCode(consExps.get(0)), consExps.get(0)); + } else if (consExps.get(0) != null && consExps.get(0) instanceof Term) { + ((Term) consExps.get(0)).setType(listType); + Map updateCons = getUpdateSet(updateFromCons, consExps); + updateCons.put(System.identityHashCode(consExps.get(0)), consExps.get(0)); + } + } + cons.put(System.identityHashCode(consExps), t.getType()); } else if (symbol.equals(DataConstraintModel.tuple)) { // If the root symbol of the term is tuple. List tupleExps = new ArrayList<>(); diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index 397a87b..1f6adab 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -184,6 +184,7 @@ cons.setSignature(new Type[] {typeList, null, typeList}); contains.setSignature(new Type[] {typeBoolean, typeList, null}); extractFaceDown.setSignature(new Type[] {typeList, null}); + sortByKey.setSignature(new Type[] {typeList, typeList}); length.setSignature(new Type[] {typeInt, null}); get.setSignature(new Type[] {null, typeList, typeInt}); set.setSignature(new Type[] {typeList, typeList, typeInt, null});