Skip to content

Commit 48edb8d

Browse files
Some rehaul in progress
1 parent b325544 commit 48edb8d

File tree

5 files changed

+121
-85
lines changed

5 files changed

+121
-85
lines changed

faster.regex

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@
55

66

77
(?<rndbrcksdecl>\s*\((?<inparen>(?<inparenin>\s*+(?&ptr)*+\s*+((?<identinside>(?&identifierpure))|(?&rndbrcksdecl))(\s*+(?&parens)\s*+)*+\s*)*+
8-
((?&inparenin)(?&inparen))?+)\)\s*(?(<identinside>)(*ACCEPT)))
8+
((?&inparenin)(?&inparen))?+)\)\s*)
99

10-
(?<declfast>\s*+(?(?=(?&rndbrcksdecl))(?&parens)|(?<identoutside>(?&identifierpure)))\s*+)
10+
(?<typeorqualifortypdf>\s*+((?&identifierpure))(?(?{checktypeorqualifortypdf(1)})|(*F))\s*+)
1111

12+
(?<qualifonly>((?&identifierpure))(?(?{checkqualifonly()})|(*F)))
1213

13-
(?<fasttypedef>((?(<typedefident>)(?<identfakedef>(?&identifier_typedef))(*F)|(?<typedefident>(?&identifier_typedef)))(?(<qualifortagfound>)(*F))|(?<qualifortagfound>(?&typeorqualif)|(?&fasttaggable))|\s*+\btypedef\b\s*+)*+)
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*+)*+)*+)))(?{dispatch_file_scope_stm()})\g{declbod}|(*F)(?{$recording--; pop2 \@matches})))
1418

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: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,25 @@
11

2-
my %tagkeys;
3-
@tagkeys{
4-
"struct",
5-
"union",
6-
"enum",
7-
} = ();
8-
9-
sub checkfastident {
10-
$istaggable = exists $tagkeys{$+{identf}};
11-
# CORE::print "$+{identf}\n";
12-
$istypedef = 0;
13-
14-
if ($+{identf} ne "typedef") {
15-
return qr{};
2+
sub dispatch_file_scope_stm {
3+
my $currpos = pos();
4+
CORE::print ( $currpos . "__" .$lastpos . "\n" );
5+
$q->enqueue([scalar($lastntypedfs), scalar($lastpos), scalar($currpos)]);
6+
$lastpos = $currpos;
7+
if ($typedefs_changed) {
8+
$qtypdfs->enqueue(\{ %{$typedefidentifiersvector->[0]} });
9+
$lastntypedfs = $qtypdfs->pending();#scalar(@{keys %{$typedefidentifiersvector->[0]}});
10+
undef $typedefs_changed;
1611
}
17-
18-
$istypedef = 1;
19-
20-
return qr{(*F)};
2112
}
2213

23-
=begin
24-
sub register_decl_universal {
25-
my $res = $_[2];
26-
my $out = $_[3];
27-
28-
if ($istypedef) {
29-
register_decl();
30-
$$res = 1;
31-
$$out = $lastdeclpos;
32-
CORE::print "$lastdeclpos";
33-
}
14+
sub register_taggable {
15+
push_decl($lastpos, $+{identtag})
3416
}
35-
=cut
3617

37-
sub register_decl_fast {
38-
CORE::print pos() . "\n";
18+
sub register_normal_decl {
19+
my $ident = $+{identnormal} // $+{identinside};
20+
$matches[-1]{'ident'} = $ident;
21+
register_decl($matches[-1]);
22+
push_decl($lastpos, $ident)
3923
}
4024

4125
1

fasterlight.regex

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
(?<identifierpure>(?>[_a-zA-Z](?<letter>[_a-zA-Z0-9])*+))
2020

21-
(?<rndbrcksdecl>\s*\((?<inparen>(?<inparenin>\s*+(?&ptr)*+\s*+((?<identinside>\K(?&identifierpure))|(?&rndbrcksdecl))(\s*+(?&parens)\s*+)*+\s*)*+
22-
((?&inparenin)(?&inparen))?+)\)\s*)
2321

24-
(?<ptr>\s*+\*\s*+(?&typeorqualif)*+\s*+)
22+
23+
(?<ptr>\s*+\*\s*+(?&qualifonly)*+\s*+)

parse.pl

Lines changed: 90 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
our @typedfsmap : shared;
1818

19-
my $q = Thread::Queue->new();
19+
$q = Thread::Queue->new();
2020

21-
our $qtypdfs = Thread::Queue->new();
21+
$qtypdfs = Thread::Queue->new();
2222

2323
my @sharedarr;
2424
my @sharedarrcommon : shared;
@@ -675,7 +675,7 @@ sub waitforid {
675675
my $execmainregshared = eval { #use re qw(Debug EXECUTE);
676676
"(?(DEFINE)$mainregexdefs)\\G(?&cprogram)" };
677677
sub execmain {
678-
use re qw(Debug EXECUTE);
678+
#use re qw(Debug EXECUTE);
679679
$regexstr = $_[0];
680680
$regex = qr{$_[0]}sxx;
681681
$subject = $_[1];
@@ -755,13 +755,12 @@ sub waitforid {
755755
$silent = 0;
756756
#CORE::print("$index - working - " . Dumper(\%typdefshash). "\n");
757757
$silent = 1;
758-
$nfilescopesrequested = scalar($item[2]);
759-
$nextpos = scalar($item[3]);
760-
$ntimes = scalar($item[4]);
758+
$nextpos = scalar($item[2]);
761759
my $ntyps = scalar($item[0]);
762760
#lock $typedefidentifiersvector;
763761
$typedefidentifiersvector = [$ntyps ? %{$qtypdfs->peek($ntyps - 1)} : {}]; #[{}];
764762
CORE::print (Dumper(\@{$typedefidentifiersvector}));
763+
#CORE::print ("$start\n");
765764
=begin
766765
for my $i (0..$ntyps) {
767766
my $elem = $qtypdfs->peek($i);
@@ -794,7 +793,7 @@ sub waitforid {
794793
#eval { updateavailidents($identstoidmap) };
795794

796795

797-
pos($subject) = $start;
796+
$currposlast = $start;
798797

799798
#CORE::print "$subject\n";
800799

@@ -844,45 +843,52 @@ sub waitforid {
844843
#$silent =0;
845844
#CORE::print ("begin " . Dumper(\$typedefidentifiersvector));
846845
#$silent =1;
846+
=begin
847847
my $currposlast = $start;
848-
for my $i (0..$ntimes) {
849-
850-
tryagain:
851-
pos($subject) = $currposlast;
852-
while(scalar(@{$typedefidentifiersvector}) != 1) {
853-
pop @{$typedefidentifiersvector};
848+
my $i = 0;
849+
while(1) {
850+
CORE::print ("pos is to after " . $+[0] . "\n");
851+
if ($i++ >= $ntimes) {
852+
last unless ($currposlast < $lastpos);
853+
CORE::print ("pos is last $lastpos\n to pos " . $currposlast . "\n");
854+
goto tryagain_begin
854855
}
855-
@flags = ();
856-
@matches = ();
857-
@savedcallouts = ();
858-
$recording = 0;
859-
if(!($subject =~ $regex)) {
860-
if ($tryingagainlocal) {
861-
lock ($tryingagain);
862-
if($tryingagain) {
863-
sleep (100000);
864-
}
865-
CORE::print ("4 failed near " . pos($subject) . " - start - $start\n");
866-
867-
$tryingagainlocal = $tryingagain = 1;
868-
$silent = 0;
869-
#CORE::print (Dump(\@{$typedefidentifiersvector}));
870-
CORE::print (Dumper(\@{$typedefidentifiersvector}));
871-
$silent = 1;
872-
CORE::print ("retrying...");
873-
874-
$regex = eval { use re qw(Debug EXECUTE); qr{$regexstr}sxx; };
875-
}
876-
$tryingagainlocal = 1;
877-
#CORE::print("currposlast" . $currposlast . "\n");
878-
goto tryagain
856+
=cut
857+
tryagain:
858+
pos($subject) = $currposlast;
859+
@flags = ();
860+
@matches = ();
861+
@savedcallouts = ();
862+
$recording = 0;
863+
if(!($subject =~ $regex) || $+[0] < $nextpos) {
864+
CORE::print ( "fail" . $+[0] . "__" .$nextpos . "\n" );
865+
if ($tryingagainlocal) {
866+
lock ($tryingagain);
867+
if($tryingagain) {
868+
sleep (100000);
869+
}
870+
CORE::print ("4 failed near " . pos($subject) . " - start - $start\n");
871+
872+
$tryingagainlocal = $tryingagain = 1;
873+
$silent = 0;
874+
#CORE::print (Dump(\@{$typedefidentifiersvector}));
875+
CORE::print (Dumper(\@{$typedefidentifiersvector}));
876+
$silent = 1;
877+
CORE::print ("retrying...");
878+
879+
$regex = eval { use re qw(Debug EXECUTE); qr{$regexstr}sxx; };
879880
}
880-
#CORE::print("$threadid -- $i ==========succes=============\n $&\n==========endsuccess=============\n");
881-
#pos($subject) = $+[0]
882-
$currposlast = $+[0]
881+
$tryingagainlocal = 1;
882+
#CORE::print("currposlast" . $currposlast . "\n");
883+
goto tryagain
883884
}
885+
#CORE::print("$threadid -- $i ==========succes=============\n $&\n==========endsuccess=============\n");
886+
#pos($subject) = $+[0]
887+
#CORE::print ("pos is to pos " . $+[0] . "\n");
888+
$currposlast = $+[0];
889+
#}
884890
#$currposlast = $+[0]
885-
CORE::print (Dumper(\@{$typedefidentifiersvector}));
891+
#CORE::print (Dumper(\@{$typedefidentifiersvector}));
886892
}
887893

888894
#CORE::print("==========succes=============\n $&\n==========endsuccess=============\n");
@@ -960,7 +966,45 @@ sub waitforid {
960966

961967
my $initseqlight = $fasterlightregexfilecontent;
962968

963-
my $initseqlight = "(?(DEFINE)$fasterlightregexfilecontent)";
969+
sub push_decl {
970+
my $lastposend = $_[0];
971+
my $possibleidentlocal = $_[1];
972+
lock $identstoidmap;
973+
if (not exists $identstoidmap->{$possibleidentlocal}) {
974+
$identstoidmap->{$possibleidentlocal} = shared_clone([[$lastposend, 0]])
975+
}
976+
else {
977+
lock (@{$identstoidmap->{$possibleidentlocal}});
978+
push @{$identstoidmap->{$possibleidentlocal}}, shared_clone([$lastposend, 0]);
979+
}
980+
}
981+
982+
my $initseqlight = qr{(?(DEFINE)$fasterregexfilecontent$fasterlightregexfilecontent)}sxx;
983+
984+
for (1..$maxthreads) {
985+
push @threads, threads->create(\&execmain, $execmainregshared, $subject, $initseq, $_);
986+
}
987+
988+
push2 \@matches, {};
989+
push2 \@flags, {"outter"=>undef,"opt"=>undef, "nonbitfl"=>undef};
990+
991+
while($subject =~ m{$initseqlight
992+
;\s*+(?&fasterdecls)|(?&parens)(\s*+(?&brackets)\s*+(?&fasterdecls))?+|(?&brackets)|(?&strunus)}sxxg) {
993+
}
994+
995+
if(!($subject =~ m{\s*+$}sxxg)) {
996+
exit -1
997+
}
998+
999+
CORE::print ("joinning for real $lastqueuepoint\n");
1000+
1001+
$q->end();
1002+
1003+
$_->join for @threads;
1004+
exit
1005+
1006+
pop2 \@matches;
1007+
pop2 \@flags;
9641008

9651009
$delegatetaggables = 1;
9661010
# sub execmain {
@@ -980,7 +1024,7 @@ sub waitforid {
9801024
}
9811025
}
9821026
}
983-
=cut
1027+
= cut
9841028
#push2 \@savedcallouts, [];
9851029
#++$recording;
9861030
#push2 \@flags, {"skiptaggedbodies"};
@@ -1103,7 +1147,7 @@ sub waitforid {
11031147
#push @typedefidentifiersvectorcopies, { %{$typedefidentifiersvector->[0]} };
11041148
++$nfilescopesrequested;
11051149
#CORE::print (("lastpos is : " . $lastpos) . "\n");
1106-
$lastqueuepoint = $lastposend;
1150+
$lastqueuepoint = $lastpos;
11071151
$ndeclsorbodies = 0;
11081152
}
11091153
@@ -1226,11 +1270,12 @@ sub waitforid {
12261270
}
12271271
12281272
if ($shouldstorelast) {
1229-
pos($subject) = $lastpos;
1273+
#pos($subject) = $lastpos;
12301274
$lastposend = $lastpos;
12311275
++$ndeclsorbodies;
12321276
}
12331277
}
1278+
=cut
12341279
#pop2 \@savedcallouts, [];
12351280
#pop2 \@flags;
12361281
#--$recording;

typename.regex.pl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ sub checktypeorqualifortypdf {
164164
eval {$matches[-1]{typefound} = $input};
165165
call "add_type" if (not $force);
166166
return 1;
167-
} elsif($force || eval { existsflag("outter", {"optoutter" => undef, "outterparams" })
167+
} elsif(eval { existsflag("outter", {"optoutter" => undef, "outterparams" })
168168
|| existsflag("outterparams", {"optoutter" => undef, "outter" })}) {
169169
if($input eq 'typedef') {
170170
eval {$matches[-1]{typedefkey} = $input};
@@ -214,7 +214,9 @@ sub register_decl{
214214
#$silent = 0;
215215
#$sielnt = 1;
216216
my $identifier = $_[0]{'ident'};
217-
#CORE::print ("register $threadid ". $identifier . "\n");
217+
CORE::print ("register $threadid ". $identifier . "\n");
218+
use Data::Dumper;
219+
Dumper($_[0]);
218220
return if not $identifier;
219221
#$last_object_identifier = $identifier;
220222
my $priorstate = exists ${$typedefidentifiersvector->[-1]}{$identifier} ? ${$typedefidentifiersvector->[-1]}{$identifier} : -1;

0 commit comments

Comments
 (0)