66 */
77
88package 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