Improve readability: add and use a script to add comments after #else and #endif - #11191
Open
lyakh wants to merge 2 commits into
Open
Improve readability: add and use a script to add comments after #else and #endif#11191lyakh wants to merge 2 commits into
#else and #endif#11191lyakh wants to merge 2 commits into
Conversation
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>
lyakh
requested review from
LaurentiuM1234,
bardliao,
dbaluta,
kv2019i,
lbetlej,
lgirdwood,
marcinszkudlinski,
mmaka1,
pblaszko,
plbossart and
tmleman
as code owners
September 11, 2026 10:25
ujfalusi
approved these changes
Sep 11, 2026
Contributor
There was a problem hiding this comment.
🟡 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
#elseand#endifdirectives. - 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_stateresetsin_string/in_charfor 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/#endifthat 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 laterwrite_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 (andappend_comment()can leave the original\rbefore 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 returnsCONFIG_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 examplesrc/ipc/ipc4/handler-user.c:881). Pass the directive kind through and prefix!forifndef.
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.
PR 11191: test resultsRun date: 2026-09-11 12:39 UTC Tested commit: d5b40286515b88c3bd3f8ed49b739a3e799c6f52 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
made with AI