]> git.cworth.org Git - apitrace/blobdiff - trace.py
Generate more compact switch statements for polymorphic types.
[apitrace] / trace.py
index 59e1a831e8cb084fad5f3a794676b22f462a6ba4..9cc2b0a77a3e746c424d05aae3f84c13af0a0fe1 100644 (file)
--- a/trace.py
+++ b/trace.py
@@ -135,6 +135,9 @@ class DumpDeclarator(stdapi.OnceVisitor):
         print "};"
         print
 
+    def visit_polymorphic(self, polymorphic):
+        pass
+
 
 class DumpImplementer(stdapi.Visitor):
     '''Dump an instance.'''
@@ -202,6 +205,15 @@ class DumpImplementer(stdapi.Visitor):
     def visit_interface(self, interface, instance):
         print '    Trace::localWriter.writeOpaque((const void *)&%s);' % instance
 
+    def visit_polymorphic(self, polymorphic, instance):
+        print '    switch (%s) {' % polymorphic.switch_expr
+        for cases, type in polymorphic.iterswitch():
+            for case in cases:
+                print '    %s:' % case
+            self.visit(type, 'static_cast<%s>(%s)' % (type, instance));
+            print '        break;'
+        print '    }'
+
 
 dump_instance = DumpImplementer().visit
 
@@ -259,6 +271,10 @@ class Wrapper(stdapi.Visitor):
         print "    if (%s) {" % instance
         print "        %s = new %s(%s);" % (instance, interface_wrap_name(interface), instance)
         print "    }"
+    
+    def visit_polymorphic(self, type, instance):
+        # XXX: There might be polymorphic values that need wrapping in the future
+        pass
 
 
 class Unwrapper(Wrapper):