From d922e1d199b882d422e6086d5923cdd9d5d0f16c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 25 Nov 2010 17:14:02 +0000 Subject: [PATCH] Handle ranges. --- glapi.py | 2 +- retrace.py | 19 +++++++++++++++---- stdapi.py | 5 +++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/glapi.py b/glapi.py index b985067..3ec2683 100644 --- a/glapi.py +++ b/glapi.py @@ -132,7 +132,7 @@ glapi.add_functions([ GlFunction(Void, "glCallList", [(GLlist, "list")]), GlFunction(Void, "glCallLists", [(GLsizei, "n"), (GLenum, "type"), (Blob(Const(GLvoid), "__glCallLists_size(n, type)"), "lists")]), # XXX GlFunction(Void, "glDeleteLists", [(GLlist, "list"), (GLsizei, "range")]), # XXX - GlFunction(GLlist, "glGenLists", [(GLsizei, "range")]), # XXX + GlFunction(Handle("list", GLuint, "range"), "glGenLists", [(GLsizei, "range")]), # XXX GlFunction(Void, "glListBase", [(GLuint, "base")]), GlFunction(Void, "glBegin", [(GLenum_mode, "mode")]), GlFunction(Void, "glBitmap", [(GLsizei, "width"), (GLsizei, "height"), (GLfloat, "xorig"), (GLfloat, "yorig"), (GLfloat, "xmove"), (GLfloat, "ymove"), (Blob(Const(GLubyte), "__glBitmap_size(width, height)"), "bitmap")]), diff --git a/retrace.py b/retrace.py index 01ee1a7..a2d30a4 100644 --- a/retrace.py +++ b/retrace.py @@ -136,9 +136,17 @@ class ValueWrapper(stdapi.Visitor): def visit_handle(self, handle, lvalue, rvalue): - print " __%s_map[static_cast<%s>(%s)] = %s;" % (handle.name, handle.type, rvalue, lvalue) - print ' if (verbosity >= 2)' - print ' std::cout << "%s " << static_cast<%s>(%s) << " -> " << %s << "\\n";' % (handle.name, handle.type, rvalue, lvalue) + if handle.range is None: + print " __{handle.name}_map[static_cast<{handle.type}>({rvalue})] = {lvalue};".format(**locals()) + print ' if (verbosity >= 2)' + print ' std::cout << "{handle.name} " << static_cast<{handle.type}>({rvalue}) << " -> " << {lvalue} << "\\n";'.format(**locals()) + else: + i = '__h' + handle.id + print ' for({handle.type} {i} = 0; {i} < {handle.range}; ++{i}) {{'.format(**locals()) + print ' __{handle.name}_map[static_cast<{handle.type}>({rvalue}) + {i}] = {lvalue} + {i};'.format(**locals()) + print ' if (verbosity >= 2)' + print ' std::cout << "{handle.name} " << (static_cast<{handle.type}>({rvalue}) + {i}) << " -> " << ({lvalue} + {i}) << "\\n";'.format(**locals()) + print ' }' def visit_blob(self, blob, lvalue, rvalue): pass @@ -229,8 +237,11 @@ class Retracer: types = api.all_types() handles = [type for type in types if isinstance(type, stdapi.Handle)] + handle_names = set() for handle in handles: - print 'static std::map<%s, %s> __%s_map;' % (handle.type, handle.type, handle.name) + if handle.name not in handle_names: + print 'static std::map<%s, %s> __%s_map;' % (handle.type, handle.type, handle.name) + handle_names.add(handle.name) print print 'unsigned verbosity = 0;' diff --git a/stdapi.py b/stdapi.py index 81a7fe3..8826953 100644 --- a/stdapi.py +++ b/stdapi.py @@ -131,7 +131,7 @@ class Rebuilder(Visitor): def visit_handle(self, handle): type = self.visit(handle.type) - return Handle(handle.name, type) + return Handle(handle.name, type, handle.range) def visit_alias(self, alias): type = self.visit(alias.type) @@ -238,10 +238,11 @@ class Pointer(Type): class Handle(Type): - def __init__(self, name, type): + def __init__(self, name, type, range=None): Type.__init__(self, type.expr, 'P' + type.id) self.name = name self.type = type + self.range = range def visit(self, visitor, *args, **kwargs): return visitor.visit_handle(self, *args, **kwargs) -- 2.7.4