X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=stdapi.py;h=122b89f84821d099c2d6754169a35925161fdea0;hb=f0d8647e4593ee3b00e679cc8a53a8b348689780;hp=e0d1f5445f6d01e05033a43eb36583a438fb0bc5;hpb=87d1cc6306ee2cfcb214c3216a9fc589158ccaba;p=apitrace diff --git a/stdapi.py b/stdapi.py index e0d1f54..122b89f 100644 --- 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 @@ -29,120 +29,9 @@ 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.'''