@@ -22,7 +22,6 @@ def __init__(self):
22
22
self .scopeframes = []
23
23
self .scopeframes .append (ScopeFrame (ScopeName (('_' ,))))
24
24
self .current = self .scopeframes [0 ]
25
- self .globalframe = self .scopeframes [0 ]
26
25
self .previousframes = OrderedDict ()
27
26
self .previousframes [self .current ] = None
28
27
self .nextframes = OrderedDict ()
@@ -64,65 +63,45 @@ def addVariable(self, name, var):
64
63
targ = self .previousframes [targ ]
65
64
return None
66
65
67
- def addNonlocal (self , name ):
68
- if self .current is None :
69
- return None
70
- targ = self .current
71
- while targ is not None :
72
- if targ .ftype == 'call' :
73
- targ .addNonlocal (name )
74
- break
75
- targ = self .previousframes [targ ]
76
- return None
77
-
78
- def addGlobal (self , name ):
79
- if self .current is None :
80
- return None
81
- targ = self .current
82
- while targ is not None :
83
- if targ .ftype == 'call' :
84
- targ .addGlobal (name )
85
- break
86
- targ = self .previousframes [targ ]
87
- return None
88
-
89
66
def addFunction (self , func ):
90
67
self .current .addFunction (func )
91
68
92
69
def searchVariable (self , name , store = False ):
93
70
if self .current is None :
94
71
return None
72
+
95
73
targ = self .current
96
- is_global = False
74
+
97
75
while targ is not None :
98
76
ret = targ .searchVariable (name )
99
77
if ret is not None :
100
78
return ret
79
+
80
+ ret = targ .searchFunction (name )
81
+ if ret is not None :
82
+ return ret
83
+
101
84
if targ .ftype == 'call' :
102
- ret = targ .searchNonlocal (name )
103
- if ret :
104
- continue
105
- ret = targ .searchGlobal (name )
106
- if ret :
107
- is_global = True
108
85
break
86
+
109
87
targ = self .previousframes [targ ]
110
- if not store or is_global :
111
- ret = self .globalframe .searchVariable (name )
112
- return ret
88
+
113
89
return None
114
90
115
91
def searchFunction (self , name ):
116
92
if self .current is None :
117
93
return None
94
+
118
95
targ = self .current
96
+
119
97
while targ is not None :
120
98
ret = targ .searchFunction (name )
121
- if ret :
99
+ if ret is not None :
122
100
return ret
101
+
123
102
targ = self .previousframes [targ ]
124
- ret = self . globalframe . searchFunction ( name )
125
- return ret
103
+
104
+ return None
126
105
127
106
def addBind (self , state , dst , var , cond = None ):
128
107
if dst not in self .binds :
@@ -239,8 +218,6 @@ def __init__(self, name, ftype=None):
239
218
self .name = name
240
219
self .ftype = ftype
241
220
self .variables = OrderedDict ()
242
- self .nonlocals = []
243
- self .globals = []
244
221
self .functions = OrderedDict ()
245
222
self .unresolved_break = []
246
223
self .unresolved_continue = []
@@ -253,12 +230,6 @@ def getNamePrefix(self):
253
230
def addVariable (self , name , var ):
254
231
self .variables [name ] = var
255
232
256
- def addNonlocal (self , name ):
257
- self .nonlocals .append (name )
258
-
259
- def addGlobal (self , name ):
260
- self .globals .append (name )
261
-
262
233
def addFunction (self , func ):
263
234
name = func .name
264
235
self .functions [name ] = func
@@ -268,16 +239,6 @@ def searchVariable(self, name):
268
239
return None
269
240
return self .variables [name ]
270
241
271
- def searchNonlocal (self , name ):
272
- if name not in self .nonlocals :
273
- return None
274
- return name
275
-
276
- def searchGlobal (self , name ):
277
- if name not in self .globals :
278
- return None
279
- return name
280
-
281
242
def searchFunction (self , name ):
282
243
if name not in self .functions :
283
244
return None
@@ -287,12 +248,6 @@ def searchFunction(self, name):
287
248
def getVariables (self ):
288
249
return tuple (self .variables )
289
250
290
- def getNonlocals (self ):
291
- return tuple (self .nonlocals )
292
-
293
- def getGlobals (self ):
294
- return tuple (self .globals )
295
-
296
251
def getFunctions (self ):
297
252
return self .functions
298
253
0 commit comments