Commit 2e16b38
committed
scripted-diff: Wrap checks with
`||` is also `delete` when decomposing an expression. See previous
commit message.
ref: https://fekir.info/post/decomposing-an-expression/
-BEGIN VERIFY SCRIPT-
set -eu
MACRO_RE='BOOST_CHECK|BOOST_REQUIRE|BOOST_CHECK_MESSAGE|BOOST_REQUIRE_MESSAGE|BOOST_CHECK_NO_THROW|BOOST_REQUIRE_NO_THROW'
FILES=$(git grep -lE "\b(${MACRO_RE})[[:space:]]*\(" -- \
':(glob)src/test/**/*.cpp' ':(glob)src/test/**/*.h' \
':(glob)src/test/*.cpp' ':(glob)src/test/*.h' \
':(glob)src/ipc/test/**/*.cpp' ':(glob)src/ipc/test/**/*.h' \
':(glob)src/ipc/test/*.cpp' ':(glob)src/ipc/test/*.h' 2>/dev/null || true)
if [ -z "$FILES" ]; then
echo "no matching files"
exit 0
fi
perl -i -0777 -pe '
use strict;
use warnings;
my $names = "BOOST_CHECK|BOOST_REQUIRE|BOOST_CHECK_MESSAGE|BOOST_REQUIRE_MESSAGE|BOOST_CHECK_NO_THROW|BOOST_REQUIRE_NO_THROW";
my $re = qr/\b($names)\s*\(/;
my @DIGIT_SEP_PREV = (0) x 256;
$DIGIT_SEP_PREV[ord($_)] = 1 for split //, "0123456789abcdefABCDEF" . chr(39);
sub is_char_open {
my ($s, $i) = @_;
return 1 if $i == 0;
return $DIGIT_SEP_PREV[ord(substr($$s, $i-1, 1))] ? 0 : 1;
}
sub close_paren {
my ($s, $open) = @_;
my ($depth, $i, $in_str, $in_char) = (0, $open, 0, 0);
my $n = length($$s);
while ($i < $n) {
my $c = substr($$s, $i, 1);
if ($in_str) {
if ($c eq "\\") { $i += 2; next; }
$in_str = 0 if $c eq q{"};
} elsif ($in_char) {
if ($c eq "\\") { $i += 2; next; }
$in_char = 0 if $c eq chr(39);
} elsif ($c eq q{"}) { $in_str = 1; }
elsif ($c eq chr(39) && is_char_open($s, $i)) { $in_char = 1; }
elsif ($c =~ /[(\[{]/) { $depth++; }
elsif ($c =~ /[)\]}]/) { $depth--; return $i if $depth == 0; }
$i++;
}
return -1;
}
sub split_first_comma {
my ($s) = @_;
my ($depth, $i, $in_str, $in_char) = (0, 0, 0, 0);
my $n = length($s);
while ($i < $n) {
my $c = substr($s, $i, 1);
if ($in_str) {
if ($c eq "\\") { $i += 2; next; }
$in_str = 0 if $c eq q{"};
} elsif ($in_char) {
if ($c eq "\\") { $i += 2; next; }
$in_char = 0 if $c eq chr(39);
} elsif ($c eq q{"}) { $in_str = 1; }
elsif ($c eq chr(39) && is_char_open(\$s, $i)) { $in_char = 1; }
elsif ($c =~ /[(\[{]/) { $depth++; }
elsif ($c =~ /[)\]}]/) { $depth--; }
elsif ($c eq "," && $depth == 0) {
return (substr($s, 0, $i), substr($s, $i));
}
$i++;
}
return ($s, "");
}
sub has_top_level_or {
my ($e) = @_;
my ($depth, $i, $in_str, $in_char) = (0, 0, 0, 0);
my $n = length($e);
while ($i < $n) {
my $c = substr($e, $i, 1);
if ($in_str) {
if ($c eq "\\") { $i += 2; next; }
$in_str = 0 if $c eq q{"};
$i++; next;
} elsif ($in_char) {
if ($c eq "\\") { $i += 2; next; }
$in_char = 0 if $c eq chr(39);
$i++; next;
}
if ($c eq q{"}) { $in_str = 1; $i++; next; }
if ($c eq chr(39) && is_char_open(\$e, $i)) { $in_char = 1; $i++; next; }
if ($c =~ /[(\[{]/) { $depth++; $i++; next; }
if ($c =~ /[)\]}]/) { $depth--; $i++; next; }
if ($depth == 0 && $i + 1 < $n && substr($e, $i, 2) eq "||") {
return 1;
}
$i++;
}
return 0;
}
my $text = $_;
my $out = "";
my $cur = 0;
while ($text =~ /$re/g) {
my $macro = $1;
my $m_start = $-[0];
my $p_open = $+[0] - 1;
my $p_close = close_paren(\$text, $p_open);
next if $p_close < 0;
my $args = substr($text, $p_open + 1, $p_close - $p_open - 1);
my ($expr_raw, $message) = split_first_comma($args);
my $expr = $expr_raw;
$expr =~ s/^\s+//;
$expr =~ s/\s+$//;
next unless has_top_level_or($expr);
$out .= substr($text, $cur, $m_start - $cur);
$out .= "$macro(($expr)$message)";
$cur = $p_close + 1;
pos($text) = $cur;
}
$out .= substr($text, $cur);
$_ = $out;
' -- $FILES
-END VERIFY SCRIPT-||
1 parent 4cdcaf2 commit 2e16b38
13 files changed
Lines changed: 25 additions & 25 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
| 188 | + | |
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
| |||
311 | 311 | | |
312 | 312 | | |
313 | 313 | | |
314 | | - | |
| 314 | + | |
315 | 315 | | |
316 | 316 | | |
317 | 317 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
334 | 334 | | |
335 | 335 | | |
336 | 336 | | |
337 | | - | |
| 337 | + | |
338 | 338 | | |
339 | 339 | | |
340 | 340 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
279 | | - | |
280 | | - | |
| 279 | + | |
| 280 | + | |
281 | 281 | | |
282 | 282 | | |
283 | 283 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
395 | | - | |
| 395 | + | |
396 | 396 | | |
397 | | - | |
| 397 | + | |
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
| |||
403 | 403 | | |
404 | 404 | | |
405 | 405 | | |
406 | | - | |
| 406 | + | |
407 | 407 | | |
408 | 408 | | |
409 | 409 | | |
| |||
453 | 453 | | |
454 | 454 | | |
455 | 455 | | |
456 | | - | |
| 456 | + | |
457 | 457 | | |
458 | 458 | | |
459 | 459 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
193 | | - | |
| 193 | + | |
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
218 | | - | |
| 218 | + | |
219 | 219 | | |
220 | 220 | | |
221 | 221 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1305 | 1305 | | |
1306 | 1306 | | |
1307 | 1307 | | |
1308 | | - | |
| 1308 | + | |
1309 | 1309 | | |
1310 | 1310 | | |
1311 | 1311 | | |
| |||
1323 | 1323 | | |
1324 | 1324 | | |
1325 | 1325 | | |
1326 | | - | |
| 1326 | + | |
1327 | 1327 | | |
1328 | 1328 | | |
1329 | 1329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
295 | | - | |
| 295 | + | |
296 | 296 | | |
297 | 297 | | |
298 | 298 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
| 60 | + | |
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
143 | | - | |
| 143 | + | |
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
| 275 | + | |
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| |||
0 commit comments