-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtypes.h
1181 lines (954 loc) · 34.8 KB
/
types.h
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
#include "winmd_reader.h"
#include "sha1.h"
#include "versioning.h"
namespace swiftwinrt
{
struct writer;
std::string get_full_type_name(TypeDef const& type);
std::string_view remove_tick(std::string_view const& name);
struct deprecation_info
{
std::string_view contract_type;
std::uint32_t version;
std::string_view message;
};
struct metadata_type
{
virtual std::string_view swift_full_name() const = 0;
virtual std::string_view swift_type_name() const = 0;
virtual std::string_view swift_abi_namespace() const = 0;
virtual std::string_view swift_logical_namespace() const = 0;
virtual std::string_view cpp_abi_name() const = 0;
virtual std::string_view cpp_logical_name() const = 0;
virtual std::string_view mangled_name() const = 0;
virtual std::string_view generic_param_mangled_name() const = 0;
virtual void append_signature(sha1& hash) const = 0;
virtual void write_c_forward_declaration(writer& w) const = 0;
virtual void write_c_abi_param(writer& w) const = 0;
virtual void write_swift_declaration(writer& w) const = 0;
/*
virtual void write_swift_abi_param(writer& w) const = 0;
virtual void write_swift_param(writer& w) const = 0;
*/
virtual bool is_experimental() const = 0;
virtual std::optional<std::size_t> contract_index(std::string_view /*typeName*/, std::size_t /*version*/) const
{
return std::nullopt;
}
virtual std::optional<contract_version> contract_from_index(std::size_t /*index*/) const
{
return std::nullopt;
}
};
inline bool operator<(metadata_type const& lhs, metadata_type const& rhs) noexcept
{
return lhs.swift_full_name() < rhs.swift_full_name();
}
struct typename_comparator
{
bool operator()(std::string_view lhs, metadata_type const& rhs)
{
return lhs < rhs.swift_full_name();
}
bool operator()(metadata_type const& lhs, std::string_view rhs)
{
return lhs.swift_full_name() < rhs;
}
};
struct element_type final : metadata_type
{
element_type(
ElementType elementType,
std::string_view swiftName,
std::string_view logicalName,
std::string_view abiName,
std::string_view cppName,
std::string_view mangledName,
std::string_view signature) :
m_type(elementType),
m_swiftName(swiftName),
m_logicalName(logicalName),
m_abiName(abiName),
m_cppName(cppName),
m_mangledName(mangledName),
m_signature(signature)
{
}
static element_type const& from_type(winmd::reader::ElementType type);
virtual std::string_view swift_abi_namespace() const override
{
return {};
}
virtual std::string_view swift_logical_namespace() const override
{
return {};
}
virtual std::string_view swift_full_name() const override
{
return m_swiftName;
}
virtual std::string_view swift_type_name() const override
{
return m_swiftName;
}
virtual std::string_view cpp_abi_name() const override
{
return m_cppName;
}
virtual std::string_view cpp_logical_name() const override
{
return m_logicalName;
}
virtual std::string_view mangled_name() const override
{
return m_mangledName;
}
virtual std::string_view generic_param_mangled_name() const override
{
return m_mangledName;
}
virtual void append_signature(sha1& hash) const override
{
hash.append(m_signature);
}
virtual void write_c_forward_declaration(writer&) const override
{
// No forward declaration necessary
}
virtual void write_c_abi_param(writer& w) const override;
virtual bool is_experimental() const override
{
// Element types are never experimental
return false;
}
virtual void write_swift_declaration(writer&) const override
{
// no special declaration necessary
}
bool is_blittable() const;
ElementType type() const { return m_type; }
private:
std::string_view m_swiftName;
std::string_view m_logicalName;
std::string_view m_abiName;
std::string_view m_cppName;
std::string_view m_mangledName;
std::string_view m_signature;
bool m_blittable{ true };
ElementType m_type;
};
struct system_type final : metadata_type
{
system_type(
std::string_view swiftModule,
std::string_view swiftTypeName,
std::string_view swiftFullName,
std::string_view cppName,
std::string_view signature,
param_category category) :
m_swiftModuleName(swiftModule),
m_swiftTypeName(swiftTypeName),
m_swiftFullName(swiftFullName),
m_cppName(cppName),
m_signature(signature),
m_category(category)
{
}
static system_type const& from_name(std::string_view typeName);
virtual std::string_view swift_abi_namespace() const override
{
// Currently all mapped types from the System namespace have no namespace
return {};
}
virtual std::string_view swift_logical_namespace() const override
{
return m_swiftModuleName;
}
virtual std::string_view swift_full_name() const override
{
return m_swiftFullName;
}
virtual std::string_view swift_type_name() const override
{
return m_swiftTypeName;
}
virtual std::string_view cpp_abi_name() const override
{
// Currently all mapped types from the System namespace do not have differing ABI/logical names
return m_cppName;
}
virtual std::string_view cpp_logical_name() const override
{
return m_cppName;
}
virtual std::string_view mangled_name() const override
{
return m_cppName;
}
virtual std::string_view generic_param_mangled_name() const override
{
// Currently all mangled names from the System namespace match their C++ name (i.e. no '_' etc. in the name)
return m_cppName;
}
virtual void append_signature(sha1& hash) const override
{
hash.append(m_signature);
}
virtual void write_c_forward_declaration(writer&) const override
{
// No forward declaration necessary
}
virtual void write_c_abi_param(writer& w) const override;
virtual bool is_experimental() const override
{
// System types are never experimental
return false;
}
virtual void write_swift_declaration(writer&) const override
{
// no special declaration necessary
}
param_category category() const { return m_category; }
private:
std::string_view m_swiftModuleName;
std::string_view m_swiftTypeName;
std::string_view m_swiftFullName;
param_category m_category;
std::string_view m_cppName;
std::string_view m_signature;
};
struct mapped_type final : metadata_type
{
mapped_type(
winmd::reader::TypeDef const& type,
std::string_view cppName,
std::string_view mangledName,
std::string_view signature) :
m_type(type),
m_swiftFullName(swiftwinrt::get_full_type_name(type)),
m_cppName(cppName),
m_mangledName(mangledName),
m_signature(signature)
{
}
static mapped_type const* from_typedef(winmd::reader::TypeDef const& type);
virtual std::string_view swift_abi_namespace() const override
{
return m_type.TypeNamespace();
}
virtual std::string_view swift_logical_namespace() const override
{
// Currently all mapped types are in the global namespace
return {};
}
virtual std::string_view swift_full_name() const override
{
return m_swiftFullName;
}
virtual std::string_view swift_type_name() const override
{
return m_type.TypeName();
}
virtual std::string_view cpp_abi_name() const override
{
// Currently no mapped types have differing ABI/logical names
return m_cppName;
}
virtual std::string_view cpp_logical_name() const override
{
return m_cppName;
}
virtual std::string_view mangled_name() const override
{
return m_mangledName;
}
virtual std::string_view generic_param_mangled_name() const override
{
// Currently no mapped type names have any characters that would make it so that the mangled name would be
// different than the generic param mangled name (i.e. no underscore, etc.)
return m_mangledName;
}
virtual void append_signature(sha1& hash) const override
{
hash.append(m_signature);
}
virtual void write_c_forward_declaration(writer&) const override
{
// No forward declaration necessary
}
virtual void write_c_abi_param(writer& w) const override;
virtual bool is_experimental() const override
{
// Mapped types are never experimental
return false;
}
virtual std::optional<std::size_t> contract_index(std::string_view typeName, std::size_t /*version*/) const override
{
// All mapped types are introduced in the UniversalApiContract version 1
using namespace std::literals;
if (typeName != "Windows.Foundation.UniversalApiContract"sv)
{
return std::nullopt;
}
return 0;
}
virtual std::optional<contract_version> contract_from_index([[maybe_unused]] std::size_t index) const override
{
using namespace std::literals;
XLANG_ASSERT(index == 0);
return contract_version{ "Windows.Foundation.UniversalApiContract"sv, 1 };
}
virtual void write_swift_declaration(writer&) const override
{
// no special declaration necessary
}
TypeDef type() const { return m_type; }
private:
winmd::reader::TypeDef m_type;
std::string m_swiftFullName;
std::string_view m_cppName;
std::string_view m_mangledName;
std::string_view m_signature;
};
struct generic_type_parameter;
struct typedef_base : metadata_type
{
typedef_base(winmd::reader::TypeDef const& type);
virtual std::string_view swift_abi_namespace() const override
{
// Most types don't have a different abi and logical type, so use the logical namespace as an easy default
return m_type.TypeNamespace();
}
virtual std::string_view swift_logical_namespace() const override
{
return m_type.TypeNamespace();
}
virtual std::string_view swift_full_name() const override
{
return m_swiftFullName;
}
virtual std::string_view cpp_abi_name() const override
{
// Most types just use the swift type name, so use that as the easy default
return m_type.TypeName();
}
virtual std::string_view swift_type_name() const override
{
return m_type.TypeName();
}
virtual std::string_view cpp_logical_name() const override
{
// Most types just use the swift type name, so use that as the easy default
return m_type.TypeName();
}
virtual std::string_view mangled_name() const override
{
return m_mangledName;
}
virtual std::string_view generic_param_mangled_name() const override
{
// Only generic instantiations should be used as generic params
XLANG_ASSERT(!is_generic());
return m_genericParamMangledName;
}
virtual bool is_experimental() const override;
virtual std::optional<std::size_t> contract_index(std::string_view typeName, std::size_t version) const override
{
if (!m_contractHistory)
{
return std::nullopt;
}
// Start with previous contracts
std::size_t result = 0;
for (auto& prev : m_contractHistory->previous_contracts)
{
if ((prev.contract_from == typeName) && (prev.version_low <= version) && (prev.version_high > version))
{
return result;
}
++result;
}
// Now the current contract
if ((m_contractHistory->current_contract.name == typeName) && (m_contractHistory->current_contract.version <= version))
{
return result;
}
return std::nullopt;
}
virtual std::optional<contract_version> contract_from_index(std::size_t index) const override
{
if (!m_contractHistory)
{
return std::nullopt;
}
// Start with previous contracts
for (auto& prev : m_contractHistory->previous_contracts)
{
if (index-- == 0)
{
return contract_version{ prev.contract_from, prev.version_low };
}
}
if (index == 0)
{
return m_contractHistory->current_contract;
}
XLANG_ASSERT(false);
return std::nullopt;
}
winmd::reader::TypeDef const& type() const noexcept
{
return m_type;
}
bool is_generic() const noexcept;
std::optional<deprecation_info> is_deprecated() const noexcept;
winmd::reader::category category() const noexcept
{
return get_category(m_type);
}
virtual void write_swift_declaration(writer&) const override
{
// not implemented by everyone yet
}
std::vector<generic_type_parameter> generic_params;
protected:
winmd::reader::TypeDef m_type;
// These strings are initialized by the base class
std::string m_swiftFullName;
std::string m_mangledName;
std::string m_genericParamMangledName;
// Versioning information filled in by the base class constructor
std::vector<platform_version> m_platformVersions;
std::optional<contract_history> m_contractHistory;
};
struct enum_type final : typedef_base
{
enum_type(winmd::reader::TypeDef const& type) :
typedef_base(type)
{
}
virtual void append_signature(sha1& hash) const override
{
using namespace std::literals;
hash.append("enum("sv);
hash.append(m_swiftFullName);
hash.append(";"sv);
element_type::from_type(underlying_type()).append_signature(hash);
hash.append(")"sv);
}
virtual void write_c_forward_declaration(writer& w) const override;
virtual void write_c_abi_param(writer& w) const override;
void write_c_definition(writer& w) const;
winmd::reader::ElementType underlying_type() const;
};
struct struct_member
{
winmd::reader::Field field;
metadata_type const* type;
};
struct struct_type final : typedef_base
{
struct_type(winmd::reader::TypeDef const& type) :
typedef_base(type)
{
}
virtual void append_signature(sha1& hash) const override
{
using namespace std::literals;
XLANG_ASSERT(members.size() == static_cast<std::size_t>(distance(m_type.FieldList())));
hash.append("struct("sv);
hash.append(m_swiftFullName);
for (auto const& member : members)
{
hash.append(";");
member.type->append_signature(hash);
}
hash.append(")"sv);
}
virtual void write_c_forward_declaration(writer& w) const override;
virtual void write_c_abi_param(writer& w) const override;
void write_c_definition(writer& w) const;
std::vector<struct_member> members;
};
struct function_return_type
{
winmd::reader::RetTypeSig signature;
std::string_view name;
metadata_type const* type;
bool in() const { return false; }
bool out() const { return true; }
bool is_array() const { return signature.Type().is_szarray() || signature.Type().is_array(); }
};
struct function_param
{
winmd::reader::Param def;
winmd::reader::ParamSig signature;
std::string_view name;
metadata_type const* type;
bool in() const { return def.Flags().In(); }
bool out() const { return def.Flags().Out(); }
bool is_array() const { return signature.Type().is_szarray() || signature.Type().is_array(); }
};
struct function_def
{
winmd::reader::MethodDef def;
std::optional<function_return_type> return_type;
std::vector<function_param> params;
bool is_async() const;
};
struct property_def
{
winmd::reader::Property def;
metadata_type const* type;
std::optional<function_def> getter;
std::optional<function_def> setter;
bool is_array() const { return def.Type().Type().is_szarray() || def.Type().Type().is_array(); }
};
struct event_def
{
winmd::reader::Event def;
metadata_type const* type;
};
using generic_param_type = const metadata_type*;
using generic_param_vector = std::vector<generic_param_type>;
struct interface_info
{
const metadata_type* type{};
bool is_default{};
bool defaulted{};
bool overridable{};
bool base{};
bool exclusive{};
bool fastabi{};
bool attributed{};
// A pair of (relativeContract, version) where 'relativeContract' is the contract the interface was introduced
// in relative to the contract history of the class. E.g. if a class goes from contract 'A' to 'B' to 'C',
// 'relativeContract' would be '0' for an interface introduced in contract 'A', '1' for an interface introduced
// in contract 'B', etc. This is only set/valid for 'fastabi' interfaces
std::pair<uint32_t, uint32_t> relative_version{};
generic_param_vector generic_params{};
};
using named_interface_info = std::pair<std::string, interface_info>;
struct attributed_type
{
const metadata_type* type;
bool activatable{};
bool statics{};
bool composable{};
bool visible{};
bool defaultComposable{};
};
struct delegate_type final : typedef_base
{
delegate_type(winmd::reader::TypeDef const& type);
virtual std::string_view cpp_logical_name() const override
{
// Even though the ABI name of delegates is different than their swift name, the logical name is still the same as
// the ABI name
return m_abiName;
}
virtual void append_signature(sha1& hash) const override;
virtual void write_c_forward_declaration(writer& w) const override;
virtual void write_c_abi_param(writer& w) const override;
void write_c_definition(writer& w) const;
std::vector<function_def> functions;
private:
std::string m_abiName;
};
struct class_type;
struct interface_type : typedef_base
{
interface_type(winmd::reader::TypeDef const& type) :
typedef_base(type)
{
}
virtual void append_signature(sha1& hash) const override;
virtual void write_c_forward_declaration(writer& w) const override;
virtual void write_c_abi_param(writer& w) const override;
void write_c_definition(writer& w) const;
std::vector<named_interface_info> required_interfaces;
std::vector<function_def> functions;
std::vector<property_def> properties;
std::vector<event_def> events;
// When non-null, this interface gets extended with functions from other exclusiveto interfaces on the class
class_type const* fast_class = nullptr;
};
struct generic_type_parameter final : metadata_type {
generic_type_parameter(std::string_view name) : param_name(name)
{
}
virtual std::string_view swift_full_name() const override
{
return param_name;
}
virtual std::string_view swift_type_name() const override
{
return param_name;
}
virtual std::string_view swift_abi_namespace() const override
{
return {};
}
virtual std::string_view swift_logical_namespace() const override
{
return {};
}
virtual std::string_view cpp_abi_name() const override
{
return param_name;
}
virtual std::string_view cpp_logical_name() const override
{
return param_name;
}
virtual std::string_view mangled_name() const override
{
return param_name;
}
virtual std::string_view generic_param_mangled_name() const override
{
return param_name;
}
virtual void append_signature(sha1& hash) const override
{
}
virtual void write_c_forward_declaration(writer&) const override
{
// No forward declaration necessary
}
virtual void write_c_abi_param(writer& w) const override {}
virtual bool is_experimental() const override
{
return false;
}
virtual void write_swift_declaration(writer&) const override
{
// no special declaration necessary
}
private:
std::string_view param_name;
};
struct class_type final : typedef_base
{
class_type(winmd::reader::TypeDef const& type);
virtual std::string_view swift_abi_namespace() const override
{
if (m_abiNamespace.empty())
{
swiftwinrt::throw_invalid("Class type '", swift_full_name(), "' does not have a default interface and therefore "
"does not have an ABI type namespace");
}
return m_abiNamespace;
}
virtual std::string_view cpp_abi_name() const override
{
if (!default_interface)
{
swiftwinrt::throw_invalid("Class type '", swift_full_name(), "' does not have a default interface and therefore "
"does not have an ABI type name");
}
return default_interface->cpp_abi_name();
}
virtual void append_signature(sha1& hash) const override
{
using namespace std::literals;
if (!default_interface)
{
swiftwinrt::throw_invalid("Class type '", swift_full_name(), "' does not have a default interface and therefore "
"does not have a signature");
}
hash.append("rc("sv);
hash.append(m_swiftFullName);
hash.append(";"sv);
default_interface->append_signature(hash);
hash.append(")"sv);
}
virtual void write_c_forward_declaration(writer& w) const override;
virtual void write_c_abi_param(writer& w) const override;
void write_c_definition(writer& w) const;
std::vector<named_interface_info> required_interfaces;
std::vector<std::pair<interface_type const*, version>> supplemental_fast_interfaces;
class_type const* base_class = nullptr;
metadata_type const* default_interface = nullptr;
std::map<std::string, attributed_type> factories;
bool is_composable() const;
private:
std::string_view m_abiNamespace;
};
struct generic_inst final : metadata_type
{
generic_inst(typedef_base const* genericType, std::vector<metadata_type const*> genericParams) :
m_genericType(genericType),
m_genericParams(std::move(genericParams))
{
m_swiftFullName = genericType->swift_full_name();
m_swiftFullName.push_back('<');
m_mangledName = genericType->mangled_name();
m_swiftTypeName = genericType->swift_type_name();
m_swiftTypeName.push_back('<');
std::string_view prefix;
for (auto param : m_genericParams)
{
m_swiftFullName += prefix;
m_swiftFullName += param->swift_full_name();
m_swiftTypeName += prefix;
// we use the param full name because short type names could conflict (i.e. Microsoft.UI.Input.PointerPoint/Windows.UI.Input.PointerPoint)
m_swiftTypeName += param->swift_full_name();
m_mangledName.push_back('_');
m_mangledName += param->generic_param_mangled_name();
prefix = ", ";
}
m_swiftFullName.push_back('>');
m_swiftTypeName.push_back('>');
}
virtual std::string_view swift_abi_namespace() const override
{
return m_genericType->swift_abi_namespace();
}
virtual std::string_view swift_logical_namespace() const override
{
return m_genericType->swift_logical_namespace();
}
virtual std::string_view swift_full_name() const override
{
return m_swiftFullName;
}
virtual std::string_view swift_type_name() const override
{
return m_swiftTypeName;
}
virtual std::string_view cpp_abi_name() const override
{
return m_mangledName;
}
virtual std::string_view cpp_logical_name() const override
{
return m_mangledName;
}
virtual std::string_view mangled_name() const override
{
return m_mangledName;
}
virtual std::string_view generic_param_mangled_name() const override
{
return m_mangledName;
}
virtual void append_signature(sha1& hash) const override;
virtual void write_c_forward_declaration(writer& w) const override;
virtual void write_c_abi_param(writer& w) const override;
virtual bool is_experimental() const override
{
// Generic instances are experimental only if their arguments are experimental
for (auto ptr : m_genericParams)
{
if (ptr->is_experimental())
{
return true;
}
}
return false;
}
typedef_base const* generic_type() const noexcept
{
return m_genericType;
}
winmd::reader::category category() const noexcept
{
return m_genericType->category();
}
std::optional<deprecation_info> is_deprecated() const noexcept
{
return m_genericType->is_deprecated();
}
std::string_view generic_type_abi_name() const noexcept
{
// Generic type swift names end with "`N" where 'N' is the number of generic parameters
auto result = m_genericType->cpp_abi_name();
auto tickPos = result.rfind('`');
XLANG_ASSERT(tickPos != std::string_view::npos);
return result.substr(0, tickPos);
}
std::vector<metadata_type const*> const& generic_params() const noexcept
{
return m_genericParams;
}
std::vector<generic_inst const*> dependencies;
std::vector<function_def> functions;
std::vector<property_def> properties;
std::vector<event_def> events;
virtual void write_swift_declaration(writer&) const override;
std::vector<named_interface_info> required_interfaces;
private:
typedef_base const* m_genericType;
std::vector<metadata_type const*> m_genericParams;
std::string m_swiftFullName;
std::string m_swiftTypeName;
std::string m_mangledName;
};
// Helpers
inline bool is_generic_inst(const metadata_type* type)
{
return dynamic_cast<const generic_inst*>(type) != nullptr;
}
inline bool is_generic_inst(metadata_type const& type)
{
return is_generic_inst(&type);
}
inline bool is_generic_def(const metadata_type* type)
{
auto typedefBase = dynamic_cast<const typedef_base*>(type);
return typedefBase != nullptr && typedefBase->is_generic();
}