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:907–949  ·  view source on GitHub ↗

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

(&self, node: Node)

Source from the content-addressed store, hash-verified

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