Search in sources :

Example 6 with SemanticConditionList

use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class ProgramAbstractionTest method modifyClass.

@Test
public void modifyClass() {
    Model model = assertParse("module M;" + "class C {}" + "delta D1; uses M;" + "modifies class C { adds Int myField = 99; }" + "delta D2; uses M;" + "modifies class C { removes Int myField; }" + "delta D3; uses M;" + "modifies class C { adds Int myMethod(String a, Bool b) { return 88; } }" + "delta D4; uses M;" + "modifies class C { modifies Int myMethod(String a, Bool b) { return 99; } }" + "delta D5; uses M;" + "modifies class C { removes Int myMethod(String a, Bool b); }" + "delta D6; uses M;" + "modifies class C adds I { }" + "delta D7; uses M;" + "modifies class C removes I { }" + "productline PL;" + "features F;" + "delta D1 when F;" + "delta D2 after D1 when F;" + "delta D3 after D2 when F;" + "delta D4 after D3 when F;" + "delta D5 after D4 when F;" + "delta D6 after D5 when F;" + "delta D7 after D6 when F;" + "root FM { group allof { opt F } }");
    SemanticConditionList errors = new SemanticConditionList();
    ProductLine pl = model.getProductLine();
    DeltaTrie trie = ProductLineAnalysisHelper.buildPFGT(pl, errors);
    // D1
    DeltaTrie.Node trieNode = trie.getRoot().getChildren().get("D1");
    ProgramAbstraction pa = trieNode.getProgramAbstraction();
    assertEquals(1, pa.getClasses().get("M.C").get("fields").keySet().size());
    assertTrue(pa.getClasses().get("M.C").get("fields").containsKey("myField"));
    assertEquals("Int", pa.getClasses().get("M.C").get("fields").get("myField").get(0));
    // D2
    trieNode = trieNode.getChildren().get("D2");
    pa = trieNode.getProgramAbstraction();
    assertEquals(0, pa.getClasses().get("M.C").get("fields").keySet().size());
    // D3
    trieNode = trieNode.getChildren().get("D3");
    pa = trieNode.getProgramAbstraction();
    assertTrue(pa.getClasses().get("M.C").get("methods").containsKey("myMethod"));
    assertEquals(3, pa.getClasses().get("M.C").get("methods").get("myMethod").size());
    assertEquals("Int", pa.getClasses().get("M.C").get("methods").get("myMethod").get(0));
    assertEquals("String", pa.getClasses().get("M.C").get("methods").get("myMethod").get(1));
    assertEquals("Bool", pa.getClasses().get("M.C").get("methods").get("myMethod").get(2));
    // D4
    trieNode = trieNode.getChildren().get("D4");
    pa = trieNode.getProgramAbstraction();
    assertTrue(pa.getClasses().get("M.C").get("methods").containsKey("myMethod"));
    assertEquals(3, pa.getClasses().get("M.C").get("methods").get("myMethod").size());
    assertEquals("Int", pa.getClasses().get("M.C").get("methods").get("myMethod").get(0));
    assertEquals("String", pa.getClasses().get("M.C").get("methods").get("myMethod").get(1));
    assertEquals("Bool", pa.getClasses().get("M.C").get("methods").get("myMethod").get(2));
    // D5
    trieNode = trieNode.getChildren().get("D5");
    pa = trieNode.getProgramAbstraction();
    assertEquals(0, pa.getClasses().get("M.C").get("methods").keySet().size());
    // D6
    trieNode = trieNode.getChildren().get("D6");
    pa = trieNode.getProgramAbstraction();
    assertTrue(pa.getClasses().get("M.C").get("interfaces").containsKey("I"));
    // D7
    trieNode = trieNode.getChildren().get("D7");
    pa = trieNode.getProgramAbstraction();
    assertEquals(0, pa.getClasses().get("M.C").get("interfaces").keySet().size());
// TODO: add/remove interface
// TODO modify interface: add/remove method; extends?
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model) ProductLine(org.abs_models.frontend.ast.ProductLine) Test(org.junit.Test)

Example 7 with SemanticConditionList

use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class ProgramAbstractionTest method addClass.

@Test
public void addClass() {
    Model model = assertParse("module M;" + "delta D;" + "uses M;" + "adds class C(Rat myParam) { Int myField = 99; Int myMethod(String a, Bool b) { return 88; } }" + "productline PL;" + "features F;" + "delta D when F;" + "root FM { group allof { opt F } }");
    SemanticConditionList errors = new SemanticConditionList();
    ProductLine pl = model.getProductLine();
    DeltaTrie trie = ProductLineAnalysisHelper.buildPFGT(pl, errors);
    ProgramAbstraction pa = trie.getRoot().getChildren().get("D").getProgramAbstraction();
    assertTrue(pa.getClasses().containsKey("M.C"));
    assertEquals(2, pa.getClasses().get("M.C").get("fields").keySet().size());
    assertTrue(pa.getClasses().get("M.C").get("fields").containsKey("myParam"));
    assertEquals("Rat", pa.getClasses().get("M.C").get("fields").get("myParam").get(0));
    assertTrue(pa.getClasses().get("M.C").get("fields").containsKey("myField"));
    assertEquals("Int", pa.getClasses().get("M.C").get("fields").get("myField").get(0));
    assertTrue(pa.getClasses().get("M.C").get("methods").containsKey("myMethod"));
    assertEquals(3, pa.getClasses().get("M.C").get("methods").get("myMethod").size());
    assertEquals("Int", pa.getClasses().get("M.C").get("methods").get("myMethod").get(0));
    assertEquals("String", pa.getClasses().get("M.C").get("methods").get("myMethod").get(1));
    assertEquals("Bool", pa.getClasses().get("M.C").get("methods").get("myMethod").get(2));
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model) ProductLine(org.abs_models.frontend.ast.ProductLine) Test(org.junit.Test)

Example 8 with SemanticConditionList

use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class ParFnAppTest method tooFewArgsForFuncParam.

@Test
public void tooFewArgsForFuncParam() {
    Model m = parse("apply(tooMany)(0);", applyFunction(), "def Int tooMany(Int i, Int j) = 0;");
    m.expandPartialFunctions();
    SemanticConditionList conditions = m.typeCheck();
    assertTrue(conditions.containsErrors());
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 9 with SemanticConditionList

use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class PardefTest method expand.

protected final Model expand(Model model) {
    try {
        model.flattenTraitOnly();
        model.expandPartialFunctions();
        SemanticConditionList e = model.typeCheck();
        assertFalse("Type check errors! First: " + e.getFirstError(), e.containsErrors());
        return model;
    } catch (Throwable e) {
        if (e instanceof PardefModellingException) {
            // prettyprint could fail if expansion left the AST in an invalid state
            throw e;
        }
        PrintWriter pw = new PrintWriter(System.out);
        model.lookupModule("UnitTest").doPrettyPrint(pw, new DefaultABSFormatter(pw));
        pw.flush();
        throw e;
    }
}
Also used : DefaultABSFormatter(org.abs_models.backend.prettyprint.DefaultABSFormatter) SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) PrintWriter(java.io.PrintWriter)

Example 10 with SemanticConditionList

use of org.abs_models.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class DeltaSamplesTest method test_ticket329_missingLineNo.

@Test
public void test_ticket329_missingLineNo() throws Exception {
    Model m = assertParseFileOk("abssamples/deltas/bug329.abs");
    SemanticConditionList errs = m.typeCheck();
    /* We are expecting a missing delta in product M.PL: */
    assertThat(errs.getFirstError(), instanceOf(TypeError.class));
    TypeError te = (TypeError) errs.getFirstError();
    Assert.assertEquals(ErrorMessage.NAME_NOT_RESOLVABLE, te.msg);
    Assert.assertEquals(10, te.getLine());
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model) TypeError(org.abs_models.frontend.analyser.TypeError) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)42 Model (org.abs_models.frontend.ast.Model)27 Test (org.junit.Test)27 ProductLine (org.abs_models.frontend.ast.ProductLine)7 SemanticCondition (org.abs_models.frontend.analyser.SemanticCondition)6 FrontendTest (org.abs_models.frontend.FrontendTest)5 ProductDecl (org.abs_models.frontend.ast.ProductDecl)3 ABSTest (org.abs_models.ABSTest)2 TypeError (org.abs_models.frontend.analyser.TypeError)2 Constraint (choco.kernel.model.constraints.Constraint)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 PrintWriter (java.io.PrintWriter)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 InternalBackendException (org.abs_models.backend.common.InternalBackendException)1 DefaultABSFormatter (org.abs_models.backend.prettyprint.DefaultABSFormatter)1