libsyntax: De-@str
pathnames
This commit is contained in:
parent
e68108b3e8
commit
8d6ef2e1b1
8 changed files with 43 additions and 48 deletions
|
@ -61,12 +61,14 @@ pub enum PpMode {
|
||||||
* The name used for source code that doesn't originate in a file
|
* The name used for source code that doesn't originate in a file
|
||||||
* (e.g. source from stdin or a string)
|
* (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 {
|
match *input {
|
||||||
// FIXME (#9639): This needs to handle non-utf8 paths
|
// 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()
|
StrInput(_) => anon_src()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +140,7 @@ fn parse_cfgspecs(cfgspecs: ~[~str], demitter: @diagnostic::Emitter)
|
||||||
-> ast::CrateConfig {
|
-> ast::CrateConfig {
|
||||||
cfgspecs.move_iter().map(|s| {
|
cfgspecs.move_iter().map(|s| {
|
||||||
let sess = parse::new_parse_sess(Some(demitter));
|
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>()
|
}).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
|
// Build a list of files used to compile the output and
|
||||||
// write Makefile-compatible dependency rules
|
// write Makefile-compatible dependency rules
|
||||||
let files: ~[@str] = {
|
let files: ~[~str] = {
|
||||||
let files = sess.codemap.files.borrow();
|
let files = sess.codemap.files.borrow();
|
||||||
files.get()
|
files.get()
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|fmap| {
|
.filter_map(|fmap| {
|
||||||
if fmap.is_real_file() {
|
if fmap.is_real_file() {
|
||||||
Some(fmap.name)
|
Some(fmap.name.clone())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -931,7 +931,7 @@ fn declare_local(bcx: &Block,
|
||||||
span: Span) {
|
span: Span) {
|
||||||
let cx: &CrateContext = bcx.ccx();
|
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 file_metadata = file_metadata(cx, filename);
|
||||||
|
|
||||||
let name: &str = token::ident_to_str(&variable_ident);
|
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 (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 file_metadata = file_metadata(cx, file_name);
|
||||||
|
|
||||||
let struct_metadata_stub = create_struct_stub(cx,
|
let struct_metadata_stub = create_struct_stub(cx,
|
||||||
|
@ -2006,7 +2006,7 @@ fn trait_metadata(cx: &CrateContext,
|
||||||
let (containing_scope, definition_span) =
|
let (containing_scope, definition_span) =
|
||||||
get_namespace_and_span_for_item(cx, def_id, usage_site_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 file_metadata = file_metadata(cx, file_name);
|
||||||
|
|
||||||
let trait_llvm_type = type_of::type_of(cx, trait_type);
|
let trait_llvm_type = type_of::type_of(cx, trait_type);
|
||||||
|
|
|
@ -183,7 +183,7 @@ pub struct ExpnInfo {
|
||||||
callee: NameAndSpan
|
callee: NameAndSpan
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type FileName = @str;
|
pub type FileName = ~str;
|
||||||
|
|
||||||
pub struct FileLines
|
pub struct FileLines
|
||||||
{
|
{
|
||||||
|
@ -301,7 +301,7 @@ impl CodeMap {
|
||||||
pub fn lookup_char_pos_adj(&self, pos: BytePos) -> LocWithOpt {
|
pub fn lookup_char_pos_adj(&self, pos: BytePos) -> LocWithOpt {
|
||||||
let loc = self.lookup_char_pos(pos);
|
let loc = self.lookup_char_pos(pos);
|
||||||
LocWithOpt {
|
LocWithOpt {
|
||||||
filename: loc.file.name,
|
filename: loc.file.name.to_str(),
|
||||||
line: loc.line,
|
line: loc.line,
|
||||||
col: loc.col,
|
col: loc.col,
|
||||||
file: Some(loc.file)
|
file: Some(loc.file)
|
||||||
|
@ -324,7 +324,7 @@ impl CodeMap {
|
||||||
|
|
||||||
pub fn span_to_filename(&self, sp: Span) -> FileName {
|
pub fn span_to_filename(&self, sp: Span) -> FileName {
|
||||||
let lo = self.lookup_char_pos(sp.lo);
|
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 {
|
pub fn span_to_lines(&self, sp: Span) -> @FileLines {
|
||||||
|
|
|
@ -250,7 +250,7 @@ pub mod rt {
|
||||||
|
|
||||||
fn parse_item(&self, s: ~str) -> @ast::Item {
|
fn parse_item(&self, s: ~str) -> @ast::Item {
|
||||||
let res = parse::parse_item_from_source_str(
|
let res = parse::parse_item_from_source_str(
|
||||||
@"<quote expansion>",
|
"<quote expansion>".to_str(),
|
||||||
s,
|
s,
|
||||||
self.cfg(),
|
self.cfg(),
|
||||||
self.parse_sess());
|
self.parse_sess());
|
||||||
|
@ -264,8 +264,7 @@ pub mod rt {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_stmt(&self, s: ~str) -> @ast::Stmt {
|
fn parse_stmt(&self, s: ~str) -> @ast::Stmt {
|
||||||
parse::parse_stmt_from_source_str(
|
parse::parse_stmt_from_source_str("<quote expansion>".to_str(),
|
||||||
@"<quote expansion>",
|
|
||||||
s,
|
s,
|
||||||
self.cfg(),
|
self.cfg(),
|
||||||
~[],
|
~[],
|
||||||
|
@ -273,16 +272,14 @@ pub mod rt {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_expr(&self, s: ~str) -> @ast::Expr {
|
fn parse_expr(&self, s: ~str) -> @ast::Expr {
|
||||||
parse::parse_expr_from_source_str(
|
parse::parse_expr_from_source_str("<quote expansion>".to_str(),
|
||||||
@"<quote expansion>",
|
|
||||||
s,
|
s,
|
||||||
self.cfg(),
|
self.cfg(),
|
||||||
self.parse_sess())
|
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(
|
parse::parse_tts_from_source_str("<quote expansion>".to_str(),
|
||||||
@"<quote expansion>",
|
|
||||||
s,
|
s,
|
||||||
self.cfg(),
|
self.cfg(),
|
||||||
self.parse_sess())
|
self.parse_sess())
|
||||||
|
|
|
@ -114,7 +114,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
|
||||||
Some(src) => {
|
Some(src) => {
|
||||||
// Add this input file to the code map to make it available as
|
// Add this input file to the code map to make it available as
|
||||||
// dependency information
|
// dependency information
|
||||||
let filename = file.display().to_str().to_managed();
|
let filename = file.display().to_str();
|
||||||
let interned = token::intern_and_get_ident(src);
|
let interned = token::intern_and_get_ident(src);
|
||||||
cx.parse_sess.cm.new_filemap(filename, src);
|
cx.parse_sess.cm.new_filemap(filename, src);
|
||||||
|
|
||||||
|
|
|
@ -347,7 +347,7 @@ pub struct Literal {
|
||||||
// probably not a good thing.
|
// probably not a good thing.
|
||||||
pub fn gather_comments_and_literals(span_diagnostic:
|
pub fn gather_comments_and_literals(span_diagnostic:
|
||||||
@diagnostic::SpanHandler,
|
@diagnostic::SpanHandler,
|
||||||
path: @str,
|
path: ~str,
|
||||||
srdr: &mut io::Reader)
|
srdr: &mut io::Reader)
|
||||||
-> (~[Comment], ~[Literal]) {
|
-> (~[Comment], ~[Literal]) {
|
||||||
let src = str::from_utf8_owned(srdr.read_to_end()).unwrap();
|
let src = str::from_utf8_owned(srdr.read_to_end()).unwrap();
|
||||||
|
|
|
@ -89,7 +89,7 @@ pub fn parse_crate_attrs_from_file(
|
||||||
return inner;
|
return inner;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_crate_from_source_str(name: @str,
|
pub fn parse_crate_from_source_str(name: ~str,
|
||||||
source: ~str,
|
source: ~str,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
sess: @ParseSess)
|
sess: @ParseSess)
|
||||||
|
@ -101,7 +101,7 @@ pub fn parse_crate_from_source_str(name: @str,
|
||||||
maybe_aborted(p.parse_crate_mod(),p)
|
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,
|
source: ~str,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
sess: @ParseSess)
|
sess: @ParseSess)
|
||||||
|
@ -114,7 +114,7 @@ pub fn parse_crate_attrs_from_source_str(name: @str,
|
||||||
return inner;
|
return inner;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_expr_from_source_str(name: @str,
|
pub fn parse_expr_from_source_str(name: ~str,
|
||||||
source: ~str,
|
source: ~str,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
sess: @ParseSess)
|
sess: @ParseSess)
|
||||||
|
@ -123,7 +123,7 @@ pub fn parse_expr_from_source_str(name: @str,
|
||||||
maybe_aborted(p.parse_expr(), p)
|
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,
|
source: ~str,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
sess: @ParseSess)
|
sess: @ParseSess)
|
||||||
|
@ -133,7 +133,7 @@ pub fn parse_item_from_source_str(name: @str,
|
||||||
maybe_aborted(p.parse_item(attrs),p)
|
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,
|
source: ~str,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
sess: @ParseSess)
|
sess: @ParseSess)
|
||||||
|
@ -142,7 +142,7 @@ pub fn parse_meta_from_source_str(name: @str,
|
||||||
maybe_aborted(p.parse_meta_item(),p)
|
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,
|
source: ~str,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
attrs: ~[ast::Attribute],
|
attrs: ~[ast::Attribute],
|
||||||
|
@ -157,7 +157,7 @@ pub fn parse_stmt_from_source_str(name: @str,
|
||||||
maybe_aborted(p.parse_stmt(attrs),p)
|
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,
|
source: ~str,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
sess: @ParseSess)
|
sess: @ParseSess)
|
||||||
|
@ -176,7 +176,7 @@ pub fn parse_tts_from_source_str(name: @str,
|
||||||
// Create a new parser from a source string
|
// Create a new parser from a source string
|
||||||
pub fn new_parser_from_source_str(sess: @ParseSess,
|
pub fn new_parser_from_source_str(sess: @ParseSess,
|
||||||
cfg: ast::CrateConfig,
|
cfg: ast::CrateConfig,
|
||||||
name: @str,
|
name: ~str,
|
||||||
source: ~str)
|
source: ~str)
|
||||||
-> Parser {
|
-> Parser {
|
||||||
filemap_to_parser(sess,string_to_filemap(sess,source,name),cfg)
|
filemap_to_parser(sess,string_to_filemap(sess,source,name),cfg)
|
||||||
|
@ -241,20 +241,16 @@ pub fn file_to_filemap(sess: @ParseSess, path: &Path, spanopt: Option<Span>)
|
||||||
};
|
};
|
||||||
match str::from_utf8_owned(bytes) {
|
match str::from_utf8_owned(bytes) {
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
return string_to_filemap(sess,
|
return string_to_filemap(sess, s, path.as_str().unwrap().to_str())
|
||||||
s,
|
|
||||||
path.as_str().unwrap().to_managed());
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
err(format!("{} is not UTF-8 encoded", path.display()))
|
|
||||||
}
|
}
|
||||||
|
None => err(format!("{} is not UTF-8 encoded", path.display())),
|
||||||
}
|
}
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
// given a session and a string, add the string to
|
// given a session and a string, add the string to
|
||||||
// the session's codemap and return the new filemap
|
// 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 {
|
-> @FileMap {
|
||||||
sess.cm.new_filemap(path, source)
|
sess.cm.new_filemap(path, source)
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ pub fn print_crate(cm: @CodeMap,
|
||||||
intr: @IdentInterner,
|
intr: @IdentInterner,
|
||||||
span_diagnostic: @diagnostic::SpanHandler,
|
span_diagnostic: @diagnostic::SpanHandler,
|
||||||
crate: &ast::Crate,
|
crate: &ast::Crate,
|
||||||
filename: @str,
|
filename: ~str,
|
||||||
input: &mut io::Reader,
|
input: &mut io::Reader,
|
||||||
out: ~io::Writer,
|
out: ~io::Writer,
|
||||||
ann: @PpAnn,
|
ann: @PpAnn,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue