Search in sources :

Example 6 with VarDeclStmt

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());
}
Also used : Type(org.abs_models.frontend.typechecker.Type) DataTypeType(org.abs_models.frontend.typechecker.DataTypeType) ClassDecl(org.abs_models.frontend.ast.ClassDecl) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) Model(org.abs_models.frontend.ast.Model) DataTypeType(org.abs_models.frontend.typechecker.DataTypeType) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) Stmt(org.abs_models.frontend.ast.Stmt) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 7 with VarDeclStmt

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;
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) Model(org.abs_models.frontend.ast.Model)

Example 8 with VarDeclStmt

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());
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) Model(org.abs_models.frontend.ast.Model) ArrayList(java.util.ArrayList) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) InterfaceDecl(org.abs_models.frontend.ast.InterfaceDecl) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

VarDeclStmt (org.abs_models.frontend.ast.VarDeclStmt)8 Model (org.abs_models.frontend.ast.Model)6 FrontendTest (org.abs_models.frontend.FrontendTest)5 Test (org.junit.Test)5 ABSTest (org.abs_models.ABSTest)3 DataTypeUse (org.abs_models.frontend.ast.DataTypeUse)3 InterfaceDecl (org.abs_models.frontend.ast.InterfaceDecl)3 ParametricDataTypeUse (org.abs_models.frontend.ast.ParametricDataTypeUse)3 TypeUse (org.abs_models.frontend.ast.TypeUse)3 Block (org.abs_models.frontend.ast.Block)2 ClassDecl (org.abs_models.frontend.ast.ClassDecl)2 InterfaceTypeUse (org.abs_models.frontend.ast.InterfaceTypeUse)2 Stmt (org.abs_models.frontend.ast.Stmt)2 Type (org.abs_models.frontend.typechecker.Type)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)1 AssignStmt (org.abs_models.frontend.ast.AssignStmt)1 DataConstructorExp (org.abs_models.frontend.ast.DataConstructorExp)1 ExpressionStmt (org.abs_models.frontend.ast.ExpressionStmt)1