Ejemplo n.º 1
0
 def test_value_matches_pattern(self):
     self.assertTrue(
         _value_matches_pattern(None, "*", is_case=True, is_re=False))
     self.assertTrue(
         _value_matches_pattern(None, "*", is_case=False, is_re=False))
     self.assertTrue(
         _value_matches_pattern(None, ".*", is_case=True, is_re=True))
     self.assertTrue(
         _value_matches_pattern(None, ".*", is_case=False, is_re=True))
Ejemplo n.º 2
0
def _get_libraries_raw(object_collection, patterns, key, is_case, is_re,
                       selection, recursive):
    found = set()
    other_libraries = set()
    while object_collection:
        obj = object_collection.pop()
        if isinstance(obj, Netlist):
            for pattern in patterns:
                pattern_is_absolute = _is_pattern_absolute(
                    pattern, is_case, is_re)
                if pattern_is_absolute:
                    result = lookup(obj, Library, key, pattern)
                    if result is not None and result not in found:
                        found.add(result)
                        yield result
                else:
                    for library in obj.libraries:
                        value = library[key] if key in library else ''
                        if library not in found and _value_matches_pattern(
                                value, pattern, is_case, is_re):
                            found.add(library)
                            yield library
        elif isinstance(obj, Library):
            # Libraries used by this library if inside
            if selection == Selection.INSIDE:
                for definition in obj.definitions:
                    for child in definition.children:
                        reference = child.reference
                        if reference:
                            library = reference.library
                            if library and library not in other_libraries:
                                other_libraries.add(library)
                                if recursive:
                                    object_collection.append(library)
            # Libraries that use this library if outside
            else:
                for definition in obj.definitions:
                    for instance in definition.references:
                        parent = instance.parent
                        if parent:
                            library = parent.library
                            if library and library not in other_libraries:
                                other_libraries.add(library)
                                if recursive:
                                    object_collection.append(library)
        elif isinstance(obj, Definition):
            if selection == Selection.INSIDE:
                library = obj.library
                if library and library not in other_libraries:
                    other_libraries.add(library)
                if recursive:
                    object_collection += obj.children
            else:
                for instance in obj.references:
                    parent = instance.parent
                    if parent:
                        library = parent.library
                        if library and library not in other_libraries:
                            other_libraries.add(library)
                        if recursive:
                            object_collection.append(parent)
        elif isinstance(obj, Instance):
            if selection == Selection.INSIDE:
                reference = obj.reference
                if reference:
                    library = reference.library
                    if library and library not in other_libraries:
                        other_libraries.add(library)
                    if recursive:
                        object_collection += reference.children
            else:
                parent = obj.parent
                if parent:
                    library = parent.library
                    if library and library not in other_libraries:
                        other_libraries.add(library)
                    if recursive:
                        object_collection += parent
        elif isinstance(obj, (Port, Cable)):
            definition = obj.definition
            if definition:
                object_collection.append(definition)
        elif isinstance(obj, InnerPin):
            port = obj.port
            if port:
                object_collection.append(port)
        elif isinstance(obj, OuterPin):
            instance = obj.instance
            if instance:
                object_collection.append(instance)
        elif isinstance(obj, Wire):
            cable = obj.cable
            if cable:
                object_collection.append(cable)
        elif isinstance(obj, HRef):
            if obj.is_valid:
                object_collection.append(obj.item)

    if other_libraries:
        namemap = dict()
        for other_instance in other_libraries:
            if other_instance in found:
                continue
            found.add(other_instance)
            name = other_instance[key] if key in other_instance else ''
            if name not in namemap:
                namemap[name] = list()
            namemap[name].append(other_instance)
        for pattern in patterns:
            pattern_is_absolute = _is_pattern_absolute(pattern, is_case, is_re)
            if pattern_is_absolute:
                if pattern in namemap:
                    result = namemap[pattern]
                    for instance in result:
                        yield instance
            else:
                discard = set()
                for instance in found:
                    value = instance[key] if key in instance else ''
                    if _value_matches_pattern(value, pattern, is_case, is_re):
                        discard.add(instance)
                        yield instance
                found -= discard
Ejemplo n.º 3
0
def _get_hports_raw(object_collection, patterns, recursive, is_case, is_re):
    in_namemap = set()
    in_yield = set()
    namemap = dict()
    bypass_namesearch = set()
    while object_collection:
        obj = object_collection.pop()
        if isinstance(obj, Netlist):
            top_instance = obj.top_instance
            if top_instance:
                href = HRef.from_parent_and_item(None, top_instance)
                object_collection.append(href)
        elif isinstance(obj, HRef):
            if obj.is_valid is False:
                continue
            item = obj.item
            if isinstance(item, Instance):
                if obj not in bypass_namesearch:
                    _update_hport_namemap(obj, recursive, in_namemap, namemap)
                else:
                    bypass_namesearch.discard(obj)
                    reference = item.reference
                    if reference:
                        # Get all cables inside a hierarchical instance
                        for port in reference.ports:
                            hport = HRef.from_parent_and_item(obj, port)
                            if hport not in in_yield:
                                in_yield.add(hport)
                                yield(hport)
                        # get internal cables recursively
                        if recursive:
                            for child in reference.children:
                                href_child = HRef.from_parent_and_item(obj, child)
                                bypass_namesearch.add(href_child)
                                object_collection.append(href_child)
            elif isinstance(item, Port):
                if obj not in in_yield:
                    in_yield.add(obj)
                    yield (obj)
            elif isinstance(item, Cable):
                for wire in item.wires:
                    href_wire = HRef.from_parent_and_item(obj, wire)
                    object_collection.append(href_wire)
            elif isinstance(item, Wire):
                    href_parent_cable = obj.parent
                    href_parent_instance = href_parent_cable.parent
                    for pin in item.pins:
                        if isinstance(pin, OuterPin):
                            instance = pin.instance
                            if instance:
                                href_inst = HRef.from_parent_and_item(href_parent_instance, pin.instance)
                                inner_pin = pin.inner_pin
                                if inner_pin:
                                    inner_port = inner_pin.port
                                    if inner_port:
                                        href_port = HRef.from_parent_and_item(href_inst, inner_port)
                                        if href_port not in in_yield:
                                            in_yield.add(href_port)
                                            yield href_port
                        else:
                            port = pin.port
                            if port:
                                href_port = HRef.from_parent_and_item(href_parent_instance, port)
                                if href_port not in in_yield:
                                    in_yield.add(href_port)
                                    yield href_port
            elif isinstance(item, InnerPin):
                hport = obj.parent
                if hport not in in_yield:
                    in_yield.add(hport)
                    yield hport
        elif isinstance(obj, Library):
            object_collection += obj.definitions
        elif isinstance(obj, Definition):
            hrefs = set(HRef.get_all_hrefs_of_instances(obj.references))
            bypass_namesearch |= hrefs
            object_collection += hrefs
        elif isinstance(obj, Instance):
            hrefs = set(HRef.get_all_hrefs_of_instances(obj))
            bypass_namesearch |= hrefs
            object_collection += hrefs
        elif isinstance(obj, (Port, Cable, InnerPin, OuterPin, Wire)):
            object_collection += HRef.get_all_hrefs_of_item(obj)

    for href in in_yield:
        in_namemap.discard(href)

    if in_namemap:  # namemap is to cable
        for pattern in patterns:
            pattern_is_absolute = _is_pattern_absolute(pattern, is_case, is_re)
            if pattern_is_absolute:
                if pattern in namemap:
                    result = namemap[pattern]
                    for href in result:
                        if href in in_namemap:
                            in_namemap.remove(href)
                            yield href
            else:
                for name in namemap:
                    if _value_matches_pattern(name, pattern, is_case, is_re):
                        result = namemap[name]
                        for href in result:
                            if href in in_namemap:
                                in_namemap.remove(href)
                                yield href
Ejemplo n.º 4
0
def _get_hwires_raw(object_collection, selection, patterns, recursive, is_case, is_re):
    in_namemap = set()
    in_yield = set()
    namemap = dict()
    hpin_search = set()
    bypass_namesearch = set()
    while object_collection:
        obj = object_collection.pop()
        if isinstance(obj, Netlist):
            top_instance = obj.top_instance
            if top_instance:
                href = HRef.from_parent_and_item(None, top_instance)
                object_collection.append(href)
        elif isinstance(obj, HRef):
            if obj.is_valid is False:
                continue
            item = obj.item
            if isinstance(item, Instance):
                if selection == Selection.INSIDE and obj not in bypass_namesearch:
                    _update_hwire_namemap(obj, recursive, in_namemap, namemap)
                else:
                    bypass_namesearch.discard(obj)
                    reference = item.reference
                    if reference:
                        if selection in {Selection.INSIDE, Selection.ALL}:
                            # Get all cables inside a hierarchical instance
                            for cable in reference.cables:
                                hcable = HRef.from_parent_and_item(obj, cable)
                                for wire in cable.wires:
                                    hwire = HRef.from_parent_and_item(hcable, wire)
                                    if hwire not in in_yield:
                                        in_yield.add(hwire)
                                        yield(hwire)
                            # get internal cables recursively
                            if recursive or selection == Selection.ALL:
                                for child in reference.children:
                                    href_child = HRef.from_parent_and_item(obj, child)
                                    bypass_namesearch.add(href_child)
                                    object_collection.append(href_child)
                        if selection in {Selection.OUTSIDE, Selection.BOTH, Selection.ALL}:
                            for port in reference.ports:
                                href_port = HRef.from_parent_and_item(obj, port)
                                for pin in port.pins:
                                    href_pin = HRef.from_parent_and_item(href_port, pin)
                                    hpin_search.add(href_pin)
            elif isinstance(item, Port):
                for pin in item.pins:
                    href_pin = HRef.from_parent_and_item(obj, pin)
                    hpin_search.add(href_pin)
            elif isinstance(item, Cable):
                for wire in item.wires:
                    href_wire = HRef.from_parent_and_item(obj, wire)
                    object_collection.append(href_wire)
            elif isinstance(item, Wire):
                if selection == Selection.INSIDE:
                    if obj not in in_yield:
                        in_yield.add(obj)
                        yield obj
                elif selection == Selection.OUTSIDE:
                    href_parent_cable = obj.parent
                    href_parent_instance = href_parent_cable.parent
                    for pin in item.pins:
                        if isinstance(pin, OuterPin):
                            href_inst = HRef.from_parent_and_item(href_parent_instance, pin.instance)
                            inner_wire = pin.inner_pin.wire
                            if inner_wire:
                                inner_cable = inner_wire.cable
                                href_cable = HRef.from_parent_and_item(href_inst, inner_cable)
                                href_wire = HRef.from_parent_and_item(href_cable, inner_wire)
                                if href_wire not in in_yield:
                                    in_yield.add(href_wire)
                                    yield href_wire
                        else:
                            href_parent = href_parent_instance.parent
                            if href_parent:
                                instance = href_parent_instance.item
                                if pin in instance.pins:
                                    outer_pin = instance.pins[pin]
                                    outer_wire = outer_pin.wire
                                    if outer_wire:
                                        outer_cable = outer_wire.cable
                                        href_cable = HRef.from_parent_and_item(href_parent, outer_cable)
                                        href_wire = HRef.from_parent_and_item(href_cable, outer_wire)
                                        if href_wire not in in_yield:
                                            in_yield.add(href_wire)
                                            yield href_wire
                else:
                    if obj not in in_yield:
                        in_yield.add(obj)
                        yield obj
                    href_cable = obj.parent
                    href_inst = href_cable.parent
                    for pin in item.pins:
                        if isinstance(pin, OuterPin):
                            href_sub_inst = HRef.from_parent_and_item(obj.parent, pin.instance)
                            inner_pin = pin.inner_pin
                            port = inner_pin.port
                            href_port = HRef.from_parent_and_item(href_sub_inst, port)
                            href_pin = HRef.from_parent_and_item(href_port, pin)
                        else:
                            port = pin.port
                            href_port = HRef.from_parent_and_item(href_inst, port)
                            href_pin = HRef.from_parent_and_item(href_port, pin)
                        object_collection.append(href_pin)
            elif isinstance(item, InnerPin):
                hpin_search.add(obj)
        elif isinstance(obj, Library):
            object_collection += obj.definitions
        elif isinstance(obj, Definition):
            hrefs = set(HRef.get_all_hrefs_of_instances(obj.references))
            bypass_namesearch |= hrefs
            object_collection += hrefs
        elif isinstance(obj, Instance):
            hrefs = set(HRef.get_all_hrefs_of_instances(obj))
            bypass_namesearch |= hrefs
            object_collection += hrefs
        elif isinstance(obj, (Port, Cable, InnerPin, OuterPin, Wire)):
            object_collection += HRef.get_all_hrefs_of_item(obj)

    if hpin_search:
        for hwire in _get_hwires_from_hpins(hpin_search, selection):
            if hwire not in in_yield:
                in_yield.add(hwire)
                yield hwire

    for href in in_yield:
        in_namemap.discard(href)

    if in_namemap:
        for pattern in patterns:
            pattern_is_absolute = _is_pattern_absolute(pattern, is_case, is_re)
            if pattern_is_absolute:
                if pattern in namemap:
                    result = namemap[pattern]
                    for href in result:
                        if href in in_namemap:
                            in_namemap.remove(href)
                            yield href
            else:
                for name in namemap:
                    if _value_matches_pattern(name, pattern, is_case, is_re):
                        result = namemap[name]
                        for href in result:
                            if href in in_namemap:
                                in_namemap.remove(href)
                                yield href
Ejemplo n.º 5
0
def _get_netlists_raw(object_collection, patterns, key, is_case, is_re):
    found = set()
    namemap = dict()
    while object_collection:
        obj = object_collection.pop()
        if isinstance(obj, Netlist):
            if obj not in found:
                found.add(obj)
                name = obj.get(key, None)
                if name not in namemap:
                    namemap[name] = list()
                namemap[name].append(obj)
        elif isinstance(obj, Library):
            netlist = obj.netlist
            if netlist:
                object_collection.append(netlist)
        elif isinstance(obj, Definition):
            library = obj.library
            if library:
                object_collection.append(library)
        elif isinstance(obj, Instance):
            reference = obj.reference
            if reference:
                object_collection.append(reference)
        elif isinstance(obj, Port):
            definition = obj.definition
            if definition:
                object_collection.append(definition)
        elif isinstance(obj, InnerPin):
            port = obj.port
            if port:
                object_collection.append(port)
        elif isinstance(obj, OuterPin):
            inner_pin = obj.inner_pin
            if inner_pin:
                object_collection.append(inner_pin)
        elif isinstance(obj, Cable):
            definition = obj.definition
            if definition:
                object_collection.append(definition)
        elif isinstance(obj, Wire):
            cable = obj.cable
            if cable:
                object_collection.append(cable)
        elif isinstance(obj, HRef):
            if obj.is_valid:
                item = obj.item
                if item:
                    object_collection.append(item)

    for pattern in patterns:
        pattern_is_absolute = _is_pattern_absolute(pattern, is_case, is_re)
        if pattern_is_absolute:
            if pattern in namemap:
                result = namemap[pattern]
                for netlist in result:
                    if netlist in found:
                        found.remove(netlist)
                        yield netlist
        else:
            yielded = set()
            for netlist in found:
                value = netlist[key] if key in netlist else ''
                if _value_matches_pattern(value, pattern, is_case, is_re):
                    yielded.add(netlist)
                    yield netlist
            found -= yielded
Ejemplo n.º 6
0
 def test_value_matches_pattern_bad_regex_expr(self):
     self.assertFalse(
         _value_matches_pattern(None, "*", is_case=False, is_re=True))
Ejemplo n.º 7
0
def _get_instances_raw(object_collection, patterns, recursive, is_case, is_re):
    in_namemap = set()
    in_yield = set()
    namemap = dict()
    instance_search = set()
    while object_collection:
        obj = object_collection.pop()
        if isinstance(obj, Netlist):
            top_instance = obj.top_instance
            if top_instance:
                href = HRef.from_parent_and_item(None, top_instance)
                _update_namemap(href, recursive, in_namemap, namemap)
        elif isinstance(obj, HRef):
            if obj.is_valid is False:
                continue
            item = obj.item
            if isinstance(item, Instance):
                _update_namemap(obj, recursive, in_namemap, namemap)
            elif isinstance(item, (Port, Cable)):
                hinstance = obj.parent
                if hinstance and hinstance not in in_yield:
                    in_yield.add(hinstance)
                    yield hinstance
            elif isinstance(item, (InnerPin, Wire)):
                hcable_or_hport = obj.parent
                if hcable_or_hport:
                    hinstance = hcable_or_hport.parent
                    if hinstance and hinstance not in in_yield:
                        in_yield.add(hinstance)
                        yield hinstance
        elif isinstance(obj, Library):
            object_collection += obj.definitions
        elif isinstance(obj, Definition):
            instance_search |= obj.references
        elif isinstance(obj, Instance):
            instance_search.add(obj)
        elif isinstance(obj, (Port, Cable)):
            definition = obj.definition
            if definition:
                object_collection.append(definition)
        elif isinstance(obj, InnerPin):
            port = obj.port
            if port:
                definition = port.definition
                if definition:
                    object_collection.append(definition)
        elif isinstance(obj, OuterPin):
            instance = obj.instance
            if instance:
                instance_search.add(instance)
        elif isinstance(obj, Wire):
            cable = obj.cable
            if cable:
                definition = cable.definition
                if definition:
                    object_collection.append(definition)

    if instance_search:
        for href in HRef.get_all_hrefs_of_instances(instance_search):
            if href not in in_yield:
                in_yield.add(href)
                yield href

    for href in in_yield:
        in_namemap.discard(href)

    if in_namemap:
        for pattern in patterns:
            pattern_is_absolute = _is_pattern_absolute(pattern, is_case, is_re)
            if pattern_is_absolute:
                if pattern in namemap:
                    result = namemap[pattern]
                    for href in result:
                        if href in in_namemap:
                            in_namemap.remove(href)
                            yield href
            else:
                for name in namemap:
                    if _value_matches_pattern(name, pattern, is_case, is_re):
                        result = namemap[name]
                        for href in result:
                            if href in in_namemap:
                                in_namemap.remove(href)
                                yield href
Ejemplo n.º 8
0
def _get_definitions_raw(object_collection, patterns, key, is_case, is_re,
                         selection, recursive):
    found = set()
    other_definitions = set()
    while object_collection:
        obj = object_collection.pop()
        if isinstance(obj, Library):
            if selection == Selection.INSIDE:
                for pattern in patterns:
                    pattern_is_absolute = _is_pattern_absolute(
                        pattern, is_case, is_re)
                    if pattern_is_absolute:
                        result = lookup(obj, Definition, key, pattern)
                        if result is not None and result not in found:
                            found.add(result)
                            yield result
                    else:
                        for definition in obj.definitions:
                            value = definition[key] if key in definition else ''
                            if definition not in found and _value_matches_pattern(
                                    value, pattern, is_case, is_re):
                                found.add(definition)
                                yield definition
                if recursive:
                    object_collection += obj.definitions
            else:
                object_collection += obj.definitions
        elif isinstance(obj, Netlist):
            object_collection += obj.libraries
        elif isinstance(obj, Definition):
            if selection == Selection.INSIDE:
                for child in obj.children:
                    reference = child.reference
                    if reference:
                        if reference not in other_definitions:
                            other_definitions.add(reference)
                            if recursive:
                                object_collection.append(reference)
            else:
                for definition in obj.references:
                    parent = definition.parent
                    if parent:
                        if parent not in other_definitions:
                            other_definitions.add(parent)
                            if recursive:
                                object_collection.append(parent)
        elif isinstance(obj, Instance):
            if selection == Selection.INSIDE:
                reference = obj.reference
                if reference:
                    if reference not in other_definitions:
                        other_definitions.add(reference)
                        if recursive:
                            object_collection += reference.children
            else:
                parent = obj.parent
                if parent:
                    if parent not in other_definitions:
                        other_definitions.add(parent)
                        if recursive:
                            object_collection.append(parent)
        elif isinstance(obj, (Port, Cable)):
            definition = obj.definition
            if definition:
                if definition not in other_definitions:
                    other_definitions.add(definition)
        elif isinstance(obj, InnerPin):
            definition = obj.port
            if definition:
                object_collection.append(definition)
        elif isinstance(obj, OuterPin):
            definition = obj.instance
            if definition:
                object_collection.append(definition)
        elif isinstance(obj, Wire):
            cable = obj.cable
            if cable:
                object_collection.append(cable)
        elif isinstance(obj, HRef):
            if obj.is_valid:
                object_collection.append(obj.item)

    if other_definitions:
        namemap = dict()
        for other_definition in other_definitions:
            if other_definition in found:
                continue
            found.add(other_definition)
            name = other_definition[key] if key in other_definition else ''
            if name not in namemap:
                namemap[name] = list()
            namemap[name].append(other_definition)
        for pattern in patterns:
            pattern_is_absolute = _is_pattern_absolute(pattern, is_case, is_re)
            if pattern_is_absolute:
                if pattern in namemap:
                    result = namemap[pattern]
                    for definition in result:
                        yield definition
            else:
                names_to_remove = list()
                for name in namemap:
                    if _value_matches_pattern(name, pattern, is_case, is_re):
                        result = namemap[name]
                        names_to_remove.append(name)
                        for definition in result:
                            yield definition
                for name in names_to_remove:
                    del namemap[name]
Ejemplo n.º 9
0
def _get_ports_raw(object_collection, patterns, key, is_case, is_re):
    found = set()
    other_ports = set()
    while object_collection:
        obj = object_collection.pop()
        if isinstance(obj, Definition):
            for pattern in patterns:
                pattern_is_absolute = _is_pattern_absolute(
                    pattern, is_case, is_re)
                if pattern_is_absolute:
                    result = lookup(obj, Port, key, pattern)
                    if result is not None and result not in found:
                        found.add(result)
                        yield result
                else:
                    for port in obj.ports:
                        value = port[key] if key in port else ''
                        if port not in found and _value_matches_pattern(
                                value, pattern, is_case, is_re):
                            found.add(port)
                            yield port
        elif isinstance(obj, Netlist):
            for library in obj.libraries:
                for definition in library.definitions:
                    object_collection.append(definition)
        elif isinstance(obj, Library):
            object_collection += obj.definitions
        elif isinstance(obj, Instance):
            reference = obj.reference
            if reference:
                object_collection.append(reference)
        elif isinstance(obj, Port):
            other_ports.add(obj)
        elif isinstance(obj, InnerPin):
            port = obj.port
            if port:
                other_ports.add(port)
        elif isinstance(obj, OuterPin):
            inner_pin = obj.inner_pin
            if inner_pin:
                object_collection.append(inner_pin)
        elif isinstance(obj, Wire):
            object_collection += obj.pins
        elif isinstance(obj, Cable):
            object_collection += obj.wires
        elif isinstance(obj, HRef):
            if obj.is_valid:
                object_collection.append(obj.item)

    if other_ports:
        namemap = dict()
        for other_port in other_ports:
            if other_port in found:
                continue
            found.add(other_port)
            name = other_port[key] if key in other_port else ''
            if name not in namemap:
                namemap[name] = list()
            namemap[name].append(other_port)
        for pattern in patterns:
            pattern_is_absolute = _is_pattern_absolute(pattern, is_case, is_re)
            if pattern_is_absolute:
                if pattern in namemap:
                    result = namemap[pattern]
                    del namemap[pattern]
                    for port in result:
                        yield port
            else:
                names_to_remove = list()
                for name in namemap:
                    if _value_matches_pattern(name, pattern, is_case, is_re):
                        result = namemap[name]
                        names_to_remove.append(name)
                        for port in result:
                            yield port
                for name in names_to_remove:
                    del namemap[name]
Ejemplo n.º 10
0
def _get_cables_raw(object_collection, patterns, key, is_case, is_re,
                    selection, recursive):
    found = set()
    other_cables = set()
    searched_wires = set()
    while object_collection:
        obj = object_collection.pop()
        if isinstance(obj, Definition):
            if selection in {Selection.INSIDE, Selection.ALL}:
                for pattern in patterns:
                    pattern_is_absolute = _is_pattern_absolute(
                        pattern, is_case, is_re)
                    if pattern_is_absolute:
                        result = lookup(obj, Cable, key, pattern)
                        if result is not None and result not in found:
                            found.add(result)
                            yield result
                    else:
                        for cable in obj.cables:
                            value = cable[key] if key in cable else ''
                            if cable not in found and _value_matches_pattern(
                                    value, pattern, is_case, is_re):
                                found.add(cable)
                                yield cable
                if recursive or selection == Selection.ALL:
                    object_collection += obj.children
            if selection in {Selection.OUTSIDE, Selection.BOTH, Selection.ALL}:
                for port in obj.ports:
                    for pin in port.pins:
                        object_collection.append(pin)
        elif isinstance(obj, Library):
            object_collection += obj.definitions
        elif isinstance(obj, Netlist):
            for library in obj.libraries:
                object_collection += library.definitions
        elif isinstance(obj, Instance):
            if selection in {Selection.INSIDE, Selection.ALL}:
                reference = obj.reference
                if reference:
                    for cable in reference.cables:
                        other_cables.add(cable)
                    if recursive or selection == Selection.ALL:
                        object_collection += reference.children
            if selection in {Selection.BOTH, Selection.OUTSIDE, Selection.ALL}:
                object_collection += obj.pins
        elif isinstance(obj, InnerPin):
            if selection in {Selection.INSIDE, Selection.BOTH, Selection.ALL}:
                wire = obj.wire
                if wire and wire not in searched_wires:
                    searched_wires.add(wire)
                    cable = wire.cable
                    if cable:
                        other_cables.add(cable)
                    if selection == Selection.ALL:
                        object_collection += wire.pins
            if selection in {Selection.OUTSIDE, Selection.BOTH, Selection.ALL}:
                port = obj.port
                if port:
                    definition = port.definition
                    if definition:
                        for instance in definition.references:
                            outer_pin = instance.pins[obj]
                            outer_wire = outer_pin.wire
                            if outer_wire and outer_wire not in searched_wires:
                                searched_wires.add(outer_wire)
                                cable = outer_wire.cable
                                if cable:
                                    other_cables.add(cable)
                                if selection == Selection.ALL:
                                    object_collection += outer_wire.pins
        elif isinstance(obj, OuterPin):
            if selection in {Selection.INSIDE, Selection.BOTH, Selection.ALL}:
                inner_pin = obj.inner_pin
                if inner_pin:
                    inner_wire = inner_pin.wire
                    if inner_wire and inner_wire not in searched_wires:
                        searched_wires.add(inner_wire)
                        cable = inner_wire.cable
                        if cable:
                            other_cables.add(cable)
                        if selection == Selection.ALL:
                            object_collection += inner_wire.pins
            if selection in {Selection.OUTSIDE, Selection.BOTH, Selection.ALL}:
                wire = obj.wire
                if wire and wire not in searched_wires:
                    searched_wires.add(wire)
                    cable = wire.cable
                    if cable:
                        other_cables.add(cable)
                    if selection == Selection.ALL:
                        object_collection += wire.pins
        elif isinstance(obj, Port):
            object_collection += obj.pins
        elif isinstance(obj, Wire):
            if selection == Selection.INSIDE:
                cable = obj.cable
                if cable:
                    other_cables.add(cable)
            elif selection == Selection.OUTSIDE:
                for pin in obj.pins:
                    if isinstance(pin, OuterPin):
                        inner_pin = pin.inner_pin
                        inner_wire = inner_pin.wire
                        if inner_wire:
                            cable = inner_wire.cable
                            if cable:
                                other_cables.add(cable)
                    else:
                        object_collection.append(pin)
            else:
                object_collection += obj.pins
        elif isinstance(obj, Cable):
            if selection == Selection.INSIDE:
                other_cables.add(obj)
            else:
                object_collection += obj.wires
        elif isinstance(obj, HRef):
            if obj.is_valid:
                object_collection.append(obj.item)

    if other_cables:
        namemap = dict()
        for other_cable in other_cables:
            if other_cable not in found:
                found.add(other_cable)
                name = other_cable[key] if key in other_cable else ''
                if name not in namemap:
                    namemap[name] = list()
                namemap[name].append(other_cable)
        for pattern in patterns:
            pattern_is_absolute = _is_pattern_absolute(pattern, is_case, is_re)
            if pattern_is_absolute:
                if pattern in namemap:
                    result = namemap[pattern]
                    del namemap[pattern]
                    for port in result:
                        yield port
            else:
                names_to_remove = list()
                for name in namemap:
                    if _value_matches_pattern(name, pattern, is_case, is_re):
                        result = namemap[name]
                        names_to_remove.append(name)
                        for port in result:
                            yield port
                for name in names_to_remove:
                    del namemap[name]