def rename_top_lf_labels(lfs: Sequence[top_utils.TopLF],
                         label_map: Dict[str, str]) -> None:
  """Rename the labels of the TopLFs in place.

  Args:
    lfs: List of TopLF objects.
    label_map: Mapping from old labels to new labels.
  """
  for lf in lfs:
    if lf.name in label_map and not label_map[lf.name]:
      raise ValueError("Cannot drop the whole LF: " + str(lf))
    stack: List[top_utils.TopLF] = [lf]
    while stack:
      sub_lf = stack.pop()
      # Renaming is done here
      if sub_lf.name in label_map:
        sub_lf.name = label_map[sub_lf.name]
      new_args = []
      for child in reversed(sub_lf.args):
        if isinstance(child, top_utils.TopLF):
          # Dropping is done here
          if child.name in label_map and not label_map[child.name]:
            continue
          stack.append(child)
        new_args.append(child)
      sub_lf.args = new_args[::-1]
Rename the labels of the TopLFs in place.

  Args:
    lfs: List of TopLF objects.
    label_map: Mapping from old labels to new labels.
  
language/casper/augment/casper_formatters.py