diff options
| author | Kevin Ballard <kevin@sb.org> | 2013-09-26 17:21:59 -0700 |
|---|---|---|
| committer | Kevin Ballard <kevin@sb.org> | 2013-10-15 21:56:54 -0700 |
| commit | 73d3d00ec437f87ac665b4e4da3bedec8ce4f9ef (patch) | |
| tree | 7050b2b93e3c58d7766e9aecd7e973ea88d9210e /src/libsyntax | |
| parent | 6741241f4046aea4014b1a23618593fb481c8606 (diff) | |
| download | rust-73d3d00ec437f87ac665b4e4da3bedec8ce4f9ef.tar.gz rust-73d3d00ec437f87ac665b4e4da3bedec8ce4f9ef.zip | |
path2: Replace the path module outright
Remove the old path. Rename path2 to path. Update all clients for the new path. Also make some miscellaneous changes to the Path APIs to help the adoption process.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 37 |
3 files changed, 27 insertions, 29 deletions
diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index e76ade0dc3d..ef09315a887 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -81,7 +81,7 @@ pub fn expand_include(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) let file = get_single_str_from_tts(cx, sp, tts, "include!"); let p = parse::new_sub_parser_from_file( cx.parse_sess(), cx.cfg(), - &res_rel_file(cx, sp, &Path(file)), sp); + &res_rel_file(cx, sp, &Path::from_str(file)), sp); base::MRExpr(p.parse_expr()) } @@ -89,7 +89,7 @@ pub fn expand_include(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_str!"); - let res = io::read_whole_file_str(&res_rel_file(cx, sp, &Path(file))); + let res = io::read_whole_file_str(&res_rel_file(cx, sp, &Path::from_str(file))); match res { result::Ok(res) => { base::MRExpr(cx.expr_str(sp, res.to_managed())) @@ -103,7 +103,7 @@ pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) pub fn expand_include_bin(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree]) -> base::MacResult { let file = get_single_str_from_tts(cx, sp, tts, "include_bin!"); - match io::read_whole_file(&res_rel_file(cx, sp, &Path(file))) { + match io::read_whole_file(&res_rel_file(cx, sp, &Path::from_str(file))) { result::Ok(src) => { let u8_exprs: ~[@ast::Expr] = src.iter().map(|char| cx.expr_u8(sp, *char)).collect(); base::MRExpr(cx.expr_vec(sp, u8_exprs)) @@ -144,10 +144,12 @@ fn topmost_expn_info(expn_info: @codemap::ExpnInfo) -> @codemap::ExpnInfo { // isn't already) fn res_rel_file(cx: @ExtCtxt, sp: codemap::Span, arg: &Path) -> Path { // NB: relative paths are resolved relative to the compilation unit - if !arg.is_absolute { - let cu = Path(cx.codemap().span_to_filename(sp)); - cu.dir_path().push_many(arg.components) + if !arg.is_absolute() { + let mut cu = Path::from_str(cx.codemap().span_to_filename(sp)); + cu.pop(); + cu.push_path(arg); + cu } else { - (*arg).clone() + arg.clone() } } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 67bcab31956..05998d80213 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -261,7 +261,8 @@ pub fn new_parser_from_tts(sess: @mut ParseSess, pub fn file_to_filemap(sess: @mut ParseSess, path: &Path, spanopt: Option<Span>) -> @FileMap { match io::read_whole_file_str(path) { - Ok(src) => string_to_filemap(sess, src.to_managed(), path.to_str().to_managed()), + // FIXME (#9639): This needs to handle non-utf8 paths + Ok(src) => string_to_filemap(sess, src.to_managed(), path.as_str().unwrap().to_managed()), Err(e) => { match spanopt { Some(span) => sess.span_diagnostic.span_fatal(span, e), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e7c579d2f19..ad565fd2ec4 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3992,27 +3992,20 @@ impl Parser { outer_attrs: &[ast::Attribute], id_sp: Span) -> (ast::item_, ~[ast::Attribute]) { - let prefix = Path(self.sess.cm.span_to_filename(*self.span)); - let prefix = prefix.dir_path(); + let mut prefix = Path::from_str(self.sess.cm.span_to_filename(*self.span)); + prefix.pop(); let mod_path_stack = &*self.mod_path_stack; - let mod_path = Path(".").push_many(*mod_path_stack); - let dir_path = prefix.push_many(mod_path.components); + let mod_path = Path::from_str(".").join_many_str(*mod_path_stack); + let dir_path = prefix.join_path(&mod_path); let file_path = match ::attr::first_attr_value_str_by_name( outer_attrs, "path") { - Some(d) => { - let path = Path(d); - if !path.is_absolute { - dir_path.push(d) - } else { - path - } - } + Some(d) => dir_path.join_str(d), None => { let mod_name = token::interner_get(id.name).to_owned(); let default_path_str = mod_name + ".rs"; let secondary_path_str = mod_name + "/mod.rs"; - let default_path = dir_path.push(default_path_str); - let secondary_path = dir_path.push(secondary_path_str); + let default_path = dir_path.join_str(default_path_str); + let secondary_path = dir_path.join_str(secondary_path_str); let default_exists = default_path.exists(); let secondary_exists = secondary_path.exists(); match (default_exists, secondary_exists) { @@ -4039,28 +4032,30 @@ impl Parser { path: Path, outer_attrs: ~[ast::Attribute], id_sp: Span) -> (ast::item_, ~[ast::Attribute]) { - let full_path = path.normalize(); - - let maybe_i = do self.sess.included_mod_stack.iter().position |p| { *p == full_path }; + let maybe_i = do self.sess.included_mod_stack.iter().position |p| { *p == path }; match maybe_i { Some(i) => { let stack = &self.sess.included_mod_stack; let mut err = ~"circular modules: "; for p in stack.slice(i, stack.len()).iter() { - err.push_str(p.to_str()); + do p.with_display_str |s| { + err.push_str(s); + } err.push_str(" -> "); } - err.push_str(full_path.to_str()); + do path.with_display_str |s| { + err.push_str(s); + } self.span_fatal(id_sp, err); } None => () } - self.sess.included_mod_stack.push(full_path.clone()); + self.sess.included_mod_stack.push(path.clone()); let p0 = new_sub_parser_from_file(self.sess, self.cfg.clone(), - &full_path, + &path, id_sp); let (inner, next) = p0.parse_inner_attrs_and_next(); let mod_attrs = vec::append(outer_attrs, inner); |
