diff --git a/src/main/java/de/tlc4b/analysis/UnsupportedConstructsFinder.java b/src/main/java/de/tlc4b/analysis/UnsupportedConstructsFinder.java index 207a6ad2b6372714b019d6be54704386c971ea5d..15cca6529a0b4d8d6a6edb9a4993c29a5248a998 100644 --- a/src/main/java/de/tlc4b/analysis/UnsupportedConstructsFinder.java +++ b/src/main/java/de/tlc4b/analysis/UnsupportedConstructsFinder.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Set; import de.be4.classicalb.core.parser.analysis.DepthFirstAdapter; @@ -46,17 +47,20 @@ public class UnsupportedConstructsFinder extends DepthFirstAdapter { } private static final List<String> SUM_TYPE = new LinkedList<>( - Arrays.asList("model_clause", "machine_clause", "substitution", "machine_parse_unit")); + Arrays.asList("model_clause", "machine_clause", "machine_parse_unit", "substitution", "expression_expression", "expression", "predicate_predicate", "predicate")); - private String formatCamel(final String input) { + private String formatClassName(String input) { StringWriter out = new StringWriter(); char[] chars = input.toCharArray(); - for (char current : chars) { - if (Character.isUpperCase(current)) { - out.append('_'); - out.append(Character.toLowerCase(current)); + for (int i = 1; i < chars.length; i++) { + char c = chars[i]; + if (Character.isUpperCase(c)) { + if (i > 1) { + out.append('_'); + } + out.append(Character.toLowerCase(c)); } else { - out.append(current); + out.append(c); } } return out.toString(); @@ -64,20 +68,20 @@ public class UnsupportedConstructsFinder extends DepthFirstAdapter { public void defaultIn(Node node) { if (unsupportedClasses.contains(node.getClass())) { - final String formatedName = formatCamel(node.getClass().getSimpleName()); - final String className = node.getClass().getSimpleName(); - for (final String suffix : SUM_TYPE) { - if (formatedName.endsWith(suffix)) { - final String shortName = formatedName.substring(3, formatedName.length() - suffix.length() - 1) - .toUpperCase(); - final String[] split = suffix.split("_"); - final String type = split[split.length - 1]; - if (type.equals("clause") || type.equals("substitution")) { + String className = node.getClass().getSimpleName(); + String formattedName = formatClassName(className); + for (String suffix : SUM_TYPE) { + if (formattedName.endsWith("_" + suffix)) { + String shortName = formattedName.substring(0, formattedName.length() - suffix.length() - 1).toUpperCase(Locale.ROOT); + String[] split = suffix.split("_"); + String type = split[split.length - 1]; + if (type.equals("clause") || type.equals("substitution") || type.equals("expression") || type.equals("predicate")) { throw new NotSupportedException(shortName + " " + type + " is not supported."); + } else if (suffix.endsWith("parse_unit")) { + throw new NotSupportedException(shortName + " parse unit is not supported."); } else { throw new NotSupportedException(shortName + " is not supported."); } - } } throw new NotSupportedException(className + " is not supported."); diff --git a/src/test/java/de/tlc4b/analysis/UnsupportedConstructsTest.java b/src/test/java/de/tlc4b/analysis/UnsupportedConstructsTest.java index 84696b21d10fc3e7cbf6d1ae91ae9773f5272621..dd99257b7a4ffc1ff7c8aa8635ddb3b668aceff6 100644 --- a/src/test/java/de/tlc4b/analysis/UnsupportedConstructsTest.java +++ b/src/test/java/de/tlc4b/analysis/UnsupportedConstructsTest.java @@ -19,4 +19,22 @@ public class UnsupportedConstructsTest { final String machine = "IMPLEMENTATION test REFINES foo END"; translate(machine); } + + @Test(expected = NotSupportedException.class) + public void testFreetypes() throws Exception { + final String machine = "MACHINE M FREETYPES F = F1, F2(INTEGER) END"; + translate(machine); + } + + @Test(expected = NotSupportedException.class) + public void testLetExpr() throws Exception { + final String machine = "MACHINE M VARIABLES x INVARIANT x : INTEGER INITIALISATION x := (LET foo BE foo=42 IN foo END) END"; + translate(machine); + } + + @Test(expected = NotSupportedException.class) + public void testLetPred() throws Exception { + final String machine = "MACHINE M VARIABLES x INVARIANT x : INTEGER INITIALISATION x : (LET foo BE foo=42 IN x=foo END) END"; + translate(machine); + } }