]> git.notmuchmail.org Git - apitrace/blobdiff - base.py
Simplify output marking.
[apitrace] / base.py
diff --git a/base.py b/base.py
index 2f2b1d0bd10e041e01c6c3a63c366b94957609e6..70e55300f1648d2fde7e3bf22736d5cbca2b4bbc 100644 (file)
--- a/base.py
+++ b/base.py
@@ -54,6 +54,9 @@ class Visitor:
     def visit_array(self, type, *args, **kwargs):
         raise NotImplementedError
 
+    def visit_blob(self, type, *args, **kwargs):
+        raise NotImplementedError
+
     def visit_enum(self, type, *args, **kwargs):
         raise NotImplementedError
 
@@ -89,6 +92,10 @@ class Rebuilder(Visitor):
         type = self.visit(array.type)
         return Array(type, array.length)
 
+    def visit_blob(self, blob):
+        type = self.visit(blob.type)
+        return Blob(type, blob.size)
+
     def visit_enum(self, enum):
         return enum
 
@@ -135,8 +142,7 @@ class Type:
     def visit(self, visitor, *args, **kwargs):
         raise NotImplementedError
 
-    def isoutput(self):
-        return False
+    isoutput = False
 
     def decl(self):
         pass
@@ -200,7 +206,7 @@ class Const(Type):
 
     def __init__(self, type):
 
-        if isinstance(type, Pointer):
+        if type.expr.startswith("const "):
             expr = type.expr + " const"
         else:
             expr = "const " + type.expr
@@ -248,10 +254,8 @@ def ConstPointer(type):
     return Pointer(Const(type))
 
 
-class OutPointer(Pointer):
-
-    def isoutput(self):
-        return True
+def OutPointer(type):
+    return Out(Pointer(type))
 
 
 class Enum(Concrete):
@@ -308,7 +312,7 @@ Flags = Bitmask
 class Array(Type):
 
     def __init__(self, type, length):
-        Type.__init__(self, type.expr + " *", 'P' + type.id)
+        Type.__init__(self, type.expr + " *")
         self.type = type
         self.length = length
 
@@ -332,10 +336,22 @@ class Array(Type):
         self.type.wrap_instance("*" + instance)
 
 
-class OutArray(Array):
+def OutArray(type, length):
+    return Out(Array(type, length))
+
+
+class Blob(Type):
+
+    def __init__(self, type, size):
+        Type.__init__(self, type.expr + ' *')
+        self.type = type
+        self.size = size
+
+    def visit(self, visitor, *args, **kwargs):
+        return visitor.visit_blob(self, *args, **kwargs)
 
-    def isoutput(self):
-        return True
+    def dump(self, instance):
+        print '    Log::LiteralBlob(%s, %s);' % (instance, self.size)
 
 
 class Struct(Concrete):
@@ -370,29 +386,9 @@ class Alias(Type):
         self.type.dump(instance)
 
 
-class Out(Type):
-
-    def __init__(self, type):
-        Type.__init__(self, type.expr)
-        self.type = type
-
-    def isoutput(self):
-        return True
-
-    def decl(self):
-        self.type.decl()
-
-    def impl(self):
-        self.type.impl()
-
-    def dump(self, instance):
-        self.type.dump(instance)
-    
-    def wrap_instance(self, instance):
-        self.type.wrap_instance(instance)
-
-    def unwrap_instance(self, instance):
-        self.type.unwrap_instance(instance)
+def Out(type):
+    type.isoutput = True
+    return type
 
 
 class Function:
@@ -464,14 +460,14 @@ class Function:
         self.get_true_pointer()
         print '    Log::BeginCall("%s");' % (self.name)
         for type, name in self.args:
-            if not type.isoutput():
+            if not type.isoutput:
                 type.unwrap_instance(name)
                 print '    Log::BeginArg("%s", "%s");' % (type, name)
                 type.dump(name)
                 print '    Log::EndArg();'
         print '    %s%s(%s);' % (result, pvalue, ', '.join([str(name) for type, name in self.args]))
         for type, name in self.args:
-            if type.isoutput():
+            if type.isoutput:
                 print '    Log::BeginArg("%s", "%s");' % (type, name)
                 type.dump(name)
                 print '    Log::EndArg();'
@@ -550,14 +546,14 @@ class Interface(Type):
             print '    Log::EndPointer();'
             print '    Log::EndArg();'
             for type, name in method.args:
-                if not type.isoutput():
+                if not type.isoutput:
                     type.unwrap_instance(name)
                     print '    Log::BeginArg("%s", "%s");' % (type, name)
                     type.dump(name)
                     print '    Log::EndArg();'
             print '    %sm_pInstance->%s(%s);' % (result, method.name, ', '.join([str(name) for type, name in method.args]))
             for type, name in method.args:
-                if type.isoutput():
+                if type.isoutput:
                     print '    Log::BeginArg("%s", "%s");' % (type, name)
                     type.dump(name)
                     print '    Log::EndArg();'
@@ -620,18 +616,21 @@ class _String(Type):
 String = _String()
 
 
-class _Opaque(Type):
+class Opaque(Type):
+    '''Opaque pointer.'''
 
-    def __init__(self):
-        Type.__init__(self, "void")
+    def __init__(self, expr):
+        Type.__init__(self, expr)
 
     def visit(self, visitor, *args, **kwargs):
         return visitor.visit_opaque(self, *args, **kwargs)
 
     def dump(self, instance):
-        print '    Log::LiteralOpaque();'
+        print '    Log::LiteralOpaque((const void *)%s);' % instance
+
 
-Opaque = Pointer(_Opaque())
+def OpaquePointer(type):
+    return Opaque(type.expr + ' *')
 
 
 Bool = Literal("bool", "Bool")