1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:04:59 +00:00

Everywhere: Use to_number<T> instead of to_{int,uint,float,double}

In a bunch of cases, this actually ends up simplifying the code as
to_number will handle something such as:

```
Optional<I> opt;
if constexpr (IsSigned<I>)
    opt = view.to_int<I>();
else
    opt = view.to_uint<I>();
```

For us.

The main goal here however is to have a single generic number conversion
API between all of the String classes.
This commit is contained in:
Shannon Booth 2023-12-23 15:59:14 +13:00 committed by Andreas Kling
parent a4ecc65398
commit e2e7c4d574
155 changed files with 397 additions and 412 deletions

View file

@ -122,7 +122,7 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi
warnln("print what memory?");
continue;
}
auto value = args[2].to_uint<u64>();
auto value = args[2].to_number<u64>();
if (!value.has_value()) {
warnln("invalid memory index {}", args[2]);
continue;
@ -144,7 +144,7 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi
warnln("print what function?");
continue;
}
auto value = args[2].to_uint<u64>();
auto value = args[2].to_number<u64>();
if (!value.has_value()) {
warnln("invalid function index {}", args[2]);
continue;
@ -170,7 +170,7 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi
continue;
}
Optional<Wasm::FunctionAddress> address;
auto index = args[1].to_uint<u64>();
auto index = args[1].to_number<u64>();
if (index.has_value()) {
address = config.frame().module().functions()[index.value()];
} else {
@ -203,7 +203,7 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi
Vector<u64> values_to_push;
Vector<Wasm::Value> values;
for (size_t index = 2; index < args.size(); ++index)
values_to_push.append(args[index].to_uint().value_or(0));
values_to_push.append(args[index].to_number<u64>().value_or(0));
for (auto& param : type.parameters())
values.append(Wasm::Value { param, values_to_push.take_last() });
@ -332,7 +332,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
.short_name = 0,
.value_name = "u64",
.accept_value = [&](StringView str) -> bool {
if (auto v = str.to_uint<u64>(); v.has_value()) {
if (auto v = str.to_number<u64>(); v.has_value()) {
values_to_push.append(v.value());
return true;
}