namer: add HUID suffix step

This commit is contained in:
Sebastien Bourdeauducq 2013-08-08 00:15:18 +02:00
parent fd34b75fb4
commit 146a1b5d51
1 changed files with 17 additions and 2 deletions

View File

@ -99,11 +99,15 @@ def _name_signal(tree, signal):
def _build_pnd(tree, signals): def _build_pnd(tree, signals):
return dict((signal, _name_signal(tree, signal)) for signal in signals) return dict((signal, _name_signal(tree, signal)) for signal in signals)
def _list_conflicting_signals(pnd): def _invert_pnd(pnd):
inv_pnd = dict() inv_pnd = dict()
for k, v in pnd.items(): for k, v in pnd.items():
inv_pnd[v] = inv_pnd.get(v, []) inv_pnd[v] = inv_pnd.get(v, [])
inv_pnd[v].append(k) inv_pnd[v].append(k)
return inv_pnd
def _list_conflicting_signals(pnd):
inv_pnd = _invert_pnd(pnd)
r = set() r = set()
for k, v in inv_pnd.items(): for k, v in inv_pnd.items():
if len(v) > 1: if len(v) > 1:
@ -117,7 +121,7 @@ def _set_use_number(tree, signals):
current = current.children[step_name] current = current.children[step_name]
current.use_number = current.signal_count > len(current.numbers) and len(current.numbers) > 1 current.use_number = current.signal_count > len(current.numbers) and len(current.numbers) > 1
_debug = True _debug = False
def build_namespace(signals): def build_namespace(signals):
basic_tree = _build_tree(signals) basic_tree = _build_tree(signals)
@ -143,6 +147,17 @@ def build_namespace(signals):
if _debug: if _debug:
print("namer: using basic strategy") print("namer: using basic strategy")
# ...then add number suffixes by HUID
inv_pnd = _invert_pnd(pnd)
huid_suffixed = False
for name, signals in inv_pnd.items():
if len(signals) > 1:
huid_suffixed = True
for n, signal in enumerate(sorted(signals, key=lambda x: x.huid)):
pnd[signal] += str(n)
if _debug and huid_suffixed:
print("namer: using HUID suffixes")
ns = Namespace(pnd) ns = Namespace(pnd)
# register signals with name_override # register signals with name_override
for signal in signals: for signal in signals: