diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index 555f07d..26205c8 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -67,16 +67,22 @@ Constant arg1 = (Constant) args.get(1); String sArg0 = arg0.getSymbol().toString(); String sArg1 = arg1.getSymbol().toString(); - if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { + if (arg0.getType() != null && arg1.getType() != null) { + if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { + return new Constant(Double.toString(Double.parseDouble(sArg0) + Double.parseDouble(sArg1)), typeDouble); + } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { + return new Constant(Float.toString(Float.parseFloat(sArg0) + Float.parseFloat(sArg1)), typeFloat); + } else if (arg0.getType().equals(typeLong) || arg1.getType().equals(typeLong)) { + return new Constant(Long.toString(Long.parseLong(sArg0) + Long.parseLong(sArg1)), typeLong); + } else if (arg0.getType().equals(typeInt) || arg1.getType().equals(typeInt)) { + return new Constant(Integer.toString(Integer.parseInt(sArg0) + Integer.parseInt(sArg1)), typeInt); + } + } + if (sArg0.contains(Parser.DOT) || sArg1.contains(Parser.DOT)) { return new Constant(Double.toString(Double.parseDouble(sArg0) + Double.parseDouble(sArg1)), typeDouble); - } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { - return new Constant(Float.toString(Float.parseFloat(sArg0) + Float.parseFloat(sArg1)), typeFloat); - } else if (arg0.getType().equals(typeLong) || arg1.getType().equals(typeLong)) { - return new Constant(Long.toString(Long.parseLong(sArg0) + Long.parseLong(sArg1)), typeLong); - } else if (arg0.getType().equals(typeInt) || arg1.getType().equals(typeInt)) { + } else { return new Constant(Integer.toString(Integer.parseInt(sArg0) + Integer.parseInt(sArg1)), typeInt); } - return new Constant(Integer.toString(Integer.parseInt(sArg0) + Integer.parseInt(sArg1))); } }); public static final Symbol mul = new Symbol(Parser.MUL, 2, Symbol.Type.INFIX, new Symbol.ICalculator() { @@ -92,16 +98,22 @@ Constant arg1 = (Constant) args.get(1); String sArg0 = arg0.getSymbol().toString(); String sArg1 = arg1.getSymbol().toString(); - if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { + if (arg0.getType() != null && arg1.getType() != null) { + if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { + return new Constant(Double.toString(Double.parseDouble(sArg0) * Double.parseDouble(sArg1)), typeDouble); + } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { + return new Constant(Float.toString(Float.parseFloat(sArg0) * Float.parseFloat(sArg1)), typeFloat); + } else if (arg0.getType().equals(typeLong) || arg1.getType().equals(typeLong)) { + return new Constant(Long.toString(Long.parseLong(sArg0) * Long.parseLong(sArg1)), typeLong); + } else if (arg0.getType().equals(typeInt) || arg1.getType().equals(typeInt)) { + return new Constant(Integer.toString(Integer.parseInt(sArg0) * Integer.parseInt(sArg1)), typeInt); + } + } + if (sArg0.contains(Parser.DOT) || sArg1.contains(Parser.DOT)) { return new Constant(Double.toString(Double.parseDouble(sArg0) * Double.parseDouble(sArg1)), typeDouble); - } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { - return new Constant(Float.toString(Float.parseFloat(sArg0) * Float.parseFloat(sArg1)), typeFloat); - } else if (arg0.getType().equals(typeLong) || arg1.getType().equals(typeLong)) { - return new Constant(Long.toString(Long.parseLong(sArg0) * Long.parseLong(sArg1)), typeLong); - } else if (arg0.getType().equals(typeInt) || arg1.getType().equals(typeInt)) { + } else { return new Constant(Integer.toString(Integer.parseInt(sArg0) * Integer.parseInt(sArg1)), typeInt); } - return new Constant(Integer.toString(Integer.parseInt(sArg0) * Integer.parseInt(sArg1))); } }); public static final Symbol sub = new Symbol(Parser.SUB, 2, Symbol.Type.INFIX, new Symbol.ICalculator() { @@ -117,16 +129,22 @@ Constant arg1 = (Constant) args.get(1); String sArg0 = arg0.getSymbol().toString(); String sArg1 = arg1.getSymbol().toString(); - if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { + if (arg0.getType() != null && arg1.getType() != null) { + if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { + return new Constant(Double.toString(Double.parseDouble(sArg0) - Double.parseDouble(sArg1)), typeDouble); + } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { + return new Constant(Float.toString(Float.parseFloat(sArg0) - Float.parseFloat(sArg1)), typeFloat); + } else if (arg0.getType().equals(typeLong) || arg1.getType().equals(typeLong)) { + return new Constant(Long.toString(Long.parseLong(sArg0) - Long.parseLong(sArg1)), typeLong); + } else if (arg0.getType().equals(typeInt) || arg1.getType().equals(typeInt)) { + return new Constant(Integer.toString(Integer.parseInt(sArg0) - Integer.parseInt(sArg1)), typeInt); + } + } + if (sArg0.contains(Parser.DOT) || sArg1.contains(Parser.DOT)) { return new Constant(Double.toString(Double.parseDouble(sArg0) - Double.parseDouble(sArg1)), typeDouble); - } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { - return new Constant(Float.toString(Float.parseFloat(sArg0) - Float.parseFloat(sArg1)), typeFloat); - } else if (arg0.getType().equals(typeLong) || arg1.getType().equals(typeLong)) { - return new Constant(Long.toString(Long.parseLong(sArg0) - Long.parseLong(sArg1)), typeLong); - } else if (arg0.getType().equals(typeInt) || arg1.getType().equals(typeInt)) { + } else { return new Constant(Integer.toString(Integer.parseInt(sArg0) - Integer.parseInt(sArg1)), typeInt); } - return new Constant(Integer.toString(Integer.parseInt(sArg0) - Integer.parseInt(sArg1))); } }); public static final Symbol div = new Symbol(Parser.DIV, 2, Symbol.Type.INFIX, new Symbol.ICalculator() { @@ -142,16 +160,22 @@ Constant arg1 = (Constant) args.get(1); String sArg0 = arg0.getSymbol().toString(); String sArg1 = arg1.getSymbol().toString(); - if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { + if (arg0.getType() != null && arg1.getType() != null) { + if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { + return new Constant(Double.toString(Double.parseDouble(sArg0) / Double.parseDouble(sArg1)), typeDouble); + } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { + return new Constant(Float.toString(Float.parseFloat(sArg0) / Float.parseFloat(sArg1)), typeFloat); + } else if (arg0.getType().equals(typeLong) || arg1.getType().equals(typeLong)) { + return new Constant(Long.toString(Long.parseLong(sArg0) / Long.parseLong(sArg1)), typeLong); + } else if (arg0.getType().equals(typeInt) || arg1.getType().equals(typeInt)) { + return new Constant(Integer.toString(Integer.parseInt(sArg0) / Integer.parseInt(sArg1)), typeInt); + } + } + if (sArg0.contains(Parser.DOT) || sArg1.contains(Parser.DOT)) { return new Constant(Double.toString(Double.parseDouble(sArg0) / Double.parseDouble(sArg1)), typeDouble); - } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { - return new Constant(Float.toString(Float.parseFloat(sArg0) / Float.parseFloat(sArg1)), typeFloat); - } else if (arg0.getType().equals(typeLong) || arg1.getType().equals(typeLong)) { - return new Constant(Long.toString(Long.parseLong(sArg0) / Long.parseLong(sArg1)), typeLong); - } else if (arg0.getType().equals(typeInt) || arg1.getType().equals(typeInt)) { + } else { return new Constant(Integer.toString(Integer.parseInt(sArg0) / Integer.parseInt(sArg1)), typeInt); } - return new Constant(Integer.toString(Integer.parseInt(sArg0) / Integer.parseInt(sArg1))); } }); public static final Symbol mod = new Symbol(Parser.MOD, 2, Symbol.Type.INFIX, "%", Symbol.Type.INFIX, new Symbol.ICalculator() { @@ -167,10 +191,12 @@ Constant arg1 = (Constant) args.get(1); String sArg0 = arg0.getSymbol().toString(); String sArg1 = arg1.getSymbol().toString(); - if (arg0.getType().equals(typeLong) || arg1.getType().equals(typeLong)) { - return new Constant(Long.toString(Long.parseLong(sArg0) % Long.parseLong(sArg1)), typeLong); - } else if (arg0.getType().equals(typeInt) || arg1.getType().equals(typeInt)) { - return new Constant(Integer.toString(Integer.parseInt(sArg0) % Integer.parseInt(sArg1)), typeInt); + if (arg0.getType() != null && arg1.getType() != null) { + if (arg0.getType().equals(typeLong) || arg1.getType().equals(typeLong)) { + return new Constant(Long.toString(Long.parseLong(sArg0) % Long.parseLong(sArg1)), typeLong); + } else if (arg0.getType().equals(typeInt) || arg1.getType().equals(typeInt)) { + return new Constant(Integer.toString(Integer.parseInt(sArg0) % Integer.parseInt(sArg1)), typeInt); + } } return new Constant(Integer.toString(Integer.parseInt(sArg0) % Integer.parseInt(sArg1))); } @@ -183,16 +209,22 @@ } Constant arg = (Constant) args.get(0); String sArg = arg.getSymbol().toString(); - if (arg.getType().equals(typeDouble)) { + if (arg.getType() != null) { + if (arg.getType().equals(typeDouble)) { + return new Constant(Double.toString(-Double.parseDouble(sArg)), typeDouble); + } else if (arg.getType().equals(typeFloat)) { + return new Constant(Float.toString(-Float.parseFloat(sArg)), typeFloat); + } else if (arg.getType().equals(typeLong)) { + return new Constant(Long.toString(-Long.parseLong(sArg)), typeLong); + } else if (arg.getType().equals(typeInt)) { + return new Constant(Integer.toString(-Integer.parseInt(sArg)), typeInt); + } + } + if (sArg.contains(Parser.DOT)) { return new Constant(Double.toString(-Double.parseDouble(sArg)), typeDouble); - } else if (arg.getType().equals(typeFloat)) { - return new Constant(Float.toString(-Float.parseFloat(sArg)), typeFloat); - } else if (arg.getType().equals(typeLong)) { - return new Constant(Long.toString(-Long.parseLong(sArg)), typeLong); - } else if (arg.getType().equals(typeInt)) { + } else { return new Constant(Integer.toString(-Integer.parseInt(sArg)), typeInt); } - return new Constant(Integer.toString(-Integer.parseInt(sArg))); } }); public static final Symbol eq = new Symbol(Parser.EQ, 2, Symbol.Type.INFIX, new Symbol.IImplGenerator() { @@ -220,6 +252,13 @@ String sArg0 = arg0.getSymbol().toString(); String sArg1 = arg1.getSymbol().toString(); boolean result = false; + if (arg0.getType() == null || arg1.getType() == null) { + if (sArg0.contains(Parser.DOT) || sArg1.contains(Parser.DOT)) { + result = Double.parseDouble(sArg0) == Double.parseDouble(sArg1); + } else { + result = Integer.parseInt(sArg0) == Integer.parseInt(sArg1); + } + } if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { result = (Double.parseDouble(sArg0) == Double.parseDouble(sArg1)); } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { @@ -263,6 +302,13 @@ String sArg0 = arg0.getSymbol().toString(); String sArg1 = arg1.getSymbol().toString(); boolean result = false; + if (arg0.getType() == null || arg1.getType() == null) { + if (sArg0.contains(Parser.DOT) || sArg1.contains(Parser.DOT)) { + result = Double.parseDouble(sArg0) != Double.parseDouble(sArg1); + } else { + result = Integer.parseInt(sArg0) != Integer.parseInt(sArg1); + } + } if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { result = (Double.parseDouble(sArg0) != Double.parseDouble(sArg1)); } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { @@ -295,6 +341,13 @@ String sArg0 = arg0.getSymbol().toString(); String sArg1 = arg1.getSymbol().toString(); boolean result = false; + if (arg0.getType() == null || arg1.getType() == null) { + if (sArg0.contains(Parser.DOT) || sArg1.contains(Parser.DOT)) { + result = Double.parseDouble(sArg0) > Double.parseDouble(sArg1); + } else { + result = Integer.parseInt(sArg0) > Integer.parseInt(sArg1); + } + } if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { result = (Double.parseDouble(sArg0) > Double.parseDouble(sArg1)); } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { @@ -325,6 +378,13 @@ String sArg0 = arg0.getSymbol().toString(); String sArg1 = arg1.getSymbol().toString(); boolean result = false; + if (arg0.getType() == null || arg1.getType() == null) { + if (sArg0.contains(Parser.DOT) || sArg1.contains(Parser.DOT)) { + result = Double.parseDouble(sArg0) < Double.parseDouble(sArg1); + } else { + result = Integer.parseInt(sArg0) < Integer.parseInt(sArg1); + } + } if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { result = (Double.parseDouble(sArg0) < Double.parseDouble(sArg1)); } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { @@ -355,6 +415,13 @@ String sArg0 = arg0.getSymbol().toString(); String sArg1 = arg1.getSymbol().toString(); boolean result = false; + if (arg0.getType() == null || arg1.getType() == null) { + if (sArg0.contains(Parser.DOT) || sArg1.contains(Parser.DOT)) { + result = Double.parseDouble(sArg0) >= Double.parseDouble(sArg1); + } else { + result = Integer.parseInt(sArg0) >= Integer.parseInt(sArg1); + } + } if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { result = (Double.parseDouble(sArg0) >= Double.parseDouble(sArg1)); } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { @@ -385,6 +452,13 @@ String sArg0 = arg0.getSymbol().toString(); String sArg1 = arg1.getSymbol().toString(); boolean result = false; + if (arg0.getType() == null || arg1.getType() == null) { + if (sArg0.contains(Parser.DOT) || sArg1.contains(Parser.DOT)) { + result = Double.parseDouble(sArg0) <= Double.parseDouble(sArg1); + } else { + result = Integer.parseInt(sArg0) <= Integer.parseInt(sArg1); + } + } if (arg0.getType().equals(typeDouble) || arg1.getType().equals(typeDouble)) { result = (Double.parseDouble(sArg0) <= Double.parseDouble(sArg1)); } else if (arg0.getType().equals(typeFloat) || arg1.getType().equals(typeFloat)) { @@ -415,6 +489,7 @@ String sArg0 = arg0.getSymbol().toString(); String sArg1 = arg1.getSymbol().toString(); boolean result = false; + if (arg0.getType() == null || arg1.getType() == null) return null; if (arg0.getType().equals(typeBoolean) || arg1.getType().equals(typeBoolean)) { result = (Boolean.parseBoolean(sArg0) && Boolean.parseBoolean(sArg1)); } @@ -439,6 +514,7 @@ String sArg0 = arg0.getSymbol().toString(); String sArg1 = arg1.getSymbol().toString(); boolean result = false; + if (arg0.getType() == null || arg1.getType() == null) return null; if (arg0.getType().equals(typeBoolean) || arg1.getType().equals(typeBoolean)) { result = (Boolean.parseBoolean(sArg0) || Boolean.parseBoolean(sArg1)); } @@ -458,6 +534,7 @@ Constant arg0 = (Constant) args.get(0); String sArg0 = arg0.getSymbol().toString(); boolean result = false; + if (arg0.getType() == null) return null; if (arg0.getType().equals(typeBoolean)) { result = !Boolean.parseBoolean(sArg0); }