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

Method recover_cpp_macro_defined_name

codegraph-kernel/src/ccpp/mod.rs:905–947  ·  view source on GitHub ↗

recoverCppMacroDefinedName (languages/c-cpp.ts:49).

(&self, node: Node)

Source from the content-addressed store, hash-verified

903
904 /// recoverCppMacroDefinedName (languages/c-cpp.ts:49).
905 fn recover_cpp_macro_defined_name(&self, node: Node) -> Option<String> {
906 if node.kind() != "function_definition" {
907 return None;
908 }
909 let declarator = node.child_by_field_name("declarator")?;
910 if declarator.kind() != "function_declarator" {
911 return None;
912 }
913 let inner = declarator.child_by_field_name("declarator")?;
914 if inner.kind() != "identifier" {
915 return None;
916 }
917 let macro_name = self.text(inner);
918 if !macro_shaped_re().is_match(macro_name) {
919 return None;
920 }
921 let params = declarator.child_by_field_name("parameters")?;
922 if params.named_child_count() < 2 {
923 return None;
924 }
925 let lone_ident_text = |p: Node| -> Option<&'t str> {
926 if p.kind() == "parameter_declaration"
927 && p.named_child_count() == 1
928 && p.named_child(0).map(|c| c.kind() == "type_identifier").unwrap_or(false)
929 {
930 Some(self.text(p.named_child(0).unwrap()))
931 } else {
932 None
933 }
934 };
935 let name = params.named_child(0).and_then(lone_ident_text)?;
936 if !has_lower_re().is_match(name) {
937 return None;
938 }
939 for i in 1..params.named_child_count() {
940 if let Some(p) = params.named_child(i) {
941 if lone_ident_text(p).is_some() {
942 return None;
943 }
944 }
945 }
946 Some(name.to_string())
947 }
948
949 /// extractCppReceiverType (languages/c-cpp.ts): the scopes are what the
950 /// qualified id writes before its name, so a specialization's arguments

Callers 2

constructor_signatureMethod · 0.80

Calls 5

macro_shaped_reFunction · 0.85
has_lower_reFunction · 0.85
mapMethod · 0.80
textMethod · 0.65
unwrapMethod · 0.60

Tested by

no test coverage detected