diff --git a/src/librustsyntax/ast.rs b/src/librustsyntax/ast.rs index c44de4ed146..339c897256c 100644 --- a/src/librustsyntax/ast.rs +++ b/src/librustsyntax/ast.rs @@ -37,10 +37,7 @@ type ident = str; type fn_ident = option; #[auto_serialize] -type path_ = {global: bool, idents: [ident], types: [@ty]}; - -#[auto_serialize] -type path = spanned; +type path = {span: span, global: bool, idents: [ident], types: [@ty]}; #[auto_serialize] type crate_num = int; diff --git a/src/librustsyntax/ast_util.rs b/src/librustsyntax/ast_util.rs index a440041acd3..f74f543a716 100644 --- a/src/librustsyntax/ast_util.rs +++ b/src/librustsyntax/ast_util.rs @@ -21,7 +21,7 @@ fn mk_sp(lo: uint, hi: uint) -> span { // make this a const, once the compiler supports it fn dummy_sp() -> span { ret mk_sp(0u, 0u); } -fn path_name(p: @path) -> str { path_name_i(p.node.idents) } +fn path_name(p: @path) -> str { path_name_i(p.idents) } fn path_name_i(idents: [ident]) -> str { str::connect(idents, "::") } @@ -183,8 +183,8 @@ fn is_exported(i: ident, m: _mod) -> bool { } ast::view_path_list(path, ids, _) { - if vec::len(path.node.idents) == 1u { - if i == path.node.idents[0] { ret true; } + if vec::len(path.idents) == 1u { + if i == path.idents[0] { ret true; } for ids.each {|id| if id.node.name == i { ret true; } } @@ -249,7 +249,7 @@ fn default_block(stmts1: [@stmt], expr1: option<@expr>, id1: node_id) -> } fn ident_to_path(s: span, i: ident) -> @path { - @respan(s, {global: false, idents: [i], types: []}) + @{span: s, global: false, idents: [i], types: []} } pure fn is_unguarded(&&a: arm) -> bool { diff --git a/src/librustsyntax/ext/auto_serialize.rs b/src/librustsyntax/ext/auto_serialize.rs index 6a361e73b93..0532a2c987b 100644 --- a/src/librustsyntax/ext/auto_serialize.rs +++ b/src/librustsyntax/ext/auto_serialize.rs @@ -124,19 +124,17 @@ fn expand(cx: ext_ctxt, impl helpers for ext_ctxt { fn helper_path(base_path: @ast::path, helper_name: str) -> @ast::path { - let head = vec::init(base_path.node.idents); - let tail = vec::last(base_path.node.idents); + let head = vec::init(base_path.idents); + let tail = vec::last(base_path.idents); self.path(base_path.span, head + [helper_name + "_" + tail]) } fn path(span: span, strs: [str]) -> @ast::path { - @{node: {global: false, idents: strs, types: []}, - span: span} + @{span: span, global: false, idents: strs, types: []} } fn path_tps(span: span, strs: [str], tps: [@ast::ty]) -> @ast::path { - @{node: {global: false, idents: strs, types: tps}, - span: span} + @{span: span, global: false, idents: strs, types: tps} } fn ty_path(span: span, strs: [str], tps: [@ast::ty]) -> @ast::ty { @@ -195,10 +193,7 @@ impl helpers for ext_ctxt { } fn binder_pat(span: span, nm: str) -> @ast::pat { - let path = @{node: {global: false, - idents: [nm], - types: []}, - span: span}; + let path = @{span: span, global: false, idents: [nm], types: []}; @{id: self.next_id(), node: ast::pat_ident(path, none), span: span} @@ -292,7 +287,7 @@ fn ser_path(cx: ext_ctxt, tps: ser_tps_map, path: @ast::path, ast::expr_path( cx.helper_path(path, "serialize"))); - let ty_args = vec::map(path.node.types) {|ty| + let ty_args = vec::map(path.types) {|ty| let sv_stmts = ser_ty(cx, tps, ty, cx.clone(s), #ast{ __v }); let sv = cx.expr(path.span, ast::expr_block(cx.blk(path.span, sv_stmts))); @@ -428,9 +423,9 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map, } ast::ty_path(path, _) { - if vec::len(path.node.idents) == 1u && - vec::is_empty(path.node.types) { - let ident = path.node.idents[0]; + if vec::len(path.idents) == 1u && + vec::is_empty(path.types) { + let ident = path.idents[0]; alt tps.find(ident) { some(f) { f(v) } @@ -566,7 +561,7 @@ fn deser_path(cx: ext_ctxt, tps: deser_tps_map, path: @ast::path, ast::expr_path( cx.helper_path(path, "deserialize"))); - let ty_args = vec::map(path.node.types) {|ty| + let ty_args = vec::map(path.types) {|ty| let dv_expr = deser_ty(cx, tps, ty, cx.clone(d)); cx.lambda(cx.expr_blk(dv_expr)) }; @@ -650,9 +645,9 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map, } ast::ty_path(path, _) { - if vec::len(path.node.idents) == 1u && - vec::is_empty(path.node.types) { - let ident = path.node.idents[0]; + if vec::len(path.idents) == 1u && + vec::is_empty(path.types) { + let ident = path.idents[0]; alt tps.find(ident) { some(f) { f() } diff --git a/src/librustsyntax/ext/base.rs b/src/librustsyntax/ext/base.rs index 125fb99b8df..a4ca819d6b6 100644 --- a/src/librustsyntax/ext/base.rs +++ b/src/librustsyntax/ext/base.rs @@ -137,9 +137,9 @@ fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: str) -> str { fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: str) -> ast::ident { alt expr.node { ast::expr_path(p) { - if vec::len(p.node.types) > 0u || vec::len(p.node.idents) != 1u { + if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { cx.span_fatal(expr.span, error); - } else { ret p.node.idents[0]; } + } else { ret p.idents[0]; } } _ { cx.span_fatal(expr.span, error); } } diff --git a/src/librustsyntax/ext/build.rs b/src/librustsyntax/ext/build.rs index 9a0ee1c75a3..ebf57745d9f 100644 --- a/src/librustsyntax/ext/build.rs +++ b/src/librustsyntax/ext/build.rs @@ -30,9 +30,8 @@ fn mk_unary(cx: ext_ctxt, sp: span, op: ast::unop, e: @ast::expr) } fn mk_path(cx: ext_ctxt, sp: span, idents: [ast::ident]) -> @ast::expr { - let path = {global: false, idents: idents, types: []}; - let sp_path = @{node: path, span: sp}; - let pathexpr = ast::expr_path(sp_path); + let path = @{span: sp, global: false, idents: idents, types: []}; + let pathexpr = ast::expr_path(path); ret @{id: cx.next_id(), node: pathexpr, span: sp}; } fn mk_access_(cx: ext_ctxt, sp: span, p: @ast::expr, m: ast::ident) diff --git a/src/librustsyntax/ext/concat_idents.rs b/src/librustsyntax/ext/concat_idents.rs index 58577eb2e08..8d2c89c0d43 100644 --- a/src/librustsyntax/ext/concat_idents.rs +++ b/src/librustsyntax/ext/concat_idents.rs @@ -16,8 +16,7 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg, } ret @{id: cx.next_id(), - node: ast::expr_path(@{node: {global: false, idents: [res], - types: []}, - span: sp}), + node: ast::expr_path(@{span: sp, global: false, idents: [res], + types: []}), span: sp}; } diff --git a/src/librustsyntax/ext/expand.rs b/src/librustsyntax/ext/expand.rs index 209e9e50c1d..f70a75bd96a 100644 --- a/src/librustsyntax/ext/expand.rs +++ b/src/librustsyntax/ext/expand.rs @@ -19,8 +19,8 @@ fn expand_expr(exts: hashmap, cx: ext_ctxt, expr_mac(mac) { alt mac.node { mac_invoc(pth, args, body) { - assert (vec::len(pth.node.idents) > 0u); - let extname = pth.node.idents[0]; + assert (vec::len(pth.idents) > 0u); + let extname = pth.idents[0]; alt exts.find(extname) { none { cx.span_fatal(pth.span, diff --git a/src/librustsyntax/ext/qquote.rs b/src/librustsyntax/ext/qquote.rs index e625ba55fed..15e61e2da67 100644 --- a/src/librustsyntax/ext/qquote.rs +++ b/src/librustsyntax/ext/qquote.rs @@ -142,7 +142,7 @@ fn expand_ast(ecx: ext_ctxt, _sp: span, ecx.span_fatal(_sp, "#ast requires exactly one arg"); } alt (args[0].node) { - ast::expr_path(@{node: {idents: id, _},_}) if vec::len(id) == 1u + ast::expr_path(@{idents: id, _}) if vec::len(id) == 1u {what = id[0]} _ {ecx.span_fatal(args[0].span, "expected an identifier");} } diff --git a/src/librustsyntax/ext/simplext.rs b/src/librustsyntax/ext/simplext.rs index 94027014897..da2acd333fd 100644 --- a/src/librustsyntax/ext/simplext.rs +++ b/src/librustsyntax/ext/simplext.rs @@ -5,14 +5,14 @@ import base::*; import fold::*; import ast_util::respan; -import ast::{ident, path, ty, blk_, expr, path_, expr_path, +import ast::{ident, path, ty, blk_, expr, expr_path, expr_vec, expr_mac, mac_invoc, node_id}; export add_new_extension; fn path_to_ident(pth: @path) -> option { - if vec::len(pth.node.idents) == 1u && vec::len(pth.node.types) == 0u { - ret some(pth.node.idents[0u]); + if vec::len(pth.idents) == 1u && vec::len(pth.types) == 0u { + ret some(pth.idents[0u]); } ret none; } @@ -190,7 +190,7 @@ fn transcribe(cx: ext_ctxt, b: bindings, body: @expr) -> @expr { let afp = default_ast_fold(); let f_pre = {fold_ident: bind transcribe_ident(cx, b, idx_path, _, _), - fold_path: bind transcribe_path(cx, b, idx_path, _, _, _), + fold_path: bind transcribe_path(cx, b, idx_path, _, _), fold_expr: bind transcribe_expr(cx, b, idx_path, _, _, _, afp.fold_expr), fold_ty: bind transcribe_type(cx, b, idx_path, _, _, _, afp.fold_ty), @@ -329,17 +329,17 @@ fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mut [uint], fn transcribe_path(cx: ext_ctxt, b: bindings, idx_path: @mut [uint], - p: path_, s:span, _fld: ast_fold) -> (path_, span) { + p: path, _fld: ast_fold) -> path { // Don't substitute into qualified names. - if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { ret (p, s); } - ret alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { - some(match_ident(id)) { - ({global: false, idents: [id.node], types: []}, id.span) - } - some(match_path(a_pth)) { (a_pth.node, a_pth.span) } - some(m) { match_error(cx, m, "a path") } - none { (p, s) } - } + if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { ret p; } + alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { + some(match_ident(id)) { + {span: id.span, global: false, idents: [id.node], types: []} + } + some(match_path(a_pth)) { *a_pth } + some(m) { match_error(cx, m, "a path") } + none { p } + } } @@ -351,15 +351,15 @@ fn transcribe_expr(cx: ext_ctxt, b: bindings, idx_path: @mut [uint], ret alt e { expr_path(p) { // Don't substitute into qualified names. - if vec::len(p.node.types) > 0u || vec::len(p.node.idents) != 1u { + if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { (e, s); } - alt follow_for_trans(cx, b.find(p.node.idents[0]), idx_path) { + alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { some(match_ident(id)) { - (expr_path(@respan(id.span, - {global: false, - idents: [id.node], - types: []})), id.span) + (expr_path(@{span: id.span, + global: false, + idents: [id.node], + types: []}), id.span) } some(match_path(a_pth)) { (expr_path(a_pth), s) } some(match_expr(a_exp)) { (a_exp.node, a_exp.span) } diff --git a/src/librustsyntax/fold.rs b/src/librustsyntax/fold.rs index 237b45408d9..b70755a1d2c 100644 --- a/src/librustsyntax/fold.rs +++ b/src/librustsyntax/fold.rs @@ -46,7 +46,7 @@ type ast_fold_precursor = fold_native_mod: fn@(native_mod, ast_fold) -> native_mod, fold_variant: fn@(variant_, span, ast_fold) -> (variant_, span), fold_ident: fn@(&&ident, ast_fold) -> ident, - fold_path: fn@(path_, span, ast_fold) -> (path_, span), + 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, @@ -559,8 +559,8 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ { fn noop_fold_ident(&&i: ident, _fld: ast_fold) -> ident { ret i; } -fn noop_fold_path(&&p: path_, fld: ast_fold) -> path_ { - ret {global: p.global, +fn noop_fold_path(&&p: path, fld: ast_fold) -> path { + ret {span: fld.new_span(p.span), global: p.global, idents: vec::map(p.idents, fld.fold_ident), types: vec::map(p.types, fld.fold_ty)}; } @@ -613,7 +613,7 @@ fn default_ast_fold() -> @ast_fold_precursor { fold_native_mod: noop_fold_native_mod, fold_variant: wrap(noop_fold_variant), fold_ident: noop_fold_ident, - fold_path: wrap(noop_fold_path), + fold_path: noop_fold_path, fold_local: wrap(noop_fold_local), map_exprs: noop_map_exprs, new_id: noop_id, @@ -754,8 +754,7 @@ fn make_fold(afp: ast_fold_precursor) -> ast_fold { ret afp.fold_ident(x, f); } fn f_path(afp: ast_fold_precursor, f: ast_fold, &&x: @path) -> @path { - let (n, s) = afp.fold_path(x.node, x.span, f); - ret @{node: n, span: afp.new_span(s)}; + @afp.fold_path(*x, f) } fn f_local(afp: ast_fold_precursor, f: ast_fold, &&x: @local) -> @local { let (n, s) = afp.fold_local(x.node, x.span, f); diff --git a/src/librustsyntax/parse/parser.rs b/src/librustsyntax/parse/parser.rs index d4160e89bca..7ebac4f5c8b 100644 --- a/src/librustsyntax/parse/parser.rs +++ b/src/librustsyntax/parse/parser.rs @@ -67,7 +67,7 @@ impl parser for parser { if vec::len(self.buffer) == 0u { let next = lexer::next_token(self.reader); self.token = next.tok; - self.span = ast_util::mk_sp(next.chpos, self.reader.chpos); + self.span = mk_sp(next.chpos, self.reader.chpos); } else { let next = vec::pop(self.buffer); self.token = next.tok; @@ -76,12 +76,12 @@ impl parser for parser { } fn swap(next: token::token, lo: uint, hi: uint) { self.token = next; - self.span = ast_util::mk_sp(lo, hi); + self.span = mk_sp(lo, hi); } fn look_ahead(distance: uint) -> token::token { while vec::len(self.buffer) < distance { let next = lexer::next_token(self.reader); - let sp = ast_util::mk_sp(next.chpos, self.reader.chpos); + let sp = mk_sp(next.chpos, self.reader.chpos); self.buffer = [{tok: next.tok, span: sp}] + self.buffer; } ret self.buffer[distance - 1u].tok; @@ -140,7 +140,7 @@ fn parse_ty_methods(p: parser) -> [ast::ty_method] { let d = parse_ty_fn(p), fhi = p.last_span.hi; expect(p, token::SEMI); {ident: ident, attrs: attrs, decl: {purity: pur with d}, tps: tps, - span: ast_util::mk_sp(flo, fhi)} + span: mk_sp(flo, fhi)} }, p).node } @@ -237,7 +237,7 @@ fn parse_ty_postfix(orig_t: ast::ty_, p: parser, colons_before_params: bool, fn mk_ty(p: parser, t: ast::ty_, lo: uint, hi: uint) -> @ast::ty { @{id: p.get_id(), node: t, - span: ast_util::mk_sp(lo, hi)} + span: mk_sp(lo, hi)} } if p.token == token::BINOP(token::SLASH) { @@ -266,10 +266,10 @@ fn parse_ty_postfix(orig_t: ast::ty_, p: parser, colons_before_params: bool, alt orig_t { ast::ty_path(pth, ann) { - ret mk_ty(p, ast::ty_path(@spanned(lo, p.last_span.hi, - {global: pth.node.global, - idents: pth.node.idents, - types: seq}), ann), + ret mk_ty(p, ast::ty_path(@{span: mk_sp(lo, p.last_span.hi), + global: pth.global, + idents: pth.idents, + types: seq}, ann), lo, p.last_span.hi); } _ { p.fatal("type parameter instantiation only allowed for paths"); } @@ -282,7 +282,7 @@ fn parse_ret_ty(p: parser) -> (ast::ret_style, @ast::ty) { if eat(p, token::NOT) { (ast::noreturn, @{id: p.get_id(), node: ast::ty_bot, - span: ast_util::mk_sp(lo, p.last_span.hi)}) + span: mk_sp(lo, p.last_span.hi)}) } else { (ast::return_val, parse_ty(p, false)) } @@ -290,7 +290,7 @@ fn parse_ret_ty(p: parser) -> (ast::ret_style, @ast::ty) { let pos = p.span.lo; (ast::return_val, @{id: p.get_id(), node: ast::ty_nil, - span: ast_util::mk_sp(pos, pos)}) + span: mk_sp(pos, pos)}) } } @@ -331,7 +331,7 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty { some(e) { ret @{id: p.get_id(), node: ast::ty_mac(spanned(lo, p.span.hi, e)), - span: ast_util::mk_sp(lo, p.span.hi)}; + span: mk_sp(lo, p.span.hi)}; } none {} } @@ -373,7 +373,7 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty { p.bump(); ast::ty_constr(@{id: p.get_id(), node: t, - span: ast_util::mk_sp(lo, hi)}, + span: mk_sp(lo, hi)}, parse_type_constraints(p)) } else { t } } else if p.token == token::LBRACKET { @@ -435,7 +435,7 @@ fn parse_fn_block_arg(p: parser) -> ast::arg { } else { @{id: p.get_id(), node: ast::ty_infer, - span: ast_util::mk_sp(p.span.lo, p.span.hi)} + span: mk_sp(p.span.lo, p.span.hi)} }; ret {mode: m, ty: t, ident: i, id: p.get_id()}; } @@ -455,7 +455,7 @@ fn maybe_parse_dollar_mac(p: parser) -> option { let e = parse_expr(p); expect(p, token::RPAREN); let hi = p.last_span.hi; - some(ast::mac_aq(ast_util::mk_sp(lo,hi), e)) + some(ast::mac_aq(mk_sp(lo,hi), e)) } _ { p.fatal("expected `(` or integer literal"); @@ -526,7 +526,7 @@ fn parse_lit(p: parser) -> ast::lit { p.bump(); lit_from_token(p, tok) }; - ret {node: lit, span: ast_util::mk_sp(lo, p.last_span.hi)}; + ret {node: lit, span: mk_sp(lo, p.last_span.hi)}; } fn parse_path(p: parser) -> @ast::path { @@ -536,13 +536,12 @@ fn parse_path(p: parser) -> @ast::path { while p.look_ahead(1u) != token::LT && eat(p, token::MOD_SEP) { ids += [parse_ident(p)]; } - ret @spanned(lo, p.last_span.hi, - {global: global, idents: ids, types: []}); + @{span: mk_sp(lo, p.last_span.hi), global: global, idents: ids, types: []} } fn parse_value_path(p: parser) -> @ast::path { let pt = parse_path(p); - let last_word = pt.node.idents[vec::len(pt.node.idents)-1u]; + let last_word = vec::last(pt.idents); if p.bad_expr_words.contains_key(last_word) { p.fatal("found " + last_word + " in expression position"); } @@ -552,15 +551,12 @@ fn parse_value_path(p: parser) -> @ast::path { fn parse_path_and_ty_param_substs(p: parser, colons: bool) -> @ast::path { let lo = p.span.lo; let path = parse_path(p); - let b = if colons { - eat(p, token::MOD_SEP) - } else { - p.token == token::LT - }; + let b = if colons { eat(p, token::MOD_SEP) } + else { p.token == token::LT }; if b { let seq = parse_seq_lt_gt(some(token::COMMA), {|p| parse_ty(p, false)}, p); - @spanned(lo, seq.span.hi, {types: seq.node with path.node}) + @{span: mk_sp(lo, seq.span.hi), types: seq.node with *path} } else { path } } @@ -586,13 +582,13 @@ fn parse_field(p: parser, sep: token::token) -> ast::field { } fn mk_expr(p: parser, lo: uint, hi: uint, node: ast::expr_) -> @ast::expr { - ret @{id: p.get_id(), node: node, span: ast_util::mk_sp(lo, hi)}; + ret @{id: p.get_id(), node: node, span: mk_sp(lo, hi)}; } fn mk_mac_expr(p: parser, lo: uint, hi: uint, m: ast::mac_) -> @ast::expr { ret @{id: p.get_id(), - node: ast::expr_mac({node: m, span: ast_util::mk_sp(lo, hi)}), - span: ast_util::mk_sp(lo, hi)}; + node: ast::expr_mac({node: m, span: mk_sp(lo, hi)}), + span: mk_sp(lo, hi)}; } fn mk_lit_u32(p: parser, i: u32) -> @ast::expr { @@ -1156,7 +1152,7 @@ fn parse_capture_clause(p: parser) -> @ast::capture_clause { alt p.token { token::IDENT(_, _) { let id = p.get_id(); - let sp = ast_util::mk_sp(p.span.lo, p.span.hi); + let sp = mk_sp(p.span.lo, p.span.hi); let ident = parse_ident(p); res += [@{id:id, name:ident, span:sp}]; if !eat(p, token::COMMA) { @@ -1364,7 +1360,7 @@ fn parse_pat(p: parser) -> @ast::pat { let lo1 = p.last_span.lo; let fieldname = parse_ident(p); let hi1 = p.last_span.lo; - let fieldpath = ast_util::ident_to_path(ast_util::mk_sp(lo1, hi1), + let fieldpath = ast_util::ident_to_path(mk_sp(lo1, hi1), fieldname); let mut subpat; if p.token == token::COLON { @@ -1376,7 +1372,7 @@ fn parse_pat(p: parser) -> @ast::pat { } subpat = @{id: p.get_id(), node: ast::pat_ident(fieldpath, none), - span: ast_util::mk_sp(lo, hi)}; + span: mk_sp(lo, hi)}; } fields += [{ident: fieldname, pat: subpat}]; } @@ -1389,7 +1385,7 @@ fn parse_pat(p: parser) -> @ast::pat { if p.token == token::RPAREN { hi = p.span.hi; p.bump(); - let lit = @{node: ast::lit_nil, span: ast_util::mk_sp(lo, hi)}; + let lit = @{node: ast::lit_nil, span: mk_sp(lo, hi)}; let expr = mk_expr(p, lo, hi, ast::expr_lit(lit)); pat = ast::pat_lit(expr); } else { @@ -1454,7 +1450,7 @@ fn parse_pat(p: parser) -> @ast::pat { pat = ast::pat_enum(enum_path, none); } else if vec::is_empty(args) && - vec::len(enum_path.node.idents) == 1u { + vec::len(enum_path.idents) == 1u { pat = ast::pat_ident(enum_path, none); } else { @@ -1463,7 +1459,7 @@ fn parse_pat(p: parser) -> @ast::pat { } } } - ret @{id: p.get_id(), node: pat, span: ast_util::mk_sp(lo, hi)}; + ret @{id: p.get_id(), node: pat, span: mk_sp(lo, hi)}; } fn parse_local(p: parser, is_mutbl: bool, @@ -1472,7 +1468,7 @@ fn parse_local(p: parser, is_mutbl: bool, let pat = parse_pat(p); let mut ty = @{id: p.get_id(), node: ast::ty_infer, - span: ast_util::mk_sp(lo, lo)}; + span: mk_sp(lo, lo)}; if eat(p, token::COLON) { ty = parse_ty(p, false); } let init = if allow_init { parse_initializer(p) } else { none }; ret @spanned(lo, p.last_span.hi, @@ -1504,7 +1500,7 @@ fn parse_instance_var(p:parser, pr: ast::privacy) -> @ast::class_member { expect(p, token::COLON); let ty = parse_ty(p, false); ret @{node: ast::instance_var(name, ty, is_mutbl, p.get_id(), pr), - span: ast_util::mk_sp(lo, p.last_span.hi)}; + span: mk_sp(lo, p.last_span.hi)}; } fn parse_stmt(p: parser, first_item_attrs: [ast::attribute]) -> @ast::stmt { @@ -1739,7 +1735,7 @@ fn mk_item(p: parser, lo: uint, hi: uint, ident: ast::ident, node: ast::item_, attrs: attrs, id: p.get_id(), node: node, - span: ast_util::mk_sp(lo, hi)}; + span: mk_sp(lo, hi)}; } fn parse_item_fn(p: parser, purity: ast::purity, @@ -1775,7 +1771,7 @@ fn parse_method(p: parser, pr: ast::privacy) -> @ast::method { let (inner_attrs, body) = parse_inner_attrs_and_block(p, true); let attrs = attrs + inner_attrs; @{ident: ident, attrs: attrs, tps: tps, decl: decl, body: body, - id: p.get_id(), span: ast_util::mk_sp(lo, body.span.hi), + id: p.get_id(), span: mk_sp(lo, body.span.hi), self_id: p.get_id(), privacy: pr} } @@ -1802,7 +1798,7 @@ fn parse_item_impl(p: parser, attrs: [ast::attribute]) -> @ast::item { let ifce = if eat_word(p, "of") { let path = parse_path_and_ty_param_substs(p, false); if option::is_none(ident) { - ident = some(path.node.idents[vec::len(path.node.idents) - 1u]); + ident = some(vec::last(path.idents)); } some(wrap_path(p, path)) } else { none }; @@ -1836,7 +1832,7 @@ fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item { ident: arg_ident, id: p.get_id()}], output: @{id: p.get_id(), node: ast::ty_nil, - span: ast_util::mk_sp(lo, lo)}, + span: mk_sp(lo, lo)}, purity: ast::impure_fn, cf: ast::return_val, constraints: []}; @@ -1850,13 +1846,13 @@ fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item { fn ident_to_path_tys(p: parser, i: ast::ident, typarams: [ast::ty_param]) -> @ast::path { let s = p.last_span; - let p_: ast::path_ = {global: false, idents: [i], - types: vec::map(typarams, - {|tp| @{id: p.get_id(), - node: ast::ty_path(ident_to_path(s, tp.ident), - p.get_id()), - span: s}})}; - @spanned(s.lo, s.hi, p_) + @{span: s, global: false, idents: [i], + types: vec::map(typarams, {|tp| + @{id: p.get_id(), + node: ast::ty_path(ident_to_path(s, tp.ident), + p.get_id()), + span: s}}) + } } fn parse_iface_ref_list(p:parser) -> [ast::iface_ref] { @@ -1934,7 +1930,7 @@ fn parse_class_item(p:parser, class_name_with_tps:@ast::path) span: decl_.output.span} with decl_}; let body = parse_block(p); - ret ctor_decl(decl, body, ast_util::mk_sp(lo, p.last_span.hi)); + ret ctor_decl(decl, body, mk_sp(lo, p.last_span.hi)); } else if eat_word(p, "priv") { expect(p, token::LBRACE); @@ -2014,7 +2010,7 @@ fn parse_item_native_fn(p: parser, attrs: [ast::attribute], attrs: attrs, node: ast::native_item_fn(decl, t.tps), id: p.get_id(), - span: ast_util::mk_sp(lo, hi)}; + span: mk_sp(lo, hi)}; } fn parse_fn_purity(p: parser) -> ast::purity { @@ -2236,13 +2232,10 @@ fn parse_view_path(p: parser) -> @ast::view_path { let id = parse_ident(p); path += [id]; } - let mut hi = p.span.hi; - ret @spanned(lo, hi, - ast::view_path_simple(first_ident, - @spanned(lo, hi, - {global: false, idents: path, - types: []}), - p.get_id())); + let path = @{span: mk_sp(lo, p.span.hi), global: false, + idents: path, types: []}; + ret @spanned(lo, p.span.hi, + ast::view_path_simple(first_ident, path, p.get_id())); } token::MOD_SEP { @@ -2263,25 +2256,19 @@ fn parse_view_path(p: parser) -> @ast::view_path { parse_seq(token::LBRACE, token::RBRACE, seq_sep(token::COMMA), parse_path_list_ident, p).node; - let mut hi = p.span.hi; - ret @spanned(lo, hi, - ast::view_path_list(@spanned(lo, hi, - {global: false, - idents: path, - types: []}), idents, - p.get_id())); + let path = @{span: mk_sp(lo, p.span.hi), + global: false, idents: path, types: []}; + ret @spanned(lo, p.span.hi, + ast::view_path_list(path, idents, p.get_id())); } // foo::bar::* token::BINOP(token::STAR) { p.bump(); - let mut hi = p.span.hi; - ret @spanned(lo, hi, - ast::view_path_glob(@spanned(lo, hi, - {global: false, - idents: path, - types: []}), - p.get_id())); + let path = @{span: mk_sp(lo, p.span.hi), + global: false, idents: path, types: []}; + ret @spanned(lo, p.span.hi, + ast::view_path_glob(path, p.get_id())); } _ { break; } @@ -2290,14 +2277,11 @@ fn parse_view_path(p: parser) -> @ast::view_path { } _ { } } - let mut hi = p.span.hi; let last = path[vec::len(path) - 1u]; - ret @spanned(lo, hi, - ast::view_path_simple(last, @spanned(lo, hi, - {global: false, - idents: path, - types: []}), - p.get_id())); + let path = @{span: mk_sp(lo, p.span.hi), global: false, + idents: path, types: []}; + ret @spanned(lo, p.span.hi, + ast::view_path_simple(last, path, p.get_id())); } fn parse_view_paths(p: parser) -> [@ast::view_path] { diff --git a/src/librustsyntax/print/pprust.rs b/src/librustsyntax/print/pprust.rs index d0d21ccd6c4..b979caab2e2 100644 --- a/src/librustsyntax/print/pprust.rs +++ b/src/librustsyntax/print/pprust.rs @@ -1222,16 +1222,16 @@ fn print_for_decl(s: ps, loc: @ast::local, coll: @ast::expr) { fn print_path(s: ps, &&path: @ast::path, colons_before_params: bool) { maybe_print_comment(s, path.span.lo); - if path.node.global { word(s.s, "::"); } + if path.global { word(s.s, "::"); } let mut first = true; - for path.node.idents.each {|id| + for path.idents.each {|id| if first { first = false; } else { word(s.s, "::"); } word(s.s, id); } - if vec::len(path.node.types) > 0u { + if vec::len(path.types) > 0u { if colons_before_params { word(s.s, "::"); } word(s.s, "<"); - commasep(s, inconsistent, path.node.types, print_type); + commasep(s, inconsistent, path.types, print_type); word(s.s, ">"); } } @@ -1455,7 +1455,7 @@ fn print_meta_item(s: ps, &&item: @ast::meta_item) { fn print_view_path(s: ps, &&vp: @ast::view_path) { alt vp.node { ast::view_path_simple(ident, path, _) { - if path.node.idents[vec::len(path.node.idents)-1u] != ident { + if path.idents[vec::len(path.idents)-1u] != ident { word_space(s, ident); word_space(s, "="); } diff --git a/src/librustsyntax/visit.rs b/src/librustsyntax/visit.rs index e55d291aa53..71dd5383e9a 100644 --- a/src/librustsyntax/visit.rs +++ b/src/librustsyntax/visit.rs @@ -213,7 +213,7 @@ fn visit_constr(_operator: @path, _sp: span, _id: node_id, _e: E, } fn visit_path(p: @path, e: E, v: vt) { - for p.node.types.each {|tp| v.visit_ty(tp, e, v); } + for p.types.each {|tp| v.visit_ty(tp, e, v); } } fn visit_pat(p: @pat, e: E, v: vt) { diff --git a/src/rustc/front/test.rs b/src/rustc/front/test.rs index 11010dade08..270b2a8b7e3 100644 --- a/src/rustc/front/test.rs +++ b/src/rustc/front/test.rs @@ -206,6 +206,10 @@ fn nospan(t: T) -> ast::spanned { ret {node: t, span: dummy_sp()}; } +fn path_node(ids: [ast::ident]) -> @ast::path { + @{span: dummy_sp(), global: false, idents: ids, types: []} +} + fn mk_tests(cx: test_ctxt) -> @ast::item { let ret_ty = mk_test_desc_vec_ty(cx); @@ -248,10 +252,7 @@ fn mk_path(cx: test_ctxt, path: [ast::ident]) -> [ast::ident] { // The ast::ty of [std::test::test_desc] fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty { - let test_desc_ty_path = - @nospan({global: false, - idents: mk_path(cx, ["test", "test_desc"]), - types: []}); + let test_desc_ty_path = path_node(mk_path(cx, ["test", "test_desc"])); let test_desc_ty: ast::ty = {id: cx.sess.next_node_id(), @@ -294,7 +295,7 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr { let name_field: ast::field = nospan({mutbl: ast::m_imm, ident: "name", expr: @name_expr}); - let fn_path = @nospan({global: false, idents: path, types: []}); + let fn_path = path_node(path); let fn_expr: ast::expr = {id: cx.sess.next_node_id(), @@ -380,7 +381,7 @@ fn mk_test_wrapper(cx: test_ctxt, } fn mk_main(cx: test_ctxt) -> @ast::item { - let str_pt = @nospan({global: false, idents: ["str"], types: []}); + let str_pt = path_node(["str"]); let str_ty = @{id: cx.sess.next_node_id(), node: ast::ty_path(str_pt, cx.sess.next_node_id()), span: dummy_sp()}; @@ -426,8 +427,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item { fn mk_test_main_call(cx: test_ctxt) -> @ast::expr { // Get the args passed to main so we can pass the to test_main - let args_path = - @nospan({global: false, idents: ["args"], types: []}); + let args_path = path_node(["args"]); let args_path_expr_: ast::expr_ = ast::expr_path(args_path); @@ -435,8 +435,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr { {id: cx.sess.next_node_id(), node: args_path_expr_, span: dummy_sp()}; // Call __test::test to generate the vector of test_descs - let test_path = - @nospan({global: false, idents: ["tests"], types: []}); + let test_path = path_node(["tests"]); let test_path_expr_: ast::expr_ = ast::expr_path(test_path); @@ -449,10 +448,7 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr { {id: cx.sess.next_node_id(), node: test_call_expr_, span: dummy_sp()}; // Call std::test::test_main - let test_main_path = - @nospan({global: false, - idents: mk_path(cx, ["test", "test_main"]), - types: []}); + let test_main_path = path_node(mk_path(cx, ["test", "test_main"])); let test_main_path_expr_: ast::expr_ = ast::expr_path(test_main_path); diff --git a/src/rustc/metadata/tydecode.rs b/src/rustc/metadata/tydecode.rs index c9b69f4df14..0aaf79d3e8f 100644 --- a/src/rustc/metadata/tydecode.rs +++ b/src/rustc/metadata/tydecode.rs @@ -103,8 +103,8 @@ fn parse_path(st: @pstate) -> @ast::path { ':' { next(st); next(st); } c { if c == '(' { - ret @respan(ast_util::dummy_sp(), - {global: false, idents: idents, types: []}); + ret @{span: ast_util::dummy_sp(), + global: false, idents: idents, types: []}; } else { idents += [parse_ident_(st, is_last)]; } } } diff --git a/src/rustc/middle/infer.rs b/src/rustc/middle/infer.rs index 568fd830e40..6ad7f20674a 100644 --- a/src/rustc/middle/infer.rs +++ b/src/rustc/middle/infer.rs @@ -493,7 +493,7 @@ impl unify_methods for infer_ctxt { ast::carg_ident(p) { alt actual.node { ast::carg_ident(q) { - if p.node != q.node { ret err_res; } + if p.idents != q.idents { ret err_res; } } _ { ret err_res; } } diff --git a/src/rustc/middle/pat_util.rs b/src/rustc/middle/pat_util.rs index 4ecfd343ce9..bcbcee5f411 100644 --- a/src/rustc/middle/pat_util.rs +++ b/src/rustc/middle/pat_util.rs @@ -69,7 +69,4 @@ fn pat_binding_ids(dm: resolve::def_map, pat: @pat) -> [node_id] { ret found; } -fn path_to_ident(p: @path) -> ident { - assert (vec::is_not_empty(p.node.idents)); // should be a constraint on path - vec::last(p.node.idents) -} +fn path_to_ident(p: @path) -> ident { vec::last(p.idents) } diff --git a/src/rustc/middle/resolve.rs b/src/rustc/middle/resolve.rs index da125214cb6..fa9f8e1f63f 100644 --- a/src/rustc/middle/resolve.rs +++ b/src/rustc/middle/resolve.rs @@ -231,16 +231,16 @@ fn map_crate(e: @env, c: @ast::crate) { iter_effective_import_paths(*i) { |vp| alt vp.node { ast::view_path_simple(name, path, id) { - e.imports.insert(id, todo(name, @path.node.idents, vp.span, + e.imports.insert(id, todo(name, @path.idents, vp.span, sc)); } ast::view_path_glob(path, id) { - e.imports.insert(id, is_glob(@path.node.idents, sc, vp.span)); + e.imports.insert(id, is_glob(@path.idents, sc, vp.span)); } ast::view_path_list(mod_path, idents, _) { for idents.each {|ident| let t = todo(ident.node.name, - @(mod_path.node.idents + [ident.node.name]), + @(mod_path.idents + [ident.node.name]), ident.span, sc); e.imports.insert(ident.node.id, t); } @@ -293,7 +293,7 @@ fn map_crate(e: @env, c: @ast::crate) { iter_effective_import_paths(*vi) { |vp| alt vp.node { ast::view_path_glob(path, _) { - alt follow_import(*e, sc, path.node.idents, vp.span) { + alt follow_import(*e, sc, path.idents, vp.span) { some(imp) { let glob = {def: imp, path: vp}; alt list::head(sc) { @@ -433,8 +433,7 @@ fn resolve_names(e: @env, c: @ast::crate) { /* visit the iface paths... */ for ifaces.each {|p| maybe_insert(e, p.id, - lookup_path_strict(*e, sc, p.path.span, p.path.node, - ns_type))}; + lookup_path_strict(*e, sc, p.path.span, p.path, ns_type))}; } _ {} } @@ -445,8 +444,7 @@ fn resolve_names(e: @env, c: @ast::crate) { alt exp.node { ast::expr_path(p) { maybe_insert(e, exp.id, - lookup_path_strict(*e, sc, exp.span, p.node, - ns_val)); + lookup_path_strict(*e, sc, exp.span, p, ns_val)); } ast::expr_fn(_, _, _, cap_clause) { let rci = bind resolve_capture_item(e, sc, _); @@ -461,7 +459,7 @@ fn resolve_names(e: @env, c: @ast::crate) { alt t.node { ast::ty_path(p, id) { maybe_insert(e, id, - lookup_path_strict(*e, sc, t.span, p.node, ns_type)); + lookup_path_strict(*e, sc, t.span, p, ns_type)); } _ { } } @@ -483,13 +481,13 @@ fn resolve_names(e: @env, c: @ast::crate) { } fn walk_constr(e: @env, p: @ast::path, sp: span, id: node_id, sc: scopes, _v: vt) { - maybe_insert(e, id, lookup_path_strict(*e, sc, sp, p.node, ns_val)); + maybe_insert(e, id, lookup_path_strict(*e, sc, sp, p, ns_val)); } fn walk_pat(e: @env, pat: @ast::pat, sc: scopes, v: vt) { visit::visit_pat(pat, sc, v); alt pat.node { ast::pat_enum(p, _) { - alt lookup_path_strict(*e, sc, p.span, p.node, ns_val) { + alt lookup_path_strict(*e, sc, p.span, p, ns_val) { some(fnd@ast::def_variant(_,_)) { e.def_map.insert(pat.id, fnd); } @@ -709,7 +707,7 @@ fn follow_import(e: env, sc: scopes, path: [ident], sp: span) -> } fn resolve_constr(e: @env, c: @ast::constr, sc: scopes, _v: vt) { - alt lookup_path_strict(*e, sc, c.span, c.node.path.node, ns_val) { + alt lookup_path_strict(*e, sc, c.span, c.node.path, ns_val) { some(d@ast::def_fn(_,ast::pure_fn)) { e.def_map.insert(c.node.id, d); } @@ -892,7 +890,7 @@ fn mk_unresolved_msg(id: ident, kind: str) -> str { } // Lookup helpers -fn lookup_path_strict(e: env, sc: scopes, sp: span, pth: ast::path_, +fn lookup_path_strict(e: env, sc: scopes, sp: span, pth: @ast::path, ns: namespace) -> option { let n_idents = vec::len(pth.idents); let headns = if n_idents == 1u { ns } else { ns_module }; @@ -2069,8 +2067,8 @@ fn check_exports(e: @env) { check_export(e, ident, _mod, id, vi); } ast::view_path_list(path, ids, node_id) { - let id = if vec::len(path.node.idents) == 1u { - path.node.idents[0] + let id = if vec::len(path.idents) == 1u { + path.idents[0] } else { e.sess.span_fatal(vp.span, "bad export name-list") }; @@ -2137,12 +2135,12 @@ fn find_impls_in_view_item(e: env, vi: @ast::view_item, alt vp.node { ast::view_path_simple(name, pt, id) { let mut found = []; - if vec::len(pt.node.idents) == 1u { + if vec::len(pt.idents) == 1u { option::iter(sc) {|sc| list::iter(sc) {|level| if vec::len(found) == 0u { for vec::each(*level) {|imp| - if imp.ident == pt.node.idents[0] { + if imp.ident == pt.idents[0] { found += [@{ident: name with *imp}]; } } diff --git a/src/rustc/middle/tstate/auxiliary.rs b/src/rustc/middle/tstate/auxiliary.rs index fbfcaae8a47..fa7bbd6c6d7 100644 --- a/src/rustc/middle/tstate/auxiliary.rs +++ b/src/rustc/middle/tstate/auxiliary.rs @@ -594,7 +594,7 @@ fn expr_to_constr_arg(tcx: ty::ctxt, e: @expr) -> @constr_arg_use { some(def_local(nid, _)) | some(def_arg(nid, _)) | some(def_binding(nid)) | some(def_upvar(nid, _, _)) { ret @respan(p.span, - carg_ident({ident: p.node.idents[0], node: nid})); + carg_ident({ident: p.idents[0], node: nid})); } some(what) { tcx.sess.span_bug(e.span, diff --git a/src/rustc/middle/tstate/bitvectors.rs b/src/rustc/middle/tstate/bitvectors.rs index ee2a159371e..f1be864f48a 100644 --- a/src/rustc/middle/tstate/bitvectors.rs +++ b/src/rustc/middle/tstate/bitvectors.rs @@ -183,20 +183,13 @@ fn kill_poststate(fcx: fn_ctxt, id: node_id, c: tsconstr) -> bool { fn clear_in_poststate_expr(fcx: fn_ctxt, e: @expr, t: poststate) { alt e.node { expr_path(p) { - alt vec::last_opt(p.node.idents) { - some(i) { - alt local_node_id_to_def(fcx, e.id) { - some(def_local(nid, _)) { - clear_in_poststate_(bit_num(fcx, ninit(nid, i)), t); - } - some(_) {/* ignore args (for now...) */ } - _ { - fcx.ccx.tcx.sess.bug("clear_in_poststate_expr: \ - unbound var"); - } - } + alt local_node_id_to_def(fcx, e.id) { + some(def_local(nid, _)) { + clear_in_poststate_(bit_num(fcx, ninit(nid, vec::last(p.idents))), + t); } - _ { fcx.ccx.tcx.sess.bug("clear_in_poststate_expr"); } + some(_) {/* ignore args (for now...) */ } + _ { fcx.ccx.tcx.sess.bug("clear_in_poststate_expr: unbound var"); } } } _ {/* do nothing */ } diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index 9574d591846..35fa0bed980 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -224,7 +224,7 @@ fn instantiate_path(fcx: @fn_ctxt, sp: span, id: ast::node_id) { let ty_param_count = vec::len(*tpt.bounds); - let ty_substs_len = vec::len(pth.node.types); + let ty_substs_len = vec::len(pth.types); // For now, there is no way to explicitly specify the region bound. // This will have to change eventually. @@ -248,7 +248,7 @@ fn instantiate_path(fcx: @fn_ctxt, (sp, "not enough type parameters provided for this item"); fcx.next_ty_vars(ty_param_count) } else { - pth.node.types.map { |aty| fcx.to_ty(aty) } + pth.types.map { |aty| fcx.to_ty(aty) } }; let substs = {self_r: self_r, tps: tps}; @@ -593,7 +593,7 @@ fn ast_ty_to_ty( some(d) { d }}; alt a_def { ast::def_ty(did) | ast::def_class(did) { - instantiate(self, rscope, ast_ty.span, did, id, path.node.types) + instantiate(self, rscope, ast_ty.span, did, id, path.types) } ast::def_prim_ty(nty) { alt nty { @@ -605,7 +605,7 @@ fn ast_ty_to_ty( } } ast::def_ty_param(id, n) { - if vec::len(path.node.types) > 0u { + if vec::len(path.types) > 0u { tcx.sess.span_err(ast_ty.span, "provided type parameters \ to a type parameter"); } @@ -614,12 +614,12 @@ fn ast_ty_to_ty( ast::def_self(self_id) { alt check tcx.items.get(self_id) { ast_map::node_item(@{node: ast::item_iface(tps, _), _}, _) { - if vec::len(tps) != vec::len(path.node.types) { + if vec::len(tps) != vec::len(path.types) { tcx.sess.span_err(ast_ty.span, "incorrect number of \ type parameters to \ self type"); } - ty::mk_self(tcx, vec::map(path.node.types, {|ast_ty| + ty::mk_self(tcx, vec::map(path.types, {|ast_ty| ast_ty_to_ty(self, rscope, ast_ty) })) } @@ -3970,22 +3970,20 @@ fn check_constraints(fcx: @fn_ctxt, cs: [@ast::constr], args: [ast::arg]) { } ast::carg_ident(i) { if i < num_args { - let p: ast::path_ = - {global: false, - idents: [args[i].ident], - types: []}; + let p = @{span: a.span, global: false, + idents: [args[i].ident], types: []}; let arg_occ_node_id = fcx.ccx.tcx.sess.next_node_id(); fcx.ccx.tcx.def_map.insert (arg_occ_node_id, ast::def_arg(args[i].id, args[i].mode)); {id: arg_occ_node_id, - node: ast::expr_path(@respan(a.span, p)), + node: ast::expr_path(p), span: a.span} } else { - fcx.ccx.tcx.sess.span_bug(a.span, - "check_constraints:\ - carg_ident index out of bounds"); + fcx.ccx.tcx.sess.span_bug( + a.span, "check_constraints:\ + carg_ident index out of bounds"); } } }]; @@ -4181,7 +4179,7 @@ fn check_fn(ccx: @crate_ctxt, if !pat_util::pat_is_variant(fcx.ccx.tcx.def_map, p) { assign(p.id, none); #debug["Pattern binding %s is assigned to %s", - path.node.idents[0], + path.idents[0], fcx.locals.get(p.id).to_str()]; } _ {}