style: Convert leading spaces to tabs in GeneralsMD Libraries and Tools#2564
style: Convert leading spaces to tabs in GeneralsMD Libraries and Tools#2564bobtista wants to merge 2 commits intoTheSuperHackers:mainfrom
Conversation
|
| Filename | Overview |
|---|---|
| scripts/cpp/convert_leading_spaces_to_tabs.py | New 482-line formatting script using tree-sitter-cpp for C++ AST-guided space-to-tab conversion; PR description says it should not be merged. |
| GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp | Whitespace-only conversion; 11 braceless if bodies in StatDumpClass::dumpStats now indented to the same level as their conditions due to the script's mixed-whitespace fast-path. |
| GeneralsMD/Code/Tools/WorldBuilder/src/mapobjectprops.cpp | Largest file in the PR (2968 line changes); whitespace-only conversion of leading spaces to tabs, no functional or non-whitespace changes. |
| GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/shader.h | Whitespace-only conversion of leading spaces/mixed whitespace to tabs in enum declarations and class body. |
| GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp | 98-line whitespace-only conversion; clean tab alignment across the file. |
| GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp | Whitespace-only conversion; no issues found. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Read C++ file\ncp1252 encoding] --> B[Parse with tree-sitter-cpp\nafter macro preprocessing]
B --> C{Too many\nparse errors?}
C -- Yes --> D[Skip file entirely]
C -- No --> E[Process each line]
E --> F{Line type?}
F -- Block comment --> G[Keep as-is]
F -- Macro continuation --> G
F -- ASM block --> G
F -- Mixed whitespace\ntab_count > 0 --> H[Use tab_count directly\nfast-path]
F -- Pure leading spaces --> I[Query tree-sitter AST\nfor node at column]
I --> J{Parse error\nor continuation?}
J -- Yes --> G
J -- No --> K[Compute depth via\nget_indent_depth]
K --> L{Special node?\naccess specifier\ncase/default\nbrace}
L -- Yes --> M[Adjust depth\nfor convention]
L -- No --> K2[Use computed depth]
M --> N[Write depth × tabs\n+ stripped content]
K2 --> N
H --> N
N --> O[Write converted file\ncp1252 encoding]
style H fill:#f9c,stroke:#c66
style D fill:#fcc,stroke:#c33
Prompt To Fix All With AI
This is a comment left during a code review.
Path: GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp
Line: 210-211
Comment:
**Braceless `if` body indented to same level as condition**
The script's mixed-whitespace fast-path (` \t` → single tab by `tab_count`) set these `fprintf` bodies to the same tab depth as their enclosing `if`, making the braceless body visually indistinguishable from the surrounding scope. 11 `fprintf` calls in `StatDumpClass::dumpStats` are affected (lines 210–211, 224, 226, 228, 237, 250, 262, 285, 287, 307, 309); the most confusing case is the inner block where a depth-2 `if` has a depth-1 body (lines 224, 226, 228).
The body should be indented one level deeper than its condition:
```suggestion
if ( flagSpikes && fps<20.0f )
fprintf( m_fp, " FPS OUT OF TOLERANCE\n" );
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: scripts/cpp/convert_leading_spaces_to_tabs.py
Line: 1
Comment:
**Script not intended to be merged**
The PR description states this file is "included for reference but is not intended to be merged." If that's still the intent, it should be removed from this PR before merging to avoid permanently adding a dev tool to the `scripts/` tree.
How can I resolve this? If you propose a fix, please make it concise.Reviews (6): Last reviewed commit: "style: Convert leading spaces to tabs in..." | Re-trigger Greptile
Skyaero42
left a comment
There was a problem hiding this comment.
Picked out a few things that don't look right. They may appear multiple times in this PR.
|
|
||
| void checkForChangedTextData(); /**< called when we need to update our | ||
| render sentence and update extents */ | ||
| render sentence and update extents */ |
There was a problem hiding this comment.
I checked this on main, and I like it this way more. The goal is to remove leading spaces (convert to semantically the same indentation in tabs) only in this PR - I think aligning multiline things to previous line spots like open parens will be another PR.
|
|
||
| void setRenderObject( RenderObjClass *robj) {assert(m_robj==nullptr); m_robj=robj;} | ||
| void setRenderObjExtent ( Real extent) { m_robjExtent = extent; } | ||
| void setRenderObjExtent ( Real extent) { m_robjExtent = extent; } |
| if ( flagSpikes ) | ||
| { | ||
| if ( Debug_Statistics::Get_Draw_Calls()>2000 ) | ||
| fprintf( m_fp, " DRAWS OUT OF TOLERANCE(2000)\n" ); |
There was a problem hiding this comment.
What do you mean? It's preserving that weird string ...DRAWS OUT OF TOLERANCE(2000)\n" ); if you look at main, it's the same there. If we want to remove the leading spaces maybe do it in another PR?
There was a problem hiding this comment.
Shouldn't fprintf not have another indent because of the if-statement above it?
There was a problem hiding this comment.
Oh you mean the conditional without braces - can fix
| if ( ! isVisible ) | ||
| continue; | ||
| if ( ! isVisible ) | ||
| continue; |
There was a problem hiding this comment.
Yeah, I had to fix these conditionals without braces in another branch too, I'll do that now
| if ( ! TheInGameUI ) | ||
| return; | ||
| if ( ! TheInGameUI ) | ||
| return; |
aea6efc to
9d36619
Compare
Summary
git diff -wis empty)Access specifiers (
public:/private:/protected:) are placed at the classbrace level, matching the existing codebase convention.
Script
The formatting script is included in the PR for reference but is not intended
to be merged — it shows how the changes were generated.
See
scripts/cpp/convert_leading_spaces_to_tabs.pyfor details.Part 4 of 4 — GeneralsMD/Code/Libraries/ and GeneralsMD/Code/Tools/ (161 files).
See also: #2561, #2562, #2563.