Skip to content

Commit 21f2844

Browse files
committed
Add to_symbol methods.
1 parent 9c7d28d commit 21f2844

File tree

5 files changed

+36
-4
lines changed

5 files changed

+36
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,6 +3009,7 @@ dependencies = [
30093009
"rustc_cratesio_shim 0.0.0",
30103010
"rustc_data_structures 0.0.0",
30113011
"serialize 0.0.0",
3012+
"syntax_pos 0.0.0",
30123013
]
30133014

30143015
[[package]]

src/librustc_target/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ log = "0.4"
1515
rustc_cratesio_shim = { path = "../librustc_cratesio_shim" }
1616
rustc_data_structures = { path = "../librustc_data_structures" }
1717
serialize = { path = "../libserialize" }
18+
syntax_pos = { path = "../libsyntax_pos" }

src/librustc_target/abi/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::fmt;
77
use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive};
88

99
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
10+
use syntax_pos::symbol::{sym, Symbol};
1011

1112
pub mod call;
1213

@@ -552,6 +553,13 @@ impl FloatTy {
552553
}
553554
}
554555

556+
pub fn to_symbol(self) -> Symbol {
557+
match self {
558+
FloatTy::F32 => sym::f32,
559+
FloatTy::F64 => sym::f64,
560+
}
561+
}
562+
555563
pub fn bit_width(self) -> usize {
556564
match self {
557565
FloatTy::F32 => 32,

src/libsyntax/ast.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::parse::token;
1010
use crate::print::pprust;
1111
use crate::ptr::P;
1212
use crate::source_map::{dummy_spanned, respan, Spanned};
13-
use crate::symbol::{kw, Symbol};
13+
use crate::symbol::{kw, sym, Symbol};
1414
use crate::tokenstream::TokenStream;
1515
use crate::ThinVec;
1616

@@ -1531,6 +1531,17 @@ impl IntTy {
15311531
}
15321532
}
15331533

1534+
pub fn to_symbol(&self) -> Symbol {
1535+
match *self {
1536+
IntTy::Isize => sym::isize,
1537+
IntTy::I8 => sym::i8,
1538+
IntTy::I16 => sym::i16,
1539+
IntTy::I32 => sym::i32,
1540+
IntTy::I64 => sym::i64,
1541+
IntTy::I128 => sym::i128,
1542+
}
1543+
}
1544+
15341545
pub fn val_to_string(&self, val: i128) -> String {
15351546
// Cast to a `u128` so we can correctly print `INT128_MIN`. All integral types
15361547
// are parsed as `u128`, so we wouldn't want to print an extra negative
@@ -1572,6 +1583,17 @@ impl UintTy {
15721583
}
15731584
}
15741585

1586+
pub fn to_symbol(&self) -> Symbol {
1587+
match *self {
1588+
UintTy::Usize => sym::usize,
1589+
UintTy::U8 => sym::u8,
1590+
UintTy::U16 => sym::u16,
1591+
UintTy::U32 => sym::u32,
1592+
UintTy::U64 => sym::u64,
1593+
UintTy::U128 => sym::u128,
1594+
}
1595+
}
1596+
15751597
pub fn val_to_string(&self, val: u128) -> String {
15761598
format!("{}{}", val, self.ty_to_string())
15771599
}

src/libsyntax/parse/literal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,14 +193,14 @@ impl LitKind {
193193
}
194194
LitKind::Int(n, ty) => {
195195
let suffix = match ty {
196-
ast::LitIntType::Unsigned(ty) => Some(Symbol::intern(ty.ty_to_string())),
197-
ast::LitIntType::Signed(ty) => Some(Symbol::intern(ty.ty_to_string())),
196+
ast::LitIntType::Unsigned(ty) => Some(ty.to_symbol()),
197+
ast::LitIntType::Signed(ty) => Some(ty.to_symbol()),
198198
ast::LitIntType::Unsuffixed => None,
199199
};
200200
(token::Integer, sym::integer(n), suffix)
201201
}
202202
LitKind::Float(symbol, ty) => {
203-
(token::Float, symbol, Some(Symbol::intern(ty.ty_to_string())))
203+
(token::Float, symbol, Some(ty.to_symbol()))
204204
}
205205
LitKind::FloatUnsuffixed(symbol) => {
206206
(token::Float, symbol, None)

0 commit comments

Comments
 (0)