Package icyllis.arc3d.compiler.tree

# Class Type

java.lang.Object
icyllis.arc3d.compiler.tree.Node
icyllis.arc3d.compiler.tree.Symbol
icyllis.arc3d.compiler.tree.Type

Direct Known Subclasses:
  `Type.AliasType`, `Type.ArrayType`, `Type.GenericType`, `Type.ImageType`, `Type.MatrixType`, `Type.SamplerType`, `Type.ScalarType`, `Type.StructType`, `Type.VectorType`

public class Type extends Symbol
Represents a type symbol, such as int or float4.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static final class`
  `Type.AliasType`
  `static final class`
  `Type.ArrayType`
  `static final class`
  `Type.CoercionCost`
  CoercionCost.
  `static final record`
  `Type.Field`
  Represents a single field in a struct/block type.
  `static final class`
  `Type.GenericType`
  `static final class`
  `Type.ImageType`
  `static final class`
  `Type.MatrixType`
  `static final class`
  `Type.SamplerType`
  `static final class`
  `Type.ScalarType`
  `static final class`
  `Type.StructType`
  `static final class`
  `Type.VectorType`

  ## Nested classes/interfaces inherited from class icyllis.arc3d.compiler.tree.Node

  `Node.ElementKind, Node.ExpressionKind, Node.StatementKind, Node.SymbolKind`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final byte`
  `kArray_TypeKind`
  Kinds of Type.
  `static final byte`
  `kBoolean_ScalarKind`
  Kinds of ScalarType.
  `static final byte`
  `kFloat_ScalarKind`
  Kinds of ScalarType.
  `static final byte`
  `kGeneric_TypeKind`
  Kinds of Type.
  `static final byte`
  `kMatrix_TypeKind`
  Kinds of Type.
  `static final int`
  `kMaxNestingDepth`
  `static final byte`
  `kNonScalar_ScalarKind`
  Kinds of ScalarType.
  `static final byte`
  `kOther_TypeKind`
  Kinds of Type.
  `static final byte`
  `kSampler_TypeKind`
  Kinds of Type.
  `static final byte`
  `kScalar_TypeKind`
  Kinds of Type.
  `static final byte`
  `kSigned_ScalarKind`
  Kinds of ScalarType.
  `static final byte`
  `kStruct_TypeKind`
  Kinds of Type.
  `static final byte`
  `kUnsigned_ScalarKind`
  Kinds of ScalarType.
  `static final int`
  `kUnsizedArray`
  `static final byte`
  `kVector_TypeKind`
  Kinds of Type.
  `static final byte`
  `kVoid_TypeKind`
  Kinds of Type.

  ### Fields inherited from class icyllis.arc3d.compiler.tree.Node

  `mPosition`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final boolean`
  `canCoerceTo(Type other, boolean allowNarrowing)`
  Returns true if an instance of this type can be freely coerced (implicitly converted) to another type.
  `boolean`
  `checkLiteralOutOfRange(Context context, int pos, double value)`
  Checks if `value` can fit in this type.
  `final Expression`
  `coerceExpression(Context context, Expression expr)`
  Coerces the passed-in expression to this type.
  `int`
  `convertArraySize(Context context, int position, int sizePosition, long size)`
  `int`
  `convertArraySize(Context context, int position, Expression size)`
  Verifies that the expression is a valid constant array size for this type.
  `String`
  `getArrayName(int size)`
  Converts an element type and a size (float, 10) into an array name ("float[10]").
  `int`
  `getArraySize()`
  For arrays, returns either the size of the array (if known) or -1 (unsized).
  `Type[]`
  `getCoercibleTypes()`
  For generic types, returns the types that this generic type can substitute for.
  `final long`
  `getCoercionCost(Type other)`
  Determines the "cost" of coercing (implicitly converting) this type to another type.
  `int`
  `getCols()`
  For matrices, returns the number of columns (e.g.
  `int`
  `getComponents()`
  For type that contains scalars, returns the number of scalars.
  `Type`
  `getComponentType()`
  For matrices and vectors, returns the scalar type of individual cells (e.g.
  `final String`
  `getDesc()`
  Returns a descriptor of the type, meant for name-mangling.
  `int`
  `getDimensions()`
  For sampler/image types, returns the SpvDim.
  `Type`
  `getElementType()`
  For arrays, returns the base type.
  `@Unmodifiable Type.Field[]`
  `getFields()`
  `Node.SymbolKind`
  `getKind()`
  `double`
  `getMaxValue()`
  Returns the maximum value that can fit in the type.
  `double`
  `getMinValue()`
  Returns the minimum value that can fit in the type.
  `int`
  `getMinWidth()`
  For scalars, returns the minimum size in bits of the type.
  `int`
  `getNestingDepth()`
  If the type is a struct, returns the depth of the most deeply-nested field.
  `int`
  `getRank()`
  Returns the "rank" of a numeric type, in order of float > half > int > short.
  `int`
  `getRows()`
  For matrices and vectors, returns the number of rows (e.g.
  `byte`
  `getScalarKind()`
  Returns the ScalarKind of this type (always NonScalar for non-scalar values).
  `final Type`
  `getType()`
  Returns this.
  `final byte`
  `getTypeKind()`
  Returns the category (scalar, vector, matrix, etc.) of this type.
  `int`
  `getWidth()`
  For scalars, returns the size in bits of the type.
  `boolean`
  `isArray()`
  `boolean`
  `isArrayed()`
  True for arrayed texture.
  `final boolean`
  `isBoolean()`
  Returns true if this type is a bool.
  `final boolean`
  `isBooleanOrCompound()`
  Returns true if this type is a bool, or its vector form.
  `boolean`
  `isCombinedSampler()`
  `final boolean`
  `isFloat()`
  Returns true if this is a floating-point scalar type (float or half).
  `final boolean`
  `isFloatOrCompound()`
  Returns true if this is a floating-point scalar type (float or half), or its vector/matrix form.
  `final boolean`
  `isGeneric()`
  `final boolean`
  `isInBuiltinTypes()`
  Returns true if this type is known to come from BuiltinTypes.
  `final boolean`
  `isInteger()`
  Returns true if this is a signed or unsigned integer.
  `boolean`
  `isInterfaceBlock()`
  `boolean`
  `isMatrix()`
  `boolean`
  `isMultiSampled()`
  `final boolean`
  `isNumeric()`
  Returns true if this is a numeric scalar type.
  `final boolean`
  `isOpaque()`
  Returns true if this is an "opaque type" (an external object which the shader references in some fashion).
  `boolean`
  `isRelaxedPrecision()`
  Returns true if the component type has relaxed precision.
  `boolean`
  `isSampled()`
  `boolean`
  `isScalar()`
  `boolean`
  `isSeparateSampler()`
  `boolean`
  `isShadow()`
  True for samplers that sample a depth texture with comparison (e.g., samplerShadow, sampler2DShadow, HLSL SamplerComparisonState).
  `final boolean`
  `isSigned()`
  Returns true if this is a signed scalar type (int or short).
  `final boolean`
  `isSignedOrCompound()`
  Returns true if this is a signed scalar type (int or short), or its vector form.
  `boolean`
  `isStorageImage()`
  `boolean`
  `isStruct()`
  `final boolean`
  `isUnsigned()`
  Returns true if this is an unsigned scalar type (uint or ushort).
  `final boolean`
  `isUnsignedOrCompound()`
  Returns true if this is an unsigned scalar type (uint or ushort), or its vector form.
  `boolean`
  `isUnsizedArray()`
  `boolean`
  `isUsableInArray(Context context, int position)`
  Reports errors and returns false if this type cannot be used as the element type for an array.
  `boolean`
  `isVector()`
  `final boolean`
  `isVoid()`
  `static Type`
  `makeAliasType(int position, String name, Type type)`
  Creates an alias which maps to another type.
  `static Type`
  `makeAliasType(String name, Type type)`
  Creates an alias which maps to another type.
  `static Type`
  `makeArrayType(String name, Type type, int size)`
  Creates an array type.
  `static Type`
  `makeCombinedType(String name, String abbr, Type component, int dimensions, boolean isShadow, boolean isArrayed, boolean isMultiSampled)`
  Create a combined sampler type.
  `static Type`
  `makeGenericType(String name, Type... types)`
  Create a generic type which maps to the listed types (e.g.
  `static Type`
  `makeImageType(String name, String abbr, Type component, int dimensions, boolean isArrayed, boolean isMultiSampled)`
  Create an image or subpass type.
  `static Type`
  `makeMatrixType(String name, String desc, Type columnType, int cols)`
  Create a matrix type.
  `static Type`
  `makeSamplerType(String name, String abbr, Type component, int dimensions, boolean isShadow, boolean isArrayed, boolean isMultiSampled, boolean isSampled, boolean isSampler)`
  Create a sampler/image type.
  `static Type`
  `makeScalarType(String name, String desc, byte kind, int rank, int width)`
  Create a scalar type.
  `static Type`
  `makeScalarType(String name, String desc, byte kind, int rank, int minWidth, int width)`
  Create a scalar type with minimum precision.
  `static Type`
  `makeSeparateType(String name, String abbr, Type component, boolean isShadow)`
  Create a separate sampler type.
  `static Type`
  `makeSpecialType(String name, String abbr, byte kind)`
  Create a "special" type with the given name.
  `static Type`
  `makeStructType(Context context, int position, String name, List<Type.Field> fields, boolean interfaceBlock)`
  Creates a struct type with the given fields.
  `static Type`
  `makeTextureType(String name, String abbr, Type component, int dimensions, boolean isArrayed, boolean isMultiSampled)`
  Create a texture type.
  `static Type`
  `makeVectorType(String name, String desc, Type componentType, int rows)`
  Create a vector type.
  `final boolean`
  `matches(Type other)`
  Returns true if these types are equal after alias resolution.
  `Type`
  `resolve()`
  If this is an alias, returns the underlying type, otherwise returns this.
  `final Type`
  `toCompound(Context context, int cols, int rows)`
  Returns the corresponding vector or matrix type with the specified number of columns and rows.
  `final String`
  `toString()`
  `final Type`
  `toVector(Context context, int rows)`
  Returns the corresponding vector type with the specified number of rows.

  ### Methods inherited from class icyllis.arc3d.compiler.tree.Symbol

  `accept, getName, setName`

  ### Methods inherited from class icyllis.arc3d.compiler.tree.Node

  `getEndOffset, getStartOffset`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### kUnsizedArray

    public static final int kUnsizedArray
    See Also:
      - Constant Field Values

  - ### kMaxNestingDepth

    public static final int kMaxNestingDepth
    See Also:
      - Constant Field Values

  - ### kArray_TypeKind

    public static final byte kArray_TypeKind
    Kinds of Type.
    See Also:
      - Constant Field Values

  - ### kGeneric_TypeKind

    public static final byte kGeneric_TypeKind
    Kinds of Type.
    See Also:
      - Constant Field Values

  - ### kMatrix_TypeKind

    public static final byte kMatrix_TypeKind
    Kinds of Type.
    See Also:
      - Constant Field Values

  - ### kOther_TypeKind

    public static final byte kOther_TypeKind
    Kinds of Type.
    See Also:
      - Constant Field Values

  - ### kSampler_TypeKind

    public static final byte kSampler_TypeKind
    Kinds of Type.
    See Also:
      - Constant Field Values

  - ### kScalar_TypeKind

    public static final byte kScalar_TypeKind
    Kinds of Type.
    See Also:
      - Constant Field Values

  - ### kStruct_TypeKind

    public static final byte kStruct_TypeKind
    Kinds of Type.
    See Also:
      - Constant Field Values

  - ### kVector_TypeKind

    public static final byte kVector_TypeKind
    Kinds of Type.
    See Also:
      - Constant Field Values

  - ### kVoid_TypeKind

    public static final byte kVoid_TypeKind
    Kinds of Type.
    See Also:
      - Constant Field Values

  - ### kFloat_ScalarKind

    public static final byte kFloat_ScalarKind
    Kinds of ScalarType.
    See Also:
      - Constant Field Values

  - ### kSigned_ScalarKind

    public static final byte kSigned_ScalarKind
    Kinds of ScalarType.
    See Also:
      - Constant Field Values

  - ### kUnsigned_ScalarKind

    public static final byte kUnsigned_ScalarKind
    Kinds of ScalarType.
    See Also:
      - Constant Field Values

  - ### kBoolean_ScalarKind

    public static final byte kBoolean_ScalarKind
    Kinds of ScalarType.
    See Also:
      - Constant Field Values

  - ### kNonScalar_ScalarKind

    public static final byte kNonScalar_ScalarKind
    Kinds of ScalarType.
    See Also:
      - Constant Field Values

- ## Method Details

  - ### makeAliasType

    @Nonnull public static Type makeAliasType(String name, Type type)
    Creates an alias which maps to another type.

  - ### makeAliasType

    @Nonnull public static Type makeAliasType(int position, String name, Type type)
    Creates an alias which maps to another type.

  - ### makeGenericType

    @Nonnull public static Type makeGenericType(String name, Type... types)
    Create a generic type which maps to the listed types (e.g. __genFType is a generic type which can match float, float2, float3 or float4).

  - ### makeScalarType

    @Nonnull public static Type makeScalarType(String name, String desc, byte kind, int rank, int width)
    Create a scalar type.
    Parameters:
      `kind` - a scalar kind

  - ### makeScalarType

    @Nonnull public static Type makeScalarType(String name, String desc, byte kind, int rank, int minWidth, int width)
    Create a scalar type with minimum precision.
    Parameters:
      `kind` - a scalar kind

  - ### makeVectorType

    @Nonnull public static Type makeVectorType(String name, String desc, Type componentType, int rows)
    Create a vector type.
    Parameters:
      `componentType` - a scalar type

  - ### makeMatrixType

    @Nonnull public static Type makeMatrixType(String name, String desc, Type columnType, int cols)
    Create a matrix type.
    Parameters:
      `columnType` - a vector type

  - ### makeSamplerType

    @Nonnull public static Type makeSamplerType(String name, String abbr, Type component, int dimensions, boolean isShadow, boolean isArrayed, boolean isMultiSampled, boolean isSampled, boolean isSampler)
    Create a sampler/image type. Includes images, textures without sampler, textures with sampler and pure samplers.
    - isSampled=true,isSampler=true: combined texture sampler (e.g. sampler2D)
    - isSampled=true,isSampler=false: pure texture (e.g. texture2D)
    - isSampled=false,isSampler=true: pure sampler (e.g. sampler)
    - isSampled=false,isSampler=false: image or subpass (e.g. image2D)
    isShadow: True for samplers that sample a depth texture with comparison (e.g. samplerShadow, sampler2DShadow, HLSL's SamplerComparisonState).
    Parameters:
      `component` - e.g. texture2D has a type of half
      `dimensions` - SpvDim (e.g. `Spv.SpvDim1D`)

  - ### makeImageType

    @Nonnull public static Type makeImageType(String name, String abbr, Type component, int dimensions, boolean isArrayed, boolean isMultiSampled)
    Create an image or subpass type.

  - ### makeTextureType

    @Nonnull public static Type makeTextureType(String name, String abbr, Type component, int dimensions, boolean isArrayed, boolean isMultiSampled)
    Create a texture type.

  - ### makeSeparateType

    @Nonnull public static Type makeSeparateType(String name, String abbr, Type component, boolean isShadow)
    Create a separate sampler type.

  - ### makeCombinedType

    @Nonnull public static Type makeCombinedType(String name, String abbr, Type component, int dimensions, boolean isShadow, boolean isArrayed, boolean isMultiSampled)
    Create a combined sampler type.

  - ### makeSpecialType

    @Nonnull public static Type makeSpecialType(String name, String abbr, byte kind)
    Create a "special" type with the given name.
    Parameters:
      `kind` - a type kind

  - ### makeArrayType

    @Nonnull public static Type makeArrayType(String name, Type type, int size)
    Creates an array type. Call `isUsableInArray(Context, int)` first.
    Parameters:
      `type` - the element type

  - ### makeStructType

    @Nonnull public static Type makeStructType(@Nonnull Context context, int position, @Nonnull String name, @Nonnull List<Type.Field> fields, boolean interfaceBlock)
    Creates a struct type with the given fields. Reports an error if the struct is ill-formed.

  - ### getKind

    @Nonnull public Node.SymbolKind getKind()
    Specified by:
      `getKind` in class `Symbol`
    See Also:
      - `Node.SymbolKind`

  - ### getType

    @Nonnull public final Type getType()
    Returns this.
    Specified by:
      `getType` in class `Symbol`

  - ### resolve

    @Nonnull public Type resolve()
    If this is an alias, returns the underlying type, otherwise returns this.

  - ### getElementType

    @Nonnull public Type getElementType()
    For arrays, returns the base type. For matrices, returns the column vector type. For vectors, returns the scalar type. For all other types, returns the type itself.

  - ### getComponentType

    @Nonnull public Type getComponentType()
    For matrices and vectors, returns the scalar type of individual cells (e.g. mat2 has a component type of Float). For textures, returns the sampled type (e.g. texture2D has a component type of Float). For arrays, returns the component type of their base type. For all other types, returns the type itself.

  - ### matches

    public final boolean matches(@Nonnull Type other)
    Returns true if these types are equal after alias resolution.

  - ### getDesc

    @Nonnull public final String getDesc()
    Returns a descriptor of the type, meant for name-mangling. (e.g. float4x4 -> f44)

  - ### getTypeKind

    public final byte getTypeKind()
    Returns the category (scalar, vector, matrix, etc.) of this type.

  - ### getScalarKind

    public byte getScalarKind()
    Returns the ScalarKind of this type (always NonScalar for non-scalar values).

  - ### toString

    @Nonnull public final String toString()
    Specified by:
      `toString` in class `Node`
    Returns:
      a string representation of this AST node

  - ### isInBuiltinTypes

    public final boolean isInBuiltinTypes()
    Returns true if this type is known to come from BuiltinTypes. If this returns true, the Type will always be available in the root SymbolTable and never needs to be copied to migrate an Expression from one location to another. If it returns false, the Type might not exist in a separate SymbolTable, and you'll need to consider copying it.

  - ### isBoolean

    public final boolean isBoolean()
    Returns true if this type is a bool.

  - ### isNumeric

    public final boolean isNumeric()
    Returns true if this is a numeric scalar type.

  - ### isFloat

    public final boolean isFloat()
    Returns true if this is a floating-point scalar type (float or half).

  - ### isSigned

    public final boolean isSigned()
    Returns true if this is a signed scalar type (int or short).

  - ### isUnsigned

    public final boolean isUnsigned()
    Returns true if this is an unsigned scalar type (uint or ushort).

  - ### isInteger

    public final boolean isInteger()
    Returns true if this is a signed or unsigned integer.

  - ### isFloatOrCompound

    public final boolean isFloatOrCompound()
    Returns true if this is a floating-point scalar type (float or half), or its vector/matrix form.

  - ### isSignedOrCompound

    public final boolean isSignedOrCompound()
    Returns true if this is a signed scalar type (int or short), or its vector form.

  - ### isUnsignedOrCompound

    public final boolean isUnsignedOrCompound()
    Returns true if this is an unsigned scalar type (uint or ushort), or its vector form.

  - ### isBooleanOrCompound

    public final boolean isBooleanOrCompound()
    Returns true if this type is a bool, or its vector form.

  - ### isOpaque

    public final boolean isOpaque()
    Returns true if this is an "opaque type" (an external object which the shader references in some fashion). Link

  - ### isGeneric

    public final boolean isGeneric()

  - ### getRank

    public int getRank()
    Returns the "rank" of a numeric type, in order of float > half > int > short. When operating on two numeric types, the result is the higher-rank type.

  - ### canCoerceTo

    public final boolean canCoerceTo(Type other, boolean allowNarrowing)
    Returns true if an instance of this type can be freely coerced (implicitly converted) to another type.

  - ### getCoercionCost

    public final long getCoercionCost(Type other)
    Determines the "cost" of coercing (implicitly converting) this type to another type. The cost is a number with no particular meaning other than that lower costs are preferable to higher costs.
    See Also:
      - `Type.CoercionCost`

  - ### getCoercibleTypes

    @Nonnull public Type[] getCoercibleTypes()
    For generic types, returns the types that this generic type can substitute for.

  - ### coerceExpression

    @Nullable public final Expression coerceExpression(@Nonnull Context context, @Nullable Expression expr)
    Coerces the passed-in expression to this type. If the types are incompatible, reports an error and returns null.

  - ### getMinValue

    public double getMinValue()
    Returns the minimum value that can fit in the type.

  - ### getMaxValue

    public double getMaxValue()
    Returns the maximum value that can fit in the type.

  - ### getCols

    public int getCols()
    For matrices, returns the number of columns (e.g. mat3x4 returns 3). For scalars and vectors, returns 1. For all other types, causes an assertion failure.

  - ### getRows

    public int getRows()
    For matrices and vectors, returns the number of rows (e.g. mat3x4 return 4). For scalars, returns 1. For all other types, causes an assertion failure.

  - ### getComponents

    public int getComponents()
    For type that contains scalars, returns the number of scalars. For all other types, causes an assertion failure.

  - ### getArraySize

    public int getArraySize()
    For arrays, returns either the size of the array (if known) or -1 (unsized). For all other types, causes an assertion failure.

  - ### getDimensions

    public int getDimensions()
    For sampler/image types, returns the SpvDim. For all other types, causes an assertion failure.

  - ### getFields

    @Nonnull public @Unmodifiable Type.Field[] getFields()

  - ### isShadow

    public boolean isShadow()
    True for samplers that sample a depth texture with comparison (e.g., samplerShadow, sampler2DShadow, HLSL SamplerComparisonState).

  - ### isArrayed

    public boolean isArrayed()
    True for arrayed texture.

  - ### isVoid

    public final boolean isVoid()

  - ### isScalar

    public boolean isScalar()

  - ### isVector

    public boolean isVector()

  - ### isMatrix

    public boolean isMatrix()

  - ### isArray

    public boolean isArray()

  - ### isUnsizedArray

    public boolean isUnsizedArray()

  - ### isStruct

    public boolean isStruct()

  - ### isInterfaceBlock

    public boolean isInterfaceBlock()

  - ### isMultiSampled

    public boolean isMultiSampled()

  - ### isSampled

    public boolean isSampled()

  - ### isCombinedSampler

    public boolean isCombinedSampler()
    Returns:
      true for texture with sampler

  - ### isSeparateSampler

    public boolean isSeparateSampler()
    Returns:
      true for pure sampler

  - ### isStorageImage

    public boolean isStorageImage()
    Returns:
      true for image, except subpass input

  - ### getMinWidth

    public int getMinWidth()
    For scalars, returns the minimum size in bits of the type.

  - ### getWidth

    public int getWidth()
    For scalars, returns the size in bits of the type.

  - ### isRelaxedPrecision

    public boolean isRelaxedPrecision()
    Returns true if the component type has relaxed precision.

  - ### toVector

    public final Type toVector(@Nonnull Context context, int rows)
    Returns the corresponding vector type with the specified number of rows.

  - ### toCompound

    public final Type toCompound(@Nonnull Context context, int cols, int rows)
    Returns the corresponding vector or matrix type with the specified number of columns and rows.

  - ### getArrayName

    @Nonnull public String getArrayName(int size)
    Converts an element type and a size (float, 10) into an array name ("float[10]").

  - ### checkLiteralOutOfRange

    public boolean checkLiteralOutOfRange(Context context, int pos, double value)
    Checks if `value` can fit in this type. The type must be scalar.

  - ### isUsableInArray

    public boolean isUsableInArray(@Nonnull Context context, int position)
    Reports errors and returns false if this type cannot be used as the element type for an array.

  - ### convertArraySize

    public int convertArraySize(@Nonnull Context context, int position, Expression size)
    Verifies that the expression is a valid constant array size for this type. Returns the array size, or reports errors and returns zero if the expression isn't a valid literal value.

  - ### convertArraySize

    public int convertArraySize(@Nonnull Context context, int position, int sizePosition, long size)

  - ### getNestingDepth

    public int getNestingDepth()
    If the type is a struct, returns the depth of the most deeply-nested field.