Search in sources :

Example 1 with InternalBackendException

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

the class MaudeCompiler 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("-timed")) {
            module = SIMULATOR.EQ_TIMED;
        } else if (arg.equals("-o")) {
            i++;
            if (i == restArgs.size()) {
                throw new InternalBackendException("Missing output file name after '-o'");
            } else {
                outputfile = new File(restArgs.get(i));
            }
        } else if (arg.startsWith("-main=")) {
            mainBlock = arg.split("=")[1];
        } else if (arg.startsWith("-limit=")) {
            // -limit implies -timed
            module = SIMULATOR.EQ_TIMED;
            clocklimit = Integer.parseInt(arg.split("=")[1]);
        } else if (arg.startsWith("-defaultcost=")) {
            defaultResources = Integer.parseInt(arg.split("=")[1]);
        } else if (arg.equals("-maude")) {
        // nothing to do
        } else {
            remainingArgs.add(arg);
        }
    }
    return remainingArgs;
}
Also used : InternalBackendException(abs.backend.common.InternalBackendException) ArrayList(java.util.ArrayList) File(java.io.File)

Example 2 with InternalBackendException

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

the class MaudeCompiler method compile.

/**
 * @param args
 * @throws Exception
 */
public int compile(String[] args) throws Exception {
    if (verbose)
        System.out.println("Generating Maude code...");
    final Model model = parse(args);
    if (model.hasParserErrors() || model.hasErrors() || model.hasTypeErrors()) {
        printErrorMessage();
        return 1;
    }
    PrintStream stream = System.out;
    if (outputfile != null) {
        stream = new PrintStream(outputfile);
    }
    InputStream is = ClassLoader.getSystemResourceAsStream(RUNTIME_INTERPRETER_PATH);
    if (is == null) {
        throw new InternalBackendException("Could not locate abs-interpreter.maude");
    }
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    stream.println("*** Generated " + dateFormat.format(new Date()));
    ByteStreams.copy(is, stream);
    model.generateMaude(stream, module, mainBlock, clocklimit, defaultResources);
    if (verbose)
        System.out.println("Finished.  Start `maude " + outputfile.toString() + "' to run the model.");
    return 0;
}
Also used : PrintStream(java.io.PrintStream) InputStream(java.io.InputStream) InternalBackendException(abs.backend.common.InternalBackendException) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Model(abs.frontend.ast.Model) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 3 with InternalBackendException

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

the class OutlinePrinterBackEnd 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("-o")) {
            i++;
            if (i == restArgs.size()) {
                throw new InternalBackendException("Missing output file name after '-o'");
            } else {
                outputfile = new File(restArgs.get(i));
                if (outputfile.exists()) {
                    outputfile.delete();
                }
            }
        } else if (arg.equals("-f")) {
            force = true;
        } else if (arg.equals("-outline")) {
        // nothing to do
        } else {
            remainingArgs.add(arg);
        }
    }
    return remainingArgs;
}
Also used : InternalBackendException(abs.backend.common.InternalBackendException) ArrayList(java.util.ArrayList) File(java.io.File)

Example 4 with InternalBackendException

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

the class PrettyPrinterBackEnd 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("-o")) {
            i++;
            if (i == restArgs.size()) {
                throw new InternalBackendException("Missing output file name after '-o'");
            } else {
                outputfile = new File(restArgs.get(i));
                if (outputfile.exists()) {
                    outputfile.delete();
                }
            }
        } else if (arg.equals("-f")) {
            force = true;
        } else if (arg.equals("-keepsugar")) {
            keepsugar = true;
        } else if (arg.equals("-prettyprint")) {
        // nothing to do
        } else {
            remainingArgs.add(arg);
        }
    }
    return remainingArgs;
}
Also used : InternalBackendException(abs.backend.common.InternalBackendException) ArrayList(java.util.ArrayList) File(java.io.File)

Example 5 with InternalBackendException

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

the class PrologBackend method parseArgs.

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("-prolog")) {
        // nothing to do
        } else if (arg.equals("-d")) {
            i++;
            if (i == restArgs.size()) {
                throw new InternalBackendException("Please provide a destination directory");
            } else {
                destDir = new File(args[i]);
            }
        } else if (arg.equals("-fn")) {
            i++;
            if (i == restArgs.size()) {
                throw new InternalBackendException("Please provide a file name");
            } else {
                outFilename = args[i];
            }
        } else {
            remainingArgs.add(arg);
        }
    }
    return remainingArgs;
}
Also used : InternalBackendException(abs.backend.common.InternalBackendException)

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