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

Method extract_function

codegraph-kernel/src/ccpp/mod.rs:851–889  ·  view source on GitHub ↗
(&mut self, node: Node<'t>)

Source from the content-addressed store, hash-verified

849 // --- extractors ----------------------------------------------------------
850
851 fn extract_function(&mut self, node: Node<'t>) {
852 // Receiver present (out-of-line `Cls::method` def) → method instead.
853 if self.variant == Variant::Cpp && self.receiver_type_of(node).is_some() {
854 self.extract_method(node);
855 return;
856 }
857
858 let name = self.extract_name(node);
859 if name == "<anonymous>" {
860 if let Some(body) = node.child_by_field_name("body") {
861 self.visit_function_body(body);
862 }
863 return;
864 }
865 // Misparse artifacts: drop the node, still walk the body (#946/#1061).
866 if self.is_misparsed_function(&name, node) {
867 if let Some(body) = node.child_by_field_name("body") {
868 self.visit_function_body(body);
869 }
870 return;
871 }
872
873 let extra = Extra {
874 docstring: preceding_docstring(node, self.src),
875 visibility: if self.variant == Variant::Cpp { self.visibility_of(node) } else { None },
876 return_type: self.return_type_of(node),
877 ..Extra::default()
878 };
879 let Some(row) = self.create_node("function", &name, node, extra) else { return };
880 // (extractTypeAnnotations + extractDecoratorsFor are structural no-ops
881 // for c/cpp: not in TYPE_ANNOTATION_LANGUAGES, and the decorator node
882 // kinds never appear as direct children/preceding siblings in these
883 // grammars — `attribute` only occurs under attribute_declaration.)
884 self.stack.push(Scope { row, kind: "function", name });
885 if let Some(body) = node.child_by_field_name("body") {
886 self.visit_function_body(body);
887 }
888 self.stack.pop();
889 }
890
891 fn extract_method(&mut self, node: Node<'t>) {
892 let receiver_type = if self.variant == Variant::Cpp { self.receiver_type_of(node) } else { None };

Callers 3

visit_nodeMethod · 0.45
extract_methodMethod · 0.45

Calls 9

preceding_docstringFunction · 0.85
is_misparsed_functionMethod · 0.80
receiver_type_ofMethod · 0.45
extract_methodMethod · 0.45
extract_nameMethod · 0.45
visit_function_bodyMethod · 0.45
visibility_ofMethod · 0.45
return_type_ofMethod · 0.45
create_nodeMethod · 0.45

Tested by

no test coverage detected