forked from microsoft/cppwinrt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_writers.h
More file actions
3510 lines (3077 loc) · 104 KB
/
code_writers.h
File metadata and controls
3510 lines (3077 loc) · 104 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
namespace cppwinrt
{
struct finish_with
{
writer& w;
void (*finisher)(writer&);
finish_with(writer& w, void (*finisher)(writer&)) : w(w), finisher(finisher) {}
finish_with(finish_with const&)= delete;
void operator=(finish_with const&) = delete;
~finish_with() { finisher(w); }
};
static void write_nothing(writer&)
{
}
static void write_preamble(writer& w)
{
if (settings.license)
{
w.write(R"(// C++/WinRT v%
%
)", CPPWINRT_VERSION_STRING, settings.license_template);
}
else
{
w.write(R"(// WARNING: Please don't edit this file. It was generated by C++/WinRT v%
)", CPPWINRT_VERSION_STRING);
}
}
static void write_version_assert(writer& w)
{
w.write_root_include("base");
auto format = R"(static_assert(winrt::check_version(CPPWINRT_VERSION, "%"), "Mismatched C++/WinRT headers.");
#define CPPWINRT_VERSION "%"
)";
w.write(format, CPPWINRT_VERSION_STRING, CPPWINRT_VERSION_STRING);
}
static void write_include_guard(writer& w)
{
auto format = R"(#pragma once
)";
w.write(format);
}
static void write_endif(writer& w)
{
auto format = R"(#endif
)";
w.write(format);
}
static void write_close_file_guard(writer& w)
{
write_endif(w);
}
static void write_open_file_guard(writer& w, std::string_view const& file_name, char impl = 0)
{
write_include_guard(w);
std::string mangled_name;
for (auto&& c : file_name)
{
mangled_name += c == '.' ? '_' : c;
}
if (impl)
{
mangled_name += '_';
mangled_name += impl;
}
auto format = R"(#ifndef WINRT_%_H
#define WINRT_%_H
)";
w.write(format, mangled_name, mangled_name);
}
template<typename... Args>
[[nodiscard]] static finish_with wrap_open_file_guard(writer& w, Args&&... args)
{
write_open_file_guard(w, std::forward<Args>(args)...);
return { w, write_close_file_guard };
}
[[nodiscard]] static finish_with wrap_lean_and_mean(writer& w, bool is_lean_and_mean = true)
{
if (is_lean_and_mean)
{
auto format = R"(#ifndef WINRT_LEAN_AND_MEAN
)";
w.write(format);
return { w, write_endif };
}
else
{
return { w, write_nothing };
}
}
[[nodiscard]] static finish_with wrap_ifdef(writer& w, std::string_view macro)
{
auto format = R"(#ifdef %
)";
w.write(format, macro);
return { w, write_endif };
}
static void write_parent_depends(writer& w, cache const& c, std::string_view const& type_namespace)
{
auto pos = type_namespace.rfind('.');
if (pos == std::string::npos)
{
return;
}
auto parent = type_namespace.substr(0, pos);
auto found = c.namespaces().find(parent);
if (found != c.namespaces().end() && has_projected_types(found->second))
{
w.write_root_include(parent);
}
else
{
write_parent_depends(w, c, parent);
}
}
static void write_pch(writer& w)
{
auto format = R"(#include "%"
)";
if (!settings.component_pch.empty())
{
w.write(format, settings.component_pch);
}
}
static void write_close_namespace(writer& w)
{
auto format = R"(}
)";
w.write(format);
}
[[nodiscard]] static finish_with wrap_impl_namespace(writer& w)
{
auto format = R"(namespace winrt::impl
{
)";
w.write(format);
return { w, write_close_namespace };
}
[[nodiscard]] static finish_with wrap_std_namespace(writer& w)
{
w.write(R"(namespace std
{
)");
return { w, write_close_namespace };
}
[[nodiscard]] static finish_with wrap_type_namespace(writer& w, std::string_view const& ns)
{
auto format = R"(WINRT_EXPORT namespace winrt::@
{
)";
w.write(format, ns);
return { w, write_close_namespace };
}
static void write_enum_field(writer& w, Field const& field)
{
auto format = R"( % = %,
)";
if (auto constant = field.Constant())
{
w.write(format, field.Name(), *constant);
}
}
static void write_enum(writer& w, TypeDef const& type)
{
auto format = R"( enum class % : %
{
% };
)";
auto fields = type.FieldList();
w.write(format, type.TypeName(), fields.first.Signature().Type(), bind_each<write_enum_field>(fields));
}
static void write_enum_operators(writer& w, TypeDef const& type)
{
if (!has_attribute(type, "System", "FlagsAttribute"))
{
return;
}
auto name = type.TypeName();
auto format = R"( constexpr auto operator|(% const left, % const right) noexcept
{
return static_cast<%>(impl::to_underlying_type(left) | impl::to_underlying_type(right));
}
constexpr auto operator|=(%& left, % const right) noexcept
{
left = left | right;
return left;
}
constexpr auto operator&(% const left, % const right) noexcept
{
return static_cast<%>(impl::to_underlying_type(left) & impl::to_underlying_type(right));
}
constexpr auto operator&=(%& left, % const right) noexcept
{
left = left & right;
return left;
}
constexpr auto operator~(% const value) noexcept
{
return static_cast<%>(~impl::to_underlying_type(value));
}
constexpr auto operator^^(% const left, % const right) noexcept
{
return static_cast<%>(impl::to_underlying_type(left) ^^ impl::to_underlying_type(right));
}
constexpr auto operator^^=(%& left, % const right) noexcept
{
left = left ^^ right;
return left;
}
)";
w.write(format, name, name, name, name, name, name, name, name, name, name, name, name, name, name, name, name, name);
}
static void write_generic_typenames(writer& w, std::pair<GenericParam, GenericParam> const& params)
{
separator s{ w };
for (auto&& param : params)
{
s();
w.write("typename %", param);
}
}
static void write_generic_asserts(writer& w, std::pair<GenericParam, GenericParam> const& params)
{
for (auto&& param : params)
{
auto format = R"(
static_assert(impl::has_category_v<%>, "% must be WinRT type.");)";
w.write(format, param, param);
}
}
static void write_comma_generic_typenames(writer& w, std::pair<GenericParam, GenericParam> const& params)
{
for (auto&& param : params)
{
w.write(", typename %", param);
}
}
static void write_comma_generic_types(writer& w, std::pair<GenericParam, GenericParam> const& params)
{
for (auto&& param : params)
{
w.write(", %", param);
}
}
static void write_forward(writer& w, TypeDef const& type)
{
type_name type_name(type);
if (get_category(type) == category::enum_type)
{
auto format = R"( enum class % : %;
)";
w.write(format, type_name.name, type.FieldList().first.Signature().Type());
return;
}
if (type_name == "Windows.Foundation.DateTime" ||
type_name == "Windows.Foundation.TimeSpan")
{
// Don't forward declare these since they're not structs.
return;
}
if (type_name.name_space == "Windows.Foundation.Numerics")
{
if (type_name.name == "Matrix3x2" ||
type_name.name == "Matrix4x4" ||
type_name.name == "Plane" ||
type_name.name == "Quaternion" ||
type_name.name == "Vector2" ||
type_name.name == "Vector3" ||
type_name.name == "Vector4")
{
// Don't forward declare these since they're already defined with different names.
return;
}
}
auto generics = type.GenericParam();
if (empty(generics))
{
auto format = R"( struct %;
)";
w.write(format, type_name.name);
return;
}
auto format = R"( template <%> struct WINRT_IMPL_EMPTY_BASES %;
)";
w.write(format,
bind<write_generic_typenames>(generics),
remove_tick(type_name.name));
}
static void write_guid_value(writer& w, std::vector<FixedArgSig> const& args)
{
using std::get;
w.write_printf("0x%08X,0x%04X,0x%04X,{ 0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X,0x%02X }",
get<std::uint32_t>(get<ElemSig>(args[0].value).value),
get<std::uint16_t>(get<ElemSig>(args[1].value).value),
get<std::uint16_t>(get<ElemSig>(args[2].value).value),
get<std::uint8_t>(get<ElemSig>(args[3].value).value),
get<std::uint8_t>(get<ElemSig>(args[4].value).value),
get<std::uint8_t>(get<ElemSig>(args[5].value).value),
get<std::uint8_t>(get<ElemSig>(args[6].value).value),
get<std::uint8_t>(get<ElemSig>(args[7].value).value),
get<std::uint8_t>(get<ElemSig>(args[8].value).value),
get<std::uint8_t>(get<ElemSig>(args[9].value).value),
get<std::uint8_t>(get<ElemSig>(args[10].value).value));
}
static void write_guid_comment(writer& w, std::vector<FixedArgSig> const& args)
{
using std::get;
w.write_printf("%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
get<std::uint32_t>(get<ElemSig>(args[0].value).value),
get<std::uint16_t>(get<ElemSig>(args[1].value).value),
get<std::uint16_t>(get<ElemSig>(args[2].value).value),
get<std::uint8_t>(get<ElemSig>(args[3].value).value),
get<std::uint8_t>(get<ElemSig>(args[4].value).value),
get<std::uint8_t>(get<ElemSig>(args[5].value).value),
get<std::uint8_t>(get<ElemSig>(args[6].value).value),
get<std::uint8_t>(get<ElemSig>(args[7].value).value),
get<std::uint8_t>(get<ElemSig>(args[8].value).value),
get<std::uint8_t>(get<ElemSig>(args[9].value).value),
get<std::uint8_t>(get<ElemSig>(args[10].value).value));
}
static void write_category(writer& w, TypeDef const& type, std::string_view const& category)
{
auto generics = type.GenericParam();
if (empty(generics))
{
auto format = R"( template <> struct category<%>{ using type = %; };
)";
w.write(format, type, category);
}
else
{
auto format = R"( template <%> struct category<%>{ using type = generic_category<%>; };
)";
w.write(format,
bind<write_generic_typenames>(generics),
type,
bind_list(", ", generics));
}
}
static void write_generic_names(writer& w, std::pair<GenericParam, GenericParam> const& params)
{
bool first = true;
for (auto&& param : params)
{
if (first)
{
first = false;
}
else
{
w.write(R"(, L", ")");
}
w.write(", name_v<%>", param.Name());
}
}
static void write_name(writer& w, TypeDef const& type)
{
type_name type_name(type);
auto generics = type.GenericParam();
if (empty(generics))
{
auto format = R"( template <> inline constexpr auto& name_v<%> = L"%.%";
)";
w.write(format, type, type_name.name_space, type_name.name);
}
else
{
auto format = R"( template <%> inline constexpr auto name_v<%> = zcombine(L"%.%<"%, L">");
)";
w.write(format,
bind<write_generic_typenames>(generics),
type,
type_name.name_space,
type_name.name,
bind<write_generic_names>(generics));
}
}
static void write_guid(writer& w, TypeDef const& type)
{
auto attribute = get_attribute(type, "Windows.Foundation.Metadata", "GuidAttribute");
if (!attribute)
{
throw_invalid("'Windows.Foundation.Metadata.GuidAttribute' attribute for type '", type.TypeNamespace(), ".", type.TypeName(), "' not found");
}
auto generics = type.GenericParam();
auto guid = attribute.Value().FixedArgs();
if (empty(generics))
{
auto format = R"( template <> inline constexpr guid guid_v<%>{ % }; // %
)";
w.write(format,
type,
bind<write_guid_value>(guid),
bind<write_guid_comment>(guid));
}
else
{
auto format = R"( template <%> inline constexpr guid guid_v<%>{ pinterface_guid<%>::value };
template <%> inline constexpr guid generic_guid_v<%>{ % }; // %
)";
w.write(format,
bind<write_generic_typenames>(generics),
type,
type,
bind<write_generic_typenames>(generics),
type,
bind<write_guid_value>(guid),
bind<write_guid_comment>(guid));
}
}
static void write_default_interface(writer& w, TypeDef const& type)
{
if (auto default_interface = get_default_interface(type))
{
auto format = R"( template <> struct default_interface<%>{ using type = %; };
)";
w.write(format, type, default_interface);
}
}
static void write_struct_category(writer& w, TypeDef const& type)
{
auto format = R"( template <> struct category<%>{ using type = struct_category<%>; };
)";
w.write(format, type, bind_list(", ", type.FieldList()));
}
static void write_array_size_name(writer& w, Param const& param)
{
if (w.param_names)
{
w.write(" __%Size", param.Name());
}
}
static void write_abi_arg_in(writer& w, TypeSig const& type)
{
if (std::holds_alternative<GenericTypeIndex>(type.Type()))
{
w.write("arg_in<%>", type);
}
else
{
w.write(type);
}
}
static void write_abi_arg_out(writer& w, TypeSig const& type)
{
if (std::holds_alternative<GenericTypeIndex>(type.Type()))
{
w.write("arg_out<%>", type);
}
else
{
w.write("%*", type);
}
}
static void write_abi_params(writer& w, method_signature const& method_signature)
{
auto abi_guard = w.push_abi_types(true);
separator s{ w };
for (auto&& [param, param_signature] : method_signature.params())
{
s();
if (param_signature->Type().is_szarray())
{
std::string_view format;
if (param.Flags().In())
{
format = "std::uint32_t%, %";
}
else if (param_signature->ByRef())
{
format = "std::uint32_t*%, %*";
}
else
{
format = "std::uint32_t%, %";
}
w.write(format, bind<write_array_size_name>(param), bind<write_abi_arg_out>(param_signature->Type()));
}
else
{
if (param.Flags().In())
{
write_abi_arg_in(w, param_signature->Type());
if (is_const(*param_signature))
{
w.write(" const&");
}
}
else
{
write_abi_arg_out(w, param_signature->Type());
}
}
if (w.param_names)
{
w.write(" %", param.Name());
}
}
if (method_signature.return_signature())
{
s();
auto const& type = method_signature.return_signature().Type();
if (type.is_szarray())
{
w.write("std::uint32_t* __%Size, %**", method_signature.return_param_name(), type);
}
else
{
write_abi_arg_out(w, type);
}
if (w.param_names)
{
w.write(" %", method_signature.return_param_name());
}
}
}
static void write_abi_args(writer& w, method_signature const& method_signature)
{
separator s{ w };
for (auto&& [param, param_signature] : method_signature.params())
{
s();
auto param_name = param.Name();
TypeDef signature_type;
auto category = get_category(param_signature->Type(), &signature_type);
if (param.Flags().In())
{
switch (category)
{
case param_category::object_type:
case param_category::string_type:
w.write("*(void**)(&%)", param_name);
break;
case param_category::generic_type:
case param_category::struct_type:
w.write("impl::bind_in(%)", param_name);
break;
case param_category::enum_type:
w.write("static_cast<%>(%)", signature_type.FieldList().first.Signature().Type(), param_name);
break;
case param_category::fundamental_type:
w.write(param_name);
break;
case param_category::array_type:
w.write("%.size(), get_abi(%)", param_name, param_name);
break;
}
}
else
{
switch (category)
{
case param_category::fundamental_type:
w.write("&%", param_name);
break;
case param_category::enum_type:
w.write("reinterpret_cast<%*>(&%)", signature_type.FieldList().first.Signature().Type(), param_name);
break;
case param_category::array_type:
if (param_signature->ByRef())
{
w.write("impl::put_size_abi(%), put_abi(%)", param_name, param_name);
}
else
{
w.write("%.size(), put_abi(%)", param_name, param_name);
}
break;
default:
w.write("impl::bind_out(%)", param_name);
break;
}
}
}
if (method_signature.return_signature())
{
s();
auto param_name = method_signature.return_param_name();
TypeDef signature_type;
auto category = get_category(method_signature.return_signature().Type(), &signature_type);
if (category == param_category::array_type)
{
w.write("&%_impl_size, &%", param_name, param_name);
}
else if (category == param_category::struct_type || category == param_category::generic_type)
{
w.write("put_abi(%)", param_name);
}
else if (category == param_category::enum_type)
{
w.write("reinterpret_cast<%*>(&%)", signature_type.FieldList().first.Signature().Type(), param_name);
}
else
{
w.write("&%", param_name);
}
}
}
static void write_fast_interface_abi(writer& w, TypeDef const& default_interface)
{
if (!settings.fastabi)
{
return;
}
auto pair = settings.fastabi_cache.find(default_interface);
if (pair == settings.fastabi_cache.end())
{
return;
}
auto bases = get_bases(pair->second);
std::for_each(bases.rbegin(), bases.rend(), [&](auto&& base)
{
auto format = R"( virtual void* __stdcall base_%() noexcept = 0;
)";
w.write(format, base.TypeName());
});
for (auto&& [name, info] : get_interfaces(w, pair->second))
{
if (info.is_default)
{
continue;
}
if (!info.fastabi)
{
break;
}
auto format = R"( virtual std::int32_t __stdcall %(%) noexcept = 0;
)";
for (auto&& method : info.type.MethodList())
{
method_signature signature{ method };
w.write(format, get_abi_name(method), bind<write_abi_params>(signature));
}
}
}
static void write_interface_abi(writer& w, TypeDef const& type)
{
auto generics = type.GenericParam();
auto guard{ w.push_generic_params(generics) };
if (empty(generics))
{
auto format = R"( template <> struct abi<%>
{
struct WINRT_IMPL_ABI_DECL type : inspectable_abi
{
)";
w.write(format, type);
}
else
{
auto format = R"( template <%> struct abi<%>
{
struct WINRT_IMPL_ABI_DECL type : inspectable_abi
{
)";
w.write(format,
bind<write_generic_typenames>(generics),
type);
}
auto format = R"( virtual std::int32_t __stdcall %(%) noexcept = 0;
)";
auto abi_guard = w.push_abi_types(true);
for (auto&& method : type.MethodList())
{
try
{
method_signature signature{ method };
w.write(format, get_abi_name(method), bind<write_abi_params>(signature));
}
catch (std::exception const& e)
{
throw_invalid(e.what(),
"\n method: ", get_name(method),
"\n type: ", type.TypeNamespace(), ".", type.TypeName(),
"\n database: ", type.get_database().path());
}
}
write_fast_interface_abi(w, type);
w.write(R"( };
};
)");
}
static void write_delegate_abi(writer& w, TypeDef const& type)
{
auto format = R"( template <%> struct abi<%>
{
struct WINRT_IMPL_ABI_DECL type : unknown_abi
{
virtual std::int32_t __stdcall Invoke(%) noexcept = 0;
};
};
)";
auto generics = type.GenericParam();
auto guard{ w.push_generic_params(generics) };
auto method = get_delegate_method(type);
method_signature signature{ method };
w.write(format,
bind<write_generic_typenames>(generics),
type,
bind<write_abi_params>(signature));
}
static void write_field_abi(writer& w, Field const& field)
{
w.write(" % %;\n", get_field_abi(w, field), field.Name());
}
static void write_struct_abi(writer& w, TypeDef const& type)
{
auto abi_guard = w.push_abi_types(true);
auto format = R"( struct struct_%
{
% };
template <> struct abi<@::%>
{
using type = struct_%;
};
)";
type_name type_name(type);
auto impl_name = get_impl_name(type_name.name_space, type_name.name);
w.write(format,
impl_name,
bind_each<write_field_abi>(type.FieldList()),
type_name.name_space, type_name.name,
impl_name);
}
static void write_consume_params(writer& w, method_signature const& signature)
{
separator s{ w };
for (auto&& [param, param_signature] : signature.params())
{
s();
if (param_signature->Type().is_szarray())
{
std::string_view format;
if (param.Flags().In())
{
format = "array_view<% const>";
}
else if (param_signature->ByRef())
{
format = "com_array<%>&";
}
else
{
format = "array_view<%>";
}
w.write(format, param_signature->Type().Type());
}
else
{
if (param.Flags().In())
{
assert(!param.Flags().Out());
w.consume_types = true;
auto param_type = std::get_if<ElementType>(¶m_signature->Type().Type());
if (param_type && *param_type != ElementType::String && *param_type != ElementType::Object)
{
w.write("%", param_signature->Type());
}
else if (std::holds_alternative<GenericTypeIndex>(param_signature->Type().Type()))
{
w.write("impl::param_type<%> const&", param_signature->Type());
}
else
{
w.write("% const&", param_signature->Type());
}
w.consume_types = false;
}
else
{
assert(!param.Flags().In());
assert(param.Flags().Out());
w.write("%&", param_signature->Type());
}
}
w.write(" %", param.Name());
}
}
static void write_implementation_params(writer& w, method_signature const& method_signature)
{
separator s{ w };
for (auto&& [param, param_signature] : method_signature.params())
{
s();
if (param_signature->Type().is_szarray())
{
std::string_view format;
if (param.Flags().In())
{
format = "array_view<% const>";
}
else if (param_signature->ByRef())
{
format = "com_array<%>&";
}
else
{
format = "array_view<%>";
}
w.write(format, param_signature->Type().Type());
}
else
{
if (param.Flags().In())
{
assert(!param.Flags().Out());
auto param_type = std::get_if<ElementType>(¶m_signature->Type().Type());
if ((!is_put_overload(method_signature.method()) && w.async_types) ||
(param_type && *param_type != ElementType::String && *param_type != ElementType::Object))
{
w.write("%", param_signature->Type());
}
else
{
w.write("% const&", param_signature->Type());
}
}
else
{
assert(!param.Flags().In());
assert(param.Flags().Out());
w.write("%&", param_signature->Type());
}
}
w.write(" %", param.Name());
}
}
static void write_consume_declaration(writer& w, MethodDef const& method)
{
method_signature signature{ method };
auto async_types_guard = w.push_async_types(signature.is_async());
auto method_name = get_name(method);
auto type = method.Parent();
w.write(" %auto %(%) const%;\n",
is_get_overload(method) ? "[[nodiscard]] " : "",
method_name,
bind<write_consume_params>(signature),
is_noexcept(method) ? " noexcept" : "");
if (is_add_overload(method))
{