token_to_ident takes argument by reference
This commit is contained in:
parent
3203595471
commit
04a691a511
21 changed files with 48 additions and 46 deletions
|
@ -296,7 +296,7 @@ impl Session_ {
|
|||
|
||||
// pointless function, now...
|
||||
pub fn str_of(@self, id: ast::ident) -> @~str {
|
||||
token::ident_to_str(id)
|
||||
token::ident_to_str(&id)
|
||||
}
|
||||
|
||||
// pointless function, now...
|
||||
|
|
|
@ -177,7 +177,7 @@ fn visit_item(e: @mut Env, i: @ast::item) {
|
|||
}
|
||||
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() {
|
||||
already_added =
|
||||
|
@ -236,7 +236,7 @@ fn resolve_crate(e: @mut Env,
|
|||
hash: @~str,
|
||||
span: span)
|
||||
-> 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) {
|
||||
None => {
|
||||
|
@ -277,7 +277,7 @@ fn resolve_crate(e: @mut Env,
|
|||
match attr::last_meta_item_value_str_by_name(load_ctxt.metas,
|
||||
"name") {
|
||||
Some(v) => v,
|
||||
None => token::ident_to_str(ident),
|
||||
None => token::ident_to_str(&ident),
|
||||
};
|
||||
let cmeta = @cstore::crate_metadata {
|
||||
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| {
|
||||
let extrn_cnum = dep.cnum;
|
||||
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", ~[]);
|
||||
debug!("resolving dep crate %s ver: %s hash: %s",
|
||||
*cname_str, *dep.vers, *dep.hash);
|
||||
|
|
|
@ -1110,7 +1110,7 @@ fn list_crate_deps(intr: @ident_interner, data: @~[u8], out: @io::Writer) {
|
|||
for get_crate_deps(intr, data).each |dep| {
|
||||
out.write_str(
|
||||
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");
|
||||
|
|
|
@ -1055,7 +1055,7 @@ fn encode_info_for_item(ecx: @EncodeContext,
|
|||
tcx.sess.span_unimpl(
|
||||
item.span,
|
||||
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,
|
||||
&m.generics.ty_params);
|
||||
|
|
|
@ -60,7 +60,7 @@ pub fn load_library_crate(cx: &Context) -> (~str, @~[u8]) {
|
|||
None => {
|
||||
cx.diag.span_fatal(
|
||||
cx.span, fmt!("can't find crate for `%s`",
|
||||
*token::ident_to_str(cx.ident)));
|
||||
*token::ident_to_str(&cx.ident)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -711,7 +711,7 @@ impl BorrowckCtxt {
|
|||
match *loan_path {
|
||||
LpVar(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));
|
||||
}
|
||||
r => {
|
||||
|
@ -725,7 +725,7 @@ impl BorrowckCtxt {
|
|||
LpExtend(lp_base, _, LpInterior(mc::InteriorField(fname))) => {
|
||||
self.append_loan_path_to_str_from_interior(lp_base, out);
|
||||
match fname {
|
||||
mc::NamedField(fname) => {
|
||||
mc::NamedField(ref fname) => {
|
||||
str::push_char(out, '.');
|
||||
str::push_str(out, *token::ident_to_str(fname));
|
||||
}
|
||||
|
|
|
@ -235,7 +235,7 @@ pub fn check_crate(tcx: ty::ctxt,
|
|||
if field.ident != ident { loop; }
|
||||
if field.vis == private {
|
||||
tcx.sess.span_err(span, fmt!("field `%s` is private",
|
||||
*token::ident_to_str(ident)));
|
||||
*token::ident_to_str(&ident)));
|
||||
}
|
||||
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.
|
||||
let check_method_common: @fn(span: span,
|
||||
method_id: def_id,
|
||||
name: ident) =
|
||||
name: &ident) =
|
||||
|span, method_id, name| {
|
||||
if method_id.crate == local_crate {
|
||||
let is_private = method_is_private(span, method_id.node);
|
||||
|
@ -275,7 +275,7 @@ pub fn check_crate(tcx: ty::ctxt,
|
|||
match def {
|
||||
def_static_method(method_id, _, _) => {
|
||||
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, _) => {
|
||||
if def_id.crate == local_crate {
|
||||
|
@ -283,13 +283,13 @@ pub fn check_crate(tcx: ty::ctxt,
|
|||
!privileged_items.contains(&def_id.node) {
|
||||
tcx.sess.span_err(span,
|
||||
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,
|
||||
def_id) != public {
|
||||
tcx.sess.span_err(span,
|
||||
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| {
|
||||
match *origin {
|
||||
method_static(method_id) => {
|
||||
check_method_common(span, method_id, ident)
|
||||
check_method_common(span, method_id, &ident)
|
||||
}
|
||||
method_param(method_param {
|
||||
trait_id: trait_id,
|
||||
|
@ -328,7 +328,7 @@ pub fn check_crate(tcx: ty::ctxt,
|
|||
.contains(&(trait_id.node)) => {
|
||||
tcx.sess.span_err(span,
|
||||
fmt!("method `%s` is private",
|
||||
*token::ident_to_str(method
|
||||
*token::ident_to_str(&method
|
||||
.ident)));
|
||||
}
|
||||
provided(_) | required(_) => {
|
||||
|
|
|
@ -2948,11 +2948,11 @@ impl Resolver {
|
|||
// top of the crate otherwise.
|
||||
let mut containing_module;
|
||||
let mut i;
|
||||
if *token::ident_to_str(module_path[0]) == ~"self" {
|
||||
if *token::ident_to_str(&module_path[0]) == ~"self" {
|
||||
containing_module =
|
||||
self.get_nearest_normal_module_parent_or_self(module_);
|
||||
i = 1;
|
||||
} else if *token::ident_to_str(module_path[0]) == ~"super" {
|
||||
} else if *token::ident_to_str(&module_path[0]) == ~"super" {
|
||||
containing_module =
|
||||
self.get_nearest_normal_module_parent_or_self(module_);
|
||||
i = 0; // We'll handle `super` below.
|
||||
|
@ -2962,7 +2962,7 @@ impl Resolver {
|
|||
|
||||
// Now loop through all the `super`s we find.
|
||||
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",
|
||||
self.module_to_str(containing_module));
|
||||
match self.get_nearest_normal_module_parent(containing_module) {
|
||||
|
|
|
@ -2505,7 +2505,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::node_id) -> ValueRef {
|
|||
}
|
||||
ast::foreign_item_const(*) => {
|
||||
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| {
|
||||
unsafe {
|
||||
llvm::LLVMAddGlobal(ccx.llmod,
|
||||
|
|
|
@ -344,7 +344,7 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
|
|||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -655,7 +655,7 @@ impl Repr for ty::Method {
|
|||
|
||||
impl Repr for ast::ident {
|
||||
fn repr(&self, tcx: ctxt) -> ~str {
|
||||
copy *token::ident_to_str(*self)
|
||||
copy *token::ident_to_str(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,10 +24,12 @@ use syntax::parse::token;
|
|||
|
||||
// Hack; rather than thread an interner through everywhere, rely on
|
||||
// thread-local data
|
||||
// Hack-Becomes-Feature: using thread-local-state everywhere...
|
||||
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 {
|
||||
return token::get_ident_interner();
|
||||
}
|
||||
|
|
|
@ -310,7 +310,7 @@ impl ExtCtxt {
|
|||
*self.trace_mac = x
|
||||
}
|
||||
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 {
|
||||
str_to_ident(st)
|
||||
|
|
|
@ -49,7 +49,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
|
|||
fmt!("expected macro name without module \
|
||||
separators"));
|
||||
}
|
||||
let extname = pth.idents[0];
|
||||
let extname = &pth.idents[0];
|
||||
let extnamestr = ident_to_str(extname);
|
||||
// leaving explicit deref here to highlight unbox op:
|
||||
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")
|
||||
};
|
||||
|
||||
let extname = pth.idents[0];
|
||||
let extname = &pth.idents[0];
|
||||
let interner = get_ident_interner();
|
||||
let extnamestr = ident_to_str(extname);
|
||||
let expanded = match (*extsbox).find(&extname.name) {
|
||||
|
@ -228,7 +228,7 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv,
|
|||
cx.span_fatal(pth.span,
|
||||
fmt!("macro %s! expects no ident argument, \
|
||||
given '%s'", *extnamestr,
|
||||
*ident_to_str(it.ident)));
|
||||
*ident_to_str(&it.ident)));
|
||||
}
|
||||
cx.bt_push(ExpandedFrom(CallInfo {
|
||||
call_site: it.span,
|
||||
|
@ -315,7 +315,7 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv,
|
|||
fmt!("expected macro name without module \
|
||||
separators"));
|
||||
}
|
||||
let extname = pth.idents[0];
|
||||
let extname = &pth.idents[0];
|
||||
let extnamestr = ident_to_str(extname);
|
||||
let (fully_expanded, sp) = match (*extsbox).find(&extname.name) {
|
||||
None =>
|
||||
|
|
|
@ -80,7 +80,7 @@ pub mod rt {
|
|||
|
||||
impl ToSource for ast::ident {
|
||||
fn to_source(&self, cx: @ExtCtxt) -> ~str {
|
||||
copy *interner_get(self.name)
|
||||
copy *ident_to_str(self)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ pub fn nameize(p_s: @mut ParseSess, ms: &[matcher], res: &[@named_match])
|
|||
} => {
|
||||
if ret_val.contains_key(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]);
|
||||
}
|
||||
|
@ -373,8 +373,8 @@ pub fn parse(
|
|||
let nts = str::connect(vec::map(bb_eis, |ei| {
|
||||
match ei.elts[ei.idx].node {
|
||||
match_nonterminal(ref bind,ref name,_) => {
|
||||
fmt!("%s ('%s')", *ident_to_str(*name),
|
||||
*ident_to_str(*bind))
|
||||
fmt!("%s ('%s')", *ident_to_str(name),
|
||||
*ident_to_str(bind))
|
||||
}
|
||||
_ => fail!()
|
||||
} }), " or ");
|
||||
|
@ -398,7 +398,7 @@ pub fn parse(
|
|||
match ei.elts[ei.idx].node {
|
||||
match_nonterminal(_, ref name, idx) => {
|
||||
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;
|
||||
}
|
||||
_ => fail!()
|
||||
|
|
|
@ -151,7 +151,7 @@ pub fn add_new_extension(cx: @ExtCtxt,
|
|||
|cx, sp, arg| generic_extension(cx, sp, name, arg, *lhses, *rhses);
|
||||
|
||||
return MRDef(MacroDef{
|
||||
name: copy *ident_to_str(name),
|
||||
name: copy *ident_to_str(&name),
|
||||
ext: NormalTT(base::SyntaxExpanderTT{expander: exp, span: Some(sp)})
|
||||
});
|
||||
}
|
||||
|
|
|
@ -145,8 +145,8 @@ fn lockstep_iter_size(t: &token_tree, r: &mut TtReader) -> lis {
|
|||
lis_contradiction(_) => copy rhs,
|
||||
lis_constraint(r_len, _) if l_len == r_len => copy lhs,
|
||||
lis_constraint(r_len, ref r_id) => {
|
||||
let l_n = copy *ident_to_str(*l_id);
|
||||
let r_n = copy *ident_to_str(*r_id);
|
||||
let l_n = copy *ident_to_str(l_id);
|
||||
let r_n = copy *ident_to_str(r_id);
|
||||
lis_contradiction(fmt!("Inconsistent lockstep iteration: \
|
||||
'%s' has %u items, but '%s' has %u",
|
||||
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(
|
||||
copy r.cur_span, /* blame the macro writer */
|
||||
fmt!("variable '%s' is still repeating at this depth",
|
||||
*ident_to_str(ident)));
|
||||
*ident_to_str(&ident)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3980,7 +3980,7 @@ impl Parser {
|
|||
match *self.token {
|
||||
token::LIT_STR(s) => {
|
||||
self.bump();
|
||||
let the_string = ident_to_str(s);
|
||||
let the_string = ident_to_str(&s);
|
||||
let mut words = ~[];
|
||||
for str::each_word(*the_string) |s| { words.push(s) }
|
||||
let mut abis = AbiSet::empty();
|
||||
|
@ -4542,7 +4542,7 @@ impl Parser {
|
|||
match *self.token {
|
||||
token::LIT_STR(s) => {
|
||||
self.bump();
|
||||
ident_to_str(s)
|
||||
ident_to_str(&s)
|
||||
}
|
||||
_ => self.fatal("expected string literal")
|
||||
}
|
||||
|
|
|
@ -178,20 +178,20 @@ pub fn to_str(in: @ident_interner, t: &Token) -> ~str {
|
|||
}
|
||||
LIT_INT_UNSUFFIXED(i) => { i.to_str() }
|
||||
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(".") {
|
||||
body += "0"; // `10.f` is not a float literal
|
||||
}
|
||||
body + ast_util::float_ty_to_str(t)
|
||||
}
|
||||
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(".") {
|
||||
body += "0"; // `10.f` is not a float literal
|
||||
}
|
||||
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 */
|
||||
IDENT(s, _) => copy *in.get(s.name),
|
||||
|
@ -199,7 +199,7 @@ pub fn to_str(in: @ident_interner, t: &Token) -> ~str {
|
|||
UNDERSCORE => ~"_",
|
||||
|
||||
/* Other */
|
||||
DOC_COMMENT(ref s) => copy *ident_to_str(*s),
|
||||
DOC_COMMENT(ref s) => copy *ident_to_str(s),
|
||||
EOF => ~"<eof>",
|
||||
INTERPOLATED(ref nt) => {
|
||||
match nt {
|
||||
|
@ -545,7 +545,7 @@ pub fn interner_get(name : Name) -> @~str {
|
|||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
|
|
|
@ -1475,7 +1475,7 @@ pub fn print_decl(s: @ps, decl: @ast::decl) {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue