Commit 1d6f345fdf for perl
commit 1d6f345fdfe4eff306ab624c1c294ec40e7d7eef
Author: Karl Williamson <khw@cpan.org>
Date: Mon Oct 5 14:22:42 2026 -0600
regcharclass.pl: Add ability to indent #defines
If a #define is within an #if, it becomes '# define'
The next commit will actually create new #if statements
diff --git a/regcharclass.h b/regcharclass.h
index 3ca39485a2..d50c54f975 100644
--- a/regcharclass.h
+++ b/regcharclass.h
@@ -4689,6 +4689,6 @@ character actually occupies.
* 94644b4e53ef4f2590ef86a261dcd22ffadf79247fcc7f31c4ebf5b19111fd25 lib/unicore/mktables
* a0079d7556b20c2de1fdc3d492797a91b8ec8a06006f94460006185cb6380962 lib/unicore/version
* 0a6b5ab33bb1026531f816efe81aea1a8ffcd34a27cbea37dd6a70a63d73c844 regen/charset_translations.pl
- * 686c4c5f2672f357790908907493cf593ac46c9fc411846d64c5f95a1464a8fd regen/regcharclass.pl
+ * a28feb8fff10e3840d4c9ec635c92ffb8c2f5dd39cd276e817eada7dc68f686d regen/regcharclass.pl
* 1ce43daf54162d0a267412453ce2a613f60f3a7631365775cc52d34213251a83 regen/regcharclass_multi_char_folds.pl
* ex: set ro ft=c: */
diff --git a/regen/regcharclass.pl b/regen/regcharclass.pl
index 6aa99705b4..918e1da2b0 100755
--- a/regen/regcharclass.pl
+++ b/regen/regcharclass.pl
@@ -1405,7 +1405,8 @@ sub _combine {
# _render()
# recursively convert an optree to text with reasonably neat formatting
sub _render {
- my ( $self, $op, $combine, $brace, $opts_ref, $def, $submacros )= @_;
+ my ( $self, $op, $combine, $left_indent, $brace, $opts_ref, $def,
+ $submacros )= @_;
return 0 if ! defined $op; # The set is empty
if ( !ref $op ) {
return $op;
@@ -1413,12 +1414,12 @@ sub _render {
my $cond= $self->_cond_as_str( $op, $combine, $opts_ref );
#no warnings 'recursion'; # This would allow really really inefficient
# code to be generated. See pod
- my $yes= $self->_render( $op->{yes}, $combine, 1, $opts_ref, $def,
- $submacros);
+ my $yes= $self->_render( $op->{yes}, $combine, $left_indent, 1, $opts_ref,
+ $def, $submacros);
return $yes if $cond eq '1';
- my $no= $self->_render( $op->{no}, $combine, 0, $opts_ref, $def,
- $submacros);
+ my $no= $self->_render( $op->{no}, $combine, $left_indent, 0, $opts_ref,
+ $def, $submacros);
return "( $cond )" if $yes eq '1' and $no eq '0';
my ( $lb, $rb )= $brace ? ( "( ", " )" ) : ( "", "" );
return "$lb$cond ? $yes : $no$rb"
@@ -1434,9 +1435,9 @@ sub _render {
my $str= "$lb$cond ?$yes$ind: $no$rb";
if (length $str > 6000) {
- push @$submacros, sprintf "#define $def\n( %s )", "_part"
+ push @$submacros, sprintf "#${left_indent}define $def\n( %s )", "_part"
. (my $yes_idx= 0+@$submacros) . "_", $yes;
- push @$submacros, sprintf "#define $def\n( %s )", "_part"
+ push @$submacros, sprintf "#${left_indent}define $def\n( %s )", "_part"
. (my $no_idx= 0+@$submacros) . "_", $no;
return sprintf "%s%s ? $def : $def%s", $lb, $cond,
"_part${yes_idx}_", "_part${no_idx}_", $rb;
@@ -1454,9 +1455,12 @@ sub _render {
sub render {
my ( $self, $op, $combine, $opts_ref, $def_fmt )= @_;
+ my $ret = "";
+ my $left_indent = "";
+
my @submacros;
- my $rendered = $self->_render( $op, $combine, 0, $opts_ref, $def_fmt,
- \@submacros);
+ my $rendered = $self->_render( $op, $combine, $left_indent, 0, $opts_ref,
+ $def_fmt, \@submacros);
# Wrap length-returning macros in a cast so that ternaries returning
# integer constants don't trigger -Wtautological-constant-compare
@@ -1464,11 +1468,12 @@ sub render {
if (($opts_ref->{ret_type} // 'len') eq 'len') {
$rendered = "(STRLEN)( $rendered )";
}
-
- my $macro= sprintf "#define $def_fmt\n( %s )", "", $rendered;
- return join "\n\n",
- map { "/*** GENERATED CODE ***/\n" . __macro( __clean( $_ ) ) }
- @submacros, $macro;
+ my $macro= sprintf "#${left_indent}define $def_fmt\n( %s )", "", $rendered;
+ $ret .= join "\n\n", map { "/*** GENERATED CODE ***/\n"
+ . __macro( __clean( $_ ) )
+ } @submacros, $macro;
+ $ret .= "#endif\n" if $left_indent;
+ return $ret;
}
# make_macro