From c3d51883cb1a50b180a7834d9d57c0691f01de16 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sat, 2 Mar 2019 13:54:48 +1100 Subject: [PATCH] tools/spec: don't use xml nodes in the Command constructor --- tools/spec.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/tools/spec.py b/tools/spec.py index 18f356f..df3f921 100644 --- a/tools/spec.py +++ b/tools/spec.py @@ -422,17 +422,12 @@ class Command(Type): def is_pointer(self): return '*' in self.param - def __init__(self, node): - assert node.tag == "command" - proto = node.find('proto') - name = proto.find('name').text + def __init__(self, name: str, result: str, params: List[Param], depends: List[str] = None): super().__init__(name) - self.result = proto.find('type').text - self.params = [self.Param(p) for p in node.findall('./param')] - self.depends += [self.result] - for p in self.params: - self.depends += p.depends + self.result = result + self.params = params + self.depends += depends or [] def declare(self): return 'extern "C" %(result)s %(name)s (%(params)s) noexcept;' % { @@ -687,7 +682,16 @@ def parse_commands(reg: Registry, root): reg.types[name] = AliasValue(name, node.attrib['alias']) continue - reg.types[name] = Command(node) + proto = node.find('proto') + name = proto.find('name').text + + result = proto.find('type').text + params = [Command.Param(p) for p in node.findall('./param')] + depends = [result] + for p in params: + depends += p.depends + + reg.types[name] = Command(name, result, params, depends) # -----------------------------------------------------------------------------