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

Method visit_node

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

Source from the content-addressed store, hash-verified

776 // --- visitNode -----------------------------------------------------------
777
778 fn visit_node(&mut self, node: Node<'t>) {
779 let kind = node.kind();
780 let mut skip_children = false;
781
782 // C++ namespace blocks: prefix-only, no node (#1291/#1093). Anonymous
783 // namespaces fall through to the generic walk.
784 if self.variant == Variant::Cpp && kind == "namespace_definition" {
785 let ns_name = node
786 .child_by_field_name("name")
787 .map(|n| self.text(n).to_string())
788 .unwrap_or_default();
789 if !ns_name.is_empty() {
790 self.namespace_prefix.push(ns_name);
791 for i in 0..node.named_child_count() {
792 if let Some(c) = node.named_child(i) {
793 self.visit_node(c);
794 }
795 }
796 self.namespace_prefix.pop();
797 return;
798 }
799 }
800
801 self.maybe_capture_fn_refs(node);
802
803 if kind == "function_definition" {
804 // functionTypes for both; cpp's methodTypes also lists it, so
805 // inside a class-like scope it extracts as a method.
806 if self.inside_class_like() && self.variant == Variant::Cpp {
807 self.extract_method(node);
808 } else {
809 self.extract_function(node);
810 }
811 skip_children = true;
812 } else if self.variant == Variant::Cpp && kind == "class_specifier" {
813 self.extract_class(node);
814 skip_children = true;
815 } else if kind == "struct_specifier" {
816 self.extract_struct(node);
817 skip_children = true;
818 } else if kind == "enum_specifier" {
819 self.extract_enum(node);
820 skip_children = true;
821 } else if kind == "type_definition"
822 || (self.variant == Variant::Cpp && kind == "alias_declaration")
823 {
824 skip_children = self.extract_type_alias(node);
825 } else if kind == "declaration" && !self.inside_class_like() {
826 self.extract_variable(node);
827 self.scan_fn_ref_subtree(node, 0);
828 skip_children = true;
829 } else if kind == "preproc_include" {
830 self.extract_import(node);
831 } else if kind == "call_expression" {
832 self.extract_call(node);
833 } else if kind == "new_expression" {
834 // INSTANTIATION_KINDS: cpp `new Foo(...)`. (No anonymous-class
835 // body exists under new_expression in this grammar; children are

Callers 5

extractFunction · 0.45
extract_classMethod · 0.45
extract_structMethod · 0.45
extract_enumMethod · 0.45
extract_type_aliasMethod · 0.45

Calls 14

textMethod · 0.45
maybe_capture_fn_refsMethod · 0.45
inside_class_likeMethod · 0.45
extract_methodMethod · 0.45
extract_functionMethod · 0.45
extract_classMethod · 0.45
extract_structMethod · 0.45
extract_enumMethod · 0.45
extract_type_aliasMethod · 0.45
extract_variableMethod · 0.45
scan_fn_ref_subtreeMethod · 0.45
extract_importMethod · 0.45

Tested by

no test coverage detected