@@ -1913,6 +1913,21 @@ struct compound_statement_node
1913
1913
return open_brace;
1914
1914
}
1915
1915
1916
+ auto add_statement (
1917
+ std::unique_ptr<statement_node>&& statement,
1918
+ int before_pos
1919
+ )
1920
+ -> bool
1921
+ {
1922
+ // Adopt this statement into our list of statements
1923
+ statements.insert (
1924
+ statements.begin () + std::clamp ( before_pos, 0 , unchecked_narrow<int >(std::ssize (statements)) ),
1925
+ std::move (statement)
1926
+ );
1927
+
1928
+ return true ;
1929
+ }
1930
+
1916
1931
auto visit (auto & v, int depth) -> void;
1917
1932
};
1918
1933
@@ -2341,7 +2356,9 @@ struct parameter_declaration_node
2341
2356
2342
2357
// API
2343
2358
//
2344
- auto to_string () const
2359
+ auto to_string (
2360
+ bool verbose = true
2361
+ ) const
2345
2362
-> std::string;
2346
2363
2347
2364
auto has_name () const
@@ -2439,15 +2456,25 @@ struct parameter_declaration_list_node
2439
2456
2440
2457
// API
2441
2458
//
2442
- auto to_string () const
2459
+ auto to_string (
2460
+ bool verbose = true
2461
+ ) const
2443
2462
-> std::string
2444
2463
{
2445
2464
assert (open_paren && close_paren);
2446
2465
2447
2466
auto ret = open_paren->to_string ();
2448
2467
2449
2468
for (auto const & p: parameters) {
2450
- ret += p->to_string () + " , " ;
2469
+ ret += p->to_string (verbose) + " , " ;
2470
+ }
2471
+
2472
+ if (
2473
+ !verbose
2474
+ && std::ssize (ret) > 3
2475
+ )
2476
+ {
2477
+ ret.resize ( std::ssize (ret) - 2 ); // omit the final ", "
2451
2478
}
2452
2479
2453
2480
ret += close_paren->as_string_view ();
@@ -2660,6 +2687,15 @@ struct function_type_node
2660
2687
return {};
2661
2688
}
2662
2689
2690
+ auto parameters_to_string (
2691
+ bool verbose = true
2692
+ ) const
2693
+ -> std::string
2694
+ {
2695
+ assert (parameters);
2696
+ return parameters->to_string (verbose);
2697
+ }
2698
+
2663
2699
auto has_bool_return_type () const
2664
2700
-> bool
2665
2701
{
@@ -3034,7 +3070,12 @@ struct declaration_node
3034
3070
3035
3071
// API
3036
3072
//
3037
- auto to_string () const
3073
+ auto to_string (
3074
+ bool verbose = true
3075
+ ) const
3076
+ -> std::string;
3077
+
3078
+ auto signature_to_string () const
3038
3079
-> std::string;
3039
3080
3040
3081
auto is_template_parameter () const
@@ -3635,6 +3676,12 @@ struct declaration_node
3635
3676
;
3636
3677
}
3637
3678
3679
+ auto get_compound_initializer () const
3680
+ -> compound_statement_node*
3681
+ {
3682
+ return initializer->get_if <compound_statement_node>();
3683
+ }
3684
+
3638
3685
auto is_function_with_this () const
3639
3686
-> bool
3640
3687
{
@@ -4087,7 +4134,9 @@ struct declaration_node
4087
4134
};
4088
4135
4089
4136
4090
- auto parameter_declaration_node::to_string () const
4137
+ auto parameter_declaration_node::to_string (
4138
+ bool verbose /* = true*/
4139
+ ) const
4091
4140
-> std::string
4092
4141
{
4093
4142
auto ret = std::string{};
@@ -4105,7 +4154,15 @@ auto parameter_declaration_node::to_string() const
4105
4154
;
4106
4155
}
4107
4156
4108
- ret += to_string_view (pass) + declaration->to_string ();
4157
+ if (
4158
+ verbose
4159
+ || pass != passing_style::in
4160
+ )
4161
+ {
4162
+ ret += to_string_view (pass);
4163
+ ret += " " ;
4164
+ }
4165
+ ret += declaration->to_string ( verbose );
4109
4166
4110
4167
return ret;
4111
4168
}
@@ -4870,15 +4927,32 @@ auto pretty_print_visualize(type_node const& n, int indent)
4870
4927
-> std::string;
4871
4928
auto pretty_print_visualize (namespace_node const & n, int indent)
4872
4929
-> std::string;
4873
- auto pretty_print_visualize (declaration_node const & n, int indent, bool include_metafunctions_list = false )
4930
+ auto pretty_print_visualize (declaration_node const & n, int indent, bool include_metafunctions_list = false , bool verbose = true )
4874
4931
-> std::string;
4875
4932
4876
4933
4877
- auto declaration_node::to_string () const
4934
+ auto declaration_node::to_string (
4935
+ bool verbose /* = true*/
4936
+ ) const
4878
4937
-> std::string
4879
4938
{
4880
4939
// These need to be unified someday... let's not duplicate this long function...
4881
- return pretty_print_visualize (*this , 0 );
4940
+ return pretty_print_visualize (*this , 0 , false , verbose);
4941
+ }
4942
+
4943
+
4944
+ auto declaration_node::signature_to_string () const
4945
+ -> std::string
4946
+ {
4947
+ auto ret = std::string{};
4948
+ if (auto fname = name ()) {
4949
+ ret += *fname;
4950
+ }
4951
+ if (auto func = std::get_if<a_function>(&type)) {
4952
+ assert ((*func)->parameters );
4953
+ ret += (*func)->parameters ->to_string (false );
4954
+ }
4955
+ return ret;
4882
4956
}
4883
4957
4884
4958
@@ -5593,7 +5667,12 @@ auto pretty_print_visualize(namespace_node const&)
5593
5667
}
5594
5668
5595
5669
5596
- auto pretty_print_visualize (declaration_node const & n, int indent, bool include_metafunctions_list /* = false */ )
5670
+ auto pretty_print_visualize (
5671
+ declaration_node const & n,
5672
+ int indent,
5673
+ bool include_metafunctions_list /* = false */ ,
5674
+ bool verbose /* = true */
5675
+ )
5597
5676
-> std::string
5598
5677
{
5599
5678
indent_spaces = 4 ;
@@ -5627,23 +5706,25 @@ auto pretty_print_visualize(declaration_node const& n, int indent, bool include_
5627
5706
}
5628
5707
5629
5708
auto initializer = std::string{};
5630
- if (n.initializer ) {
5631
- auto adjusted_indent = indent;
5632
- if (!n.name ()) {
5633
- ++adjusted_indent;
5634
- }
5635
- initializer = " =" ;
5636
- if (n.is_function () && n.is_constexpr ) {
5637
- initializer += " =" ;
5709
+ if (verbose) {
5710
+ if (n.initializer ) {
5711
+ auto adjusted_indent = indent;
5712
+ if (!n.name ()) {
5713
+ ++adjusted_indent;
5714
+ }
5715
+ initializer = " =" ;
5716
+ if (n.is_function () && n.is_constexpr ) {
5717
+ initializer += " =" ;
5718
+ }
5719
+ initializer += " " + pretty_print_visualize (*n.initializer , adjusted_indent);
5720
+ if (initializer.ends_with (" ;;" )) {
5721
+ initializer.pop_back ();
5722
+ }
5638
5723
}
5639
- initializer += " " + pretty_print_visualize (*n.initializer , adjusted_indent);
5640
- if (initializer.ends_with (" ;;" )) {
5641
- initializer.pop_back ();
5724
+ else if (!n.is_parameter ()) {
5725
+ initializer = " ;" ;
5642
5726
}
5643
5727
}
5644
- else if (!n.is_parameter ()) {
5645
- initializer = " ;" ;
5646
- }
5647
5728
5648
5729
// Then slot them in where appropriate
5649
5730
0 commit comments