mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
pgindent: Keep the alignas() placeholder the same width
pre_indent() hides each alignas(...) call from pg_bsd_indent behind
a plain identifier, because pg_bsd_indent has a fixed table of
declaration keywords and lexes anything else followed by "(" as the
start of an expression.
The placeholder was not the same width as the text it stood in for,
though, and pg_bsd_indent decides where to put a trailing comment from
the width of the code preceding it. A member declared with alignas()
and carrying a trailing comment therefore got the comment separated by
a tab where the real width calls for a single space, or the other way
round. Pad the placeholder out to the original width so that the
decision is made on the real width.
No member currently declared with alignas() has a trailing comment, so
this changes nothing in the tree today; it is a correctness fix for the
helper.
Author: Tristan Partin <tristan@partin.io>
Co-authored-by: Peter Eisentraut <peter@eisentraut.org>
Discussion: https://www.postgresql.org/message-id/flat/DKBEBF32QLUA.3L2DJRPUYNKHZ%40partin.io
This commit is contained in:
@@ -239,6 +239,24 @@ sub write_source
|
||||
# by post_indent().
|
||||
my @alignas_stash;
|
||||
|
||||
sub stash_alignas
|
||||
{
|
||||
my $text = shift;
|
||||
|
||||
push(@alignas_stash, $text);
|
||||
my $index = $#alignas_stash;
|
||||
|
||||
# Pad the placeholder with underscores so that it is as wide as
|
||||
# the text it stands in for, so that trailing comments on the line
|
||||
# are placed correctly. The padding goes before the index, so
|
||||
# that the placeholder ends in a digit and doesn't accidentally
|
||||
# swallow a following token.
|
||||
my $pad = length($text) - length('alignas') - length($index);
|
||||
$pad = 1 if $pad < 1;
|
||||
|
||||
return 'alignas' . '_' x $pad . $index;
|
||||
}
|
||||
|
||||
sub pre_indent
|
||||
{
|
||||
my $source = shift;
|
||||
@@ -276,8 +294,7 @@ sub pre_indent
|
||||
\b alignas \s*
|
||||
( \( (?: [^()]++ | (?1) )*+ \) )
|
||||
!
|
||||
push(@alignas_stash, "alignas" . $1);
|
||||
"alignas_" . $#alignas_stash . "_";
|
||||
stash_alignas("alignas" . $1);
|
||||
!gex;
|
||||
|
||||
return $source;
|
||||
@@ -288,7 +305,7 @@ sub post_indent
|
||||
my $source = shift;
|
||||
|
||||
# Restore alignas(...)
|
||||
$source =~ s!\balignas_(\d+)_!$alignas_stash[$1]!g;
|
||||
$source =~ s!\balignas_+(\d+)!$alignas_stash[$1]!g;
|
||||
|
||||
# Restore CATALOG lines
|
||||
$source =~ s!^/\*(CATALOG\(.*)\*/$!$1!gm;
|
||||
|
||||
Reference in New Issue
Block a user