Example #1
0
def _Method(module, parsed_method, interface):
    """
  Args:
    module: {mojom.Module} Module currently being constructed.
    parsed_method: {ast.Method} Parsed method.
    interface: {mojom.Interface} Interface this method belongs to.

  Returns:
    {mojom.Method} AST method.
  """
    method = mojom.Method(
        interface,
        parsed_method.mojom_name,
        ordinal=parsed_method.ordinal.value if parsed_method.ordinal else None)
    method.parameters = map(
        lambda parameter: _Parameter(module, parameter, interface),
        parsed_method.parameter_list)
    if parsed_method.response_parameter_list is not None:
        method.response_parameters = map(
            lambda parameter: _Parameter(module, parameter, interface),
            parsed_method.response_parameter_list)
    method.attributes = _AttributeListToDict(parsed_method.attribute_list)

    # Enforce that only methods with response can have a [Sync] attribute.
    if method.sync and method.response_parameters is None:
        raise Exception("Only methods with response can include a [Sync] "
                        "attribute. If no response parameters are needed, you "
                        "could use an empty response parameter list, i.e., "
                        "\"=> ()\".")

    return method
Example #2
0
def MethodFromData(module, data, interface):
  method = mojom.Method(interface, data['name'], ordinal=data.get('ordinal'))
  method.default = data.get('default')
  method.parameters = map(lambda parameter:
      ParameterFromData(module, parameter, interface), data['parameters'])
  if data.has_key('response_parameters'):
    method.response_parameters = map(
        lambda parameter: ParameterFromData(module, parameter, interface),
                          data['response_parameters'])
  return method
Example #3
0
def MethodFromData(module, data, interface):
  method = mojom.Method(interface, data['name'], ordinal=data.get('ordinal'))
  method.parameters = map(lambda parameter:
      ParameterFromData(module, parameter, interface), data['parameters'])
  if data.has_key('response_parameters'):
    method.response_parameters = map(
        lambda parameter: ParameterFromData(module, parameter, interface),
                          data['response_parameters'])
  method.attributes = data.get('attributes')

  # Enforce that only methods with response can have a [Sync] attribute.
  if method.sync and method.response_parameters is None:
    raise Exception("Only methods with response can include a [Sync] "
                    "attribute. If no response parameters are needed, you "
                    "could use an empty response parameter list, i.e., "
                    "\"=> ()\".")

  return method
Example #4
0
  def MethodFromMojom(self, mojom_method, interface):
    """Translates a mojom_types_mojom.MojomMethod to a module.Method.

    Args:
      mojom_method: {mojom_types_mojom.MojomMethod} to be translated.
      interface: {module.Interface} the method is a member of.

    Returns:
      {module.Method} translated from mojom_method.
    """
    method = module.Method(interface, mojom_method.decl_data.short_name)
    method.ordinal = mojom_method.ordinal
    method.parameters = [self.ParamFromMojom(param)
        for param in mojom_method.parameters.fields]
    if mojom_method.response_params is not None:
      method.response_parameters = [self.ParamFromMojom(param)
          for param in mojom_method.response_params.fields]
    return method
Example #5
0
    def MethodFromMojom(self, mojom_method, interface):
        """Translates a mojom_types_mojom.MojomMethod to a module.Method.

    Args:
      mojom_method: {mojom_types_mojom.MojomMethod} to be translated.
      interface: {module.Interface} the method is a member of.

    Returns:
      {module.Method} translated from mojom_method.
    """
        method = module.Method(interface, mojom_method.decl_data.short_name)
        method.ordinal = mojom_method.ordinal
        method.declaration_order = mojom_method.decl_data.declaration_order
        method.param_struct = module.Struct()
        self.StructFromMojomStruct(method.param_struct,
                                   mojom_method.parameters)
        # The name of a synthetic request parameter struct is not guaranteed by
        # the frontend to be anything in particular so we set the name of the
        # translated struct to a value that the code generators are expecting.
        method.param_struct.name = "%s_%s_Params" % (method.interface.name,
                                                     method.name)
        method.parameters = [
            self.ParamFromMojom(param)
            for param in mojom_method.parameters.fields
        ]
        if mojom_method.response_params is not None:
            method.response_param_struct = module.Struct()
            self.StructFromMojomStruct(method.response_param_struct,
                                       mojom_method.response_params)
            # The name of a synthetic response parameter struct is not guaranteed by
            # the frontend to be anything in particular so we set the name of the
            # translated struct to a value that the code generators are expecting.
            method.response_param_struct.name = "%s_%s_ResponseParams" % (
                method.interface.name, method.name)
            method.response_parameters = [
                self.ParamFromMojom(param)
                for param in mojom_method.response_params.fields
            ]

        method.min_version = mojom_method.min_version

        return method