Some miscellaneous refactoring and copy-editing

This commit is contained in:
Rangi42
2025-02-10 16:51:51 +01:00
parent 177a3abfac
commit 48412e9c56
6 changed files with 17 additions and 24 deletions

View File

@@ -163,11 +163,11 @@ void charmap_Add(std::string const &mapping, std::vector<int32_t> &&value) {
std::swap(node.value, value);
}
bool charmap_HasChar(std::string const &input) {
bool charmap_HasChar(std::string const &mapping) {
Charmap const &charmap = *currentCharmap;
size_t nodeIdx = 0;
for (char c : input) {
for (char c : mapping) {
nodeIdx = charmap.nodes[nodeIdx].next[static_cast<uint8_t>(c)];
if (!nodeIdx) {

View File

@@ -239,16 +239,16 @@ static std::unordered_map<std::string, int, CaseInsensitive, CaseInsensitive> ke
{"BITWIDTH", T_(OP_BITWIDTH) },
{"TZCOUNT", T_(OP_TZCOUNT) },
{"STRCMP", T_(OP_STRCMP) },
{"STRIN", T_(OP_STRIN) },
{"STRRIN", T_(OP_STRRIN) },
{"STRSUB", T_(OP_STRSUB) },
{"STRLEN", T_(OP_STRLEN) },
{"STRCAT", T_(OP_STRCAT) },
{"STRUPR", T_(OP_STRUPR) },
{"STRLWR", T_(OP_STRLWR) },
{"STRRPL", T_(OP_STRRPL) },
{"STRCMP", T_(OP_STRCMP) },
{"STRFMT", T_(OP_STRFMT) },
{"STRIN", T_(OP_STRIN) },
{"STRLEN", T_(OP_STRLEN) },
{"STRLWR", T_(OP_STRLWR) },
{"STRRIN", T_(OP_STRRIN) },
{"STRRPL", T_(OP_STRRPL) },
{"STRSUB", T_(OP_STRSUB) },
{"STRUPR", T_(OP_STRUPR) },
{"CHARLEN", T_(OP_CHARLEN) },
{"CHARSUB", T_(OP_CHARSUB) },

View File

@@ -1474,13 +1474,11 @@ relocexpr_no_str:
$$.makeNumber($3.compare($5));
}
| OP_STRIN LPAREN string COMMA string RPAREN {
auto pos = $3.find($5);
size_t pos = $3.find($5);
$$.makeNumber(pos != std::string::npos ? pos + 1 : 0);
}
| OP_STRRIN LPAREN string COMMA string RPAREN {
auto pos = $3.rfind($5);
size_t pos = $3.rfind($5);
$$.makeNumber(pos != std::string::npos ? pos + 1 : 0);
}
| OP_STRLEN LPAREN string RPAREN {
@@ -1532,19 +1530,16 @@ string:
| OP_STRSUB LPAREN string COMMA iconst COMMA uconst RPAREN {
size_t len = strlenUTF8($3, false);
uint32_t pos = adjustNegativePos($5, len, "STRSUB");
$$ = strsubUTF8($3, pos, $7);
}
| OP_STRSUB LPAREN string COMMA iconst RPAREN {
size_t len = strlenUTF8($3, false);
uint32_t pos = adjustNegativePos($5, len, "STRSUB");
$$ = strsubUTF8($3, pos, pos > len ? 0 : len + 1 - pos);
}
| OP_CHARSUB LPAREN string COMMA iconst RPAREN {
size_t len = charlenUTF8($3);
uint32_t pos = adjustNegativePos($5, len, "CHARSUB");
$$ = charsubUTF8($3, pos);
}
| OP_STRCAT LPAREN RPAREN {
@@ -2520,7 +2515,7 @@ static std::string strsubUTF8(std::string const &str, uint32_t pos, uint32_t len
size_t index = 0;
uint32_t state = 0;
uint32_t codepoint = 0;
uint32_t curPos = 1; // RGBASM strings are 1-indexed!
uint32_t curPos = 1;
// Advance to starting position in source string.
while (ptr[index] && curPos < pos) {
@@ -2607,7 +2602,7 @@ static std::string charsubUTF8(std::string const &str, uint32_t pos) {
}
static uint32_t adjustNegativePos(int32_t pos, size_t len, char const *functionName) {
// STRSUB and CHARSUB adjust negative `pos` arguments the same way,
// STRSUB and CHARSUB adjust negative position arguments the same way,
// such that position -1 is the last character of a string.
if (pos < 0) {
pos += len + 1;

View File

@@ -566,9 +566,7 @@ std::string sym_MakeAnonLabelName(uint32_t ofs, bool neg) {
}
}
std::string anon("!");
anon += std::to_string(id);
return anon;
return "!"s + std::to_string(id);
}
void sym_Export(std::string const &symName) {