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
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(self, visitor, *args, **kwargs):
raise NotImplementedError
- def isoutput(self):
- return False
-
def decl(self):
pass
def __init__(self, type):
- if isinstance(type, Pointer):
+ if type.expr.startswith("const "):
expr = type.expr + " const"
else:
expr = "const " + type.expr
return Pointer(Const(type))
-class OutPointer(Pointer):
-
- def isoutput(self):
- return True
-
-
class Enum(Concrete):
def __init__(self, name, values):
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
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):
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:
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
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 += ")"
raise NotImplementedError
def exit_impl(self):
- print ' ExitProcess(0);'
+ print ' Log::Abort();'
def fail_impl(self):
if self.fail is not None:
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")
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")
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")