scanner: look up interfaces by protocol name

Now that we have it, let's use it instead having to mangle names.
This commit is contained in:
Peter Hutterer 2023-04-06 10:59:23 +10:00
parent 24680aef2e
commit cfd2980ae4

View file

@ -440,11 +440,21 @@ class ProtocolParser(xml.sax.handler.ContentHandler):
col = self._locator.getColumnNumber() # type: ignore
return line, col
def interface_by_name(self, name) -> Interface:
def interface_by_name(self, protocol_name: str) -> Interface:
"""
Look up an interface by its protocol name (i.e. always "ei_foo", regardless of
what we're generating).
"""
try:
return [iface for iface in self.interfaces if iface.name == name].pop()
return [
iface
for iface in self.interfaces
if iface.protocol_name == protocol_name
].pop()
except IndexError:
raise XmlError.create(f"Unable to find interface {name}", self.location)
raise XmlError.create(
f"Unable to find interface {protocol_name}", self.location
)
def startDocument(self):
self._run_counter += 1
@ -471,7 +481,7 @@ class ProtocolParser(xml.sax.handler.ContentHandler):
# We only create the interface on the first run, in subsequent runs we
# re-use them so we can cross reference correctly
if self._run_counter > 1:
intf = self.interface_by_name(interface_name)
intf = self.interface_by_name(protocol_name)
else:
intf = Interface.create(
name=interface_name,
@ -631,9 +641,7 @@ class ProtocolParser(xml.sax.handler.ContentHandler):
summary = attrs.get("summary", "")
interface_name = attrs.get("interface", None)
if interface_name is not None:
interface = self.interface_by_name(
Interface.mangle_name(interface_name, self.component)
)
interface = self.interface_by_name(interface_name)
else:
interface = None
enum_name = attrs.get("enum", None)
@ -641,9 +649,7 @@ class ProtocolParser(xml.sax.handler.ContentHandler):
if enum_name is not None:
if "." in enum_name:
iname, enum_name = enum_name.split(".")
intf = self.interface_by_name(
Interface.mangle_name(iname, self.component)
)
intf = self.interface_by_name(iname)
else:
intf = self.current_interface