Module Simula

Class TypeConversion


public final class TypeConversion extends Expression
Type Conversion.

Link to GitHub: Source File.

  • Field Details

    • expression

      final Expression expression
      The expression.
  • Constructor Details

    • TypeConversion

      private TypeConversion(Type type, Expression expression)
      Create a new TypeConversion.
      Parameters:
      type - the new type
      expression - the expression
  • Method Details

    • mayBeConvert

      public static String mayBeConvert(Type fromType, Type toType, String expr)
      Test if a TypeConversion is necessary and then create it.
      Parameters:
      fromType - convert from this type
      toType - convert to this type
      expr - the expression
      Returns:
      piece of Java source code
    • testAndCreate

      public static Expression testAndCreate(Type toType, Expression expression)
      Test if a TypeConversion is necessary and then create it.
      Parameters:
      toType - convert to toType
      expression - the expression
      Returns:
      the resulting expression
    • testCastNeccessary

      private static boolean testCastNeccessary(Type toType, Expression expression)
      Test if a TypeConversion is necessary.
      Parameters:
      toType - the desired type
      expression - the expression
      Returns:
      piece of Java source code
    • getWriteableVariable

      public VariableExpression getWriteableVariable()
      Description copied from class: Expression
      Get a writeable variable.

      This method is redefined in Variable, RemoteVariable and TypeConversion

      Overrides:
      getWriteableVariable in class Expression
      Returns:
      a writeable variable or null
    • doChecking

      public void doChecking()
      Description copied from class: SyntaxClass
      Perform semantic checking.

      This must be redefined in every subclass.

      Overrides:
      doChecking in class SyntaxClass
    • maybeStatement

      public boolean maybeStatement()
      Description copied from class: Expression
      Returns true if this expression may be used as a statement.
      Specified by:
      maybeStatement in class Expression
      Returns:
      true if this expression may be used as a statement
    • toJavaCode

      public String toJavaCode()
      Description copied from class: SyntaxClass
      Generate Java code for this Syntax Class.
      Overrides:
      toJavaCode in class SyntaxClass
      Returns:
      Java code
    • toString

      public String toString()
      Overrides:
      toString in class Expression