Search in sources :

Example 36 with Model

use of abs.frontend.ast.Model in project abstools by abstools.

the class CaseStudyTypeChecking method assertParseFilesOk.

protected Model assertParseFilesOk(String srcFolder, Config... config) throws IOException, WrongProgramArgumentException, InternalBackendException {
    File srcFolderF = new File(srcFolder);
    assertTrue(srcFolder, srcFolderF.exists());
    Main main = new Main();
    main.setWithStdLib(isSet(WITH_STD_LIB, config));
    Model m = main.parseFiles(findAbsFiles(srcFolderF).toArray(new String[0]));
    if (m != null) {
        m.evaluateAllProductDeclarations();
        if (m.hasParserErrors())
            Assert.fail(m.getParserErrors().get(0).getMessage());
        int numSemErrs = m.getErrors().getErrorCount();
        StringBuffer errs = new StringBuffer("Semantic errors: " + numSemErrs + "\n");
        if (numSemErrs > 0) {
            for (SemanticCondition error : m.getErrors()) errs = errs.append(error.getHelpMessage() + "\n");
            fail("Failed to parse: " + srcFolder + "\n" + errs.toString());
        } else if (isSet(TYPE_CHECK, config)) {
            SemanticConditionList l = m.typeCheck();
            if (l.containsErrors()) {
                for (SemanticCondition error : l) errs = errs.append(error.getHelpMessage() + "\n");
                fail("Failed to typecheck: " + srcFolder + "\n" + errs.toString());
            }
        }
    }
    return m;
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) SemanticCondition(abs.frontend.analyser.SemanticCondition) Model(abs.frontend.ast.Model) File(java.io.File) Main(abs.frontend.parser.Main)

Example 37 with Model

use of abs.frontend.ast.Model in project abstools by abstools.

the class ExamplesTypeChecking method parse.

@Override
protected Model parse(String input) throws Exception {
    Model m = assertTypeCheckFileOk(input, true);
    if (product != null) {
        m.collapseTraitModifiers();
        m.flattenForProduct(product);
        final SemanticConditionList errors = m.getErrors();
        if (errors.containsErrors())
            onError(errors.getFirstError().getMessage());
        m.typeCheck(errors);
        if (errors.containsErrors())
            onError(errors.getFirstError().getMessage());
    }
    return m;
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model)

Example 38 with Model

use of abs.frontend.ast.Model in project abstools by abstools.

the class LocationTypeTests method testAwaitFailRewriteOff.

@Test
public void testAwaitFailRewriteOff() {
    LocationType lt = LocationType.INFER;
    Model.doAACrewrite = false;
    Model m = assertParseOkStdLib("interface T { Unit foo(); } class C { T t = null; Unit bar() { await t!foo(); }}");
    // This line is essential to trigger the NPE!
    assertFalse(m.hasErrors());
    LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(m);
    ltie.setDefaultType(lt);
    ltie.setLocationTypingPrecision(LocationTypingPrecision.CLASS_LOCAL_FAR);
    m.registerTypeSystemExtension(ltie);
    m.getErrors();
    SemanticConditionList e = m.typeCheck();
    Model.doAACrewrite = true;
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) Model(abs.frontend.ast.Model) LocationType(abs.frontend.typechecker.locationtypes.LocationType) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 39 with Model

use of abs.frontend.ast.Model 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 = assertParseOkStdLib(code);
    LocationTypeExtension te = new LocationTypeExtension(m);
    m.registerTypeSystemExtension(te);
    SemanticConditionList e = m.typeCheck();
    m.typeCheck(new SemanticConditionList());
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) LocationTypeExtension(abs.frontend.typechecker.locationtypes.LocationTypeExtension) Model(abs.frontend.ast.Model) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 40 with Model

use of abs.frontend.ast.Model in project abstools by abstools.

the class NegativeTypeCheckerTests method negTestError.

@Test
public void negTestError() {
    Model m = assertParseOkStdLib(" { Bool b = !5; }");
    assertEquals(ErrorMessage.EXPECTED_TYPE, m.typeCheck().getFirstError().msg);
}
Also used : Model(abs.frontend.ast.Model) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Aggregations

Model (abs.frontend.ast.Model)226 Test (org.junit.Test)170 FrontendTest (abs.frontend.FrontendTest)93 ClassDecl (abs.frontend.ast.ClassDecl)57 DeltaDecl (abs.frontend.ast.DeltaDecl)30 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)24 FunctionDecl (abs.frontend.ast.FunctionDecl)15 PrintStream (java.io.PrintStream)14 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)12 SkipStmt (abs.frontend.ast.SkipStmt)11 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)11 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)9 ModuleDecl (abs.frontend.ast.ModuleDecl)9 CompilationUnit (abs.frontend.ast.CompilationUnit)7 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)7 PartialFunctionDecl (abs.frontend.ast.PartialFunctionDecl)7 PureExp (abs.frontend.ast.PureExp)7 TraitExpr (abs.frontend.ast.TraitExpr)7 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)6