|
1 | 1 | use rustc_index::IndexSlice;
|
2 |
| -use rustc_middle::{mir::*, thir::*, ty::Ty}; |
| 2 | +use rustc_middle::ty::{self, Ty}; |
| 3 | +use rustc_middle::{mir::*, thir::*}; |
3 | 4 | use rustc_span::Span;
|
4 | 5 |
|
5 | 6 | use super::{PResult, ParseCtxt, ParseError};
|
@@ -159,6 +160,14 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
|
159 | 160 | );
|
160 | 161 | self.parse_local_decls(local_decls.iter().copied())?;
|
161 | 162 |
|
| 163 | + let (debuginfo, rest) = parse_by_kind!(self, rest, _, "body with debuginfo", |
| 164 | + ExprKind::Block { block } => { |
| 165 | + let block = &self.thir[*block]; |
| 166 | + (&block.stmts, block.expr.unwrap()) |
| 167 | + }, |
| 168 | + ); |
| 169 | + self.parse_debuginfo(debuginfo.iter().copied())?; |
| 170 | + |
162 | 171 | let block_defs = parse_by_kind!(self, rest, _, "body with block defs",
|
163 | 172 | ExprKind::Block { block } => &self.thir[*block].stmts,
|
164 | 173 | );
|
@@ -195,6 +204,52 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
|
195 | 204 | Ok(())
|
196 | 205 | }
|
197 | 206 |
|
| 207 | + fn parse_debuginfo(&mut self, stmts: impl Iterator<Item = StmtId>) -> PResult<()> { |
| 208 | + for stmt in stmts { |
| 209 | + let stmt = &self.thir[stmt]; |
| 210 | + let expr = match stmt.kind { |
| 211 | + StmtKind::Let { span, .. } => { |
| 212 | + return Err(ParseError { |
| 213 | + span, |
| 214 | + item_description: format!("{:?}", stmt), |
| 215 | + expected: "debuginfo".to_string(), |
| 216 | + }); |
| 217 | + } |
| 218 | + StmtKind::Expr { expr, .. } => expr, |
| 219 | + }; |
| 220 | + let span = self.thir[expr].span; |
| 221 | + let (name, operand) = parse_by_kind!(self, expr, _, "debuginfo", |
| 222 | + @call("mir_debuginfo", args) => { |
| 223 | + (args[0], args[1]) |
| 224 | + }, |
| 225 | + ); |
| 226 | + let name = parse_by_kind!(self, name, _, "debuginfo", |
| 227 | + ExprKind::Literal { lit, neg: false } => lit, |
| 228 | + ); |
| 229 | + let Some(name) = name.node.str() else { |
| 230 | + return Err(ParseError { |
| 231 | + span, |
| 232 | + item_description: format!("{:?}", name), |
| 233 | + expected: "string".to_string(), |
| 234 | + }); |
| 235 | + }; |
| 236 | + let operand = self.parse_operand(operand)?; |
| 237 | + let value = match operand { |
| 238 | + Operand::Constant(c) => VarDebugInfoContents::Const(*c), |
| 239 | + Operand::Copy(p) | Operand::Move(p) => VarDebugInfoContents::Place(p), |
| 240 | + }; |
| 241 | + let dbginfo = VarDebugInfo { |
| 242 | + name, |
| 243 | + source_info: SourceInfo { span, scope: self.source_scope }, |
| 244 | + argument_index: None, |
| 245 | + value, |
| 246 | + }; |
| 247 | + self.body.var_debug_info.push(dbginfo); |
| 248 | + } |
| 249 | + |
| 250 | + Ok(()) |
| 251 | + } |
| 252 | + |
198 | 253 | fn parse_let_statement(&mut self, stmt_id: StmtId) -> PResult<(LocalVarId, Ty<'tcx>, Span)> {
|
199 | 254 | let pattern = match &self.thir[stmt_id].kind {
|
200 | 255 | StmtKind::Let { pattern, .. } => pattern,
|
|
0 commit comments