]> git.tdb.fi Git - libs/gl.git/commitdiff
Extract parameter and return type information from gl.xml
authorMikko Rasa <tdb@tdb.fi>
Thu, 10 Oct 2013 12:23:19 +0000 (15:23 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 10 Oct 2013 12:23:19 +0000 (15:23 +0300)
scripts/extgen.py

index eef6475adbdad5506ad39068286e2efa03b3922a..6c0ef8f1799538b8d675c31640628a134c17675b 100755 (executable)
@@ -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: