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
Represents a type symbol, such as int or float4.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
static final class
static final class
CoercionCost.static final record
Represents a single field in a struct/block type.static final class
static final class
static final class
static final class
static final class
static final class
static final class
Nested classes/interfaces inherited from class icyllis.arc3d.compiler.tree.Node
Node.ElementKind, Node.ExpressionKind, Node.StatementKind, Node.SymbolKind
-
Field Summary
Modifier and TypeFieldDescriptionstatic final byte
Kinds of Type.static final byte
Kinds of ScalarType.static final byte
Kinds of ScalarType.static final byte
Kinds of Type.static final byte
Kinds of Type.static final int
static final byte
Kinds of ScalarType.static final byte
Kinds of Type.static final byte
Kinds of Type.static final byte
Kinds of Type.static final byte
Kinds of ScalarType.static final byte
Kinds of Type.static final byte
Kinds of ScalarType.static final int
static final byte
Kinds of Type.static final byte
Kinds of Type. -
Method Summary
Modifier and TypeMethodDescriptionfinal 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.getArrayName
(int size) Converts an element type and a size (float, 10) into an array name ("float[10]").int
For arrays, returns either the size of the array (if known) or -1 (unsized).Type[]
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
For type that contains scalars, returns the number of scalars.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
For sampler/image types, returns the SpvDim.For arrays, returns the base type.@Unmodifiable Type.Field[]
getKind()
double
Returns the maximum value that can fit in the type.double
Returns the minimum value that can fit in the type.int
For scalars, returns the minimum size in bits of the type.int
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
Returns the ScalarKind of this type (always NonScalar for non-scalar values).final Type
getType()
Returns this.final byte
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
True for arrayed texture.final boolean
Returns true if this type is a bool.final boolean
Returns true if this type is a bool, or its vector form.boolean
final boolean
isFloat()
Returns true if this is a floating-point scalar type (float or half).final boolean
Returns true if this is a floating-point scalar type (float or half), or its vector/matrix form.final boolean
final boolean
Returns true if this type is known to come from BuiltinTypes.final boolean
Returns true if this is a signed or unsigned integer.boolean
boolean
isMatrix()
boolean
final boolean
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
Returns true if the component type has relaxed precision.boolean
boolean
isScalar()
boolean
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
Returns true if this is a signed scalar type (int or short), or its vector form.boolean
boolean
isStruct()
final boolean
Returns true if this is an unsigned scalar type (uint or ushort).final boolean
Returns true if this is an unsigned scalar type (uint or ushort), or its vector form.boolean
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
Returns true if these types are equal after alias resolution.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
Returns the corresponding vector type with the specified number of rows.Methods inherited from class icyllis.arc3d.compiler.tree.Node
getEndOffset, getStartOffset
-
Field Details
-
kUnsizedArray
public static final int kUnsizedArray- See Also:
-
kMaxNestingDepth
public static final int kMaxNestingDepth- See Also:
-
kArray_TypeKind
public static final byte kArray_TypeKindKinds of Type.- See Also:
-
kGeneric_TypeKind
public static final byte kGeneric_TypeKindKinds of Type.- See Also:
-
kMatrix_TypeKind
public static final byte kMatrix_TypeKindKinds of Type.- See Also:
-
kOther_TypeKind
public static final byte kOther_TypeKindKinds of Type.- See Also:
-
kSampler_TypeKind
public static final byte kSampler_TypeKindKinds of Type.- See Also:
-
kScalar_TypeKind
public static final byte kScalar_TypeKindKinds of Type.- See Also:
-
kStruct_TypeKind
public static final byte kStruct_TypeKindKinds of Type.- See Also:
-
kVector_TypeKind
public static final byte kVector_TypeKindKinds of Type.- See Also:
-
kVoid_TypeKind
public static final byte kVoid_TypeKindKinds of Type.- See Also:
-
kFloat_ScalarKind
public static final byte kFloat_ScalarKindKinds of ScalarType.- See Also:
-
kSigned_ScalarKind
public static final byte kSigned_ScalarKindKinds of ScalarType.- See Also:
-
kUnsigned_ScalarKind
public static final byte kUnsigned_ScalarKindKinds of ScalarType.- See Also:
-
kBoolean_ScalarKind
public static final byte kBoolean_ScalarKindKinds of ScalarType.- See Also:
-
kNonScalar_ScalarKind
public static final byte kNonScalar_ScalarKindKinds of ScalarType.- See Also:
-
-
Method Details
-
makeAliasType
Creates an alias which maps to another type. -
makeAliasType
Creates an alias which maps to another type. -
makeGenericType
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
Create a vector type.- Parameters:
componentType
- a scalar type
-
makeMatrixType
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)
- Parameters:
component
- e.g. texture2D has a type of halfdimensions
- 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
Create a "special" type with the given name.- Parameters:
kind
- a type kind
-
makeArrayType
Creates an array type. CallisUsableInArray(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
-
getType
Returns this. -
resolve
If this is an alias, returns the underlying type, otherwise returns this. -
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
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
Returns true if these types are equal after alias resolution. -
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
-
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
Returns true if an instance of this type can be freely coerced (implicitly converted) to another type. -
getCoercionCost
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:
-
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
-
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
Returns the corresponding vector type with the specified number of rows. -
toCompound
Returns the corresponding vector or matrix type with the specified number of columns and rows. -
getArrayName
Converts an element type and a size (float, 10) into an array name ("float[10]"). -
checkLiteralOutOfRange
Checks if `value` can fit in this type. The type must be scalar. -
isUsableInArray
Reports errors and returns false if this type cannot be used as the element type for an array. -
convertArraySize
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
-
getNestingDepth
public int getNestingDepth()If the type is a struct, returns the depth of the most deeply-nested field.
-