Module Simula

Class Type

All Implemented Interfaces:
Externalizable, Serializable
Direct Known Subclasses:
OverLoad

public sealed class Type extends SyntaxClass implements Externalizable permits OverLoad
Utility class Type.
 Syntax: 
     type = value-type
          | reference-type
          
        value-type = arithmetic-type
                   | boolean
                   | character
                   
           arithmetic-type = integer-type
                           | real-type
                           
              integer-type = [ short ] integer
              
              real-type = [ long ] real
              
              reference-type = object-reference-type
                             | text
                             
                 object-reference-type = ref "(" qualification ")"
                 
                    qualification = class-identifier
 
Link to GitHub: Source File.
Author:
Øystein Myhre Andersen
See Also:
  • Field Details

    • Integer

      public static final Type Integer
      Simula's Integer type
    • Real

      public static final Type Real
      Simula's Real type
    • LongReal

      public static final Type LongReal
      Simula's Long Real type
    • Boolean

      public static final Type Boolean
      Simula's Boolean type
    • Character

      public static final Type Character
      Simula's Character type
    • Text

      public static final Type Text
      Simula's Text type
    • Ref

      public static final Type Ref
      Simula's Ref() type
    • Procedure

      public static final Type Procedure
      Simula's Procedure type
    • Label

      public static final Type Label
      Simula's Label type
    • qual

      protected ClassDeclaration qual
      Qual in case of ref(Qual) type. Set by doChecking
    • declaredIn

      public ConnectionBlock declaredIn
      Qual's scope in case of ref(Qual) type. Set by doChecking
    • key

      Token key
      KeyWord or ref(classIdentifier)
  • Constructor Details

    • Type

      public Type()
      Default constructor used by Externalization.
    • Type

      public Type(Token key)
      Create a new simple Type with the given key Token
      Parameters:
      key - the given key Token
    • Type

      public Type(String className)
      Create a new ref(className) type.
      Parameters:
      className - the class name
    • Type

      public Type(Type tp, ConnectionBlock declaredIn)
      Create a new Type based on the given Type and ConnectionBlock.
      Parameters:
      tp - the given Type
      declaredIn - the ConnectionBlock
  • Method Details

    • Ref

      public static final Type Ref(String className)
      Simula's Ref(className) type
      Parameters:
      className - the class name
      Returns:
      a new ref(className) type.
    • getQual

      public ClassDeclaration getQual()
      Returns the qualifying ClassDeclaration or null.
      Returns:
      the qualifying ClassDeclaration or null
    • getKeyWord

      public KeyWord getKeyWord()
      Returns the keyWord or the ref-identifier.
      Returns:
      the keyWord or the ref-identifier
    • getRefIdent

      public String getRefIdent()
      Returns the ref-identifier or null.
      Returns:
      the ref-identifier or null
    • getJavaRefIdent

      public String getJavaRefIdent()
      Returns the Java ref-identifier or null.
      Returns:
      the Java ref-identifier or null
    • doChecking

      public void doChecking(DeclarationScope scope)
      Perform semantic checking in the given scope.
      Parameters:
      scope - the given scope
    • isArithmeticType

      public boolean isArithmeticType()
      Returns true if this type is an arithmetic type. Integer, real or long real.
      Returns:
      true if this type is an arithmetic type.
    • isReferenceType

      public boolean isReferenceType()
      Returns true if this type is ref() type.
      Returns:
      true if this type is ref() type
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • isConvertableTo

      public Type.ConversionKind isConvertableTo(Type to)
      Checks if a type-conversion is legal.

      The possible return values are:

      • DirectAssignable - No type-conversion is necessary. E.g. integer to integer
      • ConvertValue - Type-conversion with possible Runtime check is necessary. E.g. real to integer.
      • ConvertRef - Type-conversion with Runtime check is necessary. E.g. ref(A) to ref(B) where B is a subclass of A.
      • Illegal - Conversion is illegal
      Parameters:
      to - the to type-
      Returns:
      the resulting ConversionKind
    • isSubReferenceOf

      public boolean isSubReferenceOf(Type other)
      Utility method isSubReferenceOf.

      ref(B) is a sub-reference of ref(A) iff B is a subclass of A.

      Any ref is a sub-reference of NONE

      Parameters:
      other - the other type
      Returns:
      true if the condition holds
    • commonRefType

      public static Type commonRefType(Type type1, Type type2)
      Returns the type to which both types can be converted.
      Parameters:
      type1 - argument
      type2 - argument
      Returns:
      the resulting Type
    • commonTypeConversion

      public static Type commonTypeConversion(Type type1, Type type2)
      Returns the type to which both types can be converted.
      Parameters:
      type1 - argument
      type2 - argument
      Returns:
      the resulting Type
    • arithmeticTypeConversion

      public static Type arithmeticTypeConversion(Type type1, Type type2)
      Returns the most dominant type.
      Parameters:
      type1 - argument
      type2 - argument
      Returns:
      the most dominant type
    • edDefaultValue

      public String edDefaultValue()
      Returns an edited default value of this Type.
      Returns:
      an edited default value of this Type
    • toJavaType

      public String toJavaType()
      Codeing utility: toJavaType.
      Returns:
      the resulting code string.
    • toJavaTypeClass

      public String toJavaTypeClass()
      Codeing utility: toJavaTypeClass.
      Returns:
      the resulting code string.
    • toJavaArrayType

      public String toJavaArrayType()
      Codeing utility: toJavaArrayType.
      Returns:
      the resulting code string.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • inType

      public static Type inType(ObjectInput inpt) throws IOException, ClassNotFoundException
      Read a type from an ObjectInput file.
      Parameters:
      inpt - the ObjectInput
      Returns:
      the resulting Type
      Throws:
      IOException - if an IOException occur
      ClassNotFoundException - if the operation failed
    • writeExternal

      public void writeExternal(ObjectOutput oupt) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput inpt) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException