Simplify error case of token_type_description and keyword_description

Simply return a constant string, since in practice the error case
is not hit
This commit is contained in:
ridiculousfish 2017-01-26 17:47:24 -08:00
parent a40f491c93
commit 05d569ee44

View file

@ -123,23 +123,14 @@ void parse_error_offset_source_start(parse_error_list_t *errors, size_t amt) {
const wchar_t *token_type_description(parse_token_type_t type) { const wchar_t *token_type_description(parse_token_type_t type) {
const wchar_t *description = enum_to_str(type, token_enum_map); const wchar_t *description = enum_to_str(type, token_enum_map);
if (description) return description; if (description) return description;
return L"unknown_token_type";
// This leaks memory but it should never be run unless we have a bug elsewhere in the code.
const wcstring d = format_string(L"unknown_token_type_%ld", static_cast<long>(type));
wchar_t *d2 = new wchar_t[d.size() + 1];
// cppcheck-suppress memleak
return std::wcscpy(d2, d.c_str());
} }
const wchar_t *keyword_description(parse_keyword_t type) { const wchar_t *keyword_description(parse_keyword_t type) {
const wchar_t *keyword = enum_to_str(type, keyword_enum_map); const wchar_t *keyword = enum_to_str(type, keyword_enum_map);
if (keyword) return keyword; if (keyword) return keyword;
return L"unknown_keyword";
// This leaks memory but it should never be run unless we have a bug elsewhere in the code.
const wcstring d = format_string(L"unknown_keyword_%ld", static_cast<long>(type));
wchar_t *d2 = new wchar_t[d.size() + 1];
// cppcheck-suppress memleak
return std::wcscpy(d2, d.c_str());
} }
static wcstring token_type_user_presentable_description( static wcstring token_type_user_presentable_description(