import optparse
+def stderr(x):
+ sys.stderr.write(str(x) + '\n')
+
+
class Parser:
def __init__(self, stream):
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):
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
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:
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+\[(.*)\]$')
+
+ 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)
- def parse_arg(self, arg_name, arg_type):
- base_type, inout, kind = arg_type.split(' ', 2)
- base_type = self.parse_type(base_type)
if kind == 'value':
arg_type = base_type
elif kind == 'reference':
+ arg_type = 'Pointer(%s)' % base_type
if inout == 'in':
- arg_type = 'Const(Pointer(%s))' % base_type
- elif inout == 'out':
- arg_type = 'Pointer(%s)' % base_type
- else:
- assert False
+ 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).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(Array(%s))' % base_type
- elif inout == 'out':
- arg_type = 'Array(%s)' % base_type
- else:
- assert False
+ arg_type = 'Const(%s)' % arg_type
+ else:
+ assert False
arg = '(%s, "%s")' % (arg_type, arg_name)
if inout == 'out':
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):