From 0b46715bff7f047fefed303ae149d3de8eb6be4f Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 21 Feb 2024 13:59:30 -0800 Subject: Fix parsing of literals in stdlib. (#3610) * Fix parsing of literals in stdlib. * Fix double lit limits. --- source/slang/core.meta.slang | 4 ++-- source/slang/slang-ast-expr.h | 1 + source/slang/slang-check-expr.cpp | 4 ++-- source/slang/slang-parser.cpp | 9 ++------- 4 files changed, 7 insertions(+), 11 deletions(-) (limited to 'source') diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 1e1ef061e..b02a44c5c 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -997,8 +997,8 @@ extension float : IRangedValue extension double : IRangedValue { - static const double maxValue = 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0; - static const double minValue = -179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0; + static const double maxValue = bit_cast(0x7fefffffffffffffULL); + static const double minValue = bit_cast(0xffefffffffffffffULL); } extension int : IRangedValue diff --git a/source/slang/slang-ast-expr.h b/source/slang/slang-ast-expr.h index 9f2cd22a9..9a7993937 100644 --- a/source/slang/slang-ast-expr.h +++ b/source/slang/slang-ast-expr.h @@ -79,6 +79,7 @@ class LiteralExpr : public Expr // The token that was used to express the literal. This can be // used to get the raw text of the literal, including any suffix. Token token; + BaseType suffixType = BaseType::Void; }; class IntegerLiteralExpr : public LiteralExpr diff --git a/source/slang/slang-check-expr.cpp b/source/slang/slang-check-expr.cpp index e9de74d8e..811e4b395 100644 --- a/source/slang/slang-check-expr.cpp +++ b/source/slang/slang-check-expr.cpp @@ -1384,7 +1384,7 @@ namespace Slang // if(!expr->type.type) { - expr->type = m_astBuilder->getIntType(); + expr->type = m_astBuilder->getBuiltinType(expr->suffixType); } return expr; } @@ -1393,7 +1393,7 @@ namespace Slang { if(!expr->type.type) { - expr->type = m_astBuilder->getFloatType(); + expr->type = m_astBuilder->getBuiltinType(expr->suffixType); } return expr; } diff --git a/source/slang/slang-parser.cpp b/source/slang/slang-parser.cpp index ad4e65bf2..f2aff32ea 100644 --- a/source/slang/slang-parser.cpp +++ b/source/slang/slang-parser.cpp @@ -6590,11 +6590,9 @@ namespace Slang value = _fixIntegerLiteral(suffixBaseType, value, &token, parser->sink); - ASTBuilder* astBuilder = parser->astBuilder; - Type* suffixType = (suffixBaseType == BaseType::Void) ? astBuilder->getErrorType() : astBuilder->getBuiltinType(suffixBaseType); constExpr->value = value; - constExpr->type = QualType(suffixType); + constExpr->suffixType = suffixBaseType; return constExpr; } @@ -6704,12 +6702,9 @@ namespace Slang } } - ASTBuilder* astBuilder = parser->astBuilder; - - Type* suffixType = (suffixBaseType == BaseType::Void) ? astBuilder->getErrorType() : astBuilder->getBuiltinType(suffixBaseType); constExpr->value = fixedValue; - constExpr->type = QualType(suffixType); + constExpr->suffixType = suffixBaseType; return constExpr; } -- cgit v1.2.3