Fix comment to be after extern (C):#312
Open
davispuh wants to merge 1 commit into
Open
Conversation
Currently code like this ```c #define G1 #ifdef G1 // Guard1 #define A 1 #else #define A 2 #endif #ifdef G2 // Guard2 #define B 3 #else #define B 4 #endif ``` Produces: ```d extern (C): // Guard1 enum A = 1; // Guard2 enum B = 4; ``` Notice how `Guard1` comment is in same line as `extern (C):` which looks wrong. This commit fixes this issue so that it's on a new line like `Guard2`.
There was a problem hiding this comment.
Pull request overview
This PR fixes comment placement during translation so that comments from taken preprocessor branches (e.g., #ifdef G1 // Guard1) are emitted on their own line(s) instead of being appended inline to the generated extern (C): line.
Changes:
- Add a new
lastContentLinetracker to distinguish “latest visited source line” from “latest line that actually emitted output content”. - Update comment emission logic to use
lastContentLinefor determining when a comment should be inline vs. standalone, preventingextern (C): // Guard1. - Add a regression unit test covering the
#ifdef-branch comment placement case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/unit/CommentUnitTests.d | Adds a regression test ensuring taken-branch comments don’t join the extern (C): line. |
| dstep/translator/Output.d | Tracks last emitted-content line and uses it to decide inline vs. standalone comment formatting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Currently code like this
Produces:
Notice how
Guard1comment is in same line asextern (C):which looks wrong and differs fromGuard2case.This PR fixes this issue so that it's on a new line like
Guard2so result will be: