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

Method register_name

crates/codegen/src/symboltable.rs:2582–2792  ·  view source on GitHub ↗
(
        &mut self,
        name: &str,
        role: SymbolUsage,
        range: TextRange,
    )

Source from the content-addressed store, hash-verified

2580 }
2581
2582 fn register_name(
2583 &mut self,
2584 name: &str,
2585 role: SymbolUsage,
2586 range: TextRange,
2587 ) -> SymbolTableResult {
2588 let location = self
2589 .source_file
2590 .to_source_code()
2591 .source_location(range.start(), PositionEncoding::Utf8);
2592 let location = Some(location);
2593
2594 // Note: __debug__ checks are handled by check_name function, so no check needed here.
2595
2596 let scope_depth = self.tables.len();
2597 let table = self.tables.last_mut().unwrap();
2598
2599 // Add type param names to mangled_names set for selective mangling
2600 if matches!(role, SymbolUsage::TypeParam)
2601 && let Some(ref mut set) = table.mangled_names
2602 {
2603 set.insert(name.to_owned());
2604 }
2605
2606 let name = maybe_mangle_name(
2607 self.class_name.as_deref(),
2608 table.mangled_names.as_ref(),
2609 name,
2610 );
2611 // Some checks for the symbol that present on this scope level:
2612 let symbol = if let Some(symbol) = table.symbols.get_mut(name.as_ref()) {
2613 let flags = &symbol.flags;
2614
2615 // INNER_LOOP_CONFLICT: comprehension inner loop cannot rebind
2616 // a variable that was used as a named expression target
2617 // Example: [i for i in range(5) if (j := 0) for j in range(5)]
2618 // Here 'j' is used in named expr first, then as inner loop iter target
2619 if self.in_comp_inner_loop_target
2620 && flags.contains(SymbolFlags::ASSIGNED_IN_COMPREHENSION)
2621 {
2622 return Err(SymbolTableError {
2623 error: format!(
2624 "comprehension inner loop cannot rebind assignment expression target '{}'",
2625 name
2626 ),
2627 location,
2628 });
2629 }
2630
2631 // Role already set..
2632 match role {
2633 SymbolUsage::Global if !symbol.is_global() => {
2634 if flags.contains(SymbolFlags::PARAMETER) {
2635 return Err(SymbolTableError {
2636 error: format!("name '{name}' is parameter and global"),
2637 location,
2638 });
2639 }

Callers 8

scan_annotation_innerMethod · 0.80
scan_statementMethod · 0.80
scan_expressionMethod · 0.80
scan_comprehensionMethod · 0.80
scan_type_paramsMethod · 0.80
register_identMethod · 0.80

Calls 15

maybe_mangle_nameFunction · 0.85
newFunction · 0.85
source_locationMethod · 0.80
get_mutMethod · 0.80
into_ownedMethod · 0.80
SomeClass · 0.50
ErrClass · 0.50
startMethod · 0.45
lenMethod · 0.45
unwrapMethod · 0.45
insertMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected