Search in sources :

Example 31 with SemanticConditionList

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

the class LocationTypeTests method writeBackSolutions.

private String writeBackSolutions(String code) throws Exception {
    File f = File.createTempFile("test", ".abs");
    f.deleteOnExit();
    FileWriter fw = new FileWriter(f);
    fw.write(code);
    fw.close();
    Model m = assertParseFileOk(f.getAbsolutePath(), Config.WITH_STD_LIB);
    LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(m);
    m.registerTypeSystemExtension(ltie);
    SemanticConditionList e = m.typeCheck();
    assertEquals(!e.containsErrors() ? "" : "Found error: " + e.getFirstError().getMessage(), false, e.containsErrors());
    new InferMain().writeInferenceResultsBack(ltie.getResults());
    String res = FileUtils.fileToStringBuilder(f).toString();
    f.delete();
    return res;
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) InferMain(abs.frontend.typechecker.locationtypes.infer.InferMain) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model)

Example 32 with SemanticConditionList

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

the class LocationTypeTests method assertInfer.

private Model assertInfer(String code, LocationType expected, boolean fails) {
    Model m = assertParse(code, WITH_STD_LIB);
    // m.setLocationTypingEnabled(true);
    LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(m);
    m.registerTypeSystemExtension(ltie);
    SemanticConditionList e = m.typeCheck();
    // System.out.println(ltie.getConstraints());
    assertEquals(!e.containsErrors() ? "" : "Found error: " + e.getFirstError().getMessage(), fails, e.containsErrors());
    // assertEquals(fails, generated == null);
    if (expected != null) {
        VarDeclStmt vds = ((VarDeclStmt) m.getMainBlock().getStmt(0));
        LocationType t = ltie.getResults().get(LocationTypeInferrerExtension.getLV(vds.getVarDecl().getType()));
        assertTrue(t.toString(), expected == LocationType.FAR ? t == LocationType.FAR || t.isParametricFar() : expected == t);
    }
    return m;
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) VarDeclStmt(abs.frontend.ast.VarDeclStmt) Model(abs.frontend.ast.Model) LocationType(abs.frontend.typechecker.locationtypes.LocationType)

Example 33 with SemanticConditionList

use of abs.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(abs.backend.prettyprint.DefaultABSFormatter) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) PrintWriter(java.io.PrintWriter)

Example 34 with SemanticConditionList

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

the class DeltaSamplesTest method test_ticket329.

@Test
public void test_ticket329() throws Exception {
    Model m = assertParseFileOk("tests/abssamples/deltas/bug329.abs", true);
    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);
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model) TypeError(abs.frontend.analyser.TypeError) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 35 with SemanticConditionList

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

the class DeltaTrieTest method trieContent.

@Test
public void trieContent() {
    // TODO
    Model model = assertParseOk("module Test;" + "class Ccore{}" + "delta D1; uses Test; adds class C1 {Int f1 = 0; Unit m1() {}}" + "delta D2; uses Test; adds class C2 {Int f2 = 0; Unit m2() {}}" + "delta D3;" + // + " modifies class Test.C2 { adds Int f2a = 1; modifies Unit m2() {} adds Unit m2a() {} }"
    "" + "" + "" + "" + "productline PL;" + "features A,B;" + "delta D1 when A;" + "delta D2 after D1 when B;" + "delta D3 after D1,D2 when A && B;" + "root FM {" + " group [1..*] { A, B }" + "}");
    ProductLine pl = model.getProductLine();
    DeltaTrie pfgt = ProductLineAnalysisHelper.buildPFGT(pl, new SemanticConditionList());
// TODO: tests
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model) ProductLine(abs.frontend.ast.ProductLine) 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