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.
develop
lethosor 2023-05-28 13:21:49 -04:00
parent d0250ae426
commit eb12ff17f6
No known key found for this signature in database
GPG Key ID: 76A269552F4F58C1
4 changed files with 24 additions and 27 deletions

@ -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()

@ -1,17 +1,12 @@
#include <stddef.h>
#include <fstream>
#ifndef STATIC_FIELDS_GROUP
#include "DataDefs.h"
#endif
#include <mutex>
#include <string>
#include <vector>
#include "DataFuncs.h"
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
#endif
namespace df {
#define NUMBER_IDENTITY_TRAITS(category, type, name) \
category##_identity<type> identity_traits<type>::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

@ -0,0 +1,15 @@
#include <stddef.h>
#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

@ -1092,8 +1092,7 @@ df::plant *dfhack_lua_viewscreen::getSelectedPlant()
return Lua::GetDFObject<df::plant>(Lua::Core::State, -1);
}
#define STATIC_FIELDS_GROUP
#include "../DataStaticsFields.cpp"
#include "DataStaticsFields.inc"
using df::identity_traits;