Remove dedicated ScopeKind structs in favor of AST nodes (#4648)

This commit is contained in:
Charlie Marsh 2023-05-25 15:31:02 -04:00 committed by GitHub
parent 741e180e2d
commit 0f610f2cf7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 170 additions and 205 deletions

View file

@ -961,18 +961,15 @@ where
#[derive(Default)]
struct GlobalStatementVisitor<'a> {
globals: FxHashMap<&'a str, &'a Stmt>,
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: _range,
}) => {
Stmt::Global(ast::StmtGlobal { names, range }) => {
for name in names {
self.globals.insert(name.as_str(), stmt);
self.globals.insert(name.as_str(), *range);
}
}
Stmt::FunctionDef(_) | Stmt::AsyncFunctionDef(_) | Stmt::ClassDef(_) => {
@ -984,11 +981,9 @@ impl<'a> StatementVisitor<'a> for GlobalStatementVisitor<'a> {
}
/// Extract a map from global name to its last-defining [`Stmt`].
pub fn extract_globals(body: &[Stmt]) -> FxHashMap<&str, &Stmt> {
pub fn extract_globals(body: &[Stmt]) -> FxHashMap<&str, TextRange> {
let mut visitor = GlobalStatementVisitor::default();
for stmt in body {
visitor.visit_stmt(stmt);
}
visitor.visit_body(body);
visitor.globals
}