@@ -161,7 +161,9 @@ def rec_comprehension(self, scope, code, iter, pc, accu, ctype, stmt):
161
161
assert type == "for" or type == "where" , type
162
162
163
163
if type == "for" :
164
- (var , var2 , expr ) = rest
164
+ (var , var2 , expr , start , stop ) = rest
165
+ if ctype == "for" :
166
+ stmt = self .range (start , stop )
165
167
166
168
self .define (scope , var )
167
169
if var2 != None :
@@ -188,8 +190,11 @@ def rec_comprehension(self, scope, code, iter, pc, accu, ctype, stmt):
188
190
189
191
else :
190
192
assert type == "where"
191
- negate = isinstance (rest , NaryAST ) and rest .op [0 ] == "not"
192
- cond = rest .args [0 ] if negate else rest
193
+ (expr , start , stop ) = rest
194
+ if ctype == "for" :
195
+ stmt = self .range (start , stop )
196
+ negate = isinstance (expr , NaryAST ) and expr .op [0 ] == "not"
197
+ cond = expr .args [0 ] if negate else expr
193
198
cond .compile (scope , code , stmt )
194
199
code .append (JumpCondOp (negate , pc ), self .token , self .endtoken , stmt = stmt )
195
200
self .rec_comprehension (scope , code , iter [1 :], pc , accu , ctype , stmt )
@@ -971,16 +976,17 @@ def accept_visitor(self, visitor, *args, **kwargs):
971
976
972
977
973
978
class BlockAST (AST ):
974
- def __init__ (self , endtoken , token , atomically , b ):
979
+ def __init__ (self , endtoken , token , atomically , b , colon ):
975
980
AST .__init__ (self , endtoken , token , atomically )
976
981
assert len (b ) > 0
977
982
self .b = b
983
+ self .colon = colon
978
984
979
985
def __repr__ (self ):
980
986
return "Block(" + str (self .b ) + ")"
981
987
982
988
def compile (self , scope , code , stmt ):
983
- stmt = self .stmt ( )
989
+ stmt = self .range ( self . token , self . colon )
984
990
ns = Scope (scope )
985
991
for s in self .b :
986
992
for ((lexeme , file , line , column ), lb ) in s .getLabels ():
@@ -1063,16 +1069,17 @@ def accept_visitor(self, visitor, *args, **kwargs):
1063
1069
1064
1070
1065
1071
class WhileAST (AST ):
1066
- def __init__ (self , endtoken , token , atomically , cond , stat ):
1072
+ def __init__ (self , endtoken , token , atomically , cond , stat , colon ):
1067
1073
AST .__init__ (self , endtoken , token , atomically )
1068
1074
self .cond = cond
1069
1075
self .stat = stat
1076
+ self .colon = colon
1070
1077
1071
1078
def __repr__ (self ):
1072
1079
return "While(" + str (self .cond ) + ", " + str (self .stat ) + ")"
1073
1080
1074
1081
def compile (self , scope , code , stmt ):
1075
- stmt = self .stmt ( )
1082
+ stmt = self .range ( self . token , self . colon )
1076
1083
if self .atomically :
1077
1084
code .append (AtomicIncOp (True ), self .atomically , self .atomically , stmt = stmt )
1078
1085
negate = isinstance (self .cond , NaryAST ) and self .cond .op [0 ] == "not"
@@ -1143,7 +1150,8 @@ def compile(self, scope, code, stmt):
1143
1150
if self .atomically :
1144
1151
code .append (AtomicIncOp (True ), self .atomically , self .atomically , stmt = stmt )
1145
1152
ns = Scope (scope )
1146
- for (var , expr , token , op ) in self .vars :
1153
+ for (var , expr , token , endtoken , op ) in self .vars :
1154
+ stmt = self .range (token , endtoken )
1147
1155
expr .compile (ns , code , stmt )
1148
1156
code .append (StoreVarOp (var ), token , op , stmt = stmt )
1149
1157
self .define (ns , var )
@@ -1321,15 +1329,16 @@ def accept_visitor(self, visitor, *args, **kwargs):
1321
1329
1322
1330
1323
1331
class AtomicAST (AST ):
1324
- def __init__ (self , endtoken , token , atomically , stat ):
1332
+ def __init__ (self , endtoken , token , atomically , stat , colon ):
1325
1333
AST .__init__ (self , endtoken , token , atomically )
1326
1334
self .stat = stat
1335
+ self .colon = colon
1327
1336
1328
1337
def __repr__ (self ):
1329
1338
return "Atomic(" + str (self .stat ) + ")"
1330
1339
1331
1340
def compile (self , scope , code , stmt ):
1332
- stmt = self .stmt ( )
1341
+ stmt = self .range ( self . atomically , self . colon )
1333
1342
code .append (AtomicIncOp (True ), self .atomically , self .atomically , stmt = stmt )
1334
1343
self .stat .compile (scope , code , stmt )
1335
1344
code .append (AtomicDecOp (), self .atomically , self .endtoken , stmt = stmt )
0 commit comments