Search in sources :

Example 56 with Model

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

the class ProductDeclarationTest method productIntersect.

@Test
public void productIntersect() throws WrongProgramArgumentException {
    Model model = assertParse("product P1 = {F1, F2, F3} && {F2, F3};");
    model.evaluateAllProductDeclarations();
    ProductDecl p = model.findProduct("P1");
    Product impl = p.getProduct();
    assertEquals(2, impl.getNumFeature());
    Set<String> expected = new HashSet<>(Arrays.asList("F2", "F3"));
    Set<String> actual = new HashSet<>();
    for (Feature f : impl.getFeatures()) actual.add(f.getName());
    assertEquals(expected, actual);
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) Model(org.abs_models.frontend.ast.Model) Product(org.abs_models.frontend.ast.Product) Feature(org.abs_models.frontend.ast.Feature) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 57 with Model

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

the class ProductDeclarationTest method cylicProduct.

// FIXME: there's a catch clause somewhere throwing a RuntimeException
// after catching the DeltaModellingException.  The proper fix is to just
// add an error to the SemanticConditionList during type-checking instead
// of throwing an exception
@Test(expected = java.lang.RuntimeException.class)
public // @Test(expected=DeltaModellingException.class)
void cylicProduct() throws WrongProgramArgumentException {
    Model model = assertParse("product P4 = P5;" + "product P5 = P4;");
    model.evaluateAllProductDeclarations();
}
Also used : Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 58 with Model

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

the class ProductDeclarationTest method invalidProduct.

@Test
public void invalidProduct() throws WrongProgramArgumentException {
    Model model = assertParse("product P1 = {F1, F2};" + "root FM {" + "group allof { F1, F2, F3 }" + "}");
    model.evaluateAllProductDeclarations();
    ProductDecl p = model.findProduct("P1");
    SemanticConditionList e = new SemanticConditionList();
    typeCheck(model, p, e);
    assertEquals(1, e.getErrorCount());
    assertEquals(ErrorMessage.INVALID_PRODUCT, e.getFirstError().msg);
}
Also used : ProductDecl(org.abs_models.frontend.ast.ProductDecl) SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model) Test(org.junit.Test)

Example 59 with Model

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

the class ProgramAbstractionTest method removeClass.

@Test
public void removeClass() {
    Model model = assertParse("module M;" + "class C(Rat myParam) { Int myField = 99; Int myMethod(String a, Bool b) { return 88; } }" + "delta D;" + "uses M;" + "removes class C;" + "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();
    System.out.println("******\n" + pa);
    assertFalse(pa.getClasses().containsKey("M.C"));
}
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 60 with Model

use of org.abs_models.frontend.ast.Model 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)

Aggregations

Model (org.abs_models.frontend.ast.Model)268 Test (org.junit.Test)227 FrontendTest (org.abs_models.frontend.FrontendTest)101 ClassDecl (org.abs_models.frontend.ast.ClassDecl)72 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)34 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)29 ABSTest (org.abs_models.ABSTest)22 ProductDecl (org.abs_models.frontend.ast.ProductDecl)17 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)15 HashSet (java.util.HashSet)13 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)13 PrintStream (java.io.PrintStream)12 Product (org.abs_models.frontend.ast.Product)11 SkipStmt (org.abs_models.frontend.ast.SkipStmt)11 VarUse (org.abs_models.frontend.ast.VarUse)11 Feature (org.abs_models.frontend.ast.Feature)10 File (java.io.File)9 ExpFunctionDef (org.abs_models.frontend.ast.ExpFunctionDef)9 ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)9 KindedName (org.abs_models.frontend.typechecker.KindedName)9