1.1 --- a/micropython/inspect.py Mon Nov 10 21:38:58 2008 +0100
1.2 +++ b/micropython/inspect.py Mon Nov 10 23:57:05 2008 +0100
1.3 @@ -314,6 +314,23 @@
1.4 self.dispatch(n)
1.5 return Instance()
1.6
1.7 + def _visitUnary(self, node):
1.8 +
1.9 + "Accounting method for the unary operator 'node'."
1.10 +
1.11 + method = unary_methods[node.__class__.__name__]
1.12 + self.importer.use_name(method)
1.13 + return self.OP(node)
1.14 +
1.15 + def _visitBinary(self, node):
1.16 +
1.17 + "Accounting method for the binary operator 'node'."
1.18 +
1.19 + left_method, right_method = binary_methods[node.__class__.__name__]
1.20 + self.importer.use_name(left_method)
1.21 + self.importer.use_name(right_method)
1.22 + return self.OP(node)
1.23 +
1.24 def _visitFunction(self, node, name):
1.25
1.26 """
1.27 @@ -384,7 +401,9 @@
1.28 self.add_object(function, any_scope=1)
1.29 return function
1.30
1.31 - visitAdd = OP
1.32 + # Specific handler methods.
1.33 +
1.34 + visitAdd = _visitBinary
1.35
1.36 visitAnd = OP
1.37
1.38 @@ -419,15 +438,23 @@
1.39
1.40 visitAssTuple = visitAssList
1.41
1.42 - visitAugAssign = OP
1.43 + def visitAugAssign(self, node):
1.44 +
1.45 + # Accounting.
1.46 +
1.47 + aug_method, (left_method, right_method) = augassign_methods[node.op]
1.48 + self.importer.use_name(aug_method)
1.49 + self.importer.use_name(left_method)
1.50 + self.importer.use_name(right_method)
1.51 + return self.OP(node)
1.52
1.53 visitBackquote = OP
1.54
1.55 - visitBitand = OP
1.56 + visitBitand = _visitBinary
1.57
1.58 - visitBitor = OP
1.59 + visitBitor = _visitBinary
1.60
1.61 - visitBitxor = OP
1.62 + visitBitxor = _visitBinary
1.63
1.64 visitBreak = NOP
1.65
1.66 @@ -485,7 +512,21 @@
1.67
1.68 return cls
1.69
1.70 - visitCompare = OP
1.71 + def visitCompare(self, node):
1.72 +
1.73 + # Accounting.
1.74 + # NOTE: Replicates some code in micropython.ast.visitCompare.
1.75 +
1.76 + for op in node.ops:
1.77 + op_name, next_node = op
1.78 + methods = comparison_methods[op_name]
1.79 + if methods is not None:
1.80 + self.importer.use_name(methods[0])
1.81 + self.importer.use_name(methods[1])
1.82 + elif op_name.endswith("in"):
1.83 + self.importer.use_name("__contains__")
1.84 +
1.85 + return self.OP(node)
1.86
1.87 def visitConst(self, node):
1.88 return self.importer.make_constant(node.value)
1.89 @@ -498,7 +539,7 @@
1.90
1.91 visitDiscard = NOP
1.92
1.93 - visitDiv = OP
1.94 + visitDiv = _visitBinary
1.95
1.96 visitEllipsis = NOP
1.97
1.98 @@ -506,7 +547,7 @@
1.99
1.100 visitExpression = OP
1.101
1.102 - visitFloorDiv = OP
1.103 + visitFloorDiv = _visitBinary
1.104
1.105 def visitFor(self, node):
1.106 self.in_loop = 1
1.107 @@ -613,7 +654,7 @@
1.108
1.109 return None
1.110
1.111 - visitInvert = OP
1.112 + visitInvert = _visitUnary
1.113
1.114 def visitKeyword(self, node):
1.115 self.dispatch(node.expr)
1.116 @@ -624,7 +665,7 @@
1.117 def visitLambda(self, node):
1.118 return self._visitFunction(node, None)
1.119
1.120 - visitLeftShift = OP
1.121 + visitLeftShift = _visitBinary
1.122
1.123 visitList = OP
1.124
1.125 @@ -634,7 +675,7 @@
1.126
1.127 visitListCompIf = NOP
1.128
1.129 - visitMod = OP
1.130 + visitMod = _visitBinary
1.131
1.132 def visitModule(self, node):
1.133
1.134 @@ -643,7 +684,7 @@
1.135 node.unit = self
1.136 return self.dispatch(node.node)
1.137
1.138 - visitMul = OP
1.139 + visitMul = _visitBinary
1.140
1.141 def visitName(self, node):
1.142 name = node.name
1.143 @@ -674,7 +715,7 @@
1.144
1.145 visitPass = NOP
1.146
1.147 - visitPower = OP
1.148 + visitPower = _visitBinary
1.149
1.150 visitPrint = NOP
1.151
1.152 @@ -684,7 +725,7 @@
1.153
1.154 visitReturn = NOP
1.155
1.156 - visitRightShift = OP
1.157 + visitRightShift = _visitBinary
1.158
1.159 visitSlice = OP
1.160
1.161 @@ -695,7 +736,7 @@
1.162 self.dispatch(n)
1.163 return None
1.164
1.165 - visitSub = OP
1.166 + visitSub = _visitBinary
1.167
1.168 visitSubscript = OP
1.169
1.170 @@ -717,9 +758,9 @@
1.171
1.172 visitTuple = OP
1.173
1.174 - visitUnaryAdd = OP
1.175 + visitUnaryAdd = _visitUnary
1.176
1.177 - visitUnarySub = OP
1.178 + visitUnarySub = _visitUnary
1.179
1.180 def visitWhile(self, node):
1.181 self.in_loop = 1