message: AddUniqueLabelsToAllProcesses based on name_scope and stm_outputs
diff: @@ -4,44 +4,28 @@ from hdlConvertor.hdlAst._structural import HdlModuleDef, HdlModuleDec
  class AddUniqueLabelsToAllProcesses():
  - def __init__(self):
  - self.reset_name_context()
  -
  - def reset_name_context(self):
  - self.used_names = set()
  - self.name_prefix_cntr = {}
  -
  - def checked_name(self, n):
  - un = self.used_names
  - npc = self.name_prefix_cntr
  - _n = n
  - while _n in un:
  - # try find an available name by incrementing counter behind the
  - # name
  - i = npc.get(n, 0)
  - _n = "%s_%d" % (n, i)
  - npc[n] = i + 1
  - assert len(_n) > 0
  - un.add(n)
  - return _n
  + def __init__(self, name_scope, stm_outputs):
  + """
  + :type name_scope: NameScope
  + :type stm_outputs: Dict[iHdlStatement, ]
  + """
  + self.name_scope = name_scope
  + self.stm_outputs = stm_outputs
  def module_def(self, m):
  """
  :type m: HdlModuleDef
  """
  - self.used_names = set()
  - proc_with_missing_name = []
  for o in m.objs:
  if isinstance(o, HdlStmProcess):
  - if o.labels:
  - label = o.labels[0]
  - o.labels[0] = self.checked_name(label)
  + if not o.labels:
  + outputs = self.stm_outputs[o]
  + if outputs:
  + suggested_name = "assig_process_" + outputs[0]
  else:
  - proc_with_missing_name.append(o)
  - # named processes are checked first in order to preserver their names
  - # and avoid potential collision with generated names
  - for o in proc_with_missing_name:
  - o.labels.append(self.checked_name("proc"))
  + suggested_name = "proc"
  +
  + o.labels.append(self.name_scope.checkedName(suggested_name, o))
  def context(self, context):
  """
  @@ -49,4 +33,8 @@ class AddUniqueLabelsToAllProcesses():
  """
  for o in context.objs:
  if isinstance(o, HdlModuleDec):
  + try:
  + self.name_scope = self.name_scope.get_child(o.name)
  self.module_def(o.body)
  + finally:
  + self.name_scope = self.name_scope.level_pop()
  \ No newline at end of file
  