use crate::ast_node_ref::AstNodeRef;
use crate::db::Db;
use crate::definition::Definition;
use crate::expression::Expression;
use crate::node_key::NodeKey;
use crate::scope::{FileScopeId, ScopeId};
use crate::{Program, ProgramFile};
use ruff_db::PythonFile;
use ruff_db::files::File;
use ruff_python_ast as ast;
use salsa;
#[derive(
Clone, Copy, Debug, Eq, Hash, PartialEq, salsa::Supertype, get_size2::GetSize, salsa::SalsaValue,
)]
pub enum Statement<'db> {
Expression(Expression<'db>),
Definition(Definition<'db>),
Other(StatementInner<'db>),
}
#[salsa::tracked(debug, heap_size=ruff_memory_usage::heap_size)]
pub struct StatementInner<'db> {
#[returns(copy)]
pub program_file: ProgramFile<'db>,
#[returns(copy)]
pub file_scope: FileScopeId,
#[no_eq]
#[tracked]
#[returns(ref)]
pub node_ref: AstNodeRef<ast::Stmt>,
}
impl get_size2::GetSize for StatementInner<'_> {}
impl<'db> StatementInner<'db> {
pub fn file(self, db: &'db dyn Db) -> File {
self.program_file(db).file(db)
}
pub fn python_file(self, db: &'db dyn Db) -> PythonFile<'db> {
self.program_file(db).python_file(db)
}
pub fn scope(self, db: &'db dyn Db) -> ScopeId<'db> {
self.file_scope(db).to_scope_id(db, self.program_file(db))
}
pub fn program(self, db: &'db dyn Db) -> Program<'db> {
self.scope(db).program(db)
}
}
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, get_size2::GetSize, salsa::SalsaValue)]
pub struct StatementNodeKey(NodeKey);
impl From<&ast::Stmt> for StatementNodeKey {
fn from(node: &ast::Stmt) -> Self {
Self(NodeKey::from_node(node))
}
}