diff --git a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java index ab79447..2f99781 100644 --- a/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java +++ b/AlgebraicDataflowArchitectureModel/src/models/dataConstraintModel/DataConstraintModel.java @@ -151,7 +151,24 @@ public static final Symbol left = new Symbol("left", 1, Symbol.Type.PREFIX, "getLeft", Symbol.Type.METHOD); public static final Symbol right = new Symbol("right", 1, Symbol.Type.PREFIX, "getRight", Symbol.Type.METHOD); public static final Symbol insert = new Symbol("insert", 3, Symbol.Type.PREFIX, "put", Symbol.Type.METHOD_WITH_SIDE_EFFECT); - public static final Symbol lookup = new Symbol("lookup", 2, Symbol.Type.PREFIX, "get", Symbol.Type.METHOD); +// public static final Symbol lookup = new Symbol("lookup", 2, Symbol.Type.PREFIX, "get", Symbol.Type.METHOD); + public static final Symbol lookup = new Symbol("lookup", 2, Symbol.Type.PREFIX, new Symbol.IImplGenerator() { + final int count[] = {0}; + @Override + public String generate(Type type, String[] childrenImpl, String[] childrenSideEffects, String[] sideEffect) { + String temp = "temp_get" + count[0]; + String impl = childrenSideEffects[0] + childrenSideEffects[1]; + impl += type.getInterfaceTypeName() + " " + temp + ";\n"; + impl += "if (" + childrenImpl[0] + ".get(" + childrenImpl[1] + ") != null) {\n"; + impl += "\t" + temp + " = " + childrenImpl[0] + ".get(" + childrenImpl[1] + ");\n"; + impl += "} else {\n"; + impl += "\t" + temp + " = " + getDefaultValue(type) + ";\n"; + impl += "}\n"; + sideEffect[0] = impl; + count[0]++; + return temp; + } + }); static { add.setInverses(new Symbol[] {sub, sub}); @@ -340,6 +357,23 @@ public static boolean isListType(Type type) { return typeList.isAncestorOf(type); } + + public static String getDefaultValue(Type type) { + if (type == typeInt) { + return "0"; + } else if (type == typeLong) { + return "0L"; + } else if (type == typeFloat) { + return "0.0f"; + } else if (type == typeDouble) { + return "0.0"; + } else if (type == typeBoolean) { + return "false"; + } else if (type == typeString) { + return "\"\""; + } + return "new " + type.getImplementationTypeName() + "()"; + } @Override public String toString() {