forked from M-Labs/artiq
Add support for NameConstant.
This commit is contained in:
parent
eb76f594a0
commit
d08598fa0f
@ -155,6 +155,10 @@ class TValue(Type):
|
||||
def __ne__(self, other):
|
||||
return not (self == other)
|
||||
|
||||
def TNone():
|
||||
"""The type of None."""
|
||||
return TMono("NoneType")
|
||||
|
||||
def TBool():
|
||||
"""A boolean type."""
|
||||
return TMono("bool")
|
||||
@ -193,8 +197,11 @@ class TypePrinter(object):
|
||||
self.map[typ] = "'%s" % next(self.gen)
|
||||
return self.map[typ]
|
||||
elif isinstance(typ, TMono):
|
||||
return "%s(%s)" % (typ.name, ", ".join(
|
||||
["%s=%s" % (k, self.name(typ.params[k])) for k in typ.params]))
|
||||
if typ.params == {}:
|
||||
return typ.name
|
||||
else:
|
||||
return "%s(%s)" % (typ.name, ", ".join(
|
||||
["%s=%s" % (k, self.name(typ.params[k])) for k in typ.params]))
|
||||
elif isinstance(typ, TTuple):
|
||||
if len(typ.elts) == 1:
|
||||
return "(%s,)" % self.name(typ.elts[0])
|
||||
|
@ -215,6 +215,13 @@ class Inferencer(algorithm.Transformer):
|
||||
return asttyped.NameT(type=self._find_name(node.id, node.loc),
|
||||
id=node.id, ctx=node.ctx, loc=node.loc)
|
||||
|
||||
def visit_NameConstant(self, node):
|
||||
if node.value is True or node.value is False:
|
||||
typ = types.TBool()
|
||||
elif node.value is None:
|
||||
typ = types.TNone()
|
||||
return asttyped.NameConstantT(type=typ, value=node.value, loc=node.loc)
|
||||
|
||||
def visit_Tuple(self, node):
|
||||
node = self.generic_visit(node)
|
||||
return asttyped.TupleT(type=types.TTuple([x.type for x in node.elts]),
|
||||
@ -303,7 +310,7 @@ class Printer(algorithm.Visitor):
|
||||
def generic_visit(self, node):
|
||||
if hasattr(node, "type"):
|
||||
self.rewriter.insert_after(node.loc,
|
||||
":%s".format(self.type_printer.name(node.type)))
|
||||
":{}".format(self.type_printer.name(node.type)))
|
||||
|
||||
super().generic_visit(node)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user