mirror of
https://github.com/postgres/postgres.git
synced 2026-10-23 13:29:09 +03:00
pgindent: Fix indentation of alignas() in struct members
pg_bsd_indent doesn't know about alignas(), so a struct member declared with it is misindented unless it's the first member. Disguise each alignas(...) call as a plain identifier while indenting, restoring it afterward. Stash the call's original text by index rather than embedding it in the placeholder: embedding only works for a single-token argument, and fails to match at all against nested parens (e.g. alignas(sizeof(x))) or a line break, silently skipping the disguise. This is backpatched to PostgreSQL 19 because it is by coincidence needed for a bug fix. Co-authored-by: Peter Eisentraut <peter@eisentraut.org> Co-authored-by: Andrew Dunstan <andrew@dunslane.net> Discussion: https://postgr.es/m/94a128da-bf3e-46bd-9e2d-609573c484da@eisentraut.org
This commit is contained in:
@@ -235,6 +235,10 @@ sub write_source
|
||||
return;
|
||||
}
|
||||
|
||||
# Text of each alignas(...) call, stashed by pre_indent() and restored
|
||||
# by post_indent().
|
||||
my @alignas_stash;
|
||||
|
||||
sub pre_indent
|
||||
{
|
||||
my $source = shift;
|
||||
@@ -263,6 +267,19 @@ sub pre_indent
|
||||
# Protect wrapping in CATALOG()
|
||||
$source =~ s!^(CATALOG\(.*)$!/*$1*/!gm;
|
||||
|
||||
# pg_bsd_indent doesn't know about alignas(), so a non-first struct
|
||||
# member declared with it gets misindented. Disguise each call as
|
||||
# a plain identifier; stash the original text rather than embed it,
|
||||
# so nested parens or line breaks in the argument aren't a problem.
|
||||
@alignas_stash = ();
|
||||
$source =~ s!
|
||||
\b alignas \s*
|
||||
( \( (?: [^()]++ | (?1) )*+ \) )
|
||||
!
|
||||
push(@alignas_stash, "alignas" . $1);
|
||||
"alignas_" . $#alignas_stash . "_";
|
||||
!gex;
|
||||
|
||||
return $source;
|
||||
}
|
||||
|
||||
@@ -270,6 +287,9 @@ sub post_indent
|
||||
{
|
||||
my $source = shift;
|
||||
|
||||
# Restore alignas(...)
|
||||
$source =~ s!\balignas_(\d+)_!$alignas_stash[$1]!g;
|
||||
|
||||
# Restore CATALOG lines
|
||||
$source =~ s!^/\*(CATALOG\(.*)\*/$!$1!gm;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user