]> git.cworth.org Git - apitrace/commitdiff
Cleanup/remove dead code.
authorJosé Fonseca <jfonseca@vmware.com>
Mon, 29 Nov 2010 16:09:13 +0000 (16:09 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Mon, 29 Nov 2010 16:09:13 +0000 (16:09 +0000)
stdapi.py
trace.py
winapi.py

index e0d1f5445f6d01e05033a43eb36583a438fb0bc5..122b89f84821d099c2d6754169a35925161fdea0 100644 (file)
--- a/stdapi.py
+++ b/stdapi.py
@@ -1,6 +1,6 @@
 ##########################################################################
 #
-# Copyright 2008-2009 VMware, Inc.
+# Copyright 2008-2010 VMware, Inc.
 # All Rights Reserved.
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 import debug
 
 
-all_types = {}
-
-
-class Visitor:
-
-    def visit(self, type, *args, **kwargs):
-        return type.visit(self, *args, **kwargs)
-
-    def visit_void(self, void, *args, **kwargs):
-        raise NotImplementedError
-
-    def visit_literal(self, literal, *args, **kwargs):
-        raise NotImplementedError
-
-    def visit_string(self, string, *args, **kwargs):
-        raise NotImplementedError
-
-    def visit_const(self, const, *args, **kwargs):
-        raise NotImplementedError
-
-    def visit_struct(self, struct, *args, **kwargs):
-        raise NotImplementedError
-
-    def visit_array(self, array, *args, **kwargs):
-        raise NotImplementedError
-
-    def visit_blob(self, blob, *args, **kwargs):
-        raise NotImplementedError
-
-    def visit_enum(self, enum, *args, **kwargs):
-        raise NotImplementedError
-
-    def visit_bitmask(self, bitmask, *args, **kwargs):
-        raise NotImplementedError
-
-    def visit_pointer(self, pointer, *args, **kwargs):
-        raise NotImplementedError
-
-    def visit_handle(self, handle, *args, **kwargs):
-        raise NotImplementedError
-
-    def visit_alias(self, alias, *args, **kwargs):
-        raise NotImplementedError
-
-    def visit_opaque(self, opaque, *args, **kwargs):
-        raise NotImplementedError
-
-    def visit_interface(self, interface, *args, **kwargs):
-        raise NotImplementedError
-
-
-class OnceVisitor(Visitor):
-
-    def __init__(self):
-        self.__visited = set()
-
-    def visit(self, type, *args, **kwargs):
-        if type not in self.__visited:
-            self.__visited.add(type)
-            return type.visit(self, *args, **kwargs)
-        return None
-
-
-class Rebuilder(Visitor):
-
-    def visit_void(self, void):
-        return void
-
-    def visit_literal(self, literal):
-        return literal
-
-    def visit_string(self, string):
-        return string
-
-    def visit_const(self, const):
-        return Const(const.type)
-
-    def visit_struct(self, struct):
-        members = [self.visit(member) for member in struct.members]
-        return Struct(struct.name, members)
-
-    def visit_array(self, array):
-        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
-
-    def visit_bitmask(self, bitmask):
-        type = self.visit(bitmask.type)
-        return Bitmask(type, bitmask.values)
-
-    def visit_pointer(self, pointer):
-        type = self.visit(pointer.type)
-        return Pointer(type)
-
-    def visit_handle(self, handle):
-        type = self.visit(handle.type)
-        return Handle(handle.name, type, handle.range)
-
-    def visit_alias(self, alias):
-        type = self.visit(alias.type)
-        return Alias(alias.expr, type)
-
-    def visit_opaque(self, opaque):
-        return opaque
-
-
 class Type:
 
+    __all = {}
     __seq = 0
 
     def __init__(self, expr, id = ''):
@@ -153,12 +42,12 @@ class Type:
 
         id = id.replace(' ', '_')
         
-        if id in all_types:
+        if id in Type.__all:
             Type.__seq += 1
             id += str(Type.__seq)
         
-        assert id not in all_types
-        all_types[id] = self
+        assert id not in Type.__all
+        Type.__all[id] = self
 
         self.id = id
 
@@ -181,24 +70,6 @@ class _Void(Type):
 Void = _Void()
 
 
-class Concrete(Type):
-
-    def decl(self):
-        print 'static void Dump%s(const %s &value);' % (self.id, self.expr)
-    
-    def impl(self):
-        print 'static void Dump%s(const %s &value) {' % (self.id, self.expr)
-        self._dump("value");
-        print '}'
-        print
-    
-    def _dump(self, instance):
-        raise NotImplementedError
-    
-    def dump(self, instance):
-        print '    Dump%s(%s);' % (self.id, instance)
-    
-
 class Literal(Type):
 
     def __init__(self, expr, format, base=10):
@@ -252,12 +123,12 @@ def ConstPointer(type):
     return Pointer(Const(type))
 
 
-class Enum(Concrete):
+class Enum(Type):
 
     __vid = 0
 
     def __init__(self, name, values):
-        Concrete.__init__(self, name)
+        Type.__init__(self, name)
         self.vid = Enum.__vid
         Enum.__vid += len(values)
         self.values = list(values)
@@ -270,10 +141,10 @@ def FakeEnum(type, values):
     return Enum(type.expr, values)
 
 
-class Bitmask(Concrete):
+class Bitmask(Type):
 
     def __init__(self, type, values):
-        Concrete.__init__(self, type.expr)
+        Type.__init__(self, type.expr)
         self.type = type
         self.values = values
 
@@ -305,10 +176,10 @@ class Blob(Type):
         return visitor.visit_blob(self, *args, **kwargs)
 
 
-class Struct(Concrete):
+class Struct(Type):
 
     def __init__(self, name, members):
-        Concrete.__init__(self, name)
+        Type.__init__(self, name)
         self.name = name
         self.members = members
 
@@ -395,7 +266,7 @@ def StdFunction(*args, **kwargs):
 
 
 def FunctionPointer(type, name, args, **kwargs):
-    # XXX
+    # XXX: We should probably treat function pointers (callbacks or not) in a generic fashion
     return Opaque(name)
 
 
@@ -426,8 +297,6 @@ class Method(Function):
         for index in range(len(self.args)):
             self.args[index].index = index + 1
 
-towrap = []
-
 
 def WrapPointer(type):
     return Pointer(type)
@@ -442,6 +311,7 @@ class String(Type):
     def visit(self, visitor, *args, **kwargs):
         return visitor.visit_string(self, *args, **kwargs)
 
+# C string (i.e., zero terminated)
 CString = String()
 
 
@@ -465,6 +335,115 @@ def OpaqueBlob(type, size):
     return Opaque(type.expr + ' *')
 
 
+class Visitor:
+
+    def visit(self, type, *args, **kwargs):
+        return type.visit(self, *args, **kwargs)
+
+    def visit_void(self, void, *args, **kwargs):
+        raise NotImplementedError
+
+    def visit_literal(self, literal, *args, **kwargs):
+        raise NotImplementedError
+
+    def visit_string(self, string, *args, **kwargs):
+        raise NotImplementedError
+
+    def visit_const(self, const, *args, **kwargs):
+        raise NotImplementedError
+
+    def visit_struct(self, struct, *args, **kwargs):
+        raise NotImplementedError
+
+    def visit_array(self, array, *args, **kwargs):
+        raise NotImplementedError
+
+    def visit_blob(self, blob, *args, **kwargs):
+        raise NotImplementedError
+
+    def visit_enum(self, enum, *args, **kwargs):
+        raise NotImplementedError
+
+    def visit_bitmask(self, bitmask, *args, **kwargs):
+        raise NotImplementedError
+
+    def visit_pointer(self, pointer, *args, **kwargs):
+        raise NotImplementedError
+
+    def visit_handle(self, handle, *args, **kwargs):
+        raise NotImplementedError
+
+    def visit_alias(self, alias, *args, **kwargs):
+        raise NotImplementedError
+
+    def visit_opaque(self, opaque, *args, **kwargs):
+        raise NotImplementedError
+
+    def visit_interface(self, interface, *args, **kwargs):
+        raise NotImplementedError
+
+
+class OnceVisitor(Visitor):
+
+    def __init__(self):
+        self.__visited = set()
+
+    def visit(self, type, *args, **kwargs):
+        if type not in self.__visited:
+            self.__visited.add(type)
+            return type.visit(self, *args, **kwargs)
+        return None
+
+
+class Rebuilder(Visitor):
+
+    def visit_void(self, void):
+        return void
+
+    def visit_literal(self, literal):
+        return literal
+
+    def visit_string(self, string):
+        return string
+
+    def visit_const(self, const):
+        return Const(const.type)
+
+    def visit_struct(self, struct):
+        members = [self.visit(member) for member in struct.members]
+        return Struct(struct.name, members)
+
+    def visit_array(self, array):
+        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
+
+    def visit_bitmask(self, bitmask):
+        type = self.visit(bitmask.type)
+        return Bitmask(type, bitmask.values)
+
+    def visit_pointer(self, pointer):
+        type = self.visit(pointer.type)
+        return Pointer(type)
+
+    def visit_handle(self, handle):
+        type = self.visit(handle.type)
+        return Handle(handle.name, type, handle.range)
+
+    def visit_alias(self, alias):
+        type = self.visit(alias.type)
+        return Alias(alias.expr, type)
+
+    def visit_opaque(self, opaque):
+        return opaque
+
+
 class Collector(Visitor):
     '''Collect.'''
 
index 361fd1614404207923b796923a1a27ecf17c21fd..b7ba9cf8ece74c96274d440aeceac00757b6fff6 100644 (file)
--- a/trace.py
+++ b/trace.py
 import stdapi
 
 
-all_types = {}
-
-
 def interface_wrap_name(interface):
     return "Wrap" + interface.expr
 
+
 class DumpDeclarator(stdapi.OnceVisitor):
     '''Declare helper functions to dump complex types.'''
 
index 5345a0dc5bd62ec527298d7cdf371051a06d1fa5..3777dcbf3c8baab08f5a3818a1b64da977e91f0d 100644 (file)
--- a/winapi.py
+++ b/winapi.py
@@ -151,73 +151,3 @@ IUnknown.methods = (
 )
 
 
-class DllFunction(Function):
-
-    def get_true_pointer(self):
-        ptype = self.pointer_type()
-        pvalue = self.pointer_value()
-        print '    if(!g_hDll) {'
-        print '        g_hDll = LoadLibrary(g_szDll);'
-        print '        if(!g_hDll)'
-        self.fail_impl()
-        print '    }'
-        print '    if(!%s) {' % (pvalue,)
-        print '        %s = (%s)GetProcAddress(g_hDll, "%s");' % (pvalue, ptype, self.name)
-        print '        if(!%s)' % (pvalue,)
-        self.fail_impl()
-        print '    }'
-
-
-class Dll:
-
-    def __init__(self, name):
-        self.name = name
-        self.functions = []
-        if self not in towrap:
-            towrap.append(self)
-
-    def wrap_name(self):
-        return "Wrap" + self.name
-
-    def wrap_pre_decl(self):
-        pass
-
-    def wrap_decl(self):
-        print 'static HINSTANCE g_hDll = NULL;'
-        print 'static TCHAR g_szDll[MAX_PATH] = {0};'
-        print
-        print 'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);'
-        print
-        for function in self.functions:
-            function.wrap_decl()
-        print
-
-    def wrap_impl(self):
-        print r'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {'
-        print r'    switch(fdwReason) {'
-        print r'    case DLL_PROCESS_ATTACH:'
-        print r'        if(!GetSystemDirectory(g_szDll, MAX_PATH))'
-        print r'            return FALSE;'
-        print r'        _tcscat(g_szDll, TEXT("\\%s.dll"));' % self.name
-        print r'        Trace::Open("%s");' % self.name
-        print r'    case DLL_THREAD_ATTACH:'
-        print r'        return TRUE;'
-        print r'    case DLL_THREAD_DETACH:'
-        print r'        return TRUE;'
-        print r'    case DLL_PROCESS_DETACH:'
-        print r'        Trace::Close();'
-        print r'        if(g_hDll) {'
-        print r'            FreeLibrary(g_hDll);'
-        print r'            g_hDll = NULL;'
-        print r'        }'
-        print r'        return TRUE;'
-        print r'    }'
-        print r'    (void)hinstDLL;'
-        print r'    (void)lpvReserved;'
-        print r'    return TRUE;'
-        print r'}'
-        print
-        for function in self.functions:
-            function.wrap_impl()
-        print
-