diff --git a/src/tint/number.h b/src/tint/number.h index f77f5b3bcc..a4bd369a42 100644 --- a/src/tint/number.h +++ b/src/tint/number.h @@ -72,6 +72,11 @@ bool operator==(A a, Number b) { return Number(a) == b; } +/// `AInt` is a type alias to `Number`. +using AInt = Number; +/// `AFloat` is a type alias to `Number`. +using AFloat = Number; + /// `i32` is a type alias to `Number`. using i32 = Number; /// `u32` is a type alias to `Number`. @@ -83,6 +88,16 @@ using f32 = Number; namespace tint::number_suffixes { +/// Literal suffix for abstract integer literals +inline AInt operator"" _a(unsigned long long int value) { // NOLINT + return AInt(static_cast(value)); +} + +/// Literal suffix for abstract float literals +inline AFloat operator"" _a(long double value) { // NOLINT + return AFloat(static_cast(value)); +} + /// Literal suffix for i32 literals inline i32 operator"" _i(unsigned long long int value) { // NOLINT return i32(static_cast(value)); diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index 2cd0ff2d62..7dd2c814b3 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -1004,6 +1004,35 @@ class ProgramBuilder { ast::FloatLiteralExpression::Suffix::kF); } + /// @param source the source information + /// @param value the integer value + /// @return an unsuffixed IntLiteralExpression for the AInt value + const ast::IntLiteralExpression* Expr(const Source& source, AInt value) { + return create(source, value, + ast::IntLiteralExpression::Suffix::kNone); + } + + /// @param value the integer value + /// @return an unsuffixed IntLiteralExpression for the AInt value + const ast::IntLiteralExpression* Expr(AInt value) { + return create(value, ast::IntLiteralExpression::Suffix::kNone); + } + + /// @param source the source information + /// @param value the integer value + /// @return an unsuffixed FloatLiteralExpression for the AFloat value + const ast::FloatLiteralExpression* Expr(const Source& source, AFloat value) { + return create(source, value.value, + ast::FloatLiteralExpression::Suffix::kNone); + } + + /// @param value the integer value + /// @return an unsuffixed FloatLiteralExpression for the AFloat value + const ast::FloatLiteralExpression* Expr(AFloat value) { + return create(value.value, + ast::FloatLiteralExpression::Suffix::kNone); + } + /// @param source the source information /// @param value the integer value /// @return a signed 'i'-suffixed IntLiteralExpression for the i32 value