From eb12ff17f6fc71a8b7c78c91ad46959c2e640555 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sun, 28 May 2023 13:21:49 -0400 Subject: [PATCH] Refactor: move static identity_traits to their own file, simplify field defs DataStaticsFields.cpp used to contain identity_traits specializations for primitive and opaque STL types, as well as macros used for the generated struct field definitions. Only one of these were actually used in any compilation unit, and the identity_traits definitions were hidden behind a guard to prevent them from being compiled at all when building the struct field definitions. Now, the identity_traits specializations live in their own file, DataIdentity.cpp (matching their declarations, which live in DataIdentity.h). This speeds up build times because modifying these specializations no longer requires rebuilding all of the field definitions unnecessarily. --- library/CMakeLists.txt | 11 +++++----- ...DataStaticsFields.cpp => DataIdentity.cpp} | 22 +++---------------- library/include/DataStaticsFields.inc | 15 +++++++++++++ library/modules/Screen.cpp | 3 +-- 4 files changed, 24 insertions(+), 27 deletions(-) rename library/{DataStaticsFields.cpp => DataIdentity.cpp} (74%) create mode 100644 library/include/DataStaticsFields.inc diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 8b1b7f65d..2ea2d830f 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -62,6 +62,7 @@ set(MAIN_SOURCES ColorText.cpp CompilerWorkAround.cpp DataDefs.cpp + DataIdentity.cpp Debug.cpp Error.cpp VTableInterpose.cpp @@ -71,7 +72,6 @@ set(MAIN_SOURCES LuaApi.cpp DataStatics.cpp DataStaticsCtor.cpp - DataStaticsFields.cpp MiscUtils.cpp Types.cpp PluginManager.cpp @@ -186,8 +186,7 @@ foreach(GROUP other a b c d e f g h i j k l m n o p q r s t u v w x y z) set(STATIC_FIELDS_INC_FILENAME "df/static.fields-${GROUP}.inc") endif() file(WRITE ${STATIC_FIELDS_FILENAME}.tmp - "#define STATIC_FIELDS_GROUP\n" - "#include \"../DataStaticsFields.cpp\"\n" + "#include \"DataStaticsFields.inc\"\n" "#include \"${STATIC_FIELDS_INC_FILENAME}\"\n" ) execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different @@ -294,15 +293,15 @@ add_custom_target(generate_headers if(REMOVE_SYMBOLS_FROM_DF_STUBS) if(UNIX) # Don't produce debug info for generated stubs - set_source_files_properties(DataStatics.cpp DataStaticsCtor.cpp DataStaticsFields.cpp ${STATIC_FIELDS_FILES} + set_source_files_properties(DataStatics.cpp DataStaticsCtor.cpp ${STATIC_FIELDS_FILES} PROPERTIES COMPILE_FLAGS "-g0 -O1") else(WIN32) - set_source_files_properties(DataStatics.cpp DataStaticsCtor.cpp DataStaticsFields.cpp ${STATIC_FIELDS_FILES} + set_source_files_properties(DataStatics.cpp DataStaticsCtor.cpp ${STATIC_FIELDS_FILES} PROPERTIES COMPILE_FLAGS "/O1 /bigobj") endif() else() if(WIN32) - set_source_files_properties(DataStatics.cpp DataStaticsCtor.cpp DataStaticsFields.cpp ${STATIC_FIELDS_FILES} + set_source_files_properties(DataStatics.cpp DataStaticsCtor.cpp ${STATIC_FIELDS_FILES} PROPERTIES COMPILE_FLAGS "/Od /bigobj") endif() endif() diff --git a/library/DataStaticsFields.cpp b/library/DataIdentity.cpp similarity index 74% rename from library/DataStaticsFields.cpp rename to library/DataIdentity.cpp index ac2b415eb..f6a1c2de8 100644 --- a/library/DataStaticsFields.cpp +++ b/library/DataIdentity.cpp @@ -1,17 +1,12 @@ #include #include - -#ifndef STATIC_FIELDS_GROUP -#include "DataDefs.h" -#endif +#include +#include +#include #include "DataFuncs.h" -#ifdef __GNUC__ -#pragma GCC diagnostic ignored "-Winvalid-offsetof" -#endif - namespace df { #define NUMBER_IDENTITY_TRAITS(category, type, name) \ category##_identity identity_traits::identity(name); @@ -50,15 +45,4 @@ namespace df { buffer_container_identity buffer_container_identity::base_instance; #endif -#undef NUMBER_IDENTITY_TRAITS -#undef INTEGER_IDENTITY_TRAITS -#undef FLOAT_IDENTITY_TRAITS } - -#define TID(type) (&identity_traits< type >::identity) - -#define FLD(mode, name) struct_field_info::mode, #name, offsetof(CUR_STRUCT, name) -#define GFLD(mode, name) struct_field_info::mode, #name, (size_t)&df::global::name -#define METHOD(mode, name) struct_field_info::mode, #name, 0, wrap_function(&CUR_STRUCT::name) -#define METHOD_N(mode, func, name) struct_field_info::mode, #name, 0, wrap_function(&CUR_STRUCT::func) -#define FLD_END struct_field_info::END diff --git a/library/include/DataStaticsFields.inc b/library/include/DataStaticsFields.inc new file mode 100644 index 000000000..97a036b58 --- /dev/null +++ b/library/include/DataStaticsFields.inc @@ -0,0 +1,15 @@ +#include + +#include "DataFuncs.h" + +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Winvalid-offsetof" +#endif + +#define TID(type) (&identity_traits< type >::identity) + +#define FLD(mode, name) struct_field_info::mode, #name, offsetof(CUR_STRUCT, name) +#define GFLD(mode, name) struct_field_info::mode, #name, (size_t)&df::global::name +#define METHOD(mode, name) struct_field_info::mode, #name, 0, wrap_function(&CUR_STRUCT::name) +#define METHOD_N(mode, func, name) struct_field_info::mode, #name, 0, wrap_function(&CUR_STRUCT::func) +#define FLD_END struct_field_info::END diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp index c7ef88c60..2ee91a089 100644 --- a/library/modules/Screen.cpp +++ b/library/modules/Screen.cpp @@ -1092,8 +1092,7 @@ df::plant *dfhack_lua_viewscreen::getSelectedPlant() return Lua::GetDFObject(Lua::Core::State, -1); } -#define STATIC_FIELDS_GROUP -#include "../DataStaticsFields.cpp" +#include "DataStaticsFields.inc" using df::identity_traits;