use of org.abs_models.frontend.typechecker.DataTypeType in project abstools by abstools.
the class OtherAnalysisTests method awaitRewriteModule1.
@Test
public void awaitRewriteModule1() {
Model m = assertParse("module A; export *; data X; module B; export *; data X; module C; import * from A; import B.X; class C { X m() { return await this!m();}}", Config.TYPE_CHECK, Config.WITHOUT_DESUGARING_AFTER_TYPECHECK);
ClassDecl c = (ClassDecl) m.lookupModule("C").getDecl(0);
Stmt stmt = c.getMethod(0).getBlock().getStmt(0);
ReturnStmt ret = (ReturnStmt) stmt;
assertThat(ret.getRetExp().getType(), instanceOf(DataTypeType.class));
assertEquals("A.X", ret.getRetExp().getType().getQualifiedName());
m = assertParse("module A; export *; data X; module B; export *; data X; module C; import * from A; import B.X; class C { X m() { return await this!m();}}", Config.TYPE_CHECK);
c = (ClassDecl) m.lookupModule("C").getDecl(0);
Stmt s = c.getMethod(0).getBlock().getStmt(0);
VarDeclStmt b = (VarDeclStmt) s;
Type t = ((DataTypeType) b.getVarDecl().getType()).getTypeArg(0);
assertEquals("A.X", t.getQualifiedName());
}
use of org.abs_models.frontend.typechecker.DataTypeType in project abstools by abstools.
the class TypeExtensionHelper method annotateType.
public void annotateType(Type t, ASTNode<?> originatingNode, ASTNode<?> typeNode) {
if (t.isDataType()) {
DataTypeType dt = (DataTypeType) t;
if (dt.hasTypeArgs()) {
ParametricDataTypeUse pu = null;
// typeNode maybe a type synonym
if (typeNode instanceof ParametricDataTypeUse)
pu = (ParametricDataTypeUse) typeNode;
int i = 0;
for (Type ta : dt.getTypeArgs()) {
ASTNode<?> childTypeNode = null;
if (pu != null)
childTypeNode = pu.getParam(i);
annotateType(ta, originatingNode, childTypeNode);
i++;
}
}
}
if (t.isReferenceType() || t.isNullType()) {
for (TypeSystemExtension tse : obs) {
tse.annotateType(t, originatingNode, typeNode);
}
}
}
use of org.abs_models.frontend.typechecker.DataTypeType in project abstools by abstools.
the class TypeExtensionHelper method checkAssignable.
public void checkAssignable(Type adaptTo, AdaptDirection dir, Type rht, Type lht, ASTNode<?> n) {
rht = resolveBoundedType(rht);
if (lht.isDataType() && rht.isDataType()) {
DataTypeType dtl = (DataTypeType) lht;
DataTypeType dtr = (DataTypeType) rht;
if (dtl.hasTypeArgs() && dtr.hasTypeArgs() && dtl.getTypeArgs().size() == dtr.getTypeArgs().size()) {
for (int i = 0; i < dtl.getTypeArgs().size(); i++) {
checkAssignable(adaptTo, dir, dtr.getTypeArg(i), dtl.getTypeArg(i), n);
}
}
}
if (lht.isReferenceType() && rht.isReferenceType()) {
for (TypeSystemExtension tse : obs) {
tse.checkAssignable(adaptTo, dir, rht, lht, n);
}
}
}
use of org.abs_models.frontend.typechecker.DataTypeType in project abstools by abstools.
the class TypingTest method functionTypeArgs.
@Test
public void functionTypeArgs() {
Model m = assertParse(" def Maybe<A> f<A>() = None ;");
ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
DataTypeType t = (DataTypeType) d.getTypeUse().getType();
TypeParameter typeArg = (TypeParameter) t.getTypeArg(0);
assertEquals(typeArg.getDecl(), d.getTypeParameter(0));
}
Aggregations