Skip to content

Commit

Permalink
Fix clang tidy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jianlingzhong committed Dec 20, 2024
1 parent 3d70e1a commit 8fcac7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 4 additions & 4 deletions compiler+runtime/src/cpp/jank/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ extern "C"
jank_object_ptr jank_list_create(uint64_t const size, ...)
{
/* NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) */
va_list args;
va_list args{};
va_start(args, size);

native_vector<object_ptr> v;
Expand All @@ -414,7 +414,7 @@ extern "C"
jank_object_ptr jank_vector_create(uint64_t const size, ...)
{
/* NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) */
va_list args;
va_list args{};
va_start(args, size);

obj::transient_vector trans;
Expand All @@ -433,7 +433,7 @@ extern "C"
jank_object_ptr jank_map_create(uint64_t const pairs, ...)
{
/* NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) */
va_list args;
va_list args{};
va_start(args, pairs);

/* TODO: Could optimize to build an array map, if it's small enough. */
Expand All @@ -454,7 +454,7 @@ extern "C"
jank_object_ptr jank_set_create(uint64_t const size, ...)
{
/* NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) */
va_list args;
va_list args{};
va_start(args, size);

obj::transient_hash_set trans;
Expand Down
20 changes: 16 additions & 4 deletions compiler+runtime/src/cpp/jank/read/lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,18 @@ namespace jank::read
return none;
}

static int cast_char32_t_as_int(char32_t const c)
{
if(c > static_cast<char32_t>(INT_MAX))
{
throw std::runtime_error("Value out of range for wint_t");
}

// Perform the safe conversion
auto const safe_char = static_cast<int>(c);
return safe_char;
}

static result<codepoint, error>
convert_to_codepoint(native_persistent_string_view const sv, size_t const pos)
{
Expand Down Expand Up @@ -313,7 +325,7 @@ namespace jank::read

static native_bool is_symbol_char(char32_t const c)
{
return !std::iswspace(c) && !is_special_char(c)
return !std::iswspace(cast_char32_t_as_int(c)) && !is_special_char(c)
&& (std::iswalnum(static_cast<wint_t>(c)) != 0 || c == '_' || c == '-' || c == '/'
|| c == '?' || c == '!' || c == '+' || c == '*' || c == '=' || c == '.' || c == '&'
|| c == '<' || c == '>' || c == '#' || c == '%' || is_utf8_char(c));
Expand Down Expand Up @@ -377,7 +389,7 @@ namespace jank::read
auto const ch(peek());
pos++;

if(ch.is_err() || std::iswspace(ch.expect_ok().character))
if(ch.is_err() || std::iswspace(cast_char32_t_as_int(ch.expect_ok().character)))
{
return err(error{ token_start, "Expecting a valid character literal after \\" });
}
Expand Down Expand Up @@ -514,7 +526,7 @@ namespace jank::read
return err(
error{ token_start, pos, "invalid ratio: expecting an integer denominator" });
}
else if(std::iswdigit(c) == 0)
else if(std::iswdigit(cast_char32_t_as_int(c)) == 0)
{
if(expecting_exponent)
{
Expand Down Expand Up @@ -631,7 +643,7 @@ namespace jank::read

auto const oc(peek());
auto const c(oc.expect_ok().character);
if(oc.is_err() || std::iswspace(c))
if(oc.is_err() || std::iswspace(cast_char32_t_as_int(c)))
{
++pos;
return err(
Expand Down

0 comments on commit 8fcac7f

Please sign in to comment.