Skip to content

style: Convert leading spaces to tabs in GeneralsMD Libraries and Tools#2564

Open
bobtista wants to merge 2 commits intoTheSuperHackers:mainfrom
bobtista:bobtista/feat/access-spec-indent-generalsmd-rest
Open

style: Convert leading spaces to tabs in GeneralsMD Libraries and Tools#2564
bobtista wants to merge 2 commits intoTheSuperHackers:mainfrom
bobtista:bobtista/feat/access-spec-indent-generalsmd-rest

Conversation

@bobtista
Copy link
Copy Markdown

@bobtista bobtista commented Apr 9, 2026

Summary

  • Convert leading spaces/mixed whitespace to tabs, including access specifier indentation
  • All changes are whitespace-only (git diff -w is empty)
  • Uses tree-sitter-cpp for accurate C++ parsing with macro preprocessing

Access specifiers (public:/private:/protected:) are placed at the class
brace 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.py for details.

Part 4 of 4 — GeneralsMD/Code/Libraries/ and GeneralsMD/Code/Tools/ (161 files).
See also: #2561, #2562, #2563.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 9, 2026

Greptile Summary

This PR (part 4 of 4) converts leading spaces/mixed whitespace to tabs across 158 C++ files in GeneralsMD/Code/Libraries/ and GeneralsMD/Code/Tools/, plus a new Python formatting script. Confirmed git diff -w is empty — all C++ changes are purely whitespace-only and introduce no functional differences.

  • In W3DDisplay.cpp, the script's mixed-whitespace fast-path (tab_count shortcut) produces 11 fprintf calls whose indentation is now at the same level as (or shallower than) their enclosing braceless if conditions — the only indentation regression in the diff.
  • The script scripts/cpp/convert_leading_spaces_to_tabs.py is added to the repo, but the PR description notes it is "not intended to be merged."

Confidence Score: 5/5

Safe to merge — all C++ changes are confirmed whitespace-only; no functional regressions introduced.

All remaining findings are P2: one localised indentation regression in W3DDisplay.cpp (style only, no behavioural change) and the unintended inclusion of the script file. Neither blocks correctness or build.

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp (braceless if-body indentation regression) and scripts/cpp/convert_leading_spaces_to_tabs.py (not intended to be merged per PR description).

Important Files Changed

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
Loading
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

Copy link
Copy Markdown

@Skyaero42 Skyaero42 left a comment

Choose a reason for hiding this comment

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

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 */
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This doesn't look right

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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; }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This doesn't look right

if ( flagSpikes )
{
if ( Debug_Statistics::Get_Draw_Calls()>2000 )
fprintf( m_fp, " DRAWS OUT OF TOLERANCE(2000)\n" );
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This doesn't look right

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shouldn't fprintf not have another indent because of the if-statement above it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oh you mean the conditional without braces - can fix

if ( ! isVisible )
continue;
if ( ! isVisible )
continue;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This doesn't look right

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah, I had to fix these conditionals without braces in another branch too, I'll do that now

if ( ! TheInGameUI )
return;
if ( ! TheInGameUI )
return;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Doesn't look right

@bobtista bobtista force-pushed the bobtista/feat/access-spec-indent-generalsmd-rest branch from aea6efc to 9d36619 Compare April 15, 2026 16:48
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.

2 participants