2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-26 03:38:25 +08:00

Convert Slice into typed SliceT.

This commit is contained in:
whitequark 2015-07-16 14:53:24 +03:00
parent 53fb03d1bf
commit e9416f4707
3 changed files with 16 additions and 2 deletions

View File

@ -36,6 +36,9 @@ class ExceptHandlerT(ast.ExceptHandler):
_fields = ("filter", "name", "body") # rename ast.ExceptHandler.type
_types = ("name_type",)
class SliceT(ast.Slice, commontyped):
pass
class AttributeT(ast.Attribute, commontyped):
pass
class BinOpT(ast.BinOp, commontyped):

View File

@ -276,6 +276,15 @@ class ASTTypedRewriter(algorithm.Transformer):
dot_loc=node.dot_loc, attr_loc=node.attr_loc, loc=node.loc)
return self.visit(node)
def visit_Slice(self, node):
node = self.generic_visit(node)
node = asttyped.SliceT(type=types.TVar(),
lower=node.lower, upper=node.upper, step=node.step,
bound_colon_loc=node.bound_colon_loc,
step_colon_loc=node.step_colon_loc,
loc=node.loc)
return self.visit(node)
def visit_Subscript(self, node):
node = self.generic_visit(node)
node = asttyped.SubscriptT(type=types.TVar(),

View File

@ -119,10 +119,12 @@ class Inferencer(algorithm.Visitor):
self._unify(value.type, builtins.TInt(),
value.loc, None)
def visit_Slice(self, node):
def visit_SliceT(self, node):
self._unify(node.type, builtins.TInt(),
node.loc, None)
for operand in (node.lower, node.upper, node.step):
if operand is not None:
self._unify(operand.type, builtins.TInt(),
self._unify(operand.type, node.type,
operand.loc, None)
def visit_ExtSlice(self, node):