Search in sources :

Example 1 with Command

use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.

the class CompModule method addCommand.

// ============================================================================================================================//
/**
 * Add a COMMAND declaration.
 */
void addCommand(boolean followUp, Pos pos, ExprVar name, boolean check, int overall, int bitwidth, int seq, int exp, List<CommandScope> scopes, ExprVar label) throws Err {
    if (followUp && !Version.experimental)
        throw new ErrorSyntax(pos, "Syntax error encountering => symbol.");
    if (label != null)
        pos = Pos.UNKNOWN.merge(pos).merge(label.pos);
    status = 3;
    if (name.label.length() == 0)
        throw new ErrorSyntax(pos, "Predicate/assertion name cannot be empty.");
    if (name.label.indexOf('@') >= 0)
        throw new ErrorSyntax(pos, "Predicate/assertion name cannot contain \'@\'");
    String labelName = (label == null || label.label.length() == 0) ? name.label : label.label;
    Command parent = followUp ? commands.get(commands.size() - 1) : null;
    Command newcommand = new Command(pos, name, labelName, check, overall, bitwidth, seq, exp, scopes, null, name, parent);
    if (parent != null)
        commands.set(commands.size() - 1, newcommand);
    else
        commands.add(newcommand);
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Command(edu.mit.csail.sdg.ast.Command)

Example 2 with Command

use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.

the class CompModule method addCommand.

/**
 * Add a COMMAND declaration.
 */
void addCommand(boolean followUp, Pos pos, Expr e, boolean check, int overall, int bitwidth, int seq, int expects, List<CommandScope> scopes, ExprVar label) throws Err {
    if (followUp && !Version.experimental)
        throw new ErrorSyntax(pos, "Syntax error encountering => symbol.");
    if (label != null)
        pos = Pos.UNKNOWN.merge(pos).merge(label.pos);
    status = 3;
    String n;
    if (check)
        n = addAssertion(pos, "check$" + (1 + commands.size()), e);
    else
        addFunc(e.span().merge(pos), Pos.UNKNOWN, n = "run$" + (1 + commands.size()), null, new ArrayList<Decl>(), null, e);
    String labelName = (label == null || label.label.length() == 0) ? n : label.label;
    Command parent = followUp ? commands.get(commands.size() - 1) : null;
    Command newcommand = new Command(e.span().merge(pos), e, labelName, check, overall, bitwidth, seq, expects, scopes, null, ExprVar.make(null, n), parent);
    if (parent != null)
        commands.set(commands.size() - 1, newcommand);
    else
        commands.add(newcommand);
}
Also used : ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Command(edu.mit.csail.sdg.ast.Command) ArrayList(java.util.ArrayList)

Example 3 with Command

use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.

the class CompModule method resolveCommand.

/**
 * Resolve a particular command.
 */
private Command resolveCommand(Command cmd, ConstList<Sig> exactSigs, Expr globalFacts) throws Err {
    Command parent = cmd.parent == null ? null : resolveCommand(cmd.parent, exactSigs, globalFacts);
    String cname = ((ExprVar) (cmd.formula)).label;
    Expr e;
    Clause declaringClause = null;
    if (cmd.check) {
        // We prefer assertion in the
        List<Object> m = getRawQS(2, cname);
        // topmost module
        if (m.size() == 0 && cname.indexOf('/') < 0)
            m = getRawNQS(this, 2, cname);
        if (m.size() > 1)
            unique(cmd.pos, cname, m);
        if (m.size() < 1)
            throw new ErrorSyntax(cmd.pos, "The assertion \"" + cname + "\" cannot be found.");
        Expr expr = (Expr) (m.get(0));
        e = expr.not();
    } else {
        // We prefer fun/pred in the
        List<Object> m = getRawQS(4, cname);
        // topmost module
        if (m.size() == 0 && cname.indexOf('/') < 0)
            m = getRawNQS(this, 4, cname);
        if (m.size() > 1)
            unique(cmd.pos, cname, m);
        if (m.size() < 1)
            throw new ErrorSyntax(cmd.pos, "The predicate/function \"" + cname + "\" cannot be found.");
        Func f = (Func) (m.get(0));
        declaringClause = f;
        e = f.getBody();
        if (!f.isPred)
            e = e.in(f.returnDecl);
        if (f.decls.size() > 0)
            e = ExprQt.Op.SOME.make(null, null, f.decls, e);
    }
    if (e == null)
        e = ExprConstant.TRUE;
    TempList<CommandScope> sc = new TempList<CommandScope>(cmd.scope.size());
    for (CommandScope et : cmd.scope) {
        Sig s = getRawSIG(et.sig.pos, et.sig.label);
        if (s == null)
            throw new ErrorSyntax(et.sig.pos, "The sig \"" + et.sig.label + "\" cannot be found.");
        sc.add(new CommandScope(null, s, et.isExact, et.startingScope, et.endingScope, et.increment));
    }
    if (cmd.nameExpr != null) {
        cmd.nameExpr.setReferenced(declaringClause);
    }
    return new Command(cmd.pos, cmd.nameExpr, cmd.label, cmd.check, cmd.overall, cmd.bitwidth, cmd.maxseq, cmd.expects, sc.makeConst(), exactSigs, globalFacts.and(e), parent);
}
Also used : ExprVar(edu.mit.csail.sdg.ast.ExprVar) Func(edu.mit.csail.sdg.ast.Func) PrimSig(edu.mit.csail.sdg.ast.Sig.PrimSig) Sig(edu.mit.csail.sdg.ast.Sig) SubsetSig(edu.mit.csail.sdg.ast.Sig.SubsetSig) ErrorSyntax(edu.mit.csail.sdg.alloy4.ErrorSyntax) Expr(edu.mit.csail.sdg.ast.Expr) TempList(edu.mit.csail.sdg.alloy4.ConstList.TempList) Command(edu.mit.csail.sdg.ast.Command) Clause(edu.mit.csail.sdg.ast.Clause) CommandScope(edu.mit.csail.sdg.ast.CommandScope)

Example 4 with Command

use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.

the class SimpleReporter method resultSAT.

/**
 * {@inheritDoc}
 */
@Override
public void resultSAT(Object command, long solvingTime, Object solution) {
    if (!(solution instanceof A4Solution) || !(command instanceof Command))
        return;
    A4Solution sol = (A4Solution) solution;
    Command cmd = (Command) command;
    String formula = recordKodkod ? sol.debugExtractKInput() : "";
    String filename = tempfile + ".xml";
    synchronized (SimpleReporter.class) {
        try {
            cb("R3", "   Writing the XML file...");
            if (latestModule != null)
                writeXML(this, latestModule, filename, sol, latestKodkodSRC);
        } catch (Throwable ex) {
            cb("bold", "\n" + (ex.toString().trim()) + "\nStackTrace:\n" + (MailBug.dump(ex).trim()) + "\n");
            return;
        }
        latestKodkods.clear();
        latestKodkods.add(sol.toString());
        latestKodkod = sol;
        latestKodkodXML = filename;
    }
    String formulafilename = "";
    if (formula.length() > 0 && tempfile != null) {
        formulafilename = tempfile + ".java";
        try {
            Util.writeAll(formulafilename, formula);
            formulafilename = "CNF: " + formulafilename;
        } catch (Throwable ex) {
            formulafilename = "";
        }
    }
    cb("sat", cmd.check, cmd.expects, filename, formulafilename, System.currentTimeMillis() - lastTime);
}
Also used : Command(edu.mit.csail.sdg.ast.Command) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Example 5 with Command

use of edu.mit.csail.sdg.ast.Command in project org.alloytools.alloy by AlloyTools.

the class SimpleReporter method resultUNSAT.

/**
 * {@inheritDoc}
 */
@Override
public void resultUNSAT(Object command, long solvingTime, Object solution) {
    if (!(solution instanceof A4Solution) || !(command instanceof Command))
        return;
    A4Solution sol = (A4Solution) solution;
    Command cmd = (Command) command;
    String originalFormula = recordKodkod ? sol.debugExtractKInput() : "";
    String corefilename = "", formulafilename = "";
    if (originalFormula.length() > 0 && tempfile != null) {
        formulafilename = tempfile + ".java";
        try {
            Util.writeAll(formulafilename, originalFormula);
            formulafilename = "CNF: " + formulafilename;
        } catch (Throwable ex) {
            formulafilename = "";
        }
    }
    Pair<Set<Pos>, Set<Pos>> core = sol.highLevelCore();
    if ((core.a.size() > 0 || core.b.size() > 0) && tempfile != null) {
        corefilename = tempfile + ".core";
        OutputStream fs = null;
        ObjectOutputStream os = null;
        try {
            fs = new FileOutputStream(corefilename);
            os = new ObjectOutputStream(fs);
            os.writeObject(core);
            os.writeObject(sol.lowLevelCore());
            corefilename = "CORE: " + corefilename;
        } catch (Throwable ex) {
            corefilename = "";
        } finally {
            Util.close(os);
            Util.close(fs);
        }
    }
    if (minimized == 0)
        cb("unsat", cmd.check, cmd.expects, (System.currentTimeMillis() - lastTime), formulafilename);
    else
        cb("unsat", cmd.check, cmd.expects, minimized - lastTime, formulafilename, corefilename, minimizedBefore, minimizedAfter, (System.currentTimeMillis() - minimized));
}
Also used : HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Command(edu.mit.csail.sdg.ast.Command) ObjectOutputStream(java.io.ObjectOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) A4Solution(edu.mit.csail.sdg.translator.A4Solution)

Aggregations

Command (edu.mit.csail.sdg.ast.Command)21 A4Solution (edu.mit.csail.sdg.translator.A4Solution)12 A4Options (edu.mit.csail.sdg.translator.A4Options)10 Module (edu.mit.csail.sdg.ast.Module)6 Sig (edu.mit.csail.sdg.ast.Sig)6 A4Reporter (edu.mit.csail.sdg.alloy4.A4Reporter)5 Expr (edu.mit.csail.sdg.ast.Expr)5 Func (edu.mit.csail.sdg.ast.Func)4 ErrorSyntax (edu.mit.csail.sdg.alloy4.ErrorSyntax)3 Pos (edu.mit.csail.sdg.alloy4.Pos)3 Decl (edu.mit.csail.sdg.ast.Decl)3 PrimSig (edu.mit.csail.sdg.ast.Sig.PrimSig)3 CompModule (edu.mit.csail.sdg.parser.CompModule)3 ArrayList (java.util.ArrayList)3 Err (edu.mit.csail.sdg.alloy4.Err)2 ErrorWarning (edu.mit.csail.sdg.alloy4.ErrorWarning)2 XMLNode (edu.mit.csail.sdg.alloy4.XMLNode)2 CommandScope (edu.mit.csail.sdg.ast.CommandScope)2 SubsetSig (edu.mit.csail.sdg.ast.Sig.SubsetSig)2 Test (org.junit.Test)2