Skip to content

Commit f26c2ab

Browse files
committed
style: Preserve indentation inside preprocessor blocks and re-run
1 parent fcf59f3 commit f26c2ab

9 files changed

Lines changed: 49 additions & 34 deletions

File tree

Core/GameEngineDevice/Source/W3DDevice/GameClient/W3DTerrainVisual.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,10 @@ void W3DTerrainVisual::handleSeismicSimulations()
439439

440440
}
441441

442-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
443-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
444-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
445-
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
442+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
443+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
444+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
445+
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
446446
void W3DTerrainVisual::updateSeismicSimulations()
447447
{
448448

Core/Libraries/Source/WWVegas/WWLib/FastAllocator.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,11 @@ WWINLINE void* FastAllocatorGeneral::Realloc(void* pAlloc, unsigned int n){
529529
//
530530

531531
#ifdef _MSC_VER
532-
//VC++ continues to be the one compiler that lacks the ability to compile
533-
//standard C++. So we define a version of the STL allocator specifically
534-
//for VC++, and let other compilers use a standard allocator template.
535-
template <class T>
536-
struct FastSTLAllocator{
532+
//VC++ continues to be the one compiler that lacks the ability to compile
533+
//standard C++. So we define a version of the STL allocator specifically
534+
//for VC++, and let other compilers use a standard allocator template.
535+
template <class T>
536+
struct FastSTLAllocator{
537537
typedef size_t size_type; //basically, "unsigned int"
538538
typedef ptrdiff_t difference_type; //basically, "int"
539539
typedef T* pointer;
@@ -558,14 +558,14 @@ struct FastSTLAllocator{
558558
//the above delallocate() function. So your version of deallocate
559559
//should *not* assume that it will only be given T objects to delete.
560560
char* _Charalloc(size_t n){ return (char*)FastAllocatorGeneral::Get_Allocator()->Alloc(n*sizeof(char)); }
561-
};
561+
};
562562
#else
563-
//This is a C++ language standard allocator. Most C++ compilers after 1999
564-
//other than Microsoft C++ compile this fine. Otherwise. you might be able
565-
//to use the same allocator as VC++ uses above.
566-
template <class T>
567-
class FastSTLAllocator{
568-
public:
563+
//This is a C++ language standard allocator. Most C++ compilers after 1999
564+
//other than Microsoft C++ compile this fine. Otherwise. you might be able
565+
//to use the same allocator as VC++ uses above.
566+
template <class T>
567+
class FastSTLAllocator{
568+
public:
569569
typedef size_t size_type;
570570
typedef ptrdiff_t difference_type;
571571
typedef T* pointer;
@@ -591,7 +591,7 @@ class FastSTLAllocator{
591591
size_type max_size() const { return size_t(-1) / sizeof(T); }
592592
void construct(pointer p, const T& val) { new(p) T(val); }
593593
void destroy(pointer p) { p->~T(); }
594-
};
594+
};
595595
#endif
596596

597597
template<class T>

Core/Libraries/Source/WWVegas/WWLib/lzo_conf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@
110110

111111
/* ptrdiff_t */
112112
#if (UINT_MAX >= 0xffffffffL)
113-
typedef ptrdiff_t lzo_ptrdiff_t;
113+
typedef ptrdiff_t lzo_ptrdiff_t;
114114
#else
115-
typedef long lzo_ptrdiff_t;
115+
typedef long lzo_ptrdiff_t;
116116
#endif
117117

118118

Core/Libraries/Source/WWVegas/WWLib/lzoconf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@
9494

9595
/* Unsigned type with 32 bits or more */
9696
#if (UINT_MAX >= 0xffffffffL)
97-
typedef unsigned int lzo_uint;
98-
typedef int lzo_int;
97+
typedef unsigned int lzo_uint;
98+
typedef int lzo_int;
9999
# define LZO_UINT_MAX UINT_MAX
100100
#elif (ULONG_MAX >= 0xffffffffL)
101-
typedef unsigned long lzo_uint;
102-
typedef long lzo_int;
101+
typedef unsigned long lzo_uint;
102+
typedef long lzo_int;
103103
# define LZO_UINT_MAX ULONG_MAX
104104
#else
105105
# error lzo_uint

Core/Tools/W3DView/W3DViewView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class CW3DViewView : public CView
6363

6464
#ifndef RTS_DEBUG // debug version in W3DViewView.cpp
6565
inline CW3DViewDoc* CW3DViewView::GetDocument()
66-
{ return (CW3DViewDoc*)m_pDocument; }
66+
{ return (CW3DViewDoc*)m_pDocument; }
6767
#endif
6868

6969
/////////////////////////////////////////////////////////////////////////////

Core/Tools/mangler/wlib/threadfac.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@
4545

4646

4747
#ifdef THREADFAC_CODE
48-
// This is the fake thread entry point for functions
48+
// This is the fake thread entry point for functions
4949
#ifdef _WIN32
5050
static unsigned __stdcall threadFuncLauncher(void *temp);
5151
#else // UNIX
5252
static void *threadFuncLauncher(void *temp);
5353
#endif
5454

55-
// Fake entry point for classes
55+
// Fake entry point for classes
5656
#ifdef _WIN32
5757
static unsigned __stdcall threadClassLauncher(void *temp);
5858
#else // UNIX

Core/Tools/matchbot/wlib/threadfac.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@
4545

4646

4747
#ifdef THREADFAC_CODE
48-
// This is the fake thread entry point for functions
48+
// This is the fake thread entry point for functions
4949
#ifdef _WIN32
5050
static unsigned __stdcall threadFuncLauncher(void *temp);
5151
#else // UNIX
5252
static void *threadFuncLauncher(void *temp);
5353
#endif
5454

55-
// Fake entry point for classes
55+
// Fake entry point for classes
5656
#ifdef _WIN32
5757
static unsigned __stdcall threadClassLauncher(void *temp);
5858
#else // UNIX

Dependencies/Utility/Utility/stdint_adapter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
#if defined(USING_STLPORT) || (defined(_MSC_VER) && _MSC_VER < 1300)
2222
/* 7.18.1.4 Integer types capable of holding object pointers */
2323
#ifdef _WIN64
24-
typedef __int64 intptr_t;
25-
typedef unsigned __int64 uintptr_t;
24+
typedef __int64 intptr_t;
25+
typedef unsigned __int64 uintptr_t;
2626
#else
27-
typedef int intptr_t;
28-
typedef unsigned int uintptr_t;
27+
typedef int intptr_t;
28+
typedef unsigned int uintptr_t;
2929
#endif
3030

3131
/* 7.18.1.1 Exact-width integer types */

scripts/cpp/convert_leading_spaces_to_tabs.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def process_file(filepath, dry_run=False, verbose=False):
184184
in_asm_block = False
185185
asm_brace_depth = 0
186186
asm_pending = False
187+
pp_depth = 0
187188

188189
for line_idx, line in enumerate(lines):
189190
# Track block comments manually for reliability
@@ -235,6 +236,13 @@ def process_file(filepath, dry_run=False, verbose=False):
235236

236237
# Preprocessor directives - always column 0
237238
if stripped.startswith('#'):
239+
# Track preprocessor nesting depth
240+
directive = stripped.lstrip('#').lstrip()
241+
if directive.startswith(('if ', 'if\t', 'ifdef ', 'ifdef\t',
242+
'ifndef ', 'ifndef\t')):
243+
pp_depth += 1
244+
elif directive.startswith('endif'):
245+
pp_depth = max(0, pp_depth - 1)
238246
new_lines.append(line)
239247
in_macro_continuation = line_continues_macro
240248
continue
@@ -373,9 +381,16 @@ def process_file(filepath, dry_run=False, verbose=False):
373381
# Sanity check: if the line had significant indentation but we
374382
# computed depth 0, something is likely wrong (parse errors nearby,
375383
# inline assembly corrupting the AST, etc). Skip to be safe.
376-
# Threshold of 4 spaces catches most misparses while allowing
377-
# legitimate depth-0 code with minor (1-3 space) indentation errors.
384+
# Also skip depth-0 lines inside preprocessor blocks — the codebase
385+
# convention is to indent C++ code inside #if/#ifdef blocks, but
386+
# tree-sitter doesn't model preprocessor nesting.
378387
space_count = len(leading_ws)
388+
if depth == 0 and space_count > 0 and pp_depth > 0:
389+
new_lines.append(line)
390+
skipped += 1
391+
if verbose:
392+
print(f" SKIP pp-indent L{line_idx+1}: depth=0 but pp_depth={pp_depth}: {line.rstrip()[:80]}")
393+
continue
379394
if depth == 0 and space_count >= 4:
380395
new_lines.append(line)
381396
skipped += 1

0 commit comments

Comments
 (0)