X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fswig%2Fdoc.py;h=e8767af8b987b898944b047de2fed82f29bd869f;hb=c5d081f721a0d99e726596d4f8afe72cf803a576;hp=16d9db3e9c760a644dc7ec31e4aa108d730aaff8;hpb=8fb7efe20311903dd8101962107d21a02a9884ce;p=libsigrok.git diff --git a/bindings/swig/doc.py b/bindings/swig/doc.py index 16d9db3e..e8767af8 100644 --- a/bindings/swig/doc.py +++ b/bindings/swig/doc.py @@ -21,14 +21,16 @@ from __future__ import print_function from xml.etree import ElementTree import sys, os -language, input_file = sys.argv[1:] +language, input_file = sys.argv[1:3] +if len(sys.argv) == 4: + mode = sys.argv[3] input_dir = os.path.dirname(input_file) index = ElementTree.parse(input_file) def get_text(node): paras = node.findall('para') - return str.join('\n\n', [p.text.rstrip() for p in paras if p.text]) + return str.join('\n\n', [("".join(l)).rstrip() for l in [list(p.itertext()) for p in paras] if l]) for compound in index.findall('compound'): if compound.attrib['kind'] != 'class': @@ -36,12 +38,15 @@ for compound in index.findall('compound'): class_name = compound.find('name').text if not class_name.startswith('sigrok::'): continue + trimmed_name = class_name.split('::')[1] doc = ElementTree.parse("%s/%s.xml" % (input_dir, compound.attrib['refid'])) cls = doc.find('compounddef') brief = get_text(cls.find('briefdescription')) if brief: if language == 'python': print('%%feature("docstring") %s "%s";' % (class_name, brief)) + elif language == 'ruby': + print('%%feature("docstring") %s "/* Document-class: %s\\n%s */\\n";' % (class_name, class_name.replace("sigrok", "Sigrok", 1), brief)) elif language == 'java': print('%%typemap(javaclassmodifiers) %s "/** %s */\npublic class"' % ( class_name, brief)) @@ -64,27 +69,46 @@ for compound in index.findall('compound'): if description: parameters[name] = description if brief: - if language == 'python': + if language == 'python' and kind == 'public-func': print(str.join('\n', [ '%%feature("docstring") %s::%s "%s' % ( class_name, member_name, brief)] + [ '@param %s %s' % (name, desc) for name, desc in parameters.items()]) + '";') - elif language == 'java': - if kind == 'public-func': + if language == 'ruby' and kind == 'public-func': + print(str.join('\n', [ + '%%feature("docstring") %s::%s "/* %s' % ( + class_name, member_name, brief)] + [ + '@param %s %s' % (name, desc) + for name, desc in parameters.items()]) + ' */\\n";') + elif language == 'java' and kind == 'public-func': print(str.join('\n', [ '%%javamethodmodifiers %s::%s "/** %s' % ( class_name, member_name, brief)] + [ ' * @param %s %s' % (name, desc) for name, desc in parameters.items()]) + ' */\npublic"') - elif kind == 'public-static-attrib': - constants.append((member_name, brief)) + elif kind == 'public-static-attrib': + constants.append((member_name, brief)) if language == 'java' and constants: print('%%typemap(javacode) %s %%{' % class_name) for member_name, brief in constants: - trimmed_name = class_name.split('::')[1] print(' /** %s */\n public static final %s %s = new %s(classesJNI.%s_%s_get(), false);\n' % ( brief, trimmed_name, member_name, trimmed_name, trimmed_name, member_name)) print('%}') + elif language == 'python' and constants: + if mode == 'start': + print('%%extend %s {\n%%pythoncode %%{' % class_name) + for member_name, brief in constants: + print(' ## @brief %s\n %s = None' % (brief, member_name)) + print('%}\n}') + elif mode == 'end': + print('%pythoncode %{') + for member_name, brief in constants: + print('%s.%s.__doc__ = """%s"""' % ( + trimmed_name, member_name, brief)) + print('%}') + elif language == 'ruby' and constants: + for member_name, brief in constants: + print('%%feature("docstring") %s::%s "/* %s */\\n";' % (class_name, member_name, brief))