Search in sources :

Example 41 with SemanticConditionList

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

the class ProgramAbstractionTest method core.

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

Example 42 with SemanticConditionList

use of abs.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("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);
    Assert.assertEquals(10, te.getLine());
}
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 43 with SemanticConditionList

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

the class ABSTest method assertParse.

protected Model assertParse(String s, Config... config) {
    String preamble = "module UnitTest; export *; ";
    if (isSet(WITH_STD_LIB, config))
        preamble = preamble + " import * from ABS.StdLib;";
    if (!isSet(WITHOUT_MODULE_NAME, config))
        s = preamble + s;
    try {
        Model p = Main.parseString(s, isSet(WITH_STD_LIB, config));
        if (isSet(EXPECT_PARSE_ERROR, config)) {
            if (!p.hasParserErrors())
                fail("Expected to find parse error");
        } else {
            if (p.hasParserErrors()) {
                fail("Failed to parse: " + s + "\n" + p.getParserErrors().get(0).getMessage());
            } else {
                // make ProductDecl.getProduct() not return null
                p.evaluateAllProductDeclarations();
                if (isSet(TYPE_CHECK, config)) {
                    if (isSet(WITH_LOC_INF, config)) {
                        LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(p);
                        p.registerTypeSystemExtension(ltie);
                    }
                    SemanticConditionList l = p.typeCheck();
                    if (isSet(EXPECT_TYPE_ERROR, config)) {
                        if (!l.containsErrors()) {
                            fail("Expected type errors, but none appeared");
                        }
                    } else {
                        if (l.containsErrors()) {
                            fail("Failed to typecheck: " + s + "\n" + l.getFirstError().getMessage());
                        }
                    }
                }
            }
        }
        return p;
    } catch (Exception t) {
        // TODO: remove
        throw new RuntimeException(t);
    }
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) IOException(java.io.IOException) InternalBackendException(abs.backend.common.InternalBackendException)

Example 44 with SemanticConditionList

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

the class LocationTypeInferrerExtension method finished.

@Override
public void finished() {
    if (enablesStats) {
        for (int i = 0; i < 4; i++) {
            SatGenerator satGen = new SatGenerator(constraints);
            // satGen.enableStats = enablesStats;
            results = satGen.generate(errors);
        }
    }
    SatGenerator satGen = new SatGenerator(constraints);
    satGen.enableStats = enablesStats;
    results = satGen.generate(errors);
    if (!errors.containsErrors()) {
        SemanticConditionList sel = new SemanticConditionList();
        List<TypeSystemExtension> curr = model.getTypeExt().getTypeSystemExtensionList();
        model.getTypeExt().clearTypeSystemExtensions();
        model.getTypeExt().register(new LocationTypeExtension(model, this));
        model.typeCheck(sel);
        errors.addAll(sel);
        model.getTypeExt().clearTypeSystemExtensions();
        model.getTypeExt().registerAll(curr);
    }
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) LocationTypeExtension(abs.frontend.typechecker.locationtypes.LocationTypeExtension) DefaultTypeSystemExtension(abs.frontend.typechecker.ext.DefaultTypeSystemExtension) TypeSystemExtension(abs.frontend.typechecker.ext.TypeSystemExtension)

Example 45 with SemanticConditionList

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

the class AbstractTab method updateErrors.

/**
 * Don't recommend to start projects which have errors.
 * TODO: manipulating the error message here does not cooperate well with isValid().
 */
protected boolean updateErrors() {
    boolean res = true;
    String projectName = getSelectedProjectName();
    String prod = getSelectedProductName();
    if (this.lastProjectName != null && this.lastProd != null && this.lastProjectName.equals(projectName) && this.lastProd.equals(prod)) {
        // every time something changes in the run configuration dialog
        return lastResult;
    }
    if (projectName != null) {
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
        try {
            AbsNature nat = UtilityFunctions.getAbsNature(project);
            assert nat != null;
            synchronized (nat.modelLock) {
                Model model = nat.getCompleteModel();
                /* E.g. errors in the project */
                if (model == null)
                    return false;
                /* Check product if any */
                // work on a copy:
                model = model.treeCopyNoTransform();
                model.flushTreeCache();
                if (prod != null) {
                    model.flattenForProduct(prod);
                    /* Type check again */
                    // #335, see IncrementalModelBuilder#flushAll()
                    model.flushCache();
                }
                SemanticConditionList errs = model.getErrors();
                // TODO: check for warnings also
                if (errs != null && errs.containsErrors()) {
                    createMarkers(nat, errs);
                    throw new AbsJobException(new TypeCheckerException(errs));
                }
                errs = model.typeCheck();
                // TODO: check for warnings also
                if (errs != null && errs.containsErrors()) {
                    createMarkers(nat, errs);
                    throw new AbsJobException(new TypeCheckerException(errs));
                }
            }
            setErrorMessage(null);
        } catch (AbsJobException e) {
            setErrorMessage(e.getMessage());
            res = false;
        } catch (WrongProgramArgumentException e) {
            setErrorMessage(e.getMessage());
            res = false;
        } catch (DeltaModellingException e) {
            setErrorMessage(e.getMessage());
            res = false;
        }
        getLaunchConfigurationDialog().updateMessage();
    }
    // cache the result
    lastProd = prod;
    lastProjectName = projectName;
    lastResult = res;
    return res;
}
Also used : TypeCheckerException(org.absmodels.abs.plugin.exceptions.TypeCheckerException) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) IProject(org.eclipse.core.resources.IProject) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) DeltaModellingException(abs.frontend.delta.DeltaModellingException) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

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