Make Location Copy and remove all location.clone()s

This commit is contained in:
Noah 2020-03-13 09:01:10 -05:00
parent 867152880a
commit 04606e9057

View file

@ -262,7 +262,7 @@ impl<O: OutputStream> Compiler<O> {
return Err(CompileError { return Err(CompileError {
statement: None, statement: None,
error: CompileErrorType::ExpectExpr, error: CompileErrorType::ExpectExpr,
location: statement.location.clone(), location: statement.location,
source_path: None, source_path: None,
}); });
} }
@ -306,7 +306,7 @@ impl<O: OutputStream> Compiler<O> {
fn compile_statement(&mut self, statement: &ast::Statement) -> Result<(), CompileError> { fn compile_statement(&mut self, statement: &ast::Statement) -> Result<(), CompileError> {
trace!("Compiling {:?}", statement); trace!("Compiling {:?}", statement);
self.set_source_location(&statement.location); self.set_source_location(statement.location);
use ast::StatementType::*; use ast::StatementType::*;
match &statement.node { match &statement.node {
@ -542,7 +542,7 @@ impl<O: OutputStream> Compiler<O> {
return Err(CompileError { return Err(CompileError {
statement: None, statement: None,
error: CompileErrorType::InvalidBreak, error: CompileErrorType::InvalidBreak,
location: statement.location.clone(), location: statement.location,
source_path: None, source_path: None,
}); });
} }
@ -553,7 +553,7 @@ impl<O: OutputStream> Compiler<O> {
return Err(CompileError { return Err(CompileError {
statement: None, statement: None,
error: CompileErrorType::InvalidContinue, error: CompileErrorType::InvalidContinue,
location: statement.location.clone(), location: statement.location,
source_path: None, source_path: None,
}); });
} }
@ -564,7 +564,7 @@ impl<O: OutputStream> Compiler<O> {
return Err(CompileError { return Err(CompileError {
statement: None, statement: None,
error: CompileErrorType::InvalidReturn, error: CompileErrorType::InvalidReturn,
location: statement.location.clone(), location: statement.location,
source_path: None, source_path: None,
}); });
} }
@ -643,7 +643,7 @@ impl<O: OutputStream> Compiler<O> {
return Err(CompileError { return Err(CompileError {
statement: None, statement: None,
error: CompileErrorType::Delete(expression.name()), error: CompileErrorType::Delete(expression.name()),
location: self.current_source_location.clone(), location: self.current_source_location,
source_path: None, source_path: None,
}); });
} }
@ -1348,7 +1348,7 @@ impl<O: OutputStream> Compiler<O> {
return Err(CompileError { return Err(CompileError {
statement: None, statement: None,
error: CompileErrorType::StarArgs, error: CompileErrorType::StarArgs,
location: self.current_source_location.clone(), location: self.current_source_location,
source_path: None, source_path: None,
}); });
} else { } else {
@ -1379,7 +1379,7 @@ impl<O: OutputStream> Compiler<O> {
return Err(CompileError { return Err(CompileError {
statement: None, statement: None,
error: CompileErrorType::Assign(target.name()), error: CompileErrorType::Assign(target.name()),
location: self.current_source_location.clone(), location: self.current_source_location,
source_path: None, source_path: None,
}); });
} }
@ -1570,7 +1570,7 @@ impl<O: OutputStream> Compiler<O> {
fn compile_expression(&mut self, expression: &ast::Expression) -> Result<(), CompileError> { fn compile_expression(&mut self, expression: &ast::Expression) -> Result<(), CompileError> {
trace!("Compiling {:?}", expression); trace!("Compiling {:?}", expression);
self.set_source_location(&expression.location); self.set_source_location(expression.location);
use ast::ExpressionType::*; use ast::ExpressionType::*;
match &expression.node { match &expression.node {
@ -1665,7 +1665,7 @@ impl<O: OutputStream> Compiler<O> {
return Err(CompileError { return Err(CompileError {
statement: Option::None, statement: Option::None,
error: CompileErrorType::InvalidYield, error: CompileErrorType::InvalidYield,
location: self.current_source_location.clone(), location: self.current_source_location,
source_path: Option::None, source_path: Option::None,
}); });
} }
@ -1763,7 +1763,7 @@ impl<O: OutputStream> Compiler<O> {
error: CompileErrorType::SyntaxError(std::string::String::from( error: CompileErrorType::SyntaxError(std::string::String::from(
"Invalid starred expression", "Invalid starred expression",
)), )),
location: self.current_source_location.clone(), location: self.current_source_location,
source_path: Option::None, source_path: Option::None,
}); });
} }
@ -2182,8 +2182,8 @@ impl<O: OutputStream> Compiler<O> {
self.current_output().set_label(label) self.current_output().set_label(label)
} }
fn set_source_location(&mut self, location: &ast::Location) { fn set_source_location(&mut self, location: ast::Location) {
self.current_source_location = location.clone(); self.current_source_location = location;
} }
fn get_source_line_number(&mut self) -> usize { fn get_source_line_number(&mut self) -> usize {