Skip to content
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

Rename codemap to source map #173

Merged
merged 1 commit into from
Apr 23, 2019
Merged
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
20 changes: 10 additions & 10 deletions src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ impl TokenStream {

#[cfg(span_locations)]
fn get_cursor(src: &str) -> Cursor {
// Create a dummy file & add it to the codemap
CODEMAP.with(|cm| {
// Create a dummy file & add it to the source map
SOURCE_MAP.with(|cm| {
let mut cm = cm.borrow_mut();
let name = format!("<parsed string {}>", cm.files.len());
let span = cm.add_file(&name, src);
Expand All @@ -56,7 +56,7 @@ impl FromStr for TokenStream {
type Err = LexError;

fn from_str(src: &str) -> Result<TokenStream, LexError> {
// Create a dummy file & add it to the codemap
// Create a dummy file & add it to the source map
let cursor = get_cursor(src);

match token_stream(cursor) {
Expand Down Expand Up @@ -225,7 +225,7 @@ pub struct LineColumn {

#[cfg(span_locations)]
thread_local! {
static CODEMAP: RefCell<Codemap> = RefCell::new(Codemap {
static SOURCE_MAP: RefCell<SourceMap> = RefCell::new(SourceMap {
// NOTE: We start with a single dummy file which all call_site() and
// def_site() spans reference.
files: vec![{
Expand Down Expand Up @@ -295,12 +295,12 @@ fn lines_offsets(s: &str) -> Vec<usize> {
}

#[cfg(span_locations)]
struct Codemap {
struct SourceMap {
files: Vec<FileInfo>,
}

#[cfg(span_locations)]
impl Codemap {
impl SourceMap {
fn next_start_pos(&self) -> u32 {
// Add 1 so there's always space between files.
//
Expand Down Expand Up @@ -384,7 +384,7 @@ impl Span {

#[cfg(procmacro2_semver_exempt)]
pub fn source_file(&self) -> SourceFile {
CODEMAP.with(|cm| {
SOURCE_MAP.with(|cm| {
let cm = cm.borrow();
let fi = cm.fileinfo(*self);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the cm variables (here and elsewhere) could've been renamed to sm as well (but this is a very minor nitpick).

SourceFile {
Expand All @@ -395,7 +395,7 @@ impl Span {

#[cfg(span_locations)]
pub fn start(&self) -> LineColumn {
CODEMAP.with(|cm| {
SOURCE_MAP.with(|cm| {
let cm = cm.borrow();
let fi = cm.fileinfo(*self);
fi.offset_line_column(self.lo as usize)
Expand All @@ -404,7 +404,7 @@ impl Span {

#[cfg(span_locations)]
pub fn end(&self) -> LineColumn {
CODEMAP.with(|cm| {
SOURCE_MAP.with(|cm| {
let cm = cm.borrow();
let fi = cm.fileinfo(*self);
fi.offset_line_column(self.hi as usize)
Expand All @@ -413,7 +413,7 @@ impl Span {

#[cfg(procmacro2_semver_exempt)]
pub fn join(&self, other: Span) -> Option<Span> {
CODEMAP.with(|cm| {
SOURCE_MAP.with(|cm| {
let cm = cm.borrow();
// If `other` is not within the same FileInfo as us, return None.
if !cm.fileinfo(*self).span_within(other) {
Expand Down