}
ast::ViewItemExternMod(..) => {
for attr in i.attrs.iter() {
- if "phase" == attr.name() {
+ if attr.name().get() == "phase"{
self.gate_feature("phase", attr.span,
"compile time crate loading is \
experimental and possibly buggy");
use syntax::fold::Folder;
use syntax::fold;
use syntax::opt_vec;
+use syntax::parse::token::InternedString;
+use syntax::parse::token;
use syntax::util::small_vector::SmallVector;
pub static VERSION: &'static str = "0.10-pre";
sess: Session,
}
-pub fn with_version(crate: &str) -> Option<(@str, ast::StrStyle)> {
+pub fn with_version(crate: &str) -> Option<(InternedString, ast::StrStyle)> {
match option_env!("CFG_DISABLE_INJECT_STD_VERSION") {
Some("1") => None,
_ => {
- Some((format!("{}\\#{}", crate, VERSION).to_managed(),
+ Some((token::intern_and_get_ident(format!("{}\\#{}",
+ crate,
+ VERSION)),
ast::CookedStr))
}
}
with_version("std"),
ast::DUMMY_NODE_ID),
attrs: ~[
- attr::mk_attr(attr::mk_list_item(@"phase",
- ~[attr::mk_word_item(@"syntax"),
- attr::mk_word_item(@"link")]))
+ attr::mk_attr(attr::mk_list_item(
+ InternedString::new("phase"),
+ ~[
+ attr::mk_word_item(InternedString::new("syntax")),
+ attr::mk_word_item(InternedString::new("link")
+ )]))
],
vis: ast::Inherited,
span: DUMMY_SP
0u => d::early_error(demitter, "no input filename given"),
1u => {
let ifile = matches.free[0].as_slice();
- if "-" == ifile {
+ if ifile == "-" {
let src =
str::from_utf8_owned(io::stdin().read_to_end()).unwrap();
(d::StrInput(src), None)
fn visit_view_item(e: &mut Env, i: &ast::ViewItem) {
let should_load = i.attrs.iter().all(|attr| {
- "phase" != attr.name() ||
+ attr.name().get() != "phase" ||
attr.meta_item_list().map_or(false, |phases| {
attr::contains_name(phases, "link")
})
fn extract_crate_info(i: &ast::ViewItem) -> Option<CrateInfo> {
match i.node {
- ast::ViewItemExternMod(ident, path_opt, id) => {
- let ident = token::ident_to_str(&ident);
+ ast::ViewItemExternMod(ref ident, ref path_opt, id) => {
+ let ident = token::ident_to_str(ident);
debug!("resolving extern mod stmt. ident: {:?} path_opt: {:?}",
ident, path_opt);
- let (name, version) = match path_opt {
+ let (name, version) = match *path_opt {
Some((ref path_str, _)) => {
let crateid: Option<CrateId> = from_str(path_str.get());
match crateid {
use std::libc::c_uint;
use std::vec;
use std::local_data;
+use syntax::abi::{X86, X86_64, Arm, Mips, Rust, RustIntrinsic, OsWin32};
use syntax::ast_map::{PathName, PathPrettyName, path_elem_to_str};
use syntax::ast_util::{local_def, is_local};
-use syntax::attr;
-use syntax::abi::{X86, X86_64, Arm, Mips, Rust, RustIntrinsic, OsWin32};
use syntax::attr::AttrMetaMethods;
+use syntax::attr;
use syntax::codemap::Span;
-use syntax::parse::token::{InternedString, special_idents};
+use syntax::parse::token::InternedString;
use syntax::parse::token;
-use syntax::{ast, ast_util, ast_map};
-use syntax::attr::AttrMetaMethods;
-use syntax::abi::{X86, X86_64, Arm, Mips, Rust, RustIntrinsic, OsWin32};
-use syntax::visit;
use syntax::visit::Visitor;
use syntax::visit;
-use syntax::{ast, ast_util, codemap, ast_map};
+use syntax::{ast, ast_util, ast_map};
pub use middle::trans::context::task_llcx;
use middle::trans::cleanup;
use middle::trans::cleanup::CleanupMethods;
use middle::trans::common::*;
-use middle::trans::datum::immediate_rvalue;
use middle::trans::expr;
use middle::trans::machine::*;
use middle::trans::reflect;
match content_expr.node {
ast::ExprLit(lit) => {
match lit.node {
- ast::LitStr(s, _) => {
+ ast::LitStr(ref s, _) => {
return trans_lit_str(bcx,
content_expr,
- (*s).clone(),
+ s.clone(),
dest)
}
_ => {}
match content_expr.node {
ast::ExprLit(lit) => {
match lit.node {
- ast::LitStr(s, _) => {
+ ast::LitStr(ref s, _) => {
let llptrval = C_cstr(bcx.ccx(), (*s).clone());
let llptrval = PointerCast(bcx,
llptrval,
Type::i8p());
- let llsizeval = C_uint(bcx.ccx(), s.len());
+ let llsizeval = C_uint(bcx.ccx(), s.get().len());
let typ = ty::mk_str(bcx.tcx(), ty::vstore_uniq);
let lldestval = rvalue_scratch_datum(bcx,
typ,
impl Clean<ViewItemInner> for ast::ViewItem_ {
fn clean(&self) -> ViewItemInner {
match self {
- &ast::ViewItemExternMod(ref i, ref p, ref id) =>
- ExternMod(i.clean(), p.map(|(ref x, _)| x.to_owned()), *id),
+ &ast::ViewItemExternMod(ref i, ref p, ref id) => {
+ let string = match *p {
+ None => None,
+ Some((ref x, _)) => Some(x.get().to_owned()),
+ };
+ ExternMod(i.clean(), string, *id)
+ }
&ast::ViewItemUse(ref vp) => Import(vp.clean())
}
}
match vi.node {
// ignore metadata, I guess
- ast::ViewItemExternMod(lib_ident, path_opt, _) => {
- let lib_name = match path_opt {
- Some((p, _)) => p,
- None => self.sess.str_of(lib_ident)
+ ast::ViewItemExternMod(ref lib_ident, ref path_opt, _) => {
+ let lib_name = match *path_opt {
+ Some((ref p, _)) => (*p).clone(),
+ None => token::get_ident(lib_ident.name),
};
debug!("Finding and installing... {}", lib_name);
- let crate_id: CrateId = from_str(lib_name).expect("valid crate id");
+ let crate_id: CrateId =
+ from_str(lib_name.get()).expect("valid crate id");
// Check standard Rust library path first
let whatever = system_library(&self.context.sysroot_to_use(), &crate_id);
debug!("system library returned {:?}", whatever);
use ext::expand;
use parse;
use parse::token;
-use parse::token::{InternedString, ident_to_str, intern, str_to_ident};
+use parse::token::{InternedString, intern, str_to_ident};
use util::small_vector::SmallVector;
use std::hashmap::HashMap;
pub fn set_trace_macros(&mut self, x: bool) {
self.trace_mac = x
}
- pub fn str_of(&self, id: ast::Ident) -> @str {
- ident_to_str(&id)
- }
pub fn ident_of(&self, st: &str) -> ast::Ident {
str_to_ident(st)
}
-> Option<(InternedString, ast::StrStyle)> {
match expr.node {
ast::ExprLit(l) => match l.node {
- ast::LitStr(s, style) => return Some(((*s).clone(), style)),
+ ast::LitStr(ref s, style) => return Some(((*s).clone(), style)),
_ => cx.span_err(l.span, err_msg)
},
_ => cx.span_err(expr.span, err_msg)
match tts[0] {
ast::TTTok(_, token::LIT_STR(ident))
| ast::TTTok(_, token::LIT_STR_RAW(ident, _)) => {
- return Some(cx.str_of(ident).to_str())
+ let interned_str = token::get_ident(ident.name);
+ return Some(interned_str.get().to_str())
}
_ => cx.span_err(sp, format!("{} requires a string.", name)),
}
}
} else {
match *e {
- ast::TTTok(_, token::IDENT(ident,_)) => res_str.push_str(cx.str_of(ident)),
+ ast::TTTok(_, token::IDENT(ident,_)) => {
+ let interned_str = token::get_ident(ident.name);
+ res_str.push_str(interned_str.get())
+ }
_ => {
cx.span_err(sp, "concat_idents! requires ident args.");
return MacResult::dummy_expr();
..
}) in fields.iter().enumerate() {
let name = match name {
- Some(id) => token::get_ident(id),
+ Some(id) => token::get_ident(id.name),
None => {
token::intern_and_get_ident(format!("_field{}", i))
}
let blk = cx.lambda_stmts_1(trait_span, stmts, blkarg);
let name = cx.expr_str(trait_span,
- token::get_ident(variant.node.name));
+ token::get_ident(variant.node.name.name));
let call = cx.expr_method_call(trait_span, blkencoder,
cx.ident_of("emit_enum_variant"),
~[name,
cx.expr_str_uniq(span, token::get_ident(name.name))
} else {
let buf = cx.ident_of("buf");
- let start = token::intern_and_get_ident(cx.str_of(name) + start);
+ let interned_str = token::get_ident(name.name);
+ let start =
+ token::intern_and_get_ident(interned_str.get() + start);
let init = cx.expr_str_uniq(span, start);
let mut stmts = ~[cx.stmt_let(span, true, buf, init)];
let push_str = cx.ident_of("push_str");
match name {
None => {}
Some(id) => {
- let name = cx.str_of(id) + ": ";
+ let interned_id = token::get_ident(id.name);
+ let name = interned_id.get() + ": ";
push(cx.expr_str(span,
token::intern_and_get_ident(name)));
}
fld: &mut MacroExpander)
-> ast::ViewItem {
let should_load = vi.attrs.iter().any(|attr| {
- "phase" == attr.name() &&
+ attr.name().get() == "phase" &&
attr.meta_item_list().map_or(false, |phases| {
attr::contains_name(phases, "syntax")
})
ast::ViewItemExternMod(ref name, _, _) => token::ident_to_str(name),
_ => unreachable!(),
};
- let name = format!("<{} macros>", crate_name).to_managed();
+ let name = format!("<{} macros>", crate_name);
let exported_macros = fld.cx.loader.get_exported_macros(cnum);
for source in exported_macros.iter() {
- let item = parse::parse_item_from_source_str(name,
- source.to_managed(),
+ let item = parse::parse_item_from_source_str(name.clone(),
+ (*source).clone(),
fld.cx.cfg(),
fld.cx.parse_sess())
.expect("expected a serialized item");
#[deriving(Eq)]
enum ArgumentType {
- Known(@str),
+ Known(~str),
Unsigned,
String,
}
enum Position {
Exact(uint),
- Named(@str),
+ Named(~str),
}
struct Context<'a> {
args: ~[@ast::Expr],
arg_types: ~[Option<ArgumentType>],
// Parsed named expressions and the types that we've found for them so far
- names: HashMap<@str, @ast::Expr>,
- name_types: HashMap<@str, ArgumentType>,
+ names: HashMap<~str, @ast::Expr>,
+ name_types: HashMap<~str, ArgumentType>,
// Collection of the compiled `rt::Piece` structures
pieces: ~[@ast::Expr],
- name_positions: HashMap<@str, uint>,
+ name_positions: HashMap<~str, uint>,
method_statics: ~[@ast::Item],
// Updated as arguments are consumed or methods are entered
return (extra, None);
}
};
- let name = self.ecx.str_of(ident);
+ let interned_name = token::get_ident(ident.name);
+ let name = interned_name.get();
p.expect(&token::EQ);
let e = p.parse_expr();
- match self.names.find(&name) {
+ match self.names.find_equiv(&name) {
None => {}
Some(prev) => {
self.ecx.span_err(e.span, format!("duplicate argument \
continue
}
}
- self.names.insert(name, e);
+ self.names.insert(name.to_str(), e);
} else {
self.args.push(p.parse_expr());
self.arg_types.push(None);
Exact(i)
}
parse::ArgumentIs(i) => Exact(i),
- parse::ArgumentNamed(s) => Named(s.to_managed()),
+ parse::ArgumentNamed(s) => Named(s.to_str()),
};
// and finally the method being applied
match arg.method {
None => {
- let ty = Known(arg.format.ty.to_managed());
+ let ty = Known(arg.format.ty.to_str());
self.verify_arg_type(pos, ty);
}
Some(ref method) => { self.verify_method(pos, *method); }
self.verify_arg_type(Exact(i), Unsigned);
}
parse::CountIsName(s) => {
- self.verify_arg_type(Named(s.to_managed()), Unsigned);
+ self.verify_arg_type(Named(s.to_str()), Unsigned);
}
parse::CountIsNextParam => {
if self.check_positional_ok() {
self.ecx.span_err(self.fmtsp, msg);
return;
}
- self.verify_same(self.args[arg].span, ty, self.arg_types[arg]);
+ {
+ let arg_type = match self.arg_types[arg] {
+ None => None,
+ Some(ref x) => Some(x)
+ };
+ self.verify_same(self.args[arg].span, &ty, arg_type);
+ }
if self.arg_types[arg].is_none() {
self.arg_types[arg] = Some(ty);
}
return;
}
};
- self.verify_same(span, ty,
- self.name_types.find(&name).map(|&x| x));
+ self.verify_same(span, &ty, self.name_types.find(&name));
if !self.name_types.contains_key(&name) {
- self.name_types.insert(name, ty);
+ self.name_types.insert(name.clone(), ty);
}
// Assign this named argument a slot in the arguments array if
// it hasn't already been assigned a slot.
///
/// Obviously `Some(Some(x)) != Some(Some(y))`, but we consider it true
/// that: `Some(None) == Some(Some(x))`
- fn verify_same(&self, sp: Span, ty: ArgumentType,
- before: Option<ArgumentType>) {
+ fn verify_same(&self,
+ sp: Span,
+ ty: &ArgumentType,
+ before: Option<&ArgumentType>) {
let cur = match before {
None => return,
Some(t) => t,
};
- if ty == cur { return }
+ if *ty == *cur {
+ return
+ }
match (cur, ty) {
- (Known(cur), Known(ty)) => {
+ (&Known(ref cur), &Known(ref ty)) => {
self.ecx.span_err(sp,
format!("argument redeclared with type `{}` when \
- it was previously `{}`", ty, cur));
+ it was previously `{}`",
+ *ty,
+ *cur));
}
- (Known(cur), _) => {
+ (&Known(ref cur), _) => {
self.ecx.span_err(sp,
format!("argument used to format with `{}` was \
attempted to not be used for formatting",
- cur));
+ *cur));
}
- (_, Known(ty)) => {
+ (_, &Known(ref ty)) => {
self.ecx.span_err(sp,
format!("argument previously used as a format \
argument attempted to be used as `{}`",
- ty));
+ *ty));
}
(_, _) => {
self.ecx.span_err(sp, "argument declared with multiple formats");
self.ecx.expr_path(path)
}
parse::CountIsName(n) => {
- let n = n.to_managed();
- let i = match self.name_positions.find_copy(&n) {
- Some(i) => i,
+ let i = match self.name_positions.find_equiv(&n) {
+ Some(&i) => i,
None => 0, // error already emitted elsewhere
};
let i = i + self.args.len();
// Named arguments are converted to positional arguments at
// the end of the list of arguments
parse::ArgumentNamed(n) => {
- let n = n.to_managed();
- let i = match self.name_positions.find_copy(&n) {
- Some(i) => i,
+ let i = match self.name_positions.find_equiv(&n) {
+ Some(&i) => i,
None => 0, // error already emitted elsewhere
};
let i = i + self.args.len();
locals.push(self.format_arg(e.span, Exact(i),
self.ecx.expr_ident(e.span, name)));
}
- for (&name, &e) in self.names.iter() {
- if !self.name_types.contains_key(&name) { continue }
+ for (name, &e) in self.names.iter() {
+ if !self.name_types.contains_key(name) {
+ continue
+ }
- let lname = self.ecx.ident_of(format!("__arg{}", name));
+ let lname = self.ecx.ident_of(format!("__arg{}", *name));
let e = self.ecx.expr_addr_of(e.span, e);
lets.push(self.ecx.stmt_let(e.span, false, lname, e));
- names[*self.name_positions.get(&name)] =
- Some(self.format_arg(e.span, Named(name),
+ names[*self.name_positions.get(name)] =
+ Some(self.format_arg(e.span,
+ Named((*name).clone()),
self.ecx.expr_ident(e.span, lname)));
}
Some(result)))
}
- fn format_arg(&self, sp: Span, argno: Position,
- arg: @ast::Expr) -> @ast::Expr {
+ fn format_arg(&self, sp: Span, argno: Position, arg: @ast::Expr)
+ -> @ast::Expr {
let ty = match argno {
- Exact(i) => self.arg_types[i].unwrap(),
- Named(s) => *self.name_types.get(&s)
+ Exact(ref i) => self.arg_types[*i].get_ref(),
+ Named(ref s) => self.name_types.get(s)
};
- let fmt_trait = match ty {
- Known(tyname) => {
- match tyname.as_slice() {
+ let fmt_trait = match *ty {
+ Known(ref tyname) => {
+ match (*tyname).as_slice() {
"" => "Default",
"?" => "Poly",
"b" => "Bool",
"x" => "LowerHex",
"X" => "UpperHex",
_ => {
- self.ecx.span_err(sp, format!("unknown format trait \
- `{}`", tyname));
+ self.ecx.span_err(sp,
+ format!("unknown format trait `{}`",
+ *tyname));
"Dummy"
}
}
pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> base::MacResult {
base::check_zero_tts(cx, sp, tts, "module_path!");
- let string = cx.mod_path().map(|x| cx.str_of(*x)).connect("::");
+ let string = cx.mod_path()
+ .map(|x| {
+ let interned_str = token::get_ident(x.name);
+ interned_str.get().to_str()
+ })
+ .connect("::");
base::MRExpr(cx.expr_str(sp, token::intern_and_get_ident(string)))
}
use parse::attr::ParserAttr;
use parse::token::{get_ident_interner, special_idents, gensym_ident, ident_to_str};
use parse::token::{FAT_ARROW, SEMI, NtMatchers, NtTT, EOF};
+use parse::token;
use print;
use std::cell::RefCell;
use util::small_vector::SmallVector;
rhses: &[@NamedMatch])
-> MacResult {
if cx.trace_macros() {
+ let interned_name = token::get_ident(name.name);
println!("{}! \\{ {} \\}",
- cx.str_of(name),
- print::pprust::tt_to_str(&TTDelim(@arg.to_owned()),
- get_ident_interner()));
+ interned_name.get(),
+ print::pprust::tt_to_str(&TTDelim(@arg.to_owned()),
+ get_ident_interner()));
}
// Which arm's failure should we report? (the one furthest along)
pub fn noop_fold_view_item<T: Folder>(vi: &ViewItem, folder: &mut T)
-> ViewItem{
let inner_view_item = match vi.node {
- ViewItemExternMod(ref ident,
- string,
- node_id) => {
+ ViewItemExternMod(ref ident, ref string, node_id) => {
ViewItemExternMod(ident.clone(),
- string,
- folder.new_id(node_id))
+ (*string).clone(),
+ folder.new_id(node_id))
}
ViewItemUse(ref view_paths) => {
ViewItemUse(folder.fold_view_paths(*view_paths))