Search in sources :

Example 1 with DeltaModellingException

use of abs.frontend.delta.DeltaModellingException in project abstools by abstools.

the class JavaJob method generateJavaCode.

/**
 * Generates .java files (no .class files).
 * If 'product' is set, will flatten accordingly.
 * @param monitor - must not be null
 * @param path - where to add the modules / java-files
 * @param project - the ABS project
 * @throws IOException, if unable to create java files
 * @throws AbsJobException, if unable to generate java files
 * @throws JavaCodeGenerationException, if unable to generate java files
 * @throws CoreException
 * @throws NoModelException
 */
private void generateJavaCode(IProgressMonitor monitor, Path path, IProject project) throws AbsJobException, IOException, JavaCodeGenerationException, CoreException, NoModelException {
    assert monitor != null;
    monitor.subTask("Creating java source files");
    AbsNature nat = UtilityFunctions.getAbsNature(project);
    synchronized (nat.modelLock) {
        Model model = nat.getCompleteModel();
        if (model == null)
            throw new NoModelException();
        JavaCode javaCode = new JavaCode(path.toFile());
        if (product != null) {
            /* [stolz] Flattening for a product will mangle the model according to [ramus]...
                 */
            // work on a copy:
            model = model.treeCopyNoTransform();
            model.flushTreeCache();
            String productN = product.getName();
            try {
                model.flattenForProduct(productN);
                model.flushCache();
                if (model.hasErrors() || model.hasTypeErrors()) {
                    nat.createMarkers(model);
                    throw new AbsJobException("An ABS file in the project has type errors after applying deltas");
                }
            } catch (WrongProgramArgumentException e) {
                throw new AbsJobException(e);
            } catch (DeltaModellingException e) {
                throw new AbsJobException(e);
            }
        }
        // TODO: the second parameter toggles listener code creation (3
        // Java method calls per ABS statement); make this configurable
        model.generateJavaCode(javaCode, true);
        int countUnits = model.getNumCompilationUnit();
        if (countUnits == 0)
            throw new AbsJobException("No compilation unit found");
    }
}
Also used : NoModelException(org.absmodels.abs.plugin.internal.NoModelException) Model(abs.frontend.ast.Model) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) JavaCode(abs.backend.java.codegeneration.JavaCode) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) DeltaModellingException(abs.frontend.delta.DeltaModellingException) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 2 with DeltaModellingException

use of abs.frontend.delta.DeltaModellingException in project abstools by abstools.

the class MaudeJob method runJob.

public IStatus runJob(IProgressMonitor monitor) {
    abort = false;
    boolean failed = false;
    StringBuffer output = new StringBuffer();
    AbsNature nature = getAbsNature(project);
    if (nature == null) {
        return new Status(IStatus.INFO, PLUGIN_ID, "Could not compile current selection. Project is not an ABS project.");
    }
    // Compile Maude Code
    monitor.subTask("Compiling ABS model to Maude");
    try {
        if (!abort)
            compileMaude(monitor, nature);
    } catch (CoreException e1) {
        return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while compilig", e1);
    } catch (IOException e2) {
        return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while compilig", e2);
    } catch (ParseException e4) {
        return new Status(IStatus.INFO, PLUGIN_ID, MAUDE_ERROR, "Could not compile current selection. Code has parse errors.", e4);
    } catch (TypeCheckerException e5) {
        return new Status(IStatus.INFO, PLUGIN_ID, MAUDE_ERROR, "Could not compile current selection. Code has type errors.", e5);
    } catch (WrongProgramArgumentException e) {
        return new Status(IStatus.ERROR, PLUGIN_ID, MAUDE_ERROR, "Could not compile current selection.", e);
    } catch (DeltaModellingException e) {
        return new Status(IStatus.ERROR, PLUGIN_ID, MAUDE_ERROR, "Could not compile current selection.", e);
    } catch (NoModelException e) {
        return new Status(IStatus.INFO, PLUGIN_ID, "No ABS model in project");
    }
    monitor.worked(5);
    // Execute generated Maude code
    monitor.subTask("Executing generated Maude code");
    if (exec) {
        try {
            if (!abort)
                failed = !executeMaude(output);
        } catch (IOException e1) {
            return new Status(IStatus.INFO, PLUGIN_ID, MAUDE_ERROR_MAUDE_PATH, "Encountered IOException while executing Maude (probably misconfigured location of maude executable)", e1);
        } catch (InterruptedException e2) {
            return new Status(IStatus.ERROR, PLUGIN_ID, "Fatal error while executing Maude", e2);
        } finally {
            if (!monitor.isCanceled()) {
                monitor.worked(5);
                monitor.done();
            }
        }
    }
    // If an error was encountered during Maude execution, the info code of the status is set to ERROR_MAUDE, otherwise MAUDE_INFO.
    if (!abort) {
        if (failed) {
            return new Status(IStatus.OK, PLUGIN_ID, MAUDE_ERROR_MAUDE, output.toString(), null);
        } else {
            if (exec) {
                return new Status(IStatus.OK, PLUGIN_ID, MAUDE_INFO, output.toString(), null);
            } else {
                return new Status(IStatus.OK, PLUGIN_ID, MAUDE_OK, output.toString(), null);
            }
        }
    } else {
        monitor.setCanceled(true);
        return new Status(IStatus.INFO, PLUGIN_ID, MAUDE_USER_ABORT, null, null);
    }
}
Also used : NoModelException(org.absmodels.abs.plugin.internal.NoModelException) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) DeltaModellingException(abs.frontend.delta.DeltaModellingException)

Example 3 with DeltaModellingException

use of abs.frontend.delta.DeltaModellingException 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 DeltaModellingException

use of abs.frontend.delta.DeltaModellingException 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

WrongProgramArgumentException (abs.common.WrongProgramArgumentException)4 DeltaModellingException (abs.frontend.delta.DeltaModellingException)4 Model (abs.frontend.ast.Model)3 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)3 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)2 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)2 NoModelException (org.absmodels.abs.plugin.internal.NoModelException)2 JavaCode (abs.backend.java.codegeneration.JavaCode)1 SemanticError (abs.frontend.analyser.SemanticError)1 ASTNode (abs.frontend.ast.ASTNode)1 ProductDecl (abs.frontend.ast.ProductDecl)1 DeltaModellingWithNodeException (abs.frontend.delta.DeltaModellingWithNodeException)1 TypeCheckerException (abs.frontend.typechecker.TypeCheckerException)1 LocationType (abs.frontend.typechecker.locationtypes.LocationType)1 LocationTypeInferrerExtension (abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)1 TypeCheckerException (org.absmodels.abs.plugin.exceptions.TypeCheckerException)1 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)1 IProject (org.eclipse.core.resources.IProject)1 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)1