mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
Merge pull request #1251 from RustPython/scope-detection
Extend AST python module. Add idea for scope detection.
This commit is contained in:
commit
99b3532cae
1 changed files with 22 additions and 2 deletions
|
@ -204,8 +204,25 @@ impl SymbolTableAnalyzer {
|
|||
// all is well
|
||||
}
|
||||
SymbolScope::Unknown => {
|
||||
if symbol.is_assigned {
|
||||
// Try hard to figure out what the scope of this symbol is.
|
||||
|
||||
if symbol.is_assigned || symbol.is_parameter {
|
||||
symbol.scope = SymbolScope::Local;
|
||||
} else {
|
||||
// TODO: comment this out and make it work properly:
|
||||
/*
|
||||
let found_in_outer_scope = self
|
||||
.tables
|
||||
.iter()
|
||||
.any(|t| t.symbols.contains_key(&symbol.name));
|
||||
if found_in_outer_scope {
|
||||
// Symbol is in some outer scope.
|
||||
|
||||
} else {
|
||||
// Well, it must be a global then :)
|
||||
// symbol.scope = SymbolScope::Global;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -713,7 +730,10 @@ impl SymbolTableBuilder {
|
|||
});
|
||||
}
|
||||
}
|
||||
SymbolUsage::Parameter | SymbolUsage::Assigned => {
|
||||
SymbolUsage::Parameter => {
|
||||
symbol.is_parameter = true;
|
||||
}
|
||||
SymbolUsage::Assigned => {
|
||||
symbol.is_assigned = true;
|
||||
}
|
||||
SymbolUsage::Global => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue