|
6 | 6 | # Copyright (c) 2009-2011, PostgreSQL Global Development Group
|
7 | 7 | #
|
8 | 8 | # Written by Michael Meskes <meskes@postgresql.org>
|
| 9 | +# Andy Colson <andy@squeakycode.net> |
9 | 10 | #
|
10 | 11 | # Placed under the same license as PostgreSQL.
|
11 | 12 | #
|
| 13 | +# Command line: [-v] [path only to ecpg.addons] [full filename of gram.y] |
| 14 | +# -v enables verbose mode... show's some stats... thought it might be interesting |
| 15 | +# |
| 16 | +# This script loads rule names from gram.y and sets $found{rule} = 1 for each. |
| 17 | +# Then it checks to make sure each rule in ecpg.addons was found in gram.y |
12 | 18 |
|
13 |
| -if (@ARGV) { |
14 |
| -$path =$ARGV[0]; |
15 |
| -$parser =$ARGV[1]; |
16 |
| -} |
| 19 | +use strict; |
| 20 | +use warnings; |
| 21 | +no warnings'uninitialized'; |
17 | 22 |
|
18 |
| -$[ = 1;# set array base to 1 |
| 23 | +my$verbose = 0; |
| 24 | +if ($ARGV[0]eq'-v') |
| 25 | +{ |
| 26 | +$verbose =shift; |
| 27 | +} |
| 28 | +my$path =shift ||'.'; |
| 29 | +my$parser =shift ||'../../../backend/parser/gram.y'; |
| 30 | + |
| 31 | +my$filename =$path ."/ecpg.addons"; |
| 32 | +if ($verbose) |
| 33 | +{ |
| 34 | +print"parser:$parser\n"; |
| 35 | +print"addons:$filename\n"; |
| 36 | +} |
19 | 37 |
|
20 |
| -if ($patheq'') {$path ="."; } |
21 |
| -$filename =$path ."/ecpg.addons"; |
| 38 | +my%replace_line = ( |
| 39 | +'ExecuteStmtEXECUTEnameexecute_param_clause'=> |
| 40 | +'EXECUTE prepared_name execute_param_clause execute_rest', |
22 | 41 |
|
23 |
| -if ($parsereq'') {$parser ="../../../backend/parser/gram.y"; } |
| 42 | +'ExecuteStmtCREATEOptTempTABLEcreate_as_targetASEXECUTEnameexecute_param_clause'=> |
| 43 | +'CREATE OptTemp TABLE create_as_target AS EXECUTE prepared_name execute_param_clause', |
24 | 44 |
|
25 |
| -$replace_line{'ExecuteStmtEXECUTEnameexecute_param_clause'} ='EXECUTE prepared_name execute_param_clause execute_rest'; |
26 |
| -$replace_line{'ExecuteStmtCREATEOptTempTABLEcreate_as_targetASEXECUTEnameexecute_param_clause'} ='CREATE OptTemp TABLE create_as_targetASEXECUTE prepared_name execute_param_clause'; |
27 |
| -$replace_line{'PrepareStmtPREPAREnameprep_type_clauseASPreparableStmt'} ='PREPARE prepared_name prep_type_clause AS PreparableStmt'; |
| 45 | +'PrepareStmtPREPAREnameprep_type_clauseASPreparableStmt'=> |
| 46 | +'PREPARE prepared_name prep_type_clauseASPreparableStmt' |
| 47 | +); |
28 | 48 |
|
29 |
| -$block =''; |
30 |
| -$ret = 0; |
31 |
| -$yaccmod = 0; |
32 |
| -$brace_indent = 0; |
| 49 | +my$block =''; |
| 50 | +my$yaccmode = 0; |
| 51 | +my$brace_indent = 0; |
| 52 | +my (@arr,%found); |
| 53 | +my$comment = 0; |
| 54 | +my$non_term_id =''; |
| 55 | +my$cc = 0; |
33 | 56 |
|
34 | 57 | open GRAM,$parserordie$!;
|
35 |
| -while (<GRAM>) { |
36 |
| -chomp;# strip record separator |
| 58 | +while (<GRAM>) |
| 59 | +{ |
| 60 | +if (/^%%/) |
| 61 | +{ |
| 62 | +$yaccmode++; |
| 63 | +} |
37 | 64 |
|
38 |
| -if (/^%%/) { |
39 |
| -$yaccmode++; |
| 65 | +if ($yaccmode != 1 ) |
| 66 | +{ |
| 67 | +next; |
40 | 68 | }
|
41 | 69 |
|
42 |
| -if ($yaccmode != 1) { |
43 |
| -next; |
44 |
| - } |
| 70 | +chomp;# strip record separator |
45 | 71 |
|
46 |
| -$S =$_; |
47 |
| -$prec = 0; |
| 72 | +nextif ($_eq''); |
48 | 73 |
|
49 | 74 | # Make sure any braces are split
|
50 |
| -$S =~s/{/ {/g; |
51 |
| -$S =~s/}/ }/g; |
| 75 | +s/{/ {/g; |
| 76 | +s/}/ }/g; |
| 77 | + |
52 | 78 | # Any comments are split
|
53 |
| -$S =~s#[/][*]# /*#g; |
54 |
| -$S =~s#[*][/]# */#g; |
| 79 | +s|\/\*| /*|g; |
| 80 | +s|\*\/| */|g; |
55 | 81 |
|
56 | 82 | # Now split the line into individual fields
|
57 |
| -$n = (@arr =split('',$S)); |
| 83 | +my$n = (@arr =split('' )); |
58 | 84 |
|
59 | 85 | # Go through each field in turn
|
60 |
| -for ($fieldIndexer = 1;$fieldIndexer <=$n;$fieldIndexer++) { |
61 |
| -if ($arr[$fieldIndexer]eq'*/' &&$comment) { |
62 |
| -$comment = 0; |
63 |
| -next; |
| 86 | +for (my$fieldIndexer = 0 ;$fieldIndexer <$n ;$fieldIndexer++ ) |
| 87 | +{ |
| 88 | +if ($arr[$fieldIndexer]eq'*/' &&$comment ) |
| 89 | +{ |
| 90 | +$comment = 0; |
| 91 | +next; |
64 | 92 | }
|
65 |
| -elsif ($comment) { |
66 |
| -next; |
| 93 | +elsif ($comment) |
| 94 | +{ |
| 95 | +next; |
67 | 96 | }
|
68 |
| -elsif ($arr[$fieldIndexer]eq'/*') { |
69 |
| -# start of a multiline comment |
70 |
| -$comment = 1; |
71 |
| -next; |
| 97 | +elsif ($arr[$fieldIndexer]eq'/*' ) |
| 98 | +{ |
| 99 | +# start of a multiline comment |
| 100 | +$comment = 1; |
| 101 | +next; |
72 | 102 | }
|
73 |
| -elsif ($arr[$fieldIndexer]eq'//') { |
74 |
| -next; |
| 103 | +elsif ($arr[$fieldIndexer]eq'//' ) |
| 104 | +{ |
| 105 | +next; |
75 | 106 | }
|
76 |
| -elsif ($arr[$fieldIndexer]eq'}') { |
77 |
| -$brace_indent--; |
78 |
| -next; |
| 107 | +elsif ($arr[$fieldIndexer]eq'}' ) |
| 108 | +{ |
| 109 | +$brace_indent--; |
| 110 | +next; |
79 | 111 | }
|
80 |
| -elsif ($arr[$fieldIndexer]eq'{') { |
81 |
| -$brace_indent++; |
82 |
| -next; |
| 112 | +elsif ($arr[$fieldIndexer]eq'{' ) |
| 113 | +{ |
| 114 | +$brace_indent++; |
| 115 | +next; |
83 | 116 | }
|
84 | 117 |
|
85 |
| -if ($brace_indent > 0) { |
86 |
| -next; |
| 118 | +if ($brace_indent > 0 ) |
| 119 | +{ |
| 120 | +next; |
87 | 121 | }
|
88 | 122 |
|
89 |
| -if ($arr[$fieldIndexer]eq';' ||$arr[$fieldIndexer]eq'|') { |
| 123 | +if ($arr[$fieldIndexer]eq';' ||$arr[$fieldIndexer]eq'|' ) |
| 124 | +{ |
90 | 125 | $block =$non_term_id .$block;
|
91 |
| -if ($replace_line{$block}) { |
92 |
| -$block = &generate_block($replace_line{$block}); |
| 126 | +if ($replace_line{$block} ) |
| 127 | +{ |
| 128 | +$block =$non_term_id .$replace_line{$block}; |
| 129 | +$block =~tr/ |//d; |
93 | 130 | }
|
94 |
| -$found{$block} ='found'; |
| 131 | +$found{$block} = 1; |
| 132 | +$cc++; |
95 | 133 | $block ='';
|
96 | 134 | }
|
97 |
| -elsif (($arr[$fieldIndexer] =~'[A-Za-z0-9]+:') ||$arr[$fieldIndexer + 1]eq':') { |
| 135 | +elsif ( ($arr[$fieldIndexer] =~'[A-Za-z0-9]+:' ) |
| 136 | +||$arr[$fieldIndexer + 1 ]eq':' ) |
| 137 | +{ |
98 | 138 | $non_term_id =$arr[$fieldIndexer];
|
99 |
| -$non_term_id =~s/://g; |
| 139 | +$non_term_id =~tr/://d; |
100 | 140 | }
|
101 |
| -else { |
| 141 | +else |
| 142 | +{ |
102 | 143 | $block =$block .$arr[$fieldIndexer];
|
103 | 144 | }
|
104 | 145 | }
|
105 | 146 | }
|
106 | 147 |
|
107 | 148 | close GRAM;
|
| 149 | +if ($verbose) |
| 150 | +{ |
| 151 | +print"$cc rules loaded\n"; |
| 152 | +} |
108 | 153 |
|
109 |
| -open ECPG,$filenameordie$!; |
110 |
| - |
111 |
| -line:while (<ECPG>) { |
112 |
| -chomp;# strip record separator |
113 |
| -@Fld =split('',$_, -1); |
| 154 | +my$ret = 0; |
| 155 | +$cc = 0; |
114 | 156 |
|
115 |
| -if (!/^ECPG:/) { |
116 |
| -next line; |
117 |
| - } |
| 157 | +open ECPG,$filenameordie$!; |
| 158 | +while (<ECPG>) |
| 159 | +{ |
| 160 | +if ( !/^ECPG:/ ) |
| 161 | +{ |
| 162 | +next; |
| 163 | +} |
118 | 164 |
|
119 |
| -if ($found{$Fld[2]}ne'found') { |
120 |
| -printf$Fld[2] ." is not used for building parser!\n"; |
121 |
| -$ret = 1; |
122 |
| - } |
| 165 | +my@Fld =split('',$_, 3 ); |
| 166 | +$cc++; |
| 167 | +if (notexists$found{$Fld[1] } ) |
| 168 | +{ |
| 169 | +print$Fld[1]," is not used for building parser!\n"; |
| 170 | +$ret = 1; |
| 171 | +} |
123 | 172 | }
|
124 |
| - |
125 | 173 | close ECPG;
|
126 | 174 |
|
| 175 | +if ($verbose) |
| 176 | +{ |
| 177 | +print"$cc rules checked\n"; |
| 178 | +} |
| 179 | + |
127 | 180 | exit$ret;
|
128 | 181 |
|
129 |
| -subgenerate_block { |
130 |
| -local($line) =@_; |
131 |
| -$block =$non_term_id .$line; |
132 |
| -$block =~s///g; |
133 |
| -$s ="\\|",$block =~s/$s//g; |
134 |
| -return$block; |
135 |
| -} |
|