Search in sources :

Example 1 with WrongProgramArgumentException

use of abs.common.WrongProgramArgumentException 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 WrongProgramArgumentException

use of abs.common.WrongProgramArgumentException 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 WrongProgramArgumentException

use of abs.common.WrongProgramArgumentException in project abstools by abstools.

the class InferMain method readScopeArg.

private void readScopeArg(String scope) throws WrongProgramArgumentException {
    String[] scopes = scope.split(",");
    config = EnumSet.noneOf(Config.class);
    for (String s : scopes) {
        if (s.equals("all")) {
            config = EnumSet.allOf(Config.class);
        } else {
            try {
                Config c = Config.valueOf(s.toUpperCase());
                config.add(c);
            } catch (IllegalArgumentException e) {
                throw new WrongProgramArgumentException("Unkown scope " + scope);
            }
        }
    }
}
Also used : WrongProgramArgumentException(abs.common.WrongProgramArgumentException)

Example 4 with WrongProgramArgumentException

use of abs.common.WrongProgramArgumentException in project abstools by abstools.

the class InferMain 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()) {
                System.err.println("Please provide a destination directory");
                System.exit(1);
            } else {
                destDir = new File(args[i]);
            }
        }
        if (arg.startsWith("-locinferwritebackscope=")) {
            String[] s = arg.split("=");
            if (s.length < 2) {
                System.err.println("Please provide a scope");
                System.exit(1);
            } else {
                try {
                    readScopeArg(s[1]);
                } catch (WrongProgramArgumentException e) {
                    System.err.println(e.getMessage());
                    System.exit(1);
                }
            }
        } else {
            remainingArgs.add(arg);
        }
    }
    return remainingArgs;
}
Also used : WrongProgramArgumentException(abs.common.WrongProgramArgumentException) File(java.io.File)

Example 5 with WrongProgramArgumentException

use of abs.common.WrongProgramArgumentException in project abstools by abstools.

the class Main method analyzeMTVL.

/**
 * TODO: Should probably be introduced in Model through JastAdd by MTVL package.
 * However, the command-line argument handling will have to stay in Main. Pity.
 */
private void analyzeMTVL(Model m) {
    ProductDecl productDecl = null;
    try {
        productDecl = product == null ? null : m.findProduct(product);
    } catch (WrongProgramArgumentException e) {
    // ignore in case we're just solving.
    }
    if (m.hasMTVL()) {
        if (solve) {
            if (verbose)
                System.out.println("Searching for solutions for the feature model...");
            ChocoSolver s = m.instantiateCSModel();
            System.out.print(s.getSolutionsAsString());
        }
        if (minimise) {
            assert product != null;
            if (verbose)
                System.out.println("Searching for minimum solutions of " + product + " for the feature model...");
            ChocoSolver s = m.instantiateCSModel();
            System.out.print(s.minimiseToString(product));
        }
        if (maximise) {
            assert product != null;
            if (verbose)
                System.out.println("Searching for maximum solutions of " + product + " for the feature model...");
            ChocoSolver s = m.instantiateCSModel();
            // System.out.print(s.maximiseToInt(product));
            s.addConstraint(ChocoSolver.eqeq(s.vars.get(product), s.maximiseToInt(product)));
            ChocoSolver s1 = m.instantiateCSModel();
            int i = 1;
            while (s1.solveAgain()) {
                System.out.println("------ " + (i++) + "------");
                System.out.print(s1.getSolutionsAsString());
            }
        }
        if (solveall) {
            if (verbose)
                System.out.println("Searching for all solutions for the feature model...");
            ChocoSolver solver = m.instantiateCSModel();
            System.out.print(solver.getSolutionsAsString());
        }
        if (solveWith) {
            assert product != null;
            if (verbose)
                System.out.println("Searching for solution that includes " + product + "...");
            if (productDecl != null) {
                ChocoSolver s = m.instantiateCSModel();
                HashSet<Constraint> newcs = new HashSet<>();
                productDecl.getProduct().getProdConstraints(s.vars, newcs);
                for (Constraint c : newcs) s.addConstraint(c);
                System.out.println("checking solution:\n" + s.getSolutionsAsString());
            } else {
                System.out.println("Product '" + product + "' not found.");
            }
        }
        if (minWith) {
            assert product != null;
            if (verbose)
                System.out.println("Searching for solution that includes " + product + "...");
            ChocoSolver s = m.instantiateCSModel();
            HashSet<Constraint> newcs = new HashSet<>();
            s.addIntVar("difference", 0, 50);
            if (productDecl != null) {
                m.getDiffConstraints(productDecl.getProduct(), s.vars, newcs, "difference");
                for (Constraint c : newcs) s.addConstraint(c);
                System.out.println("checking solution: " + s.minimiseToString("difference"));
            } else {
                System.out.println("Product '" + product + "' not found.");
            }
        }
        if (maxProduct) {
            assert product != null;
            if (verbose)
                System.out.println("Searching for solution that includes " + product + "...");
            ChocoSolver s = m.instantiateCSModel();
            HashSet<Constraint> newcs = new HashSet<>();
            s.addIntVar("noOfFeatures", 0, 50);
            if (m.getMaxConstraints(s.vars, newcs, "noOfFeatures")) {
                for (Constraint c : newcs) s.addConstraint(c);
                System.out.println("checking solution: " + s.maximiseToString("noOfFeatures"));
            } else {
                System.out.println("---No solution-------------");
            }
        }
        if (check) {
            assert product != null;
            ChocoSolver s = m.instantiateCSModel();
            if (productDecl == null) {
                System.out.println("Product '" + product + "' not found.");
            } else {
                Map<String, Integer> guess = productDecl.getProduct().getSolution();
                System.out.println("checking solution: " + s.checkSolution(guess, m));
            }
        }
        if (numbersol && !ignoreattr) {
            ChocoSolver s = m.instantiateCSModel();
            System.out.println("Number of solutions found: " + s.countSolutions());
        } else if (numbersol && ignoreattr) {
            ChocoSolver s = m.instantiateCSModel();
            System.out.println("Number of solutions found (without attributes): " + s.countSolutions());
        }
    }
}
Also used : Constraint(choco.kernel.model.constraints.Constraint) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) Constraint(choco.kernel.model.constraints.Constraint) ChocoSolver(abs.frontend.mtvl.ChocoSolver) HashSet(java.util.HashSet)

Aggregations

WrongProgramArgumentException (abs.common.WrongProgramArgumentException)8 Model (abs.frontend.ast.Model)4 DeltaModellingException (abs.frontend.delta.DeltaModellingException)4 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)3 AbsJobException (org.absmodels.abs.plugin.exceptions.AbsJobException)3 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)2 NoModelException (org.absmodels.abs.plugin.internal.NoModelException)2 IProject (org.eclipse.core.resources.IProject)2 ABSTestObserver (abs.backend.java.absunit.ABSTestObserver)1 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 ChocoSolver (abs.frontend.mtvl.ChocoSolver)1 TypeCheckerException (abs.frontend.typechecker.TypeCheckerException)1 LocationType (abs.frontend.typechecker.locationtypes.LocationType)1 LocationTypeInferrerExtension (abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)1 Constraint (choco.kernel.model.constraints.Constraint)1 File (java.io.File)1