MCPcopy Create free account
hub / github.com/bytedance/bolt / extract

Method extract

bolt/expression/SingleSubfieldExtractor.cpp:43–78  ·  view source on GitHub ↗

Extracts chain of field names and depth from expression tree

Source from the content-addressed store, hash-verified

41
42// Extracts chain of field names and depth from expression tree
43std::optional<std::pair<std::vector<std::string>, size_t>>
44SingleSubfieldExtractor::extract(const core::ITypedExpr* root) {
45 multipleChainsFound_ = false;
46
47 auto resultOpt = parseSingleChain(root);
48 if (!resultOpt || multipleChainsFound_) {
49 return std::nullopt;
50 }
51
52 auto& [chain, totalDepth] = *resultOpt;
53 std::vector<std::string> names;
54 names.reserve(chain.size());
55
56 for (const auto* node : chain) {
57 switch (node->typedExprKind()) {
58 case core::kDereference:
59 names.push_back(
60 static_cast<const core::DereferenceTypedExpr*>(node)->name());
61 break;
62 case core::kFieldAccess:
63 names.push_back(
64 static_cast<const core::FieldAccessTypedExpr*>(node)->name());
65 break;
66 default:
67 BOLT_UNREACHABLE();
68 }
69 }
70
71 size_t depth = 0;
72 if (totalDepth >= names.size()) {
73 depth = totalDepth - names.size() + 1;
74 }
75
76 VLOG(3) << "Extracted " << names.size() << " names with depth " << depth;
77 return std::make_pair(names, depth);
78}
79
80// Main recursive function to parse expression chains
81std::optional<std::pair<std::vector<const core::ITypedExpr*>, size_t>>

Callers 1

TEST_FFunction · 0.45

Calls 5

typedExprKindMethod · 0.80
reserveMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45
nameMethod · 0.45

Tested by 1

TEST_FFunction · 0.36