mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-09 21:28:21 +00:00
Make some of ruff_python_semantic
pub(crate)
(#5093)
This commit is contained in:
parent
916f0889f8
commit
c992cfa76e
5 changed files with 22 additions and 22 deletions
|
@ -115,7 +115,7 @@ impl<'a> Definitions<'a> {
|
|||
///
|
||||
/// Members are assumed to be pushed in traversal order, such that parents are pushed before
|
||||
/// their children.
|
||||
pub fn push_member(&mut self, member: Member<'a>) -> DefinitionId {
|
||||
pub(crate) fn push_member(&mut self, member: Member<'a>) -> DefinitionId {
|
||||
self.0.push(Definition::Member(member))
|
||||
}
|
||||
|
||||
|
|
|
@ -49,11 +49,11 @@ impl<'a> Globals<'a> {
|
|||
builder.finish()
|
||||
}
|
||||
|
||||
pub fn get(&self, name: &str) -> Option<&TextRange> {
|
||||
pub(crate) fn get(&self, name: &str) -> Option<&TextRange> {
|
||||
self.0.get(name)
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = (&&'a str, &TextRange)> + '_ {
|
||||
pub(crate) fn iter(&self) -> impl Iterator<Item = (&&'a str, &TextRange)> + '_ {
|
||||
self.0.iter()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ impl<'a> Nodes<'a> {
|
|||
/// Inserts a new node into the node tree and returns its unique id.
|
||||
///
|
||||
/// Panics if a node with the same pointer already exists.
|
||||
pub fn insert(&mut self, stmt: &'a Stmt, parent: Option<NodeId>) -> NodeId {
|
||||
pub(crate) fn insert(&mut self, stmt: &'a Stmt, parent: Option<NodeId>) -> NodeId {
|
||||
let next_id = self.nodes.next_index();
|
||||
if let Some(existing_id) = self.node_to_id.insert(RefEquality(stmt), next_id) {
|
||||
panic!("Node already exists with id {existing_id:?}");
|
||||
|
@ -61,23 +61,23 @@ impl<'a> Nodes<'a> {
|
|||
self.nodes[node_id].parent
|
||||
}
|
||||
|
||||
/// Return the depth of the node.
|
||||
#[inline]
|
||||
pub fn depth(&self, node_id: NodeId) -> u32 {
|
||||
self.nodes[node_id].depth
|
||||
}
|
||||
|
||||
/// Returns an iterator over all [`NodeId`] ancestors, starting from the given [`NodeId`].
|
||||
pub fn ancestor_ids(&self, node_id: NodeId) -> impl Iterator<Item = NodeId> + '_ {
|
||||
std::iter::successors(Some(node_id), |&node_id| self.nodes[node_id].parent)
|
||||
}
|
||||
|
||||
/// Return the parent of the given node.
|
||||
pub fn parent(&self, node: &'a Stmt) -> Option<&'a Stmt> {
|
||||
let node_id = self.node_to_id.get(&RefEquality(node))?;
|
||||
let parent_id = self.nodes[*node_id].parent?;
|
||||
Some(self[parent_id])
|
||||
}
|
||||
|
||||
/// Return the depth of the node.
|
||||
#[inline]
|
||||
pub(crate) fn depth(&self, node_id: NodeId) -> u32 {
|
||||
self.nodes[node_id].depth
|
||||
}
|
||||
|
||||
/// Returns an iterator over all [`NodeId`] ancestors, starting from the given [`NodeId`].
|
||||
pub(crate) fn ancestor_ids(&self, node_id: NodeId) -> impl Iterator<Item = NodeId> + '_ {
|
||||
std::iter::successors(Some(node_id), |&node_id| self.nodes[node_id].parent)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Index<NodeId> for Nodes<'a> {
|
||||
|
|
|
@ -36,11 +36,11 @@ pub struct ReferenceId;
|
|||
|
||||
/// The references of a program indexed by [`ReferenceId`].
|
||||
#[derive(Debug, Default)]
|
||||
pub struct References(IndexVec<ReferenceId, Reference>);
|
||||
pub(crate) struct References(IndexVec<ReferenceId, Reference>);
|
||||
|
||||
impl References {
|
||||
/// Pushes a new [`Reference`] and returns its [`ReferenceId`].
|
||||
pub fn push(
|
||||
pub(crate) fn push(
|
||||
&mut self,
|
||||
scope_id: ScopeId,
|
||||
range: TextRange,
|
||||
|
|
|
@ -124,12 +124,12 @@ impl<'a> Scope<'a> {
|
|||
}
|
||||
|
||||
/// Set the globals pointer for this scope.
|
||||
pub fn set_globals_id(&mut self, globals: GlobalsId) {
|
||||
pub(crate) fn set_globals_id(&mut self, globals: GlobalsId) {
|
||||
self.globals_id = Some(globals);
|
||||
}
|
||||
|
||||
/// Returns the globals pointer for this scope.
|
||||
pub fn globals_id(&self) -> Option<GlobalsId> {
|
||||
pub(crate) fn globals_id(&self) -> Option<GlobalsId> {
|
||||
self.globals_id
|
||||
}
|
||||
|
||||
|
@ -196,17 +196,17 @@ pub struct Scopes<'a>(IndexVec<ScopeId, Scope<'a>>);
|
|||
|
||||
impl<'a> Scopes<'a> {
|
||||
/// Returns a reference to the global scope
|
||||
pub fn global(&self) -> &Scope<'a> {
|
||||
pub(crate) fn global(&self) -> &Scope<'a> {
|
||||
&self[ScopeId::global()]
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the global scope
|
||||
pub fn global_mut(&mut self) -> &mut Scope<'a> {
|
||||
pub(crate) fn global_mut(&mut self) -> &mut Scope<'a> {
|
||||
&mut self[ScopeId::global()]
|
||||
}
|
||||
|
||||
/// Pushes a new scope and returns its unique id
|
||||
pub fn push_scope(&mut self, kind: ScopeKind<'a>, parent: ScopeId) -> ScopeId {
|
||||
pub(crate) fn push_scope(&mut self, kind: ScopeKind<'a>, parent: ScopeId) -> ScopeId {
|
||||
let next_id = ScopeId::new(self.0.len());
|
||||
self.0.push(Scope::local(kind, parent));
|
||||
next_id
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue