MCPcopy Index your code
hub / github.com/RustPython/RustPython / analyze_symbol

Method analyze_symbol

crates/codegen/src/symboltable.rs:611–708  ·  view source on GitHub ↗
(
        &mut self,
        symbol: &mut Symbol,
        st_typ: CompilerScope,
        sub_tables: &[SymbolTable],
        class_entry: Option<&SymbolMap>,
    )

Source from the content-addressed store, hash-verified

609 }
610
611 fn analyze_symbol(
612 &mut self,
613 symbol: &mut Symbol,
614 st_typ: CompilerScope,
615 sub_tables: &[SymbolTable],
616 class_entry: Option<&SymbolMap>,
617 ) -> SymbolTableResult {
618 if symbol
619 .flags
620 .contains(SymbolFlags::ASSIGNED_IN_COMPREHENSION)
621 && st_typ == CompilerScope::Comprehension
622 {
623 // propagate symbol to next higher level that can hold it,
624 // i.e., function or module. Comprehension is skipped and
625 // Class is not allowed and detected as error.
626 //symbol.scope = SymbolScope::Nonlocal;
627 self.analyze_symbol_comprehension(symbol, 0)?
628 } else {
629 match symbol.scope {
630 SymbolScope::Free => {
631 if !self.tables.as_ref().is_empty() {
632 let scope_depth = self.tables.as_ref().len();
633 // check if the name is already defined in any outer scope
634 if scope_depth < 2
635 || self.found_in_outer_scope(&symbol.name, st_typ)
636 != Some(SymbolScope::Free)
637 {
638 return Err(SymbolTableError {
639 error: format!("no binding for nonlocal '{}' found", symbol.name),
640 // TODO: accurate location info, somehow
641 location: None,
642 });
643 }
644 // Check if the nonlocal binding refers to a type parameter
645 if symbol.flags.contains(SymbolFlags::NONLOCAL) {
646 for (symbols, _typ) in self.tables.iter().rev() {
647 if let Some(sym) = symbols.get(&symbol.name) {
648 if sym.flags.contains(SymbolFlags::TYPE_PARAM) {
649 return Err(SymbolTableError {
650 error: format!(
651 "nonlocal binding not allowed for type parameter '{}'",
652 symbol.name
653 ),
654 location: None,
655 });
656 }
657 if sym.is_bound() {
658 break;
659 }
660 }
661 }
662 }
663 } else {
664 return Err(SymbolTableError {
665 error: format!(
666 "nonlocal {} defined at place without an enclosing scope",
667 symbol.name
668 ),

Callers 1

analyze_symbol_tableMethod · 0.80

Calls 13

found_in_outer_scopeMethod · 0.80
is_boundMethod · 0.80
found_in_inner_scopeMethod · 0.80
SomeClass · 0.50
ErrClass · 0.50
containsMethod · 0.45
is_emptyMethod · 0.45
as_refMethod · 0.45
lenMethod · 0.45
revMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected