tools: Update translator tool for Doxygen comment format (see issue #3384)

Comments for translated classes/methods/functions must now take the form:

///
/// ... text ...
///
This commit is contained in:
Marshall Greenblatt 2022-08-31 22:01:37 -04:00
parent 00f34d5e68
commit 7b352159df
2 changed files with 13 additions and 26 deletions

View File

@ -99,12 +99,6 @@ def get_comment(body, name):
line = data['line'].strip() line = data['line'].strip()
pos = data['start'] pos = data['start']
if len(line) == 0: if len(line) == 0:
# check if the next previous line is a comment
prevdata = get_prev_line(body, pos)
prevline = prevdata['line'].strip()
if prevline[0:2] == '//' and prevline[0:3] != '///':
result.append(None)
else:
break break
# single line /*--cef()--*/ # single line /*--cef()--*/
elif line[0:2] == '/*' and line[-2:] == '*/': elif line[0:2] == '/*' and line[-2:] == '*/':
@ -119,9 +113,9 @@ def get_comment(body, name):
continue continue
elif in_block_comment: elif in_block_comment:
continue continue
elif line[0:2] == '//': elif line[0:3] == '///':
# keep the comment line including any leading spaces # keep the comment line including any leading spaces
result.append(line[2:]) result.append(line[3:])
else: else:
break break
@ -132,15 +126,9 @@ def get_comment(body, name):
def validate_comment(file, name, comment): def validate_comment(file, name, comment):
""" Validate the comment array returned by get_comment(). """ """ Validate the comment array returned by get_comment(). """
# Verify that the comment contains beginning and ending '///' as required by # Verify that the comment contains beginning and ending '///' as required by
# CppDoc (the leading '//' from each line will already have been removed by # Doxygen (the leading '///' from each line will already have been removed by
# the get_comment() logic). There may be additional comments proceeding the # the get_comment() logic).
# CppDoc block so we look at the quantity of lines equaling '/' and expect if len(comment) < 3 or len(comment[0]) != 0 or len(comment[-1]) != 0:
# the last line to be '/'.
docct = 0
for line in comment:
if not line is None and len(line) > 0 and line == '/':
docct = docct + 1
if docct != 2 or len(comment) < 3 or comment[len(comment) - 1] != '/':
raise Exception('Missing or incorrect comment in %s for: %s' % \ raise Exception('Missing or incorrect comment in %s for: %s' % \
(file, name)) (file, name))
@ -157,14 +145,13 @@ def format_comment(comment, indent, translate_map=None, maxchars=80):
hasemptyline = False hasemptyline = False
for line in comment: for line in comment:
# if the line starts with a leading space, remove that space # if the line starts with a leading space, remove that space
if not line is None and len(line) > 0 and line[0:1] == ' ': if not line is None and len(line) > 0 and line[0] == ' ':
line = line[1:] line = line[1:]
didremovespace = True didremovespace = True
else: else:
didremovespace = False didremovespace = False
if line is None or len(line) == 0 or line[0:1] == ' ' \ if line is None or len(line) == 0 or line[0] == ' ':
or line[0:1] == '/':
# the previous paragraph, if any, has ended # the previous paragraph, if any, has ended
if len(wrapme) > 0: if len(wrapme) > 0:
if not translate_map is None: if not translate_map is None:
@ -172,14 +159,14 @@ def format_comment(comment, indent, translate_map=None, maxchars=80):
for key in translate_keys: for key in translate_keys:
wrapme = wrapme.replace(key, translate_map[key]) wrapme = wrapme.replace(key, translate_map[key])
# output the previous paragraph # output the previous paragraph
result += wrap_text(wrapme, indent + '// ', maxchars) result += wrap_text(wrapme, indent + '/// ', maxchars)
wrapme = '' wrapme = ''
if not line is None: if not line is None:
if len(line) == 0 or line[0:1] == ' ' or line[0:1] == '/': if len(line) == 0 or line[0] == ' ':
# blank lines or anything that's further indented should be # blank lines or anything that's further indented should be
# output as-is # output as-is
result += indent + '//' result += indent + '///'
if len(line) > 0: if len(line) > 0:
if didremovespace: if didremovespace:
result += ' ' + line result += ' ' + line
@ -200,7 +187,7 @@ def format_comment(comment, indent, translate_map=None, maxchars=80):
for key in translate_map.keys(): for key in translate_map.keys():
wrapme = wrapme.replace(key, translate_map[key]) wrapme = wrapme.replace(key, translate_map[key])
# output the previous paragraph # output the previous paragraph
result += wrap_text(wrapme, indent + '// ', maxchars) result += wrap_text(wrapme, indent + '/// ', maxchars)
if hasemptyline: if hasemptyline:
# an empty line means a break between comments, so the comment is # an empty line means a break between comments, so the comment is

View File

@ -163,7 +163,7 @@ extern "C" {
result += '\n' + format_comment(cls.get_comment(), '', translate_map) result += '\n' + format_comment(cls.get_comment(), '', translate_map)
result += 'typedef struct _'+classname+' {\n'+\ result += 'typedef struct _'+classname+' {\n'+\
' ///\n'+\ ' ///\n'+\
' // Base structure.\n'+\ ' /// Base structure.\n'+\
' ///\n'+\ ' ///\n'+\
' '+cls.get_parent_capi_name()+' base;\n' ' '+cls.get_parent_capi_name()+' base;\n'
funcs = cls.get_virtual_funcs() funcs = cls.get_virtual_funcs()