syntax: convert LitBinary from @[u8] to Rc<~[u8]>.

This commit is contained in:
Huon Wilson 2014-02-01 15:54:41 +11:00
parent b972cadf61
commit 891ada9be1
5 changed files with 8 additions and 9 deletions

View File

@ -75,7 +75,7 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: ast::Lit)
ast::LitBool(b) => C_bool(b),
ast::LitNil => C_nil(),
ast::LitStr(ref s, _) => C_str_slice(cx, (*s).clone()),
ast::LitBinary(data) => C_binary_slice(cx, data),
ast::LitBinary(ref data) => C_binary_slice(cx, *data.borrow()),
}
}

View File

@ -1151,7 +1151,7 @@ impl ToSource for syntax::codemap::Span {
fn lit_to_str(lit: &ast::Lit) -> ~str {
match lit.node {
ast::LitStr(ref st, _) => st.get().to_owned(),
ast::LitBinary(data) => format!("{:?}", data.as_slice()),
ast::LitBinary(ref data) => format!("{:?}", data.borrow().as_slice()),
ast::LitChar(c) => ~"'" + std::char::from_u32(c).unwrap().to_str() + "'",
ast::LitInt(i, _t) => i.to_str(),
ast::LitUint(u, _t) => u.to_str(),

View File

@ -20,6 +20,7 @@ use parse::token;
use std::cell::RefCell;
use std::hashmap::HashMap;
use std::option::Option;
use std::rc::Rc;
use std::to_str::ToStr;
use extra::serialize::{Encodable, Decodable, Encoder, Decoder};
@ -724,7 +725,7 @@ pub type Lit = Spanned<Lit_>;
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum Lit_ {
LitStr(InternedString, StrStyle),
LitBinary(@[u8]),
LitBinary(Rc<~[u8]>),
LitChar(u32),
LitInt(i64, IntTy),
LitUint(u64, UintTy),

View File

@ -22,6 +22,7 @@ use print::pprust;
use std::io;
use std::io::File;
use std::rc::Rc;
use std::str;
// These macros all relate to the file system; they either return
@ -135,8 +136,6 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> base::MacResult
{
use std::at_vec;
let file = match get_single_str_from_tts(cx, sp, tts, "include_bin!") {
Some(f) => f,
None => return MacResult::dummy_expr()
@ -148,8 +147,7 @@ pub fn expand_include_bin(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
return MacResult::dummy_expr();
}
Ok(bytes) => {
let bytes = at_vec::to_managed_move(bytes);
base::MRExpr(cx.expr_lit(sp, ast::LitBinary(bytes)))
base::MRExpr(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes))))
}
}
}

View File

@ -2212,10 +2212,10 @@ pub fn print_literal(s: &mut State, lit: &ast::Lit) {
ast::LitBool(val) => {
if val { word(&mut s.s, "true"); } else { word(&mut s.s, "false"); }
}
ast::LitBinary(arr) => {
ast::LitBinary(ref arr) => {
ibox(s, indent_unit);
word(&mut s.s, "[");
commasep_cmnt(s, Inconsistent, arr, |s, u| word(&mut s.s, format!("{}", *u)),
commasep_cmnt(s, Inconsistent, *arr.borrow(), |s, u| word(&mut s.s, format!("{}", *u)),
|_| lit.span);
word(&mut s.s, "]");
end(s);