Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
pragma_once_to_guards Namespace Reference

Functions

 guard_name (path)
 
 headers ()
 
 convert (text, guard)
 
 wrap_unguarded (text, guard)
 
 main ()
 

Variables

str SRC = 'src'
 
dict SKIP_DIRS = {'external'}
 
 PRAGMA_RE = re.compile(r'^[ \t]*#[ \t]*pragma[ \t]+once[ \t]*\r?\n', re.M)
 
 GUARD_RE
 
dict XMACRO_HEADERS
 
str MODELINE = '// clang-format off\n// modelines:'
 

Detailed Description

Replace `#pragma once` with explicit include guards across src/.

`#pragma once` silently makes a cyclic include graph compile: a header that is
re-entered mid-definition is simply skipped, leaving the first inclusion to finish
with whatever it had. Explicit guards behave the same way at the preprocessor level,
but they are greppable, portable, and -- crucially -- they make the anti-pattern
visible in review instead of hiding it.

Guard names are derived from the path relative to src/, e.g.
  src/develop/masks/masks_history.h  ->  DT_DEVELOP_MASKS_MASKS_HISTORY_H

Usage:
  python3 tools/pragma_once_to_guards.py --check        # list what would change, touch nothing
  python3 tools/pragma_once_to_guards.py                # rewrite in place
  python3 tools/pragma_once_to_guards.py --add-missing  # also guard headers that have NO guard
  python3 tools/pragma_once_to_guards.py --verify       # exit 1 if any #pragma once came back

Function Documentation

◆ convert()

pragma_once_to_guards.convert (   text,
  guard 
)

Definition at line 60 of file pragma_once_to_guards.py.

Referenced by main().

◆ guard_name()

pragma_once_to_guards.guard_name (   path)

Definition at line 47 of file pragma_once_to_guards.py.

Referenced by main().

◆ headers()

pragma_once_to_guards.headers ( )

Definition at line 52 of file pragma_once_to_guards.py.

Referenced by main().

◆ main()

pragma_once_to_guards.main ( void  )

Definition at line 106 of file pragma_once_to_guards.py.

References convert(), guard_name(), headers(), main(), and wrap_unguarded().

Referenced by main().

◆ wrap_unguarded()

pragma_once_to_guards.wrap_unguarded (   text,
  guard 
)
Guard a header that has neither #pragma once nor an #ifndef/#define pair.

The opening goes after the leading licence block comment (so the guard wraps the
actual content, not the whole file including its header comment); the #endif goes
just above the trailing modeline block, mirroring convert().

Definition at line 82 of file pragma_once_to_guards.py.

Referenced by main().

Variable Documentation

◆ GUARD_RE

pragma_once_to_guards.GUARD_RE
Initial value:
1= re.compile(r'^[ \t]*#[ \t]*ifndef[ \t]+[A-Za-z_][A-Za-z0-9_]*[ \t]*\r?\n'
2 r'[ \t]*#[ \t]*define[ \t]+', re.M)

Definition at line 26 of file pragma_once_to_guards.py.

◆ MODELINE

str pragma_once_to_guards.MODELINE = '// clang-format off\n// modelines:'

Definition at line 44 of file pragma_once_to_guards.py.

◆ PRAGMA_RE

pragma_once_to_guards.PRAGMA_RE = re.compile(r'^[ \t]*#[ \t]*pragma[ \t]+once[ \t]*\r?\n', re.M)

Definition at line 25 of file pragma_once_to_guards.py.

◆ SKIP_DIRS

dict pragma_once_to_guards.SKIP_DIRS = {'external'}

Definition at line 24 of file pragma_once_to_guards.py.

◆ SRC

str pragma_once_to_guards.SRC = 'src'

Definition at line 23 of file pragma_once_to_guards.py.

◆ XMACRO_HEADERS

dict pragma_once_to_guards.XMACRO_HEADERS
Initial value:
1= {
2 'src/common/module_api.h',
3 'src/views/view_api.h',
4 'src/libs/lib_api.h',
5 'src/imageio/format/imageio_format_api.h',
6 'src/imageio/storage/imageio_storage_api.h',
7}

Definition at line 32 of file pragma_once_to_guards.py.