It expects a previously declared JSONWriter instance named "json".'''
def visit_literal(self, literal, instance):
- if literal.format == 'Bool':
+ if literal.kind == 'Bool':
print ' json.writeBool(%s);' % instance
- elif literal.format in ('SInt', 'Uint', 'Float', 'Double'):
+ elif literal.kind in ('SInt', 'Uint', 'Float', 'Double'):
print ' json.writeNumber(%s);' % instance
else:
raise NotImplementedError
class ValueExtractor(stdapi.Visitor):
def visit_literal(self, literal, lvalue, rvalue):
- #if literal.format in ('Bool', 'UInt'):
- print ' %s = (%s).to%s();' % (lvalue, rvalue, literal.format)
+ print ' %s = (%s).to%s();' % (lvalue, rvalue, literal.kind)
def visit_const(self, const, lvalue, rvalue):
self.visit(const.type, lvalue, rvalue)
class Literal(Type):
+ """Class to describe literal types.
- def __init__(self, expr, format):
+ Types which are not defined in terms of other types, such as integers and
+ floats."""
+
+ def __init__(self, expr, kind):
Type.__init__(self, expr)
- self.format = format
+ self.kind = kind
def visit(self, visitor, *args, **kwargs):
return visitor.visit_literal(self, *args, **kwargs)
WORD = Alias("WORD", UInt16)
DWORD = Alias("DWORD", UInt32)
-WCHAR = Literal("WCHAR", "SInt")
+WCHAR = Alias("WCHAR", Short)
BOOL = Alias("BOOL", Bool)
'''Dump an instance.'''
def visit_literal(self, literal, instance):
- print ' Trace::localWriter.write%s(%s);' % (literal.format, instance)
+ print ' Trace::localWriter.write%s(%s);' % (literal.kind, instance)
def visit_string(self, string, instance):
if string.length is not None: