MCPcopy Create free account
hub / github.com/covscript/covscript / parse_define_structured_binding

Method parse_define_structured_binding

sources/instance/instance.cpp:296–317  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294 }
295
296 void
297 instance_type::parse_define_structured_binding(tree_type<token_base *>::iterator it, bool constant, bool link)
298 {
299 std::function<void(tree_type<token_base *>::iterator, const var &)> process;
300 process = [&process, this, constant, link](tree_type<token_base *>::iterator it, const var &val) {
301 auto &pl = static_cast<token_parallel *>(it.data())->get_parallel();
302 if (!val.is_type_of<array>())
303 throw runtime_error("Only support structured binding with array while variable definition.");
304 auto &arr = val.const_val<array>();
305 if (pl.size() != arr.size())
306 throw runtime_error("Unmatched structured binding while variable definition.");
307 for (std::size_t i = 0; i < pl.size(); ++i) {
308 if (pl[i].root().data()->get_type() == token_types::parallel)
309 process(pl[i].root(), arr[i]);
310 else
311 storage.add_var_no_return(static_cast<token_id *>(pl[i].root().data())->get_id(),
312 constant || link ? arr[i] : copy(arr[i]), constant);
313 }
314 };
315 const var &val = constant ? static_cast<token_value *>(it.right().data())->get_value() : parse_expr(it.right());
316 process(it.left(), val);
317 }
318
319 void instance_type::parse_using(tree_type<token_base *>::iterator it, bool override)
320 {

Callers

nothing calls this directly

Calls 9

runtime_errorClass · 0.85
dataMethod · 0.80
sizeMethod · 0.80
add_var_no_returnMethod · 0.80
rightMethod · 0.80
leftMethod · 0.80
copyFunction · 0.50
get_typeMethod · 0.45
rootMethod · 0.45

Tested by

no test coverage detected