Search in sources :

Example 16 with SemanticConditionList

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

the class LocationTypeTests method assertLocationTypeErrorOnly.

private void assertLocationTypeErrorOnly(String code) {
    Model m = assertParse(code);
    LocationTypeExtension te = new LocationTypeExtension(m);
    m.registerTypeSystemExtension(te);
    SemanticConditionList e = m.typeCheck();
    assertFalse("No type error occurred", !e.containsErrors());
    assertInferFails(code);
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model)

Example 17 with SemanticConditionList

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

the class LocationTypeTests method testInferenceRetypeChecking.

@Test
public void testInferenceRetypeChecking() {
    String code = "interface I { Unit m(); } { [Far] I i; I j; i = j; j.m(); }";
    Model m = assertParse(code);
    LocationTypeExtension te = new LocationTypeExtension(m);
    m.registerTypeSystemExtension(te);
    SemanticConditionList e = m.typeCheck();
    m.typeCheck(new SemanticConditionList());
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 18 with SemanticConditionList

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

the class LocationTypeTests method assertTypeOkOnly.

private void assertTypeOkOnly(String code) {
    Model m = assertParse(code);
    LocationTypeExtension te = new LocationTypeExtension(m);
    m.registerTypeSystemExtension(te);
    m.getErrors();
    SemanticConditionList e = m.typeCheck();
    assertTrue(!e.containsErrors() ? "" : "Found error " + e.getFirstError().getMessage(), !e.containsErrors());
    assertInferOk(code);
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model)

Example 19 with SemanticConditionList

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

the class ABSTest method assertParse.

protected static Model assertParse(String s, Config... config) {
    String preamble = "module UnitTest; export *; ";
    preamble = preamble + " import * from ABS.StdLib;";
    if (!isSet(WITHOUT_MODULE_NAME, config))
        s = preamble + s;
    try {
        Model p = parseString(s);
        if (isSet(WITHOUT_DESUGARING_AFTER_TYPECHECK, config)) {
            p.doAACrewrite = false;
            p.doForEachRewrite = false;
        }
        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)) {
                    // copy other choice parts of Main.analyzeFlattenAndRewriteModel
                    p.flattenTraitOnly();
                    p.collapseTraitModifiers();
                    p.expandPartialFunctions();
                    p.expandForeachLoops();
                    p.expandAwaitAsyncCalls();
                    if (isSet(WITH_LOC_INF, config)) {
                        LocationTypeExtension lte = new LocationTypeExtension(p);
                        p.registerTypeSystemExtension(lte);
                    }
                    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 : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) LocationTypeExtension(org.abs_models.frontend.typechecker.locationtypes.LocationTypeExtension) Model(org.abs_models.frontend.ast.Model) IOException(java.io.IOException) WrongProgramArgumentException(org.abs_models.common.WrongProgramArgumentException) InternalBackendException(org.abs_models.backend.common.InternalBackendException) DeltaModellingException(org.abs_models.frontend.delta.DeltaModellingException)

Example 20 with SemanticConditionList

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

the class FrontendTest method assertTypeErrors.

/**
 * Check for and return the first error occurring in 'absCode', or
 * null if none found.  Produces a test failure if 'config'
 * contains EXPECT_TYPE_ERROR but no error found.  Produces a test
 * failure if 'config' contains EXPECT_WARNING but no warning
 * found.
 * @param absCode - the test case source code
 * @param config - flags
 * @return The first error or null
 */
protected SemanticCondition assertTypeErrors(String absCode, Config... config) {
    Model m = assertParse(absCode, config);
    String msg = "";
    SemanticConditionList l = m.typeCheck();
    if (l.containsErrors()) {
        msg = l.getFirstError().getMsgWithHint(absCode);
    } else if (l.containsWarnings() && isSet(EXPECT_WARNING, config)) {
        msg = l.getFirstWarning().getMsgWithHint(absCode);
    }
    assertEquals(msg, isSet(EXPECT_TYPE_ERROR, config), l.containsErrors());
    if (isSet(EXPECT_WARNING, config)) {
        assertEquals(msg, isSet(EXPECT_WARNING, config), l.containsWarnings());
    }
    return l.containsErrors() ? l.getFirstError() : null;
}
Also used : SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) Model(org.abs_models.frontend.ast.Model)

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