Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0778eb7

Browse files
committed
Improve perl style in ecpg's parser-construction scripts.
parse.pl and check_rules.pl used "no warnings 'uninitialized'",which doesn't seem like it measures up to current project standards.Removing that shows that it was hiding various places that accessedoff the end of an array, which are easily protected by minor logicadjustments. There's no change in the script results.While here, improve the Makefile rule that invokes these scripts.It neglected to depend on check_rules.pl, so that editing that filedidn't result in re-running the check; and it ran check_rules.plafter building preproc.y, so that if check_rules.pl did fail thenext "make" attempt would just bypass it. check_rules.pl failuresare sufficiently un-heard-of that I don't feel a need to back-patchthis.Discussion:https://postgr.es/m/838180.1658181982@sss.pgh.pa.us
1 parentd268d0f commit0778eb7

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

‎src/interfaces/ecpg/preproc/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ preproc.h: preproc.c
6464

6565
preproc.c: BISONFLAGS += -d
6666

67-
preproc.y: ../../../backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.tokens ecpg.trailer ecpg.type
68-
$(PERL)$(srcdir)/parse.pl --srcdir$(srcdir) --parser$< --output$@
67+
preproc.y: ../../../backend/parser/gram.y parse.pl check_rules.pl ecpg.addons ecpg.header ecpg.tokens ecpg.trailer ecpg.type
6968
$(PERL)$(srcdir)/check_rules.pl --srcdir$(srcdir) --parser$<
69+
$(PERL)$(srcdir)/parse.pl --srcdir$(srcdir) --parser$< --output$@
7070

7171
# generate keyword headers
7272
c_kwlist_d.h: c_kwlist.h$(GEN_KEYWORDLIST_DEPS)

‎src/interfaces/ecpg/preproc/check_rules.pl

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

1919
use strict;
2020
use warnings;
21-
no warnings'uninitialized';
2221
use Getopt::Long;
2322

2423
my$srcdir ='.';
@@ -142,7 +141,8 @@
142141
$in_rule = 0if$arr[$fieldIndexer]eq';';
143142
}
144143
elsif (($arr[$fieldIndexer] =~'[A-Za-z0-9]+:')
145-
||$arr[$fieldIndexer + 1 ]eq':')
144+
|| ($fieldIndexer + 1 <$n
145+
&&$arr[$fieldIndexer + 1 ]eq':'))
146146
{
147147
die"unterminated rule at grammar line$.\n"
148148
if$in_rule;

‎src/interfaces/ecpg/preproc/parse.pl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
use strict;
1616
use warnings;
17-
no warnings'uninitialized';
1817
use Getopt::Long;
1918

2019
my$srcdir ='.';
@@ -40,7 +39,8 @@
4039

4140
my (%buff,$infield,$comment,%tokens,%addons);
4241
my ($stmt_mode,@fields);
43-
my ($line,$non_term_id);
42+
my$line ='';
43+
my$non_term_id;
4444

4545

4646
# some token have to be replaced by other symbols
@@ -195,6 +195,16 @@ sub main
195195
# Now split the line into individual fields
196196
my@arr =split('');
197197

198+
if (!@arr)
199+
{
200+
# empty line: in tokenmode 1, emit an empty line, else ignore
201+
if ($tokenmode == 1)
202+
{
203+
add_to_buffer('orig_tokens','');
204+
}
205+
next line;
206+
}
207+
198208
if ($arr[0]eq'%token' &&$tokenmode == 0)
199209
{
200210
$tokenmode = 1;
@@ -341,7 +351,8 @@ sub main
341351

342352
# Are we looking at a declaration of a non-terminal ?
343353
if (($arr[$fieldIndexer] =~/[A-Za-z0-9]+:/)
344-
||$arr[$fieldIndexer + 1 ]eq':')
354+
|| ($fieldIndexer + 1 <scalar(@arr)
355+
&&$arr[$fieldIndexer + 1 ]eq':'))
345356
{
346357
$non_term_id =$arr[$fieldIndexer];
347358
$non_term_id =~tr/://d;
@@ -409,11 +420,13 @@ sub main
409420
if ($copymode
410421
&& !$prec
411422
&& !$comment
423+
&&$fieldIndexer <scalar(@arr)
412424
&&length($arr[$fieldIndexer])
413425
&&$infield)
414426
{
415427
if ($arr[$fieldIndexer]ne'Op'
416-
&& ($tokens{$arr[$fieldIndexer] } > 0
428+
&& ((defined$tokens{$arr[$fieldIndexer] }
429+
&&$tokens{$arr[$fieldIndexer] } > 0)
417430
||$arr[$fieldIndexer] =~/'.+'/)
418431
||$stmt_mode == 1)
419432
{
@@ -472,11 +485,12 @@ sub include_addon
472485
my$rec =$addons{$block};
473486
return 0unless$rec;
474487

475-
if ($rec->{type}eq'rule')
488+
my$rectype = (defined$rec->{type}) ?$rec->{type} :'';
489+
if ($rectypeeq'rule')
476490
{
477491
dump_fields($stmt_mode,$fields,' {');
478492
}
479-
elsif ($rec->{type}eq'addon')
493+
elsif ($rectypeeq'addon')
480494
{
481495
add_to_buffer('rules',' {');
482496
}
@@ -487,7 +501,7 @@ sub include_addon
487501

488502
push(@{$buff{$buffer} }, @{$rec->{lines} });
489503

490-
if ($rec->{type}eq'addon')
504+
if ($rectypeeq'addon')
491505
{
492506
dump_fields($stmt_mode,$fields,'');
493507
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp