change fn name, return loc info, local name
This commit is contained in:
parent
1d9481fdc8
commit
d6a55d3409
3 changed files with 14 additions and 24 deletions
|
@ -17,7 +17,9 @@ use rustc_middle::ty::{self, Ty, TyCtxt, Variance};
|
||||||
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||||
use rustc_target::abi::FieldIdx;
|
use rustc_target::abi::FieldIdx;
|
||||||
use stable_mir::mir::{CopyNonOverlapping, Statement, UserTypeProjection, VariantIdx};
|
use stable_mir::mir::{CopyNonOverlapping, Statement, UserTypeProjection, VariantIdx};
|
||||||
use stable_mir::ty::{FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy};
|
use stable_mir::ty::{
|
||||||
|
FloatTy, GenericParamDef, IntTy, LineInfo, Movability, RigidTy, Span, TyKind, UintTy,
|
||||||
|
};
|
||||||
use stable_mir::{self, opaque, Context, Filename};
|
use stable_mir::{self, opaque, Context, Filename};
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
@ -50,7 +52,7 @@ impl<'tcx> Context for Tables<'tcx> {
|
||||||
self.tcx.def_path_str(self[def_id])
|
self.tcx.def_path_str(self[def_id])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_span(&self, span: stable_mir::ty::Span) -> String {
|
fn span_to_string(&self, span: stable_mir::ty::Span) -> String {
|
||||||
self.tcx.sess.source_map().span_to_diagnostic_string(self[span])
|
self.tcx.sess.source_map().span_to_diagnostic_string(self[span])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,27 +63,14 @@ impl<'tcx> Context for Tables<'tcx> {
|
||||||
.sess
|
.sess
|
||||||
.source_map()
|
.source_map()
|
||||||
.span_to_filename(self[*span])
|
.span_to_filename(self[*span])
|
||||||
.display(rustc_span::FileNameDisplayPreference::Short)
|
.display(rustc_span::FileNameDisplayPreference::Local)
|
||||||
.to_string(),
|
.to_string(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_lines(&self, span: &Span) -> Vec<stable_mir::ty::LineInfo> {
|
fn get_lines(&self, span: &Span) -> LineInfo {
|
||||||
let lines = &self
|
let lines = &self.tcx.sess.source_map().span_to_location_info(self[*span]);
|
||||||
.tcx
|
LineInfo { start_line: lines.1, start_col: lines.2, end_line: lines.3, end_col: lines.4 }
|
||||||
.sess
|
|
||||||
.source_map()
|
|
||||||
.span_to_lines(self[*span])
|
|
||||||
.unwrap()
|
|
||||||
.lines
|
|
||||||
.iter()
|
|
||||||
.map(|line| stable_mir::ty::LineInfo {
|
|
||||||
line_index: line.line_index + 1,
|
|
||||||
start_col: line.start_col.0 + 1,
|
|
||||||
end_col: line.end_col.0 + 1,
|
|
||||||
})
|
|
||||||
.collect::<Vec<stable_mir::ty::LineInfo>>();
|
|
||||||
lines.to_vec()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn def_kind(&mut self, def_id: stable_mir::DefId) -> stable_mir::DefKind {
|
fn def_kind(&mut self, def_id: stable_mir::DefId) -> stable_mir::DefKind {
|
||||||
|
|
|
@ -201,13 +201,13 @@ pub trait Context {
|
||||||
fn name_of_def_id(&self, def_id: DefId) -> String;
|
fn name_of_def_id(&self, def_id: DefId) -> String;
|
||||||
|
|
||||||
/// Returns printable, human readable form of `Span`
|
/// Returns printable, human readable form of `Span`
|
||||||
fn print_span(&self, span: Span) -> String;
|
fn span_to_string(&self, span: Span) -> String;
|
||||||
|
|
||||||
/// Return filename from given `Span`, for diagnostic purposes
|
/// Return filename from given `Span`, for diagnostic purposes
|
||||||
fn get_filename(&self, span: &Span) -> Filename;
|
fn get_filename(&self, span: &Span) -> Filename;
|
||||||
|
|
||||||
/// Return lines corresponding to this `Span`
|
/// Return lines corresponding to this `Span`
|
||||||
fn get_lines(&self, span: &Span) -> Vec<LineInfo>;
|
fn get_lines(&self, span: &Span) -> LineInfo;
|
||||||
|
|
||||||
/// Returns the `kind` of given `DefId`
|
/// Returns the `kind` of given `DefId`
|
||||||
fn def_kind(&mut self, def_id: DefId) -> DefKind;
|
fn def_kind(&mut self, def_id: DefId) -> DefKind;
|
||||||
|
|
|
@ -81,7 +81,7 @@ impl Debug for Span {
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("Span")
|
f.debug_struct("Span")
|
||||||
.field("id", &self.0)
|
.field("id", &self.0)
|
||||||
.field("repr", &with(|cx| cx.print_span(*self)))
|
.field("repr", &with(|cx| cx.span_to_string(*self)))
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ impl Span {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return lines that corespond to this `Span`
|
/// Return lines that corespond to this `Span`
|
||||||
pub fn get_lines(&self) -> Vec<LineInfo> {
|
pub fn get_lines(&self) -> LineInfo {
|
||||||
with(|c| c.get_lines(&self))
|
with(|c| c.get_lines(&self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,8 +102,9 @@ impl Span {
|
||||||
/// Information you get from `Span` in a struct form.
|
/// Information you get from `Span` in a struct form.
|
||||||
/// Line and col start from 1.
|
/// Line and col start from 1.
|
||||||
pub struct LineInfo {
|
pub struct LineInfo {
|
||||||
pub line_index: usize,
|
pub start_line: usize,
|
||||||
pub start_col: usize,
|
pub start_col: usize,
|
||||||
|
pub end_line: usize,
|
||||||
pub end_col: usize,
|
pub end_col: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue