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

Method extract_inheritance

codegraph-kernel/src/rustlang.rs:1142–1186  ·  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

1140 /// check on field_declaration is gated to Go (and was inert here anyway —
1141 /// every rust field has a field_identifier).
1142 fn extract_inheritance(&mut self, node: Node<'t>, class_row: u32) {
1143 stack_guard!();
1144 let extends_kind = edge_kind_index("extends").unwrap();
1145 for i in 0..node.named_child_count() {
1146 let Some(child) = node.named_child(i) else { continue };
1147 match child.kind() {
1148 "trait_bounds" => {
1149 for j in 0..child.named_child_count() {
1150 let Some(bound) = child.named_child(j) else { continue };
1151 let type_node: Option<Node> = match bound.kind() {
1152 "type_identifier" => Some(bound),
1153 "generic_type" => (0..bound.named_child_count())
1154 .filter_map(|k| bound.named_child(k))
1155 .find(|c| c.kind() == "type_identifier"),
1156 "higher_ranked_trait_bound" => {
1157 let generic = (0..bound.named_child_count())
1158 .filter_map(|k| bound.named_child(k))
1159 .find(|c| c.kind() == "generic_type");
1160 generic
1161 .and_then(|g| {
1162 (0..g.named_child_count())
1163 .filter_map(|k| g.named_child(k))
1164 .find(|c| c.kind() == "type_identifier")
1165 })
1166 .or_else(|| {
1167 (0..bound.named_child_count())
1168 .filter_map(|k| bound.named_child(k))
1169 .find(|c| c.kind() == "type_identifier")
1170 })
1171 }
1172 _ => None, // scoped_type_identifier: dropped (quirk)
1173 };
1174 if let Some(tn) = type_node {
1175 let name = self.text(tn).to_string();
1176 self.push_ref_at(class_row, &name, extends_kind, tn);
1177 }
1178 }
1179 }
1180 "field_declaration_list" | "class_heritage" => {
1181 self.extract_inheritance(child, class_row);
1182 }
1183 _ => {}
1184 }
1185 }
1186 }
1187
1188 /// extractRustImplItem — `impl Trait for Type` back-reference from the
1189 /// 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