aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/scripts/cstyle.pl
diff options
context:
space:
mode:
Diffstat (limited to 'sys/contrib/openzfs/scripts/cstyle.pl')
-rwxr-xr-xsys/contrib/openzfs/scripts/cstyle.pl26
1 files changed, 23 insertions, 3 deletions
diff --git a/sys/contrib/openzfs/scripts/cstyle.pl b/sys/contrib/openzfs/scripts/cstyle.pl
index d47fd3362408..123020b08127 100755
--- a/sys/contrib/openzfs/scripts/cstyle.pl
+++ b/sys/contrib/openzfs/scripts/cstyle.pl
@@ -211,6 +211,7 @@ my $next_in_cpp = 0;
my $in_comment = 0;
my $comment_done = 0;
my $in_warlock_comment = 0;
+my $in_macro_call = 0;
my $in_function = 0;
my $in_function_header = 0;
my $function_header_full_indent = 0;
@@ -395,12 +396,18 @@ line: while (<$filehandle>) {
}
}
+ # If this looks like a top-level macro invocation, remember it so we
+ # don't mistake it for a function declaration below.
+ if (/^[A-Za-z_][A-Za-z_0-9]*\(/) {
+ $in_macro_call = 1;
+ }
+
#
# If this matches something of form "foo(", it's probably a function
# definition, unless it ends with ") bar;", in which case it's a declaration
# that uses a macro to generate the type.
#
- if (/^\w+\(/ && !/\) \w+;/) {
+ if (!$in_macro_call && /^\w+\(/ && !/\) \w+;/) {
$in_function_header = 1;
if (/\($/) {
$function_header_full_indent = 1;
@@ -565,7 +572,9 @@ line: while (<$filehandle>) {
err("comma or semicolon followed by non-blank");
}
# allow "for" statements to have empty "while" clauses
- if (/\s[,;]/ && !/^[\t]+;$/ && !/^\s*for \([^;]*; ;[^;]*\)/) {
+ # allow macro invocations to have empty parameters
+ if (/\s[,;]/ && !/^[\t]+;$/ &&
+ !($in_macro_call || /^\s*for \([^;]*; ;[^;]*\)/)) {
err("comma or semicolon preceded by blank");
}
if (/^\s*(&&|\|\|)/) {
@@ -686,10 +695,13 @@ line: while (<$filehandle>) {
err("unary * followed by space");
}
}
- if ($check_posix_types) {
+ if ($check_posix_types && !$in_macro_call) {
# try to detect old non-POSIX types.
# POSIX requires all non-standard typedefs to end in _t,
# but historically these have been used.
+ #
+ # We don't check inside macro invocations because macros have
+ # legitmate uses for these names in function generators.
if (/\b(unchar|ushort|uint|ulong|u_int|u_short|u_long|u_char|quad)\b/) {
err("non-POSIX typedef $1 used: use $old2posix{$1} instead");
}
@@ -700,6 +712,14 @@ line: while (<$filehandle>) {
"else and right brace should be on same line");
}
}
+
+ # Macro invocations end with a closing paren, and possibly a semicolon.
+ # We do this check down here to make sure all the regular checks are
+ # applied to calls that appear entirely on a single line.
+ if ($in_macro_call && /\);?$/) {
+ $in_macro_call = 0;
+ }
+
$prev = $line;
}