Skip to content

Commit 14eb2dc

Browse files
committed
Tidy up a few codegen bits
1 parent a7b1413 commit 14eb2dc

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

cppwinrt/code_writers.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ namespace cppwinrt
144144
return { w, [macro = std::string(macro)](writer& w) { write_endif(w, macro); } };
145145
}
146146

147+
[[nodiscard]] static finish_with wrap_ifndef(writer& w, std::string_view macro)
148+
{
149+
auto format = R"(#ifndef %
150+
)";
151+
152+
w.write(format, macro);
153+
154+
return { w, [macro = std::string(macro)](writer& w) { write_endif(w, macro); } };
155+
}
156+
147157
static void write_parent_depends(writer& w, cache const& c, std::string_view const& type_namespace)
148158
{
149159
auto pos = type_namespace.rfind('.');

cppwinrt/file_writers.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace cppwinrt
99
w.write(strings::base_version_odr, CPPWINRT_VERSION_STRING);
1010
{
1111
auto wrap_file_guard = wrap_open_file_guard(w, "BASE");
12-
w.write("#ifndef WINRT_IMPORT_MODULE\n");
12+
auto wrap_import = wrap_ifndef(w, "WINRT_IMPORT_MODULE");
1313

1414
{
1515
auto wrap_includes = wrap_module_aware_includes_guard(w, true);
1616
w.write(strings::base_includes);
1717
}
18-
w.write("#include \"winrt/base_macros.h\"\n");
18+
w.write_root_include("base_macros");
1919
w.write(strings::base_source_location);
2020
w.write(strings::base_types);
2121
w.write(strings::base_extern);
@@ -47,8 +47,6 @@ namespace cppwinrt
4747
w.write(strings::base_coroutine_threadpool);
4848
w.write(strings::base_natvis);
4949
w.write(strings::base_version);
50-
51-
w.write("#endif // WINRT_IMPORT_MODULE\n");
5250
}
5351
w.flush_to_file(settings.output_folder + "winrt/base.h");
5452
}
@@ -240,7 +238,7 @@ namespace cppwinrt
240238
write_namespace_special(w, ns);
241239

242240
write_close_file_guard(w);
243-
w.write("#endif\n"); // WINRT_IMPORT_MODULE
241+
w.write("#endif // WINRT_IMPORT_MODULE\n");
244242
w.swap();
245243
write_preamble(w);
246244
write_open_file_guard(w, ns);
@@ -303,12 +301,12 @@ namespace cppwinrt
303301
write_include_guard(w);
304302

305303
w.write("#ifdef WINRT_IMPORT_MODULE\n");
306-
w.write("#include \"winrt/base_macros.h\"\n");
304+
w.write_root_include("base_macros");
307305
for (auto&& depends : w.depends)
308306
{
309307
w.write("import winrt.%;\n", depends.first);
310308
}
311-
w.write("#else\n");
309+
w.write("#else // WINRT_IMPORT_MODULE\n");
312310

313311
for (auto&& depends : w.depends)
314312
{

0 commit comments

Comments
 (0)