mojo/public/tools/mojom/mojom/generate/generator.py
def AddComputedData(module):
  """Adds computed data to the given module. The data is computed once and
  used repeatedly in the generation process."""

  def _AddStructComputedData(exported, struct):
    struct.packed = pack.PackedStruct(struct)
    struct.bytes = pack.GetByteLayout(struct.packed)
    struct.versions = pack.GetVersionInfo(struct.packed)
    struct.exported = exported

  def _AddInterfaceComputedData(interface):
    interface.version = 0
    for method in interface.methods:
      # this field is never scrambled
      method.sequential_ordinal = method.ordinal

      if method.min_version is not None:
        interface.version = max(interface.version, method.min_version)

      method.param_struct = _GetStructFromMethod(method)
      if interface.stable:
        method.param_struct.attributes[mojom.ATTRIBUTE_STABLE] = True
        if method.explicit_ordinal is None:
          raise Exception(
              'Stable interfaces must declare explicit method ordinals. The '
              'method %s on stable interface %s does not declare an explicit '
              'ordinal.' % (method.mojom_name, interface.qualified_name))
      interface.version = max(interface.version,
                              method.param_struct.versions[-1].version)

      if method.response_parameters is not None:
        method.response_param_struct = _GetResponseStructFromMethod(method)
        if interface.stable:
          method.response_param_struct.attributes[mojom.ATTRIBUTE_STABLE] = True
        interface.version = max(
            interface.version,
            method.response_param_struct.versions[-1].version)
      else:
        method.response_param_struct = None

  def _GetStructFromMethod(method):
    """Converts a method's parameters into the fields of a struct."""
    params_class = "%s_%s_Params" % (method.interface.mojom_name,
                                     method.mojom_name)
    struct = mojom.Struct(params_class,
                          module=method.interface.module,
                          attributes={})
    for param in method.parameters:
      struct.AddField(
          param.mojom_name,
          param.kind,
          param.ordinal,
          attributes=param.attributes)
    _AddStructComputedData(False, struct)
    return struct

  def _GetResponseStructFromMethod(method):
    """Converts a method's response_parameters into the fields of a struct."""
    params_class = "%s_%s_ResponseParams" % (method.interface.mojom_name,
                                             method.mojom_name)
    struct = mojom.Struct(params_class,
                          module=method.interface.module,
                          attributes={})
    for param in method.response_parameters:
      struct.AddField(
          param.mojom_name,
          param.kind,
          param.ordinal,
          attributes=param.attributes)
    _AddStructComputedData(False, struct)
    return struct

  for struct in module.structs:
    _AddStructComputedData(True, struct)
  for interface in module.interfaces:
    _AddInterfaceComputedData(interface)
Adds computed data to the given module. The data is computed once and
  used repeatedly in the generation process.
Adds computed data to the given module. The data is computed once and
used repeatedly in the generation process.
Adds computed data to the given module . The data is computed once and used repeatedly in the generation process .
def AddComputedData(module):
  def _AddStructComputedData(exported, struct):
    struct.packed = pack.PackedStruct(struct)
    struct.bytes = pack.GetByteLayout(struct.packed)
    struct.versions = pack.GetVersionInfo(struct.packed)
    struct.exported = exported
  def _AddInterfaceComputedData(interface):
    interface.version = 0
    for method in interface.methods:
      method.sequential_ordinal = method.ordinal
      if method.min_version is not None:
        interface.version = max(interface.version, method.min_version)
      method.param_struct = _GetStructFromMethod(method)
      if interface.stable:
        method.param_struct.attributes[mojom.ATTRIBUTE_STABLE] = True
        if method.explicit_ordinal is None:
          raise Exception(
              'Stable interfaces must declare explicit method ordinals. The '
              'method %s on stable interface %s does not declare an explicit '
              'ordinal.' % (method.mojom_name, interface.qualified_name))
      interface.version = max(interface.version,
                              method.param_struct.versions[-1].version)
      if method.response_parameters is not None:
        method.response_param_struct = _GetResponseStructFromMethod(method)
        if interface.stable:
          method.response_param_struct.attributes[mojom.ATTRIBUTE_STABLE] = True
        interface.version = max(
            interface.version,
            method.response_param_struct.versions[-1].version)
      else:
        method.response_param_struct = None
  def _GetStructFromMethod(method):
    params_class = "%s_%s_Params" % (method.interface.mojom_name,
                                     method.mojom_name)
    struct = mojom.Struct(params_class,
                          module=method.interface.module,
                          attributes={})
    for param in method.parameters:
      struct.AddField(
          param.mojom_name,
          param.kind,
          param.ordinal,
          attributes=param.attributes)
    _AddStructComputedData(False, struct)
    return struct
  def _GetResponseStructFromMethod(method):
    params_class = "%s_%s_ResponseParams" % (method.interface.mojom_name,
                                             method.mojom_name)
    struct = mojom.Struct(params_class,
                          module=method.interface.module,
                          attributes={})
    for param in method.response_parameters:
      struct.AddField(
          param.mojom_name,
          param.kind,
          param.ordinal,
          attributes=param.attributes)
    _AddStructComputedData(False, struct)
    return struct
  for struct in module.structs:
    _AddStructComputedData(True, struct)
  for interface in module.interfaces:
    _AddInterfaceComputedData(interface)
def AddComputedData ( module ) : def _AddStructComputedData ( exported , struct ) : struct . packed = pack . PackedStruct ( struct ) struct . bytes = pack . GetByteLayout ( struct . packed ) struct . versions = pack . GetVersionInfo ( struct . packed ) struct . exported = exported def _AddInterfaceComputedData ( interface ) : interface . version = 0 for method in interface . methods : method . sequential_ordinal = method . ordinal if method . min_version is not None : interface . version = max ( interface . version , method . min_version ) method . param_struct = _GetStructFromMethod ( method ) if interface . stable : method . param_struct . attributes [ mojom . ATTRIBUTE_STABLE ] = True if method . explicit_ordinal is None : raise Exception ( 'Stable interfaces must declare explicit method ordinals. The ' 'method %s on stable interface %s does not declare an explicit ' 'ordinal.' % ( method . mojom_name , interface . qualified_name ) ) interface . version = max ( interface . version , method . param_struct . versions [ - 1 ] . version ) if method . response_parameters is not None : method . response_param_struct = _GetResponseStructFromMethod ( method ) if interface . stable : method . response_param_struct . attributes [ mojom . ATTRIBUTE_STABLE ] = True interface . version = max ( interface . version , method . response_param_struct . versions [ - 1 ] . version ) else : method . response_param_struct = None def _GetStructFromMethod ( method ) : """Converts a method's parameters into the fields of a struct.""" params_class = "%s_%s_Params" % ( method . interface . mojom_name , method . mojom_name ) struct = mojom . Struct ( params_class , module = method . interface . module , attributes = { } ) for param in method . parameters : struct . AddField ( param . mojom_name , param . kind , param . ordinal , attributes = param . attributes ) _AddStructComputedData ( False , struct ) return struct def _GetResponseStructFromMethod ( method ) : """Converts a method's response_parameters into the fields of a struct.""" params_class = "%s_%s_ResponseParams" % ( method . interface . mojom_name , method . mojom_name ) struct = mojom . Struct ( params_class , module = method . interface . module , attributes = { } ) for param in method . response_parameters : struct . AddField ( param . mojom_name , param . kind , param . ordinal , attributes = param . attributes ) _AddStructComputedData ( False , struct ) return struct for struct in module . structs : _AddStructComputedData ( True , struct ) for interface in module . interfaces : _AddInterfaceComputedData ( interface )
Adds computed data to the given module.
Adds computed data to the given module .
"""Adds computed data to the given module. The data is computed once and
  used repeatedly in the generation process.""" # this field is never scrambled """Converts a method's parameters into the fields of a struct.""" """Converts a method's response_parameters into the fields of a struct."""
module