use of org.abs_models.frontend.ast.VarDeclStmt 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.ast.VarDeclStmt in project abstools by abstools.
the class LocationTypeTests method assertInfer.
private Model assertInfer(String code, LocationType expected, boolean fails) {
Model m = assertParse(code);
// m.setLocationTypingEnabled(true);
LocationTypeInferenceExtension ltie = new LocationTypeInferenceExtension(m);
m.registerTypeSystemExtension(ltie);
SemanticConditionList e = m.typeCheck();
// System.out.println(ltie.getConstraints());
assertEquals(!e.containsErrors() ? "" : "Found error: " + e.getFirstError().getMessage() + e.getFirstError().getNode().getPositionString(), fails, e.containsErrors());
// assertEquals(fails, generated == null);
if (expected != null) {
VarDeclStmt vds = ((VarDeclStmt) m.getMainBlock().getStmt(0));
LocationTypeVar lv = LocationTypeInferenceExtension.getVar(vds.getVarDecl().getType());
LocationType t = ltie.getResults().get(lv);
assertTrue(t.toString(), expected == LocationType.FAR ? t == LocationType.FAR : expected == t);
}
return m;
}
use of org.abs_models.frontend.ast.VarDeclStmt in project abstools by abstools.
the class TypeCheckerTest method methodSigs.
@Test
public void methodSigs() {
Model m = assertParse("interface I { Unit m(); } interface J { Unit n(); } interface K extends I, J { Unit foo(); } { K k; } ");
ModuleDecl module = m.lookupModule("UnitTest");
InterfaceDecl d = (InterfaceDecl) module.getDecl(2);
ArrayList<MethodSig> list = new ArrayList<>(d.getAllMethodSigs());
assertEquals(list.toString(), 3, list.size());
VarDeclStmt stmt = (VarDeclStmt) module.getBlock().getStmt(0);
Collection<MethodSig> sigs = stmt.getVarDecl().getTypeUse().getType().getAllMethodSigs();
assertArrayEquals(sigs.toArray(), d.getAllMethodSigs().toArray());
}
Aggregations