Search in sources :

Example 41 with ClassDecl

use of abs.frontend.ast.ClassDecl in project abstools by abstools.

the class OtherAnalysisTests method testContext1.

@Test
public void testContext1() {
    // FIXME: the code in this example is incorrect (no await statement in init block allowed)
    Model m = assertParseOk("data Unit; interface I { Unit m(); } class C implements I {{Unit x = await this!m();}}");
    ClassDecl cd = (ClassDecl) m.lookupModule("UnitTest").getDecl(2);
    AwaitAsyncCall n = (AwaitAsyncCall) down(cd);
    assertNull("Rewrite failed!", n);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) AwaitAsyncCall(abs.frontend.ast.AwaitAsyncCall) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 42 with ClassDecl

use of abs.frontend.ast.ClassDecl in project abstools by abstools.

the class OtherAnalysisTests method testContext2.

@Test
public void testContext2() {
    // FIXME: the code in this example is incorrect (no await statement in init block allowed)
    Model m = assertParseOk("data Unit; interface I { Unit m(); } class C implements I {{Unit x = await this!m();}}");
    ClassDecl cd = (ClassDecl) m.lookupModule("UnitTest").getDecl(2);
    AwaitAsyncCall n = (AwaitAsyncCall) down(cd);
    assertNull("Rewriting failed!", n);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) AwaitAsyncCall(abs.frontend.ast.AwaitAsyncCall) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 43 with ClassDecl

use of abs.frontend.ast.ClassDecl in project abstools by abstools.

the class WizardUtil method validateClass.

/**
 * Same as {@link #validate(String)} but additionally checks, whether the specified
 * class name already exists in the given module declaration
 *
 * @param text
 *            Name to be checked.
 * @param decl
 *            Target ModuleDecl.
 * @return In case of a duplicate name, this method returns
 *         ErrorType.ERROR_NO_DUPLICATE_NAME with the duplicate name set in
 *         its information string.
 */
public static ErrorType validateClass(String text, ModuleDecl decl) {
    if (decl != null) {
        for (Decl d : decl.getDecls()) {
            if (d instanceof ClassDecl && d.getName().equals(text)) {
                ErrorType type = ErrorType.ERROR_DUPLICATE_NAME;
                type.setInformationString(text);
                return type;
            }
        }
    }
    return validate(text);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) InterfaceDecl(abs.frontend.ast.InterfaceDecl) ModuleDecl(abs.frontend.ast.ModuleDecl) ClassDecl(abs.frontend.ast.ClassDecl) Decl(abs.frontend.ast.Decl)

Example 44 with ClassDecl

use of abs.frontend.ast.ClassDecl in project abstools by abstools.

the class FreeVarTest method fieldUse.

@Test
public void fieldUse() {
    ClassDecl clazz = getFirstClassDecl(assertParseOkStdLib("class C {" + "Int i = 0;" + "Int m() {" + "return i + 1;" + "}" + "}"));
    MethodImpl method = clazz.lookupMethod("m");
    assertNotNull(method);
    Stmt stmt = method.getBlock().getStmt(0);
    assertTrue(stmt instanceof ReturnStmt);
    ReturnStmt returnStmt = (ReturnStmt) stmt;
    Exp exp = returnStmt.getRetExp();
    assertEquals(exp.getFreeVars(), "i");
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) MethodImpl(abs.frontend.ast.MethodImpl) Exp(abs.frontend.ast.Exp) ReturnStmt(abs.frontend.ast.ReturnStmt) Stmt(abs.frontend.ast.Stmt) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 45 with ClassDecl

use of abs.frontend.ast.ClassDecl in project abstools by abstools.

the class OtherAnalysisTests method awaitRewriteModule1.

@Test
public void awaitRewriteModule1() {
    Model.doAACrewrite = false;
    Model m = assertParseOk("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();}}");
    ClassDecl c = (ClassDecl) m.lookupModule("C").getDecl(0);
    ReturnStmt ret = (ReturnStmt) c.getMethod(0).getBlock().getStmt(0);
    assertThat(ret.getRetExp().getType(), instanceOf(DataTypeType.class));
    assertEquals("A.X", ret.getRetExp().getType().getQualifiedName());
    Model.doAACrewrite = true;
    m = assertParseOk("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.WITH_STD_LIB);
    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(abs.frontend.typechecker.Type) DataTypeType(abs.frontend.typechecker.DataTypeType) ClassDecl(abs.frontend.ast.ClassDecl) VarDeclStmt(abs.frontend.ast.VarDeclStmt) Model(abs.frontend.ast.Model) DataTypeType(abs.frontend.typechecker.DataTypeType) ReturnStmt(abs.frontend.ast.ReturnStmt) Stmt(abs.frontend.ast.Stmt) VarDeclStmt(abs.frontend.ast.VarDeclStmt) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Aggregations

ClassDecl (abs.frontend.ast.ClassDecl)75 Test (org.junit.Test)59 Model (abs.frontend.ast.Model)57 DeltaDecl (abs.frontend.ast.DeltaDecl)22 FrontendTest (abs.frontend.FrontendTest)12 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)12 SkipStmt (abs.frontend.ast.SkipStmt)11 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 InterfaceDecl (abs.frontend.ast.InterfaceDecl)7 MethodImpl (abs.frontend.ast.MethodImpl)7 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)7 TraitExpr (abs.frontend.ast.TraitExpr)7 MethodSig (abs.frontend.ast.MethodSig)6 ReturnStmt (abs.frontend.ast.ReturnStmt)6 AddMethodModifier (abs.frontend.ast.AddMethodModifier)5 Decl (abs.frontend.ast.Decl)5 DeltaAccess (abs.frontend.ast.DeltaAccess)5 List (abs.frontend.ast.List)5 TraitSetExpr (abs.frontend.ast.TraitSetExpr)5 CompilationUnit (abs.frontend.ast.CompilationUnit)4