From 2ba84464c172ff57188c8e7709167722c9d7fb69 Mon Sep 17 00:00:00 2001 From: "Dr. David von Oheimb" Date: Tue, 12 Jul 2022 21:04:53 +0200 Subject: [PATCH] check-format.pl: improve wording: 'no' -> 'missing'; further minor improvements Reviewed-by: Richard Levitte Reviewed-by: Paul Dale Reviewed-by: Hugo Landau (Cherry-picked from https://github.com/openssl/openssl/pull/18789) --- util/check-format.pl | 55 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/util/check-format.pl b/util/check-format.pl index 17bdc0aa15a0cc..705455020dfe0e 100755 --- a/util/check-format.pl +++ b/util/check-format.pl @@ -520,9 +520,9 @@ sub check_nested_nonblock_indents { if ($in_comment > 0) { # this still includes the last line of multi-line comment my ($head, $any_symbol, $cmt_text) = m/^(\s*)(.?)(.*)$/; if ($any_symbol eq "*") { - report("no space after leading '*' in multi-line comment") if $cmt_text =~ m|^[^/\s$self_test_exception]|; + report("missing space or '*' after leading '*' in multi-line comment") if $cmt_text =~ m|^[^*\s/$self_test_exception]|; } else { - report("no leading '*' in multi-line comment"); + report("missing leading '*' in multi-line comment"); } $in_comment++; } @@ -530,13 +530,13 @@ sub check_nested_nonblock_indents { # detect end of comment, must be within multi-line comment, check if it is preceded by non-whitespace text if ((my ($head, $tail) = m|^(.*?)\*/(.*)$|) && $1 ne '/') { # ending comment: '*/' report("neither space nor '*' before '*/'") if $head =~ m/[^*\s]$/; - report("no space after '*/'") if $tail =~ m/^[^\s,;)}\]]/; # no space or ,;)}] after '*/' + report("missing space after '*/'") if $tail =~ m/^[^\s,;)}\]]/; # no space or ,;)}] after '*/' if (!($head =~ m|/\*|)) { # not begin of comment '/*', which is is handled below if ($in_comment == 0) { report("unexpected '*/' outside comment"); $_ = "$head@@".$tail; # blind the "*/" } else { - report("text before '*/' in multi-line comment") if ($head =~ m/\S/); # non-SPC before '*/' + report("text before '*/' in multi-line comment") if ($head =~ m/[^*\s]/); # non-SPC before '*/' $in_comment = -1; # indicate that multi-line comment ends on current line if ($count > 0) { # make indentation of end of multi-line comment appear like of leading intra-line comment @@ -553,9 +553,9 @@ sub check_nested_nonblock_indents { # detect begin of comment, check if it is followed by non-space text MATCH_COMMENT: if (my ($head, $opt_minus, $tail) = m|^(.*?)/\*(-?)(.*)$|) { # begin of comment: '/*' - report("no space before '/*'") + report("missing space before '/*'") if $head =~ m/[^\s(\*]$/; # not space, '(', or or '*' (needed to allow '*/') before comment delimiter - report("neither space nor '*' after '/*' or '/*-'") if $tail =~ m/^[^\s*$self_test_exception]/; + report("missing space, '*' or '!' after '/*' or '/*-'") if $tail =~ m/^[^*\s!$self_test_exception]/; my $cmt_text = $opt_minus.$tail; # preliminary if ($in_comment > 0) { report("unexpected '/*' inside multi-line comment"); @@ -568,7 +568,7 @@ sub check_nested_nonblock_indents { } else { # begin of multi-line comment my $self_test_exception = $self_test ? "(@\d?)?" : ""; report("text after '/*' in multi-line comment") - unless $tail =~ m/^$self_test_exception.?\s*$/; + unless $tail =~ m/^$self_test_exception.?[*\s]*$/; # tail not essentially blank, first char already checked # adapt to actual indentation of first line $comment_indent = length($head) + 1; @@ -577,6 +577,7 @@ sub check_nested_nonblock_indents { $leading_comment = $head =~ m/^\s*$/; # there is code before beginning delimiter $formatted_comment = $opt_minus eq "-"; } + } elsif (($head, $tail) = m|^\{-(.*)$|) { # begin of Perl pragma: '{-' } if ($in_comment > 1) { # still inside multi-line comment (not at its begin or end) @@ -688,31 +689,31 @@ sub check_nested_nonblock_indents { report("space before '$1'") if $intra_line =~ m/\s([,)\]])/; # space before ,)] report("space after '$1'") if $intra_line =~ m/([(\[~!])\s/; # space after ([~! report("space after '$1'") if $intra_line =~ m/(defined)\s/; # space after 'defined' - report("no space before '=' or '='") if $intra_line =~ m/\S(=)/; # '=' etc. without preceding space - report("no space before '$1'") if $intra_line =~ m/\S([|\/%<>^\?])/; # |/%<>^? without preceding space + report("missing space before '=' or '='") if $intra_line =~ m/\S(=)/; # '=' etc. without preceding space + report("missing space before '$1'") if $intra_line =~ m/\S([|\/%<>^\?])/; # |/%<>^? without preceding space # TODO ternary ':' without preceding SPC, while allowing no SPC before ':' after 'case' - report("no space before binary '$2'") if $intra_line =~ m/([^\s{()\[e])([+\-])/; # '+'/'-' without preceding space or {()[e + report("missing space before binary '$2'") if $intra_line =~ m/([^\s{()\[e])([+\-])/; # '+'/'-' without preceding space or {()[e # ')' may be used for type casts or before "->", 'e' may be used for numerical literals such as "1e-6" - report("no space before binary '$1'") if $intra_line =~ m/[^\s{()\[*!]([*])/; # '*' without preceding space or {()[*! - report("no space before binary '$1'") if $intra_line =~ m/[^\s{()\[]([&])/; # '&' without preceding space or {()[ - report("no space after ternary '$1'") if $intra_line =~ m/(:)[^\s\d]/; # ':' without following space or digit - report("no space after '$1'") if $intra_line =~ m/([,;=|\/%<>^\?])\S/; # ,;=|/%<>^? without following space - report("no space after binary '$1'") if $intra_line=~m/[^{(\[]([*])[^\sa-zA-Z_(),*]/;# '*' w/o space or \w(),* after + report("missing space before binary '$1'") if $intra_line =~ m/[^\s{()\[*!]([*])/; # '*' without preceding space or {()[*! + report("missing space before binary '$1'") if $intra_line =~ m/[^\s{()\[]([&])/; # '&' without preceding space or {()[ + report("missing space after ternary '$1'") if $intra_line =~ m/(:)[^\s\d]/; # ':' without following space or digit + report("missing space after '$1'") if $intra_line =~ m/([,;=|\/%<>^\?])\S/; # ,;=|/%<>^? without following space + report("missing space after binary '$1'") if $intra_line=~m/[^{(\[]([*])[^\sa-zA-Z_(),*]/;# '*' w/o space or \w(),* after # TODO unary '*' must not be followed by SPC - report("no space after binary '$1'") if $intra_line=~m/([&])[^\sa-zA-Z_(]/; # '&' w/o following space or \w( + report("missing space after binary '$1'") if $intra_line=~m/([&])[^\sa-zA-Z_(]/; # '&' w/o following space or \w( # TODO unary '&' must not be followed by SPC - report("no space after binary '$1'") if $intra_line=~m/[^{(\[]([+\-])[^\s\d(]/; # +/- w/o following space or \d( + report("missing space after binary '$1'") if $intra_line=~m/[^{(\[]([+\-])[^\s\d(]/; # +/- w/o following space or \d( # TODO unary '+' and '-' must not be followed by SPC - report("no space after '$2'") if $intra_line =~ m/(^|\W)(if|while|for|switch|case)[^\w\s]/; # kw w/o SPC - report("no space after '$2'") if $intra_line =~ m/(^|\W)(return)[^\w\s;]/; # return w/o SPC or ';' + report("missing space after '$2'") if $intra_line =~ m/(^|\W)(if|while|for|switch|case)[^\w\s]/; # kw w/o SPC + report("missing space after '$2'") if $intra_line =~ m/(^|\W)(return)[^\w\s;]/; # return w/o SPC or ';' report("space after function/macro name") if $intra_line =~ m/(\w+)\s+\(/ # fn/macro name with space before '(' && !($1 =~ m/^(sizeof|if|else|while|do|for|switch|case|default|break|continue|goto|return|void|char|signed|unsigned|int|short|long|float|double|typedef|enum|struct|union|auto|extern|static|const|volatile|register)$/) # not keyword && !(m/^\s*#\s*define\s/); # we skip macro definitions here because macros # without parameters but with body beginning with '(', e.g., '#define X (1)', # would lead to false positives - TODO also check for macros with parameters - report("no space before '{'") if $intra_line =~ m/[^\s{(\[]\{/; # '{' without preceding space or {([ - report("no space after '}'") if $intra_line =~ m/\}[^\s,;\])}]/; # '}' without following space or ,;])} + report("missing space before '{'") if $intra_line =~ m/[^\s{(\[]\{/; # '{' without preceding space or {([ + report("missing space after '}'") if $intra_line =~ m/\}[^\s,;\])}]/; # '}' without following space or ,;])} } # preprocessor directives @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@ -1042,12 +1043,12 @@ sub check_nested_nonblock_indents { !($keyword_opening_brace eq "else" && $line_opening_brace < $line_before2); } report("code after '{'") if $tail=~ m/[^\s\@]/ && # trailing non-whitespace non-comment (non-'\') - !($tail=~ m/\}/); # no '}' after last '{' + !($tail=~ m/\}/); # missing '}' after last '{' } } # check for opening brace after if/while/for/switch/do not on same line - # note that "no '{' on same line after '} else'" is handled further below + # note that "missing '{' on same line after '} else'" is handled further below if (/^[\s@]*{/ && # leading '{' $line_before > 0 && !($contents_before_ =~ m/^\s*#/) && # not preprocessor directive '#if (my ($head, $mid, $tail) = ($contents_before_ =~ m/(^|^.*\W)(if|while|for|switch|do)(\W.*$|$)/))) { @@ -1057,10 +1058,10 @@ sub check_nested_nonblock_indents { # check for closing brace on line before 'else' not followed by leading '{' elsif (my ($head, $tail) = m/(^|^.*\W)else(\W.*$|$)/) { if (parens_balance($tail) == 0 && # avoid false positive due to unfinished expr on current line - !($tail =~ m/{/) && # after 'else' no '{' on same line + !($tail =~ m/{/) && # after 'else' missing '{' on same line !($head =~ m/}[\s@]*$/) && # not: '}' then any whitespace or comments before 'else' $line_before > 0 && $contents_before_ =~ /}[\s@]*$/) { # trailing '}' on line before - report("no '{' after '} else'"); + report("missing '{' on same line after '} else'"); } } @@ -1087,10 +1088,10 @@ sub check_nested_nonblock_indents { if ($line_before > 0 && $contents_before_ =~ /}[\s@]*$/) { report("'else' not on same line as preceding '}'"); } elsif (parens_balance($tail) == 0) { # avoid false positive due to unfinished expr on current line - report("no '}' on same line before 'else ... {'") if $brace_after; + report("missing '}' on same line before 'else ... {'") if $brace_after; } } elsif (parens_balance($tail) == 0) { # avoid false positive due to unfinished expr on current line - report("no '{' on same line after '} else'") if $brace_before && !$brace_after; + report("missing '{' on same line after '} else'") if $brace_before && !$brace_after; } }