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

Start adding types to everything.


git-svn-id: https://groke.mcmaster.ca/svn/grad/colin/branches/TableTool_javization@9671 57e6efec-57d4-0310-aeb1-a6c144bb1a8b
parent 4438255e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -15,4 +15,8 @@ public class BooleanVariableType implements VariableType {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    @Override
    public boolean canCastToType(VariableType type) {
        return false;
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -30,6 +30,10 @@ final class MatlabExpressionOperation implements MatlabExpression {
        
        if(lhs_type.equals(rhs_type)) {
            return lhs_type;
        } else  if(lhs_type.canCastToType(rhs_type)) {
            return rhs_type;
        } else  if(rhs_type.canCastToType(lhs_type)) {
            return lhs_type;
        } else {
            throw new IllegalStateException("Incompatible types are used together!");
        }
+30 −1
Original line number Diff line number Diff line
@@ -25,5 +25,34 @@ public final class MatlabLiteral implements MatlabExpression, MatlabExpressionVa
    }
    
    final String m_value;
    final VariableType m_type = new RealVariableType();
    final VariableType m_type = new LiteralNumberType();
    
    /**
    * This type marks a number as castable to any value.  It is meant to be used with
    * MatlabLiteral, as it will handle 
    * @author matthew
    */
    private static class LiteralNumberType implements VariableType{

        @Override
        public String getCVC3Definition(String variableName) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
        
        @Override
        public boolean equals(Object other) {
            return other instanceof LiteralNumberType;
        }

        @Override
        public boolean canCastToType(VariableType type) {
            return type instanceof RealVariableType;
        }

        @Override
        public int hashCode() {
            return 6;
        }

    }
}
+5 −0
Original line number Diff line number Diff line
@@ -24,4 +24,9 @@ public final class RealVariableType implements VariableType {
    public int hashCode() {
        return 0;
    }

    @Override
    public boolean canCastToType(VariableType type) {
        return false;
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -18,4 +18,13 @@ public interface VariableType {
     * @return The CVC3 type definition
     */
    public String getCVC3Definition(String variableName);
    
    /**
     * Marks whether the type can be cast to this type.  Certain values may be
     * castable to a different type.  If possible, this method will mark it as
     * such.
     * @param type The type this variable type should cast to.
     * @return True if this type can act like the other type.  False otherwise.
     */
    public boolean canCastToType(VariableType type);
}
Loading