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

@ -212,7 +212,7 @@ impl<'a> SemanticModel<'a> {
}
}
seen_function |= scope.kind.is_function();
seen_function |= scope.kind.is_any_function();
import_starred = import_starred || scope.uses_star_imports();
}
@ -539,7 +539,7 @@ impl<'a> SemanticModel<'a> {
self.scope_id == scope_id
}
/// Return `true` if the context is at the top level of the module (i.e., in the module scope,
/// Return `true` if the model is at the top level of the module (i.e., in the module scope,
/// and not nested within any statements).
pub fn at_top_level(&self) -> bool {
self.scope_id.is_global()
@ -548,6 +548,19 @@ impl<'a> SemanticModel<'a> {
.map_or(true, |stmt_id| self.stmts.parent_id(stmt_id).is_none())
}
/// Return `true` if the model is in an async context.
pub fn in_async_context(&self) -> bool {
for scope in self.scopes() {
if scope.kind.is_async_function() {
return true;
}
if scope.kind.is_function() {
return false;
}
}
false
}
/// Returns `true` if the given [`BindingId`] is used.
pub fn is_used(&self, binding_id: BindingId) -> bool {
self.bindings[binding_id].is_used()