artiq/artiq/compiler/asttyped.py

112 lines
2.8 KiB
Python
Raw Normal View History

2015-05-29 14:53:24 +08:00
"""
The typedtree module exports the PythonParser AST enriched with
typing information.
"""
from pythonparser import ast
class commontyped(ast.commonloc):
"""A mixin for typed AST nodes."""
_types = ("type",)
2015-05-29 14:53:24 +08:00
def _reprfields(self):
return self._fields + self._locs + self._types
class scoped(object):
"""
:ivar typing_env: (dict with string keys and :class:`.types.Type` values)
map of variable names to variable types
:ivar globals_in_scope: (set of string keys)
2015-07-18 13:13:49 +08:00
set of variables resolved as globals
2015-05-29 14:53:24 +08:00
"""
2015-06-14 17:07:13 +08:00
# Typed versions of untyped nodes
2015-06-04 19:12:41 +08:00
class argT(ast.arg, commontyped):
2015-05-29 14:53:24 +08:00
pass
class ClassDefT(ast.ClassDef):
_types = ("constructor_type",)
2015-05-29 14:53:24 +08:00
class FunctionDefT(ast.FunctionDef, scoped):
_types = ("signature_type",)
class QuotedFunctionDefT(FunctionDefT):
pass
2015-06-13 14:28:40 +08:00
class ModuleT(ast.Module, scoped):
pass
2015-05-29 14:53:24 +08:00
2015-07-03 02:28:26 +08:00
class ExceptHandlerT(ast.ExceptHandler):
_fields = ("filter", "name", "body") # rename ast.ExceptHandler.type to filter
2015-06-29 05:31:06 +08:00
_types = ("name_type",)
class ForT(ast.For):
"""
:ivar trip_count: (:class:`iodelay.Expr`)
:ivar trip_interval: (:class:`iodelay.Expr`)
"""
class withitemT(ast.withitem):
_types = ("enter_type", "exit_type")
2015-07-16 19:53:24 +08:00
class SliceT(ast.Slice, commontyped):
pass
2015-06-04 19:12:41 +08:00
class AttributeT(ast.Attribute, commontyped):
2015-05-29 14:53:24 +08:00
pass
2015-06-04 19:12:41 +08:00
class BinOpT(ast.BinOp, commontyped):
2015-05-29 14:53:24 +08:00
pass
2015-06-04 19:12:41 +08:00
class BoolOpT(ast.BoolOp, commontyped):
2015-05-29 14:53:24 +08:00
pass
2015-06-04 19:12:41 +08:00
class CallT(ast.Call, commontyped):
2015-11-17 10:16:43 +08:00
"""
:ivar iodelay: (:class:`iodelay.Expr`)
:ivar arg_exprs: (dict of str to :class:`iodelay.Expr`)
2015-11-17 10:16:43 +08:00
"""
2015-06-04 19:12:41 +08:00
class CompareT(ast.Compare, commontyped):
2015-05-29 14:53:24 +08:00
pass
2015-06-04 19:12:41 +08:00
class DictT(ast.Dict, commontyped):
pass
class DictCompT(ast.DictComp, commontyped, scoped):
pass
class EllipsisT(ast.Ellipsis, commontyped):
pass
class GeneratorExpT(ast.GeneratorExp, commontyped, scoped):
pass
class IfExpT(ast.IfExp, commontyped):
pass
class LambdaT(ast.Lambda, commontyped, scoped):
pass
class ListT(ast.List, commontyped):
pass
class ListCompT(ast.ListComp, commontyped, scoped):
2015-05-29 14:53:24 +08:00
pass
class NameT(ast.Name, commontyped):
pass
class NameConstantT(ast.NameConstant, commontyped):
pass
2015-06-04 19:12:41 +08:00
class NumT(ast.Num, commontyped):
pass
class SetT(ast.Set, commontyped):
pass
class SetCompT(ast.SetComp, commontyped, scoped):
pass
class StrT(ast.Str, commontyped):
pass
class StarredT(ast.Starred, commontyped):
pass
class SubscriptT(ast.Subscript, commontyped):
pass
class TupleT(ast.Tuple, commontyped):
pass
class UnaryOpT(ast.UnaryOp, commontyped):
pass
class YieldT(ast.Yield, commontyped):
pass
class YieldFromT(ast.YieldFrom, commontyped):
pass
2015-06-14 17:07:13 +08:00
# Novel typed nodes
class CoerceT(ast.expr, commontyped):
_fields = ('value',) # other_value deliberately not in _fields
class QuoteT(ast.expr, commontyped):
_fields = ('value',)