Class Type

Direct Known Subclasses:
OverLoad

public class Type extends SyntaxClass

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
  • Field Details

    • keyWord

      public int keyWord
      The keyWord attribute
    • classIdent

      public String classIdent
      The Class Identifier in case of ref(classIdent)
    • 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
    • T_UNDEF

      public static final int T_UNDEF
      Simula's No type
      See Also:
    • T_INTEGER

      public static final int T_INTEGER
      Simula's Integer type
      See Also:
    • T_REAL

      public static final int T_REAL
      Simula's Real type
      See Also:
    • T_LONG_REAL

      public static final int T_LONG_REAL
      Simula's Long Real type
      See Also:
    • T_BOOLEAN

      public static final int T_BOOLEAN
      Simula's Boolean type
      See Also:
    • T_CHARACTER

      public static final int T_CHARACTER
      Simula's Character type
      See Also:
    • T_TEXT

      public static final int T_TEXT
      Simula's Text type
      See Also:
    • T_REF

      public static final int T_REF
      Simula's Ref() type
      See Also:
    • T_PROCEDURE

      public static final int T_PROCEDURE
      Simula's Procedure type
      See Also:
    • T_LABEL

      public static final int T_LABEL
      Simula's Label type
      See Also:
    • Undef

      public static final Type Undef
      Simula's Undefined type
    • 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
  • Constructor Details

    • Type

      private Type(int keyWord)
      Create a new simple Type with the given keyWord
      Parameters:
      keyWord - the given keyWord
    • Type

      public Type(int keyWord, String classIdent)
      Create a new simple Type with the given keyWord and classIdent
      Parameters:
      keyWord - the given keyWord
      classIdent - the given class identifier
    • Type

      public Type(String classIdent)
      Create a new ref(classIdent) type.
      Parameters:
      classIdent - 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 classIdent)
      Simula's Ref(classIdent) type
      Parameters:
      classIdent - the class name
      Returns:
      a new ref(classIdent) type.
    • getQual

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

      public static boolean equalsOrSubordinate(Type t1, Type t2)
      Check if types are equals or subordinate.
      Parameters:
      t1 - a type
      t2 - a type
      Returns:
      true: if types are equals or subordinate.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • 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.
    • isValueType

      public boolean isValueType()
      Returns true if this type is a value type. Integer, real or long real.
      Returns:
      true if this type is a value type.
    • isReferenceType

      public boolean isReferenceType()
      Returns true if this type is ref or text type.
      Returns:
      true if this type is ref or text type
    • isRefClassType

      public boolean isRefClassType()
      Returns true if this type is ref type.
      Returns:
      true if this type is ref type
    • 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()
      ClassFile coding utility: toJavaType.
      Returns:
      the resulting code string.
    • toJavaTypeClass

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

      public String toJavaArrayType()
      ClassFile coding utility: toJavaArrayType.
      Returns:
      the resulting code string.
    • getArrayType

      public String getArrayType()
      Return RTS Array type String.
      Returns:
      RTS Array type String.
    • toJVMType

      public String toJVMType(int kind, int mode)
      ClassFile coding utility: toJVMType.
      Parameters:
      kind - kind code.
      mode - mode code.
      Returns:
      the resulting code string.
    • toJVMType

      public String toJVMType()
      ClassFile coding utility: toJVMType.
      Returns:
      the resulting code string.
    • toJVMClassType

      public static String toJVMClassType(Type type, int kind)
      ClassFile coding utility: toJVMType. Used by: Thunk.buildClassFile.
      Parameters:
      type - a type
      kind - a kind code
      Returns:
      the resulting code string.
    • toClassDesc

      public ClassDesc toClassDesc(Declaration declaredIn)
      ClassFile coding utility: toClassDesc.
      Parameters:
      declaredIn - the owner.
      Returns:
      the resulting Class Descriptor.
    • toClassDesc

      public ClassDesc toClassDesc()
      ClassFile coding utility: toClassDesc.
      Returns:
      the resulting Class Descriptor.
    • toClassDesc

      public ClassDesc toClassDesc(int kind, int mode)
      ClassFile coding utility: toClassDesc.
      Parameters:
      kind - a kind code
      mode - a mode code
      Returns:
      the resulting Class Descriptor.
    • toObjectClassDesc

      public ClassDesc toObjectClassDesc()
      ClassFile coding utility: toClassDesc.
      Returns:
      the resulting Class Descriptor.
    • toNameClassSignature

      public ClassSignature toNameClassSignature()
      ClassFile coding utility: toNameClassSignature.
      Returns:
      the resulting Class Signature.
    • toArrayClassSignature

      public ClassSignature toArrayClassSignature()
      ClassFile coding utility: toArrayClassSignature.
      Returns:
      the resulting Array Class Signature.
    • dup

      public void dup(CodeBuilder codeBuilder)
      ClassFile coding utility: code instruction dup acording to type.
      Parameters:
      codeBuilder - the codeBuilder
    • dup_x1

      public void dup_x1(CodeBuilder codeBuilder)
      ClassFile coding utility: code instruction dup_x1 acording to type.
      Parameters:
      codeBuilder - the codeBuilder
    • pop

      public void pop(CodeBuilder codeBuilder)
      ClassFile coding utility: code instruction pop acording to type.
      Parameters:
      codeBuilder - the codeBuilder
    • checkCast

      public void checkCast(CodeBuilder codeBuilder)
      ClassFile coding utility: code instruction checkcast acording to type.
      Parameters:
      codeBuilder - the codeBuilder
    • valueToPrimitiveType

      public void valueToPrimitiveType(CodeBuilder codeBuilder)
      Convert JVM Object value to primitive type value.
      Parameters:
      codeBuilder - the CodeBuilder to use
    • buildObjectValueOf

      public void buildObjectValueOf(CodeBuilder codeBuilder)
      ClassFile coding utility: buildObjectValueOf
      Parameters:
      codeBuilder - the CodeBuilder to use
    • toString

      public String toString()
      Overrides:
      toString in class Object