mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-18 10:35:25 +00:00
Refactor checks for symbol in register_name
This commit is contained in:
parent
678b8e779b
commit
09e4e9a86c
1 changed files with 16 additions and 20 deletions
|
@ -951,10 +951,8 @@ impl SymbolTableBuilder {
|
||||||
let table = self.tables.last_mut().unwrap();
|
let table = self.tables.last_mut().unwrap();
|
||||||
let location = Default::default();
|
let location = Default::default();
|
||||||
|
|
||||||
// Some checks:
|
// Some checks for the symbol that present on this scope level:
|
||||||
let containing = table.symbols.contains_key(name);
|
if let Some(symbol) = table.symbols.get(name) {
|
||||||
if containing {
|
|
||||||
let symbol = table.symbols.get(name).unwrap();
|
|
||||||
// Role already set..
|
// Role already set..
|
||||||
match role {
|
match role {
|
||||||
SymbolUsage::Global => {
|
SymbolUsage::Global => {
|
||||||
|
@ -1000,9 +998,9 @@ impl SymbolTableBuilder {
|
||||||
// Ok?
|
// Ok?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
// The symbol does not present on this scope level.
|
||||||
// Some more checks:
|
// Some checks to insert new symbol into symbol table:
|
||||||
match role {
|
match role {
|
||||||
SymbolUsage::Nonlocal if scope_depth < 2 => {
|
SymbolUsage::Nonlocal if scope_depth < 2 => {
|
||||||
return Err(SymbolTableError {
|
return Err(SymbolTableError {
|
||||||
|
@ -1014,9 +1012,7 @@ impl SymbolTableBuilder {
|
||||||
// Ok!
|
// Ok!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert symbol when required:
|
// Insert symbol when required:
|
||||||
if !containing {
|
|
||||||
let symbol = Symbol::new(name);
|
let symbol = Symbol::new(name);
|
||||||
table.symbols.insert(name.to_owned(), symbol);
|
table.symbols.insert(name.to_owned(), symbol);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue