Repository navigation
Conversation
With -k, spaces and tabs are written out as they are in the input, and each comment becomes spaces of the same length, so a token keeps the column it has in the source file.
There was a problem hiding this comment.
🟡 Changes recommended
The -k comment-padding path can write past its allocation, while multiline comments and non-invoked function-like macros still shift token columns.
3 open issues
What changed in this PR
Adds the upstream mcpp -k option to preserve horizontal whitespace, supporting accurate source-column spans in the Slice compiler.
Changes:
- Registers and documents
-k. - Adds whitespace-preservation state and updates it during directive processing.
- Preserves spaces and tabs and pads block comments based on their length.
| File | Description |
|---|---|
system.c |
Parses -k and adds usage text. |
support.c |
Preserves horizontal whitespace and calculates comment padding. |
mcpp_main.c |
Initializes and enables whitespace-preservation mode. |
internal.H |
Declares the new option and shared state. |
directive.c |
Updates preservation state after directives. |
Review effort: Balanced
With -k, a comment that follows a truncated comment and a token on the same line had its padding length computed as a negative number, which became a huge count.
pepone
left a comment
There was a problem hiding this comment.
🤖 Claude (Opus 5.5):
-
With
-k -M, a function-like macro call that spans lines and has tokens after it setssrc_col, but only the output path inmcpp_mainclears it, so every later line skipsdirective(). With the input below,mcpp -k -Mprintsdep2.o: dep2.icewithoutdep.h, while-Malone lists it. Please clearsrc_colnext towrong_line = FALSEin theno_outputbranch (mcpp_main.c:511). I checked that this fixes-k -Mand leaves the-kand-C -koutput unchanged.#define F(x) x F( 1) z #include "dep.h"
With -k and -M, a function-like macro call that spans lines and has tokens after it sets 'src_col', and every later directive is then skipped, so the dependency line misses the files included after it.
|
Fixed in 0133d03: 🤖 Addressed by Claude Code |
This reverts commit 0133d03.
|
Reverted in ef1e5eb; my earlier comment said this was fixed. |
There was a problem hiding this comment.
I approve of this PR because it brings our fork closer to what the other MCPPs do.
And I would rather be faithful to the original, than go around fixing minor bugs.
But, -k is not sufficient to the goal of preserving column counts, at least not with the logic of this fork. I didn't check everything, but at the very least, MCPP expands/moves macros and comments in ways that -k can't handle.
So even with this PR, we won't always have accurate column counts in our Slice files.
|
🤖 Claude (Opus 5.5): Agreed: Ice links the Homebrew mcpp on macOS and the distribution's |
|
Agreed, |


Add back the
-koption of mcpp 2.7.2, so that a token in the preprocessed output keeps the column it has in the source file. The source spans in zeroc-ice/ice#7007 need this to be exact.The option was removed in 42be792 (April 2015), which cut this fork down to what Ice used at the time. The code added here is the original 2.7.2 code, from the import in e6e749e. Homebrew and the Linux distributions package the 2.7.2 release from SourceForge, Homebrew with a few of our patches, so their mcpp still accepts
-k.-kagain, and list it in the usage text.-kis given, and replace each comment with spaces of the same length (parse_lineandread_a_commentinsupport.c).-kisn't given.