pub fn declared_type<C>(&self, ctx: C) -> Result<&'t Type>
    where
        C: ExprContext<'t> + Copy,
    {
        match self.data.value {
            TypeData::Incomplete => {
                ctx.emit(
                    DiagBuilder2::error(format!("type `{}` is incomplete", self.name.value))
                        .span(self.span)
                        .add_note(format!(
                            "Provide a declaration of the form `type {} is ...` somewhere.",
                            self.name.value
                        )),
                );
                Err(())
            }
            TypeData::Enum(ref literals) => {
                let ty = EnumBasetype::new(literals.value.iter().map(|x| match *x {
                    EnumLit::Ident(x) => EnumVariant::Ident(x.value),
                    EnumLit::Char(x) => EnumVariant::Char(x.value),
                }));
                Ok(ctx.alloc_owned(ty.into_owned()))
            }
            TypeData::Range(ref range) => {
                let (dir, lb, rb) = range.value.constant_value(ctx)?;
                assert_eq!(lb.ty(), rb.ty());
                let ty = lb.ty();
                match ty.as_any() {
                    AnyType::Integer(ty) => {
                        let lb = lb.as_any().unwrap_integer();
                        let rb = rb.as_any().unwrap_integer();
                        let ty = IntegerBasetype::new(Range::with_left_right(
                            dir,
                            lb.value().clone(),
                            rb.value().clone(),
                        ));
                        Ok(ctx.alloc_owned(ty.into_owned()))
                    }
                    AnyType::Floating(ty) => {
                        let lb = lb.as_any().unwrap_floating();
                        let rb = rb.as_any().unwrap_floating();
                        let ty = FloatingBasetype::new(Range::with_left_right(
                            dir,
                            lb.value().clone(),
                            rb.value().clone(),
                        ));
                        Ok(ctx.alloc_owned(ty.into_owned()))
                    }
                    _ => {
                        ctx.emit(
                            DiagBuilder2::error(format!(
                                "bounds of type `{}` must be of integer or floating-point type",
                                self.name.value
                            ))
                            .span(range.span)
                            .add_note(format!("bounds are of type {}", ty)),
                        );
                        Err(())
                    }
                }
            }
            TypeData::Physical(ref range, ref units, primary) => {
                let (dir, lb, rb) = range.value.constant_value(ctx)?;
                assert_eq!(lb.ty(), rb.ty());
                let ty = lb.ty();
                match ty.as_any() {
                    AnyType::Integer(ty) => {
                        let lb = lb.as_any().unwrap_integer();
                        let rb = rb.as_any().unwrap_integer();
                        let ty = PhysicalBasetype::new(
                            Range::with_left_right(dir, lb.value().clone(), rb.value().clone()),
                            units.clone(),
                            primary,
                        );
                        Ok(ctx.alloc_owned(ty.into_owned()))
                    }
                    _ => {
                        ctx.emit(
                            DiagBuilder2::error(format!(
                                "bounds of physical type `{}` must be integers",
                                self.name.value
                            ))
                            .span(range.span)
                            .add_note(format!("bounds are of type {}", ty)),
                        );
                        Err(())
                    }
                }
            }
            TypeData::Access(subtype) => {
                let ty = AccessType::new(subtype.declared_type(ctx)?);
                Ok(ctx.alloc_owned(ty.into_owned()))
            }
        }
    }
/// Return the declared type.
///
/// This function maps the type declaration data to an actual `Type`.
Return the declared type.
This function maps the type declaration data to an actual `Type`.
Return the declared type . This function maps the type declaration data to an actual ` Type ` .
pub fn declared_type<C>(&self, ctx: C) -> Result<&'t Type>
    where
        C: ExprContext<'t> + Copy,
    {
        match self.data.value {
            TypeData::Incomplete => {
                ctx.emit(
                    DiagBuilder2::error(format!("type `{}` is incomplete", self.name.value))
                        .span(self.span)
                        .add_note(format!(
                            "Provide a declaration of the form `type {} is ...` somewhere.",
                            self.name.value
                        )),
                );
                Err(())
            }
            TypeData::Enum(ref literals) => {
                let ty = EnumBasetype::new(literals.value.iter().map(|x| match *x {
                    EnumLit::Ident(x) => EnumVariant::Ident(x.value),
                    EnumLit::Char(x) => EnumVariant::Char(x.value),
                }));
                Ok(ctx.alloc_owned(ty.into_owned()))
            }
            TypeData::Range(ref range) => {
                let (dir, lb, rb) = range.value.constant_value(ctx)?;
                assert_eq!(lb.ty(), rb.ty());
                let ty = lb.ty();
                match ty.as_any() {
                    AnyType::Integer(ty) => {
                        let lb = lb.as_any().unwrap_integer();
                        let rb = rb.as_any().unwrap_integer();
                        let ty = IntegerBasetype::new(Range::with_left_right(
                            dir,
                            lb.value().clone(),
                            rb.value().clone(),
                        ));
                        Ok(ctx.alloc_owned(ty.into_owned()))
                    }
                    AnyType::Floating(ty) => {
                        let lb = lb.as_any().unwrap_floating();
                        let rb = rb.as_any().unwrap_floating();
                        let ty = FloatingBasetype::new(Range::with_left_right(
                            dir,
                            lb.value().clone(),
                            rb.value().clone(),
                        ));
                        Ok(ctx.alloc_owned(ty.into_owned()))
                    }
                    _ => {
                        ctx.emit(
                            DiagBuilder2::error(format!(
                                "bounds of type `{}` must be of integer or floating-point type",
                                self.name.value
                            ))
                            .span(range.span)
                            .add_note(format!("bounds are of type {}", ty)),
                        );
                        Err(())
                    }
                }
            }
            TypeData::Physical(ref range, ref units, primary) => {
                let (dir, lb, rb) = range.value.constant_value(ctx)?;
                assert_eq!(lb.ty(), rb.ty());
                let ty = lb.ty();
                match ty.as_any() {
                    AnyType::Integer(ty) => {
                        let lb = lb.as_any().unwrap_integer();
                        let rb = rb.as_any().unwrap_integer();
                        let ty = PhysicalBasetype::new(
                            Range::with_left_right(dir, lb.value().clone(), rb.value().clone()),
                            units.clone(),
                            primary,
                        );
                        Ok(ctx.alloc_owned(ty.into_owned()))
                    }
                    _ => {
                        ctx.emit(
                            DiagBuilder2::error(format!(
                                "bounds of physical type `{}` must be integers",
                                self.name.value
                            ))
                            .span(range.span)
                            .add_note(format!("bounds are of type {}", ty)),
                        );
                        Err(())
                    }
                }
            }
            TypeData::Access(subtype) => {
                let ty = AccessType::new(subtype.declared_type(ctx)?);
                Ok(ctx.alloc_owned(ty.into_owned()))
            }
        }
    }
pub fn declared_type < C > ( & self , ctx : C ) -> Result < & ' t Type > where C : ExprContext < ' t > + Copy , { match self . data . value { TypeData :: Incomplete => { ctx . emit ( DiagBuilder2 :: error ( format ! ( " " self name value ) ) . span ( self . span ) . add_note ( format ! ( " " self name value ) ) , ) ; Err ( ( ) ) } TypeData :: Enum ( ref literals ) => { let ty = EnumBasetype :: new ( literals . value . iter ( ) . map ( | x | match * x { EnumLit :: Ident ( x ) => EnumVariant :: Ident ( x . value ) , EnumLit :: Char ( x ) => EnumVariant :: Char ( x . value ) , } ) ) ; Ok ( ctx . alloc_owned ( ty . into_owned ( ) ) ) } TypeData :: Range ( ref range ) => { let ( dir , lb , rb ) = range . value . constant_value ( ctx ) ? ; assert_eq ! ( lb ty ( ) rb ty ( ) ) ; let ty = lb . ty ( ) ; match ty . as_any ( ) { AnyType :: Integer ( ty ) => { let lb = lb . as_any ( ) . unwrap_integer ( ) ; let rb = rb . as_any ( ) . unwrap_integer ( ) ; let ty = IntegerBasetype :: new ( Range :: with_left_right ( dir , lb . value ( ) . clone ( ) , rb . value ( ) . clone ( ) , ) ) ; Ok ( ctx . alloc_owned ( ty . into_owned ( ) ) ) } AnyType :: Floating ( ty ) => { let lb = lb . as_any ( ) . unwrap_floating ( ) ; let rb = rb . as_any ( ) . unwrap_floating ( ) ; let ty = FloatingBasetype :: new ( Range :: with_left_right ( dir , lb . value ( ) . clone ( ) , rb . value ( ) . clone ( ) , ) ) ; Ok ( ctx . alloc_owned ( ty . into_owned ( ) ) ) } _ => { ctx . emit ( DiagBuilder2 :: error ( format ! ( " " self name value ) ) . span ( range . span ) . add_note ( format ! ( " " ty ) ) , ) ; Err ( ( ) ) } } } TypeData :: Physical ( ref range , ref units , primary ) => { let ( dir , lb , rb ) = range . value . constant_value ( ctx ) ? ; assert_eq ! ( lb ty ( ) rb ty ( ) ) ; let ty = lb . ty ( ) ; match ty . as_any ( ) { AnyType :: Integer ( ty ) => { let lb = lb . as_any ( ) . unwrap_integer ( ) ; let rb = rb . as_any ( ) . unwrap_integer ( ) ; let ty = PhysicalBasetype :: new ( Range :: with_left_right ( dir , lb . value ( ) . clone ( ) , rb . value ( ) . clone ( ) ) , units . clone ( ) , primary , ) ; Ok ( ctx . alloc_owned ( ty . into_owned ( ) ) ) } _ => { ctx . emit ( DiagBuilder2 :: error ( format ! ( " " self name value ) ) . span ( range . span ) . add_note ( format ! ( " " ty ) ) , ) ; Err ( ( ) ) } } } TypeData :: Access ( subtype ) => { let ty = AccessType :: new ( subtype . declared_type ( ctx ) ? ) ; Ok ( ctx . alloc_owned ( ty . into_owned ( ) ) ) } } }
Return the declared type.
Return the declared type .
&self
ctx
C
&self
ctx
C