diff --git a/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java b/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java index 1be6a1d..45a82b9 100644 --- a/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java +++ b/AlgebraicDataflowArchitectureModel/src/algorithms/TypeInference.java @@ -379,7 +379,7 @@ } for (Term t : terms) { Symbol symbol = t.getSymbol(); - if (symbol.equals(DataConstraintModel.cons) || symbol.equals(DataConstraintModel.set)) { + if (symbol.equals(DataConstraintModel.cons) || symbol.equals(DataConstraintModel.set) || symbol.equals(DataConstraintModel.append)) { // If the root symbol of the term is cons or set. List consExps = new ArrayList<>(); consExps.add(t); // list term @@ -390,10 +390,18 @@ consExps.add(e); updateExpressionBelonging(expToConsOrSet, e, consExps); } + } else if (symbol.equals(DataConstraintModel.append)) { + // If the root symbol of the term is append. + Expression e = t.getChildren().get(1); + consExps.add(e); // list element + updateExpressionBelonging(expToConsOrSet, e, consExps); + e = t.getChildren().get(0); + consExps.add(e); // list argument + updateExpressionBelonging(expToConsOrSet, e, consExps); } else { // If the root symbol of the term is set. Expression e = t.getChildren().get(2); - consExps.add(e); // list component + consExps.add(e); // list element updateExpressionBelonging(expToConsOrSet, e, consExps); e = t.getChildren().get(0); consExps.add(e); // list argument @@ -401,7 +409,7 @@ } Type newType = getExpTypeIfUpdatable(t.getType(), consExps.get(2)); if (newType != null) { - // If the type of the 2nd argument of cons (1st argument of set) is more concrete than the type of the term. + // If the type of the 2nd argument of cons (1st argument of set/append) is more concrete than the type of the term. t.setType(newType); Map updateCons = getUpdateSet(updateFromConsOrSet, consExps); updateCons.put(System.identityHashCode(t), t); @@ -410,7 +418,7 @@ if (consExps.get(2) != null && consExps.get(2) instanceof Variable) { arg2Type = ((Variable) consExps.get(2)).getType(); if (compareTypes(arg2Type, t.getType())) { - // If the type of the term is more concrete than the type of the 2nd argument of cons (1st argument of set). + // If the type of the term is more concrete than the type of the 2nd argument of cons (1st argument of set/append). ((Variable) consExps.get(2)).setType(t.getType()); Map updateCons = getUpdateSet(updateFromConsOrSet, consExps); updateCons.put(System.identityHashCode(consExps.get(2)), consExps.get(2)); @@ -418,7 +426,7 @@ } else if (consExps.get(2) != null && consExps.get(2) instanceof Term) { arg2Type = ((Term) consExps.get(2)).getType(); if (compareTypes(arg2Type, t.getType())) { - // If the type of the term is more concrete than the type of the 2nd argument of cons (1st argument of set). + // If the type of the term is more concrete than the type of the 2nd argument of cons (1st argument of set/append). ((Term) consExps.get(2)).setType(t.getType()); Map updateCons = getUpdateSet(updateFromConsOrSet, consExps); updateCons.put(System.identityHashCode(consExps.get(2)), consExps.get(2)); @@ -815,6 +823,33 @@ } else { newCompTypeList.add(null); } + Type newTermType = getExpTypeIfUpdatable(termType, mapExps.get(3)); + if (newTermType != null) { + // If the type of the 1st argument of insert is more concrete than the type of the term. + t.setType(newTermType); + termType = newTermType; + Map updateExps = getUpdateSet(updateFromMap, mapExps); + updateExps.put(System.identityHashCode(t), t); + } else { + Type arg3Type = null; + if (mapExps.get(3) != null && mapExps.get(3) instanceof Variable) { + arg3Type = ((Variable) mapExps.get(3)).getType(); + if (compareTypes(arg3Type, t.getType())) { + // If the type of the term is more concrete than the type of the 1st argument of insert. + ((Variable) mapExps.get(3)).setType(t.getType()); + Map updateExps = getUpdateSet(updateFromMap, mapExps); + updateExps.put(System.identityHashCode(mapExps.get(3)), mapExps.get(3)); + } + } else if (mapExps.get(3) != null && mapExps.get(3) instanceof Term) { + arg3Type = ((Term) mapExps.get(3)).getType(); + if (compareTypes(arg3Type, t.getType())) { + // If the type of the term is more concrete than the type of the 1st argument of insert. + ((Term) mapExps.get(3)).setType(t.getType()); + Map updateExps = getUpdateSet(updateFromMap, mapExps); + updateExps.put(System.identityHashCode(mapExps.get(3)), mapExps.get(3)); + } + } + } if (termType == DataConstraintModel.typeMap || termType == null) { Type newMapType = mapTypes.get(newCompTypeList); if (newMapType == null) { @@ -823,9 +858,16 @@ } // Update the type of the map term and record the updated expression. t.setType(newMapType); - termType = newMapType; Map updateExps = getUpdateSet(updateFromMap, mapExps); updateExps.put(System.identityHashCode(t), t); + if (mapExps.get(3) != null && mapExps.get(3) instanceof Variable) { + ((Variable) mapExps.get(3)).setType(newMapType); + updateExps.put(System.identityHashCode(mapExps.get(3)), mapExps.get(3)); + } else if (mapExps.get(3) != null && mapExps.get(3) instanceof Term) { + ((Term) mapExps.get(3)).setType(newMapType); + updateExps.put(System.identityHashCode(mapExps.get(3)), mapExps.get(3)); + } + termType = newMapType; } map.put(System.identityHashCode(mapExps), termType); } else if (symbol.equals(DataConstraintModel.addMember)) { diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/SaveAsAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/SaveAsAction.java index 1a38b08..9542cdb 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/SaveAsAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/SaveAsAction.java @@ -65,9 +65,7 @@ lastDir = fc.getSelectedFile().getParent(); String fileName = fc.getSelectedFile().getAbsolutePath() + extension; - - // checking file duplicates - if(! (fc.getSelectedFile().exists())) editor.setCurFilePath(fileName); + editor.setCurFilePath(fileName); // overwriting file editor.save(); diff --git a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java index 66107cf..b0db12f 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java +++ b/AlgebraicDataflowArchitectureModel/src/application/editor/Editor.java @@ -235,15 +235,11 @@ return; } File file = new File(curFilePath); - if (!file.exists()) { - return; - } // get a file's extension String extension = file.getName().substring(file.getName().lastIndexOf(".")); if (extension.contains(".model")) { saveModel(file); - } - if (extension.contains(".dtram")) { + } else if (extension.contains(".dtram")) { saveDTRAM(file); } } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java index 14182ed..1fd7a65 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/CodeGeneratorFromDataFlowGraph.java @@ -237,46 +237,60 @@ return params; } - private void addUpdateStatementWithConstructorInvocationToMethod(MethodDeclaration method, Expression exp, ResourceHierarchy childRes, TypeDeclaration childComponent, ILanguageSpecific langSpec) { - Type replacedJsonType = childRes.getResourceStateType(); - String replacingClassName = getComponentName(childRes, langSpec); + private void addUpdateStatementWithConstructorInvocationToMethod(MethodDeclaration method, Expression exp, ResourceHierarchy descendantRes, TypeDeclaration descendantComponent, ILanguageSpecific langSpec) { + Type replacedJsonType = descendantRes.getResourceStateType(); + String replacingClassName = getComponentName(descendantRes, langSpec); + Type descendantType = new Type(replacingClassName, replacingClassName); Map subTerms = ((Term) exp).getSubTerms(Term.class); Iterator> termEntItr = subTerms.entrySet().iterator(); while (termEntItr.hasNext()) { Entry termEnt = termEntItr.next(); Term jsonTerm = termEnt.getValue(); - if (jsonTerm.getType() != null && jsonTerm.getType().equals(replacedJsonType)) { - if (jsonTerm instanceof JsonTerm || jsonTerm.getSymbol().equals(DataConstraintModel.addMember)) { - MethodDeclaration childConstructor = getConstructor(childComponent); - List params = new ArrayList<>(); - for (VariableDeclaration var: childConstructor.getParameters()) { - JsonAccessor jsonMember = new JsonAccessor(DataConstraintModel.dot); - jsonMember.addChild(jsonTerm); - jsonMember.addChild(new Constant(var.getName(), DataConstraintModel.typeString)); - Expression param = jsonMember.reduce(); - if (param != null) { - if (param instanceof Term) { - if (((Term) param).getType() == null) { - ((Term) param).setType(var.getType()); + if (jsonTerm.getType() != null) { + if (jsonTerm.getType().equals(replacedJsonType)) { + if (jsonTerm instanceof JsonTerm || jsonTerm.getSymbol().equals(DataConstraintModel.addMember)) { + MethodDeclaration childConstructor = getConstructor(descendantComponent); + List params = new ArrayList<>(); + for (VariableDeclaration var: childConstructor.getParameters()) { + JsonAccessor jsonMember = new JsonAccessor(DataConstraintModel.dot); + jsonMember.addChild(jsonTerm); + jsonMember.addChild(new Constant(var.getName(), DataConstraintModel.typeString)); + Expression param = jsonMember.reduce(); + if (param != null) { + if (param instanceof Term) { + if (((Term) param).getType() == null) { + ((Term) param).setType(var.getType()); + } + } else if (param instanceof Variable) { + if (((Variable) param).getType() == null) { + ((Variable) param).setType(var.getType()); + } } - } else if (param instanceof Variable) { - if (((Variable) param).getType() == null) { - ((Variable) param).setType(var.getType()); - } + params.add(param.toImplementation(null)); + } else { + params.add(var.getName()); } - params.add(param.toImplementation(null)); - } else { - params.add(var.getName()); } + ((Term) exp).replaceSubTerm(termEnt.getKey(), new Constant(langSpec.getConstructorInvocation(replacingClassName, params))); + subTerms = ((Term) exp).getSubTerms(Term.class); + termEntItr = subTerms.entrySet().iterator(); + } else { + jsonTerm.setType(descendantType); } - ((Term) exp).replaceSubTerm(termEnt.getKey(), new Constant(langSpec.getConstructorInvocation(replacingClassName, params))); - subTerms = ((Term) exp).getSubTerms(Term.class); - termEntItr = subTerms.entrySet().iterator(); + } else { + Type oldType = jsonTerm.getType(); + Type newType = new Type(oldType.getTypeName(), + oldType.getImplementationTypeName().replace(replacedJsonType.getInterfaceTypeName(), replacingClassName), + oldType.getInterfaceTypeName().replace(replacedJsonType.getInterfaceTypeName(), replacingClassName)); + for (Type parent: oldType.getParentTypes()) { + newType.addParentType(parent); + } + jsonTerm.setType(newType); } } } // Replace the type of the state field. - Type fieldType = getImplStateType(childRes.getParent(), langSpec); + Type fieldType = getImplStateType(descendantRes.getParent(), langSpec); if (exp instanceof Term) { ((Term) exp).setType(fieldType); for (Map.Entry varEnt: ((Term) exp).getVariables().entrySet()) { diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java index c104e9c..59de1bd 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JavaMethodBodyGenerator.java @@ -889,42 +889,56 @@ return codes; } - private static void replaceJsonTermWithConstructorInvocation(Expression exp, Type replacedJsonType, String replacingClassName, TypeDeclaration childComponent) { + private static void replaceJsonTermWithConstructorInvocation(Expression exp, Type replacedJsonType, String replacingClassName, TypeDeclaration descendantComponent) { + Type descendantType = new Type(replacingClassName, replacingClassName); Map subTerms = ((Term) exp).getSubTerms(Term.class); Iterator> termEntItr = subTerms.entrySet().iterator(); while (termEntItr.hasNext()) { Entry termEnt = termEntItr.next(); Term jsonTerm = termEnt.getValue(); - if (jsonTerm.getType() != null && jsonTerm.getType().equals(replacedJsonType)) { - if (jsonTerm instanceof JsonTerm || jsonTerm.getSymbol().equals(DataConstraintModel.addMember)) { - String constructorInvocation = "new " + replacingClassName + "("; - MethodDeclaration childConstructor = getConstructor(childComponent); - String delimiter = ""; - for (VariableDeclaration var: childConstructor.getParameters()) { - JsonAccessor jsonMember = new JsonAccessor(DataConstraintModel.dot); - jsonMember.addChild(jsonTerm); - jsonMember.addChild(new Constant(var.getName(), DataConstraintModel.typeString)); - Expression param = jsonMember.reduce(); - if (param != null) { - if (param instanceof Term) { - if (((Term) param).getType() == null) { - ((Term) param).setType(var.getType()); + if (jsonTerm.getType() != null) { + if (jsonTerm.getType().equals(replacedJsonType)) { + if (jsonTerm instanceof JsonTerm || jsonTerm.getSymbol().equals(DataConstraintModel.addMember)) { + String constructorInvocation = "new " + replacingClassName + "("; + MethodDeclaration descendantConstructor = getConstructor(descendantComponent); + String delimiter = ""; + for (VariableDeclaration var: descendantConstructor.getParameters()) { + JsonAccessor jsonMember = new JsonAccessor(DataConstraintModel.dot); + jsonMember.addChild(jsonTerm); + jsonMember.addChild(new Constant(var.getName(), DataConstraintModel.typeString)); + Expression param = jsonMember.reduce(); + if (param != null) { + if (param instanceof Term) { + if (((Term) param).getType() == null) { + ((Term) param).setType(var.getType()); + } + } else if (param instanceof Variable) { + if (((Variable) param).getType() == null) { + ((Variable) param).setType(var.getType()); + } } - } else if (param instanceof Variable) { - if (((Variable) param).getType() == null) { - ((Variable) param).setType(var.getType()); - } + constructorInvocation = constructorInvocation + delimiter + param.toImplementation(null); + } else { + constructorInvocation = constructorInvocation + delimiter + var.getName(); } - constructorInvocation = constructorInvocation + delimiter + param.toImplementation(null); - } else { - constructorInvocation = constructorInvocation + delimiter + var.getName(); + delimiter = ", "; } - delimiter = ", "; + constructorInvocation += ")"; + ((Term) exp).replaceSubTerm(termEnt.getKey(), new Constant(constructorInvocation, descendantType)); + subTerms = ((Term) exp).getSubTerms(Term.class); + termEntItr = subTerms.entrySet().iterator(); + } else { + jsonTerm.setType(descendantType); } - constructorInvocation += ")"; - ((Term) exp).replaceSubTerm(termEnt.getKey(), new Constant(constructorInvocation)); - subTerms = ((Term) exp).getSubTerms(Term.class); - termEntItr = subTerms.entrySet().iterator(); + } else { + Type oldType = jsonTerm.getType(); + Type newType = new Type(oldType.getTypeName(), + oldType.getImplementationTypeName().replace(replacedJsonType.getInterfaceTypeName(), replacingClassName), + oldType.getInterfaceTypeName().replace(replacedJsonType.getInterfaceTypeName(), replacingClassName)); + for (Type parent: oldType.getParentTypes()) { + newType.addParentType(parent); + } + jsonTerm.setType(newType); } } } diff --git a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java index 1e4b295..47f4e58 100644 --- a/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java +++ b/AlgebraicDataflowArchitectureModel/src/generators/JerseyMethodBodyGenerator.java @@ -1010,42 +1010,56 @@ return codes; } - private static void replaceJsonTermWithConstructorInvocation(Expression exp, Type replacedJsonType, String replacingClassName, TypeDeclaration childComponent) { + private static void replaceJsonTermWithConstructorInvocation(Expression exp, Type replacedJsonType, String replacingClassName, TypeDeclaration descendantComponent) { + Type descendantType = new Type(replacingClassName, replacingClassName); Map subTerms = ((Term) exp).getSubTerms(Term.class); Iterator> termEntItr = subTerms.entrySet().iterator(); while (termEntItr.hasNext()) { Entry termEnt = termEntItr.next(); Term jsonTerm = termEnt.getValue(); - if (jsonTerm.getType() != null && jsonTerm.getType().equals(replacedJsonType)) { - if (jsonTerm instanceof JsonTerm || jsonTerm.getSymbol().equals(DataConstraintModel.addMember)) { - String constructorInvocation = "new " + replacingClassName + "("; - MethodDeclaration childConstructor = getConstructor(childComponent); - String delimiter = ""; - for (VariableDeclaration var: childConstructor.getParameters()) { - JsonAccessor jsonMember = new JsonAccessor(DataConstraintModel.dot); - jsonMember.addChild(jsonTerm); - jsonMember.addChild(new Constant(var.getName(), DataConstraintModel.typeString)); - Expression param = jsonMember.reduce(); - if (param != null) { - if (param instanceof Term) { - if (((Term) param).getType() == null) { - ((Term) param).setType(var.getType()); + if (jsonTerm.getType() != null) { + if (jsonTerm.getType().equals(replacedJsonType)) { + if (jsonTerm instanceof JsonTerm || jsonTerm.getSymbol().equals(DataConstraintModel.addMember)) { + String constructorInvocation = "new " + replacingClassName + "("; + MethodDeclaration descendantConstructor = getConstructor(descendantComponent); + String delimiter = ""; + for (VariableDeclaration var: descendantConstructor.getParameters()) { + JsonAccessor jsonMember = new JsonAccessor(DataConstraintModel.dot); + jsonMember.addChild(jsonTerm); + jsonMember.addChild(new Constant(var.getName(), DataConstraintModel.typeString)); + Expression param = jsonMember.reduce(); + if (param != null) { + if (param instanceof Term) { + if (((Term) param).getType() == null) { + ((Term) param).setType(var.getType()); + } + } else if (param instanceof Variable) { + if (((Variable) param).getType() == null) { + ((Variable) param).setType(var.getType()); + } } - } else if (param instanceof Variable) { - if (((Variable) param).getType() == null) { - ((Variable) param).setType(var.getType()); - } + constructorInvocation = constructorInvocation + delimiter + param.toImplementation(null); + } else { + constructorInvocation = constructorInvocation + delimiter + var.getName(); } - constructorInvocation = constructorInvocation + delimiter + param.toImplementation(null); - } else { - constructorInvocation = constructorInvocation + delimiter + var.getName(); + delimiter = ", "; } - delimiter = ", "; + constructorInvocation += ")"; + ((Term) exp).replaceSubTerm(termEnt.getKey(), new Constant(constructorInvocation)); + subTerms = ((Term) exp).getSubTerms(Term.class); + termEntItr = subTerms.entrySet().iterator(); + } else { + jsonTerm.setType(descendantType); } - constructorInvocation += ")"; - ((Term) exp).replaceSubTerm(termEnt.getKey(), new Constant(constructorInvocation)); - subTerms = ((Term) exp).getSubTerms(Term.class); - termEntItr = subTerms.entrySet().iterator(); + } else { + Type oldType = jsonTerm.getType(); + Type newType = new Type(oldType.getTypeName(), + oldType.getImplementationTypeName().replace(replacedJsonType.getInterfaceTypeName(), replacingClassName), + oldType.getInterfaceTypeName().replace(replacedJsonType.getInterfaceTypeName(), replacingClassName)); + for (Type parent: oldType.getParentTypes()) { + newType.addParentType(parent); + } + jsonTerm.setType(newType); } } } diff --git a/AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java b/AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java index 95c2b47..ac41269 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java +++ b/AlgebraicDataflowArchitectureModel/src/models/algebra/Term.java @@ -295,22 +295,23 @@ String component0 = components[0].replace("(", "").replace(")", ""); String[] params = component0.split(","); String exp = components[1]; + String receiver = ""; if (implParamOrder == null) { - for (int i = 0; i < params.length; i++) { + receiver = children.get(0).toImplementation(sideEffects); + exp = exp.replace(params[0], receiver); + for (int i = 1; i < params.length; i++) { exp = exp.replace(params[i], children.get(i).toImplementation(sideEffects)); } } else { - for (int i = 0; i < params.length; i++) { + receiver = children.get(implParamOrder[0]).toImplementation(sideEffects); + exp = exp.replace(params[0], receiver); + for (int i = 1; i < params.length; i++) { exp = exp.replace(params[i], children.get(implParamOrder[i]).toImplementation(sideEffects)); } } if (symbol.isImplWithSideEffect()) { sideEffects[0] = sideEffects[0] + exp + ";\n"; - if (implParamOrder == null) { - exp = children.get(0).toImplementation(new String[] {""}); - } else { - exp = children.get(implParamOrder[0]).toImplementation(new String[] {""}); - } + exp = receiver; } return exp; } @@ -333,7 +334,7 @@ String exp = symbol.generate(getType(), childrenTypes, childrenImpl, childrenSideEffects, sideEffects); if (symbol.isImplWithSideEffect()) { sideEffects[0] = sideEffects[0] + exp; - exp = children.get(0).toImplementation(new String[] {""}); // the value of this term + exp = childrenImpl[0]; // the value of this term } return exp; } else { @@ -351,7 +352,7 @@ String exp = symbol.generate(getType(), childrenTypes, childrenImpl, childrenSideEffects, sideEffects); if (symbol.isImplWithSideEffect()) { sideEffects[0] = sideEffects[0] + exp; - exp = children.get(implParamOrder[0]).toImplementation(new String[] {""}); // the value of this term + exp = childrenImpl[0]; // the value of this term } return exp; } @@ -360,14 +361,16 @@ if (implParamOrder == null) { return "(" + children.get(0).toImplementation(sideEffects) + symbol.toImplementation() + children.get(1).toImplementation(sideEffects) + ")"; } else { - return "(" + children.get(implParamOrder[0]).toImplementation(sideEffects) + symbol.toImplementation() + children.get(implParamOrder[1]).toImplementation(sideEffects) + ")"; + return "(" + children.get(implParamOrder[0]).toImplementation(sideEffects) + symbol.toImplementation() + children.get(implParamOrder[1]).toImplementation(sideEffects) + ")"; } } if ((getArity() >= 1 || getArity() == -1) && symbol.isImplMethod()) { if (implParamOrder == null) { String exp = null; + String receiver = ""; if (children.get(0) != null) { - exp = children.get(0).toImplementation(sideEffects) + "." + symbol.toImplementation() + "("; + receiver = children.get(0).toImplementation(sideEffects); + exp = receiver + "." + symbol.toImplementation() + "("; } else { exp = symbol.toImplementation() + "("; } @@ -380,15 +383,12 @@ exp += ")"; if (symbol.isImplWithSideEffect()) { sideEffects[0] = sideEffects[0] + exp + ";\n"; - if (children.get(0) != null) { - exp = children.get(0).toImplementation(new String[] {""}); - } else { - exp = ""; - } + exp = receiver; } return exp; } else { - String exp = children.get(implParamOrder[0]).toImplementation(sideEffects) + "." + symbol.toImplementation() + "("; + String receiver = children.get(implParamOrder[0]).toImplementation(sideEffects); + String exp = receiver + "." + symbol.toImplementation() + "("; String delimiter = ""; for (int i = 1; i < children.size(); i++) { Expression e = children.get(implParamOrder[i]); @@ -398,7 +398,7 @@ exp += ")"; if (symbol.isImplWithSideEffect()) { sideEffects[0] = sideEffects[0] + exp + ";\n"; - exp = children.get(implParamOrder[0]).toImplementation(new String[] {""}); + exp = receiver; } return exp; } diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index 3bdb1dd..555f07d 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -676,6 +676,7 @@ } }); public static final Symbol nil = new Symbol("nil", 0, Symbol.Type.PREFIX, new Symbol.IImplGenerator() { + final int count[] = {0}; @Override public String generate(Type type, Type[] childrenTypes, String[] children, String[] childrenSideEffects, String[] sideEffect) { String compType = ""; @@ -691,14 +692,18 @@ if (sideEffect == null) { return "new " + implType + "<>()"; } else { - String temp = "temp_nil"; - sideEffect[0] = interfaceType + " " + temp + " = " + "new " + implType + "<" + compType + ">();\n"; + String temp = "temp_nil" + count[0]; + if (sideEffect[0] == null) { + sideEffect[0] = ""; + } + sideEffect[0] += interfaceType + " " + temp + " = " + "new " + implType + "<" + compType + ">();\n"; + count[0]++; return temp; } } return "new ArrayList<" + compType + ">()"; } - }); + }, true); public static final Symbol null_ = new Symbol("null", 0, Symbol.Type.PREFIX, "null", Symbol.Type.PREFIX); public static final Symbol true_ = new Symbol("true", 0, Symbol.Type.PREFIX, "true", Symbol.Type.PREFIX); public static final Symbol false_ = new Symbol("false", 0, Symbol.Type.PREFIX, "false", Symbol.Type.PREFIX);