Skip to content

more location -> start() #4957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ impl Compiler {

fn compile_statement(&mut self, statement: &ast::Stmt) -> CompileResult<()> {
trace!("Compiling {:?}", statement);
self.set_source_location(statement.location);
self.set_source_location(statement.start());
use ast::StmtKind::*;

match &statement.node {
Expand Down Expand Up @@ -598,8 +598,9 @@ impl Compiler {

let from_list = if import_star {
if self.ctx.in_func() {
return Err(self
.error_loc(CodegenErrorType::FunctionImportStar, statement.location));
return Err(
self.error_loc(CodegenErrorType::FunctionImportStar, statement.start())
);
}
vec![ConstantData::Str {
value: "*".to_owned(),
Expand Down Expand Up @@ -800,7 +801,7 @@ impl Compiler {
emit!(self, Instruction::Break { target: end });
}
None => {
return Err(self.error_loc(CodegenErrorType::InvalidBreak, statement.location));
return Err(self.error_loc(CodegenErrorType::InvalidBreak, statement.start()));
}
},
Continue => match self.ctx.loop_data {
Expand All @@ -809,13 +810,13 @@ impl Compiler {
}
None => {
return Err(
self.error_loc(CodegenErrorType::InvalidContinue, statement.location)
self.error_loc(CodegenErrorType::InvalidContinue, statement.start())
);
}
},
Return { value } => {
if !self.ctx.in_func() {
return Err(self.error_loc(CodegenErrorType::InvalidReturn, statement.location));
return Err(self.error_loc(CodegenErrorType::InvalidReturn, statement.start()));
}
match value {
Some(v) => {
Expand All @@ -825,10 +826,8 @@ impl Compiler {
.flags
.contains(bytecode::CodeFlags::IS_GENERATOR)
{
return Err(self.error_loc(
CodegenErrorType::AsyncReturnValue,
statement.location,
));
return Err(self
.error_loc(CodegenErrorType::AsyncReturnValue, statement.start()));
}
self.compile_expression(v)?;
}
Expand Down Expand Up @@ -1487,7 +1486,7 @@ impl Compiler {

match &item.optional_vars {
Some(var) => {
self.set_source_location(var.location);
self.set_source_location(var.start());
self.compile_store(var)?;
}
None => {
Expand Down Expand Up @@ -1763,7 +1762,7 @@ impl Compiler {
.ok_or_else(|| {
self.error_loc(
CodegenErrorType::TooManyStarUnpack,
target.location,
target.start(),
)
})?;
let args = bytecode::UnpackExArgs { before, after };
Expand Down Expand Up @@ -2038,7 +2037,7 @@ impl Compiler {

fn compile_expression(&mut self, expression: &ast::Expr) -> CompileResult<()> {
trace!("Compiling {:?}", expression);
self.set_source_location(expression.location);
self.set_source_location(expression.start());

use ast::ExprKind::*;
match &expression.node {
Expand Down
8 changes: 4 additions & 4 deletions compiler/codegen/src/symboltable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ impl SymbolTableBuilder {
} else {
SymbolUsage::Parameter
};
self.register_name(&parameter.node.arg, usage, parameter.location)
self.register_name(&parameter.node.arg, usage, parameter.start())
}

fn scan_parameters_annotations(&mut self, parameters: &[ast::Arg]) -> SymbolTableResult {
Expand All @@ -635,7 +635,7 @@ impl SymbolTableBuilder {

fn scan_statement(&mut self, statement: &ast::Stmt) -> SymbolTableResult {
use ast::StmtKind::*;
let location = statement.location;
let location = statement.start();
if let ImportFrom { module, names, .. } = &statement.node {
if module.as_deref() == Some("__future__") {
for feature in names {
Expand Down Expand Up @@ -867,7 +867,7 @@ impl SymbolTableBuilder {
context: ExpressionContext,
) -> SymbolTableResult {
use ast::ExprKind::*;
let location = expression.location;
let location = expression.start();
match &expression.node {
BinOp { left, right, .. } => {
self.scan_expression(left, context)?;
Expand Down Expand Up @@ -1004,7 +1004,7 @@ impl SymbolTableBuilder {
}
}
Lambda { args, body } => {
self.enter_function("lambda", args, expression.location.row())?;
self.enter_function("lambda", args, expression.start().row())?;
match context {
ExpressionContext::IterDefinitionExp => {
self.scan_expression(body, ExpressionContext::IterDefinitionExp)?;
Expand Down