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

Function _cpp_resolution_facts

graphify/extractors/engine.py:5491–5588  ·  view source on GitHub ↗

Persist lexical type declarations; unsupported aliases still shadow outer names.

(root, source: bytes)

Source from the content-addressed store, hash-verified

5489
5490
5491def _cpp_resolution_facts(root, source: bytes) -> tuple[list[dict], dict[str, int], dict[str, str]]:
5492 """Persist lexical type declarations; unsupported aliases still shadow outer names."""
5493 bindings, includes, include_paths = [], {}, {}
5494 pending = [root]
5495 while pending:
5496 node = pending.pop()
5497 pending.extend(reversed(node.named_children))
5498 if node.type == "preproc_include":
5499 parent = node.parent
5500 while parent is not None and parent.type not in {
5501 "namespace_definition", "class_specifier", "struct_specifier", "union_specifier",
5502 "function_definition", "compound_statement",
5503 }:
5504 parent = parent.parent
5505 if parent is not None:
5506 continue
5507 line = str(node.start_point[0] + 1)
5508 includes[line] = node.start_byte
5509 path = node.child_by_field_name("path")
5510 if path is not None and path.type == "string_literal":
5511 include_paths[line] = _read_text(path, source)[1:-1]
5512 if node.type not in {"alias_declaration", "type_definition", "class_specifier", "struct_specifier", "union_specifier",
5513 "using_declaration", "namespace_definition", "namespace_alias_definition"}:
5514 continue
5515 scope = _cpp_lookup_scope(node, source)
5516 parent = node.parent
5517 block = None
5518 dependent = False
5519 conditional = False
5520 while parent is not None:
5521 if parent.type == "template_declaration":
5522 dependent = True
5523 if parent.type == "namespace_definition" and parent.child_by_field_name("name") is None:
5524 dependent = True
5525 if parent.type in {"preproc_if", "preproc_ifdef", "preproc_else", "preproc_elif"}:
5526 guard = _cpp_is_header_guard(parent, source)
5527 conditional = conditional or not guard
5528 if block is None and parent.type in {
5529 "compound_statement", "for_statement", "for_range_loop", "if_statement",
5530 "switch_statement", "catch_clause", "lambda_expression",
5531 }:
5532 block = parent
5533 parent = parent.parent
5534 alias = node.type in {"alias_declaration", "type_definition", "namespace_alias_definition"}
5535 directive = False
5536 names = [(node.child_by_field_name("name"), "")]
5537 if node.type == "namespace_definition" and names[0][0] is not None:
5538 parts = _read_text(names[0][0], source).split("::")
5539 names = [("::".join(parts[:index + 1]), "") for index in range(len(parts))]
5540 if node.type == "using_declaration":
5541 using = re.fullmatch(r"using\s+(namespace\s+)?((?:::)?[A-Za-z_]\w*(?:::[A-Za-z_]\w*)*)\s*;",
5542 _read_text(node, source))
5543 if using is None:
5544 continue
5545 directive = bool(using[1])
5546 names = [("*" if directive else using[2].rsplit("::", 1)[-1], using[2])]
5547 alias = not directive
5548 if alias and node.type != "namespace_alias_definition":

Callers 1

_extract_genericFunction · 0.85

Calls 5

_read_textFunction · 0.90
_cpp_lookup_scopeFunction · 0.85
_cpp_is_header_guardFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected