Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace header guards style with #pragma once #1734

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file contains a list of Git commit hashes that should be hidden from the
# regular Git history. Typically, this includes commits involving mass auto-formatting
# or other normalizations. Commit hashes *must* use the full 40-character notation.
# To apply the ignore list in your local Git client, you must run:
#
# git config blame.ignoreRevsFile .git-blame-ignore-revs
#
# This file is automatically used by GitHub.com's blame view.

# Style: Replace header guards with `#pragma once`
7056c996dd43ae1aa466c94d95cc2fe63853d8a9
74 changes: 13 additions & 61 deletions binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ def generate_mod_version(argcount, const=False, returns=False):
def generate_wrappers(target):
max_versions = 12

txt = """
#ifndef GDEXTENSION_WRAPPERS_GEN_H
#define GDEXTENSION_WRAPPERS_GEN_H

"""
txt = "#pragma once"

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

txt += "\n#endif\n"

with open(target, "w", encoding="utf-8") as f:
f.write(txt)

Expand Down Expand Up @@ -187,8 +181,7 @@ def generate_virtuals(target):
max_versions = 12

txt = """/* THIS FILE IS GENERATED DO NOT EDIT */
#ifndef GDEXTENSION_GDVIRTUAL_GEN_H
#define GDEXTENSION_GDVIRTUAL_GEN_H
#pragma once

"""

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

txt += "#endif // GDEXTENSION_GDVIRTUAL_GEN_H\n"

with open(target, "w", encoding="utf-8") as f:
f.write(txt)

Expand Down Expand Up @@ -359,11 +350,8 @@ def generate_builtin_bindings(api, output_dir, build_config):
variant_size_source = []
add_header("variant_size.hpp", variant_size_source)

header_guard = "GODOT_CPP_VARIANT_SIZE_HPP"
variant_size_source.append(f"#ifndef {header_guard}")
variant_size_source.append(f"#define {header_guard}")
variant_size_source.append("#pragma once")
variant_size_source.append(f'#define GODOT_CPP_VARIANT_SIZE {builtin_sizes["Variant"]}')
variant_size_source.append(f"#endif // ! {header_guard}")

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

Expand Down Expand Up @@ -443,8 +431,7 @@ def generate_builtin_bindings(api, output_dir, build_config):
builtin_header = []
add_header("builtin_types.hpp", builtin_header)

builtin_header.append("#ifndef GODOT_CPP_BUILTIN_TYPES_HPP")
builtin_header.append("#define GODOT_CPP_BUILTIN_TYPES_HPP")
builtin_header.append("#pragma once")

builtin_header.append("")

Expand All @@ -459,8 +446,6 @@ def generate_builtin_bindings(api, output_dir, build_config):

builtin_header.append("")

builtin_header.append("#endif // ! GODOT_CPP_BUILTIN_TYPES_HPP")

builtin_header_file.write("\n".join(builtin_header))

# Create a header with bindings for builtin types.
Expand All @@ -469,8 +454,7 @@ def generate_builtin_bindings(api, output_dir, build_config):
builtin_binds = []
add_header("builtin_binds.hpp", builtin_binds)

builtin_binds.append("#ifndef GODOT_CPP_BUILTIN_BINDS_HPP")
builtin_binds.append("#define GODOT_CPP_BUILTIN_BINDS_HPP")
builtin_binds.append("#pragma once")
builtin_binds.append("")
builtin_binds.append("#include <godot_cpp/variant/builtin_types.hpp>")
builtin_binds.append("")
Expand All @@ -482,7 +466,6 @@ def generate_builtin_bindings(api, output_dir, build_config):
builtin_binds.append(f"VARIANT_ENUM_CAST({builtin_api['name']}::{enum_api['name']});")

builtin_binds.append("")
builtin_binds.append("#endif // ! GODOT_CPP_BUILTIN_BINDS_HPP")

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

Expand All @@ -498,9 +481,7 @@ def generate_builtin_class_vararg_method_implements_header(builtin_classes):

add_header("builtin_vararg_methods.hpp", result)

header_guard = "GODOT_CPP_BUILTIN_VARARG_METHODS_HPP"
result.append(f"#ifndef {header_guard}")
result.append(f"#define {header_guard}")
result.append("#pragma once")
result.append("")
for builtin_api in builtin_classes:
if "methods" not in builtin_api:
Expand All @@ -515,8 +496,6 @@ def generate_builtin_class_vararg_method_implements_header(builtin_classes):
)
result.append("")

result.append(f"#endif // ! {header_guard}")

return "\n".join(result)


Expand All @@ -526,12 +505,9 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
class_name = builtin_api["name"]
snake_class_name = camel_to_snake(class_name).upper()

header_guard = f"GODOT_CPP_{snake_class_name}_HPP"

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

result.append(f"#ifndef {header_guard}")
result.append(f"#define {header_guard}")
result.append("#pragma once")

result.append("")
result.append("#include <godot_cpp/core/defs.hpp>")
Expand Down Expand Up @@ -960,8 +936,6 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
result.append("")
result.append("} // namespace godot")

result.append("")
result.append(f"#endif // ! {header_guard}")
result.append("")

return "\n".join(result)
Expand Down Expand Up @@ -1493,9 +1467,7 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
result = []
add_header(f"{snake_struct_name}.hpp", result)

header_guard = f"GODOT_CPP_{snake_struct_name.upper()}_HPP"
result.append(f"#ifndef {header_guard}")
result.append(f"#define {header_guard}")
result.append("#pragma once")

used_classes = []
expanded_format = native_struct["format"].replace("(", " ").replace(")", ";").replace(",", ";")
Expand Down Expand Up @@ -1535,7 +1507,6 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node):
result.append("")
result.append("} // namespace godot")
result.append("")
result.append(f"#endif // ! {header_guard}")

with header_filename.open("w+", encoding="utf-8") as header_file:
header_file.write("\n".join(result))
Expand All @@ -1551,11 +1522,7 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us

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

header_guard = f"GODOT_CPP_{snake_class_name}_HPP"

result.append(f"#ifndef {header_guard}")
result.append(f"#define {header_guard}")

result.append("#pragma once")
result.append("")

if len(fully_used_classes) > 0:
Expand Down Expand Up @@ -1844,7 +1811,6 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
result.append("\t")
result.append("")

result.append(f"#endif // ! {header_guard}")
result.append("")

return "\n".join(result)
Expand Down Expand Up @@ -2046,9 +2012,7 @@ def generate_global_constants(api, output_dir):

header_filename = include_gen_folder / "global_constants.hpp"

header_guard = "GODOT_CPP_GLOBAL_CONSTANTS_HPP"
header.append(f"#ifndef {header_guard}")
header.append(f"#define {header_guard}")
header.append("#pragma once")
header.append("")
header.append("#include <cstdint>")
header.append("")
Expand Down Expand Up @@ -2078,7 +2042,6 @@ def generate_global_constants(api, output_dir):
header.append("} // namespace godot")

header.append("")
header.append(f"#endif // ! {header_guard}")

with header_filename.open("w+", encoding="utf-8") as header_file:
header_file.write("\n".join(header))
Expand All @@ -2094,9 +2057,7 @@ def generate_version_header(api, output_dir):

header_file_path = include_gen_folder / header_filename

header_guard = "GODOT_CPP_VERSION_HPP"
header.append(f"#ifndef {header_guard}")
header.append(f"#define {header_guard}")
header.append("#pragma once")
header.append("")

header.append(f"#define GODOT_VERSION_MAJOR {api['header']['version_major']}")
Expand All @@ -2105,8 +2066,6 @@ def generate_version_header(api, output_dir):
header.append(f"#define GODOT_VERSION_STATUS \"{api['header']['version_status']}\"")
header.append(f"#define GODOT_VERSION_BUILD \"{api['header']['version_build']}\"")

header.append("")
header.append(f"#endif // {header_guard}")
header.append("")

with header_file_path.open("w+", encoding="utf-8") as header_file:
Expand All @@ -2127,9 +2086,7 @@ def generate_global_constant_binds(api, output_dir):

header_filename = include_gen_folder / "global_constants_binds.hpp"

header_guard = "GODOT_CPP_GLOBAL_CONSTANTS_BINDS_HPP"
header.append(f"#ifndef {header_guard}")
header.append(f"#define {header_guard}")
header.append("#pragma once")
header.append("")
header.append("#include <godot_cpp/classes/global_constants.hpp>")
header.append("")
Expand All @@ -2148,8 +2105,6 @@ def generate_global_constant_binds(api, output_dir):

header.append("")

header.append(f"#endif // ! {header_guard}")

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

Expand All @@ -2168,9 +2123,7 @@ def generate_utility_functions(api, output_dir):

header_filename = include_gen_folder / "utility_functions.hpp"

header_guard = "GODOT_CPP_UTILITY_FUNCTIONS_HPP"
header.append(f"#ifndef {header_guard}")
header.append(f"#define {header_guard}")
header.append("#pragma once")
header.append("")
header.append("#include <godot_cpp/variant/builtin_types.hpp>")
header.append("#include <godot_cpp/variant/variant.hpp>")
Expand Down Expand Up @@ -2209,7 +2162,6 @@ def generate_utility_functions(api, output_dir):
header.append("")
header.append("} // namespace godot")
header.append("")
header.append(f"#endif // ! {header_guard}")

with header_filename.open("w+", encoding="utf-8") as header_file:
header_file.write("\n".join(header))
Expand Down
5 changes: 1 addition & 4 deletions include/godot_cpp/classes/editor_plugin_registration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef GODOT_EDITOR_PLUGIN_REGISTRATION_HPP
#define GODOT_EDITOR_PLUGIN_REGISTRATION_HPP
#pragma once

#include <godot_cpp/templates/vector.hpp>

Expand Down Expand Up @@ -58,5 +57,3 @@ class EditorPlugins {
};

} // namespace godot

#endif // GODOT_EDITOR_PLUGIN_REGISTRATION_HPP
5 changes: 1 addition & 4 deletions include/godot_cpp/classes/ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef GODOT_REF_HPP
#define GODOT_REF_HPP
#pragma once

#include <godot_cpp/core/defs.hpp>

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

} // namespace godot

#endif // GODOT_REF_HPP
5 changes: 1 addition & 4 deletions include/godot_cpp/classes/wrapped.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef GODOT_WRAPPED_HPP
#define GODOT_WRAPPED_HPP
#pragma once

#include <godot_cpp/core/memory.hpp>

Expand Down Expand Up @@ -511,5 +510,3 @@ public:
#define GDVIRTUAL_BIND(m_name, ...) ::godot::ClassDB::add_virtual_method(get_class_static(), _gdvirtual_##m_name##_get_method_info(), ::godot::snarray(__VA_ARGS__));
#define GDVIRTUAL_IS_OVERRIDDEN(m_name) _gdvirtual_##m_name##_overridden()
#define GDVIRTUAL_IS_OVERRIDDEN_PTR(m_obj, m_name) m_obj->_gdvirtual_##m_name##_overridden()

#endif // GODOT_WRAPPED_HPP
5 changes: 1 addition & 4 deletions include/godot_cpp/core/binder_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef GODOT_BINDER_COMMON_HPP
#define GODOT_BINDER_COMMON_HPP
#pragma once

#include <gdextension_interface.h>

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

#include <godot_cpp/classes/global_constants_binds.hpp>
#include <godot_cpp/variant/builtin_binds.hpp>

#endif // GODOT_BINDER_COMMON_HPP
5 changes: 1 addition & 4 deletions include/godot_cpp/core/builtin_ptrcall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef GODOT_BUILTIN_PTRCALL_HPP
#define GODOT_BUILTIN_PTRCALL_HPP
#pragma once

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

} // namespace godot

#endif // GODOT_BUILTIN_PTRCALL_HPP
5 changes: 1 addition & 4 deletions include/godot_cpp/core/class_db.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef GODOT_CLASS_DB_HPP
#define GODOT_CLASS_DB_HPP
#pragma once

#include <gdextension_interface.h>

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

CLASSDB_SINGLETON_VARIANT_CAST;

#endif // GODOT_CLASS_DB_HPP
5 changes: 1 addition & 4 deletions include/godot_cpp/core/defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef GODOT_DEFS_HPP
#define GODOT_DEFS_HPP
#pragma once

#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -130,5 +129,3 @@ struct BuildIndexSequence<0, Is...> : IndexSequence<Is...> {};
// To maintain compatibility an alias is defined outside the namespace.
// Consider it deprecated.
using real_t = godot::real_t;

#endif // GODOT_DEFS_HPP
5 changes: 1 addition & 4 deletions include/godot_cpp/core/engine_ptrcall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef GODOT_ENGINE_PTRCALL_HPP
#define GODOT_ENGINE_PTRCALL_HPP
#pragma once

#include <gdextension_interface.h>

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

} // namespace godot

#endif // GODOT_ENGINE_PTRCALL_HPP
Loading