From 06e29cb474ba4ef526f295efec39c921b03ff24e Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sat, 5 Jan 2019 12:16:52 +1100 Subject: [PATCH] tools/spec: make main an actual function This reduces variable shadowing across the rest of the file --- tools/spec.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tools/spec.py b/tools/spec.py index 1c1f038..ac886c1 100644 --- a/tools/spec.py +++ b/tools/spec.py @@ -44,8 +44,8 @@ class Registry: def serialise(self, platform: Set[str]): required = [] - for (_,f) in self.features.items(): - required += f.apply(reg) + for (_, f) in self.features.items(): + required += f.apply(self) required.append(f.name) for e in self.extensions: @@ -84,7 +84,7 @@ class Type(object): def declare(self): return "" - def define(self,reg): + def define(self, reg: Registry): return "" @@ -695,7 +695,7 @@ def parse_commands(reg: Registry, root): def parse_feature(reg: Registry, root): assert root.tag == 'feature' - name = node.attrib['name'] + name = root.attrib['name'] assert name not in reg.features reg.features[name] = Feature(root) @@ -714,7 +714,7 @@ def parse_extensions(reg: Registry, root): ############################################################################### -def write_header(path: str, q: List[Type]): +def write_header(path: str, q: List[Type], reg: Registry): with open(path, 'w') as dst: dst.write("#pragma once\n") @@ -766,7 +766,7 @@ def write_header(path: str, q: List[Type]): ##----------------------------------------------------------------------------- -def write_icd(path: str, q: List[Type]): +def write_icd(path: str, q: List[Type], reg: Registry): with open(path, 'w') as icd: commands = [i for i in q if isinstance(i, Command)] instance_commands = [i for i in commands if i.is_instance(reg)] @@ -813,7 +813,7 @@ def write_icd(path: str, q: List[Type]): ##----------------------------------------------------------------------------- -def write_dispatch(path: str, q: List[Type]): +def write_dispatch(path: str, q: List[Type], reg: Registry): with open(path, 'w') as dispatch: dispatch.write(""" #include "../vk.hpp" @@ -884,7 +884,7 @@ import argparse ##----------------------------------------------------------------------------- -if __name__ == '__main__': +def main(): logging.getLogger().setLevel(logging.WARNING) parser = argparse.ArgumentParser(description='Transform XML API specification into C++ headers') @@ -935,6 +935,10 @@ if __name__ == '__main__': q = reg.serialise(args.platform) # Finally write out the header, icd, and dispatch code. - write_header(args.dst, q) - write_icd(args.icd, q) - write_dispatch(args.dispatch, q) + write_header(args.dst, q, reg) + write_icd(args.icd, q, reg) + write_dispatch(args.dispatch, q, reg) + +##----------------------------------------------------------------------------- +if __name__ == '__main__': + main()