mojo/public/tools/mojom/mojom/generate/translate.py
def _CollectReferencedKinds(module, all_defined_kinds):
  """
  Takes a {mojom.Module} object and a list of all defined kinds within that
  module, and enumerates the complete dict of user-defined mojom types
  (as {mojom.Kind} objects) referenced by the module's own defined kinds (i.e.
  as types of struct or union or interface parameters. The returned dict is
  keyed by kind spec.
  """

  def extract_referenced_user_kinds(kind):
    if mojom.IsArrayKind(kind):
      return extract_referenced_user_kinds(kind.kind)
    if mojom.IsMapKind(kind):
      return (extract_referenced_user_kinds(kind.key_kind) +
              extract_referenced_user_kinds(kind.value_kind))
    if (mojom.IsInterfaceRequestKind(kind) or mojom.IsAssociatedKind(kind)
        or mojom.IsPendingRemoteKind(kind)
        or mojom.IsPendingReceiverKind(kind)):
      return [kind.kind]
    if mojom.IsStructKind(kind):
      return [kind]
    if (mojom.IsInterfaceKind(kind) or mojom.IsEnumKind(kind)
        or mojom.IsUnionKind(kind)):
      return [kind]
    return []

  def sanitize_kind(kind):
    """Removes nullability from a kind"""
    if kind.spec.startswith('?'):
      return _Kind(module.kinds, kind.spec[1:], (module.mojom_namespace, ''))
    return kind

  referenced_user_kinds = {}
  for defined_kind in all_defined_kinds:
    if mojom.IsStructKind(defined_kind) or mojom.IsUnionKind(defined_kind):
      for field in defined_kind.fields:
        for referenced_kind in extract_referenced_user_kinds(field.kind):
          sanitized_kind = sanitize_kind(referenced_kind)
          referenced_user_kinds[sanitized_kind.spec] = sanitized_kind

  # Also scan for references in parameter lists
  for interface in module.interfaces:
    for method in interface.methods:
      for param in itertools.chain(method.parameters or [],
                                   method.response_parameters or []):
        for referenced_kind in extract_referenced_user_kinds(param.kind):
          sanitized_kind = sanitize_kind(referenced_kind)
          referenced_user_kinds[sanitized_kind.spec] = sanitized_kind
  # Consts can reference imported enums.
  for const in module.constants:
    if not const.kind in mojom.PRIMITIVES:
      sanitized_kind = sanitize_kind(const.kind)
      referenced_user_kinds[sanitized_kind.spec] = sanitized_kind

  return referenced_user_kinds

  Takes a {mojom.Module} object and a list of all defined kinds within that
  module, and enumerates the complete dict of user-defined mojom types
  (as {mojom.Kind} objects) referenced by the module's own defined kinds (i.e.
  as types of struct or union or interface parameters. The returned dict is
  keyed by kind spec.
  
Takes a {mojom.Module} object and a list of all defined kinds within that
module, and enumerates the complete dict of user-defined mojom types
(as {mojom.Kind} objects) referenced by the module's own defined kinds (i.e.
as types of struct or union or interface parameters. The returned dict is
keyed by kind spec.
Takes a { mojom . Module } object and a list of all defined kinds within that module and enumerates the complete dict of user - defined mojom types ( as { mojom . Kind } objects ) referenced by the module ' s own defined kinds ( i . e . as types of struct or union or interface parameters . The returned dict is keyed by kind spec .
def _CollectReferencedKinds(module, all_defined_kinds):
  def extract_referenced_user_kinds(kind):
    if mojom.IsArrayKind(kind):
      return extract_referenced_user_kinds(kind.kind)
    if mojom.IsMapKind(kind):
      return (extract_referenced_user_kinds(kind.key_kind) +
              extract_referenced_user_kinds(kind.value_kind))
    if (mojom.IsInterfaceRequestKind(kind) or mojom.IsAssociatedKind(kind)
        or mojom.IsPendingRemoteKind(kind)
        or mojom.IsPendingReceiverKind(kind)):
      return [kind.kind]
    if mojom.IsStructKind(kind):
      return [kind]
    if (mojom.IsInterfaceKind(kind) or mojom.IsEnumKind(kind)
        or mojom.IsUnionKind(kind)):
      return [kind]
    return []
  def sanitize_kind(kind):
    if kind.spec.startswith('?'):
      return _Kind(module.kinds, kind.spec[1:], (module.mojom_namespace, ''))
    return kind
  referenced_user_kinds = {}
  for defined_kind in all_defined_kinds:
    if mojom.IsStructKind(defined_kind) or mojom.IsUnionKind(defined_kind):
      for field in defined_kind.fields:
        for referenced_kind in extract_referenced_user_kinds(field.kind):
          sanitized_kind = sanitize_kind(referenced_kind)
          referenced_user_kinds[sanitized_kind.spec] = sanitized_kind
  for interface in module.interfaces:
    for method in interface.methods:
      for param in itertools.chain(method.parameters or [],
                                   method.response_parameters or []):
        for referenced_kind in extract_referenced_user_kinds(param.kind):
          sanitized_kind = sanitize_kind(referenced_kind)
          referenced_user_kinds[sanitized_kind.spec] = sanitized_kind
  for const in module.constants:
    if not const.kind in mojom.PRIMITIVES:
      sanitized_kind = sanitize_kind(const.kind)
      referenced_user_kinds[sanitized_kind.spec] = sanitized_kind
  return referenced_user_kinds
def _CollectReferencedKinds ( module , all_defined_kinds ) : def extract_referenced_user_kinds ( kind ) : if mojom . IsArrayKind ( kind ) : return extract_referenced_user_kinds ( kind . kind ) if mojom . IsMapKind ( kind ) : return ( extract_referenced_user_kinds ( kind . key_kind ) + extract_referenced_user_kinds ( kind . value_kind ) ) if ( mojom . IsInterfaceRequestKind ( kind ) or mojom . IsAssociatedKind ( kind ) or mojom . IsPendingRemoteKind ( kind ) or mojom . IsPendingReceiverKind ( kind ) ) : return [ kind . kind ] if mojom . IsStructKind ( kind ) : return [ kind ] if ( mojom . IsInterfaceKind ( kind ) or mojom . IsEnumKind ( kind ) or mojom . IsUnionKind ( kind ) ) : return [ kind ] return [ ] def sanitize_kind ( kind ) : """Removes nullability from a kind""" if kind . spec . startswith ( '?' ) : return _Kind ( module . kinds , kind . spec [ 1 : ] , ( module . mojom_namespace , '' ) ) return kind referenced_user_kinds = { } for defined_kind in all_defined_kinds : if mojom . IsStructKind ( defined_kind ) or mojom . IsUnionKind ( defined_kind ) : for field in defined_kind . fields : for referenced_kind in extract_referenced_user_kinds ( field . kind ) : sanitized_kind = sanitize_kind ( referenced_kind ) referenced_user_kinds [ sanitized_kind . spec ] = sanitized_kind for interface in module . interfaces : for method in interface . methods : for param in itertools . chain ( method . parameters or [ ] , method . response_parameters or [ ] ) : for referenced_kind in extract_referenced_user_kinds ( param . kind ) : sanitized_kind = sanitize_kind ( referenced_kind ) referenced_user_kinds [ sanitized_kind . spec ] = sanitized_kind for const in module . constants : if not const . kind in mojom . PRIMITIVES : sanitized_kind = sanitize_kind ( const . kind ) referenced_user_kinds [ sanitized_kind . spec ] = sanitized_kind return referenced_user_kinds
Takes a {mojom.Module} object and a list of all defined kinds within that
module, and enumerates the complete dict of user-defined mojom types
(as {mojom.Kind} objects) referenced by the module's own defined kinds (i.e.
Takes a { mojom . Module } object and a list of all defined kinds within that module and enumerates the complete dict of user - defined mojom types ( as { mojom . Kind } objects ) referenced by the module ' s own defined kinds ( i . e .
"""
  Takes a {mojom.Module} object and a list of all defined kinds within that
  module, and enumerates the complete dict of user-defined mojom types
  (as {mojom.Kind} objects) referenced by the module's own defined kinds (i.e.
  as types of struct or union or interface parameters. The returned dict is
  keyed by kind spec.
  """ """Removes nullability from a kind""" # Also scan for references in parameter lists # Consts can reference imported enums.
module
all_defined_kinds