tamer: asg::graph::object: Move {Ident,Expr}Rel into respective submodules
DEV-13159main
parent
f753a23bad
commit
a7fee3071d
|
@ -706,112 +706,6 @@ pub trait ObjectRel {
|
|||
) -> Option<ObjectIndex<OB>>;
|
||||
}
|
||||
|
||||
/// Subset of [`ObjectKind`]s that are valid targets for edges from
|
||||
/// [`Ident`].
|
||||
///
|
||||
/// See [`ObjectRel`] for more information.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum IdentRel {
|
||||
Ident(ObjectIndex<Ident>),
|
||||
Expr(ObjectIndex<Expr>),
|
||||
}
|
||||
|
||||
impl ObjectRel for IdentRel {
|
||||
fn narrow<OB: ObjectKind + ObjectRelatable>(
|
||||
self,
|
||||
) -> Option<ObjectIndex<OB>> {
|
||||
match self {
|
||||
Self::Ident(oi) => oi.filter_rel(),
|
||||
Self::Expr(oi) => oi.filter_rel(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectRelatable for Ident {
|
||||
type Rel = IdentRel;
|
||||
|
||||
fn rel_ty() -> ObjectRelTy {
|
||||
ObjectRelTy::Ident
|
||||
}
|
||||
|
||||
fn new_rel_dyn(
|
||||
ty: ObjectRelTy,
|
||||
oi: ObjectIndex<Object>,
|
||||
) -> Option<IdentRel> {
|
||||
match ty {
|
||||
ObjectRelTy::Root => None,
|
||||
ObjectRelTy::Ident => Some(IdentRel::Ident(oi.must_narrow_into())),
|
||||
ObjectRelTy::Expr => Some(IdentRel::Expr(oi.must_narrow_into())),
|
||||
ObjectRelTy::Pkg => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ObjectIndex<Ident>> for IdentRel {
|
||||
fn from(value: ObjectIndex<Ident>) -> Self {
|
||||
Self::Ident(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ObjectIndex<Expr>> for IdentRel {
|
||||
fn from(value: ObjectIndex<Expr>) -> Self {
|
||||
Self::Expr(value)
|
||||
}
|
||||
}
|
||||
|
||||
/// Subset of [`ObjectKind`]s that are valid targets for edges from
|
||||
/// [`Expr`].
|
||||
///
|
||||
/// See [`ObjectRel`] for more information.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum ExprRel {
|
||||
Ident(ObjectIndex<Ident>),
|
||||
Expr(ObjectIndex<Expr>),
|
||||
}
|
||||
|
||||
impl ObjectRel for ExprRel {
|
||||
fn narrow<OB: ObjectKind + ObjectRelatable>(
|
||||
self,
|
||||
) -> Option<ObjectIndex<OB>> {
|
||||
match self {
|
||||
Self::Ident(oi) => oi.filter_rel(),
|
||||
Self::Expr(oi) => oi.filter_rel(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectRelatable for Expr {
|
||||
type Rel = ExprRel;
|
||||
|
||||
fn rel_ty() -> ObjectRelTy {
|
||||
ObjectRelTy::Expr
|
||||
}
|
||||
|
||||
fn new_rel_dyn(
|
||||
ty: ObjectRelTy,
|
||||
oi: ObjectIndex<Object>,
|
||||
) -> Option<ExprRel> {
|
||||
match ty {
|
||||
ObjectRelTy::Root => None,
|
||||
ObjectRelTy::Ident => Some(ExprRel::Ident(oi.must_narrow_into())),
|
||||
ObjectRelTy::Expr => Some(ExprRel::Expr(oi.must_narrow_into())),
|
||||
ObjectRelTy::Pkg => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ObjectIndex<Ident>> for ExprRel {
|
||||
fn from(value: ObjectIndex<Ident>) -> Self {
|
||||
Self::Ident(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ObjectIndex<Expr>> for ExprRel {
|
||||
fn from(value: ObjectIndex<Expr>) -> Self {
|
||||
Self::Expr(value)
|
||||
}
|
||||
}
|
||||
|
||||
/// A container for an [`Object`] allowing for owned borrowing of data.
|
||||
///
|
||||
/// The purpose of allowing this owned borrowing is to permit a functional
|
||||
|
|
|
@ -21,7 +21,10 @@
|
|||
|
||||
use std::fmt::Display;
|
||||
|
||||
use super::{Asg, ObjectIndex};
|
||||
use super::{
|
||||
Asg, Ident, Object, ObjectIndex, ObjectKind, ObjectRel, ObjectRelTy,
|
||||
ObjectRelatable,
|
||||
};
|
||||
use crate::{f::Functor, num::Dim, parse::util::SPair, span::Span};
|
||||
|
||||
/// Expression.
|
||||
|
@ -182,6 +185,59 @@ impl Display for DimState {
|
|||
}
|
||||
}
|
||||
|
||||
/// Subset of [`ObjectKind`]s that are valid targets for edges from
|
||||
/// [`Expr`].
|
||||
///
|
||||
/// See [`ObjectRel`] for more information.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum ExprRel {
|
||||
Ident(ObjectIndex<Ident>),
|
||||
Expr(ObjectIndex<Expr>),
|
||||
}
|
||||
|
||||
impl ObjectRel for ExprRel {
|
||||
fn narrow<OB: ObjectKind + ObjectRelatable>(
|
||||
self,
|
||||
) -> Option<ObjectIndex<OB>> {
|
||||
match self {
|
||||
Self::Ident(oi) => oi.filter_rel(),
|
||||
Self::Expr(oi) => oi.filter_rel(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectRelatable for Expr {
|
||||
type Rel = ExprRel;
|
||||
|
||||
fn rel_ty() -> ObjectRelTy {
|
||||
ObjectRelTy::Expr
|
||||
}
|
||||
|
||||
fn new_rel_dyn(
|
||||
ty: ObjectRelTy,
|
||||
oi: ObjectIndex<Object>,
|
||||
) -> Option<ExprRel> {
|
||||
match ty {
|
||||
ObjectRelTy::Root => None,
|
||||
ObjectRelTy::Ident => Some(ExprRel::Ident(oi.must_narrow_into())),
|
||||
ObjectRelTy::Expr => Some(ExprRel::Expr(oi.must_narrow_into())),
|
||||
ObjectRelTy::Pkg => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ObjectIndex<Ident>> for ExprRel {
|
||||
fn from(value: ObjectIndex<Ident>) -> Self {
|
||||
Self::Ident(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ObjectIndex<Expr>> for ExprRel {
|
||||
fn from(value: ObjectIndex<Expr>) -> Self {
|
||||
Self::Expr(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectIndex<Expr> {
|
||||
/// Create a new subexpression as the next child of this expression and
|
||||
/// return the [`ObjectIndex`] of the new subexpression.
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
use super::{
|
||||
super::{Asg, AsgError, ObjectIndex, ObjectKind},
|
||||
ObjectRel, ObjectRelTo, ObjectRelatable, Pkg,
|
||||
Expr, Object, ObjectRel, ObjectRelTo, ObjectRelTy, ObjectRelatable, Pkg,
|
||||
};
|
||||
use crate::{
|
||||
diagnose::{Annotate, Diagnostic},
|
||||
|
@ -966,6 +966,59 @@ pub struct Source {
|
|||
pub override_: bool,
|
||||
}
|
||||
|
||||
/// Subset of [`ObjectKind`]s that are valid targets for edges from
|
||||
/// [`Ident`].
|
||||
///
|
||||
/// See [`ObjectRel`] for more information.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum IdentRel {
|
||||
Ident(ObjectIndex<Ident>),
|
||||
Expr(ObjectIndex<Expr>),
|
||||
}
|
||||
|
||||
impl ObjectRel for IdentRel {
|
||||
fn narrow<OB: ObjectKind + ObjectRelatable>(
|
||||
self,
|
||||
) -> Option<ObjectIndex<OB>> {
|
||||
match self {
|
||||
Self::Ident(oi) => oi.filter_rel(),
|
||||
Self::Expr(oi) => oi.filter_rel(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectRelatable for Ident {
|
||||
type Rel = IdentRel;
|
||||
|
||||
fn rel_ty() -> ObjectRelTy {
|
||||
ObjectRelTy::Ident
|
||||
}
|
||||
|
||||
fn new_rel_dyn(
|
||||
ty: ObjectRelTy,
|
||||
oi: ObjectIndex<Object>,
|
||||
) -> Option<IdentRel> {
|
||||
match ty {
|
||||
ObjectRelTy::Root => None,
|
||||
ObjectRelTy::Ident => Some(IdentRel::Ident(oi.must_narrow_into())),
|
||||
ObjectRelTy::Expr => Some(IdentRel::Expr(oi.must_narrow_into())),
|
||||
ObjectRelTy::Pkg => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ObjectIndex<Ident>> for IdentRel {
|
||||
fn from(value: ObjectIndex<Ident>) -> Self {
|
||||
Self::Ident(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ObjectIndex<Expr>> for IdentRel {
|
||||
fn from(value: ObjectIndex<Expr>) -> Self {
|
||||
Self::Expr(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl ObjectIndex<Ident> {
|
||||
/// Bind an identifier to a `definition`,
|
||||
/// making it [`Transparent`].
|
||||
|
|
Loading…
Reference in New Issue