Esempio n. 1
0
    def __init__(self, interfaces_info=None, outputdir=''):
        self.extended_attribute_validator = IDLExtendedAttributeValidator()
        self.interfaces_info = interfaces_info

        if interfaces_info:
            self.interface_dependency_resolver = InterfaceDependencyResolver(interfaces_info, self)
        else:
            self.interface_dependency_resolver = None

        self.parser = BlinkIDLParser(outputdir=outputdir)
Esempio n. 2
0
class IdlReader(object):
    def __init__(self, interfaces_info=None, outputdir=''):
        self.extended_attribute_validator = IDLExtendedAttributeValidator()
        self.interfaces_info = interfaces_info

        if interfaces_info:
            self.interface_dependency_resolver = InterfaceDependencyResolver(interfaces_info, self)
        else:
            self.interface_dependency_resolver = None

        self.parser = BlinkIDLParser(outputdir=outputdir)

    def read_idl_definitions(self, idl_filename):
        """Returns a dictionary whose key is component and value is an IdlDefinitions object for an IDL file, including all dependencies."""
        definitions = self.read_idl_file(idl_filename)
        component = idl_filename_to_component(idl_filename)

        if not self.interface_dependency_resolver:
            return {component: definitions}

        # This definitions should have a dictionary. No need to resolve any
        # dependencies.
        if not definitions.interfaces:
            return {component: definitions}

        return self.interface_dependency_resolver.resolve_dependencies(definitions, component)

    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
class IdlReader(object):
    def __init__(self, interfaces_info=None, outputdir=''):
        self.extended_attribute_validator = IDLExtendedAttributeValidator()
        self.interfaces_info = interfaces_info

        if interfaces_info:
            self.interface_dependency_resolver = InterfaceDependencyResolver(interfaces_info, self)
        else:
            self.interface_dependency_resolver = None

        self.parser = BlinkIDLParser(outputdir=outputdir)

    def read_idl_definitions(self, idl_filename):
        """Returns a dictionary whose key is component and value is an IdlDefinitions object for an IDL file, including all dependencies."""
        definitions = self.read_idl_file(idl_filename)
        component = idl_filename_to_component(idl_filename)

        if not self.interface_dependency_resolver:
            return {component: definitions}

        # This definitions should have a dictionary. No need to resolve any
        # dependencies.
        if not definitions.interfaces:
            return {component: definitions}

        return self.interface_dependency_resolver.resolve_dependencies(definitions, component)

    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_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
Esempio n. 4
0
class IdlReader(object):
    def __init__(self, interfaces_info=None, idl_attributes_filename=None, outputdir=''):
        if idl_attributes_filename:
            self.extended_attribute_validator = IDLExtendedAttributeValidator(idl_attributes_filename)
        else:
            self.extended_attribute_validator = None

        if interfaces_info:
            self.interface_dependency_resolver = InterfaceDependencyResolver(interfaces_info, self)
        else:
            self.interface_dependency_resolver = None

        self.parser = BlinkIDLParser(outputdir=outputdir)

    def read_idl_definitions(self, idl_filename):
        """Returns an IdlDefinitions object for an IDL file, including all dependencies."""
        definitions = self.read_idl_file(idl_filename)
        if not self.interface_dependency_resolver:
            return definitions

        interface_name, _ = os.path.splitext(os.path.basename(idl_filename))
        self.interface_dependency_resolver.resolve_dependencies(
            definitions, interface_name)
        return definitions

    def read_idl_file(self, idl_filename):
        """Returns an IdlDefinitions object for an IDL file, without any dependencies."""
        ast = blink_idl_parser.parse_file(self.parser, idl_filename)
        if not ast:
            raise Exception('Failed to parse %s' % idl_filename)
        definitions = IdlDefinitions(ast)
        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
    bindings/IDLExtendedAttributes.txt
and add an explanation to the Blink IDL documentation at:
    http://www.chromium.org/blink/webidl/blink-idl-extended-attributes
    """ % (idl_filename, str(error)))

        return definitions
Esempio n. 5
0
    def __init__(self, interfaces_info=None, outputdir=''):
        self.extended_attribute_validator = IDLExtendedAttributeValidator()

        if interfaces_info:
            self.interface_dependency_resolver = InterfaceDependencyResolver(interfaces_info, self)
        else:
            self.interface_dependency_resolver = None

        self.parser = BlinkIDLParser(outputdir=outputdir)
Esempio n. 6
0
class IdlReader(object):
    def __init__(self, interfaces_info=None, outputdir=''):
        self.extended_attribute_validator = IDLExtendedAttributeValidator()

        if interfaces_info:
            self.interface_dependency_resolver = InterfaceDependencyResolver(
                interfaces_info, self)
        else:
            self.interface_dependency_resolver = None

        self.parser = BlinkIDLParser(outputdir=outputdir)

    def read_idl_definitions(self, idl_filename):
        """Returns an IdlDefinitions object for an IDL file, including all dependencies."""
        definitions = self.read_idl_file(idl_filename)
        if not self.interface_dependency_resolver:
            return definitions
        self.interface_dependency_resolver.resolve_dependencies(definitions)
        return definitions

    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)
        definitions = IdlDefinitions(ast)

        # Validate file contents with filename convention
        # The Blink IDL filenaming convention is that the file
        # <interface_name>.idl MUST contain exactly 1 interface (or exception),
        # and the interface name must agree with the file's basename,
        # unless it is a partial interface.
        # (e.g., 'partial interface Foo' can be in FooBar.idl).
        number_of_interfaces = len(definitions.interfaces)
        if number_of_interfaces != 1:
            raise Exception(
                'Expected exactly 1 interface in file {0}, but found {1}'.
                format(idl_filename, number_of_interfaces))
        interface = next(definitions.interfaces.itervalues())
        idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename))
        if not interface.is_partial and interface.name != idl_file_basename:
            raise Exception(
                'Interface name "{0}" disagrees with IDL file basename "{1}".'.
                format(interface.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
Esempio n. 7
0
class IdlReader(object):
    def __init__(self, interfaces_info=None, outputdir=''):
        self.extended_attribute_validator = IDLExtendedAttributeValidator()

        if interfaces_info:
            self.interface_dependency_resolver = InterfaceDependencyResolver(interfaces_info, self)
        else:
            self.interface_dependency_resolver = None

        self.parser = BlinkIDLParser(outputdir=outputdir)

    def read_idl_definitions(self, idl_filename):
        """Returns an IdlDefinitions object for an IDL file, including all dependencies."""
        definitions = self.read_idl_file(idl_filename)
        if not self.interface_dependency_resolver:
            return definitions
        self.interface_dependency_resolver.resolve_dependencies(definitions)
        return definitions

    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)
        definitions = IdlDefinitions(ast)

        # Validate file contents with filename convention
        # The Blink IDL filenaming convention is that the file
        # <interface_name>.idl MUST contain exactly 1 interface (or exception),
        # and the interface name must agree with the file's basename,
        # unless it is a partial interface.
        # (e.g., 'partial interface Foo' can be in FooBar.idl).
        number_of_interfaces = len(definitions.interfaces)
        if number_of_interfaces != 1:
            raise Exception(
                'Expected exactly 1 interface in file {0}, but found {1}'
                .format(idl_filename, number_of_interfaces))
        interface = next(definitions.interfaces.itervalues())
        idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename))
        if not interface.is_partial and interface.name != idl_file_basename:
            raise Exception(
                'Interface name "{0}" disagrees with IDL file basename "{1}".'
                .format(interface.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