code: def visit_tree(node, previsit, postvisit):
      # type: (Module, Callable[[AstNode, Optional[Token]], Tuple[Optional[Token], Optional[Token]]], Optional[Callable[[AstNode, Optional[Token], Optional[Token]], None]])   -> None
      """
      Scans the tree under the node depth-first using an explicit stack. It avoids implicit recursion
      via the function call stack to avoid hitting 'maximum recursion depth exceeded' error.
  
      It calls ``previsit()`` and ``postvisit()`` as follows:
  
      * ``previsit(node, par_value)`` - should return ``(par_value, value)``
            ``par_value`` is as returned from ``previsit()`` of the parent.
  
      * ``postvisit(node, par_value, value)`` - should return ``value``
            ``par_value`` is as returned from ``previsit()`` of the parent, and ``value`` is as
            returned from ``previsit()`` of this node itself. The return ``value`` is ignored except
            the one for the root node, which is returned from the overall ``visit_tree()`` call.
  
      For the initial node, ``par_value`` is None. ``postvisit`` may be None.
      """
      if not postvisit:
          postvisit = lambda node, pvalue, value: None
  
      iter_children = iter_children_func(node)
      done = set()
      ret = None
      stack = [
          (node, None, _PREVISIT)
      ]  # type: List[Tuple[AstNode, Optional[Token], Union[Optional[Token], object]]]
      while stack:
          current, par_value, value = stack.pop()
          if value is _PREVISIT:
              assert (
                  current not in done
              )  # protect againt infinite loop in case of a bad tree.
              done.add(current)
  
              pvalue, post_value = previsit(current, par_value)
              stack.append((current, par_value, post_value))
  
              # Insert all children in reverse order (so that first child ends up on top of the stack).
              ins = len(stack)
              for n in iter_children(current):
                  stack.insert(ins, (n, pvalue, _PREVISIT))
          else:
              ret = postvisit(
                  current, par_value, cast(Optional[Token], value)
              )
      return ret
  
imports: import ast
  import collections
  import io
  import sys
  import token
  import tokenize
  from abc import ABCMeta
  from ast import Module, expr, AST
  from typing import Callable, Dict, Iterable, Iterator, List, Optional, Tuple, Union, cast, Any, TYPE_CHECKING
  from six import iteritems
label_desc: Use image node_id 15 for calling a global function with example usage: visit_tree(node, previsit, postvisit) and returns: ret