Commit add51e7e authored by Matthew Dawson's avatar Matthew Dawson
Browse files

Move all the java code to the package ca.mcmaster.cas.tabularexpressiontoolbox.

Since the java code is turning into entire toolbox for dealing with tabular
expressions, move the code to an appropriate package.  Even if it doesn't
become a full toolbox (for java), it is deeply used by the Matlab toolbox.
Thus pull the name from there.

git-svn-id: https://groke.mcmaster.ca/svn/grad/colin/branches/TableTool_javization@10844 57e6efec-57d4-0310-aeb1-a6c144bb1a8b
parent a1bd3b70
Loading
Loading
Loading
Loading
+0 −98
Original line number Diff line number Diff line
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ca.mcmaster.cas.matlab2smt;

import java.util.Arrays;
import java.util.Collection;

/**
 *
 * @author matthew
 */
public enum MatlabBinaryOperation {

    Addition,
    Minus,
    Multiplication,
    Division,

    GreaterThen,
    GreaterThenEqual,
    LessThen,
    LessThenEqual,
    Equals,

    BooleanAnd,
    BooleanOr;

    static MatlabBinaryOperation getOpForSymbol(String text) {
        if (text.equals("+")) {
            return Addition;
        } else if (text.equals("-")) {
            return Minus;
        } else if (text.equals("*")) {
            return Multiplication;
        } else if (text.equals("/")) {
            return Division;
        } else if (text.equals(">")) {
            return GreaterThen;
        } else if (text.equals(">=")) {
            return GreaterThenEqual;
        } else if (text.equals("<")) {
            return LessThen;
        } else if (text.equals("<=")) {
            return LessThenEqual;
        } else if (text.equals("==")) {
            return Equals;
        } else if (text.equals("&&")) {
            return BooleanAnd;
        } else if (text.equals("||")) {
            return BooleanOr;
        } else {
            throw new IllegalArgumentException("No such binary matlab operation defined (" + text + ")!");
        }
    }

    Collection<VariableTypeMarker> getInputTypeForOutput(VariableTypeMarker outputType) {
        // Boolean inputs only work with a boolean input!
        if (this == BooleanAnd || this == BooleanOr || this == GreaterThen || this == GreaterThenEqual ||
                this == LessThen || this == LessThenEqual || this == Equals) {
            if (!outputType.equals(new BooleanVariableType())) {
                throw new IllegalArgumentException("Boolean operators and comparisons require a boolean output type!");
            }
        }

        // Comparisions produce boolean outputs!
        switch(this) {
            case GreaterThen:
            case GreaterThenEqual:
            case LessThen:
            case LessThenEqual:
            case Equals:
                return Arrays.asList(new VariableTypeMarker[]{new RealVariableType(), new FixedPointVariableType.Marker()});
        }
        return Arrays.asList(new VariableTypeMarker[]{outputType});
    }

    public VariableType getOutputForInput(VariableType inputType) {
        // Boolean inputs only work with a boolean input!
        if (this == BooleanAnd || this == BooleanOr) {
            if (!inputType.equals(new BooleanVariableType())) {
                throw new IllegalArgumentException("Boolean operators require a boolean input type!");
            }
        }

        // Comparisions produce boolean outputs!
        switch(this) {
            case GreaterThen:
            case GreaterThenEqual:
            case LessThen:
            case LessThenEqual:
            case Equals:
                return new BooleanVariableType();
        }
        return inputType;
    }
}
Loading