Search in sources :

Example 61 with Model

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

the class OriginalCallTest method oneDeltaMultipleCalls.

@Test
public void oneDeltaMultipleCalls() throws DeltaModellingException {
    Model model = assertParseOk("module M;" + "interface I {}" + "class C implements I { Unit m() {} Unit n() {} Unit p() {} }" + "delta D;uses M;" + "modifies class C {" + "modifies Unit m() { original(); }" + "modifies Unit n() { original(); }" + "modifies Unit p() { original(); }" + "}");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    DeltaDecl delta = findDelta(model, "D");
    assertEquals(1, delta.getNumModuleModifier());
    model.applyDeltas(new ArrayList<>(Arrays.asList(delta)));
    assertEquals(6, cls.getMethods().getNumChild());
// Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta)));
// assertEquals(4, delta.getNumModuleModifier());
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 62 with Model

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

the class OriginalCallTest method originalCall.

@Test
public void originalCall() throws DeltaModellingException {
    Model model = assertParseOk("module M;" + "interface I {}" + "class C implements I { Unit m() {} }" + "delta D; uses M;" + "modifies class C { modifies Unit m() { original(); } }" + "delta D2; uses M;" + "modifies class C { modifies Unit m() { original(); } }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertTrue(cls.getMethods().getNumChild() == 1);
    DeltaDecl delta1 = findDelta(model, "D");
    assertTrue(delta1.getNumModuleModifier() == 1);
    assertTrue(((ModifyClassModifier) delta1.getModuleModifier(0)).getNumModifier() == 1);
    DeltaDecl delta2 = findDelta(model, "D2");
    assertTrue(delta2.getNumModuleModifier() == 1);
    assertTrue(((ModifyClassModifier) delta2.getModuleModifier(0)).getNumModifier() == 1);
    /*Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta1,delta2)));
        assertTrue(delta1.getNumModuleModifier() == 2);
        assertTrue(delta2.getNumModuleModifier() == 2);*/
    model.applyDeltas(new ArrayList<>(Arrays.asList(delta1, delta2)));
    // there should be 3 methods now: the original one and those added by the two deltas
    assertEquals(3, cls.getMethods().getNumChild());
    assertTrue(cls.getMethod(0).getMethodSig().getName().equals("m"));
    assertTrue(cls.getMethod(1).getMethodSig().getName().equals("m$ORIGIN_core"));
    assertTrue(cls.getMethod(2).getMethodSig().getName().equals("m$ORIGIN_D"));
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 63 with Model

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

the class OriginalCallTest method originalCall2.

@Test
public void originalCall2() throws DeltaModellingException {
    Model model = assertParseOk("module M;" + "interface I {}" + "class C implements I { Unit m() {} }" + "delta D; uses M;" + "modifies class C { modifies Unit m() { original(); } }" + "delta D2; uses M;" + "modifies class C { modifies Unit m() { original(); } }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertTrue(cls.getMethods().getNumChild() == 1);
    DeltaDecl delta1 = findDelta(model, "D");
    assertTrue(delta1.getNumModuleModifier() == 1);
    assertTrue(((ModifyClassModifier) delta1.getModuleModifier(0)).getNumModifier() == 1);
    DeltaDecl delta2 = findDelta(model, "D2");
    assertTrue(delta2.getNumModuleModifier() == 1);
    assertTrue(((ModifyClassModifier) delta2.getModuleModifier(0)).getNumModifier() == 1);
    /*Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(delta1,delta2)));
        assertTrue(delta1.getNumModuleModifier() == 2);
        assertTrue(delta2.getNumModuleModifier() == 2);*/
    model.applyDeltas(new ArrayList<>(Arrays.asList(delta1, delta2)));
    // there should be 3 methods now: the original one and those added by the two deltas
    assertEquals(3, cls.getMethods().getNumChild());
    assertTrue(cls.getMethod(0).getMethodSig().getName().equals("m"));
    assertTrue(cls.getMethod(1).getMethodSig().getName().equals("m$ORIGIN_core"));
    assertTrue(cls.getMethod(2).getMethodSig().getName().equals("m$ORIGIN_D"));
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) ModifyClassModifier(abs.frontend.ast.ModifyClassModifier) Test(org.junit.Test)

Example 64 with Model

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

the class OriginalCallTest method targetedDeltaNotYetApplied.

@Test
public void targetedDeltaNotYetApplied() throws DeltaModellingException {
    Model model = assertParseOk("module M;" + "class C { Unit m() {} }" + "delta D1;" + "uses M;" + "modifies class C { modifies Unit m() { core.original(); } }" + "delta D2;" + "uses M;" + "modifies class C { modifies Unit m() { D1.original(); } }");
    DeltaDecl d1 = findDelta(model, "D1");
    DeltaDecl d2 = findDelta(model, "D2");
    try {
        // applying deltas in wrong order (D2 then D1) should throw an exception
        // because D2 has a targeted original call to a method in D1
        // Model.resolveOriginalCalls(new ArrayList<DeltaDecl>(Arrays.asList(d2,d1)));
        model.applyDeltas(new ArrayList<>(Arrays.asList(d2, d1)));
        fail("expected a DeltaModellingException");
    } catch (DeltaModellingException e) {
        assertThat(e.getMessage(), containsString("has not yet been applied"));
    }
}
Also used : Model(abs.frontend.ast.Model) DeltaDecl(abs.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 65 with Model

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

the class PartialFunctionTest method prettyPrintImplemented.

@Test
public void prettyPrintImplemented() throws NotImplementedYetException, IOException {
    Model model = expand(parse("apply(inc)(0);", applyFunction(), incFunction()));
    PartialFunctionDecl func = getPartialFunction(model, "apply");
    assertNotNull(func);
    try (StringWriter writer = new StringWriter();
        PrintWriter pw = new PrintWriter(writer)) {
        func.prettyPrint(pw, new DefaultABSFormatter(pw));
        assertFalse(writer.toString().isEmpty());
    }
}
Also used : DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) StringWriter(java.io.StringWriter) Model(abs.frontend.ast.Model) PartialFunctionDecl(abs.frontend.ast.PartialFunctionDecl) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

Model (abs.frontend.ast.Model)224 Test (org.junit.Test)170 FrontendTest (abs.frontend.FrontendTest)93 ClassDecl (abs.frontend.ast.ClassDecl)57 DeltaDecl (abs.frontend.ast.DeltaDecl)30 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)24 FunctionDecl (abs.frontend.ast.FunctionDecl)15 PrintStream (java.io.PrintStream)14 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)12 SkipStmt (abs.frontend.ast.SkipStmt)11 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)11 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)9 ModuleDecl (abs.frontend.ast.ModuleDecl)9 CompilationUnit (abs.frontend.ast.CompilationUnit)7 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)7 PartialFunctionDecl (abs.frontend.ast.PartialFunctionDecl)7 PureExp (abs.frontend.ast.PureExp)7 TraitExpr (abs.frontend.ast.TraitExpr)7 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)6