Bug 1230747 - Fix element id generation rule for bytecode documentation. r=jwalden

This commit is contained in:
Tooru Fujisawa 2015-12-05 22:57:17 +09:00
parent 1a9d524f0b
commit 7886cc6275

View File

@ -333,8 +333,27 @@ def print_opcode(opcode):
stack_defs=escape(opcode.stack_defs) or " ", stack_defs=escape(opcode.stack_defs) or " ",
desc=opcode.desc)) # desc is already escaped desc=opcode.desc)) # desc is already escaped
def make_element_id(name): id_cache = dict()
return name.replace(' ', '-') id_count = dict()
def make_element_id(category, type=''):
key = '{}:{}'.format(category, type)
if key in id_cache:
return id_cache[key]
if type == '':
id = category.replace(' ', '_')
else:
id = type.replace(' ', '_')
if id in id_count:
id_count[id] += 1
id = '{}_{}'.format(id, id_count[id])
else:
id_count[id] = 1
id_cache[key] = id
return id
def print_doc(version, index): def print_doc(version, index):
print("""<div>{{{{SpiderMonkeySidebar("Internals")}}}}</div> print("""<div>{{{{SpiderMonkeySidebar("Internals")}}}}</div>
@ -358,7 +377,7 @@ def print_doc(version, index):
for (type_name, opcodes) in types: for (type_name, opcodes) in types:
if type_name: if type_name:
print('<h4 id="{id}">{name}</h4>'.format(name=type_name, print('<h4 id="{id}">{name}</h4>'.format(name=type_name,
id=make_element_id(type_name))) id=make_element_id(category_name, type_name)))
print('<dl>') print('<dl>')
for opcode in sorted(opcodes, for opcode in sorted(opcodes,
key=lambda opcode: opcode.sort_key): key=lambda opcode: opcode.sort_key):