Search in sources :

Example 41 with ClassDecl

use of org.abs_models.frontend.ast.ClassDecl in project abstools by abstools.

the class ReachabilityInformation method isReachable.

/**
 * checks if the method is reachable. It looks at the class name
 * and all the interface names that are directly or indirectly
 * implemented by the method's class
 * @param method
 * @return true if method is reachable, false otherwise
 */
public boolean isReachable(MethodImpl method) {
    ClassDecl clazz = obtainOwnerClass(method);
    boolean reachable = false;
    if (clazz != null) {
        List<InterfaceTypeUse> interfaces = clazz.getImplementedInterfaceUseList();
        Iterator<InterfaceTypeUse> it = interfaces.iterator();
        // checks if the method is reachable with its class name
        reachable = reachableMethods.contains(getMethodId(clazz, method.getMethodSig()));
        // implemented by its class
        while (!reachable && it.hasNext()) reachable = isReachable(it.next(), method.getMethodSig());
        return reachable;
    } else
        return false;
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) InterfaceTypeUse(org.abs_models.frontend.ast.InterfaceTypeUse)

Example 42 with ClassDecl

use of org.abs_models.frontend.ast.ClassDecl in project abstools by abstools.

the class ASTBasedABSTestRunnerGenerator method generateMainBlockAST.

private MainBlock generateMainBlockAST(List<Import> list) {
    final MainBlock block = new MainBlock();
    DataConstructorExp empty = new DataConstructorExp("EmptySet", new List<>());
    VarDeclStmt futsStatement = getVarDecl(futs, getType("Set", getFutUnitType()), empty);
    block.addStmtNoTransform(futsStatement);
    VarDeclStmt futStatement = getVarDecl(fut, getFutUnitType(), null);
    block.addStmtNoTransform(futStatement);
    Set<TypeUse> use = new HashSet<>();
    for (InterfaceDecl key : tests.keySet()) {
        for (ClassDecl clazz : tests.get(key)) {
            use.addAll(generateTestClassImplAST(key, clazz, block));
        }
    }
    block.addStmtNoTransform(generateWaitSyncAST());
    return block;
}
Also used : DataConstructorExp(org.abs_models.frontend.ast.DataConstructorExp) DataTypeUse(org.abs_models.frontend.ast.DataTypeUse) TypeUse(org.abs_models.frontend.ast.TypeUse) ParametricDataTypeUse(org.abs_models.frontend.ast.ParametricDataTypeUse) ClassDecl(org.abs_models.frontend.ast.ClassDecl) VarDeclStmt(org.abs_models.frontend.ast.VarDeclStmt) InterfaceDecl(org.abs_models.frontend.ast.InterfaceDecl) MainBlock(org.abs_models.frontend.ast.MainBlock) HashSet(java.util.HashSet)

Example 43 with ClassDecl

use of org.abs_models.frontend.ast.ClassDecl 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 44 with ClassDecl

use of org.abs_models.frontend.ast.ClassDecl in project abstools by abstools.

the class TypingTest method testThisTyping.

@Test
public void testThisTyping() {
    Model m = assertParse("class C implements I { I m() { return this; } } interface I { }");
    ClassDecl d = (ClassDecl) m.lookupModule("UnitTest").getDecl(0);
    ReturnStmt s = (ReturnStmt) d.getMethod(0).getBlock().getStmt(0);
    assertEquals(m.lookupModule("UnitTest").getDecl(1), ((UnionType) s.getRetExp().getType()).getType(0).getDecl());
}
Also used : UnionType(org.abs_models.frontend.typechecker.UnionType) ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 45 with ClassDecl

use of org.abs_models.frontend.ast.ClassDecl in project abstools by abstools.

the class TypeCheckerTest method classParamsMethodShadowsField.

@Test
public void classParamsMethodShadowsField() {
    Model m = assertParse("class C(Bool b) { Bool m(Bool b) { return b; } }");
    ModuleDecl u = m.lookupModule("UnitTest");
    ClassDecl c = (ClassDecl) u.lookup(new KindedName(KindedName.Kind.CLASS, "C"));
    MethodImpl me = c.lookupMethod("m");
    ReturnStmt r = (ReturnStmt) me.getBlock().getStmt(0);
    VarOrFieldUse vu = (VarOrFieldUse) r.getRetExp();
    ParamDecl d = (ParamDecl) vu.getDecl();
    assertThat(d.getParent().getParent(), instanceOf(MethodSig.class));
    assertThat(vu.getClass().getName(), vu, instanceOf(VarUse.class));
}
Also used : MethodSig(org.abs_models.frontend.ast.MethodSig) ClassDecl(org.abs_models.frontend.ast.ClassDecl) MethodImpl(org.abs_models.frontend.ast.MethodImpl) ParamDecl(org.abs_models.frontend.ast.ParamDecl) Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) KindedName(org.abs_models.frontend.typechecker.KindedName) VarUse(org.abs_models.frontend.ast.VarUse) ReturnStmt(org.abs_models.frontend.ast.ReturnStmt) VarOrFieldUse(org.abs_models.frontend.ast.VarOrFieldUse) ABSTest(org.abs_models.ABSTest) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

ClassDecl (org.abs_models.frontend.ast.ClassDecl)79 Model (org.abs_models.frontend.ast.Model)72 Test (org.junit.Test)72 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)24 FrontendTest (org.abs_models.frontend.FrontendTest)15 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)12 SkipStmt (org.abs_models.frontend.ast.SkipStmt)11 ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)10 KindedName (org.abs_models.frontend.typechecker.KindedName)10 DeltaTraitModifier (org.abs_models.frontend.ast.DeltaTraitModifier)7 ModifyMethodModifier (org.abs_models.frontend.ast.ModifyMethodModifier)7 TraitExpr (org.abs_models.frontend.ast.TraitExpr)7 MethodImpl (org.abs_models.frontend.ast.MethodImpl)6 AddMethodModifier (org.abs_models.frontend.ast.AddMethodModifier)5 MethodSig (org.abs_models.frontend.ast.MethodSig)5 ModuleDecl (org.abs_models.frontend.ast.ModuleDecl)5 TraitSetExpr (org.abs_models.frontend.ast.TraitSetExpr)5 HashSet (java.util.HashSet)4 List (org.abs_models.frontend.ast.List)4 ABSTest (org.abs_models.ABSTest)3