tools/spec: don't use xml nodes in the Command constructor

This commit is contained in:
Danny Robson 2019-03-02 13:54:48 +11:00
parent cfdb2f2bdd
commit c3d51883cb

View File

@ -422,17 +422,12 @@ class Command(Type):
def is_pointer(self): def is_pointer(self):
return '*' in self.param return '*' in self.param
def __init__(self, node): def __init__(self, name: str, result: str, params: List[Param], depends: List[str] = None):
assert node.tag == "command"
proto = node.find('proto')
name = proto.find('name').text
super().__init__(name) super().__init__(name)
self.result = proto.find('type').text self.result = result
self.params = [self.Param(p) for p in node.findall('./param')] self.params = params
self.depends += [self.result] self.depends += depends or []
for p in self.params:
self.depends += p.depends
def declare(self): def declare(self):
return 'extern "C" %(result)s %(name)s (%(params)s) noexcept;' % { 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']) reg.types[name] = AliasValue(name, node.attrib['alias'])
continue 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)
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------