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

Method make_qualname

crates/codegen/src/compile.rs:1724–1808  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

1722 qualname
1723 }
1724 fn make_qualname(&mut self) -> String {
1725 let stack_size = self.code_stack.len();
1726 assert!(stack_size >= 1);
1727
1728 let current_obj_name = self.current_code_info().metadata.name.clone();
1729
1730 // If we're at the module level (stack_size == 1), qualname is just the name
1731 if stack_size <= 1 {
1732 return current_obj_name;
1733 }
1734
1735 // Check parent scope
1736 let mut parent_idx = stack_size - 2;
1737 let mut parent = &self.code_stack[parent_idx];
1738
1739 // If parent is ast::TypeParams scope, look at grandparent
1740 // Check if parent is a type params scope by name pattern
1741 if parent.metadata.name.starts_with("<generic parameters of ") {
1742 if stack_size == 2 {
1743 // If we're immediately within the module, qualname is just the name
1744 return current_obj_name;
1745 }
1746 // Use grandparent
1747 parent_idx = stack_size - 3;
1748 parent = &self.code_stack[parent_idx];
1749 }
1750
1751 // Check if this is a global class/function
1752 let mut force_global = false;
1753 if stack_size > self.symbol_table_stack.len() {
1754 // We might be in a situation where symbol table isn't pushed yet
1755 // In this case, check the parent symbol table
1756 if let Some(parent_table) = self.symbol_table_stack.last()
1757 && let Some(symbol) = parent_table.lookup(&current_obj_name)
1758 && symbol.scope == SymbolScope::GlobalExplicit
1759 {
1760 force_global = true;
1761 }
1762 } else if let Some(_current_table) = self.symbol_table_stack.last() {
1763 // Mangle the name if necessary (for private names in classes)
1764 let mangled_name = self.mangle(&current_obj_name);
1765
1766 // Look up in parent symbol table to check scope
1767 if self.symbol_table_stack.len() >= 2 {
1768 let parent_table = &self.symbol_table_stack[self.symbol_table_stack.len() - 2];
1769 if let Some(symbol) = parent_table.lookup(&mangled_name)
1770 && symbol.scope == SymbolScope::GlobalExplicit
1771 {
1772 force_global = true;
1773 }
1774 }
1775 }
1776
1777 // Build the qualified name
1778 if force_global {
1779 // For global symbols, qualname is just the name
1780 current_obj_name
1781 } else {

Callers 1

set_qualnameMethod · 0.80

Calls 9

current_code_infoMethod · 0.80
starts_withMethod · 0.80
mangleMethod · 0.80
lenMethod · 0.45
cloneMethod · 0.45
lastMethod · 0.45
lookupMethod · 0.45
containsMethod · 0.45
as_refMethod · 0.45

Tested by

no test coverage detected