Search in sources :

Example 1 with LocationTypeInferrerExtension

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

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

the class Main method registerLocationTypeChecking.

private void registerLocationTypeChecking(Model m) {
    if (locationTypeInferenceEnabled) {
        if (verbose)
            System.out.println("Registering Location Type Checking...");
        LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(m);
        if (locationTypeStats) {
            ltie.enableStatistics();
        }
        if (defaultLocationType != null) {
            ltie.setDefaultType(defaultLocationType);
        }
        if (locationTypeScope != null) {
            ltie.setLocationTypingPrecision(locationTypeScope);
        }
        m.registerTypeSystemExtension(ltie);
    }
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)

Example 3 with LocationTypeInferrerExtension

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

the class IncrementalModelBuilder method typeCheckModel.

public synchronized SemanticConditionList typeCheckModel(IProgressMonitor monitor, boolean locationTypeChecking, String defaultloctype, String locationTypePrecision, boolean checkProducts) throws NoModelException, TypecheckInternalException {
    if (model == null)
        throw new NoModelException();
    if (model.hasParserErrors())
        // don't typecheck if the model has parsererrors
        return new SemanticConditionList();
    // throw new TypecheckInternalException(new Exception("Model has parser errors!"));
    // model.flushCache();
    flushAll(model);
    model.getTypeExt().clearTypeSystemExtensions();
    if (locationTypeChecking) {
        LocationType defaultLocType = LocationType.createFromName(defaultloctype);
        LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(model);
        this.ltie = ltie;
        ltie.setDefaultType(defaultLocType);
        ltie.setLocationTypingPrecision(LocationTypingPrecision.valueOf(locationTypePrecision));
        model.registerTypeSystemExtension(ltie);
    }
    try {
        SemanticConditionList semerrors = model.getErrors();
        /* Don't typecheck with semerrors, it might trip up. */
        if (!semerrors.containsErrors())
            semerrors = model.typeCheck();
        /* Check products for errors.
			 * Only the first error is reported (if any), on the product AST-node.
			 * TODO: May be time-consuming for large projects, hence the checkProducts-switch.
			 *       Also could use a timer to switch off if it becomes excessive.
			 * TODO: Use Eclipse's nested markers to show ALL contained errors?
			 * TODO: The outline could indicate the broken product as well.
			 */
        if (!semerrors.containsErrors() && checkProducts) {
            // arbitrary value
            monitor = new SubProgressMonitor(monitor, 10);
            monitor.beginTask("Checking products", model.getProductDecls().size());
            for (ProductDecl p : model.getProductDecls()) {
                monitor.subTask("Checking " + p.getName());
                Model m2 = model.treeCopyNoTransform();
                m2.flushTreeCache();
                try {
                    m2.flattenForProduct(p);
                    SemanticConditionList p_errs = m2.typeCheck();
                    if (p_errs.containsErrors()) {
                        // Only show first error, on product
                        semerrors.add(new SemanticError(p, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), p_errs.getFirstError().getMessage()));
                    }
                } catch (WrongProgramArgumentException e) {
                    semerrors.add(new SemanticError(p, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), e.getMessage()));
                } catch (DeltaModellingException e) {
                    /* We we have a better location for error reporting? */
                    final ASTNode<?> loc;
                    if (e instanceof DeltaModellingWithNodeException)
                        loc = ((DeltaModellingWithNodeException) e).getNode();
                    else
                        loc = p;
                    if (e.getDelta() == null)
                        semerrors.add(new SemanticError(loc, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), e.getMessage()));
                    else
                        semerrors.add(new SemanticError(loc, ErrorMessage.ERROR_IN_PRODUCT_WITH_DELTA, p.getName(), e.getDelta().getName(), e.getMessage()));
                }
            }
            monitor.done();
        }
        return semerrors;
    } catch (TypeCheckerException e) {
        return new SemanticConditionList(e);
    } catch (RuntimeException e) {
        throw new TypecheckInternalException(e);
    }
}
Also used : ProductDecl(abs.frontend.ast.ProductDecl) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) DeltaModellingWithNodeException(abs.frontend.delta.DeltaModellingWithNodeException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) TypeCheckerException(abs.frontend.typechecker.TypeCheckerException) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) SemanticError(abs.frontend.analyser.SemanticError) Model(abs.frontend.ast.Model) ASTNode(abs.frontend.ast.ASTNode) LocationType(abs.frontend.typechecker.locationtypes.LocationType) DeltaModellingException(abs.frontend.delta.DeltaModellingException)

Example 4 with LocationTypeInferrerExtension

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

the class LocationTypeTests method testAwaitFail.

@Test
public void testAwaitFail() {
    LocationType lt = LocationType.INFER;
    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();
}
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 5 with LocationTypeInferrerExtension

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

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