Skip to content

Commit

Permalink
Fix build on 0.11pre: Change ~"foo" to "foo".to_owned()
Browse files Browse the repository at this point in the history
[~"string" and &"string" literals are gone](rust-lang/rust#13877), and were
replaced by "string".to_owned() and just "string", respectively. This commit was made by a simple
`sed` to convert the existing instances of ~"string" on the codebase.

For reference, the command used was this:

    sed -e 's/~\("[^"]*"\)/\1.to_owned()/g' -i *.rs

That wouldn't work if for strings that contain the `\"` escape in them, but this codebase had none.

Similar work is likely to be necessary after [~T is substituted by
Box<T>](rust-lang/rust#13885).
  • Loading branch information
renato-zannon committed May 2, 2014
1 parent 02cc483 commit 6b4a11c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 38 deletions.
50 changes: 25 additions & 25 deletions gen.rs
Expand Up @@ -56,7 +56,7 @@ fn empty_generics() -> ast::Generics {
fn rust_id(ctx: &mut GenCtx, name: ~str) -> (~str, bool) { fn rust_id(ctx: &mut GenCtx, name: ~str) -> (~str, bool) {
let token = parse::token::IDENT(ctx.ext_cx.ident_of(name), false); let token = parse::token::IDENT(ctx.ext_cx.ident_of(name), false);
if parse::token::is_any_keyword(&token) || "bool" == name { if parse::token::is_any_keyword(&token) || "bool" == name {
(~"_" + name, true) ("_".to_owned() + name, true)
} else { } else {
(name, false) (name, false)
} }
Expand All @@ -77,7 +77,7 @@ fn rust_type_id(ctx: &mut GenCtx, name: ~str) -> ~str {
"i64" == name || "i64" == name ||
"Self" == name || "Self" == name ||
"str" == name { "str" == name {
~"_" + name "_".to_owned() + name
} else { } else {
let (n, _) = rust_id(ctx, name); let (n, _) = rust_id(ctx, name);
n n
Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn gen_rs(out: ~io::Writer, abi: ~str, link: &Option<~str>, globs: Vec<Globa
}; };
ctx.ext_cx.bt_push(ExpnInfo { ctx.ext_cx.bt_push(ExpnInfo {
call_site: DUMMY_SP, call_site: DUMMY_SP,
callee: NameAndSpan { name: ~"", format: MacroBang, span: None } callee: NameAndSpan { name: "".to_owned(), format: MacroBang, span: None }
}); });
let uniq_globs = tag_dup_decl(globs); let uniq_globs = tag_dup_decl(globs);


Expand Down Expand Up @@ -214,7 +214,7 @@ pub fn gen_rs(out: ~io::Writer, abi: ~str, link: &Option<~str>, globs: Vec<Globa
let v = vi.borrow(); let v = vi.borrow();
cvar_to_rs(&mut ctx, v.name.clone(), &v.ty, v.is_const) cvar_to_rs(&mut ctx, v.name.clone(), &v.ty, v.is_const)
}, },
_ => { fail!(~"generate global variables") } _ => { fail!("generate global variables".to_owned()) }
} }
}).collect(); }).collect();


Expand All @@ -225,14 +225,14 @@ pub fn gen_rs(out: ~io::Writer, abi: ~str, link: &Option<~str>, globs: Vec<Globa
match v.ty { match v.ty {
TFunc(ref rty, ref aty, var) => cfunc_to_rs(&mut ctx, v.name.clone(), TFunc(ref rty, ref aty, var) => cfunc_to_rs(&mut ctx, v.name.clone(),
*rty, *aty, var), *rty, *aty, var),
_ => { fail!(~"generate functions") } _ => { fail!("generate functions".to_owned()) }
} }
}, },
_ => { fail!(~"generate functions") } _ => { fail!("generate functions".to_owned()) }
} }
}).collect(); }).collect();


let views = Vec::from_elem(1, mk_import(&mut ctx, &[~"libc"])); let views = Vec::from_elem(1, mk_import(&mut ctx, &["libc".to_owned()]));
defs.push(mk_extern(&mut ctx, link, vars, funcs)); defs.push(mk_extern(&mut ctx, link, vars, funcs));


let crate_ = ast::Crate { let crate_ = ast::Crate {
Expand Down Expand Up @@ -292,7 +292,7 @@ fn mk_extern(ctx: &mut GenCtx, link: &Option<~str>,
None => attrs = Vec::new(), None => attrs = Vec::new(),
Some(ref l) => { Some(ref l) => {
let link_name = @dummy_spanned(ast::MetaNameValue( let link_name = @dummy_spanned(ast::MetaNameValue(
to_intern_str(ctx, ~"name"), to_intern_str(ctx, "name".to_owned()),
dummy_spanned(ast::LitStr( dummy_spanned(ast::LitStr(
to_intern_str(ctx, l.to_owned()), to_intern_str(ctx, l.to_owned()),
ast::CookedStr ast::CookedStr
Expand All @@ -301,7 +301,7 @@ fn mk_extern(ctx: &mut GenCtx, link: &Option<~str>,
let link_args = dummy_spanned(ast::Attribute_ { let link_args = dummy_spanned(ast::Attribute_ {
style: ast::AttrOuter, style: ast::AttrOuter,
value: @dummy_spanned(ast::MetaList( value: @dummy_spanned(ast::MetaList(
to_intern_str(ctx, ~"link"), to_intern_str(ctx, "link".to_owned()),
Vec::from_elem(1, link_name)) Vec::from_elem(1, link_name))
), ),
is_sugared_doc: false is_sugared_doc: false
Expand Down Expand Up @@ -623,7 +623,7 @@ fn cunion_to_rs(ctx: &mut GenCtx, name: ~str, layout: Layout, fields: Vec<FieldI


return vec!( return vec!(
union_def, union_def,
mk_item(ctx, ~"", methods, ast::Inherited) mk_item(ctx, "".to_owned(), methods, ast::Inherited)
); );
} }


Expand Down Expand Up @@ -663,7 +663,7 @@ fn mk_link_name_attr(ctx: &mut GenCtx, name: ~str) -> ast::Attribute {
ast::CookedStr ast::CookedStr
)); ));
let attr_val = @dummy_spanned(ast::MetaNameValue( let attr_val = @dummy_spanned(ast::MetaNameValue(
to_intern_str(ctx, ~"link_name"), lit to_intern_str(ctx, "link_name".to_owned()), lit
)); ));
let attr = ast::Attribute_ { let attr = ast::Attribute_ {
style: ast::AttrOuter, style: ast::AttrOuter,
Expand Down Expand Up @@ -782,23 +782,23 @@ fn cfunc_to_rs(ctx: &mut GenCtx, name: ~str, rty: &Type,


fn cty_to_rs(ctx: &mut GenCtx, ty: &Type) -> ast::Ty { fn cty_to_rs(ctx: &mut GenCtx, ty: &Type) -> ast::Ty {
return match *ty { return match *ty {
TVoid => mk_ty(ctx, ~"c_void"), TVoid => mk_ty(ctx, "c_void".to_owned()),
TInt(i, _) => match i { TInt(i, _) => match i {
IBool => mk_ty(ctx, ~"c_int"), IBool => mk_ty(ctx, "c_int".to_owned()),
ISChar => mk_ty(ctx, ~"c_char"), ISChar => mk_ty(ctx, "c_char".to_owned()),
IUChar => mk_ty(ctx, ~"c_uchar"), IUChar => mk_ty(ctx, "c_uchar".to_owned()),
IInt => mk_ty(ctx, ~"c_int"), IInt => mk_ty(ctx, "c_int".to_owned()),
IUInt => mk_ty(ctx, ~"c_uint"), IUInt => mk_ty(ctx, "c_uint".to_owned()),
IShort => mk_ty(ctx, ~"c_short"), IShort => mk_ty(ctx, "c_short".to_owned()),
IUShort => mk_ty(ctx, ~"c_ushort"), IUShort => mk_ty(ctx, "c_ushort".to_owned()),
ILong => mk_ty(ctx, ~"c_long"), ILong => mk_ty(ctx, "c_long".to_owned()),
IULong => mk_ty(ctx, ~"c_ulong"), IULong => mk_ty(ctx, "c_ulong".to_owned()),
ILongLong => mk_ty(ctx, ~"c_longlong"), ILongLong => mk_ty(ctx, "c_longlong".to_owned()),
IULongLong => mk_ty(ctx, ~"c_ulonglong") IULongLong => mk_ty(ctx, "c_ulonglong".to_owned())
}, },
TFloat(f, _) => match f { TFloat(f, _) => match f {
FFloat => mk_ty(ctx, ~"c_float"), FFloat => mk_ty(ctx, "c_float".to_owned()),
FDouble => mk_ty(ctx, ~"c_double") FDouble => mk_ty(ctx, "c_double".to_owned())
}, },
TPtr(ref t, is_const, _) => { TPtr(ref t, is_const, _) => {
let id = cty_to_rs(ctx, *t); let id = cty_to_rs(ctx, *t);
Expand Down
18 changes: 9 additions & 9 deletions main.rs
Expand Up @@ -40,7 +40,7 @@ fn parse_args(args: &[~str]) -> ParseResult {
let mut out = ~io::BufferedWriter::new(io::stdout()) as ~io::Writer; let mut out = ~io::BufferedWriter::new(io::stdout()) as ~io::Writer;
let mut pat = vec!(); let mut pat = vec!();
let mut link = None; let mut link = None;
let mut abi = ~"C"; let mut abi = "C".to_owned();
let mut builtins = false; let mut builtins = false;
let mut emit_ast = false; let mut emit_ast = false;
let mut fail_on_bitfield = true; let mut fail_on_bitfield = true;
Expand All @@ -61,7 +61,7 @@ fn parse_args(args: &[~str]) -> ParseResult {
} }
"-o" => { "-o" => {
if ix + 1u >= args_len { if ix + 1u >= args_len {
return ParseErr(~"Missing output filename"); return ParseErr("Missing output filename".to_owned());
} }
let path = path::Path::new(args[ix + 1].clone()); let path = path::Path::new(args[ix + 1].clone());
match fs::File::create(&path) { match fs::File::create(&path) {
Expand All @@ -72,14 +72,14 @@ fn parse_args(args: &[~str]) -> ParseResult {
} }
"-l" => { "-l" => {
if ix + 1u >= args_len { if ix + 1u >= args_len {
return ParseErr(~"Missing link name"); return ParseErr("Missing link name".to_owned());
} }
link = Some(args[ix + 1u].clone()); link = Some(args[ix + 1u].clone());
ix += 2u; ix += 2u;
} }
"-match" => { "-match" => {
if ix + 1u >= args_len { if ix + 1u >= args_len {
return ParseErr(~"Missing match pattern"); return ParseErr("Missing match pattern".to_owned());
} }
pat.push(args[ix + 1u].clone()); pat.push(args[ix + 1u].clone());
ix += 2u; ix += 2u;
Expand Down Expand Up @@ -122,8 +122,8 @@ fn parse_args(args: &[~str]) -> ParseResult {
fn builtin_names() -> HashSet<~str> { fn builtin_names() -> HashSet<~str> {
let mut names = HashSet::new(); let mut names = HashSet::new();
let keys = ~[ let keys = ~[
~"__va_list_tag", "__va_list_tag".to_owned(),
~"__va_list", "__va_list".to_owned(),
]; ];


keys.move_iter().advance(|s| { keys.move_iter().advance(|s| {
Expand Down Expand Up @@ -269,7 +269,7 @@ fn conv_ptr_ty(ctx: &mut BindGenCtx, ty: &cx::Type, cursor: &Cursor, layout: Lay
let decl = ty.declaration(); let decl = ty.declaration();
return if ret_ty.kind() != CXType_Invalid { return if ret_ty.kind() != CXType_Invalid {
let args_lst = ty.arg_types().iter().map(|arg| { let args_lst = ty.arg_types().iter().map(|arg| {
(~"", conv_ty(ctx, arg, cursor)) ("".to_owned(), conv_ty(ctx, arg, cursor))
}).collect(); }).collect();
let ret_ty = ~conv_ty(ctx, &ret_ty, cursor); let ret_ty = ~conv_ty(ctx, &ret_ty, cursor);


Expand Down Expand Up @@ -535,12 +535,12 @@ fn main() {
ParseOk(clang_args, mut ctx, out) => { ParseOk(clang_args, mut ctx, out) => {
let ix = cx::Index::create(false, true); let ix = cx::Index::create(false, true);
if ix.is_null() { if ix.is_null() {
fail!(~"clang failed to create index"); fail!("clang failed to create index".to_owned());
} }


let unit = TranslationUnit::parse(&ix, "", clang_args, [], 0); let unit = TranslationUnit::parse(&ix, "", clang_args, [], 0);
if unit.is_null() { if unit.is_null() {
fail!(~"No input files given"); fail!("No input files given".to_owned());
} }


let mut c_err = false; let mut c_err = false;
Expand Down
8 changes: 4 additions & 4 deletions types.rs
Expand Up @@ -18,30 +18,30 @@ impl Global {
match *self { match *self {
GComp(i) => return i, GComp(i) => return i,
GCompDecl(i) => return i, GCompDecl(i) => return i,
_ => fail!(~"global_compinfo") _ => fail!("global_compinfo".to_owned())
} }
} }


pub fn enuminfo(&self) -> @RefCell<EnumInfo> { pub fn enuminfo(&self) -> @RefCell<EnumInfo> {
match *self { match *self {
GEnum(i) => return i, GEnum(i) => return i,
GEnumDecl(i) => return i, GEnumDecl(i) => return i,
_ => fail!(~"global_enuminfo") _ => fail!("global_enuminfo".to_owned())
} }
} }


pub fn typeinfo(&self) -> @RefCell<TypeInfo> { pub fn typeinfo(&self) -> @RefCell<TypeInfo> {
match *self { match *self {
GType(i) => return i, GType(i) => return i,
_ => fail!(~"global_typeinfo") _ => fail!("global_typeinfo".to_owned())
} }
} }


pub fn varinfo(&self) -> @RefCell<VarInfo> { pub fn varinfo(&self) -> @RefCell<VarInfo> {
match *self { match *self {
GVar(i) => i, GVar(i) => i,
GFunc(i) => i, GFunc(i) => i,
_ => fail!(~"global_varinfo") _ => fail!("global_varinfo".to_owned())
} }
} }
} }
Expand Down

0 comments on commit 6b4a11c

Please sign in to comment.