librustc: Stop using @str
for source.
This commit is contained in:
parent
f152be7a42
commit
e68108b3e8
10 changed files with 87 additions and 89 deletions
|
@ -138,7 +138,7 @@ fn parse_cfgspecs(cfgspecs: ~[~str], demitter: @diagnostic::Emitter)
|
|||
-> ast::CrateConfig {
|
||||
cfgspecs.move_iter().map(|s| {
|
||||
let sess = parse::new_parse_sess(Some(demitter));
|
||||
parse::parse_meta_from_source_str(@"cfgspec", s.to_managed(), ~[], sess)
|
||||
parse::parse_meta_from_source_str(@"cfgspec", s, ~[], sess)
|
||||
}).collect::<ast::CrateConfig>()
|
||||
}
|
||||
|
||||
|
@ -146,8 +146,7 @@ pub enum Input {
|
|||
/// Load source from file
|
||||
FileInput(Path),
|
||||
/// The string is the source
|
||||
// FIXME (#2319): Don't really want to box the source string
|
||||
StrInput(@str)
|
||||
StrInput(~str)
|
||||
}
|
||||
|
||||
pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input)
|
||||
|
@ -157,9 +156,11 @@ pub fn phase_1_parse_input(sess: Session, cfg: ast::CrateConfig, input: &Input)
|
|||
FileInput(ref file) => {
|
||||
parse::parse_crate_from_file(&(*file), cfg.clone(), sess.parse_sess)
|
||||
}
|
||||
StrInput(src) => {
|
||||
parse::parse_crate_from_source_str(
|
||||
anon_src(), src, cfg.clone(), sess.parse_sess)
|
||||
StrInput(ref src) => {
|
||||
parse::parse_crate_from_source_str(anon_src(),
|
||||
(*src).clone(),
|
||||
cfg.clone(),
|
||||
sess.parse_sess)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -624,7 +625,7 @@ pub fn pretty_print_input(sess: Session,
|
|||
_ => @pprust::NoAnn as @pprust::PpAnn,
|
||||
};
|
||||
|
||||
let src = sess.codemap.get_filemap(source_name(input)).src;
|
||||
let src = &sess.codemap.get_filemap(source_name(input)).src;
|
||||
let mut rdr = MemReader::new(src.as_bytes().to_owned());
|
||||
let stdout = io::stdout();
|
||||
pprust::print_crate(sess.codemap,
|
||||
|
|
|
@ -236,8 +236,9 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
|
|||
1u => {
|
||||
let ifile = matches.free[0].as_slice();
|
||||
if "-" == ifile {
|
||||
let src = str::from_utf8_owned(io::stdin().read_to_end()).unwrap();
|
||||
(d::StrInput(src.to_managed()), None)
|
||||
let src =
|
||||
str::from_utf8_owned(io::stdin().read_to_end()).unwrap();
|
||||
(d::StrInput(src), None)
|
||||
} else {
|
||||
(d::FileInput(Path::new(ifile)), Some(Path::new(ifile)))
|
||||
}
|
||||
|
@ -319,9 +320,11 @@ fn parse_crate_attrs(sess: session::Session,
|
|||
d::FileInput(ref ifile) => {
|
||||
parse::parse_crate_attrs_from_file(ifile, ~[], sess.parse_sess)
|
||||
}
|
||||
d::StrInput(src) => {
|
||||
parse::parse_crate_attrs_from_source_str(
|
||||
d::anon_src(), src, ~[], sess.parse_sess)
|
||||
d::StrInput(ref src) => {
|
||||
parse::parse_crate_attrs_from_source_str(d::anon_src(),
|
||||
(*src).clone(),
|
||||
~[],
|
||||
sess.parse_sess)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>) {
|
|||
}
|
||||
}
|
||||
|
||||
fn maketest(s: &str, cratename: &str) -> @str {
|
||||
fn maketest(s: &str, cratename: &str) -> ~str {
|
||||
let mut prog = ~r"
|
||||
#[deny(warnings)];
|
||||
#[allow(unused_variable, dead_assignment, unused_mut, attribute_usage, dead_code)];
|
||||
|
@ -156,7 +156,7 @@ fn maketest(s: &str, cratename: &str) -> @str {
|
|||
prog.push_str("\n}");
|
||||
}
|
||||
|
||||
return prog.to_managed();
|
||||
return prog;
|
||||
}
|
||||
|
||||
pub struct Collector {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -89,12 +89,11 @@ pub fn parse_crate_attrs_from_file(
|
|||
return inner;
|
||||
}
|
||||
|
||||
pub fn parse_crate_from_source_str(
|
||||
name: @str,
|
||||
source: @str,
|
||||
pub fn parse_crate_from_source_str(name: @str,
|
||||
source: ~str,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: @ParseSess
|
||||
) -> ast::Crate {
|
||||
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,
|
||||
pub fn parse_crate_attrs_from_source_str(name: @str,
|
||||
source: ~str,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: @ParseSess
|
||||
) -> ~[ast::Attribute] {
|
||||
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,
|
||||
pub fn parse_expr_from_source_str(name: @str,
|
||||
source: ~str,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: @ParseSess
|
||||
) -> @ast::Expr {
|
||||
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,
|
||||
pub fn parse_item_from_source_str(name: @str,
|
||||
source: ~str,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: @ParseSess
|
||||
) -> Option<@ast::Item> {
|
||||
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,
|
||||
pub fn parse_meta_from_source_str(name: @str,
|
||||
source: ~str,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: @ParseSess
|
||||
) -> @ast::MetaItem {
|
||||
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,
|
||||
pub fn parse_stmt_from_source_str(name: @str,
|
||||
source: ~str,
|
||||
cfg: ast::CrateConfig,
|
||||
attrs: ~[ast::Attribute],
|
||||
sess: @ParseSess
|
||||
) -> @ast::Stmt {
|
||||
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,
|
||||
pub fn parse_tts_from_source_str(name: @str,
|
||||
source: ~str,
|
||||
cfg: ast::CrateConfig,
|
||||
sess: @ParseSess
|
||||
) -> ~[ast::TokenTree] {
|
||||
sess: @ParseSess)
|
||||
-> ~[ast::TokenTree] {
|
||||
let mut p = new_parser_from_source_str(
|
||||
sess,
|
||||
cfg,
|
||||
|
@ -184,7 +177,7 @@ pub fn parse_tts_from_source_str(
|
|||
pub fn new_parser_from_source_str(sess: @ParseSess,
|
||||
cfg: ast::CrateConfig,
|
||||
name: @str,
|
||||
source: @str)
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue