Search in sources :

Example 6 with LocationTypeInferrerExtension

use of abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension 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 7 with LocationTypeInferrerExtension

use of abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension 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 8 with LocationTypeInferrerExtension

use of abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension in project abstools by abstools.

the class AbsNature method createLocationTypeInferenceMarker.

private void createLocationTypeInferenceMarker() throws CoreException {
    synchronized (modelLock) {
        LocationTypeInferrerExtension locationTypeInferrerExtension = modelbuilder.getLocationTypeInferrerExtension();
        if (locationTypeInferrerExtension != null) {
            Map<LocationTypeVariable, LocationType> inferResult = locationTypeInferrerExtension.getResults();
            if (inferResult != null) {
                if (getProjectPreferenceStore().getBoolean(LOCATION_TYPE_OVERLAY)) {
                    for (Entry<LocationTypeVariable, LocationType> e : inferResult.entrySet()) {
                        LocationType annoType = e.getKey().getAnnotatedType();
                        if (annoType == null || annoType.equals(LocationType.INFER)) {
                            int severity = IMarker.SEVERITY_ERROR;
                            if (e.getValue().isNear()) {
                                severity = IMarker.SEVERITY_INFO;
                            } else if (e.getValue().isSomewhere()) {
                                severity = IMarker.SEVERITY_WARNING;
                            }
                            createMarker(e.getKey().getNode(), "Inferred Location Type: " + e.getValue(), severity, LOCATION_TYPE_INFERENCE_MARKER_TYPE);
                        }
                    }
                }
            } else {
                IMarker marker = getProject().createMarker(TYPECHECK_MARKER_TYPE);
                marker.setAttribute(IMarker.MESSAGE, "Location Type Inference Failed");
                marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
            }
        }
    }
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) LocationType(abs.frontend.typechecker.locationtypes.LocationType) LocationTypeVariable(abs.frontend.typechecker.locationtypes.infer.LocationTypeVariable)

Example 9 with LocationTypeInferrerExtension

use of abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension in project abstools by abstools.

the class AbsModelManagerImpl method extendedTypechecking.

private void extendedTypechecking() {
    if (absNature.getProject() != null) {
        IPersistentPreferenceStore projectPreferences = absNature.getProjectPreferenceStore();
        IncrementalModelBuilder.flushAll(model);
        model.getTypeExt().clearTypeSystemExtensions();
        boolean dolocationtypecheck = projectPreferences.getBoolean(LOCATION_TYPECHECK);
        if (dolocationtypecheck) {
            String defaultlocationtypeprecision = projectPreferences.getString(LOCATION_TYPE_PRECISION);
            LocationType defaultLocType = LocationType.createFromName(projectPreferences.getString(DEFAULT_LOCATION_TYPE));
            LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(model);
            ltie.setDefaultType(defaultLocType);
            ltie.setLocationTypingPrecision(LocationTypingPrecision.valueOf(defaultlocationtypeprecision));
            model.registerTypeSystemExtension(ltie);
        }
    }
    SemanticConditionList typeErrors = model.typeCheck();
    updateMarkers(typeErrors);
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) LocationType(abs.frontend.typechecker.locationtypes.LocationType) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore)

Aggregations

LocationTypeInferrerExtension (abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)9 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)7 Model (abs.frontend.ast.Model)6 LocationType (abs.frontend.typechecker.locationtypes.LocationType)6 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)2 FrontendTest (abs.frontend.FrontendTest)2 Test (org.junit.Test)2 InternalBackendException (abs.backend.common.InternalBackendException)1 SemanticError (abs.frontend.analyser.SemanticError)1 ASTNode (abs.frontend.ast.ASTNode)1 ProductDecl (abs.frontend.ast.ProductDecl)1 VarDeclStmt (abs.frontend.ast.VarDeclStmt)1 DeltaModellingException (abs.frontend.delta.DeltaModellingException)1 DeltaModellingWithNodeException (abs.frontend.delta.DeltaModellingWithNodeException)1 TypeCheckerException (abs.frontend.typechecker.TypeCheckerException)1 InferMain (abs.frontend.typechecker.locationtypes.infer.InferMain)1 LocationTypeVariable (abs.frontend.typechecker.locationtypes.infer.LocationTypeVariable)1 IOException (java.io.IOException)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1 IPersistentPreferenceStore (org.eclipse.jface.preference.IPersistentPreferenceStore)1