callsites.py¶
clew/query/callsites.py
A function's calls in source order, each with the control-flow frames that enclose it.
call_sequence
list[CallSite] | None clew.query.callsites.call_sequence(DbSource db, Path|str repo_root, str name, str|None qualified=None, list[int]|None rowids=None)
A function's call sites in source order, each with its enclosing frames.
Source · 45 lines
def call_sequence(
db: DbSource,
repo_root: Path | str,
name: str,
qualified: str | None = None,
rowids: list[int] | None = None,
) -> list[CallSite] | None:
"""NONE IS NOT EMPTY. "This function calls nothing" is a measured `[]`; an unknown function, a
declaration with no body, or a file the parser cannot read is None — the sequence was never
looked at, and the caller must not draw an empty lane for it.
@brief Ordered call sites with frames.
@return Sites or None.
@version 2
"""
with connect(db) as conn:
located = _body_of(conn, name, qualified, rowids)
if located is None:
return None
rel, start, end, nested = located
parsed = _parse(Path(repo_root), rel)
if parsed is None:
return None
tree, src = parsed
from ..call_edges import _ast_harvest_calls
lines = sorted(
{
(str(site[0]), int(site[1]))
for site in _ast_harvest_calls(tree, src)
if start <= int(site[1]) <= end and not _in_any(int(site[1]), nested)
},
key=lambda s: (s[1], s[0]),
)
frames = _frames(tree.root_node, start, end)
return [
CallSite(
callee=callee,
line=line,
frames=tuple(f for f in frames if f.line <= line <= f.end_line),
)
for callee, line in lines
]