Class LangPrimType

All Implemented Interfaces:
HasOwningField, TypeValue, Type

public class LangPrimType extends PrimType implements TypeValue, HasOwningField
Use to implement some special types that convert differently. May not be needed/appropriate any more now that we support arithmetic on a mix of Java and Kawa types.
  • Field Details

    • byteType

      public static final PrimType byteType
    • shortType

      public static final PrimType shortType
    • intType

      public static final PrimType intType
    • longType

      public static final PrimType longType
    • floatType

      public static final PrimType floatType
    • doubleType

      public static final PrimType doubleType
    • charType

      public static final LangPrimType charType
    • voidType

      public static final PrimType voidType
    • characterType

      public static final LangPrimType characterType
    • characterOrEofType

      public static final LangPrimType characterOrEofType
    • unsignedLongType

      public static final LangPrimType unsignedLongType
    • unsignedIntType

      public static final LangPrimType unsignedIntType
    • unsignedShortType

      public static final LangPrimType unsignedShortType
    • unsignedByteType

      public static final LangPrimType unsignedByteType
    • stringCursorType

      public static final LangPrimType stringCursorType
    • isTrueType

      public static final LangPrimType isTrueType
      Special type used for boolean-valued guard expressions in patterns.
  • Constructor Details

  • Method Details

    • getImplementationType

      public Type getImplementationType()
      Description copied from class: Type
      Return Java-level implementation type. The type used to implement types not natively understood by the JVM or the Java language. Usually, the identity function. However, a language might handle union types or template types or type expressions calculated at run time. In that case return the type used at the Java level, and known at compile time.
      Specified by:
      getImplementationType in interface TypeValue
      Overrides:
      getImplementationType in class Type
    • getOwningField

      public Field getOwningField()
      Description copied from interface: HasOwningField
      If non-null a field that has this value.
      Specified by:
      getOwningField in interface HasOwningField
    • isUnsigned

      public boolean isUnsigned()
      Overrides:
      isUnsigned in class PrimType
    • boxedType

      public ClassType boxedType()
      Overrides:
      boxedType in class PrimType
    • coerceFromObject

      public Object coerceFromObject(Object obj)
      Description copied from class: Type
      Convert an object to a value of this Type. The result is actually of the implementation type, boxed as appropriate, so it is suitable for standard reflective operations, like the arguments to Field#set or Method#invoke. Throw a ClassCastException when this is not possible.
      Overrides:
      coerceFromObject in class PrimType
    • charValue

      public char charValue(Object value)
      Description copied from class: PrimType
      Coerce value to a char. Only defined if getSignature() is "C".
      Overrides:
      charValue in class PrimType
    • emitIsInstance

      public void emitIsInstance(CodeAttr code)
      Overrides:
      emitIsInstance in class PrimType
    • emitCoerceFromObject

      public void emitCoerceFromObject(CodeAttr code)
      Description copied from class: Type
      Compile code to coerce/convert from Object to this type.
      Overrides:
      emitCoerceFromObject in class PrimType
    • coerceToObject

      public Object coerceToObject(Object obj)
      Description copied from class: Type
      Given a raw JVM value convert it to an object of this type. I.e. the argument is an object of the type returned by getRawType(), boxed as needed. The result may be a language-specific (boxed) value. Generally a no-op.
      Overrides:
      coerceToObject in class Type
    • convertToRaw

      public Object convertToRaw(Object obj)
      Overrides:
      convertToRaw in class PrimType
    • emitCoerceToObject

      public void emitCoerceToObject(CodeAttr code)
      Description copied from class: Type
      Compile code to convert a object of this type on the stack to Object.
      Overrides:
      emitCoerceToObject in class PrimType
    • compare

      public int compare(Type other)
      Description copied from class: Type
      Return a numeric code showing "subtype" relationship: 1: if other is a pure subtype of this; 0: if has the same values; -1: if this is a pure subtype of other; -2: if they have values in common but neither is a subtype of the other; -3: if the types have no values in common. "Same values" is rather loose; by "A is a subtype of B" we mean that all instance of A can be "widened" to B. More formally, A.compare(B) returns: 1: all B values can be converted to A without a coercion failure (i.e. a ClassCastException or overflow or major loss of information), but not vice versa. 0: all A values can be converted to B without a coercion failure and vice versa; -1: all A values can be converted to B without a coercion failure but not vice versa; -2: there are (potentially) some A values that can be converted to B, and some B values can be converted to A; -3: there are no A values that can be converted to B, and neither are there any B values that can be converted to A.
      Overrides:
      compare in class PrimType
    • isCompatibleWithValue

      public int isCompatibleWithValue(Type valueType)
      Description copied from class: Type
      If this is the target type, is a given source type compatible?
      Overrides:
      isCompatibleWithValue in class Type
      Returns:
      -1 if not compatible; 0 if need to check at run-time; 1 if compatible; 2 if compatible and no conversion or cast needed. We also return 0 for some "narrowing" conversions even if we know they will always succeed, so as to make such conversions less preferred when doing method overloading.
    • emitTestIfNumber

      public static void emitTestIfNumber(Variable incoming, Declaration decl, Type type, Compilation comp)
    • emitTestIf

      public void emitTestIf(Variable incoming, Declaration decl, Compilation comp)
      Description copied from interface: TypeValue
      Emit code for if (incoming instanceof this_type) decl = incoming .... This method is designed for typeswitch applications, where this call is the first part of a conditional, so it must be followed by calls to emitElse and emitFi.
      Specified by:
      emitTestIf in interface TypeValue
      Parameters:
      incoming - Contains the value we are testing to see if it has the type of this. If null, use top-of-stack. May not be null if decl is non-null.
      decl - If non-null, assign value after coercion to Declaration.
      comp - The compilation state.
    • convertValue

      public Expression convertValue(Expression value)
      Description copied from interface: TypeValue
      Return converted expression or null.
      Specified by:
      convertValue in interface TypeValue
    • emitIsInstance

      public void emitIsInstance(Variable incoming, Compilation comp, Target target)
      Description copied from interface: TypeValue
      Emit code for incoming instanceof this_type. The implementation can use InstanceOf .emitIsInstance which is a conveniece method that calls emitTestIf.
      Specified by:
      emitIsInstance in interface TypeValue
      Parameters:
      incoming - Contains the value we are testing to see if it has the the type of 'this'. If null, use top-of-stack.
      comp - The compilation state.
      target - Where to leave the result.
    • getConstructor

      public Procedure getConstructor()
      Description copied from interface: TypeValue
      Get the constructor function for this type. Returns null if there is no contructor function. Also returns null if this extends ClassType or ArrayType and standard Java constructors (<init> methods) should be used.
      Specified by:
      getConstructor in interface TypeValue
    • convertIntegerLiteral

      public static Object convertIntegerLiteral(IntNum ivalue, PrimType type, boolean nativeValue)
    • encodeType

      public String encodeType(Language language)
      Specified by:
      encodeType in interface TypeValue