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
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final classstatic final classCoercionCost.static final recordRepresents a single field in a struct/block type.static final classstatic final classstatic final classstatic final classstatic final classstatic final classstatic final classNested classes/interfaces inherited from class icyllis.arc3d.compiler.tree.Node
Node.ElementKind, Node.ExpressionKind, Node.StatementKind, Node.SymbolKind -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteKinds of Type.static final byteKinds of ScalarType.static final byteKinds of ScalarType.static final byteKinds of Type.static final byteKinds of Type.static final intstatic final byteKinds of ScalarType.static final byteKinds of Type.static final byteKinds of Type.static final byteKinds of Type.static final byteKinds of ScalarType.static final byteKinds of Type.static final byteKinds of ScalarType.static final intstatic final byteKinds of Type.static final byteKinds of Type. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleancanCoerceTo(Type other, boolean allowNarrowing) Returns true if an instance of this type can be freely coerced (implicitly converted) to another type.booleancheckLiteralOutOfRange(Context context, int pos, double value) Checks if `value` can fit in this type.final @Nullable ExpressioncoerceExpression(@NonNull Context context, @Nullable Expression expr) Coerces the passed-in expression to this type.intconvertArraySize(@NonNull Context context, int position, int sizePosition, long size) intconvertArraySize(@NonNull Context context, int position, @Nullable Expression size) Verifies that the expression is a valid constant array size for this type.@NonNull StringgetArrayName(int size) Converts an element type and a size (float, 10) into an array name ("float[10]").static @NonNull StringgetArrayName(@NonNull String baseName, int size) Converts an element type and a size (float, 10) into an array name ("float[10]").intFor arrays, returns either the size of the array (if known) or -1 (unsized).For generic types, returns the types that this generic type can substitute for.final longgetCoercionCost(Type other) Determines the "cost" of coercing (implicitly converting) this type to another type.intgetCols()For matrices, returns the number of columns (e.g.intFor type that contains scalars, returns the number of scalars.@NonNull TypeFor matrices and vectors, returns the scalar type of individual cells (e.g.final @NonNull StringgetDesc()Returns a descriptor of the type, meant for name-mangling.intFor sampler/image types, returns the SpvDim.@NonNull TypeFor arrays, returns the base type.@Unmodifiable List<Type.Field> @NonNull Node.SymbolKindgetKind()doubleReturns the maximum value that can fit in the type.doubleReturns the minimum value that can fit in the type.intFor scalars, returns the minimum size in bits of the type.intIf the type is a struct, returns the depth of the most deeply-nested field.intgetRank()Returns the "rank" of a numeric type, in order of float > half > int > short.intgetRows()For matrices and vectors, returns the number of rows (e.g.byteReturns the ScalarKind of this type (always NonScalar for non-scalar values).final @NonNull TypegetType()Returns this.final byteReturns the category (scalar, vector, matrix, etc.) of this type.intgetWidth()For scalars, returns the size in bits of the type.booleanisArray()booleanTrue for arrayed texture.final booleanReturns true if this type is a bool.final booleanReturns true if this type is a bool, or its vector form.booleanfinal booleanisFloat()Returns true if this is a floating-point scalar type (float or half).final booleanReturns true if this is a floating-point scalar type (float or half), or its vector/matrix form.final booleanfinal booleanReturns true if this type is known to come from BuiltinTypes.final booleanReturns true if this is a signed or unsigned integer.booleanbooleanisMatrix()booleanfinal booleanReturns true if this is a numeric scalar type.final booleanisOpaque()Returns true if this is an "opaque type" (an external object which the shader references in some fashion).booleanReturns true if the component type has relaxed precision.booleanbooleanisScalar()booleanbooleanisShadow()True for samplers that sample a depth texture with comparison (e.g., samplerShadow, sampler2DShadow, HLSL SamplerComparisonState).final booleanisSigned()Returns true if this is a signed scalar type (int or short).final booleanReturns true if this is a signed scalar type (int or short), or its vector form.booleanbooleanisStruct()final booleanReturns true if this is an unsigned scalar type (uint or ushort).final booleanReturns true if this is an unsigned scalar type (uint or ushort), or its vector form.booleanbooleanisUsableInArray(@NonNull Context context, int position) Reports errors and returns false if this type cannot be used as the element type for an array.booleanisVector()final booleanisVoid()static @NonNull TypemakeAliasType(int position, String name, Type type) Creates an alias which maps to another type.static @NonNull TypemakeAliasType(@NonNull String name, @NonNull Type type) Creates an alias which maps to another type.static @NonNull TypemakeArrayType(String name, Type type, int size) Creates an array type.static @NonNull TypemakeCombinedType(String name, String abbr, Type component, int dimensions, boolean isShadow, boolean isArrayed, boolean isMultiSampled) Create a combined sampler type.static @NonNull TypemakeGenericType(String name, Type... types) Create a generic type which maps to the listed types (e.g.static @NonNull TypemakeImageType(String name, String abbr, Type component, int dimensions, boolean isArrayed, boolean isMultiSampled) Create an image or subpass type.static @NonNull TypemakeMatrixType(String name, String desc, Type columnType, int cols) Create a matrix type.static @NonNull TypemakeSamplerType(String name, String abbr, Type component, int dimensions, boolean isShadow, boolean isArrayed, boolean isMultiSampled, boolean isSampled, boolean isSampler) Create a sampler/image type.static @NonNull TypemakeScalarType(String name, String desc, byte kind, int rank, int width) Create a scalar type.static @NonNull TypemakeScalarType(String name, String desc, byte kind, int rank, int minWidth, int width) Create a scalar type with minimum precision.static @NonNull TypemakeSeparateType(String name, String abbr, Type component, boolean isShadow) Create a separate sampler type.static @NonNull TypemakeSpecialType(String name, String abbr, byte kind) Create a "special" type with the given name.static @NonNull TypemakeStructType(@NonNull Context context, int position, @NonNull String name, @NonNull List<Type.Field> fields, boolean interfaceBlock) Creates a struct type with the given fields.static @NonNull TypemakeTextureType(String name, String abbr, Type component, int dimensions, boolean isArrayed, boolean isMultiSampled) Create a texture type.static @NonNull TypemakeVectorType(String name, String desc, Type componentType, int rows) Create a vector type.final booleanReturns true if these types are equal after alias resolution.@NonNull Typeresolve()If this is an alias, returns the underlying type, otherwise returns this.final TypetoCompound(@NonNull Context context, int cols, int rows) Returns the corresponding vector or matrix type with the specified number of columns and rows.final @NonNull StringtoString()final TypeReturns 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
public static @NonNull Type makeScalarType(String name, String desc, byte kind, int rank, int width) Create a scalar type.- Parameters:
kind- a scalar kind
-
makeScalarType
public static @NonNull 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
public static @NonNull 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, subpass inputs, 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
public static @NonNull Type makeImageType(String name, String abbr, Type component, int dimensions, boolean isArrayed, boolean isMultiSampled) Create an image or subpass type. -
makeTextureType
public static @NonNull Type makeTextureType(String name, String abbr, Type component, int dimensions, boolean isArrayed, boolean isMultiSampled) Create a texture type. -
makeSeparateType
public static @NonNull Type makeSeparateType(String name, String abbr, Type component, boolean isShadow) Create a separate sampler type. -
makeCombinedType
public static @NonNull 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
public static @NonNull 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
public final @Nullable 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]"). -
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.
-