File: fix-bison

package info (click to toggle)
raptor2 2.0.8-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 15,420 kB
  • sloc: ansic: 36,499; sh: 11,917; xml: 6,629; yacc: 2,357; makefile: 1,759; perl: 1,013; lex: 961; cpp: 59
file content (54 lines) | stat: -rw-r--r-- 1,388 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/perl
#
# Format output generated by bison
#
# Usage:
#  bison -b brql_parser -p brql_parser_ -d -v brql_parser.y
#  perl fix-bison brql_parser.tab.c > $tmp
#  mv $tmp brql_parser.tab.c
#
# Copyright (C) 2004-2006, David Beckett http://www.dajobe.org/
# Copyright (C) 2004, University of Bristol, UK http://www.bristol.ac.uk/
#

my $seen_yyerrlab1=0;
my $line_offset=1; # #line directives always refer to the NEXT line
while(<>) {
  # Remove code that causes a warning
  if(/Suppress GCC warning that yyerrlab1/) {
    do {
      $_=<>;
      $line_offset--; # skipped a line
    } while(!/^\#endif/);
    $line_offset--; # skipped a line
    next;
  }

  $seen_yyerrlab1=1 if /goto yyerrlab1/;

  s/^yyerrlab1:// unless $seen_yyerrlab1;

  # Do not use macro name for a temporary variable
  s/unsigned int yylineno = /unsigned int yylineno_tmp = /;
  s/yyrule - 1, yylineno\)/yyrule - 1, yylineno_tmp\)/;

  # Do not (re)define prototypes that the system did better
  if(m%^void \*malloc\s*\(%) {
    $line_offset--; # skipped a line
    next;
  }
  if(m%^void free\s*\(%) {
    $line_offset--; # skipped a line
    next; 
  }

  # Suppress warnings about empty declarations
  s/(^static int .*_init_globals.*);$/$1/;

  # Fixup pending filename renaming, see above.
  # Fix line numbers.
  my $line=$. +$line_offset;
  s/^(\#line) \d+ (.*)\.tab\.c/$1 $line $2.c/;

  print;
}