Search in sources :

Example 16 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class ProductLineTypeAnalysisTest method stronglyUnambiguousProductLinePerformance.

@Test
public void stronglyUnambiguousProductLinePerformance() {
    Model model = assertParseOk("module M; class C {}");
    CompilationUnit cu = new CompilationUnit();
    model.addCompilationUnit(cu);
    ProductLine pl = new ProductLine();
    pl.setName("PL");
    cu.setProductLine(pl);
    int n = 2000;
    for (int i = 0; i < n; i++) {
        String id = Integer.toHexString(UUID.randomUUID().hashCode());
        ModifyClassModifier cmod = new ModifyClassModifier();
        cmod.setName("C");
        MethodSig msig = new MethodSig();
        msig.setName("m" + id);
        MethodImpl mimpl = new MethodImpl();
        mimpl.setMethodSig(msig);
        abs.frontend.ast.List<MethodImpl> list = new abs.frontend.ast.List<>();
        list.add(mimpl);
        DeltaTraitModifier dmod = new DeltaTraitModifier(new ModifyMethodModifier(new TraitSetExpr(list)));
        cu.addDeltaDecl(new DeltaDecl("D" + id, new abs.frontend.ast.List<>(), new abs.frontend.ast.List<>(), new abs.frontend.ast.List<>(cmod)));
        DeltaClause dc = new DeltaClause();
        Deltaspec dspec = new Deltaspec();
        dspec.setDeltaID("D" + id);
        dc.setDeltaspec(dspec);
        pl.addDeltaClause(dc);
    }
    pl = model.getProductLine();
    SemanticConditionList errors = new SemanticConditionList();
    long startTime = System.currentTimeMillis();
    assertTrue(ProductLineAnalysisHelper.isStronglyUnambiguous(pl, errors));
    long stopTime = System.currentTimeMillis();
// System.out.println(n + " deltas. time (ms): " + (stopTime - startTime));
}
Also used : abs.frontend.ast(abs.frontend.ast) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) List(java.util.List) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Test(org.junit.Test)

Example 17 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class ProductLineTypeAnalysisTest method stronglyUnambiguousProductLine1.

@Test
public void stronglyUnambiguousProductLine1() {
    Model model = assertParseOk("module M;" + "delta D1; uses M; modifies class C { adds Unit foo() {} }" + "delta D2; modifies class M.C { adds Unit foo() {} }" + "productline PL;" + "features A;" + "delta D1;" + "delta D2 after D1;");
    ProductLine pl = model.getProductLine();
    SemanticConditionList errors = new SemanticConditionList();
    assertTrue(ProductLineAnalysisHelper.isStronglyUnambiguous(pl, errors));
    assertEquals(0, errors.getErrorCount());
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Test(org.junit.Test)

Example 18 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class ProductLineTypeAnalysisTest method stronglyUnambiguousProductLine3.

@Test
public void stronglyUnambiguousProductLine3() {
    Model model = assertParseOk("module M;" + "productline PL;" + "features A;");
    ProductLine pl = model.getProductLine();
    SemanticConditionList errors = new SemanticConditionList();
    /*
         * No deltas, no worries
         */
    assertTrue(ProductLineAnalysisHelper.isStronglyUnambiguous(pl, errors));
    assertEquals(0, errors.getErrorCount());
    List<Set<String>> partition = pl.getDeltaPartition();
    assertEquals(partition.size(), 0);
}
Also used : Set(java.util.Set) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Test(org.junit.Test)

Example 19 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class ProductLineTypeAnalysisTest method wellFormedProductLine1.

@Test
public void wellFormedProductLine1() {
    Model model = assertParseOk("module M;" + "delta D1;" + "delta D2;" + "productline PL;" + "features A;" + "delta D1 after D2;");
    ProductLine pl = model.getProductLine();
    SemanticConditionList errors = new SemanticConditionList();
    /*
         * No delta clause for D2
         */
    assertFalse(ProductLineAnalysisHelper.wellFormedProductLine(pl, errors));
    assertEquals(1, errors.getErrorCount());
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Test(org.junit.Test)

Example 20 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class ProgramAbstractionTest method modifyClass.

@Test
public void modifyClass() {
    Model model = assertParseOk("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
    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(abs.frontend.analyser.SemanticConditionList) Node(abs.frontend.delta.DeltaTrie.Node) Test(org.junit.Test)

Aggregations

SemanticConditionList (abs.frontend.analyser.SemanticConditionList)51 Test (org.junit.Test)30 Model (abs.frontend.ast.Model)24 FrontendTest (abs.frontend.FrontendTest)7 SemanticCondition (abs.frontend.analyser.SemanticCondition)7 LocationTypeInferrerExtension (abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)7 LocationType (abs.frontend.typechecker.locationtypes.LocationType)5 LocationTypeExtension (abs.frontend.typechecker.locationtypes.LocationTypeExtension)4 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)3 ProductLine (abs.frontend.ast.ProductLine)3 TypeError (abs.frontend.analyser.TypeError)2 CompilationUnit (abs.frontend.ast.CompilationUnit)2 DeltaModellingException (abs.frontend.delta.DeltaModellingException)2 Main (abs.frontend.parser.Main)2 ParserError (abs.frontend.parser.ParserError)2 File (java.io.File)2 ABSTest (abs.ABSTest)1 InternalBackendException (abs.backend.common.InternalBackendException)1 DefaultABSFormatter (abs.backend.prettyprint.DefaultABSFormatter)1 SemanticError (abs.frontend.analyser.SemanticError)1