Commit 8080ae7f authored by Matthew Dawson's avatar Matthew Dawson
Browse files

Update ExpressionGenerator documentation and parameter names.

ExpressionGenerator now has javadoc, and changed the interface's parameter
names to be more logical.  Also update all the generators to match.
parent 3c12ea25
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -131,12 +131,12 @@ final public class CVC3ExpressionGenerator implements ExpressionGenerator {
    }

    @Override
    public String GenerateBinaryOperation(BinaryOperation op, String lhsExp, String rhsExp, Type usedType) {
        switch (CVC3ExpressionGenerator.OpTypeForOpAndType(op, usedType)) {
    public String GenerateBinaryOperation(BinaryOperation op, String lhsExp, String rhsExp, Type inputType) {
        switch (CVC3ExpressionGenerator.OpTypeForOpAndType(op, inputType)) {
            case CenterOp:
                return "(" + lhsExp + " " + CVC3ExpressionGenerator.ConvertToOutputOp(op, usedType) + " " + rhsExp + ")";
                return "(" + lhsExp + " " + CVC3ExpressionGenerator.ConvertToOutputOp(op, inputType) + " " + rhsExp + ")";
            case Function:
                return CVC3ExpressionGenerator.ConvertToOutputOp(op, usedType) + lhsExp + "," + rhsExp + ")";
                return CVC3ExpressionGenerator.ConvertToOutputOp(op, inputType) + lhsExp + "," + rhsExp + ")";
            default:
                throw new IllegalStateException("Cannot output expression operation for requested operation type.");
        }
@@ -153,12 +153,12 @@ final public class CVC3ExpressionGenerator implements ExpressionGenerator {
    }

    @Override
    public String GenerateUnaryOperation(UnaryOperation op, String expression, Type usedType) {
        switch (CVC3ExpressionGenerator.OpTypeForOpAndType(op, usedType)) {
    public String GenerateUnaryOperation(UnaryOperation op, String expression, Type inputType) {
        switch (CVC3ExpressionGenerator.OpTypeForOpAndType(op, inputType)) {
            case PrefixOp:
                return "(" + CVC3ExpressionGenerator.ConvertToOutputOp(op, usedType) + " " + expression + ")";
                return "(" + CVC3ExpressionGenerator.ConvertToOutputOp(op, inputType) + " " + expression + ")";
            case Function:
                return CVC3ExpressionGenerator.ConvertToOutputOp(op, usedType) + "(" + expression + ")";
                return CVC3ExpressionGenerator.ConvertToOutputOp(op, inputType) + "(" + expression + ")";
            default:
                throw new IllegalStateException("Cannot output expression operation for requested operation type.");
        }
+2 −2
Original line number Diff line number Diff line
@@ -78,12 +78,12 @@ final public class EventBExpressionGenerator implements ExpressionGenerator {
    }

    @Override
    public String GenerateBinaryOperation(BinaryOperation op, String lhsExp, String rhsExp, Type usedType) {
    public String GenerateBinaryOperation(BinaryOperation op, String lhsExp, String rhsExp, Type inputType) {
          return "(" + lhsExp + " " + EventBExpressionGenerator.ConvertToOutputOp(op) + " " + rhsExp + ")";
    }

    @Override
    public String GenerateUnaryOperation(UnaryOperation op, String expression, Type usedType) {
    public String GenerateUnaryOperation(UnaryOperation op, String expression, Type inputType) {
          return "(" + EventBExpressionGenerator.ConvertToOutputOp(op) + " " + expression + ")";
    }

+41 −4
Original line number Diff line number Diff line
@@ -29,11 +29,48 @@
package ca.mcscert.jtet.expression;

/**
 *
 * @author matthew
 * Provides the visitor interface for the expression generation.
 * <p>
 * Users looking to extract information from the AST can implement this interface.  It is designed to work with generators
 * to produce a new string representing the expression, but can be used to simply visit each node as well.
 * @author Matthew Dawson
 */
public interface ExpressionGenerator {
    public String GenerateUnaryOperation(UnaryOperation op, String expression, Type usedType);
    public String GenerateBinaryOperation(BinaryOperation op, String lhsExp, String rhsExp, Type usedType);
    /**
     * Visit a node with a unary expression.
     * <p>
     * When a unary expression (like negation) occurs, this function is called passing in the various information realted
     * to it.
     * @param op The unary op at this node.
     * @param expression The string representing the expression this node is applied to.
     * @param inputType The type of the input (which should match the output).
     * @return A string representing this part of the expression.
     */
    public String GenerateUnaryOperation(UnaryOperation op, String expression, Type inputType);

    /**
     * Visit a node with a binary operation.
     * <p>
     * Similar to {@link #GenerateUnaryOperation}, this handles the binary operations.  Binary operations do distinguish
     * between the left and right hand side when calling into this function, and matches what is in the AST.  Also, the
     * input type is always the output type fo the two given expressions.  It is assumed the output type of this expression
     * is either the input type, or is a boolean for comparison operators.  That type change is handled by jTET's type system.
     * @param op The binary operation at this node.
     * @param lhsExp The string representing the left hand side of this operation.
     * @param rhsExp The string representing the right hand side of this operation.
     * @param inputType The type of the input.
     * @return A string representing this part of the expression.
     */
    public String GenerateBinaryOperation(BinaryOperation op, String lhsExp, String rhsExp, Type inputType);

    /**
     * Generates a string representing the given literal.
     * <p>
     * This converts the string form of the given literal into an appropriate output for the language.  Currently this
     * only deals with real numbers.
     * @param value A string representing a given number.
     * @param requestedType The type to use for the output.
     * @return A string representing this literal in an appropriate form.
     */
    public String GenerateLiteralValue(String value, Type requestedType);
}
+6 −6
Original line number Diff line number Diff line
@@ -53,18 +53,18 @@ public class ExpressionGeneratorSpy implements ExpressionGenerator {
     * {@inheritDoc}
     */
    @Override
    public String GenerateUnaryOperation(UnaryOperation op, String expression, Type usedType) {
        m_spiedUnaryOps.add(new SpiedUnaryOp(op, expression, usedType));
        return expressionGenerator.GenerateUnaryOperation(op, expression, usedType);
    public String GenerateUnaryOperation(UnaryOperation op, String expression, Type inputType) {
        m_spiedUnaryOps.add(new SpiedUnaryOp(op, expression, inputType));
        return expressionGenerator.GenerateUnaryOperation(op, expression, inputType);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String GenerateBinaryOperation(BinaryOperation op, String lhsExp, String rhsExp, Type usedType) {
        m_spiedBinaryOps.add(new SpiedBinaryOp(lhsExp, op, rhsExp, usedType));
        return expressionGenerator.GenerateBinaryOperation(op, lhsExp, rhsExp, usedType);
    public String GenerateBinaryOperation(BinaryOperation op, String lhsExp, String rhsExp, Type inputType) {
        m_spiedBinaryOps.add(new SpiedBinaryOp(lhsExp, op, rhsExp, inputType));
        return expressionGenerator.GenerateBinaryOperation(op, lhsExp, rhsExp, inputType);
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ public class SALExpressionGenerator implements ExpressionGenerator {
    }

    @Override
    public String GenerateBinaryOperation(BinaryOperation op, String lhsExp, String rhsExp, Type usedType) {
    public String GenerateBinaryOperation(BinaryOperation op, String lhsExp, String rhsExp, Type inputType) {
        return "(" + lhsExp + " " + GetInfixSymbolFor(op) + " " + rhsExp + ")";
    }

@@ -88,7 +88,7 @@ public class SALExpressionGenerator implements ExpressionGenerator {
    }

    @Override
    public String GenerateUnaryOperation(UnaryOperation op, String expression, Type usedType) {
    public String GenerateUnaryOperation(UnaryOperation op, String expression, Type inputType) {
        return "(" + GetUnaryOperationSymbolFor(op) + " " + expression + ")";
    }

Loading