Skip to content

Commit

Permalink
update dictionary generation for API macros
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbaug committed Mar 31, 2024
1 parent 84e14cf commit dce36a8
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions scripts/gen_dictionaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,66 @@ def GetFooter():

print('Found ' + str(numberOfEnums) + ' API enumerations.')

# Generate the API macro dictionaries:

numberOfMacros = 0

for types in spec.findall('types'):
for type in types.findall('type'):
name = ""
category = type.get('category')
if category == 'define':
if type.text and type.text.startswith("#define"):
name = type.find('name').text
else:
continue
else:
continue

#print('found macro: ' +name)

# Create a variant of the name that precedes underscores with
# "zero width" spaces. This causes some long names to be
# broken at more intuitive places.
htmlName = name[:3] + name[3:].replace("_", "_<wbr>")
otherName = name[:3] + name[3:].replace("_", "_&#8203;")

# Example with link:
#
# // CL_MAKE_VERSION
#:CL_MAKE_VERSION_label: pass:q[`CL_MAKE_VERSION`]
#:CL_MAKE_VERSION: <<CL_MAKE_VERSION,{CL_MAKE_VERSION_label}>>
#:CL_MAKE_VERSION_anchor: [[CL_MAKE_VERSION]]{CL_MAKE_VERSION}
linkFile.write('// ' + name + '\n')
linkFile.write('ifdef::backend-html5[]\n')
linkFile.write(':' + name + '_label: pass:q[`' + htmlName + '`]\n')
linkFile.write('endif::[]\n')
linkFile.write('ifndef::backend-html5[]\n')
linkFile.write(':' + name + '_label: pass:q[`' + otherName + '`]\n')
linkFile.write('endif::[]\n')
linkFile.write(':' + name + ': <<' + name + ',{' + name + '_label}>>\n')
linkFile.write(':' + name + '_anchor: [[' + name + ']]{' + name + '}\n')
linkFile.write('\n')

# Example without link:
#
# // CL_MAKE_VERSION
#:CL_MAKE_VERSION: pass:q[`CL_MAKE_VERSION`]
#:CL_MAKE_VERSION_anchor: {CL_MAKE_VERSION}
nolinkFile.write('// ' + name + '\n')
nolinkFile.write('ifdef::backend-html5[]\n')
nolinkFile.write(':' + name + ': pass:q[`' + htmlName + '`]\n')
nolinkFile.write('endif::[]\n')
nolinkFile.write('ifndef::backend-html5[]\n')
nolinkFile.write(':' + name + ': pass:q[`' + otherName + '`]\n')
nolinkFile.write('endif::[]\n')
nolinkFile.write(':' + name + '_anchor: {' + name + '}\n')
nolinkFile.write('\n')

numberOfMacros = numberOfMacros + 1

print('Found ' + str(numberOfMacros) + ' API macros.')

# Generate the API types dictionaries:

numberOfTypes = 0
Expand All @@ -177,6 +237,8 @@ def GetFooter():
addLink = True
name = type.get('name')
elif category == 'define':
if type.text and type.text.startswith("#define"):
continue
name = type.find('name').text
else:
continue
Expand Down

0 comments on commit dce36a8

Please sign in to comment.