dep/reshadefx: Update to 7bdfb03

This commit is contained in:
Stenzek
2024-09-08 19:19:58 +10:00
parent 3078339f64
commit 86bff869bc
25 changed files with 6041 additions and 3244 deletions

View File

@ -18,7 +18,7 @@ enum token_type
};
// Lookup table which translates a given char to a token type
static const unsigned type_lookup[256] = {
static const unsigned int s_type_lookup[256] = {
0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, SPACE,
'\n', SPACE, SPACE, SPACE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -35,7 +35,7 @@ static const unsigned type_lookup[256] = {
};
// Lookup tables which translate a given string literal to a token and backwards
static const std::unordered_map<tokenid, std::string_view> token_lookup = {
static const std::unordered_map<tokenid, std::string_view> s_token_lookup = {
{ tokenid::end_of_file, "end of file" },
{ tokenid::exclaim, "!" },
{ tokenid::hash, "#" },
@ -205,7 +205,7 @@ static const std::unordered_map<tokenid, std::string_view> token_lookup = {
{ tokenid::storage2d, "storage2D" },
{ tokenid::storage3d, "storage3D" },
};
static const std::unordered_map<std::string_view, tokenid> keyword_lookup = {
static const std::unordered_map<std::string_view, tokenid> s_keyword_lookup = {
{ "asm", tokenid::reserved },
{ "asm_fragment", tokenid::reserved },
{ "auto", tokenid::reserved },
@ -439,7 +439,7 @@ static const std::unordered_map<std::string_view, tokenid> keyword_lookup = {
{ "volatile", tokenid::volatile_ },
{ "while", tokenid::while_ }
};
static const std::unordered_map<std::string_view, tokenid> pp_directive_lookup = {
static const std::unordered_map<std::string_view, tokenid> s_pp_directive_lookup = {
{ "define", tokenid::hash_def },
{ "undef", tokenid::hash_undef },
{ "if", tokenid::hash_if },
@ -454,15 +454,15 @@ static const std::unordered_map<std::string_view, tokenid> pp_directive_lookup =
{ "include", tokenid::hash_include },
};
static inline bool is_octal_digit(char c)
static bool is_octal_digit(char c)
{
return static_cast<unsigned>(c - '0') < 8;
}
static inline bool is_decimal_digit(char c)
static bool is_decimal_digit(char c)
{
return static_cast<unsigned>(c - '0') < 10;
}
static inline bool is_hexadecimal_digit(char c)
static bool is_hexadecimal_digit(char c)
{
return is_decimal_digit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
}
@ -504,8 +504,8 @@ static long long octal_to_decimal(long long n)
std::string reshadefx::token::id_to_name(tokenid id)
{
const auto it = token_lookup.find(id);
if (it != token_lookup.end())
const auto it = s_token_lookup.find(id);
if (it != s_token_lookup.end())
return std::string(it->second);
return "unknown";
}
@ -526,7 +526,7 @@ next_token:
assert(_cur <= _end);
// Do a character type lookup for the current character
switch (type_lookup[uint8_t(*_cur)])
switch (s_type_lookup[uint8_t(*_cur)])
{
case 0xFF: // EOF
tok.id = tokenid::end_of_file;
@ -635,7 +635,7 @@ next_token:
tok.id = tokenid::minus;
break;
case '.':
if (type_lookup[uint8_t(_cur[1])] == DIGIT)
if (s_type_lookup[uint8_t(_cur[1])] == DIGIT)
parse_numeric_literal(tok);
else if (_cur[1] == '.' && _cur[2] == '.')
tok.id = tokenid::ellipsis,
@ -805,7 +805,7 @@ void reshadefx::lexer::skip_space()
continue;
}
if (type_lookup[uint8_t(*_cur)] == SPACE)
if (s_type_lookup[uint8_t(*_cur)] == SPACE)
skip(1);
else
break;
@ -841,7 +841,7 @@ void reshadefx::lexer::parse_identifier(token &tok) const
auto *const begin = _cur, *end = begin;
// Skip to the end of the identifier sequence
while (type_lookup[uint8_t(*end)] == IDENT || type_lookup[uint8_t(*end)] == DIGIT)
while (s_type_lookup[uint8_t(*end)] == IDENT || s_type_lookup[uint8_t(*end)] == DIGIT)
end++;
tok.id = tokenid::identifier;
@ -852,8 +852,8 @@ void reshadefx::lexer::parse_identifier(token &tok) const
if (_ignore_keywords)
return;
if (const auto it = keyword_lookup.find(tok.literal_as_string);
it != keyword_lookup.end())
if (const auto it = s_keyword_lookup.find(tok.literal_as_string);
it != s_keyword_lookup.end())
tok.id = it->second;
}
bool reshadefx::lexer::parse_pp_directive(token &tok)
@ -862,8 +862,8 @@ bool reshadefx::lexer::parse_pp_directive(token &tok)
skip_space(); // Skip any space between the '#' and directive
parse_identifier(tok);
if (const auto it = pp_directive_lookup.find(tok.literal_as_string);
it != pp_directive_lookup.end())
if (const auto it = s_pp_directive_lookup.find(tok.literal_as_string);
it != s_pp_directive_lookup.end())
{
tok.id = it->second;
return true;
@ -999,6 +999,9 @@ void reshadefx::lexer::parse_string_literal(token &tok, bool escape)
tok.id = tokenid::string_literal;
tok.length = end - begin + 1;
// Free up unused memory
tok.literal_as_string.shrink_to_fit();
}
void reshadefx::lexer::parse_numeric_literal(token &tok) const
{