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

Function _cpp_member_record

graphify/extractors/engine.py:5269–5316  ·  view source on GitHub ↗

Literal zero-argument member facts; unsupported syntax stays an ambiguity record.

(node, declarator, name: str, source: bytes)

Source from the content-addressed store, hash-verified

5267
5268
5269def _cpp_member_record(node, declarator, name: str, source: bytes) -> dict:
5270 """Literal zero-argument member facts; unsupported syntax stays an ambiguity record."""
5271 function = declarator
5272 while function is not None and function.type in {"pointer_declarator", "reference_declarator"}:
5273 function = function.child_by_field_name("declarator") or next(
5274 (n for n in function.named_children if n.type in {
5275 "function_declarator", "pointer_declarator", "reference_declarator",
5276 }), None)
5277 parameters = function.child_by_field_name("parameters") if function is not None else None
5278 zero_args = (parameters is not None
5279 and not any(n.type != "comment" for n in parameters.named_children))
5280 qualified = _cpp_qualified_name(node, name, source)
5281 record: dict = {
5282 "qualified": qualified,
5283 "kind": "definition" if node.type == "function_definition" else "declaration",
5284 "zero_args": zero_args, "signature": None,
5285 "source_location": f"L{declarator.start_point[0] + 1}",
5286 }
5287 type_node = node.child_by_field_name("type")
5288 safe = (zero_args and type_node is not None and not node.has_error
5289 and name.rsplit("::", 1)[-1].isidentifier()
5290 and node.child_by_field_name("default_value") is None
5291 and (node.type != "function_definition" or node.child_by_field_name("body") is not None))
5292 parent = node.parent
5293 while parent is not None:
5294 if ((parent.type.startswith("preproc_") and not _cpp_is_header_guard(parent, source))
5295 or parent.type in {"template_declaration", "function_definition", "lambda_expression"}):
5296 safe = False
5297 parent = parent.parent
5298 if not safe or function is None or parameters is None or function.type != "function_declarator":
5299 return record
5300 suffix = [n for n in function.named_children
5301 if n.start_byte >= parameters.end_byte and n.type != "comment"]
5302 prefix = [n for n in node.named_children if n.end_byte <= declarator.start_byte and n != type_node]
5303 if (any(n.type not in {"type_qualifier", "ref_qualifier", "noexcept"} for n in suffix)
5304 or any(n.type != "type_qualifier" and not (
5305 n.type == "storage_class_specifier"
5306 and _read_text(n, source) in {"static", "inline", "constexpr", "consteval"}
5307 ) for n in prefix)):
5308 return record
5309 record["signature"] = {
5310 "return_type": _read_text(type_node, source),
5311 "return_qualifiers": [_read_text(n, source) for n in prefix if n.type == "type_qualifier"],
5312 "return_declarator": source[declarator.start_byte:function.start_byte].decode(
5313 "utf-8", errors="replace").strip(),
5314 "member_qualifiers": [_read_text(n, source) for n in suffix],
5315 }
5316 return record
5317
5318
5319def _cpp_plain_template_parameters(node, source: bytes) -> list[str]:

Callers 1

walkFunction · 0.85

Calls 3

_read_textFunction · 0.90
_cpp_qualified_nameFunction · 0.85
_cpp_is_header_guardFunction · 0.85

Tested by

no test coverage detected