Skip to content

Commit c63d37e

Browse files
committed
ScopeInfo: getter for explicitNonlocalVariables
1 parent 94634b0 commit c63d37e

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/ScopeEnvironment.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public class ScopeEnvironment implements CellFrameSlotSupplier {
7272

7373
public static String CLASS_VAR_PREFIX = "<>class";
7474
public static String LAMBDA_NAME = "lambda";
75+
public static int CLASS_VAR_PREFIX_IDX = CLASS_VAR_PREFIX.length();
7576

7677
private final NodeFactory factory;
7778

@@ -116,21 +117,21 @@ public ScopeInfo popScope() {
116117
String name = identifier instanceof String ? (String) identifier : identifier.toString();
117118

118119
if (localySeenVars != null) {
119-
// remove the localy declared variable
120+
// remove the locally declared variable
120121
if (definingScopeKind == ScopeInfo.ScopeKind.Class && name.startsWith(CLASS_VAR_PREFIX)) {
121-
localySeenVars.remove(name.substring(7));
122+
localySeenVars.remove(name.substring(CLASS_VAR_PREFIX_IDX));
122123
} else {
123124
localySeenVars.remove(name);
124125
}
125126
}
126127

127128
List<ScopeInfo> usedInScopes = unresolvedVars.get(name);
128-
// was the declared varibale seen before?
129+
// was the declared variable seen before?
129130
if (usedInScopes != null && !(definingScopeKind == ScopeInfo.ScopeKind.Module && definingScope.findFrameSlot(name) != null)) {
130-
// make the varible freevar and cellvar in scopes, where is used
131+
// make the variable freevar and cellvar in scopes, where is used
131132
List<ScopeInfo> copy = new ArrayList<>(usedInScopes);
132133
for (ScopeInfo scope : copy) {
133-
// we need to find out, whether the scope is a under the defing scope
134+
// we need to find out, whether the scope is a under the defining scope
134135
ScopeInfo tmpScope = scope;
135136
ScopeInfo parentDefiningScope = definingScope.getParent();
136137
while (tmpScope != null && tmpScope != definingScope && tmpScope != parentDefiningScope) {
@@ -177,13 +178,13 @@ public ScopeInfo popScope() {
177178
String name = (String) identifier;
178179
if (name.startsWith(CLASS_VAR_PREFIX)) {
179180
definingScope.getFrameDescriptor().removeFrameSlot(identifier);
180-
name = name.substring(7);
181+
name = name.substring(CLASS_VAR_PREFIX_IDX);
181182
definingScope.createSlotIfNotPresent(name);
182183
copy = true;
183184
}
184185
}
185186
if (copy) {
186-
// we copy it because the idexes are now wrong due the issue GR-17984
187+
// we copy it because the indexes are now wrong due the issue GR-17984
187188
definingScope.setFrameDescriptor(definingScope.getFrameDescriptor().copy());
188189
}
189190
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/ScopeInfo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ public boolean isExplicitNonlocalVariable(String identifier) {
204204
return explicitNonlocalVariables != null && explicitNonlocalVariables.contains(identifier);
205205
}
206206

207+
public Set<String> getExplicitNonlocalVariables() {
208+
return explicitNonlocalVariables;
209+
}
210+
207211
public void addCellVar(String identifier) {
208212
addCellVar(identifier, false);
209213
}
@@ -218,10 +222,6 @@ public void addCellVar(String identifier, boolean createFrameSlot) {
218222
}
219223
}
220224

221-
public void addFreeVar(String identifier) {
222-
addFreeVar(identifier, false);
223-
}
224-
225225
public void addFreeVar(String identifier, boolean createFrameSlot) {
226226
if (freeVars == null) {
227227
freeVars = new TreeSet<>();

0 commit comments

Comments
 (0)