Repository: shader-slang/slang
File: source/slang/slang-parser.cpp (C++)

Code before:
    ///     - `uint`
    ///     - `int64_t`
    ///     - `uint64_t`
    ///
    /// The lexer scans the negative(-) part of literal separately, and the value part here
    /// is always positive hence it is sufficient to only compare with the maximum limits.
    BaseType baseType;
    if (rawValue <= INT32_MAX)
    {
        baseType = BaseType::Int;
    }
    else if ((rawValue <= UINT32_MAX) && !isDecimalBase)
    {
        baseType = BaseType::UInt;
    }
    else if (rawValue <= INT64_MAX)
    {
        baseType = BaseType::Int64;
    }
    else
    {
        baseType = BaseType::UInt64;

        // Emit warning if the value is too large for signed 64-bit, regardless of base
        // This fixes the inconsistency between decimal and hex literals
        if (sink && token)
        {
            // There is an edge case here where 9223372036854775808 or INT64_MAX + 1
            // brings us here, but the complete literal is -9223372036854775808 or INT64_MIN and is
            // valid. Unfortunately because the lexer handles the negative(-) part of the literal
            // separately it is impossible to know whether the literal has a negative sign or not.
            // We emit the warning and initially process it as a uint64 anyways, and the negative
            // sign will be properly parsed and the value will still be properly stored as a
            // negative INT64_MIN.

            // Decimal integer is too large to be represented as signed.
            // Output warning that it is represented as unsigned instead.
            sink->diagnose(*token, Diagnostics::integerLiteralTooLarge);
        }
    }

    return baseType;
}

static bool _isCast(Parser* parser, Expr* expr)
{
    if (as<PointerTypeExpr>(expr))
    {
        return true;
    }


Review comment (bug):
why do we need the guard here, can `sink` or `token` ever be nullptr? 

Code after:
    ///     - `uint`
    ///     - `int64_t`
    ///     - `uint64_t`
    ///
    /// The lexer scans the negative(-) part of literal separately, and the value part here
    /// is always positive hence it is sufficient to only compare with the maximum limits.
    BaseType baseType;
    if (rawValue <= INT32_MAX)
    {
        baseType = BaseType::Int;
    }
    else if ((rawValue <= UINT32_MAX) && !isDecimalBase)
    {
        baseType = BaseType::UInt;
    }
    else if (rawValue <= INT64_MAX)
    {
        baseType = BaseType::Int64;
    }
    else
    {
        baseType = BaseType::UInt64;

        // Emit warning if the value is too large for signed 64-bit, regardless of base

        // There is an edge case here where 9223372036854775808 or INT64_MAX + 1
        // brings us here, but the complete literal is -9223372036854775808 or INT64_MIN and is
        // valid. Unfortunately because the lexer handles the negative(-) part of the literal
        // separately it is impossible to know whether the literal has a negative sign or not.
        // We emit the warning and initially process it as a uint64 anyways, and the negative
        // sign will be properly parsed and the value will still be properly stored as a
        // negative INT64_MIN.

        // Decimal integer is too large to be represented as signed.
        // Output warning that it is represented as unsigned instead.
        sink->diagnose(*token, Diagnostics::integerLiteralTooLarge);
    }

    return baseType;
}

static bool _isCast(Parser* parser, Expr* expr)
{
    if (as<PointerTypeExpr>(expr))
    {
        return true;
    }

    // We can't just look at expr and look up if it's a type, because we allow
    // out-of-order declarations. So to a first approximation we'll try and
    // determine if it is a cast via a heuristic based on what comes next