1
Fork 0

libsyntax: De-@str pathnames

This commit is contained in:
Patrick Walton 2014-01-15 16:42:51 -08:00 committed by Huon Wilson
parent e68108b3e8
commit 8d6ef2e1b1
8 changed files with 43 additions and 48 deletions

View file

@ -61,12 +61,14 @@ pub enum PpMode {
* The name used for source code that doesn't originate in a file
* (e.g. source from stdin or a string)
*/
pub fn anon_src() -> @str { @"<anon>" }
pub fn anon_src() -> ~str {
"<anon>".to_str()
}
pub fn source_name(input: &Input) -> @str {
pub fn source_name(input: &Input) -> ~str {
match *input {
// FIXME (#9639): This needs to handle non-utf8 paths
FileInput(ref ifile) => ifile.as_str().unwrap().to_managed(),
FileInput(ref ifile) => ifile.as_str().unwrap().to_str(),
StrInput(_) => anon_src()
}
}
@ -138,7 +140,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, ~[], sess)
parse::parse_meta_from_source_str("cfgspec".to_str(), s, ~[], sess)
}).collect::<ast::CrateConfig>()
}
@ -484,13 +486,13 @@ fn write_out_deps(sess: Session, input: &Input, outputs: &OutputFilenames, crate
// Build a list of files used to compile the output and
// write Makefile-compatible dependency rules
let files: ~[@str] = {
let files: ~[~str] = {
let files = sess.codemap.files.borrow();
files.get()
.iter()
.filter_map(|fmap| {
if fmap.is_real_file() {
Some(fmap.name)
Some(fmap.name.clone())
} else {
None
}

View file

@ -931,7 +931,7 @@ fn declare_local(bcx: &Block,
span: Span) {
let cx: &CrateContext = bcx.ccx();
let filename = span_start(cx, span).file.name;
let filename = span_start(cx, span).file.name.clone();
let file_metadata = file_metadata(cx, filename);
let name: &str = token::ident_to_str(&variable_ident);
@ -1165,7 +1165,7 @@ fn prepare_struct_metadata(cx: &CrateContext,
let (containing_scope, definition_span) = get_namespace_and_span_for_item(cx, def_id, span);
let file_name = span_start(cx, definition_span).file.name;
let file_name = span_start(cx, definition_span).file.name.clone();
let file_metadata = file_metadata(cx, file_name);
let struct_metadata_stub = create_struct_stub(cx,
@ -2006,7 +2006,7 @@ fn trait_metadata(cx: &CrateContext,
let (containing_scope, definition_span) =
get_namespace_and_span_for_item(cx, def_id, usage_site_span);
let file_name = span_start(cx, definition_span).file.name;
let file_name = span_start(cx, definition_span).file.name.clone();
let file_metadata = file_metadata(cx, file_name);
let trait_llvm_type = type_of::type_of(cx, trait_type);

View file

@ -183,7 +183,7 @@ pub struct ExpnInfo {
callee: NameAndSpan
}
pub type FileName = @str;
pub type FileName = ~str;
pub struct FileLines
{
@ -301,7 +301,7 @@ impl CodeMap {
pub fn lookup_char_pos_adj(&self, pos: BytePos) -> LocWithOpt {
let loc = self.lookup_char_pos(pos);
LocWithOpt {
filename: loc.file.name,
filename: loc.file.name.to_str(),
line: loc.line,
col: loc.col,
file: Some(loc.file)
@ -324,7 +324,7 @@ impl CodeMap {
pub fn span_to_filename(&self, sp: Span) -> FileName {
let lo = self.lookup_char_pos(sp.lo);
lo.file.name
lo.file.name.to_str()
}
pub fn span_to_lines(&self, sp: Span) -> @FileLines {

View file

@ -250,7 +250,7 @@ pub mod rt {
fn parse_item(&self, s: ~str) -> @ast::Item {
let res = parse::parse_item_from_source_str(
@"<quote expansion>",
"<quote expansion>".to_str(),
s,
self.cfg(),
self.parse_sess());
@ -264,28 +264,25 @@ pub mod rt {
}
fn parse_stmt(&self, s: ~str) -> @ast::Stmt {
parse::parse_stmt_from_source_str(
@"<quote expansion>",
s,
self.cfg(),
~[],
self.parse_sess())
parse::parse_stmt_from_source_str("<quote expansion>".to_str(),
s,
self.cfg(),
~[],
self.parse_sess())
}
fn parse_expr(&self, s: ~str) -> @ast::Expr {
parse::parse_expr_from_source_str(
@"<quote expansion>",
s,
self.cfg(),
self.parse_sess())
parse::parse_expr_from_source_str("<quote expansion>".to_str(),
s,
self.cfg(),
self.parse_sess())
}
fn parse_tts(&self, s: ~str) -> ~[ast::TokenTree] {
parse::parse_tts_from_source_str(
@"<quote expansion>",
s,
self.cfg(),
self.parse_sess())
parse::parse_tts_from_source_str("<quote expansion>".to_str(),
s,
self.cfg(),
self.parse_sess())
}
}

View file

@ -114,7 +114,7 @@ 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 filename = file.display().to_str().to_managed();
let filename = file.display().to_str();
let interned = token::intern_and_get_ident(src);
cx.parse_sess.cm.new_filemap(filename, src);

View file

@ -347,7 +347,7 @@ pub struct Literal {
// probably not a good thing.
pub fn gather_comments_and_literals(span_diagnostic:
@diagnostic::SpanHandler,
path: @str,
path: ~str,
srdr: &mut io::Reader)
-> (~[Comment], ~[Literal]) {
let src = str::from_utf8_owned(srdr.read_to_end()).unwrap();

View file

@ -89,7 +89,7 @@ pub fn parse_crate_attrs_from_file(
return inner;
}
pub fn parse_crate_from_source_str(name: @str,
pub fn parse_crate_from_source_str(name: ~str,
source: ~str,
cfg: ast::CrateConfig,
sess: @ParseSess)
@ -101,7 +101,7 @@ pub fn parse_crate_from_source_str(name: @str,
maybe_aborted(p.parse_crate_mod(),p)
}
pub fn parse_crate_attrs_from_source_str(name: @str,
pub fn parse_crate_attrs_from_source_str(name: ~str,
source: ~str,
cfg: ast::CrateConfig,
sess: @ParseSess)
@ -114,7 +114,7 @@ pub fn parse_crate_attrs_from_source_str(name: @str,
return inner;
}
pub fn parse_expr_from_source_str(name: @str,
pub fn parse_expr_from_source_str(name: ~str,
source: ~str,
cfg: ast::CrateConfig,
sess: @ParseSess)
@ -123,7 +123,7 @@ pub fn parse_expr_from_source_str(name: @str,
maybe_aborted(p.parse_expr(), p)
}
pub fn parse_item_from_source_str(name: @str,
pub fn parse_item_from_source_str(name: ~str,
source: ~str,
cfg: ast::CrateConfig,
sess: @ParseSess)
@ -133,7 +133,7 @@ pub fn parse_item_from_source_str(name: @str,
maybe_aborted(p.parse_item(attrs),p)
}
pub fn parse_meta_from_source_str(name: @str,
pub fn parse_meta_from_source_str(name: ~str,
source: ~str,
cfg: ast::CrateConfig,
sess: @ParseSess)
@ -142,7 +142,7 @@ pub fn parse_meta_from_source_str(name: @str,
maybe_aborted(p.parse_meta_item(),p)
}
pub fn parse_stmt_from_source_str(name: @str,
pub fn parse_stmt_from_source_str(name: ~str,
source: ~str,
cfg: ast::CrateConfig,
attrs: ~[ast::Attribute],
@ -157,7 +157,7 @@ pub fn parse_stmt_from_source_str(name: @str,
maybe_aborted(p.parse_stmt(attrs),p)
}
pub fn parse_tts_from_source_str(name: @str,
pub fn parse_tts_from_source_str(name: ~str,
source: ~str,
cfg: ast::CrateConfig,
sess: @ParseSess)
@ -176,7 +176,7 @@ pub fn parse_tts_from_source_str(name: @str,
// Create a new parser from a source string
pub fn new_parser_from_source_str(sess: @ParseSess,
cfg: ast::CrateConfig,
name: @str,
name: ~str,
source: ~str)
-> Parser {
filemap_to_parser(sess,string_to_filemap(sess,source,name),cfg)
@ -241,21 +241,17 @@ 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,
path.as_str().unwrap().to_managed());
}
None => {
err(format!("{} is not UTF-8 encoded", path.display()))
return string_to_filemap(sess, s, path.as_str().unwrap().to_str())
}
None => err(format!("{} is not UTF-8 encoded", path.display())),
}
unreachable!()
}
// 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)
-> @FileMap {
pub fn string_to_filemap(sess: @ParseSess, source: ~str, path: ~str)
-> @FileMap {
sess.cm.new_filemap(path, source)
}

View file

@ -117,7 +117,7 @@ pub fn print_crate(cm: @CodeMap,
intr: @IdentInterner,
span_diagnostic: @diagnostic::SpanHandler,
crate: &ast::Crate,
filename: @str,
filename: ~str,
input: &mut io::Reader,
out: ~io::Writer,
ann: @PpAnn,