mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-15 17:15:24 +00:00
&str::to_string -> &str::to_owned for literals
This commit is contained in:
parent
9a599e81a4
commit
7860fc877d
2 changed files with 18 additions and 18 deletions
|
@ -88,7 +88,7 @@ fn with_compiler(
|
||||||
) -> Result<CodeObject, CompileError> {
|
) -> Result<CodeObject, CompileError> {
|
||||||
let mut compiler = Compiler::new(optimize);
|
let mut compiler = Compiler::new(optimize);
|
||||||
compiler.source_path = Some(source_path);
|
compiler.source_path = Some(source_path);
|
||||||
compiler.push_new_code_object("<module>".to_string());
|
compiler.push_new_code_object("<module>".to_owned());
|
||||||
f(&mut compiler)?;
|
f(&mut compiler)?;
|
||||||
let code = compiler.pop_code_object();
|
let code = compiler.pop_code_object();
|
||||||
trace!("Compilation completed: {:?}", code);
|
trace!("Compilation completed: {:?}", code);
|
||||||
|
@ -897,7 +897,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
// key:
|
// key:
|
||||||
self.emit(Instruction::LoadConst {
|
self.emit(Instruction::LoadConst {
|
||||||
value: bytecode::Constant::String {
|
value: bytecode::Constant::String {
|
||||||
value: "return".to_string(),
|
value: "return".to_owned(),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
// value:
|
// value:
|
||||||
|
@ -989,11 +989,11 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
let (new_body, doc_str) = get_doc(body);
|
let (new_body, doc_str) = get_doc(body);
|
||||||
|
|
||||||
self.emit(Instruction::LoadName {
|
self.emit(Instruction::LoadName {
|
||||||
name: "__name__".to_string(),
|
name: "__name__".to_owned(),
|
||||||
scope: bytecode::NameScope::Global,
|
scope: bytecode::NameScope::Global,
|
||||||
});
|
});
|
||||||
self.emit(Instruction::StoreName {
|
self.emit(Instruction::StoreName {
|
||||||
name: "__module__".to_string(),
|
name: "__module__".to_owned(),
|
||||||
scope: bytecode::NameScope::Free,
|
scope: bytecode::NameScope::Free,
|
||||||
});
|
});
|
||||||
self.emit(Instruction::LoadConst {
|
self.emit(Instruction::LoadConst {
|
||||||
|
@ -1002,7 +1002,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
self.emit(Instruction::StoreName {
|
self.emit(Instruction::StoreName {
|
||||||
name: "__qualname__".to_string(),
|
name: "__qualname__".to_owned(),
|
||||||
scope: bytecode::NameScope::Free,
|
scope: bytecode::NameScope::Free,
|
||||||
});
|
});
|
||||||
self.compile_statements(new_body)?;
|
self.compile_statements(new_body)?;
|
||||||
|
@ -1090,7 +1090,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
|
|
||||||
self.emit(Instruction::Rotate { amount: 2 });
|
self.emit(Instruction::Rotate { amount: 2 });
|
||||||
self.emit(Instruction::StoreAttr {
|
self.emit(Instruction::StoreAttr {
|
||||||
name: "__doc__".to_string(),
|
name: "__doc__".to_owned(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1171,7 +1171,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
self.set_label(check_asynciter_label);
|
self.set_label(check_asynciter_label);
|
||||||
self.emit(Instruction::Duplicate);
|
self.emit(Instruction::Duplicate);
|
||||||
self.emit(Instruction::LoadName {
|
self.emit(Instruction::LoadName {
|
||||||
name: "StopAsyncIteration".to_string(),
|
name: "StopAsyncIteration".to_owned(),
|
||||||
scope: bytecode::NameScope::Global,
|
scope: bytecode::NameScope::Global,
|
||||||
});
|
});
|
||||||
self.emit(Instruction::CompareOperation {
|
self.emit(Instruction::CompareOperation {
|
||||||
|
@ -1732,7 +1732,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
func: FunctionContext::Function,
|
func: FunctionContext::Function,
|
||||||
};
|
};
|
||||||
|
|
||||||
let name = "<lambda>".to_string();
|
let name = "<lambda>".to_owned();
|
||||||
self.enter_function(&name, args)?;
|
self.enter_function(&name, args)?;
|
||||||
self.compile_expression(body)?;
|
self.compile_expression(body)?;
|
||||||
self.emit(Instruction::ReturnValue);
|
self.emit(Instruction::ReturnValue);
|
||||||
|
@ -1933,7 +1933,7 @@ impl<O: OutputStream> Compiler<O> {
|
||||||
// Create magnificent function <listcomp>:
|
// Create magnificent function <listcomp>:
|
||||||
self.push_output(CodeObject::new(
|
self.push_output(CodeObject::new(
|
||||||
Default::default(),
|
Default::default(),
|
||||||
vec![".0".to_string()],
|
vec![".0".to_owned()],
|
||||||
Varargs::None,
|
Varargs::None,
|
||||||
vec![],
|
vec![],
|
||||||
Varargs::None,
|
Varargs::None,
|
||||||
|
@ -2264,8 +2264,8 @@ mod tests {
|
||||||
|
|
||||||
fn compile_exec(source: &str) -> CodeObject {
|
fn compile_exec(source: &str) -> CodeObject {
|
||||||
let mut compiler: Compiler = Default::default();
|
let mut compiler: Compiler = Default::default();
|
||||||
compiler.source_path = Some("source_path".to_string());
|
compiler.source_path = Some("source_path".to_owned());
|
||||||
compiler.push_new_code_object("<module>".to_string());
|
compiler.push_new_code_object("<module>".to_owned());
|
||||||
let ast = parser::parse_program(&source.to_string()).unwrap();
|
let ast = parser::parse_program(&source.to_string()).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();
|
||||||
|
|
14
src/error.rs
14
src/error.rs
|
@ -62,7 +62,7 @@ impl CompileError {
|
||||||
match parse {
|
match parse {
|
||||||
ParseErrorType::Lexical(LexicalErrorType::IndentationError) => true,
|
ParseErrorType::Lexical(LexicalErrorType::IndentationError) => true,
|
||||||
ParseErrorType::UnrecognizedToken(token, expected) => {
|
ParseErrorType::UnrecognizedToken(token, expected) => {
|
||||||
*token == Tok::Indent || expected.clone() == Some("Indent".to_string())
|
*token == Tok::Indent || expected.clone() == Some("Indent".to_owned())
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
@ -88,14 +88,14 @@ impl fmt::Display for CompileError {
|
||||||
let error_desc = match &self.error {
|
let error_desc = match &self.error {
|
||||||
CompileErrorType::Assign(target) => format!("can't assign to {}", target),
|
CompileErrorType::Assign(target) => format!("can't assign to {}", target),
|
||||||
CompileErrorType::Delete(target) => format!("can't delete {}", target),
|
CompileErrorType::Delete(target) => format!("can't delete {}", target),
|
||||||
CompileErrorType::ExpectExpr => "Expecting expression, got statement".to_string(),
|
CompileErrorType::ExpectExpr => "Expecting expression, got statement".to_owned(),
|
||||||
CompileErrorType::Parse(err) => err.to_string(),
|
CompileErrorType::Parse(err) => err.to_string(),
|
||||||
CompileErrorType::SyntaxError(err) => err.to_string(),
|
CompileErrorType::SyntaxError(err) => err.to_string(),
|
||||||
CompileErrorType::StarArgs => "Two starred expressions in assignment".to_string(),
|
CompileErrorType::StarArgs => "Two starred expressions in assignment".to_owned(),
|
||||||
CompileErrorType::InvalidBreak => "'break' outside loop".to_string(),
|
CompileErrorType::InvalidBreak => "'break' outside loop".to_owned(),
|
||||||
CompileErrorType::InvalidContinue => "'continue' outside loop".to_string(),
|
CompileErrorType::InvalidContinue => "'continue' outside loop".to_owned(),
|
||||||
CompileErrorType::InvalidReturn => "'return' outside function".to_string(),
|
CompileErrorType::InvalidReturn => "'return' outside function".to_owned(),
|
||||||
CompileErrorType::InvalidYield => "'yield' outside function".to_string(),
|
CompileErrorType::InvalidYield => "'yield' outside function".to_owned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(statement) = &self.statement {
|
if let Some(statement) = &self.statement {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue