src/xs_helper.hpp

filter: Statementstmt 68.6% 35 / 51 Branchbran 48.3% 29 / 60 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 57.6% 64 / 111 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« XS_xsgen.cc ↑ Summary XS.xs »
1 #pragma once
2  
3 #include <panda/string.h>
4 #include <xs/dict.h>
5 #include <xs/export.h>
6  
7 #include <dict.hpp> //rapidjson conflicts with perl macroses
8  
9 using namespace xs;
10 using panda::string;
11  
12 namespace json_tree {
13  
14 47 Sv dict2sv(const Dict* dict) {
15 47 ▶ if (dict == nullptr) return Sv::undef;
Branch: 1 branch
BranchTrueFalseTotal
if (dict == nullptr) return Sv::undef; 2 45 47
16 45 return std::visit(overloaded{
17 7 [](const Dict::ObjectMap& m) -> Sv {
18 7 ▶ auto ret = Hash::create(m.size());
Branch: 1 branch
BranchTrueFalseTotal
auto ret = Hash::create(m.size()); 7 0 7
19 21 ▶ for (const auto& r : m) ret[r.first.c_str()] = dict2sv(&r.second);
Branch: 6 branches
BranchTrueFalseTotal
for (const auto& r : m) ret[r.first.c_str()] = dict2sv(&r.second); 14 0 14
for (const auto& r : m) ret[r.first.c_str()] = dict2sv(&r.second); 14 0 14
for (const auto& r : m) ret[r.first.c_str()] = dict2sv(&r.second); 14 0 14
for (const auto& r : m) ret[r.first.c_str()] = dict2sv(&r.second); 14 0 14
for (const auto& r : m) ret[r.first.c_str()] = dict2sv(&r.second); 14 0 14
for (const auto& r : m) ret[r.first.c_str()] = dict2sv(&r.second); 14 7 21
20 14 ▶ return Ref::create(ret);
Branch: 1 branch
BranchTrueFalseTotal
return Ref::create(ret); 7 0 7
21 7 },
22 4 [](const Dict::ObjectArr& a) -> Sv {
23 4 ▶ auto ret = Array::create(a.size());
Branch: 1 branch
BranchTrueFalseTotal
auto ret = Array::create(a.size()); 4 0 4
24 15 ▶ for (const auto& r : a) ret.push(dict2sv(&r));
Branch: 3 branches
BranchTrueFalseTotal
for (const auto& r : a) ret.push(dict2sv(&r)); 11 0 11
for (const auto& r : a) ret.push(dict2sv(&r)); 11 0 11
for (const auto& r : a) ret.push(dict2sv(&r)); 11 4 15
25 8 ▶ return Ref::create(ret);
Branch: 1 branch
BranchTrueFalseTotal
return Ref::create(ret); 4 0 4
26 4 },
27 2 [](panda::string s) -> Sv {
28 2 ▶ return Simple(s.c_str());
Branch: 3 branches
BranchTrueFalseTotal
return Simple(s.c_str()); 2 0 2
return Simple(s.c_str()); 2 0 2
return Simple(s.c_str()); 2 0 2
29 },
30 2 [](Undef) -> Sv {
31 2 return Sv::undef;
32 },
33 30 [](auto v) -> Sv {
34 30 ▶ return Simple(v);
Branch: 3 branches
BranchTrueFalseTotal
return Simple(v); 6 0 6
return Simple(v); 4 0 4
return Simple(v); 20 0 20
35 },
36 },
37 45 ▶ dict->value);
Branch: 1 branch
BranchTrueFalseTotal
dict->value); 45 0 45
38 }
39  
40 9 Sv dict2sv_slice(const Dict* dict, panda::string field) {
41 9 ▶ if (dict == nullptr) return Sv::undef;
Branch: 1 branch
BranchTrueFalseTotal
if (dict == nullptr) return Sv::undef; 0 9 9
42  
43 9 return std::visit(overloaded{
44 9 [&](const Dict::ObjectMap& m) -> Sv {
45 9 ▶ if (m.find(field) == m.end()) return Sv::undef;
Branch: 2 branches
BranchTrueFalseTotal
if (m.find(field) == m.end()) return Sv::undef; 9 0 9
if (m.find(field) == m.end()) return Sv::undef; 3 6 9
46 6 return dict2sv(&m.at(field));
47 },
48 0 [&](const Dict::ObjectArr& a) -> Sv {
49 uint64_t i;
50 0 ▶ auto [p, ec] = std::from_chars(field.data(), field.data() + field.size(), i);
Branch: 1 branch
BranchTrueFalseTotal
auto [p, ec] = std::from_chars(field.data(), field.data() + field.size(), i); 0 0 0
51 0 ▶ if (ec != std::errc() || i >= a.size()) return nullptr;
Branch: 3 branches
BranchTrueFalseTotal
if (ec != std::errc() || i >= a.size()) return nullptr; 0 0 0
if (ec != std::errc() || i >= a.size()) return nullptr; 0 0 0
if (ec != std::errc() || i >= a.size()) return nullptr; 0 0 0
52  
53 0 ▶ return dict2sv(&a[i]);
Branch: 1 branch
BranchTrueFalseTotal
return dict2sv(&a[i]); 0 0 0
54 },
55 0 [](auto) -> Sv {
56 0 return Sv::undef;
57 },
58 },
59 9 ▶ dict->value);
Branch: 1 branch
BranchTrueFalseTotal
dict->value); 9 0 9
60 }
61  
62 struct StringArgsRange {
63 SV** args;
64 size_t _size;
65 109 size_t size() const { return _size; }
66 60 panda::string operator[](size_t i) const { return xs::in<panda::string>(args[i]); }
67 };
68  
69 } // namespace json_tree
« XS_xsgen.cc ↑ Summary XS.xs »