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

Function _cpp_is_header_guard

graphify/extractors/engine.py:5223–5238  ·  view source on GitHub ↗

Recognize only a whole-file #ifndef NAME / #define NAME wrapper.

(node, source: bytes)

Source from the content-addressed store, hash-verified

5221
5222
5223def _cpp_is_header_guard(node, source: bytes) -> bool:
5224 """Recognize only a whole-file #ifndef NAME / #define NAME wrapper."""
5225 if (node.type != "preproc_ifdef" or node.parent is None
5226 or node.parent.type != "translation_unit" or node.children[0].type != "#ifndef"):
5227 return False
5228 siblings = [n for n in node.parent.named_children if n.type != "comment"]
5229 contents = [n for n in node.named_children if n.type != "comment"]
5230 if (siblings != [node] or len(contents) < 2 or contents[1].type != "preproc_def"
5231 or any(n.type in {"preproc_else", "preproc_elif", "preproc_elifdef"} for n in contents)):
5232 return False
5233 name = node.child_by_field_name("name")
5234 define = contents[1].child_by_field_name("name")
5235 if name is None or define is None or _read_text(name, source) != _read_text(define, source):
5236 return False
5237 return not any(line.replace(" ", "").replace("\t", "").startswith("#undef")
5238 for line in _read_text(node, source).splitlines())
5239
5240
5241def _cpp_lookup_scope(node, source: bytes) -> str:

Callers 4

_import_cFunction · 0.90
_cpp_member_recordFunction · 0.85
_cpp_resolution_factsFunction · 0.85
walkFunction · 0.85

Calls 1

_read_textFunction · 0.90

Tested by

no test coverage detected