MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / _cpp_primary_template_function_name

Function _cpp_primary_template_function_name

graphify/extractors/engine.py:5355–5406  ·  view source on GitHub ↗

Prove a same-file primary owner instead of erasing arbitrary template arguments. shortcut: only unique parameterless primitive-returning members are matched, use signature-aware template resolution for overloads or dependent signatures.

(node, source: bytes, classes: dict)

Source from the content-addressed store, hash-verified

5353
5354
5355def _cpp_primary_template_function_name(node, source: bytes, classes: dict) -> str | None:
5356 """Prove a same-file primary owner instead of erasing arbitrary template arguments.
5357
5358 shortcut: only unique parameterless primitive-returning members are matched,
5359 use signature-aware template resolution for overloads or dependent signatures.
5360 """
5361 parameters = _cpp_plain_template_parameters(node.parent, source)
5362 signature = _cpp_zero_arg_member_signature(node, source)
5363 if not parameters or signature is None:
5364 return None
5365 declarator = node.child_by_field_name("declarator").child_by_field_name("declarator")
5366 if declarator.type != "qualified_identifier":
5367 return None
5368 owner = declarator.child_by_field_name("scope")
5369 member = declarator.child_by_field_name("name")
5370 if owner is None or owner.type != "template_type" or member is None or member.type != "identifier":
5371 return None
5372 owner_name = owner.child_by_field_name("name")
5373 arguments = owner.child_by_field_name("arguments")
5374 if owner_name is None or owner_name.type != "type_identifier" or arguments is None:
5375 return None
5376 if ["".join(_read_text(c, source).split()) for c in arguments.named_children] != parameters:
5377 return None
5378 name = _read_text(owner_name, source)
5379 candidates = classes.get(normalize_id(name), [])
5380 if len(candidates) != 1:
5381 return None
5382 primary = candidates[0]
5383 template = primary.parent
5384 scope = node.parent.parent
5385 if (scope is None or scope.type not in {"translation_unit", "declaration_list"}
5386 or template is None or template.parent != scope
5387 or len(_cpp_plain_template_parameters(template, source)) != len(parameters)
5388 or _read_text(primary.child_by_field_name("name"), source) != name):
5389 return None
5390 body = primary.child_by_field_name("body")
5391 if body is None:
5392 return None
5393 method = _read_text(member, source)
5394 declarations = []
5395 for child in body.named_children:
5396 declaration = child
5397 while declaration.type == "template_declaration":
5398 declaration = declaration.named_children[-1]
5399 for item in declaration.children_by_field_name("declarator"):
5400 if normalize_id(_get_cpp_func_name(item, source) or "") == normalize_id(method):
5401 declarations.append((child, declaration))
5402 if (len(declarations) != 1 or declarations[0][0].type != "field_declaration"
5403 or _get_cpp_func_name(declarations[0][1], source) != method
5404 or _cpp_zero_arg_member_signature(declarations[0][1], source) != signature):
5405 return None
5406 return f"{name}::{method}"
5407
5408
5409def _cpp_type_is_dependent(node, source: bytes) -> bool:

Callers 1

walkFunction · 0.85

Calls 7

_read_textFunction · 0.90
normalize_idFunction · 0.90
_get_cpp_func_nameFunction · 0.85
joinMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected