Пример #1
0
    def AddSecondaryMembers(self, interface):
        # With multiple inheritance, attributes and operations of non-first
        # interfaces need to be added.  Sometimes the attribute or operation is
        # defined in the current interface as well as a parent.  In that case we
        # avoid making a duplicate definition and pray that the signatures match.
        secondary_parents = self._TransitiveSecondaryParents(interface)
        for parent_interface in sorted(secondary_parents):
            if isinstance(parent_interface, str):
                continue
            for attr in sorted(parent_interface.attributes,
                               ConstantOutputOrder):
                if not FindMatchingAttribute(interface, attr):
                    self.SecondaryContext(parent_interface)
                    self.AddAttribute(attr)

            # Group overloaded operations by name.
            operationsByName = self._OperationsByName(parent_interface)

            # Generate operations.
            for id in sorted(operationsByName.keys()):
                if not any(op.id == id for op in interface.operations):
                    operations = operationsByName[id]
                    info = AnalyzeOperation(interface, operations)
                    self.SecondaryContext(parent_interface)
                    self.AddOperation(info)
Пример #2
0
    def AddMembers(self, interface, declare_only=False):
        for const in sorted(interface.constants, ConstantOutputOrder):
            self.AddConstant(const)

        for attr in sorted(interface.attributes, ConstantOutputOrder):
            if attr.type.id != 'EventListener':
                self.AddAttribute(attr, declare_only)

        # The implementation should define an indexer if the interface directly
        # extends List.
        element_type = None
        requires_indexer = False
        if self._interface_type_info.list_item_type():
            self.AddIndexer(self._interface_type_info.list_item_type())
        else:
            for parent in self._database.Hierarchy(self._interface):
                if parent == self._interface:
                    continue
                parent_type_info = self._type_registry.TypeInfo(parent.id)
                if parent_type_info.list_item_type():
                    self.AmendIndexer(parent_type_info.list_item_type())
                    break

        # Group overloaded operations by name.
        operationsByName = self._OperationsByName(interface)

        # Generate operations.
        for id in sorted(operationsByName.keys()):
            operations = operationsByName[id]
            info = AnalyzeOperation(interface, operations)
            self.AddOperation(info, declare_only)
            if ('%s.%s' % (interface.id, info.declared_name)
                    in convert_to_future_members):
                self.AddOperation(ConvertToFuture(info), declare_only)
Пример #3
0
  def AddSecondaryMembers(self, interface):
    secondary_parents = self._database.TransitiveSecondaryParents(interface,
                          not self._dart_use_blink)
    remove_duplicate_parents = list(set(secondary_parents))
    if len(secondary_parents) != len(remove_duplicate_parents):
      secondary_parents = remove_duplicate_parents
      parent_list = ", ".join(["  %s" % (parent.id) for parent in secondary_parents])
      _logger.warn('Interface %s has duplicate parent interfaces %s - ' \
                   'ignoring duplicates. Please file a bug with the dart:html team.' % (interface.id, parent_list))

    for parent_interface in sorted(secondary_parents):
      if isinstance(parent_interface, str):
        continue

      for attr in sorted(parent_interface.attributes, ConstantOutputOrder):
        if not FindMatchingAttribute(interface, attr):
          if attr.type.id != 'EventHandler':
            self.SecondaryContext(parent_interface)
            self.AddAttribute(attr)

      # Group overloaded operations by name.
      operationsByName =self._OperationsByName(parent_interface)

      if self.OmitOperationOverrides():
        self._RemoveShadowingOperationsWithSameSignature(operationsByName,
            interface)

      # Generate operations.
      for id in sorted(operationsByName.keys()):
        if not any(op.id == id for op in interface.operations):
          operations = operationsByName[id]
          info = AnalyzeOperation(interface, operations)
          self.SecondaryContext(parent_interface)
          self.AddOperation(info)
Пример #4
0
    def AddMembers(self, interface, declare_only=False, dart_js_interop=False):
        if self._interface.id == 'WebGLRenderingContextBase' or self._interface.id == 'WebGL2RenderingContextBase' or \
            self._interface.id == 'WebGLDrawBuffers':
            # Constants in classes WebGLRenderingContextBase, WebGL2RenderingContext, WebGLDrawBuffers are consolidated into
            # one synthesized class (WebGL).
            self._gl_constants.extend(interface.constants)
        else:
            for const in sorted(interface.constants, ConstantOutputOrder):
                self.AddConstant(const)

        for attr in sorted(interface.attributes, ConstantOutputOrder):
            if attr.type.id != 'EventHandler' and attr.type.id != 'EventListener':
                self.AddAttribute(attr, declare_only)

        # The implementation should define an indexer if the interface directly
        # extends List.
        element_type = None
        requires_indexer = False
        if self._interface_type_info.list_item_type():
            self.AddIndexer(
                self._interface_type_info.list_item_type(),
                self._interface_type_info.list_item_type_nullable())
        else:
            for parent in self._database.Hierarchy(self._interface):
                if parent == self._interface:
                    continue
                parent_type_info = self._type_registry.TypeInfo(parent.id)
                if parent_type_info.list_item_type():
                    self.AmendIndexer(parent_type_info.list_item_type())
                    break

        # Group overloaded operations by name.
        self._AddRenamedOverloads(interface)
        operationsByName = self._OperationsByName(interface)
        if self.OmitOperationOverrides():
            self._RemoveShadowingOperationsWithSameSignature(
                operationsByName, interface)

        # Generate operations.
        for id in sorted(operationsByName.keys()):
            operations = operationsByName[id]
            info = AnalyzeOperation(interface, operations)
            info.nnbd = self._nnbd
            self.AddOperation(info, declare_only, dart_js_interop)
            if ('%s.%s' % (interface.id, info.declared_name)
                    in convert_to_future_members):
                self.AddOperation(ConvertToFuture(info), declare_only)
Пример #5
0
def _Emit_Blink_Operation(blink_file, interface, analyzeOperations):
    analyzed = AnalyzeOperation(interface, analyzeOperations)
    (arg_min_count,
     arg_max_count) = generate_parameter_entries(analyzed.param_infos)
    name = analyzed.js_name
    is_native = _Is_Native(interface.id, name)

    operation = analyzeOperations[0]
    if (name.startswith('__') and \
        ('getter' in operation.specials or \
         'setter' in operation.specials or \
         'deleter' in operation.specials)):
        if name == '__propertyQuery__':
            blink_file.write(
                Select_Stub(OPERATION_PQ, is_native) % (name, interface.id))
        else:
            arg_min_count = arg_max_count
            if arg_max_count == 2:
                blink_file.write(
                    Select_Stub(OPERATION_1, is_native) %
                    (name, interface.id, name))
            elif arg_max_count == 3:
                blink_file.write(
                    Select_Stub(OPERATION_2, is_native) %
                    (name, interface.id, name))
            else:
                print "FATAL ERROR: _blink emitter operator %s.%s" % (
                    interface.id, name)
                exit

        return

    for callback_index in range(arg_min_count, arg_max_count):
        if callback_index == 0:
            if operation.is_static:
                class_property = CLASS_STATIC % interface.id
                blink_file.write(
                    Select_Stub(STATIC_OPERATION_0, is_native) %
                    (name, class_property, interface.id, name))
            else:
                blink_file.write(
                    Select_Stub(OPERATION_0, is_native) %
                    (name, interface.id, name))
        else:
            arguments = []
            for i in range(0, callback_index):
                arguments.append(ARGUMENT_NUM % i)
            argument_list = ', '.join(arguments)
            if operation.is_static:
                class_property = CLASS_STATIC % interface.id
                blink_file.write(
                    Select_Stub(STATIC_OPERATION_ARGS, is_native) %
                    (name, callback_index, argument_list, class_property,
                     interface.id, name, argument_list))
            else:
                blink_file.write(
                    Select_Stub(OPERATION_ARGS, is_native) %
                    (name, callback_index, argument_list, interface.id, name,
                     argument_list))
Пример #6
0
    def AddSecondaryMembers(self, interface):
        # With multiple inheritance, attributes and operations of non-first
        # interfaces need to be added.  Sometimes the attribute or operation is
        # defined in the current interface as well as a parent.  In that case we
        # avoid making a duplicate definition and pray that the signatures match.
        if not self._renamer.ShouldSuppressInterface(interface):
            secondary_constants = sorted(self._HoistableConstants(interface),
                                         ConstantOutputOrder)
            for const in secondary_constants:
                self.AddConstant(const)

        secondary_parents = self._database.TransitiveSecondaryParents(
            interface, not self._dart_use_blink)
        remove_duplicate_parents = list(set(secondary_parents))
        if len(secondary_parents) != len(remove_duplicate_parents):
            secondary_parents = remove_duplicate_parents
            parent_list = ", ".join(
                ["  %s" % (parent.id) for parent in secondary_parents])
            _logger.warn('Interface %s has duplicate parent interfaces %s - ' \
                         'ignoring duplicates. Please file a bug with the dart:html team.' % (interface.id, parent_list))

        for parent_interface in sorted(secondary_parents):
            if isinstance(parent_interface, str):
                continue

            for attr in sorted(parent_interface.attributes,
                               ConstantOutputOrder):
                if not FindMatchingAttribute(interface, attr):
                    if attr.type.id != 'EventHandler':
                        self.SecondaryContext(parent_interface)
                        self.AddAttribute(attr)

            # Group overloaded operations by name.
            operationsByName = self._OperationsByName(parent_interface)

            if self.OmitOperationOverrides():
                self._RemoveShadowingOperationsWithSameSignature(
                    operationsByName, interface)

            # Generate operations.
            for id in sorted(operationsByName.keys()):
                if not any(op.id == id for op in interface.operations):
                    operations = operationsByName[id]
                    info = AnalyzeOperation(interface, operations)
                    self.SecondaryContext(parent_interface)
                    self.AddOperation(info)
Пример #7
0
def _Emit_Blink_Operation(blink_file, interface, analyzeOperations):
    analyzed = AnalyzeOperation(interface, analyzeOperations)
    (arg_min_count,
     arg_max_count) = generate_parameter_entries(analyzed.param_infos)
    name = analyzed.js_name

    operation = analyzeOperations[0]
    if (name.startswith('__') and \
        ('getter' in operation.specials or \
         'setter' in operation.specials or \
         'deleter' in operation.specials)):
        if name == '__propertyQuery__':
            blink_file.write(OPERATION_PQ % (name))
        else:
            arg_min_count = arg_max_count
            if arg_max_count == 2:
                blink_file.write(OPERATION_1 % (name, name))
            elif arg_max_count == 3:
                blink_file.write(OPERATION_2 % (name, name))
            else:
                print "FATAL ERROR: _blink emitter operator %s.%s" % (
                    interface.id, name)
                exit

        return

    for callback_index in range(arg_min_count, arg_max_count):
        if callback_index == 0:
            blink_file.write(OPERATION_0 % (name, name))
        else:
            arguments = []
            for i in range(0, callback_index):
                arguments.append(ARGUMENT_NUM % i)
            argument_list = ', '.join(arguments)
            blink_file.write(
                OPERATION_ARGS %
                (name, callback_index, argument_list, name, argument_list))