/// Resolve a compound name within a scope.
Resolve a compound name within a scope.
Resolve a compound name within a scope .
pub fn resolve_compound_name<'a>(
        &self,
        name: &'a ast::CompoundName,
        scope_id: ScopeRef,
        only_defs: bool,
    ) -> Result<(ResolvableName, Vec<Spanned<Def>>, Span, &'a [ast::NamePart])> {
        if self.sess.opts.trace_scoreboard {
            debugln!(
                "[SB][VHDL] resolve compound {:?} in scope {:?}",
                name,
                scope_id
            );
        }
        // First resolve the primary name.
        let mut seen_span = name.primary.span;
        let mut res_name = self.resolvable_from_primary_name(&name.primary)?;
        let mut defs = self.resolve_name(res_name, scope_id, only_defs, false)?;
        // Resolve as many name parts as possible.
        for i in 0..name.parts.len() {
            match name.parts[i] {
                ast::NamePart::Select(ref pn) => {
                    // Ensure that we only have one definition, i.e. that the
                    // name up to this point is not ambiguous.
                    let def = if defs.len() == 1 {
                        defs[0]
                    } else {
                        let span_str = seen_span.extract();
                        let mut d = DiagBuilder2::error(format!("`{}` is ambiguous", span_str))
                            .span(seen_span)
                            .add_note(format!(
                                "`{}` refers to the following {} items:",
                                span_str,
                                defs.len()
                            ));
                        for def in &defs {
                            d = d.span(def.span);
                        }
                        self.emit(d);
                        return Err(());
                    };
                    // Make sure that we can map the definition to a scope
                    // reference. We can only select into things that have a
                    // scope of their own.
                    let scope = match def.value {
                        Def::Lib(id) => id.into(),
                        Def::Pkg(id) => id.into(),
                        // Def::PkgInst(id) => id.into(),
                        Def::BuiltinPkg(id) => id.into(),
                        d => {
                            self.emit(
                                DiagBuilder2::error(format!("cannot select into {:?}", d))
                                    .span(pn.span),
                            );
                            return Err(());
                        }
                    };
                    // Perform the name resolution in the scope determined
                    // above.
                    seen_span.expand(pn.span);
                    res_name = self.resolvable_from_primary_name(pn)?;
                    defs = self.resolve_name(res_name, scope, true, false)?;
                }
                // All other name parts we do not resolve and simply pass back
                // to the caller.
                _ => return Ok((res_name.value, defs, seen_span, &name.parts[i..])),
            }
        }
        // If we arrive here, we were able to resolve the entire name. So we
        // simply return the definitions found and an empty slice of remaining
        // parts.
        Ok((res_name.value, defs, seen_span, &[]))
    }
pub fn resolve_compound_name < ' a > ( & self , name : & ' a ast :: CompoundName , scope_id : ScopeRef , only_defs : bool , ) -> Result < ( ResolvableName , Vec < Spanned < Def > > , Span , & ' a [ ast :: NamePart ] ) > { if self . sess . opts . trace_scoreboard { debugln ! ( " " name scope_id ) ; } // First resolve the primary name. let mut seen_span = name . primary . span ; let mut res_name = self . resolvable_from_primary_name ( & name . primary ) ? ; let mut defs = self . resolve_name ( res_name , scope_id , only_defs , false ) ? ; // Resolve as many name parts as possible. for i in 0 .. name . parts . len ( ) { match name . parts [ i ] { ast :: NamePart :: Select ( ref pn ) => { // Ensure that we only have one definition, i.e. that the // name up to this point is not ambiguous. let def = if defs . len ( ) == 1 { defs [ 0 ] } else { let span_str = seen_span . extract ( ) ; let mut d = DiagBuilder2 :: error ( format ! ( " " span_str ) ) . span ( seen_span ) . add_note ( format ! ( " " span_str defs len ( ) ) ) ; for def in & defs { d = d . span ( def . span ) ; } self . emit ( d ) ; return Err ( ( ) ) ; } ; // Make sure that we can map the definition to a scope // reference. We can only select into things that have a // scope of their own. let scope = match def . value { Def :: Lib ( id ) => id . into ( ) , Def :: Pkg ( id ) => id . into ( ) , // Def::PkgInst(id) => id.into(), Def :: BuiltinPkg ( id ) => id . into ( ) , d => { self . emit ( DiagBuilder2 :: error ( format ! ( " " d ) ) . span ( pn . span ) , ) ; return Err ( ( ) ) ; } } ; // Perform the name resolution in the scope determined // above. seen_span . expand ( pn . span ) ; res_name = self . resolvable_from_primary_name ( pn ) ? ; defs = self . resolve_name ( res_name , scope , true , false ) ? ; } // All other name parts we do not resolve and simply pass back // to the caller. _ => return Ok ( ( res_name . value , defs , seen_span , & name . parts [ i .. ] ) ) , } } // If we arrive here, we were able to resolve the entire name. So we // simply return the definitions found and an empty slice of remaining // parts. Ok ( ( res_name . value , defs , seen_span , & [ ] ) ) }
Resolve a compound name within a scope.
Resolve a compound name within a scope .
&self
name
&'a ast::CompoundName
scope_id
ScopeRef
only_defs
bool