| 1 |
|
| #include "export.h" |
| 2 |
|
| #include <xs/Ref.h> |
| 3 |
|
| #include <xs/Array.h> |
| 4 |
|
| #include <panda/optional.h> |
| 5 |
|
| |
| 6 |
|
| namespace xs { namespace exp { |
| 7 |
|
| |
| 8 |
|
| using panda::string; |
| 9 |
|
| using panda::string_view; |
| 10 |
|
| |
| 11 |
|
| static PERL_ITHREADS_LOCAL struct { |
| 12 |
|
| Hash clists; |
| 13 |
|
| Stash self_stash = Stash("Export::XS", GV_ADD); |
| 14 |
|
| } tls; |
| 15 |
|
| |
| 16 |
3 |
| static bool _init () { |
| 17 |
3 |
▶ | xs::at_perl_destroy([]{ |
Branch: 2 branches
| Branch | True | False | Total |
| xs::at_perl_destroy([]{ |
3 |
0 |
3 |
| xs::at_perl_destroy([]{ |
3 |
0 |
3 |
|
| 18 |
3 |
| tls.clists = nullptr; |
| 19 |
3 |
| tls.self_stash = nullptr; |
| 20 |
3 |
| }); |
| 21 |
3 |
| return true; |
| 22 |
|
| } |
| 23 |
|
| static bool __init = _init(); |
| 24 |
|
| |
| 25 |
0 |
▶ | static void throw_noname (Stash s) { throw std::logic_error(string("Export::XS: can't define a constant with an empty name in '") + s.name() + "'"); } |
Branch: 5 branches
| Branch | True | False | Total |
| static void throw_noname (Stash s) { throw std::logic_error(string("Export::XS: can't define a constant with an empty name in '") + s.name() + "'"); } |
0 |
0 |
0 |
| static void throw_noname (Stash s) { throw std::logic_error(string("Export::XS: can't define a constant with an empty name in '") + s.name() + "'"); } |
0 |
0 |
0 |
| static void throw_noname (Stash s) { throw std::logic_error(string("Export::XS: can't define a constant with an empty name in '") + s.name() + "'"); } |
0 |
0 |
0 |
| static void throw_noname (Stash s) { throw std::logic_error(string("Export::XS: can't define a constant with an empty name in '") + s.name() + "'"); } |
0 |
0 |
0 |
| static void throw_noname (Stash s) { throw std::logic_error(string("Export::XS: can't define a constant with an empty name in '") + s.name() + "'"); } |
0 |
0 |
0 |
|
| 26 |
|
| |
| 27 |
10 |
| Array constants_list (const Stash& stash) { |
| 28 |
10 |
▶ | if (!tls.clists) tls.clists = Hash::create(); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!tls.clists) tls.clists = Hash::create(); |
3 |
7 |
10 |
| if (!tls.clists) tls.clists = Hash::create(); |
3 |
0 |
3 |
|
| 29 |
10 |
▶ | auto clist = tls.clists[stash.name()]; |
Branch: 2 branches
| Branch | True | False | Total |
| auto clist = tls.clists[stash.name()]; |
10 |
0 |
10 |
| auto clist = tls.clists[stash.name()]; |
10 |
0 |
10 |
|
| 30 |
10 |
▶ | if (!clist.defined()) clist = Ref::create(Array::create()); |
Branch: 5 branches
| Branch | True | False | Total |
| if (!clist.defined()) clist = Ref::create(Array::create()); |
10 |
0 |
10 |
| if (!clist.defined()) clist = Ref::create(Array::create()); |
3 |
7 |
10 |
| if (!clist.defined()) clist = Ref::create(Array::create()); |
3 |
0 |
3 |
| if (!clist.defined()) clist = Ref::create(Array::create()); |
3 |
0 |
3 |
| if (!clist.defined()) clist = Ref::create(Array::create()); |
3 |
0 |
3 |
|
| 31 |
20 |
▶ | return Array(clist); |
Branch: 1 branch
| Branch | True | False | Total |
| return Array(clist); |
10 |
0 |
10 |
|
| 32 |
10 |
| } |
| 33 |
|
| |
| 34 |
17 |
| static void register_export_impl (const Stash& stash, string_view name, Array clist) { |
| 35 |
17 |
▶ | if (!name.length()) throw_noname(stash); |
Branch: 3 branches
| Branch | True | False | Total |
| if (!name.length()) throw_noname(stash); |
0 |
17 |
17 |
| if (!name.length()) throw_noname(stash); |
0 |
0 |
0 |
| if (!name.length()) throw_noname(stash); |
0 |
0 |
0 |
|
| 36 |
17 |
▶ | if (!clist) clist = constants_list(stash); |
Branch: 2 branches
| Branch | True | False | Total |
| if (!clist) clist = constants_list(stash); |
0 |
17 |
17 |
| if (!clist) clist = constants_list(stash); |
0 |
0 |
0 |
|
| 37 |
17 |
▶ | clist.push(Simple(name)); |
Branch: 2 branches
| Branch | True | False | Total |
| clist.push(Simple(name)); |
17 |
0 |
17 |
| clist.push(Simple(name)); |
17 |
0 |
17 |
|
| 38 |
17 |
| } |
| 39 |
|
| |
| 40 |
0 |
| void register_export (const Stash& stash, string_view name) { |
| 41 |
0 |
▶ | register_export_impl(stash, name, {}); |
Branch: 1 branch
| Branch | True | False | Total |
| register_export_impl(stash, name, {}); |
0 |
0 |
0 |
|
| 42 |
0 |
| } |
| 43 |
|
| |
| 44 |
18 |
| static void create_constant_impl (Stash& stash, const Constant& c, Array clist) { |
| 45 |
18 |
▶ | if (!c.name.length()) throw_noname(stash); |
Branch: 3 branches
| Branch | True | False | Total |
| if (!c.name.length()) throw_noname(stash); |
0 |
18 |
18 |
| if (!c.name.length()) throw_noname(stash); |
0 |
0 |
0 |
| if (!c.name.length()) throw_noname(stash); |
0 |
0 |
0 |
|
| 46 |
|
| |
| 47 |
|
| // check that we won't redefine any subroutine |
| 48 |
18 |
▶ | if (stash.sub(c.name)) throw std::logic_error(string("Export::XS: can't create constant '") + stash.name() + "::" + c.name + "' - symbol already exists"); |
Branch: 9 branches
| Branch | True | False | Total |
| if (stash.sub(c.name)) throw std::logic_error(string("Export::XS: can't create constant '") + stash.name() + "::" + c.name + "' - symbol already exists"); |
18 |
0 |
18 |
| if (stash.sub(c.name)) throw std::logic_error(string("Export::XS: can't create constant '") + stash.name() + "::" + c.name + "' - symbol already exists"); |
1 |
17 |
18 |
| if (stash.sub(c.name)) throw std::logic_error(string("Export::XS: can't create constant '") + stash.name() + "::" + c.name + "' - symbol already exists"); |
1 |
0 |
1 |
| if (stash.sub(c.name)) throw std::logic_error(string("Export::XS: can't create constant '") + stash.name() + "::" + c.name + "' - symbol already exists"); |
1 |
0 |
1 |
| if (stash.sub(c.name)) throw std::logic_error(string("Export::XS: can't create constant '") + stash.name() + "::" + c.name + "' - symbol already exists"); |
1 |
0 |
1 |
| if (stash.sub(c.name)) throw std::logic_error(string("Export::XS: can't create constant '") + stash.name() + "::" + c.name + "' - symbol already exists"); |
1 |
0 |
1 |
| if (stash.sub(c.name)) throw std::logic_error(string("Export::XS: can't create constant '") + stash.name() + "::" + c.name + "' - symbol already exists"); |
1 |
0 |
1 |
| if (stash.sub(c.name)) throw std::logic_error(string("Export::XS: can't create constant '") + stash.name() + "::" + c.name + "' - symbol already exists"); |
1 |
0 |
1 |
| if (stash.sub(c.name)) throw std::logic_error(string("Export::XS: can't create constant '") + stash.name() + "::" + c.name + "' - symbol already exists"); |
1 |
0 |
1 |
|
| 49 |
|
| |
| 50 |
17 |
| stash.add_const_sub(c.name, c.value); |
| 51 |
17 |
▶ | register_export_impl(stash, c.name, clist); |
Branch: 2 branches
| Branch | True | False | Total |
| register_export_impl(stash, c.name, clist); |
17 |
0 |
17 |
| register_export_impl(stash, c.name, clist); |
17 |
0 |
17 |
|
| 52 |
17 |
| } |
| 53 |
|
| |
| 54 |
0 |
| void create_constant (Stash stash, const Constant& c) { |
| 55 |
0 |
▶ | create_constant_impl(stash, c, {}); |
Branch: 1 branch
| Branch | True | False | Total |
| create_constant_impl(stash, c, {}); |
0 |
0 |
0 |
|
| 56 |
0 |
| } |
| 57 |
|
| |
| 58 |
0 |
| void create_constants (Stash stash, const std::initializer_list<Constant>& list) { |
| 59 |
0 |
▶ | auto clist = constants_list(stash); |
Branch: 1 branch
| Branch | True | False | Total |
| auto clist = constants_list(stash); |
0 |
0 |
0 |
|
| 60 |
0 |
▶ | for (auto& c : list) create_constant_impl(stash, c, clist); |
Branch: 3 branches
| Branch | True | False | Total |
| for (auto& c : list) create_constant_impl(stash, c, clist); |
0 |
0 |
0 |
| for (auto& c : list) create_constant_impl(stash, c, clist); |
0 |
0 |
0 |
| for (auto& c : list) create_constant_impl(stash, c, clist); |
0 |
0 |
0 |
|
| 61 |
0 |
| } |
| 62 |
|
| |
| 63 |
3 |
| void create_constants (Stash stash, const Hash& hash) { |
| 64 |
3 |
▶ | auto clist = constants_list(stash); |
Branch: 1 branch
| Branch | True | False | Total |
| auto clist = constants_list(stash); |
3 |
0 |
3 |
|
| 65 |
18 |
▶ | for (const auto& row : hash) create_constant_impl(stash, Constant(row.key(), row.value()), clist); |
Branch: 7 branches
| Branch | True | False | Total |
| for (const auto& row : hash) create_constant_impl(stash, Constant(row.key(), row.value()), clist); |
3 |
0 |
3 |
| for (const auto& row : hash) create_constant_impl(stash, Constant(row.key(), row.value()), clist); |
13 |
0 |
13 |
| for (const auto& row : hash) create_constant_impl(stash, Constant(row.key(), row.value()), clist); |
13 |
0 |
13 |
| for (const auto& row : hash) create_constant_impl(stash, Constant(row.key(), row.value()), clist); |
13 |
0 |
13 |
| for (const auto& row : hash) create_constant_impl(stash, Constant(row.key(), row.value()), clist); |
13 |
0 |
13 |
| for (const auto& row : hash) create_constant_impl(stash, Constant(row.key(), row.value()), clist); |
12 |
1 |
13 |
| for (const auto& row : hash) create_constant_impl(stash, Constant(row.key(), row.value()), clist); |
13 |
2 |
15 |
|
| 66 |
3 |
| } |
| 67 |
|
| |
| 68 |
4 |
| void create_constants (Stash stash, SV*const* list, size_t items) { |
| 69 |
4 |
▶ | if (!list || !items) return; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!list || !items) return; |
4 |
0 |
4 |
| if (!list || !items) return; |
0 |
4 |
4 |
|
| 70 |
4 |
▶ | auto clist = constants_list(stash); |
Branch: 1 branch
| Branch | True | False | Total |
| auto clist = constants_list(stash); |
4 |
0 |
4 |
|
| 71 |
9 |
▶ | for (size_t i = 0; i < items - 1; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (size_t i = 0; i < items - 1; i += 2) { |
6 |
3 |
9 |
|
| 72 |
6 |
▶ | Simple name = *list++; |
Branch: 1 branch
| Branch | True | False | Total |
| Simple name = *list++; |
5 |
1 |
6 |
|
| 73 |
5 |
| Sv value = *list++; |
| 74 |
5 |
▶ | create_constant_impl(stash, Constant(name, value), clist); |
Branch: 4 branches
| Branch | True | False | Total |
| create_constant_impl(stash, Constant(name, value), clist); |
5 |
0 |
5 |
| create_constant_impl(stash, Constant(name, value), clist); |
5 |
0 |
5 |
| create_constant_impl(stash, Constant(name, value), clist); |
5 |
0 |
5 |
| create_constant_impl(stash, Constant(name, value), clist); |
5 |
0 |
5 |
|
| 75 |
5 |
| } |
| 76 |
4 |
| } |
| 77 |
|
| |
| 78 |
31 |
| void export_sub (const Stash& from, Stash to, string_view name) { |
| 79 |
31 |
▶ | auto gv = from.fetch(name); |
Branch: 1 branch
| Branch | True | False | Total |
| auto gv = from.fetch(name); |
31 |
0 |
31 |
|
| 80 |
31 |
▶ | if (!gv.sub()) throw std::logic_error(string("Export::XS: can't export unexisting symbol '") + from.name() + "::" + name + "'"); |
Branch: 9 branches
| Branch | True | False | Total |
| if (!gv.sub()) throw std::logic_error(string("Export::XS: can't export unexisting symbol '") + from.name() + "::" + name + "'"); |
31 |
0 |
31 |
| if (!gv.sub()) throw std::logic_error(string("Export::XS: can't export unexisting symbol '") + from.name() + "::" + name + "'"); |
1 |
30 |
31 |
| if (!gv.sub()) throw std::logic_error(string("Export::XS: can't export unexisting symbol '") + from.name() + "::" + name + "'"); |
1 |
0 |
1 |
| if (!gv.sub()) throw std::logic_error(string("Export::XS: can't export unexisting symbol '") + from.name() + "::" + name + "'"); |
1 |
0 |
1 |
| if (!gv.sub()) throw std::logic_error(string("Export::XS: can't export unexisting symbol '") + from.name() + "::" + name + "'"); |
1 |
0 |
1 |
| if (!gv.sub()) throw std::logic_error(string("Export::XS: can't export unexisting symbol '") + from.name() + "::" + name + "'"); |
1 |
0 |
1 |
| if (!gv.sub()) throw std::logic_error(string("Export::XS: can't export unexisting symbol '") + from.name() + "::" + name + "'"); |
1 |
0 |
1 |
| if (!gv.sub()) throw std::logic_error(string("Export::XS: can't export unexisting symbol '") + from.name() + "::" + name + "'"); |
1 |
0 |
1 |
| if (!gv.sub()) throw std::logic_error(string("Export::XS: can't export unexisting symbol '") + from.name() + "::" + name + "'"); |
1 |
0 |
1 |
|
| 81 |
30 |
▶ | to[name] = gv; // "to[name] = sub" leads to "used once once" warning. setting the whole glob supresses the warning |
Branch: 2 branches
| Branch | True | False | Total |
| to[name] = gv; // "to[name] = sub" leads to "used once once" warning. setting the whole glob supresses the warning |
30 |
0 |
30 |
| to[name] = gv; // "to[name] = sub" leads to "used once once" warning. setting the whole glob supresses the warning |
30 |
0 |
30 |
|
| 82 |
31 |
| } |
| 83 |
|
| |
| 84 |
3 |
| void export_constants (const Stash& from, Stash to) { |
| 85 |
3 |
▶ | auto clist = constants_list(from); |
Branch: 1 branch
| Branch | True | False | Total |
| auto clist = constants_list(from); |
3 |
0 |
3 |
|
| 86 |
26 |
▶ | for (const auto& elem : clist) export_sub(from, to, Simple(elem)); |
Branch: 8 branches
| Branch | True | False | Total |
| for (const auto& elem : clist) export_sub(from, to, Simple(elem)); |
3 |
0 |
3 |
| for (const auto& elem : clist) export_sub(from, to, Simple(elem)); |
3 |
0 |
3 |
| for (const auto& elem : clist) export_sub(from, to, Simple(elem)); |
23 |
0 |
23 |
| for (const auto& elem : clist) export_sub(from, to, Simple(elem)); |
23 |
0 |
23 |
| for (const auto& elem : clist) export_sub(from, to, Simple(elem)); |
23 |
0 |
23 |
| for (const auto& elem : clist) export_sub(from, to, Simple(elem)); |
23 |
0 |
23 |
| for (const auto& elem : clist) export_sub(from, to, Simple(elem)); |
23 |
0 |
23 |
| for (const auto& elem : clist) export_sub(from, to, Simple(elem)); |
23 |
3 |
26 |
|
| 87 |
3 |
| } |
| 88 |
|
| |
| 89 |
2 |
| void autoexport (Stash stash) { |
| 90 |
2 |
▶ | auto gv = tls.self_stash["import"]; |
Branch: 1 branch
| Branch | True | False | Total |
| auto gv = tls.self_stash["import"]; |
2 |
0 |
2 |
|
| 91 |
2 |
▶ | auto dsub = stash.sub("import"); |
Branch: 1 branch
| Branch | True | False | Total |
| auto dsub = stash.sub("import"); |
2 |
0 |
2 |
|
| 92 |
2 |
| if ( |
| 93 |
2 |
| dsub && |
| 94 |
3 |
▶ | dsub != gv.sub() && |
Branch: 5 branches
| Branch | True | False | Total |
| dsub != gv.sub() && |
1 |
0 |
1 |
| dsub != gv.sub() && |
1 |
0 |
1 |
| dsub != gv.sub() && |
0 |
1 |
1 |
| dsub != gv.sub() && |
0 |
2 |
2 |
| dsub != gv.sub() && |
0 |
0 |
0 |
|
| 95 |
5 |
▶ | (!dsub.stash() || dsub.stash().name() != "UNIVERSAL") && |
Branch: 11 branches
| Branch | True | False | Total |
| (!dsub.stash() || dsub.stash().name() != "UNIVERSAL") && |
1 |
1 |
2 |
| (!dsub.stash() || dsub.stash().name() != "UNIVERSAL") && |
0 |
0 |
0 |
| (!dsub.stash() || dsub.stash().name() != "UNIVERSAL") && |
0 |
0 |
0 |
| (!dsub.stash() || dsub.stash().name() != "UNIVERSAL") && |
0 |
0 |
0 |
| (!dsub.stash() || dsub.stash().name() != "UNIVERSAL") && |
0 |
0 |
0 |
| (!dsub.stash() || dsub.stash().name() != "UNIVERSAL") && |
0 |
0 |
0 |
| (!dsub.stash() || dsub.stash().name() != "UNIVERSAL") && |
0 |
0 |
0 |
| (!dsub.stash() || dsub.stash().name() != "UNIVERSAL") && |
0 |
2 |
2 |
| (!dsub.stash() || dsub.stash().name() != "UNIVERSAL") && |
1 |
1 |
2 |
| (!dsub.stash() || dsub.stash().name() != "UNIVERSAL") && |
0 |
0 |
0 |
| (!dsub.stash() || dsub.stash().name() != "UNIVERSAL") && |
0 |
0 |
0 |
|
| 96 |
2 |
▶ | (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
Branch: 21 branches
| Branch | True | False | Total |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
2 |
2 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
2 |
2 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
2 |
2 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
2 |
2 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
2 |
2 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
2 |
2 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
| (!dsub.glob() || !dsub.glob().stash() || dsub.glob().stash().name() != "UNIVERSAL") |
0 |
0 |
0 |
|
| 97 |
|
| ) { |
| 98 |
0 |
▶ | throw std::logic_error(string("Export::XS: can't make autoexport for stash '") + stash.name() + "' - you already have import() sub"); |
Branch: 5 branches
| Branch | True | False | Total |
| throw std::logic_error(string("Export::XS: can't make autoexport for stash '") + stash.name() + "' - you already have import() sub"); |
0 |
0 |
0 |
| throw std::logic_error(string("Export::XS: can't make autoexport for stash '") + stash.name() + "' - you already have import() sub"); |
0 |
0 |
0 |
| throw std::logic_error(string("Export::XS: can't make autoexport for stash '") + stash.name() + "' - you already have import() sub"); |
0 |
0 |
0 |
| throw std::logic_error(string("Export::XS: can't make autoexport for stash '") + stash.name() + "' - you already have import() sub"); |
0 |
0 |
0 |
| throw std::logic_error(string("Export::XS: can't make autoexport for stash '") + stash.name() + "' - you already have import() sub"); |
0 |
0 |
0 |
|
| 99 |
|
| } |
| 100 |
2 |
▶ | stash["import"] = gv; |
Branch: 2 branches
| Branch | True | False | Total |
| stash["import"] = gv; |
2 |
0 |
2 |
| stash["import"] = gv; |
2 |
0 |
2 |
|
| 101 |
2 |
| } |
| 102 |
|
| |
| 103 |
|
| }} |