forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Metafunctions.cpp
5592 lines (4780 loc) · 208 KB
/
Metafunctions.cpp
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
//===--- Metafunctions.cpp - Functions targeting reflections ----*- C++ -*-===//
//
// Copyright 2024 Bloomberg Finance L.P.
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements all metafunctions from the <experimental/meta> header.
//
//===----------------------------------------------------------------------===//
#include "clang/AST/APValue.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclGroup.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/Expr.h"
#include "clang/AST/RecordLayout.h"
#include "clang/AST/Reflection.h"
#include "clang/Basic/DiagnosticMetafn.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Sema/EnterExpressionEvaluationContext.h"
#include "clang/Sema/Metafunction.h"
#include "clang/Sema/ParsedTemplate.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/Template.h"
#include "clang/Sema/TemplateDeduction.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
namespace clang {
using EvalFn = Metafunction::EvaluateFn;
using DiagFn = Metafunction::DiagnoseFn;
// -----------------------------------------------------------------------------
// P2996 Metafunction declarations
// -----------------------------------------------------------------------------
static bool get_begin_enumerator_decl_of(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool get_next_enumerator_decl_of(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy,
SourceRange Range,
ArrayRef<Expr *> Args);
static bool get_ith_base_of(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool get_ith_template_argument_of(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool get_begin_member_decl_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool get_next_member_decl_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool map_decl_to_entity(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool identifier_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool has_identifier(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool operator_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool source_location_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool type_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool parent_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool dealias(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool value_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool object_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool template_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool can_substitute(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool substitute(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool extract(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_public(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_protected(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_private(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_access_specified(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool access_context(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_accessible(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_virtual(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_pure_virtual(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_override(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_deleted(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_defaulted(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_explicit(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_noexcept(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_bit_field(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_enumerator(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_const(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_volatile(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_lvalue_reference_qualified(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_rvalue_reference_qualified(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool has_static_storage_duration(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool has_thread_storage_duration(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool has_automatic_storage_duration(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool has_internal_linkage(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool has_module_linkage(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool has_external_linkage(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool has_linkage(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_class_member(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_namespace_member(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_nonstatic_data_member(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_static_member(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_base(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_data_member_spec(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_namespace(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_function(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_variable(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_type(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_alias(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_incomplete_type(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_template(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_function_template(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_variable_template(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_class_template(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_alias_template(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_conversion_function_template(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy,
SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_operator_function_template(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_literal_operator_template(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_constructor_template(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_concept(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_structured_binding(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_value(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_object(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool has_template_arguments(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool has_default_member_initializer(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_conversion_function(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_operator_function(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_literal_operator(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_constructor(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_default_constructor(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_copy_constructor(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_move_constructor(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_assignment(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_copy_assignment(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_move_assignment(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_destructor(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_special_member_function(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_user_provided(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool reflect_result(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool reflect_invoke(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool data_member_spec(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool define_class(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool offset_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool size_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool bit_offset_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool bit_size_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool alignment_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool define_static_string(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
// -----------------------------------------------------------------------------
// P3096 Metafunction declarations
// -----------------------------------------------------------------------------
static bool get_ith_parameter_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool has_consistent_identifier(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool has_ellipsis_parameter(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool has_default_argument(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool is_explicit_object_parameter(APValue &Result, Sema &S,
EvalFn Evaluator, DiagFn Diagnoser,
QualType ResultTy, SourceRange Range,
ArrayRef<Expr *> Args);
static bool is_function_parameter(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
static bool return_type_of(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args);
// -----------------------------------------------------------------------------
// Metafunction table
//
// Order of entries MUST be kept in sync with order of declarations in the
// <experimental/meta>
// header file.
// -----------------------------------------------------------------------------
static constexpr Metafunction Metafunctions[] = {
// Kind, MinArgs, MaxArgs, Impl
// non-exposed metafunctions
{ Metafunction::MFRK_metaInfo, 2, 2, get_begin_enumerator_decl_of },
{ Metafunction::MFRK_metaInfo, 2, 2, get_next_enumerator_decl_of },
{ Metafunction::MFRK_metaInfo, 3, 3, get_ith_base_of },
{ Metafunction::MFRK_metaInfo, 3, 3, get_ith_template_argument_of },
{ Metafunction::MFRK_metaInfo, 2, 2, get_begin_member_decl_of },
{ Metafunction::MFRK_metaInfo, 2, 2, get_next_member_decl_of },
{ Metafunction::MFRK_metaInfo, 1, 1, map_decl_to_entity },
// exposed metafunctions
{ Metafunction::MFRK_spliceFromArg, 4, 4, identifier_of },
{ Metafunction::MFRK_bool, 1, 1, has_identifier },
{ Metafunction::MFRK_sizeT, 1, 1, operator_of },
{ Metafunction::MFRK_sourceLoc, 1, 1, source_location_of },
{ Metafunction::MFRK_metaInfo, 1, 1, type_of },
{ Metafunction::MFRK_metaInfo, 1, 1, parent_of },
{ Metafunction::MFRK_metaInfo, 1, 1, dealias },
{ Metafunction::MFRK_metaInfo, 1, 1, object_of },
{ Metafunction::MFRK_metaInfo, 1, 1, value_of },
{ Metafunction::MFRK_metaInfo, 1, 1, template_of },
{ Metafunction::MFRK_bool, 3, 3, can_substitute },
{ Metafunction::MFRK_metaInfo, 3, 3, substitute },
{ Metafunction::MFRK_spliceFromArg, 2, 2, extract },
{ Metafunction::MFRK_bool, 1, 1, is_public },
{ Metafunction::MFRK_bool, 1, 1, is_protected },
{ Metafunction::MFRK_bool, 1, 1, is_private },
{ Metafunction::MFRK_bool, 1, 1, is_access_specified },
{ Metafunction::MFRK_metaInfo, 0, 0, access_context },
{ Metafunction::MFRK_bool, 1, 2, is_accessible },
{ Metafunction::MFRK_bool, 1, 1, is_virtual },
{ Metafunction::MFRK_bool, 1, 1, is_pure_virtual },
{ Metafunction::MFRK_bool, 1, 1, is_override },
{ Metafunction::MFRK_bool, 1, 1, is_deleted },
{ Metafunction::MFRK_bool, 1, 1, is_defaulted },
{ Metafunction::MFRK_bool, 1, 1, is_explicit },
{ Metafunction::MFRK_bool, 1, 1, is_noexcept },
{ Metafunction::MFRK_bool, 1, 1, is_bit_field },
{ Metafunction::MFRK_bool, 1, 1, is_enumerator },
{ Metafunction::MFRK_bool, 1, 1, is_const },
{ Metafunction::MFRK_bool, 1, 1, is_volatile },
{ Metafunction::MFRK_bool, 1, 1, is_lvalue_reference_qualified },
{ Metafunction::MFRK_bool, 1, 1, is_rvalue_reference_qualified },
{ Metafunction::MFRK_bool, 1, 1, has_static_storage_duration },
{ Metafunction::MFRK_bool, 1, 1, has_thread_storage_duration },
{ Metafunction::MFRK_bool, 1, 1, has_automatic_storage_duration },
{ Metafunction::MFRK_bool, 1, 1, has_internal_linkage },
{ Metafunction::MFRK_bool, 1, 1, has_module_linkage },
{ Metafunction::MFRK_bool, 1, 1, has_external_linkage },
{ Metafunction::MFRK_bool, 1, 1, has_linkage },
{ Metafunction::MFRK_bool, 1, 1, is_class_member },
{ Metafunction::MFRK_bool, 1, 1, is_namespace_member },
{ Metafunction::MFRK_bool, 1, 1, is_nonstatic_data_member },
{ Metafunction::MFRK_bool, 1, 1, is_static_member },
{ Metafunction::MFRK_bool, 1, 1, is_base },
{ Metafunction::MFRK_bool, 1, 1, is_data_member_spec },
{ Metafunction::MFRK_bool, 1, 1, is_namespace },
{ Metafunction::MFRK_bool, 1, 1, is_function },
{ Metafunction::MFRK_bool, 1, 1, is_variable },
{ Metafunction::MFRK_bool, 1, 1, is_type },
{ Metafunction::MFRK_bool, 1, 1, is_alias },
{ Metafunction::MFRK_bool, 1, 1, is_incomplete_type },
{ Metafunction::MFRK_bool, 1, 1, is_template },
{ Metafunction::MFRK_bool, 1, 1, is_function_template },
{ Metafunction::MFRK_bool, 1, 1, is_variable_template },
{ Metafunction::MFRK_bool, 1, 1, is_class_template },
{ Metafunction::MFRK_bool, 1, 1, is_alias_template },
{ Metafunction::MFRK_bool, 1, 1, is_conversion_function_template },
{ Metafunction::MFRK_bool, 1, 1, is_operator_function_template },
{ Metafunction::MFRK_bool, 1, 1, is_literal_operator_template },
{ Metafunction::MFRK_bool, 1, 1, is_constructor_template },
{ Metafunction::MFRK_bool, 1, 1, is_concept },
{ Metafunction::MFRK_bool, 1, 1, is_structured_binding },
{ Metafunction::MFRK_bool, 1, 1, is_value },
{ Metafunction::MFRK_bool, 1, 1, is_object },
{ Metafunction::MFRK_bool, 1, 1, has_template_arguments },
{ Metafunction::MFRK_bool, 1, 1, has_default_member_initializer },
{ Metafunction::MFRK_bool, 1, 1, is_conversion_function },
{ Metafunction::MFRK_bool, 1, 1, is_operator_function },
{ Metafunction::MFRK_bool, 1, 1, is_literal_operator },
{ Metafunction::MFRK_bool, 1, 1, is_constructor },
{ Metafunction::MFRK_bool, 1, 1, is_default_constructor },
{ Metafunction::MFRK_bool, 1, 1, is_copy_constructor },
{ Metafunction::MFRK_bool, 1, 1, is_move_constructor },
{ Metafunction::MFRK_bool, 1, 1, is_assignment },
{ Metafunction::MFRK_bool, 1, 1, is_copy_assignment },
{ Metafunction::MFRK_bool, 1, 1, is_move_assignment },
{ Metafunction::MFRK_bool, 1, 1, is_destructor },
{ Metafunction::MFRK_bool, 1, 1, is_special_member_function },
{ Metafunction::MFRK_bool, 1, 1, is_user_provided },
{ Metafunction::MFRK_metaInfo, 2, 2, reflect_result },
{ Metafunction::MFRK_metaInfo, 5, 5, reflect_invoke },
{ Metafunction::MFRK_metaInfo, 10, 10, data_member_spec },
{ Metafunction::MFRK_metaInfo, 3, 3, define_class },
{ Metafunction::MFRK_sizeT, 1, 1, offset_of },
{ Metafunction::MFRK_sizeT, 1, 1, size_of },
{ Metafunction::MFRK_sizeT, 1, 1, bit_offset_of },
{ Metafunction::MFRK_sizeT, 1, 1, bit_size_of },
{ Metafunction::MFRK_sizeT, 1, 1, alignment_of },
{ Metafunction::MFRK_spliceFromArg, 5, 5, define_static_string },
// P3096 metafunction extensions
{ Metafunction::MFRK_metaInfo, 3, 3, get_ith_parameter_of },
{ Metafunction::MFRK_bool, 1, 1, has_consistent_identifier },
{ Metafunction::MFRK_bool, 1, 1, has_ellipsis_parameter },
{ Metafunction::MFRK_bool, 1, 1, has_default_argument },
{ Metafunction::MFRK_bool, 1, 1, is_explicit_object_parameter },
{ Metafunction::MFRK_bool, 1, 1, is_function_parameter },
{ Metafunction::MFRK_metaInfo, 1, 1, return_type_of },
};
constexpr const unsigned NumMetafunctions = sizeof(Metafunctions) /
sizeof(Metafunction);
// -----------------------------------------------------------------------------
// class Metafunction implementation
// -----------------------------------------------------------------------------
bool Metafunction::evaluate(APValue &Result, Sema &S, EvalFn Evaluator,
DiagFn Diagnoser, QualType ResultTy,
SourceRange Range, ArrayRef<Expr *> Args) const {
return ImplFn(Result, S, Evaluator, Diagnoser, ResultTy, Range, Args);
}
bool Metafunction::Lookup(unsigned ID, const Metafunction *&result) {
if (ID >= NumMetafunctions)
return true;
result = &Metafunctions[ID];
return false;
}
// -----------------------------------------------------------------------------
// Metafunction helper functions
// -----------------------------------------------------------------------------
static APValue makeBool(ASTContext &C, bool B) {
return APValue(C.MakeIntValue(B, C.BoolTy));
}
static APValue makeReflection(QualType QT) {
return APValue(ReflectionKind::Type, QT.getAsOpaquePtr());
}
static APValue makeReflection(Decl *D) {
if (isa<NamespaceDecl>(D) || isa<NamespaceAliasDecl>(D) ||
isa<TranslationUnitDecl>(D))
return APValue(ReflectionKind::Namespace, D);
return APValue(ReflectionKind::Declaration, D);
}
static APValue makeReflection(TemplateName TName) {
return APValue(ReflectionKind::Template, TName.getAsVoidPointer());
}
static APValue makeReflection(CXXBaseSpecifier *Base) {
return APValue(ReflectionKind::BaseSpecifier, Base);
}
static APValue makeReflection(TagDataMemberSpec *TDMS) {
return APValue(ReflectionKind::DataMemberSpec, TDMS);
}
static Expr *makeStrLiteral(StringRef Str, ASTContext &C, bool Utf8) {
QualType ConstCharTy = (Utf8 ? C.Char8Ty : C.CharTy).withConst();
// Get the type for 'const char[Str.size()]'.
QualType StrLitTy =
C.getConstantArrayType(ConstCharTy, llvm::APInt(32, Str.size() + 1),
nullptr, ArraySizeModifier::Normal, 0);
// Create a string literal having type 'const char [Str.size()]'.
StringLiteralKind SLK = Utf8 ? StringLiteralKind::UTF8 :
StringLiteralKind::Ordinary;
return StringLiteral::Create(C, Str, SLK, false, StrLitTy, SourceLocation{});
}
static bool SetAndSucceed(APValue &Out, const APValue &Result) {
Out = Result;
return false;
}
static TemplateName findTemplateOfDecl(const Decl *D) {
TemplateDecl *TDecl = nullptr;
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
if (FunctionTemplateSpecializationInfo *Info =
FD->getTemplateSpecializationInfo())
TDecl = Info->getTemplate();
} else if (const auto *VD = dyn_cast<VarDecl>(D)) {
if (const auto *P = VD->getTemplateInstantiationPattern())
VD = P;
TDecl = VD->getDescribedVarTemplate();
}
assert(!isa<ClassTemplateSpecializationDecl>(D) &&
"use findTemplateOfType instead");
return TDecl ? TemplateName(TDecl) : TemplateName();
}
static TemplateName findTemplateOfType(QualType QT) {
// If it's an ElaboratedType, get the underlying NamedType.
if (const ElaboratedType *ET = dyn_cast<ElaboratedType>(QT))
QT = ET->getNamedType();
if (auto *TST = dyn_cast<TemplateSpecializationType>(QT)) {
TemplateName TName = TST->getTemplateName();
if (TName.getKind() == TemplateName::QualifiedTemplate)
TName = TName.getAsQualifiedTemplateName()->getUnderlyingTemplate();
return TName;
}
if (auto *CXXRD = QT->getAsCXXRecordDecl())
if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(CXXRD))
return TemplateName(CTSD->getSpecializedTemplate());
return TemplateName();
}
static void getTemplateName(std::string &Result, ASTContext &C,
TemplateName TName) {
PrintingPolicy PP = C.getPrintingPolicy();
{
llvm::raw_string_ostream NameOut(Result);
TName.print(NameOut, PP, TemplateName::Qualified::None);
}
}
static void getDeclName(std::string &Result, ASTContext &C, Decl *D) {
if (TemplateName TName = findTemplateOfDecl(D); !TName.isNull())
return getTemplateName(Result, C, TName);
PrintingPolicy PP = C.getPrintingPolicy();
{
llvm::raw_string_ostream NameOut(Result);
if (auto *ND = dyn_cast<NamedDecl>(D);
ND && !isa<TemplateParamObjectDecl>(D))
ND->printName(NameOut, PP);
}
}
static bool getParameterName(ParmVarDecl *PVD, std::string &Out) {
StringRef FirstNameSeen = PVD->getName();
unsigned ParamIdx = PVD->getFunctionScopeIndex();
FunctionDecl *FD = cast<FunctionDecl>(PVD->getDeclContext());
FD = FD->getMostRecentDecl();
bool Consistent = true;
PVD = FD->getParamDecl(ParamIdx);
while (PVD) {
FD = cast<FunctionDecl>(PVD->getDeclContext());
FD = FD->getPreviousDecl();
if (!FD) {
Out = FirstNameSeen;
return true;
}
PVD = FD->getParamDecl(ParamIdx);
assert(PVD);
if (IdentifierInfo *II = PVD->getIdentifier()) {
if (FirstNameSeen.empty()) {
FirstNameSeen = II->getName();
} else if (II->getName() != FirstNameSeen) {
Consistent = false;
break;
}
}
}
Out = FirstNameSeen;
return Consistent;
}
static NamedDecl *findTypeDecl(QualType QT) {
// If it's an ElaboratedType, get the underlying NamedType.
if (const ElaboratedType *ET = dyn_cast<ElaboratedType>(QT))
QT = ET->getNamedType();
// Get the type's declaration.
NamedDecl *D = nullptr;
if (auto *TDT = dyn_cast<TypedefType>(QT))
D = TDT->getDecl();
else if (auto *UT = dyn_cast<UsingType>(QT))
D = UT->getFoundDecl();
else if (auto *TD = QT->getAsTagDecl())
return TD;
else if (auto *TT = dyn_cast<TagType>(QT))
D = TT->getDecl();
else if (auto *UUTD = dyn_cast<UnresolvedUsingType>(QT))
D = UUTD->getDecl();
else if (auto *TS = dyn_cast<TemplateSpecializationType>(QT)) {
if (auto *CTD = dyn_cast<ClassTemplateDecl>(
TS->getTemplateName().getAsTemplateDecl())) {
void *InsertPos;
D = CTD->findSpecialization(TS->template_arguments(), InsertPos);
}
} else if (auto *STTP = dyn_cast<SubstTemplateTypeParmType>(QT))
D = findTypeDecl(STTP->getReplacementType());
else if (auto *ICNT = dyn_cast<InjectedClassNameType>(QT))
D = ICNT->getDecl();
else if (auto *DTT = dyn_cast<DecltypeType>(QT))
D = findTypeDecl(DTT->getUnderlyingType());
return D;
}
static bool findTypeDeclLoc(APValue &Result, ASTContext &C, EvalFn Evaluator,
QualType ResultTy, QualType QT) {
// If it's an ElaboratedType, get the underlying NamedType.
if (const ElaboratedType *ET = dyn_cast<ElaboratedType>(QT))
QT = ET->getNamedType();
// Get the type's declaration.
NamedDecl *D = const_cast<NamedDecl *>(findTypeDecl(QT));
SourceLocExpr *SLE =
new (C) SourceLocExpr(C, SourceLocIdentKind::SourceLocStruct,
ResultTy,
D ? D->getLocation() : SourceLocation(),
SourceLocation(),
D ? D->getDeclContext() : nullptr);
return !Evaluator(Result, SLE, true);
}
static bool findDeclLoc(APValue &Result, ASTContext &C, EvalFn Evaluator,
QualType ResultTy, Decl *D) {
SourceLocExpr *SLE =
new (C) SourceLocExpr(C, SourceLocIdentKind::SourceLocStruct,
ResultTy,
D ? D->getLocation() : SourceLocation(),
SourceLocation(),
D ? D->getDeclContext() : nullptr);
return !Evaluator(Result, SLE, true);
}
static bool findBaseSpecLoc(APValue &Result, ASTContext &C, EvalFn Evaluator,
QualType ResultTy, CXXBaseSpecifier *B) {
SourceLocExpr *SLE =
new (C) SourceLocExpr(C, SourceLocIdentKind::SourceLocStruct,
ResultTy, B->getBeginLoc(),
SourceLocation(), nullptr);
return !Evaluator(Result, SLE, true);
}
static QualType desugarType(QualType QT, bool UnwrapAliases, bool DropCV,
bool DropRefs) {
bool IsConst = QT.isConstQualified();
bool IsVolatile = QT.isVolatileQualified();
while (true) {
QT = QualType(QT.getTypePtr(), 0);
if (const ElaboratedType *ET = dyn_cast<ElaboratedType>(QT))
QT = ET->getNamedType();
else if (auto *TDT = dyn_cast<TypedefType>(QT); TDT && UnwrapAliases)
QT = TDT->desugar();
else if (auto *UT = dyn_cast<UsingType>(QT); TDT && UnwrapAliases)
QT = UT->desugar();
else if (auto *TST = dyn_cast<TemplateSpecializationType>(QT);
TST && UnwrapAliases && TST->isTypeAlias())
QT = TST->getAliasedType();
else if (auto *AT = dyn_cast<AutoType>(QT))
QT = AT->desugar();
else if (auto *RT = dyn_cast<ReferenceType>(QT); RT && DropRefs)
QT = RT->getPointeeType();
else if (auto *STTP = dyn_cast<SubstTemplateTypeParmType>(QT))
QT = STTP->getReplacementType();
else if (auto *RST = dyn_cast<ReflectionSpliceType>(QT))
QT = RST->desugar();
else
break;
}
if (!DropCV) {
if (IsConst)
QT = QT.withConst();
if (IsVolatile)
QT = QT.withVolatile();
}
return QT;
}
static bool isTypeAlias(QualType QT) {
// If it's an ElaboratedType, get the underlying NamedType.
if (const ElaboratedType *ET = dyn_cast<ElaboratedType>(QT))
QT = ET->getNamedType();
// If it's a TypedefType, it's an alias.
return QT->isTypedefNameType();
}
static void expandTemplateArgPacks(ArrayRef<TemplateArgument> Args,
SmallVectorImpl<TemplateArgument> &Out) {
for (const TemplateArgument &Arg : Args)
if (Arg.getKind() == TemplateArgument::Pack)
for (const TemplateArgument &TA : Arg.getPackAsArray())
Out.push_back(TA);
else
Out.push_back(Arg);
}
bool getTemplateArgumentsFromType(QualType QT,
SmallVectorImpl<TemplateArgument> &Out) {
// Obtain the template arguments from the Type* representation
if (auto asTmplSpecialization = QT->getAs<TemplateSpecializationType>())
expandTemplateArgPacks(asTmplSpecialization->template_arguments(), Out);
else if (auto DTST = QT->getAs<DependentTemplateSpecializationType>())
expandTemplateArgPacks(DTST->template_arguments(), Out);
else if (auto *CTSD = dyn_cast_or_null<ClassTemplateSpecializationDecl>(
QT->getAsRecordDecl()))
expandTemplateArgPacks(CTSD->getTemplateArgs().asArray(), Out);
else
return true;
return false;
}
bool getTemplateArgumentsFromDecl(Decl* D,
SmallVectorImpl<TemplateArgument> &Out) {
if (auto FD = dyn_cast<FunctionDecl>(D)) {
if (auto templArgs = FD->getTemplateSpecializationArgs()) {
expandTemplateArgPacks(templArgs->asArray(), Out);
return false;
}
} else if (auto VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) {
expandTemplateArgPacks(VTSD->getTemplateArgs().asArray(), Out);
return false;
}
return true;
}
static APValue getNthTemplateArgument(Sema &S,
ArrayRef<TemplateArgument> templateArgs,
EvalFn Evaluator, APValue Sentinel,
size_t Idx) {
if (Idx >= templateArgs.size())
return Sentinel;
const auto& templArgument = templateArgs[Idx];
switch (templArgument.getKind()) {
case TemplateArgument::Type:
return makeReflection(templArgument.getAsType());
case TemplateArgument::Expression: {
Expr *TExpr = templArgument.getAsExpr();
APValue ArgResult;
bool success = Evaluator(ArgResult, TExpr, !TExpr->isLValue());
assert(success);
return ArgResult.Lift(TExpr->getType());
}
case TemplateArgument::Template: {
TemplateName TName = templArgument.getAsTemplate();
if (TName.getKind() == TemplateName::QualifiedTemplate)
TName = TName.getAsQualifiedTemplateName()->getUnderlyingTemplate();
return makeReflection(TName);
} case TemplateArgument::Declaration:
return makeReflection(templArgument.getAsDecl());
case TemplateArgument::NullPtr: {
APValue NullPtrValue((ValueDecl *)nullptr,
CharUnits::fromQuantity(
S.Context.getTargetNullPointerValue(
templArgument.getNullPtrType())),
APValue::NoLValuePath(),
/*IsNullPtr=*/true);
return NullPtrValue.Lift(templArgument.getNullPtrType());
}
case TemplateArgument::StructuralValue: {
APValue SV = templArgument.getAsStructuralValue();
return SV.Lift(templArgument.getStructuralValueType());
}
case TemplateArgument::Integral: {
APValue IV(templArgument.getAsIntegral());
return IV.Lift(templArgument.getIntegralType());
}
case TemplateArgument::SpliceSpecifier:
llvm_unreachable("TemplateArgument::SpliceSpecifier should have been "
"transformed by now");
case TemplateArgument::Pack:
llvm_unreachable("Packs should be expanded before calling this");
// Could not get a test case to hit one of the below
case TemplateArgument::Null:
llvm_unreachable("TemplateArgument::Null not supported");
case TemplateArgument::TemplateExpansion:
llvm_unreachable("TemplateArgument::TemplateExpansion not supported");
}
llvm_unreachable("Unknown template argument type");
}
static bool isTemplateSpecialization(QualType QT) {
if (isa<UsingType>(QT) || isa<TypedefType>(QT))
return false;
return isa<TemplateSpecializationType>(QT) ||
isa<DependentTemplateSpecializationType>(QT) ||
isa_and_nonnull<ClassTemplateSpecializationDecl>(
QT->getAsCXXRecordDecl());
}
static size_t getBitOffsetOfField(ASTContext &C, const FieldDecl *FD) {
const RecordDecl *Parent = FD->getParent();
assert(Parent && "no parent for field!");
const ASTRecordLayout &Layout = C.getASTRecordLayout(Parent);
return Layout.getFieldOffset(FD->getFieldIndex());
}