From e5dc347ccfe92d9d1dd23f0b4a257a1cb3532462 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 31 Jan 2014 16:10:06 -0800 Subject: [PATCH] libsyntax: Remove the `interner_get` function and all uses --- src/libsyntax/ast.rs | 7 ++++--- src/libsyntax/ast_util.rs | 5 ++++- src/libsyntax/parse/parser.rs | 3 ++- src/libsyntax/parse/token.rs | 27 --------------------------- src/libsyntax/print/pprust.rs | 5 +++-- 5 files changed, 13 insertions(+), 34 deletions(-) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a8bbdbd60d3..fd8e9dbfa67 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -14,8 +14,8 @@ use codemap::{Span, Spanned, DUMMY_SP}; use abi::AbiSet; use ast_util; use opt_vec::OptVec; -use parse::token::{InternedString, interner_get, special_idents}; -use parse::token::{str_to_ident}; +use parse::token::{InternedString, special_idents, str_to_ident}; +use parse::token; use std::cell::RefCell; use std::hashmap::HashMap; @@ -126,7 +126,8 @@ pub type Mrk = u32; impl Encodable for Ident { fn encode(&self, s: &mut S) { - s.emit_str(interner_get(self.name)); + let string = token::get_ident(self.name); + s.emit_str(string.get()); } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 405de5c5542..afedb62105b 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -25,7 +25,10 @@ use std::num; pub fn path_name_i(idents: &[Ident]) -> ~str { // FIXME: Bad copies (#2543 -- same for everything else that says "bad") - idents.map(|i| token::interner_get(i.name)).connect("::") + idents.map(|i| { + let string = token::get_ident(i.name); + string.get().to_str() + }).connect("::") } // totally scary function: ignores all but the last element, should have diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 34080ffb624..86913711801 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4178,7 +4178,8 @@ impl Parser { outer_attrs, "path") { Some(d) => dir_path.join(d), None => { - let mod_name = token::interner_get(id.name).to_owned(); + let mod_string = token::get_ident(id.name); + let mod_name = mod_string.get().to_owned(); let default_path_str = mod_name + ".rs"; let secondary_path_str = mod_name + "/mod.rs"; let default_path = dir_path.join(default_path_str.as_slice()); diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 2c57a4effd5..806c84c5553 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -651,11 +651,6 @@ pub fn gensym(str : &str) -> Name { interner.gensym(str) } -// map an interned representation back to a string -pub fn interner_get(name : Name) -> @str { - get_ident_interner().get(name) -} - // maps a string to an identifier with an empty syntax context pub fn str_to_ident(str : &str) -> ast::Ident { ast::Ident::new(intern(str)) @@ -679,28 +674,6 @@ pub fn fresh_name(src : &ast::Ident) -> Name { gensym(format!("{}_{}",ident_to_str(src),num))*/ } -// it looks like there oughta be a str_ptr_eq fn, but no one bothered to implement it? - -// determine whether two @str values are pointer-equal -pub fn str_ptr_eq(a : @str, b : @str) -> bool { - unsafe { - let p : uint = cast::transmute(a); - let q : uint = cast::transmute(b); - let result = p == q; - // got to transmute them back, to make sure the ref count is correct: - let _junk1 : @str = cast::transmute(p); - let _junk2 : @str = cast::transmute(q); - result - } -} - -// return true when two identifiers refer (through the intern table) to the same ptr_eq -// string. This is used to compare identifiers in places where hygienic comparison is -// not wanted (i.e. not lexical vars). -pub fn ident_spelling_eq(a : &ast::Ident, b : &ast::Ident) -> bool { - str_ptr_eq(interner_get(a.name),interner_get(b.name)) -} - // create a fresh mark. pub fn fresh_mark() -> Mrk { gensym("mark") diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 93d912e7522..2e20560b9ca 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -19,7 +19,7 @@ use codemap::{CodeMap, BytePos}; use codemap; use diagnostic; use parse::classify::expr_is_simple_block; -use parse::token::{IdentInterner, interner_get}; +use parse::token::IdentInterner; use parse::{comments, token}; use parse; use print::pp::{break_offset, word, space, zerobreak, hardbreak}; @@ -1544,7 +1544,8 @@ pub fn print_ident(s: &mut State, ident: ast::Ident) { } pub fn print_name(s: &mut State, name: ast::Name) { - word(&mut s.s, interner_get(name)); + let string = token::get_ident(name); + word(&mut s.s, string.get()); } pub fn print_for_decl(s: &mut State, loc: &ast::Local, coll: &ast::Expr) {