tools/spec: update whitespacing to conform to PEP8

This commit is contained in:
Danny Robson 2019-01-05 12:04:31 +11:00
parent fa2eed7e03
commit d13f684853

View File

@ -9,7 +9,7 @@ import re
###############################################################################
def rename(name:str):
def rename(name: str):
return name
@ -24,7 +24,7 @@ class registry:
self.applied = set()
def _serialise(self, name:str, queued:Set[str]):
def _serialise(self, name: str, queued: Set[str]):
if name in queued:
return []
@ -42,7 +42,7 @@ class registry:
return result
def serialise(self, platform:Set[str]):
def serialise(self, platform: Set[str]):
required = []
for (_,f) in self.features.items():
@ -69,7 +69,7 @@ class type(object):
This includes (but is not limited to) types, like structures; and values,
like constants.
"""
def __init__(self, name:str, depends:List[str] = None):
def __init__(self, name: str, depends: List[str] = None):
assert name
self.name = name
@ -97,7 +97,7 @@ class aliastype(type):
May be serialised using an appropriate host language facility
(eg, a typedef)
"""
def __init__(self, name:str, target:str, depends:List[str]=None):
def __init__(self, name: str, target: str, depends: List[str]=None):
depends = depends or []
super().__init__(name, depends=depends+[target])
self.target = target
@ -113,7 +113,7 @@ class aliasvalue(type):
May be serialised using an appropriate host language facility.
"""
def __init__(self, name:str, target:str):
def __init__(self, name: str, target: str):
super().__init__(name, depends=[target])
self.target = target
self.value = target
@ -127,21 +127,20 @@ class aliasvalue(type):
##-----------------------------------------------------------------------------
class placeholder(type):
def __init__(self, name:str):
def __init__(self, name: str):
super().__init__(name)
##-----------------------------------------------------------------------------
class unscoped(type):
def __init__(self, name:str):
def __init__(self, name: str):
super().__init__(name)
self.values = []
def declare(self):
return "\n".join(t.declare() for t in self.values)
def define(self,reg):
return "\n".join(t.define(reg.types) for t in self.values)
@ -176,7 +175,7 @@ class define(type):
class bitmask(type):
def __init__(self,node):
def __init__(self, node):
assert node.tag == 'type'
assert node.attrib['category'] == 'bitmask'
@ -196,8 +195,8 @@ class bitmask(type):
"type": self.type
}
def define(self, reg:registry):
return self.declare();
def define(self, reg: registry):
return self.declare()
if not self.requires:
return self.declare()
@ -244,7 +243,7 @@ class handle(type):
"type": self.type
}
def has_parent(self, name:str, reg:registry) -> bool:
def has_parent(self, name: str, reg: registry) -> bool:
"""
Recursively check if this type is derived from a given parent type.
"""
@ -266,16 +265,16 @@ class handle(type):
class enum(type):
def __init__(self,node):
def __init__(self, node):
assert node.tag == 'type'
assert node.attrib['category'] == 'enum'
name = node.attrib['name']
super().__init__(name,depends=["VkEnum"])
super().__init__(name, depends=["VkEnum"])
self.values = {}
def __setitem__(self, key:str, value):
def __setitem__(self, key: str, value):
assert isinstance(value, constant) or isinstance(value, aliasvalue)
self.values[key] = value
@ -285,7 +284,7 @@ class enum(type):
"name": self.name
}
def define(self,reg:registry):
def define(self, reg: registry):
values = ("%(name)s = %(value)s" % { "name": k, "value": v.value } for (k,v) in self.values.items())
return "enum %(name)s : int32_t { %(values)s };" % {
@ -311,7 +310,7 @@ class basetype(aliastype):
class funcpointer(type):
def __init__(self,node):
def __init__(self, node):
assert node.tag == 'type'
assert node.attrib['category'] == 'funcpointer'
@ -327,7 +326,7 @@ class funcpointer(type):
class pod(type):
def __init__(self,node):
def __init__(self, node):
assert node.tag == 'type'
assert node.attrib['category'] in ['struct', 'union']
@ -364,7 +363,7 @@ class pod(type):
'name': rename(self.name)
}
def define(self,reg:registry):
def define(self, reg: registry):
return "%(category)s %(name)s {\n%(members)s\n};" % {
'category': self._category,
'name': rename(self.name),
@ -373,17 +372,17 @@ class pod(type):
class struct(pod):
def __init__(self,node):
def __init__(self, node):
super().__init__(node)
class union(pod):
def __init__(self,node):
def __init__(self, node):
super().__init__(node)
class constant(type):
def __init__(self,node,**kwargs):
def __init__(self, node, **kwargs):
assert node.tag == 'enum'
name = node.attrib['name']
@ -451,7 +450,7 @@ class command(type):
'params': ", ".join(p.param for p in self.params)
}
def is_instance(self, reg:registry):
def is_instance(self, reg: registry):
assert reg
if not self.params:
@ -501,7 +500,7 @@ class require(object):
else:
raise "Unknown requires node"
def apply(self,reg:registry,extnumber=None):
def apply(self, reg: registry, extnumber=None):
required = []
required += self.depends
@ -549,10 +548,10 @@ class feature(type):
else:
raise "Unhandled feature node"
def define(self, reg:registry):
def define(self, reg: registry):
return "#define %s" % self.name
def apply(self,reg:registry):
def apply(self, reg: registry):
logging.info("Applying feature:", self.name, file=sys.stderr)
result = []
@ -583,7 +582,7 @@ class extension(type):
else:
raise "Unknown extension node"
def apply(self, reg:registry, platform:Set[str]):
def apply(self, reg: registry, platform: Set[str]):
if self.name in reg.applied:
return []
reg.applied.add(self.name)
@ -613,7 +612,7 @@ parse_platforms = ignore_node
parse_tags = ignore_node
def parse_types(reg:registry, root):
def parse_types(reg: registry, root):
assert root.tag == 'types'
for t in root.findall('type'):
@ -662,7 +661,7 @@ def parse_types(reg:registry, root):
##-----------------------------------------------------------------------------
def parse_enums(reg:registry, root):
def parse_enums(reg: registry, root):
assert root.tag == 'enums'
ownername = root.attrib['name']
owner = reg.types[ownername] if ownername != 'API Constants' else reg.types
@ -679,7 +678,7 @@ def parse_enums(reg:registry, root):
##-----------------------------------------------------------------------------
def parse_commands(reg:registry, root):
def parse_commands(reg: registry, root):
assert root.tag == 'commands'
for node in root.findall('./command'):
@ -694,7 +693,7 @@ def parse_commands(reg:registry, root):
##-----------------------------------------------------------------------------
def parse_feature(reg:registry, root):
def parse_feature(reg: registry, root):
assert root.tag == 'feature'
name = node.attrib['name']
@ -705,7 +704,7 @@ def parse_feature(reg:registry, root):
##-----------------------------------------------------------------------------
def parse_extensions(reg:registry, root):
def parse_extensions(reg: registry, root):
assert root.tag == 'extensions'
for node in root.findall('./extension'):
@ -716,7 +715,7 @@ def parse_extensions(reg:registry, root):
###############################################################################
def write_header(path:str, q:List[type]):
def write_header(path: str, q: List[type]):
with open(path, 'w') as dst:
dst.write("#pragma once\n")
@ -768,7 +767,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]):
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)]
@ -815,7 +814,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]):
with open(path, 'w') as dispatch:
dispatch.write("""
#include "../vk.hpp"