mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-14 16:45:25 +00:00
&str::to_string -> &str::to_owned for variables
This commit is contained in:
parent
7860fc877d
commit
04c29f384e
2 changed files with 21 additions and 21 deletions
|
@ -290,7 +290,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
fn load_name(&mut self, name: &str) {
|
fn load_name(&mut self, name: &str) {
|
||||||
let scope = self.scope_for_name(name);
|
let scope = self.scope_for_name(name);
|
||||||
self.emit(Instruction::LoadName {
|
self.emit(Instruction::LoadName {
|
||||||
name: name.to_string(),
|
name: name.to_owned(),
|
||||||
scope,
|
scope,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -298,7 +298,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
fn store_name(&mut self, name: &str) {
|
fn store_name(&mut self, name: &str) {
|
||||||
let scope = self.scope_for_name(name);
|
let scope = self.scope_for_name(name);
|
||||||
self.emit(Instruction::StoreName {
|
self.emit(Instruction::StoreName {
|
||||||
name: name.to_string(),
|
name: name.to_owned(),
|
||||||
scope,
|
scope,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -359,7 +359,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
for name in names {
|
for name in names {
|
||||||
// import symbol from module:
|
// import symbol from module:
|
||||||
self.emit(Instruction::ImportFrom {
|
self.emit(Instruction::ImportFrom {
|
||||||
name: name.symbol.to_string(),
|
name: name.symbol.to_owned(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Store module under proper name:
|
// Store module under proper name:
|
||||||
|
@ -619,13 +619,13 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
match &expression.node {
|
match &expression.node {
|
||||||
ast::ExpressionType::Identifier { name } => {
|
ast::ExpressionType::Identifier { name } => {
|
||||||
self.emit(Instruction::DeleteName {
|
self.emit(Instruction::DeleteName {
|
||||||
name: name.to_string(),
|
name: name.to_owned(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ast::ExpressionType::Attribute { value, name } => {
|
ast::ExpressionType::Attribute { value, name } => {
|
||||||
self.compile_expression(value)?;
|
self.compile_expression(value)?;
|
||||||
self.emit(Instruction::DeleteAttr {
|
self.emit(Instruction::DeleteAttr {
|
||||||
name: name.to_string(),
|
name: name.to_owned(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ast::ExpressionType::Subscript { a, b } => {
|
ast::ExpressionType::Subscript { a, b } => {
|
||||||
|
@ -701,7 +701,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
compile_varargs(&args.kwarg),
|
compile_varargs(&args.kwarg),
|
||||||
self.source_path.clone().unwrap(),
|
self.source_path.clone().unwrap(),
|
||||||
line_number,
|
line_number,
|
||||||
name.to_string(),
|
name.to_owned(),
|
||||||
));
|
));
|
||||||
self.enter_scope();
|
self.enter_scope();
|
||||||
|
|
||||||
|
@ -909,7 +909,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
if let Some(annotation) = &arg.annotation {
|
if let Some(annotation) = &arg.annotation {
|
||||||
self.emit(Instruction::LoadConst {
|
self.emit(Instruction::LoadConst {
|
||||||
value: bytecode::Constant::String {
|
value: bytecode::Constant::String {
|
||||||
value: arg.arg.to_string(),
|
value: arg.arg.to_owned(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
self.compile_expression(&annotation)?;
|
self.compile_expression(&annotation)?;
|
||||||
|
@ -982,7 +982,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
Varargs::None,
|
Varargs::None,
|
||||||
self.source_path.clone().unwrap(),
|
self.source_path.clone().unwrap(),
|
||||||
line_number,
|
line_number,
|
||||||
name.to_string(),
|
name.to_owned(),
|
||||||
));
|
));
|
||||||
self.enter_scope();
|
self.enter_scope();
|
||||||
|
|
||||||
|
@ -1022,7 +1022,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
});
|
});
|
||||||
self.emit(Instruction::LoadConst {
|
self.emit(Instruction::LoadConst {
|
||||||
value: bytecode::Constant::String {
|
value: bytecode::Constant::String {
|
||||||
value: name.to_string(),
|
value: name.to_owned(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1044,7 +1044,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
for keyword in keywords {
|
for keyword in keywords {
|
||||||
if let Some(name) = &keyword.name {
|
if let Some(name) = &keyword.name {
|
||||||
kwarg_names.push(bytecode::Constant::String {
|
kwarg_names.push(bytecode::Constant::String {
|
||||||
value: name.to_string(),
|
value: name.to_owned(),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// This means **kwargs!
|
// This means **kwargs!
|
||||||
|
@ -1308,7 +1308,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
});
|
});
|
||||||
self.emit(Instruction::LoadConst {
|
self.emit(Instruction::LoadConst {
|
||||||
value: bytecode::Constant::String {
|
value: bytecode::Constant::String {
|
||||||
value: name.to_string(),
|
value: name.to_owned(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
self.emit(Instruction::StoreSubscript);
|
self.emit(Instruction::StoreSubscript);
|
||||||
|
@ -1332,7 +1332,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
ast::ExpressionType::Attribute { value, name } => {
|
ast::ExpressionType::Attribute { value, name } => {
|
||||||
self.compile_expression(value)?;
|
self.compile_expression(value)?;
|
||||||
self.emit(Instruction::StoreAttr {
|
self.emit(Instruction::StoreAttr {
|
||||||
name: name.to_string(),
|
name: name.to_owned(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ast::ExpressionType::List { elements } | ast::ExpressionType::Tuple { elements } => {
|
ast::ExpressionType::List { elements } | ast::ExpressionType::Tuple { elements } => {
|
||||||
|
@ -1605,7 +1605,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
Attribute { value, name } => {
|
Attribute { value, name } => {
|
||||||
self.compile_expression(value)?;
|
self.compile_expression(value)?;
|
||||||
self.emit(Instruction::LoadAttr {
|
self.emit(Instruction::LoadAttr {
|
||||||
name: name.to_string(),
|
name: name.to_owned(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Compare { vals, ops } => {
|
Compare { vals, ops } => {
|
||||||
|
@ -1795,7 +1795,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
if let Some(name) = &keyword.name {
|
if let Some(name) = &keyword.name {
|
||||||
self.emit(Instruction::LoadConst {
|
self.emit(Instruction::LoadConst {
|
||||||
value: bytecode::Constant::String {
|
value: bytecode::Constant::String {
|
||||||
value: name.to_string(),
|
value: name.to_owned(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
self.compile_expression(&keyword.value)?;
|
self.compile_expression(&keyword.value)?;
|
||||||
|
@ -1858,7 +1858,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
for keyword in keywords {
|
for keyword in keywords {
|
||||||
if let Some(name) = &keyword.name {
|
if let Some(name) = &keyword.name {
|
||||||
kwarg_names.push(bytecode::Constant::String {
|
kwarg_names.push(bytecode::Constant::String {
|
||||||
value: name.to_string(),
|
value: name.to_owned(),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// This means **kwargs!
|
// This means **kwargs!
|
||||||
|
@ -1927,7 +1927,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
ast::ComprehensionKind::Set { .. } => "<setcomp>",
|
ast::ComprehensionKind::Set { .. } => "<setcomp>",
|
||||||
ast::ComprehensionKind::Dict { .. } => "<dictcomp>",
|
ast::ComprehensionKind::Dict { .. } => "<dictcomp>",
|
||||||
}
|
}
|
||||||
.to_string();
|
.to_owned();
|
||||||
|
|
||||||
let line_number = self.get_source_line_number();
|
let line_number = self.get_source_line_number();
|
||||||
// Create magnificent function <listcomp>:
|
// Create magnificent function <listcomp>:
|
||||||
|
@ -2099,7 +2099,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
ast::StringGroup::Constant { value } => {
|
ast::StringGroup::Constant { value } => {
|
||||||
self.emit(Instruction::LoadConst {
|
self.emit(Instruction::LoadConst {
|
||||||
value: bytecode::Constant::String {
|
value: bytecode::Constant::String {
|
||||||
value: value.to_string(),
|
value: value.to_owned(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2266,7 +2266,7 @@ mod tests {
|
||||||
let mut compiler: Compiler = Default::default();
|
let mut compiler: Compiler = Default::default();
|
||||||
compiler.source_path = Some("source_path".to_owned());
|
compiler.source_path = Some("source_path".to_owned());
|
||||||
compiler.push_new_code_object("<module>".to_owned());
|
compiler.push_new_code_object("<module>".to_owned());
|
||||||
let ast = parser::parse_program(&source.to_string()).unwrap();
|
let ast = parser::parse_program(source).unwrap();
|
||||||
let symbol_scope = make_symbol_table(&ast).unwrap();
|
let symbol_scope = make_symbol_table(&ast).unwrap();
|
||||||
compiler.compile_program(&ast, symbol_scope).unwrap();
|
compiler.compile_program(&ast, symbol_scope).unwrap();
|
||||||
compiler.pop_code_object()
|
compiler.pop_code_object()
|
||||||
|
|
|
@ -105,7 +105,7 @@ pub struct Symbol {
|
||||||
impl Symbol {
|
impl Symbol {
|
||||||
fn new(name: &str) -> Self {
|
fn new(name: &str) -> Self {
|
||||||
Symbol {
|
Symbol {
|
||||||
name: name.to_string(),
|
name: name.to_owned(),
|
||||||
// table,
|
// table,
|
||||||
scope: SymbolScope::Unknown,
|
scope: SymbolScope::Unknown,
|
||||||
is_param: false,
|
is_param: false,
|
||||||
|
@ -304,7 +304,7 @@ impl SymbolTableBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn enter_scope(&mut self, name: &str, typ: SymbolTableType, line_number: usize) {
|
fn enter_scope(&mut self, name: &str, typ: SymbolTableType, line_number: usize) {
|
||||||
let table = SymbolTable::new(name.to_string(), typ, line_number);
|
let table = SymbolTable::new(name.to_owned(), typ, line_number);
|
||||||
self.tables.push(table);
|
self.tables.push(table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -793,7 +793,7 @@ impl SymbolTableBuilder {
|
||||||
// Insert symbol when required:
|
// Insert symbol when required:
|
||||||
if !containing {
|
if !containing {
|
||||||
let symbol = Symbol::new(name);
|
let symbol = Symbol::new(name);
|
||||||
table.symbols.insert(name.to_string(), symbol);
|
table.symbols.insert(name.to_owned(), symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set proper flags on symbol:
|
// Set proper flags on symbol:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue