Fix clang template warnings
Fix:
MODIFY
CMakeLists.txt
CMakeLists.txt
@@ -74,6 +74,7 @@ add_library(lcf
src/writer_lcf.h
src/writer_xml.cpp
src/writer_xml.h
+ src/generated/fwd_struct_impl.h
src/generated/ldb_actor.cpp
src/generated/ldb_animation.cpp
src/generated/ldb_animationcelldata.cpp

MODIFY
Makefile.am
Makefile.am
@@ -141,6 +141,7 @@ pkginclude_HEADERS = \
src/scope_guard.h \
src/writer_lcf.h \
src/writer_xml.h \
+ src/generated/fwd_struct_impl.h \
src/generated/ldb_chunks.h \
src/generated/ldb_terrain_flags.h \
src/generated/ldb_trooppagecondition_flags.h \

MODIFY
generator/generate.py
generator/generate.py
@@ -354,6 +354,17 @@ def generate():
type=filetype
))
+ structs_flat = []
+ for filetype, struct in structs.items():
+ for elem in struct:
+ structs_flat.append(elem)
+
+ filepath = os.path.join(tmp_dir, 'fwd_struct_impl.h')
+ with open(filepath, 'w') as f:
+ f.write(fwd_tmpl.render(
+ structs=sorted([x.name for x in structs_flat])
+ ))
+
for filetype, structlist in structs.items():
for struct in structlist:
filename = struct.name.lower()
@@ -413,7 +424,7 @@ def main(argv):
os.mkdir(dest_dir)
global structs, sfields, enums, flags, setup, constants, headers
- global chunk_tmpl, lcf_struct_tmpl, rpg_header_tmpl, rpg_source_tmpl, flags_tmpl, enums_tmpl
+ global chunk_tmpl, lcf_struct_tmpl, rpg_header_tmpl, rpg_source_tmpl, flags_tmpl, enums_tmpl, fwd_tmpl
structs = get_structs('structs.csv','structs_easyrpg.csv')
sfields = get_fields('fields.csv','fields_easyrpg.csv')
@@ -453,6 +464,7 @@ def main(argv):
rpg_source_tmpl = env.get_template('rpg_source.tmpl', globals=globals)
flags_tmpl = env.get_template('flag_reader.tmpl', globals=globals)
enums_tmpl = env.get_template('rpg_enums.tmpl', globals=globals)
+ fwd_tmpl = env.get_template('fwd_header.tmpl', globals=globals)
generate()

ADD
generator/templates/fwd_header.tmpl
+{% include "copyright.tmpl" %}
+// MSVC incorrectly treats these declarations as definitions and fails.
+#ifndef _MSC_VER
+{% for struct in structs -%}
+template <>
+const char* const Struct<RPG::{{ struct }}>::name;
+template <>
+Field<RPG::{{ struct }}> const* Struct<RPG::{{ struct }}>::fields[];
+
+{% endfor -%}
+#endif

ADD
src/generated/fwd_struct_impl.h
src/generated/fwd_struct_impl.h
Binary files /dev/null and b/src/generated/fwd_struct_impl.h differ

MODIFY
src/reader_struct_impl.h
src/reader_struct_impl.h
@@ -271,3 +271,4 @@ void Struct<S>::BeginXml(std::vector<S>& obj, XmlReader& stream) {
stream.SetHandler(new StructVectorXmlHandler<S>(obj));
}
+#include "fwd_struct_impl.h"

Fix clang template warnings

Fix: #221