cairo_lang_semantic/
semantic.rsuse cairo_lang_defs::db::DefsGroup;
use cairo_lang_defs::ids::LocalVarId;
pub use cairo_lang_defs::ids::{ParamId, VarId};
use cairo_lang_proc_macros::{DebugWithDb, SemanticObject};
use cairo_lang_syntax::node::ids::SyntaxStablePtrId;
use cairo_lang_syntax::node::{ast, TypedStablePtr};
use smol_str::SmolStr;
pub use super::expr::objects::*;
use crate::db::SemanticGroup;
pub use crate::expr::pattern::{
Pattern, PatternEnumVariant, PatternFixedSizeArray, PatternLiteral, PatternOtherwise,
PatternStringLiteral, PatternStruct, PatternTuple, PatternVariable,
};
pub use crate::items::enm::{ConcreteVariant, MatchArmSelector, ValueSelectorArm, Variant};
pub use crate::items::function_with_body::FunctionBody;
pub use crate::items::functions::{
ConcreteFunction, ConcreteFunctionWithBodyId, FunctionId, FunctionLongId, Signature,
};
pub use crate::items::generics::{GenericArgumentId, GenericParam};
pub use crate::items::imp::{ConcreteImplId, ConcreteImplLongId};
pub use crate::items::structure::Member;
pub use crate::items::trt::{ConcreteTraitId, ConcreteTraitLongId};
pub use crate::types::{
ConcreteEnumId, ConcreteExternTypeId, ConcreteStructId, ConcreteTypeId, TypeId, TypeLongId,
};
#[derive(Clone, Debug, Hash, PartialEq, Eq, DebugWithDb, SemanticObject)]
#[debug_db(dyn SemanticGroup + 'static)]
pub struct LocalVariable {
pub id: LocalVarId,
pub ty: TypeId,
#[dont_rewrite]
pub is_mut: bool,
}
impl LocalVariable {
pub fn stable_ptr(&self, db: &dyn DefsGroup) -> ast::TerminalIdentifierPtr {
self.id.stable_ptr(db)
}
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, DebugWithDb, SemanticObject)]
#[debug_db(dyn SemanticGroup + 'static)]
pub struct Parameter {
pub id: ParamId,
#[dont_rewrite]
pub name: SmolStr,
pub ty: TypeId,
#[dont_rewrite]
pub mutability: Mutability,
#[hide_field_debug_with_db]
#[dont_rewrite]
pub stable_ptr: ast::TerminalIdentifierPtr,
}
impl Parameter {
pub fn stable_ptr(&self, db: &dyn DefsGroup) -> ast::ParamPtr {
self.id.stable_ptr(db)
}
}
#[derive(Debug, Clone, Hash, PartialEq, Eq, Copy)]
pub enum Mutability {
Immutable,
Mutable,
Reference,
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, DebugWithDb)]
#[debug_db(dyn SemanticGroup + 'static)]
pub enum Variable {
Local(LocalVariable),
Param(Parameter),
}
impl Variable {
pub fn id(&self) -> VarId {
match self {
Variable::Local(local) => VarId::Local(local.id),
Variable::Param(param) => VarId::Param(param.id),
}
}
pub fn ty(&self) -> TypeId {
match self {
Variable::Local(local) => local.ty,
Variable::Param(param) => param.ty,
}
}
pub fn is_mut(&self) -> bool {
match self {
Variable::Local(local) => local.is_mut,
Variable::Param(param) => param.mutability != Mutability::Immutable,
}
}
pub fn stable_ptr(&self, db: &dyn DefsGroup) -> SyntaxStablePtrId {
match self {
Variable::Local(local) => local.stable_ptr(db).untyped(),
Variable::Param(param) => param.stable_ptr(db).untyped(),
}
}
}
impl From<LocalVariable> for Variable {
fn from(var: LocalVariable) -> Self {
Self::Local(var)
}
}
impl From<Parameter> for Variable {
fn from(param: Parameter) -> Self {
Self::Param(param)
}
}