kerneldoc.py

clew/kerneldoc.py

kernel-doc comments, read into their own `kerneldoc` layer (S6; index only).

ingest_kerneldoc

int clew.kerneldoc.ingest_kerneldoc(Path db_path, Path repo_root, IndexCache|None cache=None)

Record every indexed C file's kernel-doc blocks.

clew/kerneldoc.py:200

Show on the map →

Called by _build_stages, run_real_stages

Tested by

1 teststest_the_layer_records_c_files_only_and_exists_when_empty

Calls _row, kerneldoc_of, within_repo

Source · 33 lines
def ingest_kerneldoc(db_path: Path, repo_root: Path, cache: IndexCache | None = None) -> int:
    """THE TABLE IS ALWAYS CREATED, empty in a tree with no kernel-doc.

    @brief Build the kernel-doc layer.
    @return Row count.
    """
    from .filedocs import _indexed_files

    conn = sqlite3.connect(str(db_path))
    try:
        conn.executescript(_DDL)
        conn.execute("DELETE FROM kerneldoc")
        resolved: dict[str, str] = {}
        rows = []
        for rel in _indexed_files(conn):
            if not rel.endswith(_SUFFIXES):
                continue
            if (
                within_repo(
                    repo_root / rel, repo_root, setting=f"kernel-doc of {rel}", memo=resolved
                )
                is None
            ):
                continue
            rows += [_row(rel, b) for b in kerneldoc_of(cache, repo_root, rel)]
        conn.executemany(_INSERT, rows)
        conn.commit()
    finally:
        conn.close()
    logger.info("kerneldoc: %d block(s)", len(rows))
    return len(rows)

Activity · 17 steps
lines 206–206from .filedocs import _indexed_fileslines 208–208conn = sqlite3.connect(str(db_path))lines 209–209trylines 210–210conn.executescript(_DDL)lines 211–211conn.execute("DELETE FROM kerneldoc")lines 212–212resolved: dict[str, str] = {}lines 213–213rows = []lines 214–214◇ for rel in _indexed_files(conn)lines 215–215◇ if not rel.endswith(_SUFFIXES)lines 216–216continuelines 217–221◇ if (lines 223–223continuelines 224–224rows += [_row(rel, b) for b in kerneldoc_of(cache, repo_root, rel)]lines 225–225conn.executemany(_INSERT, rows)lines 226–226conn.commit()lines 229–229logger.info("kerneldoc: %d block(s)", len(rows))lines 230–230return len(rows)

Requirements

REQ-DDB-INDEX-009

parse_kerneldoc

list[dict] clew.kerneldoc.parse_kerneldoc(str text)

The kernel-doc blocks of one C source text.

clew/kerneldoc.py:81

Source · 16 lines
def parse_kerneldoc(text: str) -> list[dict]:
    """@brief Read every kernel-doc block. @return Blocks."""
    out = []
    for match in _BLOCK.finditer(text):
        body = [re.sub(r"^\s*\* ?", "", raw).rstrip() for raw in match.group(1).splitlines()]
        while body and not body[0].strip():
            body.pop(0)
        if not body or _DOXYGEN.search(match.group(1)):
            continue
        block = _block(body)
        if block is not None:
            block["line"] = text.count("\n", 0, match.start()) + 1
            out.append(block)
    return out

Activity · 12 steps
lines 83–83out = []lines 84–84◇ for match in _BLOCK.finditer(text)lines 85–85body = [re.sub(r"^\s*\* ?", "", raw).rstrip() for raw in match.group(1).splitlines()]lines 86–86◇ while body and not body[0].strip()lines 87–87body.pop(0)lines 88–88◇ if not body or _DOXYGEN.search(match.group(1))lines 89–89continuelines 90–90block = _block(body)lines 91–91◇ if block is not Nonelines 92–92block["line"] = text.count("\n", 0, match.start()) + 1lines 93–93out.append(block)lines 94–94return out

Requirements

REQ-DDB-INDEX-009

refresh_kerneldoc

None clew.kerneldoc.refresh_kerneldoc(sqlite3.Connection conn, Path repo_root, str rel, IndexCache cache)

Rewrite one edited file's kernel-doc rows (the fast tier).

clew/kerneldoc.py:268

Show on the map →

Called by refresh_text_layers

Calls _row, kerneldoc_of

Source · 10 lines
def refresh_kerneldoc(
    conn: sqlite3.Connection, repo_root: Path, rel: str, cache: IndexCache
) -> None:
    """@brief The same rows `ingest_kerneldoc` writes, for one file. @return None."""
    if not rel.endswith(_SUFFIXES):
        return
    if conn.execute("SELECT 1 FROM sqlite_master WHERE name = 'kerneldoc'").fetchone() is None:
        return
    conn.execute("DELETE FROM kerneldoc WHERE file_path = ?", (rel,))
    conn.executemany(_INSERT, [_row(rel, b) for b in kerneldoc_of(cache, repo_root, rel)])

1 more lines, not shown

Activity · 6 steps
lines 272–272◇ if not rel.endswith(_SUFFIXES)lines 273–273returnlines 274–274◇ if conn.execute("SELECT 1 FROM sqlite_master WHERE name = 'kerneldoc'").fetchone() is Nonelines 275–275returnlines 276–276conn.execute("DELETE FROM kerneldoc WHERE file_path = ?", (rel,))lines 277–277conn.executemany(_INSERT, [_row(rel, b) for b in kerneldoc_of(cache, repo_root, rel)])

Requirements

REQ-DDB-INDEX-006