Skip to content

Commit f3dc5db

Browse files
authored
Array counter examples (#21)
* Add noModelElementSet value to enum * Add support for the lus_main_const option * Support parsing type of arbitrary arrays * Reduced code duplication
1 parent 0d78aeb commit f3dc5db

3 files changed

Lines changed: 30 additions & 8 deletions

File tree

src/main/java/edu/uiowa/cs/clc/kind2/results/Labels.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class Labels
4141
public static final String blockType = "blockType";
4242
public static final String streams = "streams";
4343
public static final String type = "type";
44+
public static final String typeInfo = "typeInfo";
45+
public static final String baseType = "baseType";
4446
public static final String classField = "class";
4547
public static final String instantValues = "instantValues";
4648
public static final String subNodes = "subnodes";

src/main/java/edu/uiowa/cs/clc/kind2/results/Stream.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public Stream(SubNode kind2SubNode, JsonElement jsonElement)
4848
json = new GsonBuilder().setPrettyPrinting().create().toJson(jsonElement);
4949
name = jsonElement.getAsJsonObject().get(Labels.name).getAsString();
5050
String typeString = jsonElement.getAsJsonObject().get(Labels.type).getAsString();
51-
kind2Type = Type.getType(typeString);
51+
JsonElement typeInfo = jsonElement.getAsJsonObject().get(Labels.typeInfo);
52+
kind2Type = Type.getType(typeString, typeInfo);
5253
streamClass = jsonElement.getAsJsonObject().get(Labels.classField).getAsString();
5354

5455
this.stepValues = new ArrayList<>();

src/main/java/edu/uiowa/cs/clc/kind2/results/Type.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77

88
package edu.uiowa.cs.clc.kind2.results;
9+
import edu.uiowa.cs.clc.kind2.Kind2Exception;
10+
11+
import com.google.gson.JsonElement;
912

1013
/**
1114
* An abstract class for all kind2 types.
@@ -21,7 +24,20 @@ public Type(String name)
2124

2225
public static Type getType(String type)
2326
{
24-
switch (type)
27+
return getType(type, null);
28+
}
29+
private static Type makeNestedArray(String baseType, int numDims){
30+
if (numDims == 0){
31+
return getType(baseType);
32+
} else {
33+
return new Array(makeNestedArray(baseType, numDims-1));
34+
}
35+
}
36+
37+
38+
public static Type getType(String typeString, JsonElement typeInfo)
39+
{
40+
switch (typeString)
2541
{
2642
case "bool":
2743
return new Bool();
@@ -39,27 +55,30 @@ public static Type getType(String type)
3955
case "real":
4056
return new Real();
4157
case "array":
42-
return new Array(new Bool());
58+
if (typeInfo == null) throw new Kind2Exception("Array with no type info found");
59+
String baseType = typeInfo.getAsJsonObject().get(Labels.baseType).getAsString();
60+
int numIndicies = typeInfo.getAsJsonObject().get("sizes").getAsJsonArray().size();
61+
return makeNestedArray(baseType, numIndicies);
4362
default:
4463
{
45-
if (type.matches("subrange \\[.*?\\] of int"))
64+
if (typeString.matches("subrange \\[.*?\\] of int"))
4665
{
47-
String [] range = type.replaceAll("subrange \\[", "")
66+
String [] range = typeString.replaceAll("subrange \\[", "")
4867
.replaceAll("\\] of int", "").split(",");
4968
int min = Integer.parseInt(range[0]);
5069
int max = Integer.parseInt(range[0]);
5170
return new SubRange(min, max);
5271
}
5372

54-
if (type.startsWith("array of"))
73+
if (typeString.startsWith("array of"))
5574
{
56-
String elementTypeName = type.replaceFirst("array of", "").trim();
75+
String elementTypeName = typeString.replaceFirst("array of", "").trim();
5776
Type elementType = getType(elementTypeName);
5877
return new Array(elementType);
5978
}
6079

6180
// the type is enum
62-
return new Enum(type);
81+
return new Enum(typeString);
6382
}
6483
}
6584
}

0 commit comments

Comments
 (0)