-
Notifications
You must be signed in to change notification settings - Fork 231
/
reflect.h
5343 lines (4354 loc) · 207 KB
/
reflect.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
#ifndef REFLECT_H_CPP2
#define REFLECT_H_CPP2
//=== Cpp2 type declarations ====================================================
#include "cpp2util.h"
#line 1 "reflect.h2"
#line 22 "reflect.h2"
namespace cpp2 {
namespace meta {
#line 34 "reflect.h2"
class compiler_services;
#line 233 "reflect.h2"
class declaration_base;
#line 259 "reflect.h2"
class declaration;
#line 341 "reflect.h2"
class function_declaration;
#line 431 "reflect.h2"
class object_declaration;
#line 467 "reflect.h2"
class type_declaration;
#line 604 "reflect.h2"
class alias_declaration;
#line 1012 "reflect.h2"
class value_member_info;
#line 1530 "reflect.h2"
class expression_flags;
#line 1546 "reflect.h2"
class regex_token;
#line 1572 "reflect.h2"
class regex_token_check;
#line 1591 "reflect.h2"
class regex_token_code;
#line 1610 "reflect.h2"
class regex_token_empty;
#line 1626 "reflect.h2"
class regex_token_list;
#line 1665 "reflect.h2"
class parse_context_group_state;
#line 1726 "reflect.h2"
class parse_context_branch_reset_state;
#line 1769 "reflect.h2"
class parse_context;
#line 2167 "reflect.h2"
class generation_function_context;
#line 2185 "reflect.h2"
class generation_context;
#line 2383 "reflect.h2"
class alternative_token;
#line 2398 "reflect.h2"
class alternative_token_gen;
#line 2450 "reflect.h2"
class any_token;
#line 2468 "reflect.h2"
class char_token;
#line 2571 "reflect.h2"
class class_token;
#line 2786 "reflect.h2"
class group_ref_token;
#line 2917 "reflect.h2"
class group_token;
#line 3204 "reflect.h2"
class lookahead_token;
#line 3285 "reflect.h2"
class range_token;
#line 3433 "reflect.h2"
class special_range_token;
#line 3500 "reflect.h2"
template<typename Error_out> class regex_generator;
#line 3750 "reflect.h2"
}
}
//=== Cpp2 type definitions and function declarations ===========================
#line 1 "reflect.h2"
// Copyright (c) Herb Sutter
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//===========================================================================
// Reflection and meta
//===========================================================================
#include "parse.h"
#include "cpp2regex.h"
using namespace cpp2::regex;
#line 22 "reflect.h2"
namespace cpp2 {
namespace meta {
#line 34 "reflect.h2"
class compiler_services
{
#line 38 "reflect.h2"
private: std::vector<error_entry>* errors;
private: std::set<std::string>* includes;
private: int errors_original_size;
private: stable_vector<token>* generated_tokens;
private: cpp2::parser parser;
private: std::string metafunction_name {};
private: std::vector<std::string> metafunction_args {};
private: bool metafunctions_used {false};
#line 49 "reflect.h2"
public: explicit compiler_services(
std::vector<error_entry>* errors_,
std::set<std::string>* includes_,
stable_vector<token>* generated_tokens_
);
#line 65 "reflect.h2"
public: auto set_metafunction_name(cpp2::impl::in<std::string_view> name, cpp2::impl::in<std::vector<std::string>> args) & -> void;
#line 71 "reflect.h2"
public: [[nodiscard]] auto get_metafunction_name() const& -> std::string_view;
public: [[nodiscard]] auto get_argument(cpp2::impl::in<int> index) & -> std::string;
#line 81 "reflect.h2"
public: [[nodiscard]] auto get_arguments() & -> std::vector<std::string>;
#line 86 "reflect.h2"
public: [[nodiscard]] auto arguments_were_used() const& -> bool;
using parse_statement_ret = std::unique_ptr<statement_node>;
#line 88 "reflect.h2"
protected: [[nodiscard]] auto parse_statement(
std::string_view source
) & -> parse_statement_ret;
#line 141 "reflect.h2"
public: auto add_runtime_support_include(cpp2::impl::in<std::string_view> s) & -> void;
public: [[nodiscard]] virtual auto position() const -> source_position;
#line 152 "reflect.h2"
public: auto require(
cpp2::impl::in<bool> b,
cpp2::impl::in<std::string_view> msg
) const& -> void;
#line 163 "reflect.h2"
public: auto error(cpp2::impl::in<std::string_view> msg) const& -> void;
#line 175 "reflect.h2"
public: auto report_violation(auto const& msg) const& -> void;
#line 183 "reflect.h2"
public: [[nodiscard]] auto is_active() const& -> auto;
public: virtual ~compiler_services() noexcept;
public: compiler_services(compiler_services const& that);
#line 184 "reflect.h2"
};
#line 233 "reflect.h2"
class declaration_base
: public compiler_services {
#line 237 "reflect.h2"
protected: declaration_node* n;
protected: explicit declaration_base(
declaration_node* n_,
cpp2::impl::in<compiler_services> s
);
#line 250 "reflect.h2"
public: [[nodiscard]] auto position() const -> source_position override;
public: [[nodiscard]] auto print() const& -> std::string;
public: virtual ~declaration_base() noexcept;
public: declaration_base(declaration_base const& that);
#line 253 "reflect.h2"
};
#line 259 "reflect.h2"
class declaration
: public declaration_base {
#line 263 "reflect.h2"
public: explicit declaration(
declaration_node* n_,
cpp2::impl::in<compiler_services> s
);
#line 272 "reflect.h2"
public: [[nodiscard]] auto is_public() const& -> bool;
public: [[nodiscard]] auto is_protected() const& -> bool;
public: [[nodiscard]] auto is_private() const& -> bool;
public: [[nodiscard]] auto is_default_access() const& -> bool;
public: auto default_to_public() & -> void;
public: auto default_to_protected() & -> void;
public: auto default_to_private() & -> void;
public: [[nodiscard]] auto make_public() & -> bool;
public: [[nodiscard]] auto make_protected() & -> bool;
public: [[nodiscard]] auto make_private() & -> bool;
public: [[nodiscard]] auto has_name() const& -> bool;
public: [[nodiscard]] auto has_name(cpp2::impl::in<std::string_view> s) const& -> bool;
public: [[nodiscard]] auto name() const& -> std::string_view;
#line 293 "reflect.h2"
public: [[nodiscard]] auto has_initializer() const& -> bool;
public: [[nodiscard]] auto is_global() const& -> bool;
public: [[nodiscard]] auto is_function() const& -> bool;
public: [[nodiscard]] auto is_object() const& -> bool;
public: [[nodiscard]] auto is_base_object() const& -> bool;
public: [[nodiscard]] auto is_member_object() const& -> bool;
public: [[nodiscard]] auto is_type() const& -> bool;
public: [[nodiscard]] auto is_namespace() const& -> bool;
public: [[nodiscard]] auto is_alias() const& -> bool;
public: [[nodiscard]] auto is_type_alias() const& -> bool;
public: [[nodiscard]] auto is_namespace_alias() const& -> bool;
public: [[nodiscard]] auto is_object_alias() const& -> bool;
public: [[nodiscard]] auto is_function_expression() const& -> bool;
public: [[nodiscard]] auto as_function() const& -> function_declaration;
public: [[nodiscard]] auto as_object() const& -> object_declaration;
public: [[nodiscard]] auto as_type() const& -> type_declaration;
public: [[nodiscard]] auto as_alias() const& -> alias_declaration;
public: [[nodiscard]] auto get_parent() const& -> declaration;
public: [[nodiscard]] auto parent_is_function() const& -> bool;
public: [[nodiscard]] auto parent_is_object() const& -> bool;
public: [[nodiscard]] auto parent_is_type() const& -> bool;
public: [[nodiscard]] auto parent_is_namespace() const& -> bool;
public: [[nodiscard]] auto parent_is_alias() const& -> bool;
public: [[nodiscard]] auto parent_is_type_alias() const& -> bool;
public: [[nodiscard]] auto parent_is_namespace_alias() const& -> bool;
public: [[nodiscard]] auto parent_is_object_alias() const& -> bool;
public: [[nodiscard]] auto parent_is_polymorphic() const& -> bool;
public: auto mark_for_removal_from_enclosing_type() & -> void;
public: virtual ~declaration() noexcept;
public: declaration(declaration const& that);
#line 335 "reflect.h2"
};
#line 341 "reflect.h2"
class function_declaration
: public declaration {
#line 345 "reflect.h2"
public: explicit function_declaration(
declaration_node* n_,
cpp2::impl::in<compiler_services> s
);
#line 355 "reflect.h2"
public: [[nodiscard]] auto index_of_parameter_named(cpp2::impl::in<std::string_view> s) const& -> int;
public: [[nodiscard]] auto has_parameter_named(cpp2::impl::in<std::string_view> s) const& -> bool;
public: [[nodiscard]] auto has_in_parameter_named(cpp2::impl::in<std::string_view> s) const& -> bool;
public: [[nodiscard]] auto has_copy_parameter_named(cpp2::impl::in<std::string_view> s) const& -> bool;
public: [[nodiscard]] auto has_inout_parameter_named(cpp2::impl::in<std::string_view> s) const& -> bool;
public: [[nodiscard]] auto has_out_parameter_named(cpp2::impl::in<std::string_view> s) const& -> bool;
public: [[nodiscard]] auto has_move_parameter_named(cpp2::impl::in<std::string_view> s) const& -> bool;
public: [[nodiscard]] auto has_forward_parameter_named(cpp2::impl::in<std::string_view> s) const& -> bool;
public: [[nodiscard]] auto first_parameter_name() const& -> std::string;
public: [[nodiscard]] auto has_parameter_with_name_and_pass(cpp2::impl::in<std::string_view> s, cpp2::impl::in<passing_style> pass) const& -> bool;
public: [[nodiscard]] auto is_function_with_this() const& -> bool;
public: [[nodiscard]] auto is_virtual() const& -> bool;
public: [[nodiscard]] auto is_defaultable() const& -> bool;
public: [[nodiscard]] auto is_constructor() const& -> bool;
public: [[nodiscard]] auto is_default_constructor() const& -> bool;
public: [[nodiscard]] auto is_move() const& -> bool;
public: [[nodiscard]] auto is_swap() const& -> bool;
public: [[nodiscard]] auto is_constructor_with_that() const& -> bool;
public: [[nodiscard]] auto is_constructor_with_in_that() const& -> bool;
public: [[nodiscard]] auto is_constructor_with_move_that() const& -> bool;
public: [[nodiscard]] auto is_assignment() const& -> bool;
public: [[nodiscard]] auto is_assignment_with_that() const& -> bool;
public: [[nodiscard]] auto is_assignment_with_in_that() const& -> bool;
public: [[nodiscard]] auto is_assignment_with_move_that() const& -> bool;
public: [[nodiscard]] auto is_destructor() const& -> bool;
public: [[nodiscard]] auto is_copy_or_move() const& -> bool;
public: [[nodiscard]] auto has_declared_return_type() const& -> bool;
public: [[nodiscard]] auto has_deduced_return_type() const& -> bool;
public: [[nodiscard]] auto has_bool_return_type() const& -> bool;
public: [[nodiscard]] auto has_non_void_return_type() const& -> bool;
public: [[nodiscard]] auto unnamed_return_type() const& -> std::string;
public: [[nodiscard]] auto get_parameters() const& -> std::vector<object_declaration>;
#line 402 "reflect.h2"
public: [[nodiscard]] auto is_binary_comparison_function() const& -> bool;
public: auto default_to_virtual() & -> void;
public: [[nodiscard]] auto make_virtual() & -> bool;
public: auto add_initializer(cpp2::impl::in<std::string_view> source) & -> void;
public: function_declaration(function_declaration const& that);
#line 425 "reflect.h2"
};
#line 431 "reflect.h2"
class object_declaration
: public declaration {
#line 435 "reflect.h2"
public: explicit object_declaration(
declaration_node* n_,
cpp2::impl::in<compiler_services> s
);
#line 445 "reflect.h2"
public: [[nodiscard]] auto is_const() const& -> bool;
public: [[nodiscard]] auto has_wildcard_type() const& -> bool;
public: [[nodiscard]] auto type() const& -> std::string;
#line 455 "reflect.h2"
public: [[nodiscard]] auto initializer() const& -> std::string;
public: object_declaration(object_declaration const& that);
#line 461 "reflect.h2"
};
#line 467 "reflect.h2"
class type_declaration
: public declaration {
#line 471 "reflect.h2"
public: explicit type_declaration(
declaration_node* n_,
cpp2::impl::in<compiler_services> s
);
#line 481 "reflect.h2"
public: auto reserve_names(cpp2::impl::in<std::string_view> name, auto&& ...etc) const& -> void;
#line 495 "reflect.h2"
public: [[nodiscard]] auto is_polymorphic() const& -> bool;
public: [[nodiscard]] auto is_final() const& -> bool;
public: [[nodiscard]] auto make_final() & -> bool;
public: [[nodiscard]] auto get_member_functions() const& -> std::vector<function_declaration>;
#line 510 "reflect.h2"
public: [[nodiscard]] auto get_member_functions_needing_initializer() const& -> std::vector<function_declaration>;
#line 525 "reflect.h2"
public: [[nodiscard]] auto get_member_objects() const& -> std::vector<object_declaration>;
#line 535 "reflect.h2"
public: [[nodiscard]] auto get_member_types() const& -> std::vector<type_declaration>;
#line 545 "reflect.h2"
public: [[nodiscard]] auto get_member_aliases() const& -> std::vector<alias_declaration>;
#line 555 "reflect.h2"
public: [[nodiscard]] auto get_members() const& -> std::vector<declaration>;
struct query_declared_value_set_functions_ret { bool out_this_in_that; bool out_this_move_that; bool inout_this_in_that; bool inout_this_move_that; };
#line 565 "reflect.h2"
public: [[nodiscard]] auto query_declared_value_set_functions() const& -> query_declared_value_set_functions_ret;
#line 580 "reflect.h2"
public: auto add_member(cpp2::impl::in<std::string_view> source) & -> void;
#line 594 "reflect.h2"
public: auto remove_marked_members() & -> void;
public: auto remove_all_members() & -> void;
public: auto disable_member_function_generation() & -> void;
public: type_declaration(type_declaration const& that);
#line 598 "reflect.h2"
};
#line 604 "reflect.h2"
class alias_declaration
: public declaration {
#line 608 "reflect.h2"
public: explicit alias_declaration(
declaration_node* n_,
cpp2::impl::in<compiler_services> s
);
public: alias_declaration(alias_declaration const& that);
#line 617 "reflect.h2"
};
#line 632 "reflect.h2"
auto add_virtual_destructor(meta::type_declaration& t) -> void;
#line 650 "reflect.h2"
auto interface(meta::type_declaration& t) -> void;
#line 696 "reflect.h2"
auto polymorphic_base(meta::type_declaration& t) -> void;
#line 741 "reflect.h2"
auto ordered_impl(
meta::type_declaration& t,
cpp2::impl::in<std::string_view> ordering
) -> void;
#line 770 "reflect.h2"
auto ordered(meta::type_declaration& t) -> void;
#line 778 "reflect.h2"
auto weakly_ordered(meta::type_declaration& t) -> void;
#line 786 "reflect.h2"
auto partially_ordered(meta::type_declaration& t) -> void;
#line 808 "reflect.h2"
auto copyable(meta::type_declaration& t) -> void;
#line 842 "reflect.h2"
auto basic_value(meta::type_declaration& t) -> void;
#line 870 "reflect.h2"
auto value(meta::type_declaration& t) -> void;
#line 876 "reflect.h2"
auto weakly_ordered_value(meta::type_declaration& t) -> void;
#line 882 "reflect.h2"
auto partially_ordered_value(meta::type_declaration& t) -> void;
#line 911 "reflect.h2"
auto cpp1_rule_of_zero(meta::type_declaration& t) -> void;
#line 948 "reflect.h2"
auto cpp2_struct(meta::type_declaration& t) -> void;
#line 1012 "reflect.h2"
class value_member_info {
public: std::string name;
public: std::string type;
public: std::string value;
public: value_member_info(auto const& name_, auto const& type_, auto const& value_);
#line 1016 "reflect.h2"
};
auto basic_enum(
meta::type_declaration& t,
auto const& nextval,
cpp2::impl::in<bool> bitwise
) -> void;
#line 1282 "reflect.h2"
auto cpp2_enum(meta::type_declaration& t) -> void;
#line 1309 "reflect.h2"
auto flag_enum(meta::type_declaration& t) -> void;
#line 1355 "reflect.h2"
auto cpp2_union(meta::type_declaration& t) -> void;
#line 1506 "reflect.h2"
auto print(cpp2::impl::in<meta::type_declaration> t) -> void;
#line 1526 "reflect.h2"
using error_func = std::function<void(cpp2::impl::in<std::string> x)>;
#line 1530 "reflect.h2"
class expression_flags
{
private: cpp2::u8 _value; private: constexpr expression_flags(cpp2::impl::in<cpp2::i64> _val);
private: constexpr auto operator=(cpp2::impl::in<cpp2::i64> _val) -> expression_flags& ;
public: constexpr auto operator|=(expression_flags const& that) & -> void;
public: constexpr auto operator&=(expression_flags const& that) & -> void;
public: constexpr auto operator^=(expression_flags const& that) & -> void;
public: [[nodiscard]] constexpr auto operator|(expression_flags const& that) const& -> expression_flags;
public: [[nodiscard]] constexpr auto operator&(expression_flags const& that) const& -> expression_flags;
public: [[nodiscard]] constexpr auto operator^(expression_flags const& that) const& -> expression_flags;
public: [[nodiscard]] constexpr auto has(expression_flags const& that) const& -> bool;
public: constexpr auto set(expression_flags const& that) & -> void;
public: constexpr auto clear(expression_flags const& that) & -> void;
public: static const expression_flags case_insensitive;
public: static const expression_flags multiple_lines;
public: static const expression_flags single_line;
public: static const expression_flags no_group_captures;
public: static const expression_flags perl_code_syntax;
public: static const expression_flags perl_code_syntax_in_classes;
public: static const expression_flags none;
public: [[nodiscard]] constexpr auto get_raw_value() const& -> cpp2::u8;
public: constexpr explicit expression_flags();
public: constexpr expression_flags(expression_flags const& that);
public: constexpr auto operator=(expression_flags const& that) -> expression_flags& ;
public: constexpr expression_flags(expression_flags&& that) noexcept;
public: constexpr auto operator=(expression_flags&& that) noexcept -> expression_flags& ;
public: [[nodiscard]] auto operator<=>(expression_flags const& that) const& -> std::strong_ordering = default;
public: [[nodiscard]] auto to_string_impl(cpp2::impl::in<std::string_view> prefix, cpp2::impl::in<std::string_view> separator) const& -> std::string;
public: [[nodiscard]] auto to_string() const& -> std::string;
public: [[nodiscard]] auto to_code() const& -> std::string;
public: [[nodiscard]] static auto from_string(cpp2::impl::in<std::string_view> s) -> expression_flags;
public: [[nodiscard]] static auto from_code(cpp2::impl::in<std::string_view> s) -> expression_flags;
#line 1538 "reflect.h2"
};
#line 1546 "reflect.h2"
class regex_token
{
public: std::string string_rep;
public: explicit regex_token(cpp2::impl::in<std::string> str);
#line 1554 "reflect.h2"
public: explicit regex_token();
#line 1559 "reflect.h2"
public: virtual auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void = 0;
public: virtual auto add_groups([[maybe_unused]] std::set<int>& unnamed_param_2) const -> void;
public: [[nodiscard]] auto to_string() const& -> std::string;
public: auto set_string(cpp2::impl::in<std::string> s) & -> void;
public: virtual ~regex_token() noexcept;
public: regex_token(regex_token const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(regex_token const&) -> void = delete;
#line 1564 "reflect.h2"
};
using token_ptr = std::shared_ptr<regex_token>;
using token_vec = std::vector<token_ptr>;
#line 1570 "reflect.h2"
// Adds a check in code generation.
//
class regex_token_check
: public regex_token {
#line 1576 "reflect.h2"
private: std::string check;
public: explicit regex_token_check(cpp2::impl::in<std::string> str, cpp2::impl::in<std::string> check_);
#line 1583 "reflect.h2"
public: auto generate_code(generation_context& ctx) const -> void override;
public: virtual ~regex_token_check() noexcept;
public: regex_token_check(regex_token_check const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(regex_token_check const&) -> void = delete;
#line 1586 "reflect.h2"
};
#line 1589 "reflect.h2"
// Adds code in code generation.
//
class regex_token_code
: public regex_token {
#line 1595 "reflect.h2"
private: std::string code;
public: explicit regex_token_code(cpp2::impl::in<std::string> str, cpp2::impl::in<std::string> code_);
#line 1602 "reflect.h2"
public: auto generate_code(generation_context& ctx) const -> void override;
public: virtual ~regex_token_code() noexcept;
public: regex_token_code(regex_token_code const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(regex_token_code const&) -> void = delete;
#line 1605 "reflect.h2"
};
#line 1608 "reflect.h2"
// Token that does not influence the matching. E.g. comment.
//
class regex_token_empty
: public regex_token {
#line 1614 "reflect.h2"
public: explicit regex_token_empty(cpp2::impl::in<std::string> str);
#line 1618 "reflect.h2"
public: auto generate_code([[maybe_unused]] generation_context& unnamed_param_2) const -> void override;
public: virtual ~regex_token_empty() noexcept;
public: regex_token_empty(regex_token_empty const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(regex_token_empty const&) -> void = delete;
#line 1621 "reflect.h2"
};
#line 1624 "reflect.h2"
// Represents a list of regex tokens as one token.
//
class regex_token_list
: public regex_token {
#line 1630 "reflect.h2"
public: token_vec tokens;
public: explicit regex_token_list(cpp2::impl::in<token_vec> t);
#line 1637 "reflect.h2"
public: auto generate_code(generation_context& ctx) const -> void override;
#line 1643 "reflect.h2"
public: auto add_groups(std::set<int>& groups) const -> void override;
#line 1649 "reflect.h2"
public: [[nodiscard]] static auto gen_string(cpp2::impl::in<token_vec> vec) -> std::string;
public: virtual ~regex_token_list() noexcept;
public: regex_token_list(regex_token_list const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(regex_token_list const&) -> void = delete;
#line 1656 "reflect.h2"
};
#line 1659 "reflect.h2"
//
// Parse and generation context.
//
// State of the current capturing group. See '(<pattern>)'
//
class parse_context_group_state
{
public: token_vec cur_match_list {}; // Current list of matchers.
public: token_vec alternate_match_lists {}; // List of alternate matcher lists. E.g. ab|cd|xy.
public: expression_flags modifiers {}; // Current modifiers for the group/regular expression.
// Start a new alternative.
public: auto next_alternative() & -> void;
#line 1679 "reflect.h2"
// Swap this state with the other one.
public: auto swap(parse_context_group_state& t) & -> void;
#line 1686 "reflect.h2"
// Convert this state into a regex token.
public: [[nodiscard]] auto get_as_token() & -> token_ptr;
#line 1698 "reflect.h2"
// Add a token to the current matcher list.
public: auto add(cpp2::impl::in<token_ptr> token) & -> void;
#line 1703 "reflect.h2"
// True if current matcher list is empty.
public: [[nodiscard]] auto empty() const& -> bool;
#line 1707 "reflect.h2"
// Apply optimizations to the matcher list.
public: static auto post_process_list(token_vec& list) -> void;
public: parse_context_group_state(auto const& cur_match_list_, auto const& alternate_match_lists_, auto const& modifiers_);
public: parse_context_group_state();
#line 1721 "reflect.h2"
};
#line 1724 "reflect.h2"
// State for the branch reset. Takes care of the group numbering. See '(|<pattern>)'.
//
class parse_context_branch_reset_state
{
public: bool is_active {false}; // If we have a branch reset group.
public: int cur_group {1}; // Next group identifier. 0 == global capture group.
public: int max_group {1}; // Maximum group identifier generated.
public: int from {1}; // Starting identifier on new alternative branch.
// Next group identifier.
public: [[nodiscard]] auto next() & -> int;
#line 1742 "reflect.h2"
// Set next group identifier.
public: auto set_next(cpp2::impl::in<int> g) & -> void;
#line 1748 "reflect.h2"
// Start a new alternative branch.
public: auto next_alternative() & -> void;
#line 1755 "reflect.h2"
// Initialize for a branch reset group.
public: auto set_active_reset(cpp2::impl::in<int> restart) & -> void;
public: parse_context_branch_reset_state(auto const& is_active_, auto const& cur_group_, auto const& max_group_, auto const& from_);
public: parse_context_branch_reset_state();
#line 1762 "reflect.h2"
};
#line 1765 "reflect.h2"
// Context during parsing of the regular expressions.
//
// Keeps track of the distributed group identifiers, current parsed group and branch resets.
//
class parse_context
{
private: std::string_view regex; // Regular expression string.
private: size_t pos {0}; // Current parsing position.
private: token_ptr root; // Token representing the regular expression.
private: parse_context_group_state cur_group_state {};
private: parse_context_branch_reset_state cur_branch_reset_state {};
#line 1779 "reflect.h2"
public: std::map<std::string,int> named_groups {};
private: error_func error_out; // TODO: Declaring std::function<void(std::string)> fails for cpp2.
private: bool has_error {false};
public: explicit parse_context(cpp2::impl::in<std::string_view> r, auto const& e);
#line 1790 "reflect.h2"
// State management functions
//
// Returned group state needs to be stored and provided in `end_group`.
public: [[nodiscard]] auto start_group() & -> parse_context_group_state;
#line 1803 "reflect.h2"
// `old_state` argument needs to be from start group.
public: [[nodiscard]] auto end_group(cpp2::impl::in<parse_context_group_state> old_state) & -> token_ptr;
#line 1811 "reflect.h2"
public: [[nodiscard]] auto get_modifiers() const& -> expression_flags;
#line 1815 "reflect.h2"
public: auto set_modifiers(cpp2::impl::in<expression_flags> mod) & -> void;
#line 1819 "reflect.h2"
// Branch reset management functions
//
public: [[nodiscard]] auto branch_reset_new_state() & -> parse_context_branch_reset_state;
#line 1831 "reflect.h2"
public: auto branch_reset_restore_state(cpp2::impl::in<parse_context_branch_reset_state> old_state) & -> void;
#line 1838 "reflect.h2"
public: auto next_alternative() & -> void;
#line 1844 "reflect.h2"
// Regex token management
//
public: auto add_token(cpp2::impl::in<token_ptr> token) & -> void;
#line 1850 "reflect.h2"
public: [[nodiscard]] auto has_token() const& -> bool;
#line 1854 "reflect.h2"
public: [[nodiscard]] auto pop_token() & -> token_ptr;
#line 1865 "reflect.h2"
public: [[nodiscard]] auto get_as_token() & -> token_ptr;
#line 1869 "reflect.h2"
// Group management
//
public: [[nodiscard]] auto get_cur_group() const& -> int;
#line 1875 "reflect.h2"
public: [[nodiscard]] auto next_group() & -> int;
#line 1879 "reflect.h2"
public: auto set_named_group(cpp2::impl::in<std::string> name, cpp2::impl::in<int> id) & -> void;
#line 1886 "reflect.h2"
public: [[nodiscard]] auto get_named_group(cpp2::impl::in<std::string> name) const& -> int;
#line 1897 "reflect.h2"
// Position management functions
//
public: [[nodiscard]] auto current() const& -> char;
// Get the next token in the regex, skipping spaces according to the parameters. See `x` and `xx` modifiers.
private: [[nodiscard]] auto get_next_position(cpp2::impl::in<bool> in_class, cpp2::impl::in<bool> no_skip) const& -> size_t;
#line 1941 "reflect.h2"
// Return true if next token is available.
private: [[nodiscard]] auto next_impl(cpp2::impl::in<bool> in_class, cpp2::impl::in<bool> no_skip) & -> bool;
#line 1953 "reflect.h2"
public: [[nodiscard]] auto next() & -> auto;
public: [[nodiscard]] auto next_in_class() & -> auto;
public: [[nodiscard]] auto next_no_skip() & -> auto;
public: [[nodiscard]] auto next_n(cpp2::impl::in<int> n) & -> bool;
#line 1966 "reflect.h2"
public: [[nodiscard]] auto has_next() const& -> bool;
private: [[nodiscard]] auto grab_until_impl(cpp2::impl::in<std::string> e, cpp2::impl::out<std::string> r, cpp2::impl::in<bool> any) & -> bool;
#line 1989 "reflect.h2"
public: [[nodiscard]] auto grab_until(cpp2::impl::in<std::string> e, cpp2::impl::out<std::string> r) & -> auto;
public: [[nodiscard]] auto grab_until(cpp2::impl::in<char> e, cpp2::impl::out<std::string> r) & -> auto;
public: [[nodiscard]] auto grab_until_one_of(cpp2::impl::in<std::string> e, cpp2::impl::out<std::string> r) & -> auto;
public: [[nodiscard]] auto grab_n(cpp2::impl::in<int> n, cpp2::impl::out<std::string> r) & -> bool;
#line 2006 "reflect.h2"
public: [[nodiscard]] auto grab_number() & -> std::string;
#line 2027 "reflect.h2"
private: [[nodiscard]] auto peek_impl(cpp2::impl::in<bool> in_class) const& -> char;
#line 2037 "reflect.h2"
public: [[nodiscard]] auto peek() const& -> auto;
public: [[nodiscard]] auto peek_in_class() const& -> auto;
#line 2041 "reflect.h2"
// Parsing functions
//
public: [[nodiscard]] auto parser_group_modifiers(cpp2::impl::in<std::string> change_str, expression_flags& parser_modifiers) & -> bool;
#line 2097 "reflect.h2"
public: [[nodiscard]] auto parse_until(cpp2::impl::in<char> term) & -> bool;
#line 2135 "reflect.h2"
public: [[nodiscard]] auto parse(cpp2::impl::in<std::string> modifiers) & -> bool;
#line 2150 "reflect.h2"
// Misc functions
public: [[nodiscard]] auto get_pos() const& -> auto;
public: [[nodiscard]] auto get_range(cpp2::impl::in<size_t> start, cpp2::impl::in<size_t> end) const& -> auto;
public: [[nodiscard]] auto valid() const& -> bool;
public: [[nodiscard]] auto error(cpp2::impl::in<std::string> err) & -> token_ptr;
public: parse_context(parse_context const&) = delete; /* No 'that' constructor, suppress copy */
public: auto operator=(parse_context const&) -> void = delete;
#line 2161 "reflect.h2"
};
#line 2164 "reflect.h2"
// Context for one function generation. Generation of functions can be interleaved,
// therefore we buffer the code for one function here.
//
class generation_function_context {
public: std::string code {""};
public: std::string tabs {""};
public: auto add_tabs(cpp2::impl::in<int> c) & -> void;
#line 2178 "reflect.h2"
public: auto remove_tabs(cpp2::impl::in<int> c) & -> void;
public: generation_function_context(auto const& code_, auto const& tabs_);
public: generation_function_context();
#line 2181 "reflect.h2"
};
#line 2184 "reflect.h2"
// Context for generating the state machine.
class generation_context
{
private: std::vector<generation_function_context> gen_stack {1}; // Element 0 contains all the code.
private: int matcher_func {0};
private: int reset_func {0};
private: int temp_name {0};
private: std::string entry_func {""};
// Generation helpers
//
public: [[nodiscard]] auto match_parameters() const& -> std::string;
// Code generation.
// Add code line.
public: auto add(cpp2::impl::in<std::string> s) & -> void;
#line 2206 "reflect.h2"
// Add check for token. The check needs to be a function call that returns a boolean.
public: auto add_check(cpp2::impl::in<std::string> check) & -> void;
#line 2212 "reflect.h2"
// Add a stateful check. The check needs to return a `match_return`.
public: auto add_statefull(cpp2::impl::in<std::string> next_func, cpp2::impl::in<std::string> check) & -> void;
#line 2221 "reflect.h2"
protected: auto start_func_named(cpp2::impl::in<std::string> name) & -> void;
#line 2232 "reflect.h2"
protected: [[nodiscard]] auto start_func() & -> std::string;
#line 2239 "reflect.h2"
protected: auto end_func_statefull(cpp2::impl::in<std::string> s) & -> void;
#line 2258 "reflect.h2"
// Generate the function for a token.
public: [[nodiscard]] auto generate_func(cpp2::impl::in<token_ptr> token) & -> std::string;
#line 2268 "reflect.h2"
// Generate the reset for a list of group identifiers.
public: [[nodiscard]] auto generate_reset(cpp2::impl::in<std::set<int>> groups) & -> std::string;
#line 2291 "reflect.h2"
// Name generation
//
protected: [[nodiscard]] auto gen_func_name() & -> std::string;
#line 2299 "reflect.h2"
public: [[nodiscard]] auto next_func_name() & -> std::string;
#line 2303 "reflect.h2"
protected: [[nodiscard]] auto gen_reset_func_name() & -> std::string;
#line 2309 "reflect.h2"