Skip to content

Commit d8807a1

Browse files
authored
Merge pull request godotengine#1734 from Repiteo/style/pragma-once
Replace header guards style with `#pragma once`
2 parents a5db125 + c963321 commit d8807a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+138
-418
lines changed

.git-blame-ignore-revs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file contains a list of Git commit hashes that should be hidden from the
2+
# regular Git history. Typically, this includes commits involving mass auto-formatting
3+
# or other normalizations. Commit hashes *must* use the full 40-character notation.
4+
# To apply the ignore list in your local Git client, you must run:
5+
#
6+
# git config blame.ignoreRevsFile .git-blame-ignore-revs
7+
#
8+
# This file is automatically used by GitHub.com's blame view.
9+
10+
# Style: Replace header guards with `#pragma once`
11+
7056c996dd43ae1aa466c94d95cc2fe63853d8a9

binding_generator.py

Lines changed: 13 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ def generate_mod_version(argcount, const=False, returns=False):
5151
def generate_wrappers(target):
5252
max_versions = 12
5353

54-
txt = """
55-
#ifndef GDEXTENSION_WRAPPERS_GEN_H
56-
#define GDEXTENSION_WRAPPERS_GEN_H
57-
58-
"""
54+
txt = "#pragma once"
5955

6056
for i in range(max_versions + 1):
6157
txt += "\n/* Module Wrapper " + str(i) + " Arguments */\n"
@@ -64,8 +60,6 @@ def generate_wrappers(target):
6460
txt += generate_mod_version(i, True, False)
6561
txt += generate_mod_version(i, True, True)
6662

67-
txt += "\n#endif\n"
68-
6963
with open(target, "w", encoding="utf-8") as f:
7064
f.write(txt)
7165

@@ -187,8 +181,7 @@ def generate_virtuals(target):
187181
max_versions = 12
188182

189183
txt = """/* THIS FILE IS GENERATED DO NOT EDIT */
190-
#ifndef GDEXTENSION_GDVIRTUAL_GEN_H
191-
#define GDEXTENSION_GDVIRTUAL_GEN_H
184+
#pragma once
192185
193186
"""
194187

@@ -203,8 +196,6 @@ def generate_virtuals(target):
203196
txt += generate_virtual_version(i, True, False, True)
204197
txt += generate_virtual_version(i, True, True, True)
205198

206-
txt += "#endif // GDEXTENSION_GDVIRTUAL_GEN_H\n"
207-
208199
with open(target, "w", encoding="utf-8") as f:
209200
f.write(txt)
210201

@@ -364,11 +355,8 @@ def generate_builtin_bindings(api, output_dir, build_config):
364355
variant_size_source = []
365356
add_header("variant_size.hpp", variant_size_source)
366357

367-
header_guard = "GODOT_CPP_VARIANT_SIZE_HPP"
368-
variant_size_source.append(f"#ifndef {header_guard}")
369-
variant_size_source.append(f"#define {header_guard}")
358+
variant_size_source.append("#pragma once")
370359
variant_size_source.append(f'#define GODOT_CPP_VARIANT_SIZE {builtin_sizes["Variant"]}')
371-
variant_size_source.append(f"#endif // ! {header_guard}")
372360

373361
variant_size_file.write("\n".join(variant_size_source))
374362

@@ -448,8 +436,7 @@ def generate_builtin_bindings(api, output_dir, build_config):
448436
builtin_header = []
449437
add_header("builtin_types.hpp", builtin_header)
450438

451-
builtin_header.append("#ifndef GODOT_CPP_BUILTIN_TYPES_HPP")
452-
builtin_header.append("#define GODOT_CPP_BUILTIN_TYPES_HPP")
439+
builtin_header.append("#pragma once")
453440

454441
builtin_header.append("")
455442

@@ -464,8 +451,6 @@ def generate_builtin_bindings(api, output_dir, build_config):
464451

465452
builtin_header.append("")
466453

467-
builtin_header.append("#endif // ! GODOT_CPP_BUILTIN_TYPES_HPP")
468-
469454
builtin_header_file.write("\n".join(builtin_header))
470455

471456
# Create a header with bindings for builtin types.
@@ -474,8 +459,7 @@ def generate_builtin_bindings(api, output_dir, build_config):
474459
builtin_binds = []
475460
add_header("builtin_binds.hpp", builtin_binds)
476461

477-
builtin_binds.append("#ifndef GODOT_CPP_BUILTIN_BINDS_HPP")
478-
builtin_binds.append("#define GODOT_CPP_BUILTIN_BINDS_HPP")
462+
builtin_binds.append("#pragma once")
479463
builtin_binds.append("")
480464
builtin_binds.append("#include <godot_cpp/variant/builtin_types.hpp>")
481465
builtin_binds.append("")
@@ -487,7 +471,6 @@ def generate_builtin_bindings(api, output_dir, build_config):
487471
builtin_binds.append(f"VARIANT_ENUM_CAST({builtin_api['name']}::{enum_api['name']});")
488472

489473
builtin_binds.append("")
490-
builtin_binds.append("#endif // ! GODOT_CPP_BUILTIN_BINDS_HPP")
491474

492475
builtin_binds_file.write("\n".join(builtin_binds))
493476

@@ -503,9 +486,7 @@ def generate_builtin_class_vararg_method_implements_header(builtin_classes):
503486

504487
add_header("builtin_vararg_methods.hpp", result)
505488

506-
header_guard = "GODOT_CPP_BUILTIN_VARARG_METHODS_HPP"
507-
result.append(f"#ifndef {header_guard}")
508-
result.append(f"#define {header_guard}")
489+
result.append("#pragma once")
509490
result.append("")
510491
for builtin_api in builtin_classes:
511492
if "methods" not in builtin_api:
@@ -520,8 +501,6 @@ def generate_builtin_class_vararg_method_implements_header(builtin_classes):
520501
)
521502
result.append("")
522503

523-
result.append(f"#endif // ! {header_guard}")
524-
525504
return "\n".join(result)
526505

527506

@@ -531,12 +510,9 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
531510
class_name = builtin_api["name"]
532511
snake_class_name = camel_to_snake(class_name).upper()
533512

534-
header_guard = f"GODOT_CPP_{snake_class_name}_HPP"
535-
536513
add_header(f"{snake_class_name.lower()}.hpp", result)
537514

538-
result.append(f"#ifndef {header_guard}")
539-
result.append(f"#define {header_guard}")
515+
result.append("#pragma once")
540516

541517
result.append("")
542518
result.append("#include <godot_cpp/core/defs.hpp>")
@@ -965,8 +941,6 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
965941
result.append("")
966942
result.append("} // namespace godot")
967943

968-
result.append("")
969-
result.append(f"#endif // ! {header_guard}")
970944
result.append("")
971945

972946
return "\n".join(result)
@@ -1498,9 +1472,7 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
14981472
result = []
14991473
add_header(f"{snake_struct_name}.hpp", result)
15001474

1501-
header_guard = f"GODOT_CPP_{snake_struct_name.upper()}_HPP"
1502-
result.append(f"#ifndef {header_guard}")
1503-
result.append(f"#define {header_guard}")
1475+
result.append("#pragma once")
15041476

15051477
used_classes = []
15061478
expanded_format = native_struct["format"].replace("(", " ").replace(")", ";").replace(",", ";")
@@ -1540,7 +1512,6 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
15401512
result.append("")
15411513
result.append("} // namespace godot")
15421514
result.append("")
1543-
result.append(f"#endif // ! {header_guard}")
15441515

15451516
with header_filename.open("w+", encoding="utf-8") as header_file:
15461517
header_file.write("\n".join(result))
@@ -1556,11 +1527,7 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
15561527

15571528
add_header(f"{snake_class_name.lower()}.hpp", result)
15581529

1559-
header_guard = f"GODOT_CPP_{snake_class_name}_HPP"
1560-
1561-
result.append(f"#ifndef {header_guard}")
1562-
result.append(f"#define {header_guard}")
1563-
1530+
result.append("#pragma once")
15641531
result.append("")
15651532

15661533
if len(fully_used_classes) > 0:
@@ -1849,7 +1816,6 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
18491816
result.append("\t")
18501817
result.append("")
18511818

1852-
result.append(f"#endif // ! {header_guard}")
18531819
result.append("")
18541820

18551821
return "\n".join(result)
@@ -2051,9 +2017,7 @@ def generate_global_constants(api, output_dir):
20512017

20522018
header_filename = include_gen_folder / "global_constants.hpp"
20532019

2054-
header_guard = "GODOT_CPP_GLOBAL_CONSTANTS_HPP"
2055-
header.append(f"#ifndef {header_guard}")
2056-
header.append(f"#define {header_guard}")
2020+
header.append("#pragma once")
20572021
header.append("")
20582022
header.append("#include <cstdint>")
20592023
header.append("")
@@ -2083,7 +2047,6 @@ def generate_global_constants(api, output_dir):
20832047
header.append("} // namespace godot")
20842048

20852049
header.append("")
2086-
header.append(f"#endif // ! {header_guard}")
20872050

20882051
with header_filename.open("w+", encoding="utf-8") as header_file:
20892052
header_file.write("\n".join(header))
@@ -2099,9 +2062,7 @@ def generate_version_header(api, output_dir):
20992062

21002063
header_file_path = include_gen_folder / header_filename
21012064

2102-
header_guard = "GODOT_CPP_VERSION_HPP"
2103-
header.append(f"#ifndef {header_guard}")
2104-
header.append(f"#define {header_guard}")
2065+
header.append("#pragma once")
21052066
header.append("")
21062067

21072068
header.append(f"#define GODOT_VERSION_MAJOR {api['header']['version_major']}")
@@ -2110,8 +2071,6 @@ def generate_version_header(api, output_dir):
21102071
header.append(f"#define GODOT_VERSION_STATUS \"{api['header']['version_status']}\"")
21112072
header.append(f"#define GODOT_VERSION_BUILD \"{api['header']['version_build']}\"")
21122073

2113-
header.append("")
2114-
header.append(f"#endif // {header_guard}")
21152074
header.append("")
21162075

21172076
with header_file_path.open("w+", encoding="utf-8") as header_file:
@@ -2132,9 +2091,7 @@ def generate_global_constant_binds(api, output_dir):
21322091

21332092
header_filename = include_gen_folder / "global_constants_binds.hpp"
21342093

2135-
header_guard = "GODOT_CPP_GLOBAL_CONSTANTS_BINDS_HPP"
2136-
header.append(f"#ifndef {header_guard}")
2137-
header.append(f"#define {header_guard}")
2094+
header.append("#pragma once")
21382095
header.append("")
21392096
header.append("#include <godot_cpp/classes/global_constants.hpp>")
21402097
header.append("")
@@ -2153,8 +2110,6 @@ def generate_global_constant_binds(api, output_dir):
21532110

21542111
header.append("")
21552112

2156-
header.append(f"#endif // ! {header_guard}")
2157-
21582113
with header_filename.open("w+", encoding="utf-8") as header_file:
21592114
header_file.write("\n".join(header))
21602115

@@ -2173,9 +2128,7 @@ def generate_utility_functions(api, output_dir):
21732128

21742129
header_filename = include_gen_folder / "utility_functions.hpp"
21752130

2176-
header_guard = "GODOT_CPP_UTILITY_FUNCTIONS_HPP"
2177-
header.append(f"#ifndef {header_guard}")
2178-
header.append(f"#define {header_guard}")
2131+
header.append("#pragma once")
21792132
header.append("")
21802133
header.append("#include <godot_cpp/variant/builtin_types.hpp>")
21812134
header.append("#include <godot_cpp/variant/variant.hpp>")
@@ -2214,7 +2167,6 @@ def generate_utility_functions(api, output_dir):
22142167
header.append("")
22152168
header.append("} // namespace godot")
22162169
header.append("")
2217-
header.append(f"#endif // ! {header_guard}")
22182170

22192171
with header_filename.open("w+", encoding="utf-8") as header_file:
22202172
header_file.write("\n".join(header))

include/godot_cpp/classes/editor_plugin_registration.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31-
#ifndef GODOT_EDITOR_PLUGIN_REGISTRATION_HPP
32-
#define GODOT_EDITOR_PLUGIN_REGISTRATION_HPP
31+
#pragma once
3332

3433
#include <godot_cpp/templates/vector.hpp>
3534

@@ -58,5 +57,3 @@ class EditorPlugins {
5857
};
5958

6059
} // namespace godot
61-
62-
#endif // GODOT_EDITOR_PLUGIN_REGISTRATION_HPP

include/godot_cpp/classes/ref.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31-
#ifndef GODOT_REF_HPP
32-
#define GODOT_REF_HPP
31+
#pragma once
3332

3433
#include <godot_cpp/core/defs.hpp>
3534

@@ -284,5 +283,3 @@ struct GetTypeInfo<const Ref<T> &, typename EnableIf<TypeInherits<RefCounted, T>
284283
};
285284

286285
} // namespace godot
287-
288-
#endif // GODOT_REF_HPP

include/godot_cpp/classes/wrapped.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31-
#ifndef GODOT_WRAPPED_HPP
32-
#define GODOT_WRAPPED_HPP
31+
#pragma once
3332

3433
#include <godot_cpp/core/memory.hpp>
3534

@@ -511,5 +510,3 @@ public:
511510
#define GDVIRTUAL_BIND(m_name, ...) ::godot::ClassDB::add_virtual_method(get_class_static(), _gdvirtual_##m_name##_get_method_info(), ::godot::snarray(__VA_ARGS__));
512511
#define GDVIRTUAL_IS_OVERRIDDEN(m_name) _gdvirtual_##m_name##_overridden()
513512
#define GDVIRTUAL_IS_OVERRIDDEN_PTR(m_obj, m_name) m_obj->_gdvirtual_##m_name##_overridden()
514-
515-
#endif // GODOT_WRAPPED_HPP

include/godot_cpp/core/binder_common.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31-
#ifndef GODOT_BINDER_COMMON_HPP
32-
#define GODOT_BINDER_COMMON_HPP
31+
#pragma once
3332

3433
#include <gdextension_interface.h>
3534

@@ -692,5 +691,3 @@ void call_with_ptr_args_static_method_ret(R (*p_method)(P...), const GDExtension
692691

693692
#include <godot_cpp/classes/global_constants_binds.hpp>
694693
#include <godot_cpp/variant/builtin_binds.hpp>
695-
696-
#endif // GODOT_BINDER_COMMON_HPP

include/godot_cpp/core/builtin_ptrcall.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31-
#ifndef GODOT_BUILTIN_PTRCALL_HPP
32-
#define GODOT_BUILTIN_PTRCALL_HPP
31+
#pragma once
3332

3433
#include <gdextension_interface.h>
3534
#include <godot_cpp/core/object.hpp>
@@ -88,5 +87,3 @@ T _call_builtin_ptr_getter(const GDExtensionPtrGetter getter, GDExtensionConstTy
8887
} // namespace internal
8988

9089
} // namespace godot
91-
92-
#endif // GODOT_BUILTIN_PTRCALL_HPP

include/godot_cpp/core/class_db.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31-
#ifndef GODOT_CLASS_DB_HPP
32-
#define GODOT_CLASS_DB_HPP
31+
#pragma once
3332

3433
#include <gdextension_interface.h>
3534

@@ -370,5 +369,3 @@ MethodBind *ClassDB::bind_vararg_method(uint32_t p_flags, StringName p_name, M p
370369
} // namespace godot
371370

372371
CLASSDB_SINGLETON_VARIANT_CAST;
373-
374-
#endif // GODOT_CLASS_DB_HPP

include/godot_cpp/core/defs.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31-
#ifndef GODOT_DEFS_HPP
32-
#define GODOT_DEFS_HPP
31+
#pragma once
3332

3433
#include <cstddef>
3534
#include <cstdint>
@@ -130,5 +129,3 @@ struct BuildIndexSequence<0, Is...> : IndexSequence<Is...> {};
130129
// To maintain compatibility an alias is defined outside the namespace.
131130
// Consider it deprecated.
132131
using real_t = godot::real_t;
133-
134-
#endif // GODOT_DEFS_HPP

include/godot_cpp/core/engine_ptrcall.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2929
/**************************************************************************/
3030

31-
#ifndef GODOT_ENGINE_PTRCALL_HPP
32-
#define GODOT_ENGINE_PTRCALL_HPP
31+
#pragma once
3332

3433
#include <gdextension_interface.h>
3534

@@ -93,5 +92,3 @@ void _call_utility_no_ret(const GDExtensionPtrUtilityFunction func, const Args &
9392
} // namespace internal
9493

9594
} // namespace godot
96-
97-
#endif // GODOT_ENGINE_PTRCALL_HPP

0 commit comments

Comments
 (0)