diff options
| author | James Miller <james@aatch.net> | 2013-07-05 22:15:21 +1200 |
|---|---|---|
| committer | James Miller <bladeon@gmail.com> | 2013-07-07 22:51:09 +1200 |
| commit | cd1b6c897911c91167c5a3c5e3c2fa0d9334ad45 (patch) | |
| tree | 547f2b0e84098a4aeea47dc30fa08b70541f30f6 /src/libsyntax | |
| parent | a69eb952336bb3d483dd046373daa8e3948390a7 (diff) | |
| download | rust-cd1b6c897911c91167c5a3c5e3c2fa0d9334ad45.tar.gz rust-cd1b6c897911c91167c5a3c5e3c2fa0d9334ad45.zip | |
De-managed ast::Path
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 22 | ||||
| -rw-r--r-- | src/libsyntax/ast_map.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 46 | ||||
| -rw-r--r-- | src/libsyntax/ext/concat_idents.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/generic.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/ty.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/ext/pipes/ast_builder.rs | 26 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 26 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 20 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 60 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 36 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 16 |
16 files changed, 148 insertions, 140 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index ffbd61b15ed..d053c203b91 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -255,10 +255,10 @@ pub enum pat_ { // which it is. The resolver determines this, and // records this pattern's node_id in an auxiliary // set (of "pat_idents that refer to nullary enums") - pat_ident(binding_mode, @Path, Option<@pat>), - pat_enum(@Path, Option<~[@pat]>), /* "none" means a * pattern where + pat_ident(binding_mode, Path, Option<@pat>), + pat_enum(Path, Option<~[@pat]>), /* "none" means a * pattern where * we don't bind the fields to names */ - pat_struct(@Path, ~[field_pat], bool), + pat_struct(Path, ~[field_pat], bool), pat_tup(~[@pat]), pat_box(@pat), pat_uniq(@pat), @@ -456,7 +456,7 @@ pub enum expr_ { expr_assign_op(node_id, binop, @expr, @expr), expr_field(@expr, ident, ~[@Ty]), expr_index(node_id, @expr, @expr), - expr_path(@Path), + expr_path(Path), /// The special identifier `self`. expr_self, @@ -471,7 +471,7 @@ pub enum expr_ { expr_mac(mac), // A struct literal expression. - expr_struct(@Path, ~[field], Option<@expr>), + expr_struct(Path, ~[field], Option<@expr>), // A vector literal constructed from one repeated element. expr_repeat(@expr /* element */, @expr /* count */, mutability), @@ -583,7 +583,7 @@ pub type mac = spanned<mac_>; #[deriving(Eq, Encodable, Decodable,IterBytes)] pub enum mac_ { - mac_invoc_tt(@Path,~[token_tree]), // new macro-invocation + mac_invoc_tt(Path,~[token_tree]), // new macro-invocation } pub type lit = spanned<lit_>; @@ -734,7 +734,7 @@ pub enum ty_ { ty_closure(@TyClosure), ty_bare_fn(@TyBareFn), ty_tup(~[@Ty]), - ty_path(@Path, @Option<OptVec<TyParamBound>>, node_id), // for #7264; see above + ty_path(Path, @Option<OptVec<TyParamBound>>, node_id), // for #7264; see above ty_mac(mac), // ty_infer means the type should be inferred instead of it having been // specified. This should only appear at the "top level" of a type and not @@ -890,13 +890,13 @@ pub enum view_path_ { // or just // // foo::bar::baz (with 'baz =' implicitly on the left) - view_path_simple(ident, @Path, node_id), + view_path_simple(ident, Path, node_id), // foo::bar::* - view_path_glob(@Path, node_id), + view_path_glob(Path, node_id), // foo::bar::{a,b,c} - view_path_list(@Path, ~[path_list_ident], node_id) + view_path_list(Path, ~[path_list_ident], node_id) } #[deriving(Eq, Encodable, Decodable,IterBytes)] @@ -939,7 +939,7 @@ pub struct attribute_ { */ #[deriving(Eq, Encodable, Decodable,IterBytes)] pub struct trait_ref { - path: @Path, + path: Path, ref_id: node_id, } diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 3abbe397054..59020e9d183 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -196,7 +196,7 @@ pub fn map_block(b: &blk, (cx,v): (@mut Ctx, visit::vt<@mut Ctx>)) { pub fn map_pat(pat: @pat, (cx,v): (@mut Ctx, visit::vt<@mut Ctx>)) { match pat.node { - pat_ident(_, path, _) => { + pat_ident(_, ref path, _) => { // Note: this is at least *potentially* a pattern... cx.map.insert(pat.id, node_local(ast_util::path_to_ident(path))); } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index ce8e24fd444..35f9782f694 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -27,7 +27,7 @@ pub fn path_name_i(idents: &[ident]) -> ~str { idents.map(|i| token::interner_get(i.name)).connect("::") } -pub fn path_to_ident(p: @Path) -> ident { copy *p.idents.last() } +pub fn path_to_ident(p: &Path) -> ident { copy *p.idents.last() } pub fn local_def(id: node_id) -> def_id { ast::def_id { crate: local_crate, node: id } @@ -212,8 +212,8 @@ pub fn default_block( } } -pub fn ident_to_path(s: span, i: ident) -> @Path { - @ast::Path { span: s, +pub fn ident_to_path(s: span, i: ident) -> Path { + ast::Path { span: s, global: false, idents: ~[i], rp: None, diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index ad14b567b96..56868874916 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -326,7 +326,7 @@ pub fn expr_to_ident(cx: @ExtCtxt, expr: @ast::expr, err_msg: &str) -> ast::ident { match expr.node { - ast::expr_path(p) => { + ast::expr_path(ref p) => { if p.types.len() > 0u || p.idents.len() != 1u { cx.span_fatal(expr.span, err_msg); } diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index e2b8ff3c030..c933caa16c4 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -32,21 +32,21 @@ mod syntax { pub trait AstBuilder { // paths - fn path(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; - fn path_ident(&self, span: span, id: ast::ident) -> @ast::Path; - fn path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::Path; + fn path(&self, span: span, strs: ~[ast::ident]) -> ast::Path; + fn path_ident(&self, span: span, id: ast::ident) -> ast::Path; + fn path_global(&self, span: span, strs: ~[ast::ident]) -> ast::Path; fn path_all(&self, sp: span, global: bool, idents: ~[ast::ident], rp: Option<@ast::Lifetime>, types: ~[@ast::Ty]) - -> @ast::Path; + -> ast::Path; // types fn ty_mt(&self, ty: @ast::Ty, mutbl: ast::mutability) -> ast::mt; fn ty(&self, span: span, ty: ast::ty_) -> @ast::Ty; - fn ty_path(&self, @ast::Path, @Option<OptVec<ast::TyParamBound>>) -> @ast::Ty; + fn ty_path(&self, ast::Path, @Option<OptVec<ast::TyParamBound>>) -> @ast::Ty; fn ty_ident(&self, span: span, idents: ast::ident) -> @ast::Ty; fn ty_rptr(&self, span: span, @@ -68,8 +68,8 @@ pub trait AstBuilder { fn typaram(&self, id: ast::ident, bounds: @OptVec<ast::TyParamBound>) -> ast::TyParam; - fn trait_ref(&self, path: @ast::Path) -> @ast::trait_ref; - fn typarambound(&self, path: @ast::Path) -> ast::TyParamBound; + fn trait_ref(&self, path: ast::Path) -> @ast::trait_ref; + fn typarambound(&self, path: ast::Path) -> ast::TyParamBound; fn lifetime(&self, span: span, ident: ast::ident) -> ast::Lifetime; // statements @@ -86,7 +86,7 @@ pub trait AstBuilder { // expressions fn expr(&self, span: span, node: ast::expr_) -> @ast::expr; - fn expr_path(&self, path: @ast::Path) -> @ast::expr; + fn expr_path(&self, path: ast::Path) -> @ast::expr; fn expr_ident(&self, span: span, id: ast::ident) -> @ast::expr; fn expr_self(&self, span: span) -> @ast::expr; @@ -110,7 +110,7 @@ pub trait AstBuilder { fn expr_blk(&self, b: ast::blk) -> @ast::expr; fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::field; - fn expr_struct(&self, span: span, path: @ast::Path, fields: ~[ast::field]) -> @ast::expr; + fn expr_struct(&self, span: span, path: ast::Path, fields: ~[ast::field]) -> @ast::expr; fn expr_struct_ident(&self, span: span, id: ast::ident, fields: ~[ast::field]) -> @ast::expr; fn expr_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr; @@ -138,9 +138,9 @@ pub trait AstBuilder { span: span, ident: ast::ident, bm: ast::binding_mode) -> @ast::pat; - fn pat_enum(&self, span: span, path: @ast::Path, subpats: ~[@ast::pat]) -> @ast::pat; + fn pat_enum(&self, span: span, path: ast::Path, subpats: ~[@ast::pat]) -> @ast::pat; fn pat_struct(&self, span: span, - path: @ast::Path, field_pats: ~[ast::field_pat]) -> @ast::pat; + path: ast::Path, field_pats: ~[ast::field_pat]) -> @ast::pat; fn arm(&self, span: span, pats: ~[@ast::pat], expr: @ast::expr) -> ast::arm; fn arm_unreachable(&self, span: span) -> ast::arm; @@ -226,13 +226,13 @@ pub trait AstBuilder { } impl AstBuilder for @ExtCtxt { - fn path(&self, span: span, strs: ~[ast::ident]) -> @ast::Path { + fn path(&self, span: span, strs: ~[ast::ident]) -> ast::Path { self.path_all(span, false, strs, None, ~[]) } - fn path_ident(&self, span: span, id: ast::ident) -> @ast::Path { + fn path_ident(&self, span: span, id: ast::ident) -> ast::Path { self.path(span, ~[id]) } - fn path_global(&self, span: span, strs: ~[ast::ident]) -> @ast::Path { + fn path_global(&self, span: span, strs: ~[ast::ident]) -> ast::Path { self.path_all(span, true, strs, None, ~[]) } fn path_all(&self, sp: span, @@ -240,8 +240,8 @@ impl AstBuilder for @ExtCtxt { idents: ~[ast::ident], rp: Option<@ast::Lifetime>, types: ~[@ast::Ty]) - -> @ast::Path { - @ast::Path { + -> ast::Path { + ast::Path { span: sp, global: global, idents: idents, @@ -265,7 +265,7 @@ impl AstBuilder for @ExtCtxt { } } - fn ty_path(&self, path: @ast::Path, bounds: @Option<OptVec<ast::TyParamBound>>) + fn ty_path(&self, path: ast::Path, bounds: @Option<OptVec<ast::TyParamBound>>) -> @ast::Ty { self.ty(path.span, ast::ty_path(path, bounds, self.next_id())) @@ -358,14 +358,14 @@ impl AstBuilder for @ExtCtxt { } } - fn trait_ref(&self, path: @ast::Path) -> @ast::trait_ref { + fn trait_ref(&self, path: ast::Path) -> @ast::trait_ref { @ast::trait_ref { path: path, ref_id: self.next_id() } } - fn typarambound(&self, path: @ast::Path) -> ast::TyParamBound { + fn typarambound(&self, path: ast::Path) -> ast::TyParamBound { ast::TraitTyParamBound(self.trait_ref(path)) } @@ -421,7 +421,7 @@ impl AstBuilder for @ExtCtxt { } } - fn expr_path(&self, path: @ast::Path) -> @ast::expr { + fn expr_path(&self, path: ast::Path) -> @ast::expr { self.expr(path.span, ast::expr_path(path)) } @@ -487,7 +487,7 @@ impl AstBuilder for @ExtCtxt { fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::field { respan(span, ast::field_ { ident: name, expr: e }) } - fn expr_struct(&self, span: span, path: @ast::Path, fields: ~[ast::field]) -> @ast::expr { + fn expr_struct(&self, span: span, path: ast::Path, fields: ~[ast::field]) -> @ast::expr { self.expr(span, ast::expr_struct(path, fields, None)) } fn expr_struct_ident(&self, span: span, @@ -570,12 +570,12 @@ impl AstBuilder for @ExtCtxt { let pat = ast::pat_ident(bm, path, None); self.pat(span, pat) } - fn pat_enum(&self, span: span, path: @ast::Path, subpats: ~[@ast::pat]) -> @ast::pat { + fn pat_enum(&self, span: span, path: ast::Path, subpats: ~[@ast::pat]) -> @ast::pat { let pat = ast::pat_enum(path, Some(subpats)); self.pat(span, pat) } fn pat_struct(&self, span: span, - path: @ast::Path, field_pats: ~[ast::field_pat]) -> @ast::pat { + path: ast::Path, field_pats: ~[ast::field_pat]) -> @ast::pat { let pat = ast::pat_struct(path, field_pats, false); self.pat(span, pat) } diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 7df8874076e..900668df117 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -36,7 +36,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) let e = @ast::expr { id: cx.next_id(), node: ast::expr_path( - @ast::Path { + ast::Path { span: sp, global: false, idents: ~[res], diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 0e4fc9d96fa..e397a416304 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -335,7 +335,7 @@ impl<'self> TraitDef<'self> { cx.typarambound(p.to_path(cx, span, type_ident, generics)) }); // require the current trait - bounds.push(cx.typarambound(trait_path)); + bounds.push(cx.typarambound(copy trait_path)); trait_generics.ty_params.push(cx.typaram(ty_param.ident, @bounds)); } @@ -890,7 +890,7 @@ fn summarise_struct(cx: @ExtCtxt, span: span, pub fn create_subpatterns(cx: @ExtCtxt, span: span, - field_paths: ~[@ast::Path], + field_paths: ~[ast::Path], mutbl: ast::mutability) -> ~[@ast::pat] { do field_paths.map |&path| { @@ -941,7 +941,7 @@ fn create_struct_pattern(cx: @ExtCtxt, }; let path = cx.path_ident(span, cx.ident_of(fmt!("%s_%u", prefix, i))); - paths.push(path); + paths.push(copy path); ident_expr.push((opt_id, cx.expr_path(path))); } @@ -987,7 +987,7 @@ fn create_enum_variant_pattern(cx: @ExtCtxt, let path = cx.path_ident(span, cx.ident_of(fmt!("%s_%u", prefix, i))); - paths.push(path); + paths.push(copy path); ident_expr.push((None, cx.expr_path(path))); } diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index e210853bfb4..4dee2e2cdb8 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -70,7 +70,7 @@ impl<'self> Path<'self> { span: span, self_ty: ident, self_generics: &Generics) - -> @ast::Path { + -> ast::Path { let idents = self.path.map(|s| cx.ident_of(*s) ); let lt = mk_lifetime(cx, span, &self.lifetime); let tys = self.params.map(|t| t.to_ty(cx, span, self_ty, self_generics)); @@ -162,7 +162,7 @@ impl<'self> Ty<'self> { span: span, self_ty: ident, self_generics: &Generics) - -> @ast::Path { + -> ast::Path { match *self { Self => { let self_params = do self_generics.ty_params.map |ty_param| { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 2b18ede8879..940bd5ef61c 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -40,7 +40,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv, expr_mac(ref mac) => { match (*mac).node { // Token-tree macros: - mac_invoc_tt(pth, ref tts) => { + mac_invoc_tt(ref pth, ref tts) => { if (pth.idents.len() > 1u) { cx.span_fatal( pth.span, @@ -208,7 +208,7 @@ pub fn expand_item_mac(extsbox: @mut SyntaxEnv, fld: @ast_fold) -> Option<@ast::item> { let (pth, tts) = match it.node { - item_mac(codemap::spanned { node: mac_invoc_tt(pth, ref tts), _}) => { + item_mac(codemap::spanned { node: mac_invoc_tt(ref pth, ref tts), _}) => { (pth, copy *tts) } _ => cx.span_bug(it.span, "invalid item macro invocation") @@ -298,7 +298,7 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, let (mac, pth, tts, semi) = match *s { stmt_mac(ref mac, semi) => { match mac.node { - mac_invoc_tt(pth, ref tts) => { + mac_invoc_tt(ref pth, ref tts) => { (copy *mac, pth, copy *tts, semi) } } @@ -372,10 +372,10 @@ pub fn new_name_finder() -> @Visitor<@mut ~[ast::ident]> { (ident_accum, v): (@mut ~[ast::ident], visit::vt<@mut ~[ast::ident]>)| { match *p { // we found a pat_ident! - ast::pat{id:_, node: ast::pat_ident(_,path,ref inner), span:_} => { + ast::pat{id:_, node: ast::pat_ident(_,ref path,ref inner), span:_} => { match path { // a path of length one: - @ast::Path{global: false,idents: [id], span:_,rp:_,types:_} => + &ast::Path{global: false,idents: [id], span:_,rp:_,types:_} => ident_accum.push(id), // I believe these must be enums... _ => () diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index 1af6e7810a5..58838b0c40b 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -25,16 +25,16 @@ mod syntax { pub use parse; } -pub fn path(ids: ~[ident], span: span) -> @ast::Path { - @ast::Path { span: span, +pub fn path(ids: ~[ident], span: span) -> ast::Path { + ast::Path { span: span, global: false, idents: ids, rp: None, types: ~[] } } -pub fn path_global(ids: ~[ident], span: span) -> @ast::Path { - @ast::Path { span: span, +pub fn path_global(ids: ~[ident], span: span) -> ast::Path { + ast::Path { span: span, global: true, idents: ids, rp: None, @@ -42,22 +42,22 @@ pub fn path_global(ids: ~[ident], span: span) -> @ast::Path { } pub trait append_types { - fn add_ty(&self, ty: @ast::Ty) -> @ast::Path; - fn add_tys(&self, tys: ~[@ast::Ty]) -> @ast::Path; + fn add_ty(&self, ty: @ast::Ty) -> ast::Path; + fn add_tys(&self, tys: ~[@ast::Ty]) -> ast::Path; } -impl append_types for @ast::Path { - fn add_ty(&self, ty: @ast::Ty) -> @ast::Path { - @ast::Path { +impl append_types for ast::Path { + fn add_ty(&self, ty: @ast::Ty) -> ast::Path { + ast::Path { types: vec::append_one(copy self.types, ty), - .. copy **self + .. copy *self } } - fn add_tys(&self, tys: ~[@ast::Ty]) -> @ast::Path { - @ast::Path { + fn add_tys(&self, tys: ~[@ast::Ty]) -> ast::Path { + ast::Path { types: vec::append(copy self.types, tys), - .. copy **self + .. copy *self } } } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index b4d64ba3e2d..e9710c9e114 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -33,7 +33,7 @@ pub trait ast_fold { fn fold_foreign_mod(@self, &foreign_mod) -> foreign_mod; fn fold_variant(@self, &variant) -> variant; fn fold_ident(@self, ident) -> ident; - fn fold_path(@self, @Path) -> @Path; + fn fold_path(@self, &Path) -> Path; fn fold_local(@self, @local) -> @local; fn map_exprs(@self, @fn(@expr) -> @expr, &[@expr]) -> ~[@expr]; fn new_id(@self, node_id) -> node_id; @@ -62,7 +62,7 @@ pub struct AstFoldFns { fold_foreign_mod: @fn(&foreign_mod, @ast_fold) -> foreign_mod, fold_variant: @fn(&variant_, span, @ast_fold) -> (variant_, span), fold_ident: @fn(ident, @ast_fold) -> ident, - fold_path: @fn(@Path, @ast_fold) -> Path, + fold_path: @fn(&Path, @ast_fold) -> Path, fold_local: @fn(&local_, span, @ast_fold) -> (local_, span), map_exprs: @fn(@fn(@expr) -> @expr, &[@expr]) -> ~[@expr], new_id: @fn(node_id) -> node_id, @@ -117,7 +117,7 @@ fn fold_arg_(a: arg, fld: @ast_fold) -> arg { fn fold_mac_(m: &mac, fld: @ast_fold) -> mac { spanned { node: match m.node { - mac_invoc_tt(p,ref tts) => + mac_invoc_tt(ref p,ref tts) => mac_invoc_tt(fld.fold_path(p), fold_tts(*tts,fld)) }, @@ -337,7 +337,7 @@ fn fold_struct_def(struct_def: @ast::struct_def, fld: @ast_fold) fn fold_trait_ref(p: @trait_ref, fld: @ast_fold) -> @trait_ref { @ast::trait_ref { - path: fld.fold_path(p.path), + path: fld.fold_path(&p.path), ref_id: fld.new_id(p.ref_id), } } @@ -419,7 +419,7 @@ fn noop_fold_arm(a: &arm, fld: @ast_fold) -> arm { pub fn noop_fold_pat(p: &pat_, fld: @ast_fold) -> pat_ { match *p { pat_wild => pat_wild, - pat_ident(binding_mode, pth, ref sub) => { + pat_ident(binding_mode, ref pth, ref sub) => { pat_ident( binding_mode, fld.fold_path(pth), @@ -427,13 +427,13 @@ pub fn noop_fold_pat(p: &pat_, fld: @ast_fold) -> pat_ { ) } pat_lit(e) => pat_lit(fld.fold_expr(e)), - pat_enum(pth, ref pats) => { + pat_enum(ref pth, ref pats) => { pat_enum( fld.fold_path(pth), pats.map(|pats| pats.map(|x| fld.fold_pat(*x))) ) } - pat_struct(pth, ref fields, etc) => { + pat_struct(ref pth, ref fields, etc) => { let pth_ = fld.fold_path(pth); let fs = do fields.map |f| { ast::field_pat { @@ -596,7 +596,7 @@ pub fn noop_fold_expr(e: &expr_, fld: @ast_fold) -> expr_ { fld.fold_expr(er) ) } - expr_path(pth) => expr_path(fld.fold_path(pth)), + expr_path(ref pth) => expr_path(fld.fold_path(pth)), expr_self => expr_self, expr_break(ref opt_ident) => { expr_break(opt_ident.map(|x| fld.fold_ident(*x))) @@ -621,7 +621,7 @@ pub fn noop_fold_expr(e: &expr_, fld: @ast_fold) -> expr_ { }) } expr_mac(ref mac) => expr_mac(fold_mac(mac)), - expr_struct(path, ref fields, maybe_expr) => { + expr_struct(ref path, ref fields, maybe_expr) => { expr_struct( fld.fold_path(path), fields.map(|x| fold_field(*x)), @@ -682,7 +682,7 @@ pub fn noop_fold_ty(t: &ty_, fld: @ast_fold) -> ty_ { }) } ty_tup(ref tys) => ty_tup(tys.map(|ty| fld.fold_ty(*ty))), - ty_path(path, bounds, id) => + ty_path(ref path, bounds, id) => ty_path(fld.fold_path(path), @fold_opt_bounds(bounds, fld), fld.new_id(id)), ty_fixed_length_vec(ref mt, e) => { ty_fixed_length_vec( @@ -754,7 +754,7 @@ fn noop_fold_ident(i: ident, _fld: @ast_fold) -> ident { /* FIXME (#2543) */ copy i } -fn noop_fold_path(p: @Path, fld: @ast_fold) -> Path { +fn noop_fold_path(p: &Path, fld: @ast_fold) -> Path { ast::Path { span: fld.new_span(p.span), global: p.global, @@ -907,8 +907,8 @@ impl ast_fold for AstFoldFns { fn fold_ident(@self, x: ident) -> ident { (self.fold_ident)(x, self as @ast_fold) } - fn fold_path(@self, x: @Path) -> @Path { - @(self.fold_path)(x, self as @ast_fold) + fn fold_path(@self, x: &Path) -> Path { + (self.fold_path)(x, self as @ast_fold) } fn fold_local(@self, x: @local) -> @local { let (n, s) = (self.fold_local)(&x.node, x.span, self as @ast_fold); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 6dd8d4880e3..634efbe165d 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -366,7 +366,7 @@ mod test { #[test] fn path_exprs_1 () { assert_eq!(string_to_expr(@"a"), @ast::expr{id:1, - node:ast::expr_path(@ast::Path {span:sp(0,1), + node:ast::expr_path(ast::Path {span:sp(0,1), global:false, idents:~[str_to_ident("a")], rp:None, @@ -378,7 +378,7 @@ mod test { assert_eq!(string_to_expr(@"::a::b"), @ast::expr{id:1, node:ast::expr_path( - @ast::Path {span:sp(0,6), + ast::Path {span:sp(0,6), global:true, idents:strs_to_idents(~["a","b"]), rp:None, @@ -428,7 +428,7 @@ mod test { node:ast::expr_ret( Some(@ast::expr{id:1, node:ast::expr_path( - @ast::Path{span:sp(7,8), + ast::Path{span:sp(7,8), global:false, idents:~[str_to_ident("d")], rp:None, @@ -444,7 +444,7 @@ mod test { node: ast::stmt_expr(@ast::expr{ id: 1, node: ast::expr_path( - @ast::Path{ + ast::Path{ span:sp(0,1), global:false, idents:~[str_to_ident("b")], @@ -465,7 +465,7 @@ mod test { assert_eq!(parser.parse_pat(), @ast::pat{id:1, // fixme node: ast::pat_ident(ast::bind_infer, - @ast::Path{ + ast::Path{ span:sp(0,1), global:false, idents:~[str_to_ident("b")], @@ -483,7 +483,7 @@ mod test { ast::arg{ is_mutbl: false, ty: @ast::Ty{id:3, // fixme - node: ast::ty_path(@ast::Path{ + node: ast::ty_path(ast::Path{ span:sp(4,4), // this is bizarre... // check this in the original parser? global:false, @@ -494,7 +494,7 @@ mod test { span:sp(4,7)}, pat: @ast::pat{id:1, node: ast::pat_ident(ast::bind_infer, - @ast::Path{ + ast::Path{ span:sp(0,1), global:false, idents:~[str_to_ident("b")], @@ -520,7 +520,7 @@ mod test { inputs: ~[ast::arg{ is_mutbl: false, ty: @ast::Ty{id:3, // fixme - node: ast::ty_path(@ast::Path{ + node: ast::ty_path(ast::Path{ span:sp(10,13), global:false, idents:~[str_to_ident("int")], @@ -531,7 +531,7 @@ mod test { pat: @ast::pat{id:1, // fixme node: ast::pat_ident( ast::bind_infer, - @ast::Path{ + ast::Path{ span:sp(6,7), global:false, idents:~[str_to_ident("b")], @@ -561,7 +561,7 @@ mod test { node: ast::stmt_semi(@ast::expr{ id: 6, node: ast::expr_path( - @ast::Path{ + ast::Path{ span:sp(17,18), global:false, idents:~[str_to_ident("b")], diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 35c558c5296..00386f611b1 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -130,20 +130,28 @@ The important thing is to make sure that lookahead doesn't balk at INTERPOLATED tokens */ macro_rules! maybe_whole_expr ( ($p:expr) => ( - match *($p).token { - INTERPOLATED(token::nt_expr(e)) => { - $p.bump(); - return e; - } - INTERPOLATED(token::nt_path(pt)) => { - $p.bump(); - return $p.mk_expr( - ($p).span.lo, - ($p).span.hi, - expr_path(pt) - ); + { + // This horrible convolution is brought to you by + // @mut, have a terrible day + let ret = match *($p).token { + INTERPOLATED(token::nt_expr(e)) => { + Some(e) + } + INTERPOLATED(token::nt_path(ref pt)) => { + Some($p.mk_expr( + ($p).span.lo, + ($p).span.hi, + expr_path(/* bad */ copy *pt))) + } + _ => None + }; + match ret { + Some(e) => { + $p.bump(); + return e; + } + None => () } - _ => () } ) ) @@ -1218,10 +1226,10 @@ impl Parser { } // parse a path that doesn't have type parameters attached - pub fn parse_path_without_tps(&self) -> @ast::Path { + pub fn parse_path_without_tps(&self) -> ast::Path { maybe_whole!(self, nt_path); let (ids,is_global,sp) = self.parse_path(); - @ast::Path { span: sp, + ast::Path { span: sp, global: is_global, idents: ids, rp: None, @@ -1229,7 +1237,7 @@ impl Parser { } pub fn parse_bounded_path_with_tps(&self, colons: bool, - before_tps: Option<&fn()>) -> @ast::Path { + before_tps: Option<&fn()>) -> ast::Path { debug!("parse_path_with_tps(colons=%b)", colons); maybe_whole!(self, nt_path); @@ -1288,22 +1296,22 @@ impl Parser { } }; - @ast::Path { span: mk_sp(lo, hi), + ast::Path { span: mk_sp(lo, hi), rp: rp, types: tps, - .. copy *path } + .. path } } // parse a path optionally with type parameters. If 'colons' // is true, then type parameters must be preceded by colons, // as in a::t::<t1,t2> - pub fn parse_path_with_tps(&self, colons: bool) -> @ast::Path { + pub fn parse_path_with_tps(&self, colons: bool) -> ast::Path { self.parse_bounded_path_with_tps(colons, None) } // Like the above, but can also parse kind bounds in the case of a // path to be used as a type that might be a trait. - pub fn parse_type_path(&self) -> (@ast::Path, Option<OptVec<TyParamBound>>) { + pub fn parse_type_path(&self) -> (ast::Path, Option<OptVec<TyParamBound>>) { let mut bounds = None; let path = self.parse_bounded_path_with_tps(false, Some(|| { // Note: this closure might not even get called in the case of a @@ -3557,9 +3565,9 @@ impl Parser { let opt_trait = if could_be_trait && self.eat_keyword(keywords::For) { // New-style trait. Reinterpret the type as a trait. let opt_trait_ref = match ty.node { - ty_path(path, @None, node_id) => { + ty_path(ref path, @None, node_id) => { Some(@trait_ref { - path: path, + path: /* bad */ copy *path, ref_id: node_id }) } @@ -4558,7 +4566,7 @@ impl Parser { let id = self.parse_ident(); path.push(id); } - let path = @ast::Path { span: mk_sp(lo, self.span.hi), + let path = ast::Path { span: mk_sp(lo, self.span.hi), global: false, idents: path, rp: None, @@ -4588,7 +4596,7 @@ impl Parser { seq_sep_trailing_allowed(token::COMMA), |p| p.parse_path_list_ident() ); - let path = @ast::Path { span: mk_sp(lo, self.span.hi), + let path = ast::Path { span: mk_sp(lo, self.span.hi), global: false, idents: path, rp: None, @@ -4600,7 +4608,7 @@ impl Parser { // foo::bar::* token::BINOP(token::STAR) => { self.bump(); - let path = @ast::Path { span: mk_sp(lo, self.span.hi), + let path = ast::Path { span: mk_sp(lo, self.span.hi), global: false, idents: path, rp: None, @@ -4616,7 +4624,7 @@ impl Parser { _ => () } let last = path[path.len() - 1u]; - let path = @ast::Path { span: mk_sp(lo, self.span.hi), + let path = ast::Path { span: mk_sp(lo, self.span.hi), global: false, idents: path, rp: None, diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index a50fa416832..0264903076b 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -106,7 +106,7 @@ pub enum nonterminal { nt_expr(@ast::expr), nt_ty( @ast::Ty), nt_ident(ast::ident, bool), - nt_path(@ast::Path), + nt_path( ast::Path), nt_tt( @ast::token_tree), //needs @ed to break a circularity nt_matchers(~[ast::matcher]) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index f6d62e47610..36e9ba4b08a 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -179,7 +179,7 @@ pub fn generics_to_str(generics: &ast::Generics, to_str(generics, print_generics, intr) } -pub fn path_to_str(p: @ast::Path, intr: @ident_interner) -> ~str { +pub fn path_to_str(p: &ast::Path, intr: @ident_interner) -> ~str { to_str(p, |a,b| print_path(a, b, false), intr) } @@ -419,7 +419,7 @@ pub fn print_type(s: @ps, ty: @ast::Ty) { f.purity, f.onceness, &f.decl, None, &f.bounds, Some(&generics), None); } - ast::ty_path(path, bounds, _) => print_bounded_path(s, path, bounds), + ast::ty_path(ref path, bounds, _) => print_bounded_path(s, path, bounds), ast::ty_fixed_length_vec(ref mt, v) => { word(s.s, "["); match mt.mutbl { @@ -600,7 +600,7 @@ pub fn print_item(s: @ps, item: @ast::item) { if i != 0 { word_space(s, "+"); } - print_path(s, trait_.path, false); + print_path(s, &trait_.path, false); } } word(s.s, " "); @@ -610,7 +610,7 @@ pub fn print_item(s: @ps, item: @ast::item) { } bclose(s, item.span); } - ast::item_mac(codemap::spanned { node: ast::mac_invoc_tt(pth, ref tts), + ast::item_mac(codemap::spanned { node: ast::mac_invoc_tt(ref pth, ref tts), _}) => { print_visibility(s, item.vis); print_path(s, pth, false); @@ -627,7 +627,7 @@ pub fn print_item(s: @ps, item: @ast::item) { } fn print_trait_ref(s: @ps, t: &ast::trait_ref) { - print_path(s, t.path, false); + print_path(s, &t.path, false); } pub fn print_enum_def(s: @ps, enum_definition: &ast::enum_def, @@ -1005,7 +1005,7 @@ pub fn print_if(s: @ps, test: @ast::expr, blk: &ast::blk, pub fn print_mac(s: @ps, m: &ast::mac) { match m.node { - ast::mac_invoc_tt(pth, ref tts) => { + ast::mac_invoc_tt(ref pth, ref tts) => { print_path(s, pth, false); word(s.s, "!"); popen(s); @@ -1134,7 +1134,7 @@ pub fn print_expr(s: @ps, expr: @ast::expr) { end(s); } - ast::expr_struct(path, ref fields, wth) => { + ast::expr_struct(ref path, ref fields, wth) => { print_path(s, path, true); word(s.s, "{"); commasep_cmnt(s, consistent, (*fields), print_field, get_span); @@ -1359,7 +1359,7 @@ pub fn print_expr(s: @ps, expr: @ast::expr) { print_expr(s, index); word(s.s, "]"); } - ast::expr_path(path) => print_path(s, path, true), + ast::expr_path(ref path) => print_path(s, path, true), ast::expr_self => word(s.s, "self"), ast::expr_break(opt_ident) => { word(s.s, "break"); @@ -1486,7 +1486,7 @@ pub fn print_for_decl(s: @ps, loc: @ast::local, coll: @ast::expr) { print_expr(s, coll); } -fn print_path_(s: @ps, path: @ast::Path, colons_before_params: bool, +fn print_path_(s: @ps, path: &ast::Path, colons_before_params: bool, opt_bounds: &Option<OptVec<ast::TyParamBound>>) { maybe_print_comment(s, path.span.lo); if path.global { word(s.s, "::"); } @@ -1518,11 +1518,11 @@ fn print_path_(s: @ps, path: @ast::Path, colons_before_params: bool, } } -pub fn print_path(s: @ps, path: @ast::Path, colons_before_params: bool) { +pub fn print_path(s: @ps, path: &ast::Path, colons_before_params: bool) { print_path_(s, path, colons_before_params, &None) } -pub fn print_bounded_path(s: @ps, path: @ast::Path, +pub fn print_bounded_path(s: @ps, path: &ast::Path, bounds: &Option<OptVec<ast::TyParamBound>>) { print_path_(s, path, false, bounds) } @@ -1543,7 +1543,7 @@ pub fn print_pat(s: @ps, pat: @ast::pat, refutable: bool) { is that it doesn't matter */ match pat.node { ast::pat_wild => word(s.s, "_"), - ast::pat_ident(binding_mode, path, sub) => { + ast::pat_ident(binding_mode, ref path, sub) => { if refutable { match binding_mode { ast::bind_by_ref(mutbl) => { @@ -1562,7 +1562,7 @@ pub fn print_pat(s: @ps, pat: @ast::pat, refutable: bool) { None => () } } - ast::pat_enum(path, ref args_) => { + ast::pat_enum(ref path, ref args_) => { print_path(s, path, true); match *args_ { None => word(s.s, "(*)"), @@ -1576,7 +1576,7 @@ pub fn print_pat(s: @ps, pat: @ast::pat, refutable: bool) { } } } - ast::pat_struct(path, ref fields, etc) => { + ast::pat_struct(ref path, ref fields, etc) => { print_path(s, path, true); word(s.s, "{"); fn print_field(s: @ps, f: ast::field_pat, refutable: bool) { @@ -1815,7 +1815,7 @@ pub fn print_meta_item(s: @ps, item: @ast::meta_item) { pub fn print_view_path(s: @ps, vp: @ast::view_path) { match vp.node { - ast::view_path_simple(ident, path, _) => { + ast::view_path_simple(ident, ref path, _) => { if path.idents[path.idents.len()-1u] != ident { print_ident(s, ident); space(s.s); @@ -1824,12 +1824,12 @@ pub fn print_view_path(s: @ps, vp: @ast::view_path) { print_path(s, path, false); } - ast::view_path_glob(path, _) => { + ast::view_path_glob(ref path, _) => { print_path(s, path, false); word(s.s, "::*"); } - ast::view_path_list(path, ref idents, _) => { + ast::view_path_list(ref path, ref idents, _) => { print_path(s, path, false); word(s.s, "::{"); do commasep(s, inconsistent, (*idents)) |s, w| { @@ -1892,7 +1892,7 @@ pub fn print_arg(s: @ps, input: ast::arg) { ast::ty_infer => print_irrefutable_pat(s, input.pat), _ => { match input.pat.node { - ast::pat_ident(_, path, _) if + ast::pat_ident(_, ref path, _) if path.idents.len() == 1 && path.idents[0] == parse::token::special_idents::invalid => { // Do nothing. diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 944e94ddc0a..1e615ccb777 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -139,7 +139,7 @@ pub fn visit_local<E: Copy>(loc: &local, (e, v): (E, vt<E>)) { } fn visit_trait_ref<E: Copy>(tref: &ast::trait_ref, (e, v): (E, vt<E>)) { - visit_path(tref.path, (e, v)); + visit_path(&tref.path, (e, v)); } pub fn visit_item<E: Copy>(i: &item, (e, v): (E, vt<E>)) { @@ -197,7 +197,7 @@ pub fn visit_item<E: Copy>(i: &item, (e, v): (E, vt<E>)) { } item_trait(ref generics, ref traits, ref methods) => { (v.visit_generics)(generics, (copy e, v)); - for traits.iter().advance |p| { visit_path(p.path, (copy e, v)); } + for traits.iter().advance |p| { visit_path(&p.path, (copy e, v)); } for methods.iter().advance |m| { (v.visit_trait_method)(m, (copy e, v)); } @@ -252,7 +252,7 @@ pub fn visit_ty<E: Copy>(t: &Ty, (e, v): (E, vt<E>)) { for f.decl.inputs.iter().advance |a| { (v.visit_ty)(a.ty, (copy e, v)); } (v.visit_ty)(f.decl.output, (e, v)); }, - ty_path(p, bounds, _) => { + ty_path(ref p, bounds, _) => { visit_path(p, (copy e, v)); do bounds.map |bounds| { visit_ty_param_bounds(bounds, (copy e, v)); @@ -272,7 +272,7 @@ pub fn visit_path<E: Copy>(p: &Path, (e, v): (E, vt<E>)) { pub fn visit_pat<E: Copy>(p: &pat, (e, v): (E, vt<E>)) { match p.node { - pat_enum(path, ref children) => { + pat_enum(ref path, ref children) => { visit_path(path, (copy e, v)); for children.iter().advance |children| { for children.iter().advance |child| { @@ -280,7 +280,7 @@ pub fn visit_pat<E: Copy>(p: &pat, (e, v): (E, vt<E>)) { } } } - pat_struct(path, ref fields, _) => { + pat_struct(ref path, ref fields, _) => { visit_path(path, (copy e, v)); for fields.iter().advance |f| { (v.visit_pat)(f.pat, (copy e, v)); @@ -294,7 +294,7 @@ pub fn visit_pat<E: Copy>(p: &pat, (e, v): (E, vt<E>)) { pat_box(inner) | pat_uniq(inner) | pat_region(inner) => { (v.visit_pat)(inner, (e, v)) }, - pat_ident(_, path, ref inner) => { + pat_ident(_, ref path, ref inner) => { visit_path(path, (copy e, v)); for inner.iter().advance |subpat| { (v.visit_pat)(*subpat, (copy e, v)) @@ -458,7 +458,7 @@ pub fn visit_expr<E: Copy>(ex: @expr, (e, v): (E, vt<E>)) { (v.visit_expr)(element, (copy e, v)); (v.visit_expr)(count, (copy e, v)); } - expr_struct(p, ref flds, base) => { + expr_struct(ref p, ref flds, base) => { visit_path(p, (copy e, v)); for flds.iter().advance |f| { (v.visit_expr)(f.node.expr, (copy e, v)); @@ -534,7 +534,7 @@ pub fn visit_expr<E: Copy>(ex: @expr, (e, v): (E, vt<E>)) { (v.visit_expr)(a, (copy e, v)); (v.visit_expr)(b, (copy e, v)); } - expr_path(p) => visit_path(p, (copy e, v)), + expr_path(ref p) => visit_path(p, (copy e, v)), expr_self => (), expr_break(_) => (), expr_again(_) => (), |
