MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extract_inheritance

Method extract_inheritance

codegraph-kernel/src/rustlang.rs:1124–1168  ·  view source on GitHub ↗

extractInheritance — the rust-reachable cases: trait_bounds (supertraits; a scoped `fmt::Debug` bound matches NO case and is dropped) and the field_declaration_list recursion. The TS Go-embedding check on field_declaration is gated to Go (and was inert here anyway — every rust field has a field_identifier).

(&mut self, node: Node<'t>, class_row: u32)

Source from the content-addressed store, hash-verified

1122 /// check on field_declaration is gated to Go (and was inert here anyway —
1123 /// every rust field has a field_identifier).
1124 fn extract_inheritance(&mut self, node: Node<'t>, class_row: u32) {
1125 stack_guard!();
1126 let extends_kind = edge_kind_index("extends").unwrap();
1127 for i in 0..node.named_child_count() {
1128 let Some(child) = node.named_child(i) else { continue };
1129 match child.kind() {
1130 "trait_bounds" => {
1131 for j in 0..child.named_child_count() {
1132 let Some(bound) = child.named_child(j) else { continue };
1133 let type_node: Option<Node> = match bound.kind() {
1134 "type_identifier" => Some(bound),
1135 "generic_type" => (0..bound.named_child_count())
1136 .filter_map(|k| bound.named_child(k))
1137 .find(|c| c.kind() == "type_identifier"),
1138 "higher_ranked_trait_bound" => {
1139 let generic = (0..bound.named_child_count())
1140 .filter_map(|k| bound.named_child(k))
1141 .find(|c| c.kind() == "generic_type");
1142 generic
1143 .and_then(|g| {
1144 (0..g.named_child_count())
1145 .filter_map(|k| g.named_child(k))
1146 .find(|c| c.kind() == "type_identifier")
1147 })
1148 .or_else(|| {
1149 (0..bound.named_child_count())
1150 .filter_map(|k| bound.named_child(k))
1151 .find(|c| c.kind() == "type_identifier")
1152 })
1153 }
1154 _ => None, // scoped_type_identifier: dropped (quirk)
1155 };
1156 if let Some(tn) = type_node {
1157 let name = self.text(tn).to_string();
1158 self.push_ref_at(class_row, &name, extends_kind, tn);
1159 }
1160 }
1161 }
1162 "field_declaration_list" | "class_heritage" => {
1163 self.extract_inheritance(child, class_row);
1164 }
1165 _ => {}
1166 }
1167 }
1168 }
1169
1170 /// extractRustImplItem — `impl Trait for Type` back-reference from the
1171 /// grammar's `trait` / `type` fields (#1588; an inherent impl has no

Callers 3

extract_interfaceMethod · 0.45
extract_aggregateMethod · 0.45
extract_enumMethod · 0.45

Calls 4

edge_kind_indexFunction · 0.85
textMethod · 0.65
unwrapMethod · 0.60
push_ref_atMethod · 0.45

Tested by

no test coverage detected