Search in sources :

Example 6 with InternalBackendException

use of abs.backend.common.InternalBackendException in project abstools by abstools.

the class IncrementalModelBuilder method getStdLibCompilationUnit.

private CompilationUnit getStdLibCompilationUnit() {
    CompilationUnit stdLib;
    File bundle;
    try {
        stdLib = new Main().getStdLib();
        bundle = FileLocator.getBundleFile(Platform.getBundle(ABSFRONTEND_PLUGIN_ID));
    } catch (IOException e) {
        Activator.logException(e);
        // Your plugin is probably busted.
        return null;
    } catch (InternalBackendException e) {
        Activator.logException(e);
        // Your plugin is probably busted.
        return null;
    }
    File src = new File(bundle, stdLib.getFileName());
    if (!src.exists()) {
        src = new File(bundle, "src/" + stdLib.getFileName());
    }
    stdLib.setName(src.getAbsolutePath());
    return stdLib;
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) InternalBackendException(abs.backend.common.InternalBackendException) IOException(java.io.IOException) File(java.io.File) Main(abs.frontend.parser.Main)

Example 7 with InternalBackendException

use of abs.backend.common.InternalBackendException in project abstools by abstools.

the class ErlangBackend method compile.

public static void compile(Model m, File destDir, EnumSet<CompileOptions> options) throws IOException, InterruptedException, InternalBackendException {
    int version = getErlangVersion();
    if (version < minErlangVersion) {
        String message = "ABS requires at least erlang version " + Integer.toString(minErlangVersion) + ", installed version is " + Integer.toString(version);
        throw new InternalBackendException(message);
    }
    ErlApp erlApp = new ErlApp(destDir);
    m.generateErlangCode(erlApp, options);
    erlApp.close();
    String[] rebarProgram = new String[] { "escript", "../bin/rebar", "compile" };
    Process p = Runtime.getRuntime().exec(rebarProgram, null, new File(destDir, "absmodel"));
    if (options.contains(CompileOptions.VERBOSE))
        IOUtils.copy(p.getInputStream(), System.out);
    else
        IOUtils.copy(p.getInputStream(), new NullOutputStream());
    p.waitFor();
    if (p.exitValue() != 0) {
        String message = "Compilation of generated erlang code failed with exit value " + p.exitValue();
        if (!options.contains(CompileOptions.VERBOSE))
            message = message + "\n  (use -v for detailed compiler output)";
        throw new InternalBackendException(message);
    // TODO: consider removing the generated code here.  For now,
    // let's leave it in place for diagnosis.
    } else {
        if (options.contains(CompileOptions.VERBOSE)) {
            System.out.println();
            System.out.println("Finished.  \"gen/erl/run\" to start the model.");
            System.out.println("          (\"gen/erl/run --help\" for more options)");
        }
    }
}
Also used : InternalBackendException(abs.backend.common.InternalBackendException) File(java.io.File) NullOutputStream(org.apache.commons.io.output.NullOutputStream)

Example 8 with InternalBackendException

use of abs.backend.common.InternalBackendException in project abstools by abstools.

the class ErlangBackend method parseArgs.

@Override
public List<String> parseArgs(String[] args) throws InternalBackendException {
    List<String> restArgs = super.parseArgs(args);
    List<String> remainingArgs = new ArrayList<>();
    for (int i = 0; i < restArgs.size(); i++) {
        String arg = restArgs.get(i);
        if (arg.equals("-erlang")) {
        // nothing to do
        } else if (arg.equals("-d")) {
            i++;
            if (i == restArgs.size()) {
                throw new InternalBackendException("Please provide an output directory");
            } else {
                destDir = new File(restArgs.get(i));
            }
        } else if (arg.equals("-cover")) {
            compileOptions.add(CompileOptions.COVERAGE);
        } else {
            remainingArgs.add(arg);
        }
    }
    // KLUDGE
    if (verbose)
        compileOptions.add(CompileOptions.VERBOSE);
    // KLUDGE
    if (debug)
        compileOptions.add(CompileOptions.DEBUG);
    return remainingArgs;
}
Also used : InternalBackendException(abs.backend.common.InternalBackendException) ArrayList(java.util.ArrayList) File(java.io.File)

Example 9 with InternalBackendException

use of abs.backend.common.InternalBackendException in project abstools by abstools.

the class JavaBackend method parseArgs.

@Override
public List<String> parseArgs(String[] args) throws InternalBackendException {
    List<String> restArgs = super.parseArgs(args);
    List<String> remainingArgs = new ArrayList<>();
    for (int i = 0; i < restArgs.size(); i++) {
        String arg = restArgs.get(i);
        if (arg.equals("-d")) {
            i++;
            if (i == restArgs.size()) {
                throw new InternalBackendException("Destination directory name not given after '-d'");
            } else {
                destDir = new File(args[i]);
            }
        } else if (arg.equals("-sourceonly")) {
            this.sourceOnly = true;
        } else if (arg.equals("-dynamic")) {
            this.untypedJavaGen = true;
        } else if (arg.equals("-no-debuginfo")) {
            this.includeDebug = false;
        } else if (arg.equals("-debuginfo")) {
            this.includeDebug = true;
        } else if (arg.equals("-java")) {
        // nothing to do
        } else {
            remainingArgs.add(arg);
        }
    }
    return remainingArgs;
}
Also used : InternalBackendException(abs.backend.common.InternalBackendException) File(java.io.File)

Example 10 with InternalBackendException

use of abs.backend.common.InternalBackendException in project abstools by abstools.

the class Main method mainMethod.

public int mainMethod(final String... args) {
    int result = 0;
    try {
        java.util.List<String> argslist = Arrays.asList(args);
        if (argslist.contains("-help") || argslist.contains("-h") || argslist.contains("--help")) {
            printUsage();
        } else if (argslist.contains("-version") || argslist.contains("--version")) {
            printVersion();
        } else if (argslist.contains("-maude")) {
            result = abs.backend.maude.MaudeCompiler.doMain(args);
        } else if (argslist.contains("-java")) {
            result = abs.backend.java.JavaBackend.doMain(args);
        } else if (argslist.contains("-erlang")) {
            result = abs.backend.erlang.ErlangBackend.doMain(args);
        } else if (argslist.contains("-prolog")) {
            result = abs.backend.prolog.PrologBackend.doMain(args);
        } else if (argslist.contains("-coreabs")) {
            result = abs.backend.coreabs.CoreAbsBackend.doMain(args);
        } else if (argslist.contains("-prettyprint")) {
            result = abs.backend.prettyprint.PrettyPrinterBackEnd.doMain(args);
        } else if (argslist.contains("-outline")) {
            result = abs.backend.outline.OutlinePrinterBackEnd.doMain(args);
        } else {
            Model m = parse(args);
            if (m.hasParserErrors() || m.hasErrors() || m.hasTypeErrors()) {
                printErrorMessage();
                result = 1;
            }
        }
    } catch (InternalBackendException e) {
        // don't print stack trace here
        printError(e.getMessage());
        result = 1;
    } catch (Exception e) {
        if (e.getMessage() == null) {
            e.printStackTrace();
        }
        assert e.getMessage() != null : e.toString();
        printError(e.getMessage());
        result = 1;
    }
    return result;
}
Also used : InternalBackendException(abs.backend.common.InternalBackendException) Constraint(choco.kernel.model.constraints.Constraint) DeltaModellingException(abs.frontend.delta.DeltaModellingException) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) InternalBackendException(abs.backend.common.InternalBackendException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

InternalBackendException (abs.backend.common.InternalBackendException)10 File (java.io.File)7 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)2 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)1 CompilationUnit (abs.frontend.ast.CompilationUnit)1 Model (abs.frontend.ast.Model)1 DeltaModellingException (abs.frontend.delta.DeltaModellingException)1 Main (abs.frontend.parser.Main)1 Constraint (choco.kernel.model.constraints.Constraint)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 PrintStream (java.io.PrintStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 NullOutputStream (org.apache.commons.io.output.NullOutputStream)1