1#!/usr/bin/env python3
2#
3# Find missing and extra parameters in documentation compared to
4# output of: gcc --help=params.
5#
6# This file is part of GCC.
7#
8# GCC is free software; you can redistribute it and/or modify it under
9# the terms of the GNU General Public License as published by the Free
10# Software Foundation; either version 3, or (at your option) any later
11# version.
12#
13# GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14# WARRANTY; without even the implied warranty of MERCHANTABILITY or
15# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16# for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with GCC; see the file COPYING3.  If not see
20# <http://www.gnu.org/licenses/>.  */
21#
22#
23#
24
25import sys
26import json
27import argparse
28
29from itertools import *
30
31def get_param_tuple(line):
32    line = line.strip()
33    i = line.find(' ')
34    return (line[:i], line[i:].strip())
35
36parser = argparse.ArgumentParser()
37parser.add_argument('texi_file')
38parser.add_argument('params_output')
39
40args = parser.parse_args()
41
42ignored = set(['logical-op-non-short-circuit'])
43params = {}
44
45for line in open(args.params_output).readlines():
46    if line.startswith('  '):
47        r = get_param_tuple(line)
48        params[r[0]] = r[1]
49
50# Find section in .texi manual with parameters
51texi = ([x.strip() for x in open(args.texi_file).readlines()])
52texi = dropwhile(lambda x: not 'item --param' in x, texi)
53texi = takewhile(lambda x: not '@node Instrumentation Options' in x, texi)
54texi = list(texi)[1:]
55
56token = '@item '
57texi = [x[len(token):] for x in texi if x.startswith(token)]
58sorted_texi = sorted(texi)
59
60texi_set = set(texi) - ignored
61params_set = set(params.keys()) - ignored
62
63extra = texi_set - params_set
64if len(extra):
65    print('Extra:')
66    print(extra)
67
68missing = params_set - texi_set
69if len(missing):
70    print('Missing:')
71    for m in missing:
72        print('@item ' + m)
73        print(params[m])
74        print()
75
76if texi != sorted_texi:
77    print('WARNING: not sorted alphabetically!')
78