private void GetTextureValueAndScalarType(PredefinedObjectTypeSyntax node, out TypeSymbol valueType, out ScalarType scalarType) { if (node.TemplateArgumentList != null) { var valueTypeSyntax = (TypeSyntax)node.TemplateArgumentList.Arguments[0]; valueType = Bind(valueTypeSyntax, x => BindType(x, null)).TypeSymbol; switch (valueTypeSyntax.Kind) { case SyntaxKind.PredefinedScalarType: scalarType = TypeFacts.GetScalarType((ScalarTypeSyntax)valueTypeSyntax); break; case SyntaxKind.PredefinedVectorType: scalarType = TypeFacts.GetVectorType(((VectorTypeSyntax)valueTypeSyntax).TypeToken.Kind).Item1; break; case SyntaxKind.PredefinedGenericVectorType: scalarType = TypeFacts.GetScalarType(((GenericVectorTypeSyntax)valueTypeSyntax).ScalarType); break; default: throw new ArgumentOutOfRangeException(); } } else { valueType = IntrinsicTypes.Float4; scalarType = ScalarType.Float; } }
private BoundScalarType BindScalarType(ScalarTypeSyntax node) { var scalarType = TypeFacts.GetScalarType(node); switch (scalarType) { case ScalarType.Void: return(new BoundScalarType(IntrinsicTypes.Void)); case ScalarType.Bool: return(new BoundScalarType(IntrinsicTypes.Bool)); case ScalarType.Int: return(new BoundScalarType(IntrinsicTypes.Int)); case ScalarType.Uint: return(new BoundScalarType(IntrinsicTypes.Uint)); case ScalarType.Half: return(new BoundScalarType(IntrinsicTypes.Half)); case ScalarType.Float: return(new BoundScalarType(IntrinsicTypes.Float)); case ScalarType.Double: return(new BoundScalarType(IntrinsicTypes.Double)); case ScalarType.String: return(new BoundScalarType(IntrinsicTypes.String)); default: throw new ArgumentOutOfRangeException(); } }
private BoundVectorType BindVectorType(VectorTypeSyntax node) { var vectorType = TypeFacts.GetVectorType(node.TypeToken.Kind); var scalarType = vectorType.Item1; var numComponents = vectorType.Item2; return(new BoundVectorType(IntrinsicTypes.GetVectorType(scalarType, numComponents))); }
private BoundMatrixType BindMatrixType(MatrixTypeSyntax node) { var matrixType = TypeFacts.GetMatrixType(node.TypeToken.Kind); var scalarType = matrixType.Item1; var numRows = matrixType.Item2; var numCols = matrixType.Item3; return(new BoundMatrixType(IntrinsicTypes.GetMatrixType(scalarType, numRows, numCols))); }
private BoundGenericVectorType BindGenericVectorType(GenericVectorTypeSyntax node) { var scalarType = TypeFacts.GetScalarType(node.ScalarType); var numComponents = (int)node.SizeToken.Value; return(new BoundGenericVectorType( IntrinsicTypes.GetVectorType(scalarType, numComponents), Bind(node.ScalarType, BindScalarType))); }
private BoundGenericMatrixType BindGenericMatrixType(GenericMatrixTypeSyntax node) { var scalarType = TypeFacts.GetScalarType(node.ScalarType); var numRows = (int)node.RowsToken.Value; var numCols = (int)node.ColsToken.Value; return(new BoundGenericMatrixType( IntrinsicTypes.GetMatrixType(scalarType, numRows, numCols), Bind(node.ScalarType, BindScalarType))); }
private void GetTextureValueAndScalarType(PredefinedObjectTypeSyntax node, out TypeSymbol valueType, out ScalarType scalarType) { if (node.TemplateArgumentList != null) { var valueTypeSyntax = (TypeSyntax)node.TemplateArgumentList.Arguments[0]; if (valueTypeSyntax is ModifiedTypeSyntax modifiedType) { valueTypeSyntax = modifiedType.Type; } valueType = Bind(valueTypeSyntax, x => BindType(x, null)).TypeSymbol; switch (valueTypeSyntax.Kind) { case SyntaxKind.PredefinedScalarType: scalarType = TypeFacts.GetScalarType((ScalarTypeSyntax)valueTypeSyntax); break; case SyntaxKind.PredefinedVectorType: scalarType = TypeFacts.GetVectorType(((VectorTypeSyntax)valueTypeSyntax).TypeToken.Kind).Item1; break; case SyntaxKind.PredefinedGenericVectorType: scalarType = TypeFacts.GetScalarType(((GenericVectorTypeSyntax)valueTypeSyntax).ScalarType); break; default: Diagnostics.ReportInvalidType(valueTypeSyntax); scalarType = ScalarType.Float; break; } } else { valueType = IntrinsicTypes.Float4; scalarType = ScalarType.Float; } }
static BinaryOperator() { BuiltInMultiplySignatures = IntrinsicTypes.AllNumericTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.Multiply, x)).ToArray(); BuiltInDivideSignatures = IntrinsicTypes.AllNumericTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.Divide, x)).ToArray(); BuiltInModulusSignatures = IntrinsicTypes.AllNumericTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.Modulo, x)).ToArray(); BuiltInAddSignatures = IntrinsicTypes.AllNumericTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.Add, x)).ToArray(); BuiltInSubSignatures = IntrinsicTypes.AllNumericTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.Subtract, x)).ToArray(); BuiltInLeftShiftSignatures = IntrinsicTypes.AllIntegralTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.LeftShift, x)).ToArray(); BuiltInRightShiftSignatures = IntrinsicTypes.AllIntegralTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.RightShift, x)).ToArray(); BuiltInEqualSignatures = IntrinsicTypes.AllNumericTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.Equal, TypeFacts.GetMatchingBoolType(x), x)).ToArray(); BuiltInNotEqualSignatures = IntrinsicTypes.AllNumericTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.NotEqual, TypeFacts.GetMatchingBoolType(x), x)).ToArray(); BuiltInLessSignatures = IntrinsicTypes.AllNumericTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.Less, TypeFacts.GetMatchingBoolType(x), x)).ToArray(); BuiltInGreaterSignatures = IntrinsicTypes.AllNumericTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.Greater, TypeFacts.GetMatchingBoolType(x), x)).ToArray(); BuiltInLessOrEqualSignatures = IntrinsicTypes.AllNumericTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.LessEqual, TypeFacts.GetMatchingBoolType(x), x)).ToArray(); BuiltInGreaterOrEqualSignatures = IntrinsicTypes.AllNumericTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.GreaterEqual, TypeFacts.GetMatchingBoolType(x), x)).ToArray(); BuiltInBitAndSignatures = IntrinsicTypes.AllIntegralTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.BitwiseAnd, x)).ToArray(); BuiltInBitOrSignatures = IntrinsicTypes.AllIntegralTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.BitwiseOr, x)).ToArray(); BuiltInBitXorSignatures = IntrinsicTypes.AllIntegralTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.BitwiseXor, x)).ToArray(); BuiltInLogicalAndSignatures = IntrinsicTypes.AllBoolTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.LogicalAnd, x)).ToArray(); BuiltInLogicalOrSignatures = IntrinsicTypes.AllBoolTypes.Select(x => new BinaryOperatorSignature(BinaryOperatorKind.LogicalOr, x)).ToArray(); }
static UnaryOperator() { BuiltInIdentitySignatures = IntrinsicTypes.AllNumericTypes.Select(x => new UnaryOperatorSignature(UnaryOperatorKind.Plus, x)).ToArray(); BuiltInNegationSignatures = IntrinsicTypes.AllNumericTypes.Select(x => new UnaryOperatorSignature(UnaryOperatorKind.Minus, x)).ToArray(); BuiltInBitwiseNotSignatures = IntrinsicTypes.AllIntegralTypes.Select(x => new UnaryOperatorSignature(UnaryOperatorKind.BitwiseNot, x)).ToArray(); BuiltInLogicalNotSignatures = IntrinsicTypes.AllNumericTypes.Select(x => new UnaryOperatorSignature(UnaryOperatorKind.LogicalNot, TypeFacts.GetMatchingBoolType(x), x)).ToArray(); BuiltInPostDecrementSignatures = IntrinsicTypes.AllNumericNonBoolTypes.Select(x => new UnaryOperatorSignature(UnaryOperatorKind.PostDecrement, x)).ToArray(); BuiltInPostIncrementSignatures = IntrinsicTypes.AllNumericNonBoolTypes.Select(x => new UnaryOperatorSignature(UnaryOperatorKind.PostIncrement, x)).ToArray(); BuiltInPreDecrementSignatures = IntrinsicTypes.AllNumericNonBoolTypes.Select(x => new UnaryOperatorSignature(UnaryOperatorKind.PreDecrement, x)).ToArray(); BuiltInPreIncrementSignatures = IntrinsicTypes.AllNumericNonBoolTypes.Select(x => new UnaryOperatorSignature(UnaryOperatorKind.PreIncrement, x)).ToArray(); }