X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=helpers%2Fspec.py;h=401c317b064a3825a1dce2ffbb39507af73e9aa9;hb=fe3791e8f5a5ac034180c2e335f5d75bc4541b49;hp=c4f2df5faf074207a038f76133a88d00ea39a703;hpb=e89a8004d76ff8b743446057475c5855bb5f1e1e;p=apitrace diff --git a/helpers/spec.py b/helpers/spec.py index c4f2df5..401c317 100755 --- a/helpers/spec.py +++ b/helpers/spec.py @@ -30,6 +30,10 @@ import re import optparse +def stderr(x): + sys.stderr.write(str(x) + '\n') + + class Parser: def __init__(self, stream): @@ -92,8 +96,9 @@ class TypemapParser(LineParser): fields = [field.strip() for field in line.split(',')] src = fields[0] dst = fields[3] + if dst != '*': + typemap[src] = dst self.skip_whitespace() - typemap[src] = dst return typemap def match_comment(self): @@ -142,6 +147,11 @@ class SpecParser(LineParser): function_name, arg_names = mo.groups() arg_names = [arg_name.strip() for arg_name in arg_names.split(',') if arg_name.strip()] + extra = '' + if self.get_function_re.match(function_name): + extra += ', sideeffects=False' + function_name = self.prefix + function_name + ret_type = 'Void' arg_types = {} category = None @@ -152,7 +162,7 @@ class SpecParser(LineParser): ret_type = self.parse_type(fields[1]) elif fields[0] == 'param': arg_name, arg_type = fields[1:3] - arg_types[fields[1]] = self.parse_arg(arg_name, arg_type) + arg_types[fields[1]] = self.parse_arg(function_name, arg_name, arg_type) elif fields[0] == 'category': category = fields[1] else: @@ -176,17 +186,21 @@ class SpecParser(LineParser): if self.prefix == 'wgl': constructor = 'StdFunction' else: - constructor = 'glFunction' - extra = '' - if self.get_function_re.match(function_name): - extra += ', sideeffects=False' - print ' %s(%s, "%s%s", [%s]%s),' % (constructor, ret_type, self.prefix, function_name, ', '.join(args), extra) + constructor = 'GlFunction' + + print ' %s(%s, "%s", [%s]%s),' % (constructor, ret_type, function_name, ', '.join(args), extra) array_re = re.compile(r'^array\s+\[(.*)\]$') - def parse_arg(self, arg_name, arg_type): - base_type, inout, kind = arg_type.split(' ', 2) - base_type = self.parse_type(base_type) + string_typemap = { + 'GLchar': 'GLstring', + 'GLcharARB': 'GLstringARB', + } + + def parse_arg(self, function_name, arg_name, arg_type): + orig_type, inout, kind = arg_type.split(' ', 2) + + base_type = self.parse_type(orig_type) if kind == 'value': arg_type = base_type @@ -195,12 +209,25 @@ class SpecParser(LineParser): if inout == 'in': arg_type = 'Const(%s)' % arg_type elif kind.startswith("array"): + arg_type = 'OpaquePointer(%s)' % base_type + mo = self.array_re.match(kind) if mo: - length = mo.group(1) - arg_type = 'Array(%s, "%s")' % (base_type, length) - else: - arg_type = 'OpaquePointer(%s)' % base_type + length = mo.group(1).strip() + if length == '': + try: + arg_type = self.string_typemap[base_type] + except KeyError: + pass + elif length == '1': + arg_type = 'Pointer(%s)' % base_type + elif length.find("COMPSIZE") == -1: + arg_type = 'Array(%s, "%s")' % (base_type, length) + else: + # XXX: Handle COMPSIZE better + length = length.replace("COMPSIZE", "__%s_size" % function_name) + length = length.replace("/", ",") + arg_type = 'Array(%s, "%s")' % (base_type, length) if inout == 'in': arg_type = 'Const(%s)' % arg_type else: @@ -211,15 +238,24 @@ class SpecParser(LineParser): arg = 'Out' + arg return arg - _typemap = { + semantic_typemap = { + 'String': 'CString', + 'Texture': 'GLtexture', + } + + post_typemap = { 'void': 'Void', 'int': 'Int', 'float': 'Float', } def parse_type(self, type): + try: + return self.semantic_typemap[type] + except KeyError: + pass type = self.typemap.get(type, type) - type = self._typemap.get(type, type) + type = self.post_typemap.get(type, type) return type def match_comment(self):