Skip to content

Commit 74289d7

Browse files
authored
chore: remove deprecated api usage (#219)
1 parent aa0998f commit 74289d7

File tree

6 files changed

+144
-160
lines changed

6 files changed

+144
-160
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ bazel_dep(name = "rules_cc", version = "0.0.9")
88
bazel_dep(name = "bazel_skylib", version = "1.6.1")
99
bazel_dep(name = "ecsact_runtime", version = "0.6.9")
1010
bazel_dep(name = "rules_ecsact", version = "0.5.8")
11-
bazel_dep(name = "ecsact_codegen", version = "0.4.1")
11+
bazel_dep(name = "ecsact_codegen", version = "0.4.2")
1212

1313
bazel_dep(name = "ecsact_cli", version = "0.3.17", dev_dependency = True)
1414
bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2", dev_dependency = True)

cpp_header_codegen/cpp_header_codegen.cc

Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ static void write_constexpr_id(
1616
T id,
1717
std::string_view indentation
1818
) {
19-
ctx.write(
19+
ctx.writef(
20+
"{}static constexpr auto id = static_cast<{}>({});\n",
2021
indentation,
21-
"static constexpr auto id = static_cast<",
2222
id_type_name,
23-
">(",
24-
static_cast<int32_t>(id),
25-
");\n"
23+
static_cast<int32_t>(id)
2624
);
2725
}
2826

@@ -84,30 +82,32 @@ static void write_fields(
8482
auto field_type = ecsact_meta_field_type(compo_id, field_id);
8583
auto field_name = ecsact_meta_field_name(compo_id, field_id);
8684

87-
ctx.write(indentation);
88-
ctx.write(cpp_field_type_name(field_type));
89-
ctx.write(" "s, field_name);
85+
ctx.writef(
86+
"{}{} {}",
87+
indentation,
88+
cpp_field_type_name(field_type),
89+
field_name
90+
);
9091

9192
if(field_type.length > 1) {
92-
ctx.write("[", field_type.length, "]");
93+
ctx.writef("[{}]", field_type.length);
9394
}
94-
ctx.write(";\n");
95+
ctx.writef(";\n");
9596
}
9697

97-
ctx.write(
98+
ctx.writef(
99+
"{}auto operator<=>(const {}&) const = default;\n",
98100
indentation,
99-
"auto operator<=>(const ",
100-
cpp_identifier(full_name),
101-
"&) const = default;\n"
101+
cpp_identifier(full_name)
102102
);
103103
}
104104

105105
static void write_system_impl_decl(
106106
ecsact::codegen_plugin_context& ctx,
107107
std::string_view indentation
108108
) {
109-
ctx.write(indentation, "struct context;\n");
110-
ctx.write(indentation, "static void impl(context&);\n");
109+
ctx.writef("{}struct context;\n", indentation);
110+
ctx.writef("{}static void impl(context&);\n", indentation);
111111
}
112112

113113
static void write_system_struct(
@@ -121,18 +121,18 @@ static void write_system_struct(
121121

122122
std::string sys_name = ecsact_meta_system_name(sys_id);
123123
if(!sys_name.empty()) {
124-
ctx.write(indentation, "struct "s, sys_name, " {\n"s);
124+
ctx.writef("{}struct {} {{\n", indentation, sys_name);
125125
write_constexpr_id(ctx, "ecsact_system_id", sys_id, indentation + "\t");
126126
for(auto child_system_id : get_child_system_ids(sys_id)) {
127127
write_system_struct(ctx, child_system_id, indentation + "\t");
128128
}
129129
write_system_impl_decl(ctx, indentation + "\t");
130-
ctx.write(indentation, "};\n"s);
130+
ctx.writef("{}}};\n", indentation);
131131
} else {
132-
ctx.write(indentation, "struct "s, anonymous_system_name(sys_id), " {\n");
132+
ctx.writef("{}struct {} {{\n", indentation, anonymous_system_name(sys_id));
133133
write_constexpr_id(ctx, "ecsact_system_id", sys_id, indentation + "\t");
134-
ctx.write(indentation, "\tstruct context;\n");
135-
ctx.write(indentation, "};\n"s);
134+
ctx.writef("{}\tstruct context;\n", indentation);
135+
ctx.writef("{}}};\n", indentation);
136136

137137
for(auto child_system_id : get_child_system_ids(sys_id)) {
138138
write_system_struct(ctx, child_system_id, indentation);
@@ -175,74 +175,71 @@ void ecsact_codegen_plugin(
175175

176176
ecsact::codegen_plugin_context ctx{package_id, 0, write_fn, report_fn};
177177

178-
ctx.write(GENERATED_FILE_DISCLAIMER);
179-
ctx.write("#pragma once\n\n");
178+
ctx.writef(GENERATED_FILE_DISCLAIMER);
179+
ctx.writef("#pragma once\n\n");
180180

181-
ctx.write("#include <cstdint>\n");
182-
ctx.write("#include <compare>\n");
183-
ctx.write("#include \"ecsact/runtime/common.h\"\n");
184-
ctx.write("\n");
181+
ctx.writef("#include <cstdint>\n");
182+
ctx.writef("#include <compare>\n");
183+
ctx.writef("#include \"ecsact/runtime/common.h\"\n");
184+
ctx.writef("\n");
185185

186186
const auto namespace_str =
187187
cpp_identifier(ecsact_meta_package_name(ctx.package_id));
188188

189-
ctx.write("namespace "s, namespace_str, " {\n\n"s);
189+
ctx.writef("namespace {} {{\n\n", namespace_str);
190190

191191
for(auto enum_id : get_enum_ids(ctx.package_id)) {
192-
ctx.write("enum class "s, ecsact_meta_enum_name(enum_id), "{");
192+
ctx.writef("enum class {} {{", ecsact_meta_enum_name(enum_id));
193193
++ctx.indentation;
194-
ctx.write("\n");
194+
ctx.writef("\n");
195195

196196
for(auto& enum_value : get_enum_values(enum_id)) {
197-
ctx.write(enum_value.name, " = ", enum_value.value, ",\n");
197+
ctx.writef("{} = {},\n", enum_value.name, enum_value.value);
198198
}
199-
ctx.write("};");
199+
ctx.writef("}};");
200200
--ctx.indentation;
201201
}
202202

203203
for(auto comp_id : get_component_ids(ctx.package_id)) {
204204
auto compo_id = ecsact_id_cast<ecsact_composite_id>(comp_id);
205-
ctx.write("struct "s, ecsact_meta_component_name(comp_id), " {\n"s);
206-
ctx.write("\tstatic constexpr bool transient = false;\n");
207-
ctx.write(
208-
"\tstatic constexpr bool has_assoc_fields = ",
209-
has_assoc_fields(comp_id) ? "true" : "false",
210-
";\n"
205+
ctx.writef("struct {} {{\n", ecsact_meta_component_name(comp_id));
206+
ctx.writef("\tstatic constexpr bool transient = false;\n");
207+
ctx.writef(
208+
"\tstatic constexpr bool has_assoc_fields = {};\n",
209+
has_assoc_fields(comp_id) ? "true" : "false"
211210
);
212211
write_constexpr_id(ctx, "ecsact_component_id", comp_id, "\t");
213212
write_fields(ctx, compo_id, "\t"s);
214-
ctx.write("};\n"s);
213+
ctx.writef("}};\n");
215214
}
216215

217216
for(auto comp_id : get_transient_ids(ctx.package_id)) {
218217
auto compo_id = ecsact_id_cast<ecsact_composite_id>(comp_id);
219-
ctx.write("struct "s, ecsact_meta_transient_name(comp_id), " {\n"s);
220-
ctx.write("\tstatic constexpr bool transient = true;\n");
221-
ctx.write(
222-
"\tstatic constexpr bool has_assoc_fields = ",
223-
has_assoc_fields(comp_id) ? "true" : "false",
224-
";\n"
218+
ctx.writef("struct {} {{\n", ecsact_meta_transient_name(comp_id));
219+
ctx.writef("\tstatic constexpr bool transient = true;\n");
220+
ctx.writef(
221+
"\tstatic constexpr bool has_assoc_fields = {};\n",
222+
has_assoc_fields(comp_id) ? "true" : "false"
225223
);
226224
write_constexpr_id(ctx, "ecsact_transient_id", comp_id, "\t");
227225
write_fields(ctx, compo_id, "\t"s);
228-
ctx.write("};\n"s);
226+
ctx.writef("}};\n");
229227
}
230228

231229
for(auto action_id : get_action_ids(ctx.package_id)) {
232230
auto compo_id = ecsact_id_cast<ecsact_composite_id>(action_id);
233-
ctx.write("struct "s, ecsact_meta_action_name(action_id), " {\n"s);
234-
ctx.write(
235-
"\tstatic constexpr bool has_assoc_fields = ",
236-
has_assoc_fields(action_id) ? "true" : "false",
237-
";\n"
231+
ctx.writef("struct {} {{\n", ecsact_meta_action_name(action_id));
232+
ctx.writef(
233+
"\tstatic constexpr bool has_assoc_fields = {};\n",
234+
has_assoc_fields(action_id) ? "true" : "false"
238235
);
239236
write_constexpr_id(ctx, "ecsact_action_id", compo_id, "\t");
240237
for(auto child_system_id : get_child_system_ids(action_id)) {
241238
write_system_struct(ctx, child_system_id, "\t");
242239
}
243240
write_system_impl_decl(ctx, "\t");
244241
write_fields(ctx, compo_id, "\t");
245-
ctx.write("};\n"s);
242+
ctx.writef("}};\n");
246243
}
247244

248245
for(auto sys_id : get_system_ids(ctx.package_id)) {
@@ -253,5 +250,5 @@ void ecsact_codegen_plugin(
253250
write_system_struct(ctx, sys_id, "");
254251
}
255252

256-
ctx.write("\n}// namespace "s, namespace_str, "\n"s);
253+
ctx.writef("\n}}// namespace {}\n", namespace_str);
257254
}

0 commit comments

Comments
 (0)