diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-01-15 16:26:20 -0800 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-02-02 01:44:48 +1100 |
| commit | e68108b3e8b8eaef62bb7b7340a77b96fcfc51cd (patch) | |
| tree | 1c39cd392414e5db5505c05ce8f3abbd170f068a /src/libsyntax | |
| parent | f152be7a425e7d66f717ffe8b210bcacf82539cc (diff) | |
| download | rust-e68108b3e8b8eaef62bb7b7340a77b96fcfc51cd.tar.gz rust-e68108b3e8b8eaef62bb7b7340a77b96fcfc51cd.zip | |
librustc: Stop using `@str` for source.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/codemap.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/comments.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 88 | ||||
| -rw-r--r-- | src/libsyntax/util/parser_testing.rs | 22 |
7 files changed, 69 insertions, 75 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index d4a412bbe9f..16b31f0a415 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -206,7 +206,7 @@ pub struct FileMap { /// e.g. `<anon>` name: FileName, /// The complete source code - src: @str, + src: ~str, /// The start position of this source in the CodeMap start_pos: BytePos, /// Locations of lines beginnings in the source code @@ -267,7 +267,7 @@ impl CodeMap { } } - pub fn new_filemap(&self, filename: FileName, src: @str) -> @FileMap { + pub fn new_filemap(&self, filename: FileName, src: ~str) -> @FileMap { let mut files = self.files.borrow_mut(); let start_pos = match files.get().last() { None => 0, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d98a549725c..3eaafba55cd 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1047,7 +1047,7 @@ mod test { ~[], sess); // should fail: let mut loader = ErrLoader; - expand_crate(sess,&mut loader,~[],crate_ast); + expand_crate(sess, &mut loader, ~[], crate_ast); } #[test] fn test_contains_flatten (){ diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 71879fc2f1e..11f61c340fc 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -203,7 +203,7 @@ pub mod rt { ($t:ty) => ( impl ToTokens for $t { fn to_tokens(&self, cx: &ExtCtxt) -> ~[TokenTree] { - cx.parse_tts(self.to_source().to_managed()) + cx.parse_tts(self.to_source()) } } ) @@ -213,7 +213,7 @@ pub mod rt { ($t:ty) => ( impl<'a> ToTokens for $t { fn to_tokens(&self, cx: &ExtCtxt) -> ~[TokenTree] { - cx.parse_tts(self.to_source().to_managed()) + cx.parse_tts(self.to_source()) } } ) @@ -240,15 +240,15 @@ pub mod rt { impl_to_tokens!(u64) pub trait ExtParseUtils { - fn parse_item(&self, s: @str) -> @ast::Item; - fn parse_expr(&self, s: @str) -> @ast::Expr; - fn parse_stmt(&self, s: @str) -> @ast::Stmt; - fn parse_tts(&self, s: @str) -> ~[ast::TokenTree]; + fn parse_item(&self, s: ~str) -> @ast::Item; + fn parse_expr(&self, s: ~str) -> @ast::Expr; + fn parse_stmt(&self, s: ~str) -> @ast::Stmt; + fn parse_tts(&self, s: ~str) -> ~[ast::TokenTree]; } impl<'a> ExtParseUtils for ExtCtxt<'a> { - fn parse_item(&self, s: @str) -> @ast::Item { + fn parse_item(&self, s: ~str) -> @ast::Item { let res = parse::parse_item_from_source_str( @"<quote expansion>", s, @@ -257,13 +257,13 @@ pub mod rt { match res { Some(ast) => ast, None => { - error!("Parse error with ```\n{}\n```", s); + error!("Parse error"); fail!() } } } - fn parse_stmt(&self, s: @str) -> @ast::Stmt { + fn parse_stmt(&self, s: ~str) -> @ast::Stmt { parse::parse_stmt_from_source_str( @"<quote expansion>", s, @@ -272,7 +272,7 @@ pub mod rt { self.parse_sess()) } - fn parse_expr(&self, s: @str) -> @ast::Expr { + fn parse_expr(&self, s: ~str) -> @ast::Expr { parse::parse_expr_from_source_str( @"<quote expansion>", s, @@ -280,7 +280,7 @@ pub mod rt { self.parse_sess()) } - fn parse_tts(&self, s: @str) -> ~[ast::TokenTree] { + fn parse_tts(&self, s: ~str) -> ~[ast::TokenTree] { parse::parse_tts_from_source_str( @"<quote expansion>", s, diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index b67f3ed263e..1367ab0677e 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -114,11 +114,11 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) Some(src) => { // Add this input file to the code map to make it available as // dependency information - let src = src.to_managed(); let filename = file.display().to_str().to_managed(); + let interned = token::intern_and_get_ident(src); cx.parse_sess.cm.new_filemap(filename, src); - base::MRExpr(cx.expr_str(sp, token::intern_and_get_ident(src))) + base::MRExpr(cx.expr_str(sp, interned)) } None => { cx.span_err(sp, format!("{} wasn't a utf-8 file", file.display())); diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 21a34ab5e1e..bbd0e00f4dd 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -350,7 +350,7 @@ pub fn gather_comments_and_literals(span_diagnostic: path: @str, srdr: &mut io::Reader) -> (~[Comment], ~[Literal]) { - let src = str::from_utf8_owned(srdr.read_to_end()).unwrap().to_managed(); + let src = str::from_utf8_owned(srdr.read_to_end()).unwrap(); let cm = CodeMap::new(); let filemap = cm.new_filemap(path, src); let rdr = lexer::new_low_level_string_reader(span_diagnostic, filemap); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index e026a11cafe..e7bc5ff3df3 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -89,12 +89,11 @@ pub fn parse_crate_attrs_from_file( return inner; } -pub fn parse_crate_from_source_str( - name: @str, - source: @str, - cfg: ast::CrateConfig, - sess: @ParseSess -) -> ast::Crate { +pub fn parse_crate_from_source_str(name: @str, + source: ~str, + cfg: ast::CrateConfig, + sess: @ParseSess) + -> ast::Crate { let mut p = new_parser_from_source_str(sess, /*bad*/ cfg.clone(), name, @@ -102,12 +101,11 @@ pub fn parse_crate_from_source_str( maybe_aborted(p.parse_crate_mod(),p) } -pub fn parse_crate_attrs_from_source_str( - name: @str, - source: @str, - cfg: ast::CrateConfig, - sess: @ParseSess -) -> ~[ast::Attribute] { +pub fn parse_crate_attrs_from_source_str(name: @str, + source: ~str, + cfg: ast::CrateConfig, + sess: @ParseSess) + -> ~[ast::Attribute] { let mut p = new_parser_from_source_str(sess, /*bad*/ cfg.clone(), name, @@ -116,44 +114,40 @@ pub fn parse_crate_attrs_from_source_str( return inner; } -pub fn parse_expr_from_source_str( - name: @str, - source: @str, - cfg: ast::CrateConfig, - sess: @ParseSess -) -> @ast::Expr { +pub fn parse_expr_from_source_str(name: @str, + source: ~str, + cfg: ast::CrateConfig, + sess: @ParseSess) + -> @ast::Expr { let mut p = new_parser_from_source_str(sess, cfg, name, source); maybe_aborted(p.parse_expr(), p) } -pub fn parse_item_from_source_str( - name: @str, - source: @str, - cfg: ast::CrateConfig, - sess: @ParseSess -) -> Option<@ast::Item> { +pub fn parse_item_from_source_str(name: @str, + source: ~str, + cfg: ast::CrateConfig, + sess: @ParseSess) + -> Option<@ast::Item> { let mut p = new_parser_from_source_str(sess, cfg, name, source); let attrs = p.parse_outer_attributes(); maybe_aborted(p.parse_item(attrs),p) } -pub fn parse_meta_from_source_str( - name: @str, - source: @str, - cfg: ast::CrateConfig, - sess: @ParseSess -) -> @ast::MetaItem { +pub fn parse_meta_from_source_str(name: @str, + source: ~str, + cfg: ast::CrateConfig, + sess: @ParseSess) + -> @ast::MetaItem { let mut p = new_parser_from_source_str(sess, cfg, name, source); maybe_aborted(p.parse_meta_item(),p) } -pub fn parse_stmt_from_source_str( - name: @str, - source: @str, - cfg: ast::CrateConfig, - attrs: ~[ast::Attribute], - sess: @ParseSess -) -> @ast::Stmt { +pub fn parse_stmt_from_source_str(name: @str, + source: ~str, + cfg: ast::CrateConfig, + attrs: ~[ast::Attribute], + sess: @ParseSess) + -> @ast::Stmt { let mut p = new_parser_from_source_str( sess, cfg, @@ -163,12 +157,11 @@ pub fn parse_stmt_from_source_str( maybe_aborted(p.parse_stmt(attrs),p) } -pub fn parse_tts_from_source_str( - name: @str, - source: @str, - cfg: ast::CrateConfig, - sess: @ParseSess -) -> ~[ast::TokenTree] { +pub fn parse_tts_from_source_str(name: @str, + source: ~str, + cfg: ast::CrateConfig, + sess: @ParseSess) + -> ~[ast::TokenTree] { let mut p = new_parser_from_source_str( sess, cfg, @@ -184,8 +177,8 @@ pub fn parse_tts_from_source_str( pub fn new_parser_from_source_str(sess: @ParseSess, cfg: ast::CrateConfig, name: @str, - source: @str) - -> Parser { + source: ~str) + -> Parser { filemap_to_parser(sess,string_to_filemap(sess,source,name),cfg) } @@ -248,7 +241,8 @@ pub fn file_to_filemap(sess: @ParseSess, path: &Path, spanopt: Option<Span>) }; match str::from_utf8_owned(bytes) { Some(s) => { - return string_to_filemap(sess, s.to_managed(), + return string_to_filemap(sess, + s, path.as_str().unwrap().to_managed()); } None => { @@ -260,7 +254,7 @@ pub fn file_to_filemap(sess: @ParseSess, path: &Path, spanopt: Option<Span>) // given a session and a string, add the string to // the session's codemap and return the new filemap -pub fn string_to_filemap(sess: @ParseSess, source: @str, path: @str) +pub fn string_to_filemap(sess: @ParseSess, source: ~str, path: @str) -> @FileMap { sess.cm.new_filemap(path, source) } diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs index dd3ae168149..02bfa31d0e1 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -17,29 +17,29 @@ use parse::token; // map a string to tts, using a made-up filename: return both the TokenTree's // and the ParseSess -pub fn string_to_tts_and_sess (source_str : @str) -> (~[ast::TokenTree], @ParseSess) { +pub fn string_to_tts_and_sess (source_str : ~str) -> (~[ast::TokenTree], @ParseSess) { let ps = new_parse_sess(None); (filemap_to_tts(ps,string_to_filemap(ps,source_str,@"bogofile")),ps) } // map a string to tts, using a made-up filename: -pub fn string_to_tts(source_str : @str) -> ~[ast::TokenTree] { +pub fn string_to_tts(source_str : ~str) -> ~[ast::TokenTree] { let (tts,_) = string_to_tts_and_sess(source_str); tts } -pub fn string_to_parser_and_sess(source_str: @str) -> (Parser,@ParseSess) { +pub fn string_to_parser_and_sess(source_str: ~str) -> (Parser,@ParseSess) { let ps = new_parse_sess(None); (new_parser_from_source_str(ps,~[],@"bogofile",source_str),ps) } // map string to parser (via tts) -pub fn string_to_parser(source_str: @str) -> Parser { +pub fn string_to_parser(source_str: ~str) -> Parser { let (p,_) = string_to_parser_and_sess(source_str); p } -fn with_error_checking_parse<T>(s: @str, f: |&mut Parser| -> T) -> T { +fn with_error_checking_parse<T>(s: ~str, f: |&mut Parser| -> T) -> T { let mut p = string_to_parser(s); let x = f(&mut p); p.abort_if_errors(); @@ -47,34 +47,34 @@ fn with_error_checking_parse<T>(s: @str, f: |&mut Parser| -> T) -> T { } // parse a string, return a crate. -pub fn string_to_crate (source_str : @str) -> ast::Crate { +pub fn string_to_crate (source_str : ~str) -> ast::Crate { with_error_checking_parse(source_str, |p| { p.parse_crate_mod() }) } // parse a string, return a crate and the ParseSess -pub fn string_to_crate_and_sess (source_str : @str) -> (ast::Crate,@ParseSess) { +pub fn string_to_crate_and_sess (source_str : ~str) -> (ast::Crate,@ParseSess) { let (mut p,ps) = string_to_parser_and_sess(source_str); (p.parse_crate_mod(),ps) } // parse a string, return an expr -pub fn string_to_expr (source_str : @str) -> @ast::Expr { +pub fn string_to_expr (source_str : ~str) -> @ast::Expr { with_error_checking_parse(source_str, |p| { p.parse_expr() }) } // parse a string, return an item -pub fn string_to_item (source_str : @str) -> Option<@ast::Item> { +pub fn string_to_item (source_str : ~str) -> Option<@ast::Item> { with_error_checking_parse(source_str, |p| { p.parse_item(~[]) }) } // parse a string, return a stmt -pub fn string_to_stmt(source_str : @str) -> @ast::Stmt { +pub fn string_to_stmt(source_str : ~str) -> @ast::Stmt { with_error_checking_parse(source_str, |p| { p.parse_stmt(~[]) }) @@ -82,7 +82,7 @@ pub fn string_to_stmt(source_str : @str) -> @ast::Stmt { // parse a string, return a pat. Uses "irrefutable"... which doesn't // (currently) affect parsing. -pub fn string_to_pat(source_str : @str) -> @ast::Pat { +pub fn string_to_pat(source_str : ~str) -> @ast::Pat { string_to_parser(source_str).parse_pat() } |
