]> git.ipfire.org Git - thirdparty/gcc.git/blame - contrib/check-params-in-docs.py
[Ada] Use new API when creating a special SPARK heap entity
[thirdparty/gcc.git] / contrib / check-params-in-docs.py
CommitLineData
4cac9d00
ML
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
4cac9d00 25import argparse
467adc05 26from itertools import dropwhile, takewhile
4cac9d00 27
4cac9d00
ML
28
29def get_param_tuple(line):
467adc05 30 line = line.strip().replace('--param=', '')
4cac9d00 31 i = line.find(' ')
467adc05
ML
32 name = line[:i]
33 if '=' in name:
34 name = name[:name.find('=')]
35 description = line[i:].strip()
36 return (name, description)
37
4cac9d00
ML
38
39parser = argparse.ArgumentParser()
40parser.add_argument('texi_file')
41parser.add_argument('params_output')
42
43args = parser.parse_args()
44
08bc73f0 45ignored = set(['logical-op-non-short-circuit'])
4cac9d00
ML
46params = {}
47
48for line in open(args.params_output).readlines():
49 if line.startswith(' '):
50 r = get_param_tuple(line)
51 params[r[0]] = r[1]
52
53# Find section in .texi manual with parameters
54texi = ([x.strip() for x in open(args.texi_file).readlines()])
467adc05
ML
55texi = dropwhile(lambda x: 'item --param' not in x, texi)
56texi = takewhile(lambda x: '@node Instrumentation Options' not in x, texi)
4cac9d00
ML
57texi = list(texi)[1:]
58
59token = '@item '
60texi = [x[len(token):] for x in texi if x.startswith(token)]
61sorted_texi = sorted(texi)
62
08bc73f0
ML
63texi_set = set(texi) - ignored
64params_set = set(params.keys()) - ignored
4cac9d00
ML
65
66extra = texi_set - params_set
67if len(extra):
68 print('Extra:')
69 print(extra)
70
71missing = params_set - texi_set
72if len(missing):
73 print('Missing:')
74 for m in missing:
75 print('@item ' + m)
76 print(params[m])
77 print()
78
79if texi != sorted_texi:
80 print('WARNING: not sorted alphabetically!')