Skip to content

Commit

Permalink
B fixes checkOptree when open is used
Browse files Browse the repository at this point in the history
Fix #267

Adjust strip_open_hints logic to be more flexible
to hint characters.
  • Loading branch information
atoomic authored and jkeenan committed Sep 18, 2020
1 parent ed01a61 commit d3ef531
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 237 deletions.
60 changes: 49 additions & 11 deletions ext/B/t/OptreeCheck.pm
Original file line number Diff line number Diff line change
Expand Up @@ -669,18 +669,56 @@ sub mkCheckRex {
. '\\)'!msgxe;
# widened for -terse mode
$str =~ s/(?:next|db)state/(?:next|db)state/msg;

if (!$using_open && $tc->{strip_open_hints}) {
$str =~ s[( # capture
\(\?:next\|db\)state # the regexp matching next/db state
.* # all sorts of things follow it
v # The opening v
)
(?:(:>,<,%,\\\{) # hints when open.pm is in force
|(:>,<,%)) # (two variations)
(\ ->(?:-|[0-9a-z]+))?
$
]
[$1 . ($2 && ':\{') . $4]xegm; # change to the hints without open.pm
# remove the '<,>' from the regexp and convert to a list []

# we are going to capture a little more
my $all_hints = q|[,><%{*$&\\\]+|;

my $qr = qr[( # capture
\(\?:next\|db\)state # the regexp matching next/db state
.* # all sorts of things follow it
v: # The opening v
)
($all_hints)
]xm;

if ( $str =~ $qr ) {
my $expected_hints = $2;
$expected_hints =~ s{\\}{}g; # stip the \ which is added later

# maybe split on comma: ','
my $used_chars = { map { $_ => 1 } split( //, $expected_hints ) };
$used_chars->{'\,'} = 1;

# strip open hints
delete $used_chars->{'>'};
delete $used_chars->{'<'};
delete $used_chars->{'%'};

delete $used_chars->{'\\'}; # added later
my $extra_chars = '\\';

{
delete $used_chars->{'{'};
$extra_chars .= '\{';
}

my $chars = join '', sort keys %$used_chars;

my $hints_without_open = '(:[' . $chars . $extra_chars . ']+)?';

$str =~ s[( # capture
\(\?:next\|db\)state # the regexp matching next/db state
.* # all sorts of things follow it
v # The opening v
)
:
($all_hints)
]
[$1 . $hints_without_open ]xegm; # change to the hints without open.pm
}
}


Expand Down
12 changes: 6 additions & 6 deletions ext/B/t/optree_check.t
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,11 @@ checkOptree ( name => 'fixup nextstate (in reftext)',
code => sub {my $a},
strip_open_hints => 1,
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
# 1 <;> nextstate( NOTE THAT THIS CAN BE ANYTHING ) v:*,&,$
# 1 <;> nextstate( NOTE THAT THIS CAN BE ANYTHING ) v:>,<,%,*,&,$
# 2 <0> padsv[$a:54,55] sM/LVINTRO
# 3 <1> leavesub[1 ref] K/REFC,1
EOT_EOT
# 1 <;> nextstate(main 54 optree_concise.t:84) v:*,&,$
# 1 <;> nextstate(main 54 optree_concise.t:84) v:>,<,%,*,&,$
# 2 <0> padsv[$a:54,55] sM/LVINTRO
# 3 <1> leavesub[1 ref] K/REFC,1
EONT_EONT
Expand All @@ -163,11 +163,11 @@ checkOptree ( name => 'fixup opcode args',
code => sub {my $a},
strip_open_hints => 1,
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
# 1 <;> nextstate(main 56 optree_concise.t:96) v:*,&,$
# 1 <;> nextstate(main 56 optree_concise.t:96) v:>,<,%,*,&,$
# 2 <0> padsv[$a:56,57] sM/LVINTRO
# 3 <1> leavesub[1 ref] K/REFC,1
EOT_EOT
# 1 <;> nextstate(main 56 optree_concise.t:96) v:*,&,$
# 1 <;> nextstate(main 56 optree_concise.t:96) v:>,<,%,*,&,$
# 2 <0> padsv[$a:56,57] sM/LVINTRO
# 3 <1> leavesub[1 ref] K/REFC,1
EONT_EONT
Expand All @@ -183,7 +183,7 @@ checkOptree ( name => 'canonical example w -basic',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
# 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->7
# 1 <;> nextstate(main 380 optree_selftest.t:139) v:*,&,{,$ ->2
# 1 <;> nextstate(main 380 optree_selftest.t:139) v:>,<,%,*,&,{,$ ->2
# 6 <2> sassign sKS/2 ->7
# 4 <2> add[t3] sK/2 ->5
# - <1> ex-rv2sv sK/STRICT,1 ->3
Expand All @@ -194,7 +194,7 @@ checkOptree ( name => 'canonical example w -basic',
EOT_EOT
# 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->7
# 1 <;> nextstate(main 60 optree_concise.t:122) v:*,&,{,$ ->2
# 1 <;> nextstate(main 60 optree_concise.t:122) v:>,<,%,*,&,{,$ ->2
# 6 <2> sassign sKS/2 ->7
# 4 <2> add[t1] sK/2 ->5
# - <1> ex-rv2sv sK/STRICT,1 ->3
Expand Down
40 changes: 20 additions & 20 deletions ext/B/t/optree_concise.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ checkOptree ( name => 'canonical example w -basic',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
# 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->7
# 1 <;> nextstate(foo bar) v:*,&,{,$ ->2
# 1 <;> nextstate(foo bar) v:>,<,%,*,&,{,$ ->2
# 6 <2> sassign sKS/2 ->7
# 4 <2> add[t3] sK/2 ->5
# - <1> ex-rv2sv sK/STRICT,1 ->3
Expand All @@ -44,7 +44,7 @@ checkOptree ( name => 'canonical example w -basic',
EOT_EOT
# 7 <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->7
# 1 <;> nextstate(main 60 optree_concise.t:122) v:*,&,{,$ ->2
# 1 <;> nextstate(main 60 optree_concise.t:122) v:>,<,%,*,&,{,$ ->2
# 6 <2> sassign sKS/2 ->7
# 4 <2> add[t1] sK/2 ->5
# - <1> ex-rv2sv sK/STRICT,1 ->3
Expand All @@ -59,15 +59,15 @@ checkOptree ( name => 'canonical example w -exec',
code => sub{$a=$b+42},
strip_open_hints => 1,
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
# 1 <;> nextstate(main 61 optree_concise.t:139) v:*,&,{,$
# 1 <;> nextstate(main 61 optree_concise.t:139) v:>,<,%,*,&,{,$
# 2 <#> gvsv[*b] s
# 3 <$> const[IV 42] s
# 4 <2> add[t3] sK/2
# 5 <#> gvsv[*a] s
# 6 <2> sassign sKS/2
# 7 <1> leavesub[1 ref] K/REFC,1
EOT_EOT
# 1 <;> nextstate(main 61 optree_concise.t:139) v:*,&,{,$
# 1 <;> nextstate(main 61 optree_concise.t:139) v:>,<,%,*,&,{,$
# 2 <$> gvsv(*b) s
# 3 <$> const(IV 42) s
# 4 <2> add[t1] sK/2
Expand All @@ -84,15 +84,15 @@ checkOptree ( name => '-base3 sticky-exec',
code => sub{$a=$b+42},
strip_open_hints => 1,
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <;> dbstate(main 24 optree_concise.t:132) v:*,&,{,$
1 <;> dbstate(main 24 optree_concise.t:132) v:>,<,%,*,&,{,$
2 <#> gvsv[*b] s
10 <$> const[IV 42] s
11 <2> add[t3] sK/2
12 <#> gvsv[*a] s
20 <2> sassign sKS/2
21 <1> leavesub[1 ref] K/REFC,1
EOT_EOT
# 1 <;> nextstate(main 62 optree_concise.t:161) v:*,&,{,$
# 1 <;> nextstate(main 62 optree_concise.t:161) v:>,<,%,*,&,{,$
# 2 <$> gvsv(*b) s
# 10 <$> const(IV 42) s
# 11 <2> add[t1] sK/2
Expand All @@ -108,7 +108,7 @@ checkOptree ( name => 'sticky-base3, -basic over sticky-exec',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
21 <1> leavesub[1 ref] K/REFC,1 ->(end)
- <@> lineseq KP ->21
1 <;> nextstate(main 32 optree_concise.t:164) v:*,&,{,$ ->2
1 <;> nextstate(main 32 optree_concise.t:164) v:>,<,%,*,&,{,$ ->2
20 <2> sassign sKS/2 ->21
11 <2> add[t3] sK/2 ->12
- <1> ex-rv2sv sK/STRICT,1 ->10
Expand All @@ -119,7 +119,7 @@ checkOptree ( name => 'sticky-base3, -basic over sticky-exec',
EOT_EOT
# 21 <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->21
# 1 <;> nextstate(main 63 optree_concise.t:186) v:*,&,{,$ ->2
# 1 <;> nextstate(main 63 optree_concise.t:186) v:>,<,%,*,&,{,$ ->2
# 20 <2> sassign sKS/2 ->21
# 11 <2> add[t1] sK/2 ->12
# - <1> ex-rv2sv sK/STRICT,1 ->10
Expand All @@ -136,7 +136,7 @@ checkOptree ( name => '-base4',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
13 <1> leavesub[1 ref] K/REFC,1 ->(end)
- <@> lineseq KP ->13
1 <;> nextstate(main 26 optree_concise.t:145) v:*,&,{,$ ->2
1 <;> nextstate(main 26 optree_concise.t:145) v:>,<,%,*,&,{,$ ->2
12 <2> sassign sKS/2 ->13
10 <2> add[t3] sK/2 ->11
- <1> ex-rv2sv sK/STRICT,1 ->3
Expand All @@ -147,7 +147,7 @@ checkOptree ( name => '-base4',
EOT_EOT
# 13 <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->13
# 1 <;> nextstate(main 64 optree_concise.t:193) v:*,&,{,$ ->2
# 1 <;> nextstate(main 64 optree_concise.t:193) v:>,<,%,*,&,{,$ ->2
# 12 <2> sassign sKS/2 ->13
# 10 <2> add[t1] sK/2 ->11
# - <1> ex-rv2sv sK/STRICT,1 ->3
Expand All @@ -165,13 +165,13 @@ checkOptree ( name => "restore -base36 default",
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
3 <1> leavesub[1 ref] K/REFC,1 ->(end)
- <@> lineseq KP ->3
1 <;> nextstate(main 27 optree_concise.t:161) v:*,&,$ ->2
1 <;> nextstate(main 27 optree_concise.t:161) v:>,<,%,*,&,$ ->2
- <1> ex-rv2sv sK/STRICT,1 ->-
2 <#> gvsv[*a] s ->3
EOT_EOT
# 3 <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->3
# 1 <;> nextstate(main 65 optree_concise.t:210) v:*,&,$ ->2
# 1 <;> nextstate(main 65 optree_concise.t:210) v:>,<,%,*,&,$ ->2
# - <1> ex-rv2sv sK/STRICT,1 ->-
# 2 <$> gvsv(*a) s ->3
EONT_EONT
Expand Down Expand Up @@ -218,15 +218,15 @@ checkOptree ( name => 'cmdline invoke -basic works',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
# 7 <@> leave[1 ref] vKP/REFC ->(end)
# 1 <0> enter v ->2
# 2 <;> nextstate(main 1 -e:1) v:{ ->3
# 2 <;> nextstate(main 1 -e:1) v:>,<,%,{ ->3
# 6 <@> sort vK ->7
# 3 <0> pushmark s ->4
# 5 <1> rv2av[t2] lK/1 ->6
# 4 <#> gv[*a] s ->5
EOT_EOT
# 7 <@> leave[1 ref] vKP/REFC ->(end)
# 1 <0> enter v ->2
# 2 <;> nextstate(main 1 -e:1) v:{ ->3
# 2 <;> nextstate(main 1 -e:1) v:>,<,%,{ ->3
# 6 <@> sort vK ->7
# 3 <0> pushmark s ->4
# 5 <1> rv2av[t1] lK/1 ->6
Expand All @@ -242,15 +242,15 @@ checkOptree ( name => 'cmdline invoke -exec works',
strip_open_hints => 1,
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <0> enter v
2 <;> nextstate(main 1 -e:1) v:{
2 <;> nextstate(main 1 -e:1) v:>,<,%,{
3 <0> pushmark s
4 <#> gv[*a] s
5 <1> rv2av[t2] lK/1
6 <@> sort vK
7 <@> leave[1 ref] vKP/REFC
EOT_EOT
# 1 <0> enter v
# 2 <;> nextstate(main 1 -e:1) v:{
# 2 <;> nextstate(main 1 -e:1) v:>,<,%,{
# 3 <0> pushmark s
# 4 <$> gv(*a) s
# 5 <1> rv2av[t1] lK/1
Expand Down Expand Up @@ -291,15 +291,15 @@ checkOptree
strip_open_hints => 1,
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
# 1 <0> enter v
# 2 <;> nextstate(main 2 -e:1) v:{
# 2 <;> nextstate(main 2 -e:1) v:>,<,%,{
# 3 <0> pushmark s
# 4 <#> gv[*a] s
# 5 <1> rv2av[t5] lK/1
# 6 <@> sort vK
# 7 <@> leave[1 ref] vKP/REFC
EOT_EOT
# 1 <0> enter v
# 2 <;> nextstate(main 2 -e:1) v:{
# 2 <;> nextstate(main 2 -e:1) v:>,<,%,{
# 3 <0> pushmark s
# 4 <$> gv(*a) s
# 5 <1> rv2av[t3] lK/1
Expand Down Expand Up @@ -366,15 +366,15 @@ checkOptree ( name => 'callback used, independent of style',
code => sub{$a=$b+42},
strip_open_hints => 1,
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
1 <;> nextstate(main 76 optree_concise.t:337) v:*,&,{,$
1 <;> nextstate(main 76 optree_concise.t:337) v:>,<,%,*,&,{,$
2 <#> gvsv[*b] s
3 <$> const[IV 42] CALLBACK s
4 <2> add[t3] sK/2
5 <#> gvsv[*a] s
6 <2> sassign sKS/2
7 <1> leavesub[1 ref] K/REFC,1
EOT_EOT
# 1 <;> nextstate(main 455 optree_concise.t:328) v:*,&,{,$
# 1 <;> nextstate(main 455 optree_concise.t:328) v:>,<,%,*,&,{,$
# 2 <$> gvsv(*b) s
# 3 <$> const(IV 42) CALLBACK s
# 4 <2> add[t1] sK/2
Expand Down
32 changes: 16 additions & 16 deletions ext/B/t/optree_constants.t
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ sub printem {
my ($expect, $expect_nt) = (<<'EOT_EOT', <<'EONT_EONT');
# 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->9
# 1 <;> nextstate(main 635 optree_constants.t:163) v:*,&,$ ->2
# 1 <;> nextstate(main 635 optree_constants.t:163) v:>,<,%,*,&,$ ->2
# 8 <@> prtf sK ->9
# 2 <0> pushmark sM ->3
# 3 <$> const[PV "myint %d mystr %s myfl %f pi %f\n"] sM/FOLD ->4
Expand All @@ -220,7 +220,7 @@ my ($expect, $expect_nt) = (<<'EOT_EOT', <<'EONT_EONT');
EOT_EOT
# 9 <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->9
# 1 <;> nextstate(main 635 optree_constants.t:163) v:*,&,$ ->2
# 1 <;> nextstate(main 635 optree_constants.t:163) v:>,<,%,*,&,$ ->2
# 8 <@> prtf sK ->9
# 2 <0> pushmark sM ->3
# 3 <$> const(PV "myint %d mystr %s myfl %f pi %f\n") sM/FOLD ->4
Expand Down Expand Up @@ -310,62 +310,62 @@ checkOptree ( name => 'lc*,uc*,gt,lt,ge,le,cmp',
expect => <<'EOT_EOT', expect_nt => <<'EONT_EONT');
# r <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->r
# 1 <;> nextstate(main 916 optree_constants.t:307) v:*,&,{,$ ->2
# 1 <;> nextstate(main 916 optree_constants.t:307) v:>,<,%,*,&,{,$ ->2
# 4 <2> sassign vKS/2 ->5
# 2 <$> const[PV "FOO.Bar.low.lOW"] s/FOLD ->3
# - <1> ex-rv2sv sKRM*/STRICT,1 ->4
# 3 <#> gvsv[*a] s ->4
# 5 <;> nextstate(main 916 optree_constants.t:308) v:*,&,{,$ ->6
# 5 <;> nextstate(main 916 optree_constants.t:308) v:>,<,%,*,&,{,$ ->6
# 8 <@> print vK/FOLD ->9
# 6 <0> pushmark s ->7
# 7 <$> const[PV "a-lt-b"] s ->8
# 9 <;> nextstate(main 916 optree_constants.t:309) v:*,&,{,$ ->a
# 9 <;> nextstate(main 916 optree_constants.t:309) v:>,<,%,*,&,{,$ ->a
# c <@> print vK/FOLD ->d
# a <0> pushmark s ->b
# b <$> const[PV "b-gt-a"] s ->c
# d <;> nextstate(main 916 optree_constants.t:310) v:*,&,{,$ ->e
# d <;> nextstate(main 916 optree_constants.t:310) v:>,<,%,*,&,{,$ ->e
# g <@> print vK/FOLD ->h
# e <0> pushmark s ->f
# f <$> const[PV "a-le-b"] s ->g
# h <;> nextstate(main 916 optree_constants.t:311) v:*,&,{,$ ->i
# h <;> nextstate(main 916 optree_constants.t:311) v:>,<,%,*,&,{,$ ->i
# k <@> print vK/FOLD ->l
# i <0> pushmark s ->j
# j <$> const[PV "b-ge-a"] s ->k
# l <;> nextstate(main 916 optree_constants.t:312) v:*,&,{,$ ->m
# l <;> nextstate(main 916 optree_constants.t:312) v:>,<,%,*,&,{,$ ->m
# o <@> print vK/FOLD ->p
# m <0> pushmark s ->n
# n <$> const[PV "b-cmp-a"] s ->o
# p <;> nextstate(main 916 optree_constants.t:313) v:*,&,{,$ ->q
# p <;> nextstate(main 916 optree_constants.t:313) v:>,<,%,*,&,{,$ ->q
# q <$> const[SPECIAL sv_no] s/SHORT,FOLD ->r
EOT_EOT
# r <1> leavesub[1 ref] K/REFC,1 ->(end)
# - <@> lineseq KP ->r
# 1 <;> nextstate(main 916 optree_constants.t:307) v:*,&,{,$ ->2
# 1 <;> nextstate(main 916 optree_constants.t:307) v:>,<,%,*,&,{,$ ->2
# 4 <2> sassign vKS/2 ->5
# 2 <$> const(PV "FOO.Bar.low.lOW") s/FOLD ->3
# - <1> ex-rv2sv sKRM*/STRICT,1 ->4
# 3 <$> gvsv(*a) s ->4
# 5 <;> nextstate(main 916 optree_constants.t:308) v:*,&,{,$ ->6
# 5 <;> nextstate(main 916 optree_constants.t:308) v:>,<,%,*,&,{,$ ->6
# 8 <@> print vK/FOLD ->9
# 6 <0> pushmark s ->7
# 7 <$> const(PV "a-lt-b") s ->8
# 9 <;> nextstate(main 916 optree_constants.t:309) v:*,&,{,$ ->a
# 9 <;> nextstate(main 916 optree_constants.t:309) v:>,<,%,*,&,{,$ ->a
# c <@> print vK/FOLD ->d
# a <0> pushmark s ->b
# b <$> const(PV "b-gt-a") s ->c
# d <;> nextstate(main 916 optree_constants.t:310) v:*,&,{,$ ->e
# d <;> nextstate(main 916 optree_constants.t:310) v:>,<,%,*,&,{,$ ->e
# g <@> print vK/FOLD ->h
# e <0> pushmark s ->f
# f <$> const(PV "a-le-b") s ->g
# h <;> nextstate(main 916 optree_constants.t:311) v:*,&,{,$ ->i
# h <;> nextstate(main 916 optree_constants.t:311) v:>,<,%,*,&,{,$ ->i
# k <@> print vK/FOLD ->l
# i <0> pushmark s ->j
# j <$> const(PV "b-ge-a") s ->k
# l <;> nextstate(main 916 optree_constants.t:312) v:*,&,{,$ ->m
# l <;> nextstate(main 916 optree_constants.t:312) v:>,<,%,*,&,{,$ ->m
# o <@> print vK/FOLD ->p
# m <0> pushmark s ->n
# n <$> const(PV "b-cmp-a") s ->o
# p <;> nextstate(main 916 optree_constants.t:313) v:*,&,{,$ ->q
# p <;> nextstate(main 916 optree_constants.t:313) v:>,<,%,*,&,{,$ ->q
# q <$> const(SPECIAL sv_no) s/SHORT,FOLD ->r
EONT_EONT
Expand Down
Loading

0 comments on commit d3ef531

Please sign in to comment.