From f9af11d6cc0266a5690897b4645d8cab2ed1115b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Wed, 15 Jan 2014 18:30:40 -0800 Subject: [PATCH] libsyntax: Remove all `@str` from the AST --- src/librustc/metadata/creader.rs | 4 ++-- src/librustc/middle/trans/asm.rs | 18 +++++++++--------- src/libsyntax/ast.rs | 10 +++++----- src/libsyntax/ext/asm.rs | 18 +++++++++--------- src/libsyntax/fold.rs | 8 ++++++-- src/libsyntax/parse/parser.rs | 13 ++++++++----- src/libsyntax/print/pprust.rs | 14 +++++++------- 7 files changed, 46 insertions(+), 39 deletions(-) diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index c43cf0a6ad7..56ede9dfce1 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -168,8 +168,8 @@ fn extract_crate_info(i: &ast::ViewItem) -> Option { debug!("resolving extern mod stmt. ident: {:?} path_opt: {:?}", ident, path_opt); let (name, version) = match path_opt { - Some((path_str, _)) => { - let crateid: Option = from_str(path_str); + Some((ref path_str, _)) => { + let crateid: Option = from_str(path_str.get()); match crateid { None => (@"", @""), Some(crateid) => { diff --git a/src/librustc/middle/trans/asm.rs b/src/librustc/middle/trans/asm.rs index bae35f68ada..db99bd53704 100644 --- a/src/librustc/middle/trans/asm.rs +++ b/src/librustc/middle/trans/asm.rs @@ -38,8 +38,8 @@ pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::InlineAsm) let temp_scope = fcx.push_custom_cleanup_scope(); // Prepare the output operands - let outputs = ia.outputs.map(|&(c, out)| { - constraints.push(c); + let outputs = ia.outputs.map(|&(ref c, out)| { + constraints.push((*c).clone()); let out_datum = unpack_datum!(bcx, expr::trans(bcx, out)); output_types.push(type_of::type_of(bcx.ccx(), out_datum.ty)); @@ -48,8 +48,8 @@ pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::InlineAsm) }); // Now the input operands - let inputs = ia.inputs.map(|&(c, input)| { - constraints.push(c); + let inputs = ia.inputs.map(|&(ref c, input)| { + constraints.push((*c).clone()); unpack_result!(bcx, { callee::trans_arg_expr(bcx, @@ -63,13 +63,13 @@ pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::InlineAsm) // no failure occurred preparing operands, no need to cleanup fcx.pop_custom_cleanup_scope(temp_scope); - let mut constraints = constraints.connect(","); + let mut constraints = constraints.map(|s| s.get().to_str()).connect(","); let mut clobbers = getClobbers(); - if !ia.clobbers.is_empty() && !clobbers.is_empty() { - clobbers = format!("{},{}", ia.clobbers, clobbers); + if !ia.clobbers.get().is_empty() && !clobbers.is_empty() { + clobbers = format!("{},{}", ia.clobbers.get(), clobbers); } else { - clobbers.push_str(ia.clobbers); + clobbers.push_str(ia.clobbers.get()); } // Add the clobbers to our constraints list @@ -98,7 +98,7 @@ pub fn trans_inline_asm<'a>(bcx: &'a Block<'a>, ia: &ast::InlineAsm) ast::AsmIntel => lib::llvm::AD_Intel }; - let r = ia.asm.with_c_str(|a| { + let r = ia.asm.get().with_c_str(|a| { constraints.with_c_str(|c| { InlineAsmCall(bcx, a, c, inputs, output_type, ia.volatile, ia.alignstack, dialect) }) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 380641a8689..a8bbdbd60d3 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -898,11 +898,11 @@ pub enum AsmDialect { #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct InlineAsm { - asm: @str, + asm: InternedString, asm_str_style: StrStyle, - clobbers: @str, - inputs: ~[(@str, @Expr)], - outputs: ~[(@str, @Expr)], + clobbers: InternedString, + inputs: ~[(InternedString, @Expr)], + outputs: ~[(InternedString, @Expr)], volatile: bool, alignstack: bool, dialect: AsmDialect @@ -1075,7 +1075,7 @@ pub enum ViewItem_ { // optional @str: if present, this is a location (containing // arbitrary characters) from which to fetch the crate sources // For example, extern mod whatever = "github.com/mozilla/rust" - ViewItemExternMod(Ident, Option<(@str, StrStyle)>, NodeId), + ViewItemExternMod(Ident, Option<(InternedString,StrStyle)>, NodeId), ViewItemUse(~[@ViewPath]), } diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index babf0f13874..1a3ebf3ce5d 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -80,10 +80,10 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) let (constraint, _str_style) = p.parse_str(); - if constraint.starts_with("+") { + if constraint.get().starts_with("+") { cx.span_unimpl(p.last_span, "'+' (read+write) output operand constraint modifier"); - } else if !constraint.starts_with("=") { + } else if !constraint.get().starts_with("=") { cx.span_err(p.last_span, "output operand constraint lacks '='"); } @@ -105,9 +105,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) let (constraint, _str_style) = p.parse_str(); - if constraint.starts_with("=") { + if constraint.get().starts_with("=") { cx.span_err(p.last_span, "input operand constraint contains '='"); - } else if constraint.starts_with("+") { + } else if constraint.get().starts_with("+") { cx.span_err(p.last_span, "input operand constraint contains '+'"); } @@ -138,11 +138,11 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) Options => { let (option, _str_style) = p.parse_str(); - if "volatile" == option { + if option.equiv(&("volatile")) { volatile = true; - } else if "alignstack" == option { + } else if option.equiv(&("alignstack")) { alignstack = true; - } else if "intel" == option { + } else if option.equiv(&("intel")) { dialect = ast::AsmIntel; } @@ -192,9 +192,9 @@ pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) MRExpr(@ast::Expr { id: ast::DUMMY_NODE_ID, node: ast::ExprInlineAsm(ast::InlineAsm { - asm: asm.get().to_managed(), + asm: token::intern_and_get_ident(asm.get()), asm_str_style: asm_str_style.unwrap(), - clobbers: cons.to_managed(), + clobbers: token::intern_and_get_ident(cons), inputs: inputs, outputs: outputs, volatile: volatile, diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 9a346e17d28..f41d508f07d 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -814,8 +814,12 @@ pub fn noop_fold_expr(e: @Expr, folder: &mut T) -> @Expr { } ExprInlineAsm(ref a) => { ExprInlineAsm(InlineAsm { - inputs: a.inputs.map(|&(c, input)| (c, folder.fold_expr(input))), - outputs: a.outputs.map(|&(c, out)| (c, folder.fold_expr(out))), + inputs: a.inputs.map(|&(ref c, input)| { + ((*c).clone(), folder.fold_expr(input)) + }), + outputs: a.outputs.map(|&(ref c, out)| { + ((*c).clone(), folder.fold_expr(out)) + }), .. (*a).clone() }) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e86873d6418..07124120b12 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5130,17 +5130,20 @@ pub fn parse_crate_mod(&mut self) -> Crate { } } - pub fn parse_optional_str(&mut self) -> Option<(@str, ast::StrStyle)> { + pub fn parse_optional_str(&mut self) + -> Option<(InternedString, ast::StrStyle)> { let (s, style) = match self.token { - token::LIT_STR(s) => (s, ast::CookedStr), - token::LIT_STR_RAW(s, n) => (s, ast::RawStr(n)), + token::LIT_STR(s) => (self.id_to_interned_str(s), ast::CookedStr), + token::LIT_STR_RAW(s, n) => { + (self.id_to_interned_str(s), ast::RawStr(n)) + } _ => return None }; self.bump(); - Some((ident_to_str(&s), style)) + Some((s, style)) } - pub fn parse_str(&mut self) -> (@str, StrStyle) { + pub fn parse_str(&mut self) -> (InternedString, StrStyle) { match self.parse_optional_str() { Some(s) => { s } _ => self.fatal("expected string literal") diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d2a388cc14d..2761cc4ea56 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1466,25 +1466,25 @@ fn print_field(s: &mut State, field: &ast::Field) { word(&mut s.s, "asm!"); } popen(s); - print_string(s, a.asm, a.asm_str_style); + print_string(s, a.asm.get(), a.asm_str_style); word_space(s, ":"); - for &(co, o) in a.outputs.iter() { - print_string(s, co, ast::CookedStr); + for &(ref co, o) in a.outputs.iter() { + print_string(s, co.get(), ast::CookedStr); popen(s); print_expr(s, o); pclose(s); word_space(s, ","); } word_space(s, ":"); - for &(co, o) in a.inputs.iter() { - print_string(s, co, ast::CookedStr); + for &(ref co, o) in a.inputs.iter() { + print_string(s, co.get(), ast::CookedStr); popen(s); print_expr(s, o); pclose(s); word_space(s, ","); } word_space(s, ":"); - print_string(s, a.clobbers, ast::CookedStr); + print_string(s, a.clobbers.get(), ast::CookedStr); pclose(s); } ast::ExprMac(ref m) => print_mac(s, m), @@ -1998,7 +1998,7 @@ pub fn print_view_item(s: &mut State, item: &ast::ViewItem) { space(&mut s.s); word(&mut s.s, "="); space(&mut s.s); - print_string(s, *p, style); + print_string(s, p.get(), style); } } -- 2.44.0