Search in sources :

Example 41 with SemanticConditionList

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

the class ProductDeclarationTest method undeclaredProduct.

// FIXME: The correct error message is emitted, but via throwing an
// exception instead of reporting it in the condition list.  Additionally,
// the WrongProgramArgumentException is re-thrown as a RuntimeException.
// The proper fix is to just add an error to the SemanticConditionList
// instead of throwing an exception
// @Test(expected=org.abs_models.common.WrongProgramArgumentException.class)
@Test(expected = java.lang.RuntimeException.class)
public void undeclaredProduct() throws WrongProgramArgumentException {
    Model model = assertParse("product P1 = P2 && P3 || P4 || {F1, F2};");
    ProductDecl p = model.findProduct("P1");
    SemanticConditionList e = new SemanticConditionList();
    typeCheck(model, p, e);
    assertEquals(3, e.getErrorCount());
    Assert.assertEquals(ErrorMessage.UNDECLARED_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 42 with SemanticConditionList

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

the class ProgramAbstractionTest method core.

@Test
public void core() {
    Model model = assertParse("module M;" + "class C(Rat myParam) { Int myField = 99; Int myMethod(String a, Bool b) { return 88; } }" + "productline PL;" + "features F;");
    SemanticConditionList errors = new SemanticConditionList();
    ProductLine pl = model.getProductLine();
    DeltaTrie trie = ProductLineAnalysisHelper.buildPFGT(pl, errors);
    ProgramAbstraction pa = trie.getRoot().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)

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