Skip to content

Commit eb962c2

Browse files
committed
Add ty_to_symbol methods.
1 parent c040b3b commit eb962c2

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
@@ -2995,6 +2995,7 @@ dependencies = [
29952995
"rustc_cratesio_shim 0.0.0",
29962996
"rustc_data_structures 0.0.0",
29972997
"serialize 0.0.0",
2998+
"syntax_pos 0.0.0",
29982999
]
29993000

30003001
[[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

@@ -1534,6 +1534,17 @@ impl IntTy {
15341534
}
15351535
}
15361536

1537+
pub fn to_symbol(&self) -> Symbol {
1538+
match *self {
1539+
IntTy::Isize => sym::isize,
1540+
IntTy::I8 => sym::i8,
1541+
IntTy::I16 => sym::i16,
1542+
IntTy::I32 => sym::i32,
1543+
IntTy::I64 => sym::i64,
1544+
IntTy::I128 => sym::i128,
1545+
}
1546+
}
1547+
15371548
pub fn val_to_string(&self, val: i128) -> String {
15381549
// Cast to a `u128` so we can correctly print `INT128_MIN`. All integral types
15391550
// are parsed as `u128`, so we wouldn't want to print an extra negative
@@ -1575,6 +1586,17 @@ impl UintTy {
15751586
}
15761587
}
15771588

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

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)