Skip to content

Commit 964c9da

Browse files
Usable again
1 parent 5a25102 commit 964c9da

File tree

4 files changed

+143
-52
lines changed

4 files changed

+143
-52
lines changed

faster.regex

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44

55

66

7-
(?<rndbrcksdecl>\s*\((?<inparen>(?<inparenin>\s*+(?&ptr)*+\s*+((?<identinside>(?&identifierpure))|(?&rndbrcksdecl))(\s*+(?&parens)\s*+)*+\s*)*+
8-
((?&inparenin)(?&inparen))?+)\)\s*)
9-
10-
(?<typeorqualifortypdf>\s*+((?&identifierpure))(?(?{checktypeorqualifortypdf(1)})|(*F))\s*+)
7+
(?<typeorqualifortypdf>((?&identifierpure))(?(?{checktypeorqualifortypdf(1)})|(*F)))
118

129
(?<qualifonly>((?&identifierpure))(?(?{checkqualifonly()})|(*F)))
1310

14-
(?<fasterdecls>(?(?=(?{push2 \@matches, {}})(?<declbod>((?&typeorqualifortypdf)
15-
|\s*+(struct|union|enum)\s*+(?<identtag>(?&identifierpure))?+\s*+((?&brackets)(?{register_taggable()}))?+)*+
16-
(?<identoutter>\s*+(?&ptr)*+((?&rndbrcksdecl)|(?<identnormal>(?&identifierpure))(?{register_normal_decl()}))\s*+)
17-
(\s*+(?&parens)\s*+)*+((,(?&identoutter)(\s*+(?&parens)\s*+)*+)*+)))|(*F)(?{pop2 \@matches})))
11+
(?<fasterdecls>(?(?=(?{push2 \@matches, {}})(?<declbod>((?(<tagend>)(*F))(\s*+(?&typeorqualifortypdf)\s*+
12+
|\s*+\b(?<tagtype>struct|union|enum)\b\s*+(?<identtag>((?&identifierpure))(?{eval {$matches[-1]{strc}=$^N}}))?+\s*+((?&brackets)(?{register_taggable()}))?+\s*+((?<tagend>;)(?{dispatch_file_scope_stm(pos(),$minlen)}))?+))*+
13+
(?(<tagend>)|(?&identoutter)
14+
(\s*+(?&parens)\s*+)*+((,(?&identoutter)(\s*+(?&parens)\s*+)*+)*+
15+
((?![{])((?&parens)|(?&brackets)|(?&strunus)|[^\[\]\(\)\{\}'";])*+;(?{dispatch_file_scope_stm(pos(),$minlen)}))
16+
|\s*+(?&brackets)\s*+(?{dispatch_file_scope_stm(pos(),$minlen)})))))
17+
\g{declbod}
18+
(?{pop2 \@matches})|(*F)(?{pop2 \@matches})))
19+
20+
(?<rndbrcksdecl>\s*\((?<inparen>(?<inparenin>\s*+(?&ptr)*+\s*+((?<identinside>(?&identifierpure))(?{register_normal_decl($+{identinside})})|(?&rndbrcksdecl))(\s*+(?&parens)\s*+)*+\s*)*+
21+
((?&inparenin)(?&inparen))?+)\)\s*)
22+
23+
(?<identoutter>\s*+(?&ptr)*+((?&rndbrcksdecl)|(?<identnormal>(?&identifierpure))(?{register_normal_decl($+{identnormal})}))\s*+)
1824

19-
(?<rndbrcksdecl>\s*\((?<inparen>(?<inparenin>\s*+(?&ptr)*+\s*+((?<identinside>(?&identifierpure))(?{register_normal_decl()})|(?&rndbrcksdecl))(\s*+(?&parens)\s*+)*+\s*)*+
20-
((?&inparenin)(?&inparen))?+)\)\s*)

faster.regex.pl

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11

22
sub dispatch_file_scope_stm {
3-
my $currpos = pos();
3+
my $currpos = $_[0];
4+
$lastcurpos = $currpos;
45
#CORE::print ( $currpos . "__" .$lastpos . "\n" );
5-
$q->enqueue(shared_clone([scalar($lastntypedfs), scalar($lastpos), scalar($currpos)]));
6-
$lastpos = $currpos;
7-
if ($typedefs_changed) {
8-
# eval {#use Data::Dumper;
9-
#CORE::print ("sending\n");
10-
#CORE::print Dumper(\$typedefidentifiersvector);
11-
# };
12-
$qtypdfs->enqueue(shared_clone({ %{$typedefidentifiersvector->[0]} }));
13-
$lastntypedfs = $qtypdfs->pending();#scalar(@{keys %{$typedefidentifiersvector->[0]}});
14-
undef $typedefs_changed;
6+
if ($nqueues++ == $minlen) {
7+
$q->enqueue([scalar($lastntypedfs), scalar($lastpos), scalar($currpos), scalar($nqueues) + 1]);
8+
$lastpos = $currpos;
9+
if ($typedefs_changed) {
10+
# eval {#use Data::Dumper;
11+
#CORE::print ("sending\n");
12+
#CORE::print Dumper(\$typedefidentifiersvector);
13+
# };
14+
$qtypdfs->enqueue({ %{$typedefidentifiersvector->[0]} });
15+
$lastntypedfs = $qtypdfs->pending();#scalar(@{keys %{$typedefidentifiersvector->[0]}});
16+
undef $typedefs_changed;
17+
}
18+
$nqueues = 0;
1519
}
1620
}
1721

1822
sub register_taggable {
19-
push_decl($lastpos, $+{identtag})
23+
push_decl($lastcurpos, $+{tagtype} . " " . $+{identtag})
2024
}
2125

2226
sub register_normal_decl {
23-
my $ident = $+{identnormal} // $+{identinside};
27+
my $ident = $_[0];
2428
$matches[-1]{'ident'} = $ident;
2529
register_decl($matches[-1]);
26-
push_decl($lastpos, $ident)
30+
push_decl($lastcurpos, $ident)
2731
}
2832

2933
1

parse.pl

Lines changed: 95 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#my $condinput : shared;
3535
my $condexit : shared;
3636
my $scopevarsdone : shared;
37-
my $identstoidmap : shared = shared_clone({});
37+
$identstoidmap = shared_clone({});
3838
my $identsdone : shared = shared_clone({});
3939
my $identwaiters : shared = shared_clone({});
4040

@@ -56,7 +56,7 @@
5656

5757
@flags = ();
5858

59-
$minlen = $ENV{'MINLEN'};
59+
$minlen = $ENV{'MINQUEUECOUNT'};
6060
$debug = $ENV{'DEBUG'};
6161
$silent = $ENV{'SILENT'};
6262
$lineonly = $ENV{'LINEONLY'};
@@ -67,7 +67,7 @@
6767
my sub print {CORE::print(@_) if( 0 )}
6868
my sub print2 {CORE::print(@_) if(0)}
6969
sub print3 {CORE::print(@_) if( 0)}
70-
my sub Dumper2 {use Data::Dumper; CORE::print(Dumper(@_)) }
70+
sub Dumper2 {use Data::Dumper; CORE::print(Dumper(@_)) }
7171
my sub Dumper {use Data::Dumper; Dumper(@_) if( 0 )}
7272
my sub strftime {use POSIX; strftime(@_) if( 0 )}
7373

@@ -365,7 +365,7 @@ sub dec {
365365

366366
parseregexfile((substr $mainregexfilecontent, length $&), 1);
367367

368-
$mainregexdefs = "$mainregexfinal";
368+
$mainregexdefs = $mainregexfinal;
369369

370370
$mainregexfinal =~s/\s|\n//g if(not $matchinperl);
371371

@@ -635,7 +635,7 @@ sub waitforid {
635635
lock @{$identstoidmap->{$ident}};
636636

637637

638-
#CORE::print("$currpos waitin : " . Dumper2(\@{$identstoidmap->{$ident}}));
638+
CORE::print("$currpos waitin : " . Dumper2(\@{$identstoidmap->{$ident}}));
639639

640640
foreach my $ind (@{$identstoidmap->{$ident}}) {
641641
lock @{$ind};
@@ -652,7 +652,7 @@ sub waitforid {
652652

653653
cond_wait(@{$identstoidmap->{$ident}});
654654

655-
#CORE::print ("end wait on " . $ident . "\n");
655+
CORE::print ("end wait on " . $ident . "\n");
656656
}
657657
}
658658

@@ -661,8 +661,8 @@ sub waitforid {
661661

662662
my $tryingagain: shared = 0;
663663

664-
if(not $isnested)
665-
{
664+
#if(not $isnested)
665+
#{
666666

667667
#my $i = 2;
668668
#use re qw(Debug EXECUTE);
@@ -672,12 +672,13 @@ sub waitforid {
672672
@typedefidentifiersvector = eval { require $ENV{'REPLAY'} . ".txt"};
673673
}
674674
my $flind = 1;
675-
my $execmainregshared = eval { #use re qw(Debug EXECUTE);
676-
"(?(DEFINE)$mainregexdefs)\\G(?&cprogram)" };
675+
my $execmainregshared = $mainregexdefs; #eval { #use re qw(Debug EXECUTE);
676+
#"(?(DEFINE)$mainregexdefs)\\G(?&cprogram)" };
677677
sub execmain {
678678
#use re qw(Debug EXECUTE);
679+
#CORE::print("here1\n");
679680
$regexstr = $_[0];
680-
$regex = qr{$_[0]}sxx;
681+
$regex = qr{(?(DEFINE)$regexstr)\G(?&cprogram)}sxx;
681682
$subject = $_[1];
682683
$fasterregex = $_[2];
683684
$threadid = $_[3];
@@ -698,6 +699,8 @@ sub waitforid {
698699

699700
my $tryingagainlocal;
700701

702+
#CORE::print("here\n");
703+
701704
while (1) {
702705
if (not $tryingagainlocal)
703706
{
@@ -732,6 +735,7 @@ sub waitforid {
732735

733736
#cond_signal ($q)
734737
}
738+
#CORE::print("here\n");
735739

736740
#$silent = 0;
737741

@@ -757,9 +761,10 @@ sub waitforid {
757761
$silent = 1;
758762
$nextpos = scalar($item[2]);
759763
my $ntyps = scalar($item[0]);
764+
my $ntomatch = scalar($item[3]);
760765
#lock $typedefidentifiersvector;
761766
$typedefidentifiersvector = [$ntyps ? {%{$qtypdfs->peek($ntyps - 1)}} : {}]; #[{}];
762-
CORE::print (Dumper(\@{$typedefidentifiersvector}));
767+
#CORE::print (Dumper(\@{$typedefidentifiersvector}));
763768
#CORE::print ("$start\n");
764769
=begin
765770
for my $i (0..$ntyps) {
@@ -854,14 +859,33 @@ sub waitforid {
854859
goto tryagain_begin
855860
}
856861
=cut
857-
tryagain:
858-
pos($subject) = $currposlast;
862+
pos($subject) = $start;
863+
my $lastvalid = $start;
864+
my $tryingagainlocal;
865+
my $lasrtypedefobj = {%{$typedefidentifiersvector->[0]}};
866+
my $i = 1;
867+
my $entertryagain = 0;
868+
while(1){
869+
if ($i++ >= $ntomatch) {
870+
if($+[0] < $nextpos) {
871+
CORE::print "less than nextpos\n";
872+
CORE::print ( "fail" . pos($subject) . "__" .$nextpos . "\n" );
873+
$entertryagain = 1;
874+
goto tryagain
875+
}
876+
last
877+
}
878+
tryagain: #[{}];
879+
#pos($subject) = $currposlast;
859880
@flags = ();
860881
@matches = ();
861882
@savedcallouts = ();
862883
$recording = 0;
863-
if(!($subject =~ $regex) || $+[0] < $nextpos) {
864-
CORE::print ( "fail" . $+[0] . "__" .$nextpos . "\n" );
884+
#CORE::print ("matchin...");
885+
if($entertryagain || !($subject =~ m{$regex}gxxs)) {
886+
#CORE::print ( "fail" . $+[0] . "__" .$nextpos . "\n" );
887+
pos($subject) = $lastvalid;
888+
$typedefidentifiersvector = [{%{$lasrtypedefobj}}];
865889
if ($tryingagainlocal) {
866890
lock ($tryingagain);
867891
if($tryingagain) {
@@ -870,22 +894,29 @@ sub waitforid {
870894
CORE::print ("4 failed near " . pos($subject) . " - start - $start\n");
871895

872896
$tryingagainlocal = $tryingagain = 1;
873-
$silent = 0;
897+
#$silent = 0;
874898
#CORE::print (Dump(\@{$typedefidentifiersvector}));
875-
CORE::print (Dumper(\@{$typedefidentifiersvector}));
876-
$silent = 1;
899+
#CORE::print (Dumper2(\@{$typedefidentifiersvector}));
900+
#$silent = 1;
877901
CORE::print ("retrying...");
878902

879-
$regex = eval { use re qw(Debug EXECUTE); qr{$regexstr}sxx; };
903+
$regex = eval { use re qw(Debug EXECUTE); qr{(?(DEFINE)$regexstr)\G(?&cprogram)}sxx; };
880904
}
881905
$tryingagainlocal = 1;
906+
$entertryagain = 0;
882907
#CORE::print("currposlast" . $currposlast . "\n");
883908
goto tryagain
884909
}
910+
#else {
911+
$lastvalid = $+[0];
912+
$tryingagainlocal = 0;
913+
$lasrtypedefobj = {%{$typedefidentifiersvector->[0]}};
914+
#}
885915
#CORE::print("$threadid -- $i ==========succes=============\n $&\n==========endsuccess=============\n");
886916
#pos($subject) = $+[0]
887917
#CORE::print ("pos is to pos " . $+[0] . "\n");
888-
$currposlast = $+[0];
918+
#$currposlast = $+[0];
919+
}
889920
#}
890921
#$currposlast = $+[0]
891922
#CORE::print (Dumper(\@{$typedefidentifiersvector}));
@@ -988,12 +1019,49 @@ sub waitforid {
9881019
push2 \@matches, {};
9891020
push2 \@flags, {"outter"=>undef,"opt"=>undef, "nonbitfl"=>undef};
9901021

991-
while($subject =~ m{$initseqlight
992-
(;|^)(?{dispatch_file_scope_stm()})\s*+(?&fasterdecls)|(?&parens)(\s*+(?&brackets)\s*+(?{dispatch_file_scope_stm()})(?&fasterdecls))?+|(?&brackets)|(?&strunus)}sxxg) {
993-
}
1022+
my $tryagain = 2;
1023+
my $lasrtypedefobj = {%{$typedefidentifiersvector->[0]}};
1024+
my $lastposcurrlast = 0;
1025+
my $compreg = qr{$initseqlight\G\s*+(?&fasterdecls)}sxx;
9941026

995-
if(!($subject =~ m{\s*+$}sxxg)) {
996-
exit -1
1027+
#while(1) {
1028+
{
1029+
tryagain_main:
1030+
while($subject =~ m{$compreg}gxxs) {
1031+
#CORE::print($lastposcurrlast . "\n");
1032+
$lasrtypedefobj = {%{$typedefidentifiersvector->[0]}};
1033+
$lastposcurrlast = $+[0];
1034+
}
1035+
1036+
if(!($subject =~ m{$}sxxg)) {
1037+
@flags = ();
1038+
@matches = ();
1039+
@savedcallouts = ();
1040+
$recording = 0;
1041+
push2 \@matches, {};
1042+
push2 \@flags, {"outter"=>undef,"opt"=>undef, "nonbitfl"=>undef};
1043+
$typedefidentifiersvector = [{%{$lasrtypedefobj}}];
1044+
if(!$tryagain) {
1045+
1046+
$tryagain = 1;
1047+
pos($subject) = $lastposcurrlast;
1048+
goto tryagain_main
1049+
}
1050+
elsif($tryagain++ == 1) {
1051+
use re qw(Debug EXECUTE);
1052+
$compreg = qr{(?(DEFINE)$fasterregexfilecontent$fasterlightregexfilecontent)\G\s*+(?&fasterdecls)}sxx;
1053+
#CORE::print("trying again with debug\n" . $initseqlight );
1054+
pos($subject) = $lastposcurrlast;
1055+
goto tryagain_main
1056+
}
1057+
CORE::print ( "test failed" . $lastposcurrlast . "__" .length $subject . "\n" );
1058+
exit -1;
1059+
}
1060+
}
1061+
#}
1062+
1063+
if ($nqueues) {
1064+
$q->enqueue(([scalar($lastntypedfs), scalar($lastpos), scalar(length $subject), scalar($nqueues) + 1]));
9971065
}
9981066

9991067
CORE::print ("joinning for real $lastqueuepoint\n");
@@ -1398,7 +1466,7 @@ sub waitforid {
13981466
=cut
13991467
# }
14001468
exit;
1401-
}
1469+
#}
14021470

14031471
#}
14041472

typename.regex.pl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616

1717
#sub inittypenameconstants {
1818

19+
%types = ();
20+
%ququalifiers = ();
21+
%storageclass = ();
22+
%keywords = ();
23+
%tags = ();
24+
1925
@types{
2026
"int",
2127
"char",
@@ -60,6 +66,12 @@
6066
"while"
6167
} = ();
6268

69+
@tags{
70+
"struct",
71+
"union",
72+
"enum"
73+
} = ();
74+
6375
%qualifsnstrgcls_all = (%qualifiers, %storageclass, "typedef");
6476

6577
%keywords = (%qualifsnstrgcls_all, %types, %keywords);
@@ -156,8 +168,11 @@ sub checktypeorqualifortypdf {
156168
my $force = $_[0];
157169

158170
#inc2 "facet";
159-
# CORE::print ("at g " . Dumper(\%typeandqualifs) . "\n");
171+
#CORE::print ("dumping\n");
172+
#Dumper2(\%tags);
160173
my $input = $^N;
174+
#CORE::print ("iednt $input \n");
175+
return 0 if (exists $tags{$input});
161176
if (exists $typeandqualifs{$input}) {
162177
print3 "$^N -> qualifortype\n";
163178
if(exists $types{$input}) {

0 commit comments

Comments
 (0)