]> sigrok.org Git - libsigrok.git/blame - bindings/swig/doc.py
C++: Add parameter documentation and additional method descriptions.
[libsigrok.git] / bindings / swig / doc.py
CommitLineData
bd4fda24
ML
1##
2## This file is part of the libsigrok project.
3##
4## Copyright (C) 2014 Martin Ling <martin-sigrok@earth.li>
5##
6## This program is free software: you can redistribute it and/or modify
7## it under the terms of the GNU General Public License as published by
8## the Free Software Foundation, either version 3 of the License, or
9## (at your option) any later version.
10##
11## This program is distributed in the hope that it will be useful,
12## but WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14## GNU General Public License for more details.
15##
16## You should have received a copy of the GNU General Public License
17## along with this program. If not, see <http://www.gnu.org/licenses/>.
18##
19
20from xml.etree import ElementTree
21import sys, os
22
23language, input_file = sys.argv[1:]
24input_dir = os.path.dirname(input_file)
25
26index = ElementTree.parse(input_file)
27
28def get_text(node):
29 paras = node.findall('para')
30 return str.join('\n\n', [p.text.rstrip() for p in paras if p.text])
31
32for compound in index.findall('compound'):
33 if compound.attrib['kind'] != 'class':
34 continue
35 class_name = compound.find('name').text
36 if not class_name.startswith('sigrok::'):
37 continue
38 doc = ElementTree.parse("%s/%s.xml" % (input_dir, compound.attrib['refid']))
39 cls = doc.find('compounddef')
40 brief = get_text(cls.find('briefdescription'))
41 if brief:
42 if language == 'python':
43 print '%%feature("docstring") %s "%s";' % (class_name, brief)
44 elif language == 'java':
45 print '%%typemap(javaclassmodifiers) %s "/** %s */\npublic class"' % (
46 class_name, brief)
47 for section in cls.findall('sectiondef'):
48 if section.attrib['kind'] != 'public-func':
49 continue
50 for function in section.findall('memberdef'):
51 function_name = function.find('name').text
52 brief = get_text(function.find('briefdescription'))
53 if brief:
54 if language == 'python':
55 print '%%feature("docstring") %s::%s "%s";' % (
56 class_name, function_name, brief)
57 elif language == 'java':
58 print '%%javamethodmodifiers %s::%s "/** %s */\npublic"' % (
59 class_name, function_name, brief)