]> git.cworth.org Git - apitrace/blobdiff - base.py
Abstract process termination.
[apitrace] / base.py
diff --git a/base.py b/base.py
index 2f2b1d0bd10e041e01c6c3a63c366b94957609e6..4afcb577b94e593c845359fe1e790c83a3033ae5 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,9 +142,6 @@ class Type:
     def visit(self, visitor, *args, **kwargs):
         raise NotImplementedError
 
-    def isoutput(self):
-        return False
-
     def decl(self):
         pass
 
@@ -200,7 +204,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,12 +252,6 @@ def ConstPointer(type):
     return Pointer(Const(type))
 
 
-class OutPointer(Pointer):
-
-    def isoutput(self):
-        return True
-
-
 class Enum(Concrete):
 
     def __init__(self, name, values):
@@ -308,7 +306,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 +330,18 @@ class Array(Type):
         self.type.wrap_instance("*" + instance)
 
 
-class OutArray(Array):
+class Blob(Type):
 
-    def isoutput(self):
-        return True
+    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 dump(self, instance):
+        print '    Log::LiteralBlob(%s, %s);' % (instance, self.size)
 
 
 class Struct(Concrete):
@@ -370,29 +376,20 @@ class Alias(Type):
         self.type.dump(instance)
 
 
-class Out(Type):
+def Out(type, name):
+    arg = Arg(type, name, output=True)
+    return arg
 
-    def __init__(self, type):
-        Type.__init__(self, type.expr)
-        self.type = type
 
-    def isoutput(self):
-        return True
-
-    def decl(self):
-        self.type.decl()
+class Arg:
 
-    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 __init__(self, type, name, output=False):
+        self.type = type
+        self.name = name
+        self.output = output
 
-    def unwrap_instance(self, instance):
-        self.type.unwrap_instance(instance)
+    def __str__(self):
+        return '%s %s' % (self.type, self.name)
 
 
 class Function:
@@ -400,7 +397,14 @@ class Function:
     def __init__(self, type, name, args, call = '__stdcall', fail = None):
         self.type = type
         self.name = name
-        self.args = args
+
+        self.args = []
+        for arg in args:
+            if isinstance(arg, tuple):
+                arg_type, arg_name = arg
+                arg = Arg(arg_type, arg_name)
+            self.args.append(arg)
+
         self.call = call
         self.fail = fail
 
@@ -417,7 +421,7 @@ class Function:
         s = self.type.expr + ' ' + s
         s += "("
         if self.args:
-            s += ", ".join(["%s %s" % (type, name) for type, name in self.args])
+            s += ", ".join(["%s %s" % (arg.type, arg.name) for arg in self.args])
         else:
             s += "void"
         s += ")"
@@ -440,7 +444,7 @@ class Function:
         raise NotImplementedError
 
     def exit_impl(self):
-        print '            ExitProcess(0);'
+        print '            Log::Abort();'
 
     def fail_impl(self):
         if self.fail is not None:
@@ -463,19 +467,19 @@ class Function:
             result = 'result = '
         self.get_true_pointer()
         print '    Log::BeginCall("%s");' % (self.name)
-        for type, name in self.args:
-            if not type.isoutput():
-                type.unwrap_instance(name)
-                print '    Log::BeginArg("%s", "%s");' % (type, name)
-                type.dump(name)
+        for arg in self.args:
+            if not arg.output:
+                arg.type.unwrap_instance(arg.name)
+                print '    Log::BeginArg("%s", "%s");' % (arg.type, arg.name)
+                arg.type.dump(arg.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():
-                print '    Log::BeginArg("%s", "%s");' % (type, name)
-                type.dump(name)
+        print '    %s%s(%s);' % (result, pvalue, ', '.join([str(arg.name) for arg in self.args]))
+        for arg in self.args:
+            if arg.output:
+                print '    Log::BeginArg("%s", "%s");' % (arg.type, arg.name)
+                arg.type.dump(arg.name)
                 print '    Log::EndArg();'
-                type.wrap_instance(name)
+                arg.type.wrap_instance(arg.name)
         if self.type is not Void:
             print '    Log::BeginReturn("%s");' % self.type
             self.type.dump("result")
@@ -549,19 +553,19 @@ class Interface(Type):
             print '    Log::BeginPointer("%s", (const void *)m_pInstance);' % self.name
             print '    Log::EndPointer();'
             print '    Log::EndArg();'
-            for type, name in method.args:
-                if not type.isoutput():
-                    type.unwrap_instance(name)
-                    print '    Log::BeginArg("%s", "%s");' % (type, name)
-                    type.dump(name)
+            for arg in method.args:
+                if not arg.output:
+                    arg.type.unwrap_instance(arg.name)
+                    print '    Log::BeginArg("%s", "%s");' % (arg.type, arg.name)
+                    arg.type.dump(arg.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():
-                    print '    Log::BeginArg("%s", "%s");' % (type, name)
-                    type.dump(name)
+            print '    %sm_pInstance->%s(%s);' % (result, method.name, ', '.join([str(arg.name) for arg in method.args]))
+            for arg in method.args:
+                if arg.output:
+                    print '    Log::BeginArg("%s", "%s");' % (arg.type, arg.name)
+                    arg.type.dump(arg.name)
                     print '    Log::EndArg();'
-                    type.wrap_instance(name)
+                    arg.type.wrap_instance(arg.name)
             if method.type is not Void:
                 print '    Log::BeginReturn("%s");' % method.type
                 method.type.dump("result")
@@ -620,18 +624,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")