fix: fix span in lalrpop

This commit is contained in:
Edgar 2024-03-04 07:55:12 +01:00
parent 466b7687a7
commit f71abb0b26
No known key found for this signature in database
GPG key ID: 70ADAE8F35904387
3 changed files with 20 additions and 25 deletions

View file

@ -85,6 +85,7 @@ pub fn lowering_error_to_report(
.finish() .finish()
}, },
LoweringError::UnexpectedType { span, found, expected } => { LoweringError::UnexpectedType { span, found, expected } => {
dbg!(span);
let mut labels = vec![ let mut labels = vec![
Label::new((path.clone(), span.into())) Label::new((path.clone(), span.into()))
.with_message(format!("Unexpected type '{}', expected '{}'", found, expected.kind)) .with_message(format!("Unexpected type '{}', expected '{}'", found, expected.kind))

View file

@ -479,8 +479,6 @@ fn lower_assign(builder: &mut BodyBuilder, info: &ast::AssignStmt) -> Result<(),
kind: ty, kind: ty,
}; };
dbg!("here1");
for _ in 0..info.deref_times { for _ in 0..info.deref_times {
match &ty.kind { match &ty.kind {
TypeKind::Ptr(is_mut, inner) => { TypeKind::Ptr(is_mut, inner) => {
@ -500,12 +498,8 @@ fn lower_assign(builder: &mut BodyBuilder, info: &ast::AssignStmt) -> Result<(),
place.projection.push(PlaceElem::Deref); place.projection.push(PlaceElem::Deref);
} }
dbg!("here2");
let (rvalue, _ty, _span) = lower_expr(builder, &info.value, Some(&ty))?; let (rvalue, _ty, _span) = lower_expr(builder, &info.value, Some(&ty))?;
dbg!("here3");
builder.statements.push(Statement { builder.statements.push(Statement {
span: Some(info.name.first.span), span: Some(info.name.first.span),
kind: StatementKind::Assign(place, rvalue), kind: StatementKind::Assign(place, rvalue),

View file

@ -348,34 +348,34 @@ pub(crate) Expression: ast::Expression = {
} }
pub BinaryFirstLvlOp: ast::BinaryOp = { pub BinaryFirstLvlOp: ast::BinaryOp = {
<lo:@L> "==" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::Eq, ast::Span::new(hi, lo)), <lo:@L> "==" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::Eq, ast::Span::new(lo, hi)),
<lo:@L> "!=" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::NotEq, ast::Span::new(hi, lo)), <lo:@L> "!=" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::NotEq, ast::Span::new(lo, hi)),
<lo:@L> "<" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::Lt, ast::Span::new(hi, lo)), <lo:@L> "<" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::Lt, ast::Span::new(lo, hi)),
<lo:@L> ">" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::Gt, ast::Span::new(hi, lo)), <lo:@L> ">" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::Gt, ast::Span::new(lo, hi)),
<lo:@L> "<=" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::LtEq, ast::Span::new(hi, lo)), <lo:@L> "<=" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::LtEq, ast::Span::new(lo, hi)),
<lo:@L> ">=" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::GtEq, ast::Span::new(hi, lo)), <lo:@L> ">=" <hi:@R> => ast::BinaryOp::Compare(ast::CmpOp::GtEq, ast::Span::new(lo, hi)),
<lo:@L> "&&" <hi:@R> => ast::BinaryOp::Logic(ast::LogicOp::And, ast::Span::new(hi, lo)), <lo:@L> "&&" <hi:@R> => ast::BinaryOp::Logic(ast::LogicOp::And, ast::Span::new(lo, hi)),
<lo:@L> "||" <hi:@R> => ast::BinaryOp::Logic(ast::LogicOp::Or, ast::Span::new(hi, lo)), <lo:@L> "||" <hi:@R> => ast::BinaryOp::Logic(ast::LogicOp::Or, ast::Span::new(lo, hi)),
} }
pub BinarySecondLvlOp: ast::BinaryOp = { pub BinarySecondLvlOp: ast::BinaryOp = {
<lo:@L> "/" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Div, ast::Span::new(hi, lo)), <lo:@L> "/" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Div, ast::Span::new(lo, hi)),
<lo:@L> "*" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Mul, ast::Span::new(hi, lo)), <lo:@L> "*" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Mul, ast::Span::new(lo, hi)),
<lo:@L> "%" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Mod, ast::Span::new(hi, lo)), <lo:@L> "%" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Mod, ast::Span::new(lo, hi)),
} }
pub BinaryThirdLvlOp: ast::BinaryOp = { pub BinaryThirdLvlOp: ast::BinaryOp = {
<lo:@L> "+" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Add, ast::Span::new(hi, lo)), <lo:@L> "+" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Add, ast::Span::new(lo, hi)),
<lo:@L> "-" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Sub, ast::Span::new(hi, lo)), <lo:@L> "-" <hi:@R> => ast::BinaryOp::Arith(ast::ArithOp::Sub, ast::Span::new(lo, hi)),
<lo:@L> "&" <hi:@R> => ast::BinaryOp::Bitwise(ast::BitwiseOp::And, ast::Span::new(hi, lo)), <lo:@L> "&" <hi:@R> => ast::BinaryOp::Bitwise(ast::BitwiseOp::And, ast::Span::new(lo, hi)),
<lo:@L> "|" <hi:@R> => ast::BinaryOp::Bitwise(ast::BitwiseOp::Or, ast::Span::new(hi, lo)), <lo:@L> "|" <hi:@R> => ast::BinaryOp::Bitwise(ast::BitwiseOp::Or, ast::Span::new(lo, hi)),
<lo:@L> "^" <hi:@R> => ast::BinaryOp::Bitwise(ast::BitwiseOp::Xor, ast::Span::new(hi, lo)), <lo:@L> "^" <hi:@R> => ast::BinaryOp::Bitwise(ast::BitwiseOp::Xor, ast::Span::new(lo, hi)),
} }
pub UnaryOp: ast::UnaryOp = { pub UnaryOp: ast::UnaryOp = {
<lo:@L> "-" <hi:@R> => ast::UnaryOp::ArithNeg(ast::Span::new(hi, lo)), <lo:@L> "-" <hi:@R> => ast::UnaryOp::ArithNeg(ast::Span::new(lo, hi)),
<lo:@L> "!" <hi:@R> => ast::UnaryOp::LogicalNot(ast::Span::new(hi, lo)), <lo:@L> "!" <hi:@R> => ast::UnaryOp::LogicalNot(ast::Span::new(lo, hi)),
<lo:@L> "~" <hi:@R> => ast::UnaryOp::BitwiseNot(ast::Span::new(hi, lo)), <lo:@L> "~" <hi:@R> => ast::UnaryOp::BitwiseNot(ast::Span::new(lo, hi)),
} }
pub(crate) ValueExpr: ast::ValueExpr = { pub(crate) ValueExpr: ast::ValueExpr = {