]> git.cworth.org Git - apitrace/blobdiff - specs/stdapi.py
Allow basic specification of polymorphic types.
[apitrace] / specs / stdapi.py
index d6973c11073c7eb2769f5f701647ada4cec807d6..1b9bf58ad5f5ab0f4b6cb57f5f6f275048e3f628 100644 (file)
@@ -305,10 +305,6 @@ class Method(Function):
             self.args[index].index = index + 1
 
 
-def WrapPointer(type):
-    return Pointer(type)
-
-
 class String(Type):
 
     def __init__(self, expr = "char *", length = None):
@@ -342,6 +338,18 @@ def OpaqueBlob(type, size):
     return Opaque(type.expr + ' *')
 
 
+class Polymorphic(Type):
+
+    def __init__(self, default_type, switch_expr, switch_types):
+        Type.__init__(self, default_type.expr)
+        self.default_type = default_type
+        self.switch_expr = switch_expr
+        self.switch_types = switch_types
+
+    def visit(self, visitor, *args, **kwargs):
+        return visitor.visit_polymorphic(self, *args, **kwargs)
+
+
 class Visitor:
 
     def visit(self, type, *args, **kwargs):
@@ -389,6 +397,10 @@ class Visitor:
     def visit_interface(self, interface, *args, **kwargs):
         raise NotImplementedError
 
+    def visit_polymorphic(self, polymorphic, *args, **kwargs):
+        raise NotImplementedError
+        #return self.visit(polymorphic.default_type, *args, **kwargs)
+
 
 class OnceVisitor(Visitor):
 
@@ -450,6 +462,12 @@ class Rebuilder(Visitor):
     def visit_opaque(self, opaque):
         return opaque
 
+    def visit_polymorphic(self, polymorphic):
+        default_type = self.visit(polymorphic.default_type)
+        switch_expr = polymorphic.switch_expr
+        switch_types = [(expr, self.visit(type)) for expr, type in polymorphic.switch_types]
+        return Polymorphic(default_type, switch_expr, switch_types)
+
 
 class Collector(Visitor):
     '''Collect.'''
@@ -513,6 +531,11 @@ class Collector(Visitor):
                 self.visit(arg.type)
             self.visit(method.type)
 
+    def visit_polymorphic(self, polymorphic):
+        self.visit(polymorphic.default_type)
+        for expr, type in polymorphic.switch_types:
+            self.visit(type)
+
 
 class API: