mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-26 21:12:07 +00:00
Deprecate treating multi-unit strings as numbers (#1438)
This commit is contained in:
@@ -70,7 +70,7 @@
|
||||
|
||||
yy::parser::symbol_type yylex(); // Provided by lexer.cpp
|
||||
|
||||
static uint32_t str2int2(std::vector<int32_t> const &s);
|
||||
static uint32_t strToNum(std::vector<int32_t> const &s);
|
||||
static void errorInvalidUTF8Byte(uint8_t byte, char const *functionName);
|
||||
static size_t strlenUTF8(std::string const &str);
|
||||
static std::string strsubUTF8(std::string const &str, uint32_t pos, uint32_t len);
|
||||
@@ -1261,7 +1261,7 @@ relocexpr:
|
||||
}
|
||||
| string {
|
||||
std::vector<int32_t> output = charmap_Convert($1);
|
||||
$$.makeNumber(str2int2(output));
|
||||
$$.makeNumber(strToNum(output));
|
||||
}
|
||||
;
|
||||
|
||||
@@ -2378,7 +2378,7 @@ void yy::parser::error(std::string const &str) {
|
||||
::error("%s\n", str.c_str());
|
||||
}
|
||||
|
||||
static uint32_t str2int2(std::vector<int32_t> const &s) {
|
||||
static uint32_t strToNum(std::vector<int32_t> const &s) {
|
||||
uint32_t length = s.size();
|
||||
|
||||
if (length == 1) {
|
||||
@@ -2387,23 +2387,13 @@ static uint32_t str2int2(std::vector<int32_t> const &s) {
|
||||
return (uint32_t)s[0];
|
||||
}
|
||||
|
||||
warning(WARNING_OBSOLETE, "Treating multi-unit strings as numbers is deprecated\n");
|
||||
|
||||
for (int32_t v : s) {
|
||||
if (!checkNBit(v, 8, "All character units"))
|
||||
break;
|
||||
}
|
||||
|
||||
if (length > 4)
|
||||
warning(
|
||||
WARNING_NUMERIC_STRING_1,
|
||||
"Treating string as a number ignores first %" PRIu32 " byte%s\n",
|
||||
length - 4,
|
||||
length == 5 ? "" : "s"
|
||||
);
|
||||
else if (length > 1)
|
||||
warning(
|
||||
WARNING_NUMERIC_STRING_2, "Treating %" PRIu32 "-byte string as a number\n", length
|
||||
);
|
||||
|
||||
uint32_t r = 0;
|
||||
|
||||
for (uint32_t i = length < 4 ? 0 : length - 4; i < length; i++) {
|
||||
|
||||
@@ -37,7 +37,7 @@ static WarningState const defaultWarnings[ARRAY_SIZE(warningStates)] = {
|
||||
WARNING_DISABLED, // WARNING_SHIFT_AMOUNT
|
||||
WARNING_ENABLED, // WARNING_USER
|
||||
|
||||
WARNING_ENABLED, // WARNING_NUMERIC_STRING_1
|
||||
WARNING_DISABLED, // WARNING_NUMERIC_STRING_1
|
||||
WARNING_DISABLED, // WARNING_NUMERIC_STRING_2
|
||||
WARNING_ENABLED, // WARNING_TRUNCATION_1
|
||||
WARNING_DISABLED, // WARNING_TRUNCATION_2
|
||||
@@ -114,7 +114,10 @@ static bool tryProcessParamWarning(char const *flag, uint8_t param, WarningState
|
||||
for (size_t i = 0; i < ARRAY_SIZE(paramWarnings); i++) {
|
||||
uint8_t maxParam = paramWarnings[i].nbLevels;
|
||||
|
||||
if (!strcmp(paramWarnings[i].name, flag)) { // Match!
|
||||
if (!strcmp(flag, paramWarnings[i].name)) { // Match!
|
||||
if (!strcmp(flag, "numeric-string"))
|
||||
warning(WARNING_OBSOLETE, "Treating multi-unit strings as numbers is deprecated\n");
|
||||
|
||||
// If making the warning an error but param is 0, set to the maximum
|
||||
// This accommodates `-Werror=flag`, but also `-Werror=flag=0`, which is
|
||||
// thus filtered out by the caller.
|
||||
@@ -158,7 +161,6 @@ static uint8_t const _wallCommands[] = {
|
||||
WARNING_LARGE_CONSTANT,
|
||||
WARNING_NESTED_COMMENT,
|
||||
WARNING_OBSOLETE,
|
||||
WARNING_NUMERIC_STRING_1,
|
||||
WARNING_UNMAPPED_CHAR_1,
|
||||
META_WARNING_DONE,
|
||||
};
|
||||
@@ -169,7 +171,6 @@ static uint8_t const _wextraCommands[] = {
|
||||
WARNING_MACRO_SHIFT,
|
||||
WARNING_NESTED_COMMENT,
|
||||
WARNING_OBSOLETE,
|
||||
WARNING_NUMERIC_STRING_2,
|
||||
WARNING_TRUNCATION_1,
|
||||
WARNING_TRUNCATION_2,
|
||||
WARNING_UNMAPPED_CHAR_1,
|
||||
@@ -191,8 +192,6 @@ static uint8_t const _weverythingCommands[] = {
|
||||
WARNING_OBSOLETE,
|
||||
WARNING_SHIFT,
|
||||
WARNING_SHIFT_AMOUNT,
|
||||
WARNING_NUMERIC_STRING_1,
|
||||
WARNING_NUMERIC_STRING_2,
|
||||
WARNING_TRUNCATION_1,
|
||||
WARNING_TRUNCATION_2,
|
||||
WARNING_UNMAPPED_CHAR_1,
|
||||
|
||||
Reference in New Issue
Block a user