From: Mikko Rasa Date: Tue, 18 Jan 2011 07:32:49 +0000 (+0000) Subject: Unify array and reference print generation X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=6a5b15f6382ca79e2b5f724585d29b73a40e8194;p=gldbg.git Unify array and reference print generation Describe arrays of enums --- diff --git a/flavors/gl/gl.io b/flavors/gl/gl.io index 914ff29..b4bc0a5 100644 --- a/flavors/gl/gl.io +++ b/flavors/gl/gl.io @@ -1,6 +1,6 @@ -enum, int, %s, describe_enum:p.name:'"%s"'%p.type +enum, int, %s, describe_enum boolean, char, %i -bitfield, int, %s, describe_bitfield:p.name:'"%s"'%p.type +bitfield, int, %s, describe_bitfield byte, char, %i ubyte, char, %u short, short, %i diff --git a/source/glprint.c b/source/glprint.c index 6f645a7..dff66f4 100644 --- a/source/glprint.c +++ b/source/glprint.c @@ -119,6 +119,42 @@ static const char *print_array(const char *fmt, const void *data, unsigned elem_ return buffer; } +static const char *print_array_described(const char *(*describe)(GLenum, const char *), const char *categ, const void *data, unsigned elem_size, unsigned count) +{ + char *buffer; + unsigned buf_size; + char *ptr; + unsigned i; + + if(!data) + return NULL; + + count /= elem_size; + buf_size = count*50; + buffer = tmpalloc(buf_size); + ptr = buffer; + *ptr++ = '{'; + for(i=0; i0) + { + *ptr++ = ','; + *ptr++ = ' '; + } + memcpy(&element, (const char *)data+i*elem_size, elem_size); + len = snprintf(ptr, buf_size, "%s", describe(element, categ)); + ptr += len; + buf_size -= len; + } + *ptr++ = '}'; + *ptr = 0; + + return buffer; +} + static const char *print_data(const void *data, unsigned size) { if(!data) diff --git a/source/glprint.funcs.t b/source/glprint.funcs.t index d98f6e7..5f703e1 100644 --- a/source/glprint.funcs.t +++ b/source/glprint.funcs.t @@ -14,12 +14,9 @@ for p in params: w(', ') if p.kind=="value": w('%s', p.io[1]) - elif p.kind=="reference": - if p.io: - w('{%s}', p.io[1]) - else: - w('', p.type) - elif p.kind=="array": + elif p.kind=="reference" and not p.io: + w('', p.type) + else: w('%%s') first = False w(')') @@ -30,25 +27,19 @@ for p in params+[ret]: if p.ctype!="void": if p.kind=="value": if len(p.io)>=3 and p.io[2]: - f = p.io[2].split(':') - w(', %s(%s)', f[0], ", ".join(eval(x) for x in f[1:])) - else: - w(', %s', p.name) - elif p.kind=="reference": - if p.io: - w(', *%s', p.name) + w(', %s(%s, "%s")', p.io[2], p.name, p.type) else: w(', %s', p.name) - elif p.kind=="array": - if not p.csize: - w(', print_data(%s, 0)', p.name) - elif p.base_ctype=="GLvoid" or p.base_ctype=="void": - w(', print_data(%s, %s)', p.name, p.csize) - else: - f = p.io[1] - if len(p.io)>=3 and p.io[2]: - f = "%x" - w(', print_array("%s", %s, sizeof(%s), %s)', f, p.name, p.base_ctype, p.csize) + elif p.kind=="reference" and not p.io: + w(', %s', p.name) + elif not p.csize: + w(', print_data(%s, 0)', p.name) + elif p.base_ctype=="GLvoid" or p.base_ctype=="void": + w(', print_data(%s, %s)', p.name, p.csize) + elif len(p.io)>=3 and p.io[2]: + w(', print_array_described(%s, "%s", %s, sizeof(%s), %s)', p.io[2], p.type, p.name, p.base_ctype, p.csize) + else: + w(', print_array("%s", %s, sizeof(%s), %s)', p.io[1], p.name, p.base_ctype, p.csize) wl(');') wl('}') :static void init_print(GlDecoder *dec)