token_to_ident takes argument by reference

This commit is contained in:
John Clements 2013-06-03 23:00:49 -07:00
parent 3203595471
commit 04a691a511
21 changed files with 48 additions and 46 deletions

View file

@ -296,7 +296,7 @@ impl Session_ {
// pointless function, now... // pointless function, now...
pub fn str_of(@self, id: ast::ident) -> @~str { pub fn str_of(@self, id: ast::ident) -> @~str {
token::ident_to_str(id) token::ident_to_str(&id)
} }
// pointless function, now... // pointless function, now...

View file

@ -177,7 +177,7 @@ fn visit_item(e: @mut Env, i: @ast::item) {
} }
nn nn
} }
None => token::ident_to_str(i.ident) None => token::ident_to_str(&i.ident)
}; };
if attr::find_attrs_by_name(i.attrs, "nolink").is_empty() { if attr::find_attrs_by_name(i.attrs, "nolink").is_empty() {
already_added = already_added =
@ -236,7 +236,7 @@ fn resolve_crate(e: @mut Env,
hash: @~str, hash: @~str,
span: span) span: span)
-> ast::crate_num { -> ast::crate_num {
let metas = metas_with_ident(token::ident_to_str(ident), metas); let metas = metas_with_ident(token::ident_to_str(&ident), metas);
match existing_match(e, metas, hash) { match existing_match(e, metas, hash) {
None => { None => {
@ -277,7 +277,7 @@ fn resolve_crate(e: @mut Env,
match attr::last_meta_item_value_str_by_name(load_ctxt.metas, match attr::last_meta_item_value_str_by_name(load_ctxt.metas,
"name") { "name") {
Some(v) => v, Some(v) => v,
None => token::ident_to_str(ident), None => token::ident_to_str(&ident),
}; };
let cmeta = @cstore::crate_metadata { let cmeta = @cstore::crate_metadata {
name: cname, name: cname,
@ -306,7 +306,7 @@ fn resolve_crate_deps(e: @mut Env, cdata: @~[u8]) -> cstore::cnum_map {
for decoder::get_crate_deps(e.intr, cdata).each |dep| { for decoder::get_crate_deps(e.intr, cdata).each |dep| {
let extrn_cnum = dep.cnum; let extrn_cnum = dep.cnum;
let cname = dep.name; let cname = dep.name;
let cname_str = token::ident_to_str(dep.name); let cname_str = token::ident_to_str(&dep.name);
let cmetas = metas_with(dep.vers, @~"vers", ~[]); let cmetas = metas_with(dep.vers, @~"vers", ~[]);
debug!("resolving dep crate %s ver: %s hash: %s", debug!("resolving dep crate %s ver: %s hash: %s",
*cname_str, *dep.vers, *dep.hash); *cname_str, *dep.vers, *dep.hash);

View file

@ -1110,7 +1110,7 @@ fn list_crate_deps(intr: @ident_interner, data: @~[u8], out: @io::Writer) {
for get_crate_deps(intr, data).each |dep| { for get_crate_deps(intr, data).each |dep| {
out.write_str( out.write_str(
fmt!("%d %s-%s-%s\n", fmt!("%d %s-%s-%s\n",
dep.cnum, *token::ident_to_str(dep.name), *dep.hash, *dep.vers)); dep.cnum, *token::ident_to_str(&dep.name), *dep.hash, *dep.vers));
} }
out.write_str("\n"); out.write_str("\n");

View file

@ -1055,7 +1055,7 @@ fn encode_info_for_item(ecx: @EncodeContext,
tcx.sess.span_unimpl( tcx.sess.span_unimpl(
item.span, item.span,
fmt!("Method %s is both provided and static", fmt!("Method %s is both provided and static",
*token::ident_to_str(method_ty.ident))); *token::ident_to_str(&method_ty.ident)));
} }
encode_type_param_bounds(ebml_w, ecx, encode_type_param_bounds(ebml_w, ecx,
&m.generics.ty_params); &m.generics.ty_params);

View file

@ -60,7 +60,7 @@ pub fn load_library_crate(cx: &Context) -> (~str, @~[u8]) {
None => { None => {
cx.diag.span_fatal( cx.diag.span_fatal(
cx.span, fmt!("can't find crate for `%s`", cx.span, fmt!("can't find crate for `%s`",
*token::ident_to_str(cx.ident))); *token::ident_to_str(&cx.ident)));
} }
} }
} }

View file

@ -711,7 +711,7 @@ impl BorrowckCtxt {
match *loan_path { match *loan_path {
LpVar(id) => { LpVar(id) => {
match self.tcx.items.find(&id) { match self.tcx.items.find(&id) {
Some(&ast_map::node_local(ident)) => { Some(&ast_map::node_local(ref ident)) => {
str::push_str(out, *token::ident_to_str(ident)); str::push_str(out, *token::ident_to_str(ident));
} }
r => { r => {
@ -725,7 +725,7 @@ impl BorrowckCtxt {
LpExtend(lp_base, _, LpInterior(mc::InteriorField(fname))) => { LpExtend(lp_base, _, LpInterior(mc::InteriorField(fname))) => {
self.append_loan_path_to_str_from_interior(lp_base, out); self.append_loan_path_to_str_from_interior(lp_base, out);
match fname { match fname {
mc::NamedField(fname) => { mc::NamedField(ref fname) => {
str::push_char(out, '.'); str::push_char(out, '.');
str::push_str(out, *token::ident_to_str(fname)); str::push_str(out, *token::ident_to_str(fname));
} }

View file

@ -235,7 +235,7 @@ pub fn check_crate(tcx: ty::ctxt,
if field.ident != ident { loop; } if field.ident != ident { loop; }
if field.vis == private { if field.vis == private {
tcx.sess.span_err(span, fmt!("field `%s` is private", tcx.sess.span_err(span, fmt!("field `%s` is private",
*token::ident_to_str(ident))); *token::ident_to_str(&ident)));
} }
break; break;
} }
@ -244,7 +244,7 @@ pub fn check_crate(tcx: ty::ctxt,
// Given the ID of a method, checks to ensure it's in scope. // Given the ID of a method, checks to ensure it's in scope.
let check_method_common: @fn(span: span, let check_method_common: @fn(span: span,
method_id: def_id, method_id: def_id,
name: ident) = name: &ident) =
|span, method_id, name| { |span, method_id, name| {
if method_id.crate == local_crate { if method_id.crate == local_crate {
let is_private = method_is_private(span, method_id.node); let is_private = method_is_private(span, method_id.node);
@ -275,7 +275,7 @@ pub fn check_crate(tcx: ty::ctxt,
match def { match def {
def_static_method(method_id, _, _) => { def_static_method(method_id, _, _) => {
debug!("found static method def, checking it"); debug!("found static method def, checking it");
check_method_common(span, method_id, *path.idents.last()) check_method_common(span, method_id, path.idents.last())
} }
def_fn(def_id, _) => { def_fn(def_id, _) => {
if def_id.crate == local_crate { if def_id.crate == local_crate {
@ -283,13 +283,13 @@ pub fn check_crate(tcx: ty::ctxt,
!privileged_items.contains(&def_id.node) { !privileged_items.contains(&def_id.node) {
tcx.sess.span_err(span, tcx.sess.span_err(span,
fmt!("function `%s` is private", fmt!("function `%s` is private",
*token::ident_to_str(*path.idents.last()))); *token::ident_to_str(path.idents.last())));
} }
} else if csearch::get_item_visibility(tcx.sess.cstore, } else if csearch::get_item_visibility(tcx.sess.cstore,
def_id) != public { def_id) != public {
tcx.sess.span_err(span, tcx.sess.span_err(span,
fmt!("function `%s` is private", fmt!("function `%s` is private",
*token::ident_to_str(*path.idents.last()))); *token::ident_to_str(path.idents.last())));
} }
} }
_ => {} _ => {}
@ -303,7 +303,7 @@ pub fn check_crate(tcx: ty::ctxt,
|span, origin, ident| { |span, origin, ident| {
match *origin { match *origin {
method_static(method_id) => { method_static(method_id) => {
check_method_common(span, method_id, ident) check_method_common(span, method_id, &ident)
} }
method_param(method_param { method_param(method_param {
trait_id: trait_id, trait_id: trait_id,
@ -328,7 +328,7 @@ pub fn check_crate(tcx: ty::ctxt,
.contains(&(trait_id.node)) => { .contains(&(trait_id.node)) => {
tcx.sess.span_err(span, tcx.sess.span_err(span,
fmt!("method `%s` is private", fmt!("method `%s` is private",
*token::ident_to_str(method *token::ident_to_str(&method
.ident))); .ident)));
} }
provided(_) | required(_) => { provided(_) | required(_) => {

View file

@ -2948,11 +2948,11 @@ impl Resolver {
// top of the crate otherwise. // top of the crate otherwise.
let mut containing_module; let mut containing_module;
let mut i; let mut i;
if *token::ident_to_str(module_path[0]) == ~"self" { if *token::ident_to_str(&module_path[0]) == ~"self" {
containing_module = containing_module =
self.get_nearest_normal_module_parent_or_self(module_); self.get_nearest_normal_module_parent_or_self(module_);
i = 1; i = 1;
} else if *token::ident_to_str(module_path[0]) == ~"super" { } else if *token::ident_to_str(&module_path[0]) == ~"super" {
containing_module = containing_module =
self.get_nearest_normal_module_parent_or_self(module_); self.get_nearest_normal_module_parent_or_self(module_);
i = 0; // We'll handle `super` below. i = 0; // We'll handle `super` below.
@ -2962,7 +2962,7 @@ impl Resolver {
// Now loop through all the `super`s we find. // Now loop through all the `super`s we find.
while i < module_path.len() && while i < module_path.len() &&
*token::ident_to_str(module_path[i]) == ~"super" { *token::ident_to_str(&module_path[i]) == ~"super" {
debug!("(resolving module prefix) resolving `super` at %s", debug!("(resolving module prefix) resolving `super` at %s",
self.module_to_str(containing_module)); self.module_to_str(containing_module));
match self.get_nearest_normal_module_parent(containing_module) { match self.get_nearest_normal_module_parent(containing_module) {

View file

@ -2505,7 +2505,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
} }
ast::foreign_item_const(*) => { ast::foreign_item_const(*) => {
let typ = ty::node_id_to_type(tcx, ni.id); let typ = ty::node_id_to_type(tcx, ni.id);
let ident = token::ident_to_str(ni.ident); let ident = token::ident_to_str(&ni.ident);
let g = do str::as_c_str(*ident) |buf| { let g = do str::as_c_str(*ident) |buf| {
unsafe { unsafe {
llvm::LLVMAddGlobal(ccx.llmod, llvm::LLVMAddGlobal(ccx.llmod,

View file

@ -344,7 +344,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
} }
} }
ast::foreign_item_const(*) => { ast::foreign_item_const(*) => {
let ident = token::ident_to_str(foreign_item.ident); let ident = token::ident_to_str(&foreign_item.ident);
ccx.item_symbols.insert(foreign_item.id, copy *ident); ccx.item_symbols.insert(foreign_item.id, copy *ident);
} }
} }

View file

@ -655,7 +655,7 @@ impl Repr for ty::Method {
impl Repr for ast::ident { impl Repr for ast::ident {
fn repr(&self, tcx: ctxt) -> ~str { fn repr(&self, tcx: ctxt) -> ~str {
copy *token::ident_to_str(*self) copy *token::ident_to_str(self)
} }
} }

View file

@ -24,10 +24,12 @@ use syntax::parse::token;
// Hack; rather than thread an interner through everywhere, rely on // Hack; rather than thread an interner through everywhere, rely on
// thread-local data // thread-local data
// Hack-Becomes-Feature: using thread-local-state everywhere...
pub fn to_str(id: ast::ident) -> ~str { pub fn to_str(id: ast::ident) -> ~str {
return copy *ident_to_str(id); return copy *ident_to_str(&id);
} }
// get rid of this pointless function:
pub fn interner() -> @ident_interner { pub fn interner() -> @ident_interner {
return token::get_ident_interner(); return token::get_ident_interner();
} }

View file

@ -310,7 +310,7 @@ impl ExtCtxt {
*self.trace_mac = x *self.trace_mac = x
} }
pub fn str_of(&self, id: ast::ident) -> ~str { pub fn str_of(&self, id: ast::ident) -> ~str {
copy *ident_to_str(id) copy *ident_to_str(&id)
} }
pub fn ident_of(&self, st: &str) -> ast::ident { pub fn ident_of(&self, st: &str) -> ast::ident {
str_to_ident(st) str_to_ident(st)

View file

@ -49,7 +49,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
fmt!("expected macro name without module \ fmt!("expected macro name without module \
separators")); separators"));
} }
let extname = pth.idents[0]; let extname = &pth.idents[0];
let extnamestr = ident_to_str(extname); let extnamestr = ident_to_str(extname);
// leaving explicit deref here to highlight unbox op: // leaving explicit deref here to highlight unbox op:
match (*extsbox).find(&extname.name) { match (*extsbox).find(&extname.name) {
@ -216,7 +216,7 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
_ => cx.span_bug(it.span, "invalid item macro invocation") _ => cx.span_bug(it.span, "invalid item macro invocation")
}; };
let extname = pth.idents[0]; let extname = &pth.idents[0];
let interner = get_ident_interner(); let interner = get_ident_interner();
let extnamestr = ident_to_str(extname); let extnamestr = ident_to_str(extname);
let expanded = match (*extsbox).find(&extname.name) { let expanded = match (*extsbox).find(&extname.name) {
@ -228,7 +228,7 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
cx.span_fatal(pth.span, cx.span_fatal(pth.span,
fmt!("macro %s! expects no ident argument, \ fmt!("macro %s! expects no ident argument, \
given '%s'", *extnamestr, given '%s'", *extnamestr,
*ident_to_str(it.ident))); *ident_to_str(&it.ident)));
} }
cx.bt_push(ExpandedFrom(CallInfo { cx.bt_push(ExpandedFrom(CallInfo {
call_site: it.span, call_site: it.span,
@ -315,7 +315,7 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
fmt!("expected macro name without module \ fmt!("expected macro name without module \
separators")); separators"));
} }
let extname = pth.idents[0]; let extname = &pth.idents[0];
let extnamestr = ident_to_str(extname); let extnamestr = ident_to_str(extname);
let (fully_expanded, sp) = match (*extsbox).find(&extname.name) { let (fully_expanded, sp) = match (*extsbox).find(&extname.name) {
None => None =>

View file

@ -80,7 +80,7 @@ pub mod rt {
impl ToSource for ast::ident { impl ToSource for ast::ident {
fn to_source(&self, cx: @ExtCtxt) -> ~str { fn to_source(&self, cx: @ExtCtxt) -> ~str {
copy *interner_get(self.name) copy *ident_to_str(self)
} }
} }

View file

@ -205,7 +205,7 @@ pub fn nameize(p_s: @mut ParseSess, ms: &[matcher], res: &[@named_match])
} => { } => {
if ret_val.contains_key(bind_name) { if ret_val.contains_key(bind_name) {
p_s.span_diagnostic.span_fatal(sp, ~"Duplicated bind name: "+ p_s.span_diagnostic.span_fatal(sp, ~"Duplicated bind name: "+
*ident_to_str(*bind_name)) *ident_to_str(bind_name))
} }
ret_val.insert(*bind_name, res[idx]); ret_val.insert(*bind_name, res[idx]);
} }
@ -373,8 +373,8 @@ pub fn parse(
let nts = str::connect(vec::map(bb_eis, |ei| { let nts = str::connect(vec::map(bb_eis, |ei| {
match ei.elts[ei.idx].node { match ei.elts[ei.idx].node {
match_nonterminal(ref bind,ref name,_) => { match_nonterminal(ref bind,ref name,_) => {
fmt!("%s ('%s')", *ident_to_str(*name), fmt!("%s ('%s')", *ident_to_str(name),
*ident_to_str(*bind)) *ident_to_str(bind))
} }
_ => fail!() _ => fail!()
} }), " or "); } }), " or ");
@ -398,7 +398,7 @@ pub fn parse(
match ei.elts[ei.idx].node { match ei.elts[ei.idx].node {
match_nonterminal(_, ref name, idx) => { match_nonterminal(_, ref name, idx) => {
ei.matches[idx].push(@matched_nonterminal( ei.matches[idx].push(@matched_nonterminal(
parse_nt(&rust_parser, *ident_to_str(*name)))); parse_nt(&rust_parser, *ident_to_str(name))));
ei.idx += 1u; ei.idx += 1u;
} }
_ => fail!() _ => fail!()

View file

@ -151,7 +151,7 @@ pub fn add_new_extension(cx: @ExtCtxt,
|cx, sp, arg| generic_extension(cx, sp, name, arg, *lhses, *rhses); |cx, sp, arg| generic_extension(cx, sp, name, arg, *lhses, *rhses);
return MRDef(MacroDef{ return MRDef(MacroDef{
name: copy *ident_to_str(name), name: copy *ident_to_str(&name),
ext: NormalTT(base::SyntaxExpanderTT{expander: exp, span: Some(sp)}) ext: NormalTT(base::SyntaxExpanderTT{expander: exp, span: Some(sp)})
}); });
} }

View file

@ -145,8 +145,8 @@ fn lockstep_iter_size(t: &token_tree, r: &mut TtReader) -> lis {
lis_contradiction(_) => copy rhs, lis_contradiction(_) => copy rhs,
lis_constraint(r_len, _) if l_len == r_len => copy lhs, lis_constraint(r_len, _) if l_len == r_len => copy lhs,
lis_constraint(r_len, ref r_id) => { lis_constraint(r_len, ref r_id) => {
let l_n = copy *ident_to_str(*l_id); let l_n = copy *ident_to_str(l_id);
let r_n = copy *ident_to_str(*r_id); let r_n = copy *ident_to_str(r_id);
lis_contradiction(fmt!("Inconsistent lockstep iteration: \ lis_contradiction(fmt!("Inconsistent lockstep iteration: \
'%s' has %u items, but '%s' has %u", '%s' has %u items, but '%s' has %u",
l_n, l_len, r_n, r_len)) l_n, l_len, r_n, r_len))
@ -296,7 +296,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
r.sp_diag.span_fatal( r.sp_diag.span_fatal(
copy r.cur_span, /* blame the macro writer */ copy r.cur_span, /* blame the macro writer */
fmt!("variable '%s' is still repeating at this depth", fmt!("variable '%s' is still repeating at this depth",
*ident_to_str(ident))); *ident_to_str(&ident)));
} }
} }
} }

View file

@ -3980,7 +3980,7 @@ impl Parser {
match *self.token { match *self.token {
token::LIT_STR(s) => { token::LIT_STR(s) => {
self.bump(); self.bump();
let the_string = ident_to_str(s); let the_string = ident_to_str(&s);
let mut words = ~[]; let mut words = ~[];
for str::each_word(*the_string) |s| { words.push(s) } for str::each_word(*the_string) |s| { words.push(s) }
let mut abis = AbiSet::empty(); let mut abis = AbiSet::empty();
@ -4542,7 +4542,7 @@ impl Parser {
match *self.token { match *self.token {
token::LIT_STR(s) => { token::LIT_STR(s) => {
self.bump(); self.bump();
ident_to_str(s) ident_to_str(&s)
} }
_ => self.fatal("expected string literal") _ => self.fatal("expected string literal")
} }

View file

@ -178,20 +178,20 @@ pub fn to_str(in: @ident_interner, t: &Token) -> ~str {
} }
LIT_INT_UNSUFFIXED(i) => { i.to_str() } LIT_INT_UNSUFFIXED(i) => { i.to_str() }
LIT_FLOAT(ref s, t) => { LIT_FLOAT(ref s, t) => {
let mut body = copy *ident_to_str(*s); let mut body = copy *ident_to_str(s);
if body.ends_with(".") { if body.ends_with(".") {
body += "0"; // `10.f` is not a float literal body += "0"; // `10.f` is not a float literal
} }
body + ast_util::float_ty_to_str(t) body + ast_util::float_ty_to_str(t)
} }
LIT_FLOAT_UNSUFFIXED(ref s) => { LIT_FLOAT_UNSUFFIXED(ref s) => {
let mut body = copy *ident_to_str(*s); let mut body = copy *ident_to_str(s);
if body.ends_with(".") { if body.ends_with(".") {
body += "0"; // `10.f` is not a float literal body += "0"; // `10.f` is not a float literal
} }
body body
} }
LIT_STR(ref s) => { ~"\"" + str::escape_default(*ident_to_str(*s)) + "\"" } LIT_STR(ref s) => { ~"\"" + str::escape_default(*ident_to_str(s)) + "\"" }
/* Name components */ /* Name components */
IDENT(s, _) => copy *in.get(s.name), IDENT(s, _) => copy *in.get(s.name),
@ -199,7 +199,7 @@ pub fn to_str(in: @ident_interner, t: &Token) -> ~str {
UNDERSCORE => ~"_", UNDERSCORE => ~"_",
/* Other */ /* Other */
DOC_COMMENT(ref s) => copy *ident_to_str(*s), DOC_COMMENT(ref s) => copy *ident_to_str(s),
EOF => ~"<eof>", EOF => ~"<eof>",
INTERPOLATED(ref nt) => { INTERPOLATED(ref nt) => {
match nt { match nt {
@ -545,7 +545,7 @@ pub fn interner_get(name : Name) -> @~str {
} }
// maps an identifier to the string that it corresponds to // maps an identifier to the string that it corresponds to
pub fn ident_to_str(id : ast::ident) -> @~str { pub fn ident_to_str(id : &ast::ident) -> @~str {
interner_get(id.name) interner_get(id.name)
} }

View file

@ -1475,7 +1475,7 @@ pub fn print_decl(s: @ps, decl: @ast::decl) {
} }
pub fn print_ident(s: @ps, ident: ast::ident) { pub fn print_ident(s: @ps, ident: ast::ident) {
word(s.s, *ident_to_str(ident)); word(s.s, *ident_to_str(&ident));
} }
pub fn print_for_decl(s: @ps, loc: @ast::local, coll: @ast::expr) { pub fn print_for_decl(s: @ps, loc: @ast::local, coll: @ast::expr) {