/// Map a term to a discrete range.
Map a term to a discrete range.
Map a term to a discrete range .
pub fn term_to_discrete_range(
        &self,
        term: Spanned<Term>,
    ) -> Result<Spanned<hir::DiscreteRange>> {
        let term = self.fold_term_as_type(term)?;
        Ok(match term.value {
            Term::SubtypeInd(..) | Term::TypeMark(..) => {
                let hir = self.term_to_subtype_ind(term)?;
                let add_ctx = AddContext::new(self.ctx, self.scope);
                Spanned::new(add_ctx.add_subtype_ind_hir(hir.value)?.into(), hir.span)
            }
            Term::Range(..) => self.term_to_range(term)?.map_into(),
            _ => {
                self.emit(
                    DiagBuilder2::error(format!(
                        "`{}` is not a valid discrete range",
                        term.span.extract()
                    ))
                    .span(term.span)
                    .add_note("A discrete range can be one of the following:")
                    .add_note(
                        "- a subtype indication of the form `[resolution] type_mark [constraint]`",
                    )
                    .add_note("- a range of the form `a to b` or `a downto b`")
                    .add_note("- a range attribute of the form `T'range`")
                    .add_note("See IEEE 1076-2008 section 5.3.2.1."),
                );
                debugln!("It is a {:#?}", term);
                return Err(());
            }
        })
    }
pub fn term_to_discrete_range ( & self , term : Spanned < Term > , ) -> Result < Spanned < hir :: DiscreteRange > > { let term = self . fold_term_as_type ( term ) ? ; Ok ( match term . value { Term :: SubtypeInd ( .. ) | Term :: TypeMark ( .. ) => { let hir = self . term_to_subtype_ind ( term ) ? ; let add_ctx = AddContext :: new ( self . ctx , self . scope ) ; Spanned :: new ( add_ctx . add_subtype_ind_hir ( hir . value ) ? . into ( ) , hir . span ) } Term :: Range ( .. ) => self . term_to_range ( term ) ? . map_into ( ) , _ => { self . emit ( DiagBuilder2 :: error ( format ! ( " " term span extract ( ) ) ) . span ( term . span ) . add_note ( " " ) . add_note ( " " , ) . add_note ( " " ) . add_note ( " " ) . add_note ( " " ) , ) ; debugln ! ( " " term ) ; return Err ( ( ) ) ; } } ) }
Map a term to a discrete range.
Map a term to a discrete range .
&self
term
Spanned<Term>