// Populate the scope of the context items that appear before a design unit. The
// scope of the design unit itself is a subscope of the context items.
Populate the scope of the context items that appear before a design unit. The
scope of the design unit itself is a subscope of the context items.
Populate the scope of the context items that appear before a design unit . The scope of the design unit itself is a subscope of the context items .
pub fn make_ctx_items_scope(
        &self,
        id: CtxItemsRef,
        parent: Option<ScopeRef>,
    ) -> Result<CtxItemsRef> {
        let (_, items) = self.ast(id);
        let mut defs = Vec::new();
        let mut explicit_defs = HashMap::new();
        defs.push(id.into());
        for item in items {
            if let &ast::CtxItem::UseClause(Spanned {
                value: ref names, ..
            }) = item
            {
                for name in names {
                    // TODO: This creates an infinite loop, since the name lookup requires the context items to be ready.
                    let (res_name, mut out_defs, valid_span, mut tail) =
                        self.resolve_compound_name(name, id.into(), true)?;
                    // Resolve the optional `all`.
                    match tail.first() {
                        Some(&ast::NamePart::SelectAll(all_span)) => {
                            tail = &tail[1..];
                            match out_defs.pop() {
                                Some(Spanned {
                                    value: Def::Pkg(id),
                                    ..
                                }) => {
                                    defs.push(id.into());
                                }
                                Some(_) => {
                                    self.emit(
                                        DiagBuilder2::error(format!(
                                            "`all` not possible on `{}`",
                                            valid_span.extract()
                                        ))
                                        .span(all_span),
                                    );
                                    continue;
                                }
                                None => unreachable!(),
                            }
                        }
                        _ => {
                            explicit_defs
                                .entry(res_name)
                                .or_insert_with(|| Vec::new())
                                .extend(out_defs);
                        }
                    }
                    // Ensure that there is no garbage.
                    if tail.len() > 0 {
                        let span = Span::union(valid_span.end().into(), name.span.end());
                        self.emit(DiagBuilder2::error("invalid name suffix").span(span));
                        continue;
                    }
                }
            }
        }
        self.sb.scope_table.borrow_mut().insert(
            id.into(),
            self.sb.arenas.scope.alloc(Scope {
                parent: Some(parent.unwrap_or(*ROOT_SCOPE_REF)),
                defs: defs,
                explicit_defs: explicit_defs,
            }),
        );
        Ok(id)
    }
pub fn make_ctx_items_scope ( & self , id : CtxItemsRef , parent : Option < ScopeRef > , ) -> Result < CtxItemsRef > { let ( _ , items ) = self . ast ( id ) ; let mut defs = Vec :: new ( ) ; let mut explicit_defs = HashMap :: new ( ) ; defs . push ( id . into ( ) ) ; for item in items { if let & ast :: CtxItem :: UseClause ( Spanned { value : ref names , .. } ) = item { for name in names { // TODO: This creates an infinite loop, since the name lookup requires the context items to be ready. let ( res_name , mut out_defs , valid_span , mut tail ) = self . resolve_compound_name ( name , id . into ( ) , true ) ? ; // Resolve the optional `all`. match tail . first ( ) { Some ( & ast :: NamePart :: SelectAll ( all_span ) ) => { tail = & tail [ 1 .. ] ; match out_defs . pop ( ) { Some ( Spanned { value : Def :: Pkg ( id ) , .. } ) => { defs . push ( id . into ( ) ) ; } Some ( _ ) => { self . emit ( DiagBuilder2 :: error ( format ! ( " " valid_span extract ( ) ) ) . span ( all_span ) , ) ; continue ; } None => unreachable ! ( ) , } } _ => { explicit_defs . entry ( res_name ) . or_insert_with ( | | Vec :: new ( ) ) . extend ( out_defs ) ; } } // Ensure that there is no garbage. if tail . len ( ) > 0 { let span = Span :: union ( valid_span . end ( ) . into ( ) , name . span . end ( ) ) ; self . emit ( DiagBuilder2 :: error ( " " ) . span ( span ) ) ; continue ; } } } } self . sb . scope_table . borrow_mut ( ) . insert ( id . into ( ) , self . sb . arenas . scope . alloc ( Scope { parent : Some ( parent . unwrap_or ( * ROOT_SCOPE_REF ) ) , defs : defs , explicit_defs : explicit_defs , } ) , ) ; Ok ( id ) }
Populate the scope of the context items that appear before a design unit.
Populate the scope of the context items that appear before a design unit .
&self
id
CtxItemsRef
parent
Option<ScopeRef>