Search in sources :

Example 1 with NoModelException

use of org.absmodels.abs.plugin.internal.NoModelException 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 NoModelException

use of org.absmodels.abs.plugin.internal.NoModelException 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 NoModelException

use of org.absmodels.abs.plugin.internal.NoModelException in project abstools by abstools.

the class AbsNature method addPackagesForTypeChecking.

/**
 * Add ABS package dependencies to {@link AbsNature#modelbuilder} for type checking
 * @throws TypecheckInternalException
 */
private void addPackagesForTypeChecking() throws TypecheckInternalException {
    try {
        Main m = new Main();
        m.setWithStdLib(true);
        List<CompilationUnit> units = new ArrayList<CompilationUnit>();
        for (PackageEntry entry : packageContainer.getPackages()) {
            File file = new File(entry.getPath());
            if (isABSPackage(file)) {
                units.addAll(m.parseABSPackageFile(file));
            }
        }
        modelbuilder.addCompilationUnits(units);
    } catch (IOException e) {
        throw new TypecheckInternalException(e);
    } catch (NoModelException e) {
    // ignore
    }
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) NoModelException(org.absmodels.abs.plugin.internal.NoModelException) PackageEntry(org.absmodels.abs.plugin.editor.outline.PackageEntry) TypecheckInternalException(org.absmodels.abs.plugin.internal.TypecheckInternalException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Main(abs.frontend.parser.Main) PackageAbsFile(org.absmodels.abs.plugin.editor.outline.PackageAbsFile) File(java.io.File)

Example 4 with NoModelException

use of org.absmodels.abs.plugin.internal.NoModelException in project abstools by abstools.

the class AbsNature method parseABSFile.

/**
 * @deprecated unused
 */
public void parseABSFile(PackageAbsFile file, boolean withincomplete, Object monitor) {
    Main m = new Main();
    m.setWithStdLib(true);
    List<CompilationUnit> units = new ArrayList<CompilationUnit>();
    try {
        final File f = new File(file.getAbsoluteFilePath());
        assert f.exists();
        units.addAll(m.parseABSPackageFile(f));
        modelbuilder.addCompilationUnits(units);
    } catch (IOException e) {
        Activator.logException(e);
    } catch (NoModelException e) {
    }
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) NoModelException(org.absmodels.abs.plugin.internal.NoModelException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Main(abs.frontend.parser.Main) PackageAbsFile(org.absmodels.abs.plugin.editor.outline.PackageAbsFile) File(java.io.File)

Example 5 with NoModelException

use of org.absmodels.abs.plugin.internal.NoModelException in project abstools by abstools.

the class MaudeJob method compileMaude.

/**
 * Compiles an ABS project into a .maude file. If an ABS file is currently opened in the editor, the project containing this file
 * will be compiled, otherwise the project currently selected in the project explorer will be compiled.
 * @throws ParseException Is thrown, if the project which is compiled has parse errors
 * @throws TypeCheckerException Is thrown, if the project which is compiled has type errors
 * @throws DeltaModellingException
 * @throws WrongProgramArgumentException
 * @throws NoModelException
 */
private void compileMaude(IProgressMonitor monitor, AbsNature nature) throws CoreException, IOException, ParseException, TypeCheckerException, WrongProgramArgumentException, DeltaModellingException, NoModelException {
    PrintStream ps = null;
    FileInputStream fis = null;
    try {
        String path = nature.getProjectPreferenceStore().getString(MAUDE_PATH);
        IFolder folder = project.getFolder(path);
        prepareFolder(monitor, folder);
        String fileName = project.getName() + ".maude";
        final IFile wspaceFile = folder.getFile(fileName);
        /* generateMaude only knows how to fill PrintStreams */
        final File tmpFile = File.createTempFile(fileName, null);
        ps = new PrintStream(tmpFile);
        // Get model, check for errors and throw respective exception
        Model model = nature.getCompleteModel();
        if (model == null)
            throw new NoModelException();
        if (model.hasParserErrors()) {
            throw new ParseException(model.getParserErrors());
        }
        if (getProduct() != null) {
            // work on a copy:
            model = model.treeCopy();
            model.flushTreeCache();
            model.flattenForProduct(getProduct());
            // #335
            model.flushCache();
        }
        if (model.hasTypeErrors()) {
            throw new TypeCheckerException(model.typeCheck());
        }
        String mb = getMainBlock();
        if (mb != null && mb.isEmpty())
            mb = null;
        // KLUDGE: use default values for clock limit, resource cost for now
        if (realTime) {
            model.generateMaude(ps, MaudeCompiler.SIMULATOR.EQ_TIMED, mb, 100, 0);
        } else {
            model.generateMaude(ps, MaudeCompiler.SIMULATOR.RL, mb, 100, 0);
        }
        ps.close();
        fis = new FileInputStream(tmpFile);
        if (wspaceFile.exists())
            wspaceFile.setContents(fis, true, false, monitor);
        else
            wspaceFile.create(fis, true, monitor);
        fis.close();
        tmpFile.delete();
        destFile = new File(project.getLocation().append(path).toFile(), fileName);
    } finally {
        if (ps != null) {
            ps.flush();
            ps.close();
        }
        if (fis != null) {
            fis.close();
        }
    }
}
Also used : NoModelException(org.absmodels.abs.plugin.internal.NoModelException) Model(abs.frontend.ast.Model)

Aggregations

NoModelException (org.absmodels.abs.plugin.internal.NoModelException)6 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)2 CompilationUnit (abs.frontend.ast.CompilationUnit)2 Model (abs.frontend.ast.Model)2 DeltaModellingException (abs.frontend.delta.DeltaModellingException)2 Main (abs.frontend.parser.Main)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)2 PackageAbsFile (org.absmodels.abs.plugin.editor.outline.PackageAbsFile)2 TypecheckInternalException (org.absmodels.abs.plugin.internal.TypecheckInternalException)2 JavaCode (abs.backend.java.codegeneration.JavaCode)1 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)1 PackageEntry (org.absmodels.abs.plugin.editor.outline.PackageEntry)1 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)1 UtilityFunctions.getAbsNature (org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature)1