use of org.abs_models.frontend.typechecker.TypeParameter in project abstools by abstools.
the class TypingTest method functionTypeArgs5.
@Test
public void functionTypeArgs5() {
Model m = assertParse("def B nth<B>(List<B> list, Int n) = nth(tail(list), n-1) ; ");
ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
TypeParameterDecl typeParameter = d.getTypeParameter(0);
TypeParameter type = (TypeParameter) ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
assertEquals(typeParameter.getName(), type.getDecl().getName());
}
use of org.abs_models.frontend.typechecker.TypeParameter in project abstools by abstools.
the class TypeExtensionHelper method checkFnApp.
public void checkFnApp(FnApp f) {
FunctionDecl decl = (FunctionDecl) f.getDecl();
if (decl instanceof ParametricFunctionDecl) {
HashMap<TypeParameter, Type> map = new HashMap<>();
for (int i = 0; i < decl.getNumParam(); i++) {
Type t = f.getParam(i).getType();
Type arg = decl.getParam(i).getType();
checkTypeParameter(map, t, arg, f.getParam(i));
}
} else {
checkAssignable(null, decl, f);
}
}
use of org.abs_models.frontend.typechecker.TypeParameter in project abstools by abstools.
the class TypeExtensionHelper method checkTypeParameter.
private void checkTypeParameter(HashMap<TypeParameter, Type> map, Type rht, Type lht, ASTNode<?> origin) {
rht = resolveBoundedType(rht);
if (rht.isBoundedType())
return;
if (lht.isTypeParameter() && rht.isReferenceType()) {
TypeParameter typeParam = (TypeParameter) lht;
Type lt = map.get(typeParam);
if (lt != null) {
checkEq(lt, rht, origin);
} else {
map.put(typeParam, rht);
}
} else if (lht.isDataType()) {
DataTypeType argdt = (DataTypeType) lht;
if (argdt.hasTypeArgs()) {
DataTypeType dt = (DataTypeType) rht;
for (int i = 0; i < dt.numTypeArgs(); i++) {
checkTypeParameter(map, dt.getTypeArg(i), argdt.getTypeArg(i), origin);
}
}
} else if (lht.isReferenceType()) {
checkEq(lht, rht, origin);
}
}
use of org.abs_models.frontend.typechecker.TypeParameter in project abstools by abstools.
the class JavaBackend method getQualifiedString.
public static String getQualifiedString(Type absType) {
String res = null;
if (absType.isDataType()) {
DataTypeType dt = (DataTypeType) absType;
res = dataTypeMap.get(dt.getDecl().getName());
if (res != null)
return res;
StringBuilder sb = new StringBuilder();
if (dt.hasTypeArgs() && !containsUnboundedType(dt.getTypeArgs())) {
sb.append("<");
boolean first = true;
for (Type t : dt.getTypeArgs()) {
if (first)
first = false;
else
sb.append(',');
sb.append(getQualifiedString(t));
}
sb.append(">");
}
return getQualifiedString(dt.getDecl()) + sb.toString();
/*
* if (dt.hasTypeArgs() && !containsUnboundedType(dt.getTypeArgs()))
* {
*
* sb.append("<"); boolean first = true; for (Type t :
* dt.getTypeArgs()) { if (first) first = false; else
* sb.append(','); sb.append(getQualifiedString(t)); }
* sb.append(">"); }
*/
} else if (absType.isInterfaceType()) {
InterfaceType it = (InterfaceType) absType;
return getQualifiedString(it.getDecl());
} else if (absType.isTypeParameter()) {
TypeParameter tp = (TypeParameter) absType;
return tp.getDecl().getName();
} else if (absType.isBoundedType()) {
BoundedType bt = (BoundedType) absType;
if (bt.hasBoundType())
return getQualifiedString(bt.getBoundType());
return "?";
} else if (absType.isAnyType()) {
return "java.lang.Object";
} else if (absType.isUnionType()) {
return getQualifiedString(((UnionType) absType).getOriginatingClass());
}
throw new RuntimeException("Type " + absType.getClass().getName() + " not yet supported by Java backend");
}
use of org.abs_models.frontend.typechecker.TypeParameter in project abstools by abstools.
the class TypeExtensionHelper method checkDataConstructorExp.
public void checkDataConstructorExp(DataConstructorExp e) {
DataConstructor decl = (DataConstructor) e.getDecl();
if (decl.getDataTypeDecl() instanceof ParametricDataTypeDecl) {
HashMap<TypeParameter, Type> map = new HashMap<>();
for (int i = 0; i < decl.getNumConstructorArg(); i++) {
Type rht = e.getParam(i).getType();
Type arg = decl.getConstructorArg(i).getType();
checkTypeParameter(map, rht, arg, e.getParam(i));
}
}
}
Aggregations