Apply review suggestions

This commit is contained in:
Noah 2020-12-04 14:18:17 -06:00
parent 9305316f69
commit ff8512cd54
2 changed files with 11 additions and 9 deletions

View file

@ -60,13 +60,10 @@ impl CodeInfo {
.cellvars .cellvars
.iter() .iter()
.map(|var| { .map(|var| {
for (i, arg) in all_args.iter().enumerate() { all_args.iter().position(|arg| var == arg).map_or(-1, |i| {
if var == arg { found_cellarg = true;
found_cellarg = true; i as isize
return i as isize; })
}
}
-1
}) })
.collect::<Box<[_]>>(); .collect::<Box<[_]>>();
if found_cellarg { if found_cellarg {

View file

@ -108,6 +108,7 @@ pub struct Symbol {
pub is_parameter: bool, pub is_parameter: bool,
pub is_annotated: bool, pub is_annotated: bool,
pub is_imported: bool, pub is_imported: bool,
pub is_nonlocal: bool,
// indicates if the symbol gets a value assigned by a named expression in a comprehension // indicates if the symbol gets a value assigned by a named expression in a comprehension
// this is required to correct the scope in the analysis. // this is required to correct the scope in the analysis.
@ -139,6 +140,7 @@ impl Symbol {
is_parameter: false, is_parameter: false,
is_annotated: false, is_annotated: false,
is_imported: false, is_imported: false,
is_nonlocal: false,
is_assign_namedexpr_in_comprehension: false, is_assign_namedexpr_in_comprehension: false,
is_iter: false, is_iter: false,
is_free_class: false, is_free_class: false,
@ -218,7 +220,9 @@ mod stack {
} }
} }
impl<T> StackStack<T> { impl<T> StackStack<T> {
pub fn append<F, R>(&mut self, x: &mut T, f: F) -> R /// Appends a reference to this stack for the duration of the function `f`. When `f`
/// returns, the reference will be popped off the stack.
pub fn with_append<F, R>(&mut self, x: &mut T, f: F) -> R
where where
F: FnOnce(&mut Self) -> R, F: FnOnce(&mut Self) -> R,
{ {
@ -273,7 +277,7 @@ impl SymbolTableAnalyzer {
let sub_tables = &mut *symbol_table.sub_tables; let sub_tables = &mut *symbol_table.sub_tables;
let mut info = (symbols, symbol_table.typ); let mut info = (symbols, symbol_table.typ);
self.tables.append(&mut info, |list| { self.tables.with_append(&mut info, |list| {
let inner_scope = unsafe { &mut *(list as *mut _ as *mut SymbolTableAnalyzer) }; let inner_scope = unsafe { &mut *(list as *mut _ as *mut SymbolTableAnalyzer) };
// Analyze sub scopes: // Analyze sub scopes:
for sub_table in sub_tables.iter_mut() { for sub_table in sub_tables.iter_mut() {
@ -1162,6 +1166,7 @@ impl SymbolTableBuilder {
match role { match role {
SymbolUsage::Nonlocal => { SymbolUsage::Nonlocal => {
symbol.scope = SymbolScope::Free; symbol.scope = SymbolScope::Free;
symbol.is_nonlocal = true;
} }
SymbolUsage::Imported => { SymbolUsage::Imported => {
symbol.is_assigned = true; symbol.is_assigned = true;