remove get_ident
and get_name
, make as_str
sound
This commit is contained in:
parent
9ca511cf63
commit
00a5e66f81
68 changed files with 433 additions and 534 deletions
|
@ -15,6 +15,7 @@ use codemap::{self, Span, CodeMap, FileMap};
|
|||
use diagnostic::{SpanHandler, Handler, Auto, FatalError};
|
||||
use parse::attr::ParserAttr;
|
||||
use parse::parser::Parser;
|
||||
use parse::token::InternedString;
|
||||
use ptr::P;
|
||||
use str::char_at;
|
||||
|
||||
|
@ -439,7 +440,7 @@ fn looks_like_width_suffix(first_chars: &[char], s: &str) -> bool {
|
|||
fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>,
|
||||
sd: &SpanHandler, sp: Span) -> ast::Lit_ {
|
||||
debug!("filtered_float_lit: {}, {:?}", data, suffix);
|
||||
match suffix {
|
||||
match suffix.as_ref().map(|s| &**s) {
|
||||
Some("f32") => ast::LitFloat(data, ast::TyF32),
|
||||
Some("f64") => ast::LitFloat(data, ast::TyF64),
|
||||
Some(suf) => {
|
||||
|
@ -457,12 +458,13 @@ fn filtered_float_lit(data: token::InternedString, suffix: Option<&str>,
|
|||
None => ast::LitFloatUnsuffixed(data)
|
||||
}
|
||||
}
|
||||
pub fn float_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) -> ast::Lit_ {
|
||||
pub fn float_lit(s: &str, suffix: Option<InternedString>,
|
||||
sd: &SpanHandler, sp: Span) -> ast::Lit_ {
|
||||
debug!("float_lit: {:?}, {:?}", s, suffix);
|
||||
// FIXME #2252: bounds checking float literals is deferred until trans
|
||||
let s = s.chars().filter(|&c| c != '_').collect::<String>();
|
||||
let data = token::intern_and_get_ident(&*s);
|
||||
filtered_float_lit(data, suffix, sd, sp)
|
||||
let data = token::intern_and_get_ident(&s);
|
||||
filtered_float_lit(data, suffix.as_ref().map(|s| &**s), sd, sp)
|
||||
}
|
||||
|
||||
/// Parse a string representing a byte literal into its final form. Similar to `char_lit`
|
||||
|
@ -557,7 +559,11 @@ pub fn binary_lit(lit: &str) -> Rc<Vec<u8>> {
|
|||
Rc::new(res)
|
||||
}
|
||||
|
||||
pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) -> ast::Lit_ {
|
||||
pub fn integer_lit(s: &str,
|
||||
suffix: Option<InternedString>,
|
||||
sd: &SpanHandler,
|
||||
sp: Span)
|
||||
-> ast::Lit_ {
|
||||
// s can only be ascii, byte indexing is fine
|
||||
|
||||
let s2 = s.chars().filter(|&c| c != '_').collect::<String>();
|
||||
|
@ -579,8 +585,8 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) ->
|
|||
}
|
||||
|
||||
// 1f64 and 2f32 etc. are valid float literals.
|
||||
match suffix {
|
||||
Some(suf) if looks_like_width_suffix(&['f'], suf) => {
|
||||
if let Some(ref suf) = suffix {
|
||||
if looks_like_width_suffix(&['f'], suf) {
|
||||
match base {
|
||||
16 => sd.span_err(sp, "hexadecimal float literal is not supported"),
|
||||
8 => sd.span_err(sp, "octal float literal is not supported"),
|
||||
|
@ -588,18 +594,17 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) ->
|
|||
_ => ()
|
||||
}
|
||||
let ident = token::intern_and_get_ident(&*s);
|
||||
return filtered_float_lit(ident, suffix, sd, sp)
|
||||
return filtered_float_lit(ident, Some(&**suf), sd, sp)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
if base != 10 {
|
||||
s = &s[2..];
|
||||
}
|
||||
|
||||
if let Some(suf) = suffix {
|
||||
if let Some(ref suf) = suffix {
|
||||
if suf.is_empty() { sd.span_bug(sp, "found empty literal suffix in Some")}
|
||||
ty = match suf {
|
||||
ty = match &**suf {
|
||||
"isize" => ast::SignedIntLit(ast::TyIs, ast::Plus),
|
||||
"i8" => ast::SignedIntLit(ast::TyI8, ast::Plus),
|
||||
"i16" => ast::SignedIntLit(ast::TyI16, ast::Plus),
|
||||
|
@ -739,8 +744,8 @@ mod tests {
|
|||
Some(&ast::TtToken(_, token::Ident(name_zip, token::Plain))),
|
||||
Some(&ast::TtDelimited(_, ref macro_delimed)),
|
||||
)
|
||||
if name_macro_rules.as_str() == "macro_rules"
|
||||
&& name_zip.as_str() == "zip" => {
|
||||
if name_macro_rules.name == "macro_rules"
|
||||
&& name_zip.name == "zip" => {
|
||||
let tts = ¯o_delimed.tts[..];
|
||||
match (tts.len(), tts.get(0), tts.get(1), tts.get(2)) {
|
||||
(
|
||||
|
@ -755,10 +760,10 @@ mod tests {
|
|||
(
|
||||
2,
|
||||
Some(&ast::TtToken(_, token::Dollar)),
|
||||
Some(&ast::TtToken(_, token::Ident(name, token::Plain))),
|
||||
Some(&ast::TtToken(_, token::Ident(ident, token::Plain))),
|
||||
)
|
||||
if first_delimed.delim == token::Paren
|
||||
&& name.as_str() == "a" => {},
|
||||
&& ident.name == "a" => {},
|
||||
_ => panic!("value 3: {:?}", **first_delimed),
|
||||
}
|
||||
let tts = &second_delimed.tts[..];
|
||||
|
@ -766,10 +771,10 @@ mod tests {
|
|||
(
|
||||
2,
|
||||
Some(&ast::TtToken(_, token::Dollar)),
|
||||
Some(&ast::TtToken(_, token::Ident(name, token::Plain))),
|
||||
Some(&ast::TtToken(_, token::Ident(ident, token::Plain))),
|
||||
)
|
||||
if second_delimed.delim == token::Paren
|
||||
&& name.as_str() == "a" => {},
|
||||
&& ident.name == "a" => {},
|
||||
_ => panic!("value 4: {:?}", **second_delimed),
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue