]> git.cworth.org Git - apitrace/blobdiff - specs/stdapi.py
Adjust D3D9's sideeffect settings.
[apitrace] / specs / stdapi.py
index b9d6c64f5c1d83c834e28b32f75fd893a2b0c7cc..30a42df888794ba543fe3227c57896f0196eb757 100644 (file)
@@ -127,6 +127,25 @@ class Pointer(Type):
         return visitor.visitPointer(self, *args, **kwargs)
 
 
+class IntPointer(Type):
+    '''Integer encoded as a pointer.'''
+
+    def visit(self, visitor, *args, **kwargs):
+        return visitor.visitIntPointer(self, *args, **kwargs)
+
+
+class LinearPointer(Type):
+    '''Integer encoded as a pointer.'''
+
+    def __init__(self, type, size = None):
+        Type.__init__(self, type.expr + " *", 'P' + type.tag)
+        self.type = type
+        self.size = size
+
+    def visit(self, visitor, *args, **kwargs):
+        return visitor.visitLinearPointer(self, *args, **kwargs)
+
+
 class Handle(Type):
 
     def __init__(self, name, type, range=None, key=None):
@@ -298,6 +317,9 @@ class Function:
         s += ")"
         return s
 
+    def argNames(self):
+        return [arg.name for arg in self.args]
+
 
 def StdFunction(*args, **kwargs):
     kwargs.setdefault('call', '__stdcall')
@@ -328,27 +350,40 @@ class Interface(Type):
             yield method
         raise StopIteration
 
+    def iterBaseMethods(self):
+        if self.base is not None:
+            for iface, method in self.base.iterBaseMethods():
+                yield iface, method
+        for method in self.methods:
+            yield self, method
+        raise StopIteration
+
 
 class Method(Function):
 
-    def __init__(self, type, name, args):
-        Function.__init__(self, type, name, args, call = '__stdcall')
+    def __init__(self, type, name, args, const=False, sideeffects=True):
+        Function.__init__(self, type, name, args, call = '__stdcall', sideeffects=sideeffects)
         for index in range(len(self.args)):
             self.args[index].index = index + 1
+        self.const = const
+
+    def prototype(self, name=None):
+        s = Function.prototype(self, name)
+        if self.const:
+            s += ' const'
+        return s
 
 
 class String(Type):
 
-    def __init__(self, expr = "char *", length = None):
+    def __init__(self, expr = "char *", length = None, kind = 'String'):
         Type.__init__(self, expr)
         self.length = length
+        self.kind = kind
 
     def visit(self, visitor, *args, **kwargs):
         return visitor.visitString(self, *args, **kwargs)
 
-# C string (i.e., zero terminated)
-CString = String()
-
 
 class Opaque(Type):
     '''Opaque pointer.'''
@@ -434,6 +469,12 @@ class Visitor:
     def visitPointer(self, pointer, *args, **kwargs):
         raise NotImplementedError
 
+    def visitIntPointer(self, pointer, *args, **kwargs):
+        raise NotImplementedError
+
+    def visitLinearPointer(self, pointer, *args, **kwargs):
+        raise NotImplementedError
+
     def visitHandle(self, handle, *args, **kwargs):
         raise NotImplementedError
 
@@ -505,6 +546,13 @@ class Rebuilder(Visitor):
         type = self.visit(pointer.type)
         return Pointer(type)
 
+    def visitIntPointer(self, pointer):
+        return pointer
+
+    def visitLinearPointer(self, pointer):
+        type = self.visit(pointer.type)
+        return LinearPointer(type, pointer.size)
+
     def visitHandle(self, handle):
         type = self.visit(handle.type)
         return Handle(handle.name, type, range=handle.range, key=handle.key)
@@ -516,6 +564,9 @@ class Rebuilder(Visitor):
     def visitOpaque(self, opaque):
         return opaque
 
+    def visitInterface(self, interface, *args, **kwargs):
+        return interface
+
     def visitPolymorphic(self, polymorphic):
         defaultType = self.visit(polymorphic.defaultType)
         switchExpr = polymorphic.switchExpr
@@ -568,6 +619,12 @@ class Collector(Visitor):
     def visitPointer(self, pointer):
         self.visit(pointer.type)
 
+    def visitIntPointer(self, pointer):
+        pass
+
+    def visitLinearPointer(self, pointer):
+        self.visit(pointer.type)
+
     def visitHandle(self, handle):
         self.visit(handle.type)
 
@@ -603,7 +660,7 @@ class API:
         self.functions = []
         self.interfaces = []
 
-    def all_types(self):
+    def getAllTypes(self):
         collector = Collector()
         for function in self.functions:
             for arg in function.args:
@@ -617,6 +674,14 @@ class API:
                 collector.visit(method.type)
         return collector.types
 
+    def getAllInterfaces(self):
+        types = self.getAllTypes()
+        interfaces = [type for type in types if isinstance(type, Interface)]
+        for interface in self.interfaces:
+            if interface not in interfaces:
+                interfaces.append(interface)
+        return interfaces
+
     def addFunction(self, function):
         self.functions.append(function)
 
@@ -656,7 +721,10 @@ ULongLong = Literal("unsigned long long", "UInt")
 Float = Literal("float", "Float")
 Double = Literal("double", "Double")
 SizeT = Literal("size_t", "UInt")
-WString = Literal("wchar_t *", "WString")
+
+# C string (i.e., zero terminated)
+CString = String()
+WString = String("wchar_t *", kind="WString")
 
 Int8 = Literal("int8_t", "SInt")
 UInt8 = Literal("uint8_t", "UInt")