From: Mikko Rasa Date: Thu, 10 Oct 2013 12:23:19 +0000 (+0300) Subject: Extract parameter and return type information from gl.xml X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=0a98aafdf8cd59cd6eb5a926d3a31a01d27ffba8;p=libs%2Fgl.git Extract parameter and return type information from gl.xml --- diff --git a/scripts/extgen.py b/scripts/extgen.py index eef6475a..6c0ef8f1 100755 --- a/scripts/extgen.py +++ b/scripts/extgen.py @@ -69,6 +69,8 @@ class Thing: class Function(Thing): def __init__(self, name): Thing.__init__(self, name, Thing.FUNCTION) + self.return_type = "void" + self.params = [] self.typedef = None self.vectorequiv = None @@ -103,7 +105,8 @@ def parse_file(fn): root = doc.documentElement commands = get_nested_elements(root, "commands/command") for cmd in commands: - name = get_text_contents(get_nested_elements(cmd, "proto/name")[0]) + proto = cmd.getElementsByTagName("proto")[0] + name = get_text_contents(proto.getElementsByTagName("name")[0]) func = things.get(name) if not func: func = Function(name) @@ -117,6 +120,19 @@ def parse_file(fn): if vec: func.vectorequiv = vec[0].getAttribute("name") + ptype = proto.getElementsByTagName("ptype") + if ptype: + func.return_type = get_text_contents(ptype[0]) + else: + for c in proto.childNodes: + if c.nodeType==xml.dom.Node.TEXT_NODE and c.data.strip(): + func.return_type = c.data.strip() + break + + params = cmd.getElementsByTagName("param") + for p in params: + func.params.append(get_text_contents(p)) + enums = get_nested_elements(root, "enums/enum") for en in enums: name = en.getAttribute("name") @@ -241,7 +257,7 @@ namespace GL { if funcs or enums: out.write("\n#ifndef GL_%s\n"%ext) for f in funcs: - out.write("typedef int (*%s)(...);\n"%f.typedef) + out.write("typedef %s (*%s)(%s);\n"%(f.return_type, f.typedef, ", ".join(f.params))) if funcs and enums: out.write("\n") for e in enums: