1.1 --- a/common.py Tue Aug 30 17:25:15 2016 +0200
1.2 +++ b/common.py Tue Aug 30 19:09:42 2016 +0200
1.3 @@ -465,121 +465,6 @@
1.4 self.next_iterator()
1.5 self.process_structure_node(node)
1.6
1.7 - def convert_ifexp_node(self, n):
1.8 -
1.9 - """
1.10 - Convert the given if expression node 'n'. An if expression is considered
1.11 - as mapping to a function body containing an if statement as follows:
1.12 -
1.13 - <expr> if <test> else <altexpr>
1.14 -
1.15 - lambda <argnames>:
1.16 - if <test>:
1.17 - return <expr>
1.18 - else:
1.19 - return <altexpr>
1.20 -
1.21 - The <argnames> are populated with defaults after the node has been
1.22 - processed.
1.23 - """
1.24 -
1.25 - node = compiler.ast.Lambda(
1.26 - [], [], 0,
1.27 - compiler.ast.If([
1.28 - (n.test, compiler.ast.Return(n.then))
1.29 - ],
1.30 - compiler.ast.Return(n.else_)
1.31 - ))
1.32 -
1.33 - return node
1.34 -
1.35 - def convert_listcomp_node(self, n):
1.36 -
1.37 - """
1.38 - Convert the given list comprehension node 'n'. A list comprehension is
1.39 - considered as mapping to a function body containing a for loop as
1.40 - follows:
1.41 -
1.42 - [<expr> for <varexpr1> in <list1> if <ifexpr1> for <varexpr2> in <list2> if <ifexpr2> if <ifexpr3>]
1.43 -
1.44 - lambda <argnames>:
1.45 - <result> = []
1.46 - for <varexpr1> in <list1>:
1.47 - if <ifexpr1>:
1.48 - for <varexpr2> in <list2>:
1.49 - if <ifexpr2>:
1.50 - if <ifexpr3>:
1.51 - <result>.append(<expr>)
1.52 - return <result>
1.53 -
1.54 - The <argnames> are populated with defaults after the node has been
1.55 - processed.
1.56 - """
1.57 -
1.58 - temp = "$tr"
1.59 -
1.60 - node = compiler.ast.Lambda(
1.61 - [], [], 0,
1.62 - compiler.ast.Stmt([
1.63 -
1.64 - # <result> = []
1.65 -
1.66 - compiler.ast.Assign([compiler.ast.AssName(temp, "OP_ASSIGN")],
1.67 - compiler.ast.List([])
1.68 - ),
1.69 -
1.70 - # for ...
1.71 -
1.72 - self.convert_listcomp_for_node(n.quals[0], n.quals[1:], n.expr, temp),
1.73 -
1.74 - # return <result>
1.75 -
1.76 - compiler.ast.Return(compiler.ast.Name(temp))
1.77 - ]))
1.78 -
1.79 - return node
1.80 -
1.81 - def convert_listcomp_for_node(self, loop, following_loops, expr, temp):
1.82 -
1.83 - """
1.84 - Return a node representing 'loop', encapsulating 'following_loops' and
1.85 - employing 'expr' in the innermost loop body appending to 'temp'.
1.86 - """
1.87 -
1.88 - if loop.ifs:
1.89 - body = self.convert_listcomp_if_node(loop.ifs[0], loop.ifs[1:], following_loops, expr, temp)
1.90 - elif following_loops:
1.91 - body = self.convert_listcomp_for_node(following_loops[0], following_loops[1:], expr, temp)
1.92 - else:
1.93 - body = self.convert_listcomp_body_node(expr, temp)
1.94 -
1.95 - return compiler.ast.For(loop.assign, loop.list, compiler.ast.Stmt([body]), None)
1.96 -
1.97 - def convert_listcomp_if_node(self, if_, following_ifs, following_loops, expr, temp):
1.98 -
1.99 - """
1.100 - Return a node representing 'if_', encapsulating the 'following_ifs' and
1.101 - 'following_loops' and employing 'expr' in the innermost loop body
1.102 - appending to 'temp'.
1.103 - """
1.104 -
1.105 - if following_ifs:
1.106 - body = self.convert_listcomp_if_node(following_ifs[0], following_ifs[1:], following_loops, expr, temp)
1.107 - elif following_loops:
1.108 - body = self.convert_listcomp_for_node(following_loops[0], following_loops[1:], expr, temp)
1.109 - else:
1.110 - body = self.convert_listcomp_body_node(expr, temp)
1.111 -
1.112 - return compiler.ast.If([(if_.test, compiler.ast.Stmt([body]))], None)
1.113 -
1.114 - def convert_listcomp_body_node(self, expr, temp):
1.115 -
1.116 - "Return a node appending 'expr' to 'temp'."
1.117 -
1.118 - return compiler.ast.Discard(
1.119 - compiler.ast.CallFunc(
1.120 - compiler.ast.Getattr(compiler.ast.Name(temp), "append"), [expr]))
1.121 -
1.122 def process_literal_sequence_node(self, n, name, ref, cls):
1.123
1.124 """
2.1 --- a/inspector.py Tue Aug 30 17:25:15 2016 +0200
2.2 +++ b/inspector.py Tue Aug 30 19:09:42 2016 +0200
2.3 @@ -22,6 +22,7 @@
2.4
2.5 from branching import BranchTracker
2.6 from common import *
2.7 +from errors import InspectError
2.8 from modules import *
2.9 from os import listdir
2.10 from os.path import extsep, split, splitext
2.11 @@ -582,13 +583,16 @@
2.12 elif isinstance(n, compiler.ast.Tuple):
2.13 return self.get_literal_instance(n, "tuple")
2.14
2.15 - # List comprehensions and if expressions.
2.16 + # Unsupported nodes.
2.17 +
2.18 + elif isinstance(n, compiler.ast.GenExpr):
2.19 + raise InspectError("Generator expressions are not supported.", self.get_namespace_path(), n)
2.20 +
2.21 + elif isinstance(n, compiler.ast.IfExp):
2.22 + raise InspectError("If-else expressions are not supported.", self.get_namespace_path(), n)
2.23
2.24 elif isinstance(n, compiler.ast.ListComp):
2.25 - self.process_listcomp_node(n)
2.26 -
2.27 - elif isinstance(n, compiler.ast.IfExp):
2.28 - self.process_ifexp_node(n)
2.29 + raise InspectError("List comprehensions are not supported.", self.get_namespace_path(), n)
2.30
2.31 # All other nodes are processed depth-first.
2.32
2.33 @@ -987,18 +991,6 @@
2.34
2.35 tracker.merge_branches()
2.36
2.37 - def process_ifexp_node(self, n):
2.38 -
2.39 - "Process the given if expression node 'n'."
2.40 -
2.41 - name_ref = self.process_structure_node(self.convert_ifexp_node(n))
2.42 -
2.43 - path = self.get_namespace_path()
2.44 - self.allocate_arguments(path, self.function_defaults[name_ref.get_origin()])
2.45 - self.deallocate_arguments(path, self.function_defaults[name_ref.get_origin()])
2.46 -
2.47 - return InvocationRef(name_ref)
2.48 -
2.49 def process_import_node(self, n):
2.50
2.51 "Process the given import node 'n'."
2.52 @@ -1060,18 +1052,6 @@
2.53 origin = self.get_object_path(name)
2.54 return ResolvedNameRef(name, Reference("<function>", origin))
2.55
2.56 - def process_listcomp_node(self, n):
2.57 -
2.58 - "Process the given list comprehension node 'n'."
2.59 -
2.60 - name_ref = self.process_structure_node(self.convert_listcomp_node(n))
2.61 -
2.62 - path = self.get_namespace_path()
2.63 - self.allocate_arguments(path, self.function_defaults[name_ref.get_origin()])
2.64 - self.deallocate_arguments(path, self.function_defaults[name_ref.get_origin()])
2.65 -
2.66 - return InvocationRef(name_ref)
2.67 -
2.68 def process_logical_node(self, n):
2.69
2.70 "Process the given operator node 'n'."