Skip to content

Improve readability: add and use a script to add comments after #else and #endif - #11191

Open
lyakh wants to merge 2 commits into
thesofproject:mainfrom
lyakh:proproc
Open

Improve readability: add and use a script to add comments after #else and #endif#11191
lyakh wants to merge 2 commits into
thesofproject:mainfrom
lyakh:proproc

Conversation

@lyakh

@lyakh lyakh commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

made with AI

Add a script to add missing comments after #endif and #else.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Use the add-endif-comments.py script to add missing comments to ipc,
library_manager and schedule directories under src/.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The annotation script has unresolved literal-scanning and #ifndef labeling issues.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This pull request adds a Python utility to annotate long preprocessor conditionals across scheduler, library-manager, and IPC sources.

Changes:

  • Adds scripts/add-endif-comments.py.
  • Adds comments to selected #else and #endif directives.
  • Improves conditional-code readability.

The utility needs fixes for continued/raw literals and #ifndef annotation handling.

File summaries
File Reviewed change
src/schedule/zephyr_ll.c Annotates scheduler conditionals
src/schedule/zephyr_dp_schedule_application.c Annotates userspace guards
src/schedule/zephyr_domain.c Annotates cross-core guards
src/schedule/ll_schedule_xtos.c Annotates scheduler feature guards
src/library_manager/llext_manager.c Annotates memory/userspace guards
src/ipc/ipc4/notification.c Annotates userspace guards
src/ipc/ipc4/logging.c Annotates logging guards
src/ipc/ipc4/helper.c Annotates IPC feature guards
src/ipc/ipc4/handler-user.c Annotates IPC configuration guards
src/ipc/ipc4/handler-kernel.c Annotates kernel IPC guards
src/ipc/ipc4/dai.c Annotates ACE version guards
src/ipc/ipc3/host-page-table.c Annotates driver selection guards
src/ipc/ipc3/helper.c Annotates library guards
src/ipc/ipc3/handler.c Annotates IPC feature guards
src/ipc/ipc3/dai.c Annotates platform guards
src/ipc/ipc-common.c Annotates IPC initialization guards
scripts/add-endif-comments.py Adds the conditional-commenting utility
Review details

Suppressed comments (3)

scripts/add-endif-comments.py:55

  • compute_comment_state resets in_string/in_char for every physical line and does not account for backslash-newline splicing. A valid continued string literal (or continued // comment) can therefore contain a physical line beginning with #if/#endif that this scanner treats as a real directive, causing it to pair or annotate the wrong conditional block. Track lexical state across escaped lines, or tokenize logical preprocessor lines, before matching directives.
        in_string = in_char = False
        while i < length:
            if in_block_comment:

scripts/add-endif-comments.py:182

  • read_text() uses universal-newline translation, and the later write_text() writes the normalized text back with \n. Therefore, running this on a CRLF source file that has any matching block rewrites every line ending (and append_comment() can leave the original \r before the inserted comment), even though only a directive should change. Preserve the original newline convention when reading/writing and when appending the comment.
    original_text = path.read_text(encoding='utf-8', errors='surrogateescape')
    lines = original_text.splitlines(keepends=True)

scripts/add-endif-comments.py:93

  • For an opening #ifndef CONFIG_FOO, this returns CONFIG_FOO, so the generated closing tag becomes #endif /* CONFIG_FOO */ and loses the negation. That is misleading for the exact readability goal; the existing convention uses #endif /* !CONFIG_FOO */ (for example src/ipc/ipc4/handler-user.c:881). Pass the directive kind through and prefix ! for ifndef.
def format_condition(text):
    """Normalize a raw #if/#ifdef/#ifndef argument into comment text."""
    text = re.sub(r'/\*.*?\*/', '', text)
    text = re.sub(r'//.*$', '', text)
    return re.sub(r'\s+', ' ', text).strip()
  • Files reviewed: 17/17 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread scripts/add-endif-comments.py
@intel-sofci

Copy link
Copy Markdown

PR 11191: test results

Run date: 2026-09-11 12:39 UTC

Tested commit: d5b40286515b88c3bd3f8ed49b739a3e799c6f52

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants