Exemple #1
0
    def read_idl_file(self, idl_filename):
        """Returns an IdlDefinitions object for an IDL file, without any dependencies.

        The IdlDefinitions object is guaranteed to contain a single
        IdlInterface; it may also contain other definitions, such as
        callback functions and enumerations."""
        ast = blink_idl_parser.parse_file(self.parser, idl_filename)
        if not ast:
            raise Exception('Failed to parse %s' % idl_filename)
        idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename))
        definitions = IdlDefinitions(ast)

        validate_blink_idl_definitions(
            idl_filename, idl_file_basename, definitions)

        # Validate extended attributes
        if not self.extended_attribute_validator:
            return definitions

        try:
            self.extended_attribute_validator.validate_extended_attributes(definitions)
        except IDLInvalidExtendedAttributeError as error:
            raise IDLInvalidExtendedAttributeError("""
IDL ATTRIBUTE ERROR in file:
%s:
    %s
If you want to add a new IDL extended attribute, please add it to:
    %s
and add an explanation to the Blink IDL documentation at:
    http://www.chromium.org/blink/webidl/blink-idl-extended-attributes
    """ % (idl_filename, str(error), EXTENDED_ATTRIBUTES_RELATIVE_PATH))

        return definitions
Exemple #2
0
def file_node_to_idl_definitions(node):
    callback_functions = {}
    enumerations = {}
    exceptions = {}
    interfaces = {}
    typedefs = STANDARD_TYPEDEFS

    # FIXME: only needed for Perl, remove later
    file_name = os.path.abspath(node.GetName())

    children = node.GetChildren()
    for child in children:
        child_class = child.GetClass()
        if child_class == 'Interface':
            interface = interface_node_to_idl_interface(child)
            interfaces[interface.name] = interface
        elif child_class == 'Exception':
            exception = exception_node_to_idl_exception(child)
            exceptions[exception.name] = exception
        elif child_class == 'Typedef':
            type_name = child.GetName()
            typedefs[type_name] = typedef_node_to_idl_typedef(child)
        elif child_class == 'Enum':
            enumeration = enum_node_to_idl_enum(child)
            enumerations[enumeration.name] = enumeration
        elif child_class == 'Callback':
            callback_function = callback_node_to_idl_callback_function(child)
            callback_functions[callback_function.name] = callback_function
        elif child_class == 'Implements':
            # Implements is handled at the interface merging step
            pass
        else:
            raise ValueError('Unrecognized node class: %s' % child_class)

    return IdlDefinitions(callback_functions=callback_functions, enumerations=enumerations, exceptions=exceptions, file_name=file_name, interfaces=interfaces, typedefs=typedefs)
Exemple #3
0
    def read_idl_file(self, idl_filename):
        """Returns an IdlDefinitions object for an IDL file, without any dependencies.

        The IdlDefinitions object is guaranteed to contain a single
        IdlInterface; it may also contain other definitions, such as
        callback functions and enumerations."""
        ast = blink_idl_parser.parse_file(self.parser, idl_filename)
        if not ast:
            raise Exception('Failed to parse %s' % idl_filename)
        idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename))
        definitions = IdlDefinitions(idl_file_basename, ast)

        # Validate file contents with filename convention
        # The Blink IDL filenaming convention is that the file
        # <definition_name>.idl MUST contain exactly 1 definition
        # (interface, dictionary or exception), and the definition name must
        # agree with the file's basename, unless it is a partial definition.
        # (e.g., 'partial interface Foo' can be in FooBar.idl).
        targets = (definitions.interfaces.values() +
                   definitions.dictionaries.values())
        number_of_targets = len(targets)
        if number_of_targets != 1:
            raise Exception(
                'Expected exactly 1 definition in file {0}, but found {1}'.
                format(idl_filename, number_of_targets))
        target = targets[0]
        if not target.is_partial and target.name != idl_file_basename:
            raise Exception(
                'Definition name "{0}" disagrees with IDL file basename "{1}".'
                .format(target.name, idl_file_basename))

        # Validate extended attributes
        if not self.extended_attribute_validator:
            return definitions

        try:
            self.extended_attribute_validator.validate_extended_attributes(
                definitions)
        except IDLInvalidExtendedAttributeError as error:
            raise IDLInvalidExtendedAttributeError("""
IDL ATTRIBUTE ERROR in file:
%s:
    %s
If you want to add a new IDL extended attribute, please add it to:
    %s
and add an explanation to the Blink IDL documentation at:
    http://www.chromium.org/blink/webidl/blink-idl-extended-attributes
    """ % (idl_filename, str(error), EXTENDED_ATTRIBUTES_RELATIVE_PATH))

        return definitions
Exemple #4
0
    def process_idl_file(self, path):
        content = self._read_idl_content(path)
        idl_nodes = self._parser.ParseText(path, content)
        if self._parser.GetErrors() > 0:
            raise Exception('Failed to parse %s' % path)
        idl_name, _ = os.path.splitext(os.path.basename(path))
        definitions = IdlDefinitions(idl_name, idl_nodes)
        definitions = self._rewrite_definitions(definitions)

        self._interfaces.update({
            interface.name: interface
            for interface in definitions.interfaces.itervalues()
            if not interface.is_partial
        })
        self._partial_interfaces.update({
            interface.name: interface
            for interface in definitions.interfaces.itervalues()
            if interface.is_partial
        })
        for impl in definitions.implements:
            self._implements[impl.left_interface].append(impl.right_interface)