Remove globals table from Scope (#4686)

This commit is contained in:
Charlie Marsh 2023-05-27 22:35:20 -04:00 committed by GitHub
parent 901060fa96
commit 9741f788c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 147 additions and 96 deletions

View file

@ -959,34 +959,6 @@ where
}
}
#[derive(Default)]
struct GlobalStatementVisitor<'a> {
globals: FxHashMap<&'a str, TextRange>,
}
impl<'a> StatementVisitor<'a> for GlobalStatementVisitor<'a> {
fn visit_stmt(&mut self, stmt: &'a Stmt) {
match stmt {
Stmt::Global(ast::StmtGlobal { names, range }) => {
for name in names {
self.globals.insert(name.as_str(), *range);
}
}
Stmt::FunctionDef(_) | Stmt::AsyncFunctionDef(_) | Stmt::ClassDef(_) => {
// Don't recurse.
}
_ => walk_stmt(self, stmt),
}
}
}
/// Extract a map from global name to its last-defining [`Stmt`].
pub fn extract_globals(body: &[Stmt]) -> FxHashMap<&str, TextRange> {
let mut visitor = GlobalStatementVisitor::default();
visitor.visit_body(body);
visitor.globals
}
/// Return `true` if a [`Ranged`] has leading content.
pub fn has_leading_content<T>(located: &T, locator: &Locator) -> bool
where