From 4bd14246227255843e420c3c691ec9a59cea1a9f Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 19 Jul 2013 07:38:55 +0200 Subject: Ast spanned refactoring, renaming: crate, local, blk, crate_num, crate_cfg. `crate => Crate` `local => Local` `blk => Block` `crate_num => CrateNum` `crate_cfg => CrateConfig` Also, Crate and Local are not wrapped in spanned anymore. --- src/libsyntax/ast.rs | 42 ++++++++++++-------------- src/libsyntax/ast_map.rs | 8 ++--- src/libsyntax/ast_util.rs | 10 +++---- src/libsyntax/ext/base.rs | 6 ++-- src/libsyntax/ext/build.rs | 58 ++++++++++++++++++------------------ src/libsyntax/ext/expand.rs | 12 ++++---- src/libsyntax/ext/quote.rs | 4 +-- src/libsyntax/ext/tt/macro_parser.rs | 4 +-- src/libsyntax/fold.rs | 46 ++++++++++++++-------------- src/libsyntax/parse/classify.rs | 2 +- src/libsyntax/parse/mod.rs | 36 +++++++++++----------- src/libsyntax/parse/parser.rs | 58 ++++++++++++++++++------------------ src/libsyntax/parse/token.rs | 2 +- src/libsyntax/print/pprust.rs | 40 ++++++++++++------------- src/libsyntax/util/parser_testing.rs | 2 +- src/libsyntax/visit.rs | 36 +++++++++++----------- 16 files changed, 181 insertions(+), 185 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f2974423a1a..0874163118a 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -113,17 +113,17 @@ pub struct Path { types: ~[Ty], } -pub type crate_num = int; +pub type CrateNum = int; pub type node_id = int; #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub struct def_id { - crate: crate_num, + crate: CrateNum, node: node_id, } -pub static local_crate: crate_num = 0; +pub static local_crate: CrateNum = 0; pub static crate_node_id: node_id = 0; // The AST represents all type param bounds as types. @@ -195,15 +195,14 @@ pub enum def { // The set of MetaItems that define the compilation environment of the crate, // used to drive conditional compilation -pub type crate_cfg = ~[@MetaItem]; - -pub type crate = spanned; +pub type CrateConfig = ~[@MetaItem]; #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct crate_ { +pub struct Crate { module: _mod, attrs: ~[Attribute], - config: crate_cfg, + config: CrateConfig, + span: span, } pub type MetaItem = spanned; @@ -240,10 +239,8 @@ impl Eq for MetaItem_ { } } -//pub type blk = spanned; - #[deriving(Clone, Eq, Encodable, Decodable,IterBytes)] -pub struct blk { +pub struct Block { view_items: ~[view_item], stmts: ~[@stmt], expr: Option<@expr>, @@ -385,22 +382,21 @@ pub enum stmt_ { // FIXME (pending discussion of #1697, #2178...): local should really be // a refinement on pat. #[deriving(Eq, Encodable, Decodable,IterBytes)] -pub struct local_ { +pub struct Local { is_mutbl: bool, ty: Ty, pat: @pat, init: Option<@expr>, id: node_id, + span: span, } -pub type local = spanned; - pub type decl = spanned; #[deriving(Eq, Encodable, Decodable,IterBytes)] pub enum decl_ { // a local (let) binding: - decl_local(@local), + decl_local(@Local), // an item binding: decl_item(@item), } @@ -409,7 +405,7 @@ pub enum decl_ { pub struct arm { pats: ~[@pat], guard: Option<@expr>, - body: blk, + body: Block, } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] @@ -464,21 +460,21 @@ pub enum expr_ { expr_unary(node_id, unop, @expr), expr_lit(@lit), expr_cast(@expr, Ty), - expr_if(@expr, blk, Option<@expr>), - expr_while(@expr, blk), + expr_if(@expr, Block, Option<@expr>), + expr_while(@expr, Block), /* Conditionless loop (can be exited with break, cont, or ret) Same semantics as while(true) { body }, but typestate knows that the (implicit) condition is always true. */ - expr_loop(blk, Option), + expr_loop(Block, Option), expr_match(@expr, ~[arm]), - expr_fn_block(fn_decl, blk), + expr_fn_block(fn_decl, Block), // Inner expr is always an expr_fn_block. We need the wrapping node to // easily type this (a function returning nil on the inside but bool on // the outside). expr_loop_body(@expr), // Like expr_loop_body but for 'do' blocks expr_do_body(@expr), - expr_block(blk), + expr_block(Block), expr_assign(@expr, @expr), expr_assign_op(node_id, binop, @expr, @expr), @@ -863,7 +859,7 @@ pub struct method { explicit_self: explicit_self, purity: purity, decl: fn_decl, - body: blk, + body: Block, id: node_id, span: span, self_id: node_id, @@ -1051,7 +1047,7 @@ pub struct item { #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum item_ { item_static(Ty, mutability, @expr), - item_fn(fn_decl, purity, AbiSet, Generics, blk), + item_fn(fn_decl, purity, AbiSet, Generics, Block), item_mod(_mod), item_foreign_mod(foreign_mod), item_ty(Ty, Generics), diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index aef201a0232..2981336466e 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -73,7 +73,7 @@ pub enum ast_node { node_stmt(@stmt), node_arg, node_local(ident), - node_block(blk), + node_block(Block), node_struct_ctor(@struct_def, @item, @path), node_callee_scope(@expr) } @@ -104,7 +104,7 @@ pub fn mk_ast_map_visitor() -> vt { }); } -pub fn map_crate(diag: @span_handler, c: &crate) -> map { +pub fn map_crate(diag: @span_handler, c: &Crate) -> map { let cx = @mut Ctx { map: @mut HashMap::new(), path: ~[], @@ -157,7 +157,7 @@ pub fn map_decoded_item(diag: @span_handler, pub fn map_fn( fk: &visit::fn_kind, decl: &fn_decl, - body: &blk, + body: &Block, sp: codemap::span, id: node_id, (cx,v): (@mut Ctx, @@ -169,7 +169,7 @@ pub fn map_fn( visit::visit_fn(fk, decl, body, sp, id, (cx, v)); } -pub fn map_block(b: &blk, (cx,v): (@mut Ctx, visit::vt<@mut Ctx>)) { +pub fn map_block(b: &Block, (cx,v): (@mut Ctx, visit::vt<@mut Ctx>)) { cx.map.insert(b.id, node_block(/* FIXME (#2543) */ (*b).clone())); visit::visit_block(b, (cx, v)); } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 15ac50b917c..37112a533c8 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -195,7 +195,7 @@ pub fn is_call_expr(e: @expr) -> bool { match e.node { expr_call(*) => true, _ => false } } -pub fn block_from_expr(e: @expr) -> blk { +pub fn block_from_expr(e: @expr) -> Block { let mut blk = default_block(~[], option::Some::<@expr>(e), e.id); blk.span = e.span; return blk; @@ -205,8 +205,8 @@ pub fn default_block( stmts1: ~[@stmt], expr1: Option<@expr>, id1: node_id -) -> blk { - ast::blk { +) -> Block { + ast::Block { view_items: ~[], stmts: stmts1, expr: expr1, @@ -443,7 +443,7 @@ pub fn id_visitor(vfn: @fn(node_id, T)) -> visit::vt { }, visit_local: |l, (t, vt)| { - vfn(l.node.id, t.clone()); + vfn(l.id, t.clone()); visit::visit_local(l, (t, vt)); }, visit_block: |b, (t, vt)| { @@ -570,7 +570,7 @@ pub trait EachViewItem { pub fn each_view_item(&self, f: @fn(&ast::view_item) -> bool) -> bool; } -impl EachViewItem for ast::crate { +impl EachViewItem for ast::Crate { fn each_view_item(&self, f: @fn(&ast::view_item) -> bool) -> bool { let broke = @mut false; let vtor: visit::vt<()> = visit::mk_simple_visitor(@visit::SimpleVisitor { diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 753d32fee5a..e831e32f23d 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -212,7 +212,7 @@ pub fn syntax_expander_table() -> SyntaxEnv { // -> expn_info of their expansion context stored into their span. pub struct ExtCtxt { parse_sess: @mut parse::ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, backtrace: @mut Option<@ExpnInfo>, // These two @mut's should really not be here, @@ -225,7 +225,7 @@ pub struct ExtCtxt { } impl ExtCtxt { - pub fn new(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg) + pub fn new(parse_sess: @mut parse::ParseSess, cfg: ast::CrateConfig) -> @ExtCtxt { @ExtCtxt { parse_sess: parse_sess, @@ -238,7 +238,7 @@ impl ExtCtxt { pub fn codemap(&self) -> @CodeMap { self.parse_sess.cm } pub fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess } - pub fn cfg(&self) -> ast::crate_cfg { self.cfg.clone() } + pub fn cfg(&self) -> ast::CrateConfig { self.cfg.clone() } pub fn call_site(&self) -> span { match *self.backtrace { Some(@ExpnInfo {call_site: cs, _}) => cs, diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index df5f3d8d895..3b32173dfb5 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -76,12 +76,12 @@ pub trait AstBuilder { fn stmt_let(&self, sp: span, mutbl: bool, ident: ast::ident, ex: @ast::expr) -> @ast::stmt; // blocks - fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@ast::expr>) -> ast::blk; - fn blk_expr(&self, expr: @ast::expr) -> ast::blk; + fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@ast::expr>) -> ast::Block; + fn blk_expr(&self, expr: @ast::expr) -> ast::Block; fn blk_all(&self, span: span, view_items: ~[ast::view_item], stmts: ~[@ast::stmt], - expr: Option<@ast::expr>) -> ast::blk; + expr: Option<@ast::expr>) -> ast::Block; // expressions fn expr(&self, span: span, node: ast::expr_) -> @ast::expr; @@ -105,7 +105,7 @@ pub trait AstBuilder { fn expr_method_call(&self, span: span, expr: @ast::expr, ident: ast::ident, args: ~[@ast::expr]) -> @ast::expr; - fn expr_blk(&self, b: ast::blk) -> @ast::expr; + fn expr_blk(&self, b: ast::Block) -> @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; @@ -147,11 +147,11 @@ pub trait AstBuilder { fn expr_if(&self, span: span, cond: @ast::expr, then: @ast::expr, els: Option<@ast::expr>) -> @ast::expr; - fn lambda_fn_decl(&self, span: span, fn_decl: ast::fn_decl, blk: ast::blk) -> @ast::expr; + fn lambda_fn_decl(&self, span: span, fn_decl: ast::fn_decl, blk: ast::Block) -> @ast::expr; - fn lambda(&self, span: span, ids: ~[ast::ident], blk: ast::blk) -> @ast::expr; - fn lambda0(&self, span: span, blk: ast::blk) -> @ast::expr; - fn lambda1(&self, span: span, blk: ast::blk, ident: ast::ident) -> @ast::expr; + fn lambda(&self, span: span, ids: ~[ast::ident], blk: ast::Block) -> @ast::expr; + fn lambda0(&self, span: span, blk: ast::Block) -> @ast::expr; + fn lambda1(&self, span: span, blk: ast::Block, ident: ast::ident) -> @ast::expr; fn lambda_expr(&self, span: span, ids: ~[ast::ident], blk: @ast::expr) -> @ast::expr; fn lambda_expr_0(&self, span: span, expr: @ast::expr) -> @ast::expr; @@ -175,13 +175,13 @@ pub trait AstBuilder { inputs: ~[ast::arg], output: ast::Ty, generics: Generics, - body: ast::blk) -> @ast::item; + body: ast::Block) -> @ast::item; fn item_fn(&self, span: span, name: ident, inputs: ~[ast::arg], output: ast::Ty, - body: ast::blk) -> @ast::item; + body: ast::Block) -> @ast::item; fn variant(&self, span: span, name: ident, tys: ~[ast::Ty]) -> ast::variant; fn item_enum_poly(&self, @@ -375,31 +375,31 @@ impl AstBuilder for @ExtCtxt { fn stmt_let(&self, sp: span, mutbl: bool, ident: ast::ident, ex: @ast::expr) -> @ast::stmt { let pat = self.pat_ident(sp, ident); - let local = @respan(sp, - ast::local_ { - is_mutbl: mutbl, - ty: self.ty_infer(sp), - pat: pat, - init: Some(ex), - id: self.next_id(), - }); + let local = @ast::Local { + is_mutbl: mutbl, + ty: self.ty_infer(sp), + pat: pat, + init: Some(ex), + id: self.next_id(), + span: sp, + }; let decl = respan(sp, ast::decl_local(local)); @respan(sp, ast::stmt_decl(@decl, self.next_id())) } - fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@expr>) -> ast::blk { + fn blk(&self, span: span, stmts: ~[@ast::stmt], expr: Option<@expr>) -> ast::Block { self.blk_all(span, ~[], stmts, expr) } - fn blk_expr(&self, expr: @ast::expr) -> ast::blk { + fn blk_expr(&self, expr: @ast::expr) -> ast::Block { self.blk_all(expr.span, ~[], ~[], Some(expr)) } fn blk_all(&self, span: span, view_items: ~[ast::view_item], stmts: ~[@ast::stmt], - expr: Option<@ast::expr>) -> ast::blk { - ast::blk { + expr: Option<@ast::expr>) -> ast::Block { + ast::Block { view_items: view_items, stmts: stmts, expr: expr, @@ -474,7 +474,7 @@ impl AstBuilder for @ExtCtxt { self.expr(span, ast::expr_method_call(self.next_id(), expr, ident, ~[], args, ast::NoSugar)) } - fn expr_blk(&self, b: ast::blk) -> @ast::expr { + fn expr_blk(&self, b: ast::Block) -> @ast::expr { self.expr(b.span, ast::expr_block(b)) } fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::field { @@ -595,23 +595,23 @@ impl AstBuilder for @ExtCtxt { self.expr(span, ast::expr_if(cond, self.blk_expr(then), els)) } - fn lambda_fn_decl(&self, span: span, fn_decl: ast::fn_decl, blk: ast::blk) -> @ast::expr { + fn lambda_fn_decl(&self, span: span, fn_decl: ast::fn_decl, blk: ast::Block) -> @ast::expr { self.expr(span, ast::expr_fn_block(fn_decl, blk)) } - fn lambda(&self, span: span, ids: ~[ast::ident], blk: ast::blk) -> @ast::expr { + fn lambda(&self, span: span, ids: ~[ast::ident], blk: ast::Block) -> @ast::expr { let fn_decl = self.fn_decl( ids.map(|id| self.arg(span, *id, self.ty_infer(span))), self.ty_infer(span)); self.expr(span, ast::expr_fn_block(fn_decl, blk)) } - fn lambda0(&self, _span: span, blk: ast::blk) -> @ast::expr { + fn lambda0(&self, _span: span, blk: ast::Block) -> @ast::expr { let ext_cx = *self; let blk_e = self.expr(blk.span, ast::expr_block(blk.clone())); quote_expr!(|| $blk_e ) } - fn lambda1(&self, _span: span, blk: ast::blk, ident: ast::ident) -> @ast::expr { + fn lambda1(&self, _span: span, blk: ast::Block, ident: ast::ident) -> @ast::expr { let ext_cx = *self; let blk_e = self.expr(blk.span, ast::expr_block(blk.clone())); quote_expr!(|$ident| $blk_e ) @@ -674,7 +674,7 @@ impl AstBuilder for @ExtCtxt { inputs: ~[ast::arg], output: ast::Ty, generics: Generics, - body: ast::blk) -> @ast::item { + body: ast::Block) -> @ast::item { self.item(span, name, ~[], @@ -690,7 +690,7 @@ impl AstBuilder for @ExtCtxt { name: ident, inputs: ~[ast::arg], output: ast::Ty, - body: ast::blk + body: ast::Block ) -> @ast::item { self.item_fn_poly( span, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index e78254f11f5..af05f726860 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ast::{blk, crate, expr_, expr_mac, mac_invoc_tt}; +use ast::{Block, Crate, expr_, expr_mac, mac_invoc_tt}; use ast::{item_mac, stmt_, stmt_mac, stmt_expr, stmt_semi}; use ast::{illegal_ctxt}; use ast; @@ -395,10 +395,10 @@ pub fn new_name_finder() -> @Visitor<@mut ~[ast::ident]> { pub fn expand_block(extsbox: @mut SyntaxEnv, _cx: @ExtCtxt, - blk: &blk, + blk: &Block, fld: @ast_fold, - orig: @fn(&blk, @ast_fold) -> blk) - -> blk { + orig: @fn(&Block, @ast_fold) -> Block) + -> Block { // see note below about treatment of exts table with_exts_frame!(extsbox,false,orig(blk,fld)) } @@ -691,7 +691,7 @@ pub fn std_macros() -> @str { // add a bunch of macros as though they were placed at the head of the // program (ick). This should run before cfg stripping. pub fn inject_std_macros(parse_sess: @mut parse::ParseSess, - cfg: ast::crate_cfg, c: &crate) -> @crate { + cfg: ast::CrateConfig, c: &Crate) -> @Crate { let sm = match parse_item_from_source_str(@"", std_macros(), cfg.clone(), @@ -718,7 +718,7 @@ pub fn inject_std_macros(parse_sess: @mut parse::ParseSess, } pub fn expand_crate(parse_sess: @mut parse::ParseSess, - cfg: ast::crate_cfg, c: &crate) -> @crate { + cfg: ast::CrateConfig, c: &Crate) -> @Crate { // adding *another* layer of indirection here so that the block // visitor can swap out one exts table for another for the duration // of the block. The cleaner alternative would be to thread the diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index d8ac2ede29e..1439f4cabab 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -110,7 +110,7 @@ pub mod rt { } } - impl ToSource for ast::blk { + impl ToSource for ast::Block { fn to_source(&self) -> @str { pprust::block_to_str(self, get_ident_interner()).to_managed() } @@ -238,7 +238,7 @@ pub mod rt { } } - impl ToTokens for ast::blk { + impl ToTokens for ast::Block { fn to_tokens(&self, cx: @ExtCtxt) -> ~[token_tree] { cx.parse_tts(self.to_source()) } diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 54ccd489171..9d9155ff0d5 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -223,7 +223,7 @@ pub enum parse_result { pub fn parse_or_else( sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, rdr: @reader, ms: ~[matcher] ) -> HashMap { @@ -236,7 +236,7 @@ pub fn parse_or_else( pub fn parse( sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, rdr: @reader, ms: &[matcher] ) -> parse_result { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 63cb3cf38f6..6af08d0a8d5 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -15,14 +15,14 @@ use parse::token; use opt_vec::OptVec; pub trait ast_fold { - fn fold_crate(@self, &crate) -> crate; + fn fold_crate(@self, &Crate) -> Crate; fn fold_view_item(@self, &view_item) -> view_item; fn fold_foreign_item(@self, @foreign_item) -> @foreign_item; fn fold_item(@self, @item) -> Option<@item>; fn fold_struct_field(@self, @struct_field) -> @struct_field; fn fold_item_underscore(@self, &item_) -> item_; fn fold_method(@self, @method) -> @method; - fn fold_block(@self, &blk) -> blk; + fn fold_block(@self, &Block) -> Block; fn fold_stmt(@self, &stmt) -> Option<@stmt>; fn fold_arm(@self, &arm) -> arm; fn fold_pat(@self, @pat) -> @pat; @@ -34,7 +34,7 @@ pub trait ast_fold { fn fold_variant(@self, &variant) -> variant; fn fold_ident(@self, ident) -> ident; fn fold_path(@self, &Path) -> Path; - fn fold_local(@self, @local) -> @local; + fn fold_local(@self, @Local) -> @Local; fn map_exprs(@self, @fn(@expr) -> @expr, &[@expr]) -> ~[@expr]; fn new_id(@self, node_id) -> node_id; fn new_span(@self, span) -> span; @@ -44,14 +44,14 @@ pub trait ast_fold { pub struct AstFoldFns { //unlike the others, item_ is non-trivial - fold_crate: @fn(&crate_, span, @ast_fold) -> (crate_, span), + fold_crate: @fn(&Crate, @ast_fold) -> Crate, fold_view_item: @fn(&view_item_, @ast_fold) -> view_item_, fold_foreign_item: @fn(@foreign_item, @ast_fold) -> @foreign_item, fold_item: @fn(@item, @ast_fold) -> Option<@item>, fold_struct_field: @fn(@struct_field, @ast_fold) -> @struct_field, fold_item_underscore: @fn(&item_, @ast_fold) -> item_, fold_method: @fn(@method, @ast_fold) -> @method, - fold_block: @fn(&blk, @ast_fold) -> blk, + fold_block: @fn(&Block, @ast_fold) -> Block, fold_stmt: @fn(&stmt_, span, @ast_fold) -> (Option, span), fold_arm: @fn(&arm, @ast_fold) -> arm, fold_pat: @fn(&pat_, span, @ast_fold) -> (pat_, span), @@ -63,7 +63,7 @@ pub struct AstFoldFns { fold_variant: @fn(&variant_, span, @ast_fold) -> (variant_, span), fold_ident: @fn(ident, @ast_fold) -> ident, fold_path: @fn(&Path, @ast_fold) -> Path, - fold_local: @fn(&local_, span, @ast_fold) -> (local_, span), + fold_local: @fn(@Local, @ast_fold) -> @Local, map_exprs: @fn(@fn(@expr) -> @expr, &[@expr]) -> ~[@expr], new_id: @fn(node_id) -> node_id, new_span: @fn(span) -> span @@ -196,14 +196,15 @@ pub fn fold_generics(generics: &Generics, fld: @ast_fold) -> Generics { lifetimes: fold_lifetimes(&generics.lifetimes, fld)} } -pub fn noop_fold_crate(c: &crate_, fld: @ast_fold) -> crate_ { +pub fn noop_fold_crate(c: &Crate, fld: @ast_fold) -> Crate { let fold_meta_item = |x| fold_meta_item_(x, fld); let fold_attribute = |x| fold_attribute_(x, fld); - crate_ { + Crate { module: fld.fold_mod(&c.module), attrs: c.attrs.map(|x| fold_attribute(*x)), config: c.config.map(|x| fold_meta_item(*x)), + span: fld.new_span(c.span), } } @@ -376,7 +377,7 @@ fn noop_fold_method(m: @method, fld: @ast_fold) -> @method { } -pub fn noop_fold_block(b: &blk, fld: @ast_fold) -> blk { +pub fn noop_fold_block(b: &Block, fld: @ast_fold) -> Block { let view_items = b.view_items.map(|x| fld.fold_view_item(x)); let mut stmts = ~[]; for b.stmts.iter().advance |stmt| { @@ -385,7 +386,7 @@ pub fn noop_fold_block(b: &blk, fld: @ast_fold) -> blk { Some(stmt) => stmts.push(stmt) } } - ast::blk { + ast::Block { view_items: view_items, stmts: stmts, expr: b.expr.map(|x| fld.fold_expr(*x)), @@ -771,13 +772,14 @@ fn noop_fold_path(p: &Path, fld: @ast_fold) -> Path { } } -fn noop_fold_local(l: &local_, fld: @ast_fold) -> local_ { - local_ { +fn noop_fold_local(l: @Local, fld: @ast_fold) -> @Local { + @Local { is_mutbl: l.is_mutbl, ty: fld.fold_ty(&l.ty), pat: fld.fold_pat(l.pat), init: l.init.map(|e| fld.fold_expr(*e)), id: fld.new_id(l.id), + span: fld.new_span(l.span), } } @@ -793,7 +795,7 @@ fn noop_span(sp: span) -> span { return sp; } pub fn default_ast_fold() -> ast_fold_fns { @AstFoldFns { - fold_crate: wrap(noop_fold_crate), + fold_crate: noop_fold_crate, fold_view_item: noop_fold_view_item, fold_foreign_item: noop_fold_foreign_item, fold_item: noop_fold_item, @@ -812,7 +814,7 @@ pub fn default_ast_fold() -> ast_fold_fns { fold_variant: wrap(noop_fold_variant), fold_ident: noop_fold_ident, fold_path: noop_fold_path, - fold_local: wrap(noop_fold_local), + fold_local: noop_fold_local, map_exprs: noop_map_exprs, new_id: noop_id, new_span: noop_span, @@ -821,9 +823,8 @@ pub fn default_ast_fold() -> ast_fold_fns { impl ast_fold for AstFoldFns { /* naturally, a macro to write these would be nice */ - fn fold_crate(@self, c: &crate) -> crate { - let (n, s) = (self.fold_crate)(&c.node, c.span, self as @ast_fold); - spanned { node: n, span: (self.new_span)(s) } + fn fold_crate(@self, c: &Crate) -> Crate { + (self.fold_crate)(c, self as @ast_fold) } fn fold_view_item(@self, x: &view_item) -> view_item { ast::view_item { @@ -856,7 +857,7 @@ impl ast_fold for AstFoldFns { fn fold_method(@self, x: @method) -> @method { (self.fold_method)(x, self as @ast_fold) } - fn fold_block(@self, x: &blk) -> blk { + fn fold_block(@self, x: &Block) -> Block { (self.fold_block)(x, self as @ast_fold) } fn fold_stmt(@self, x: &stmt) -> Option<@stmt> { @@ -916,9 +917,8 @@ impl ast_fold for AstFoldFns { 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); - @spanned { node: n, span: (self.new_span)(s) } + fn fold_local(@self, x: @Local) -> @Local { + (self.fold_local)(x, self as @ast_fold) } fn map_exprs(@self, f: @fn(@expr) -> @expr, @@ -969,8 +969,8 @@ mod test { } // this version doesn't care about getting comments or docstrings in. - fn fake_print_crate(s: @pprust::ps, crate: &ast::crate) { - pprust::print_mod(s, &crate.node.module, crate.node.attrs); + fn fake_print_crate(s: @pprust::ps, crate: &ast::Crate) { + pprust::print_mod(s, &crate.module, crate.attrs); } // change every identifier to "zz" diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 44497f72003..e31b0ccff80 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -39,7 +39,7 @@ pub fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool { pub fn expr_is_simple_block(e: @ast::expr) -> bool { match e.node { ast::expr_block( - ast::blk { rules: ast::default_blk, _ } + ast::Block { rules: ast::default_blk, _ } ) => true, _ => false } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index c7a65c80de1..bd57f123cc5 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -76,9 +76,9 @@ pub fn new_parse_sess_special_handler(sh: @span_handler, pub fn parse_crate_from_file( input: &Path, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, sess: @mut ParseSess -) -> @ast::crate { +) -> @ast::Crate { new_parser_from_file(sess, /*bad*/ cfg.clone(), input).parse_crate_mod() // why is there no p.abort_if_errors here? } @@ -86,9 +86,9 @@ pub fn parse_crate_from_file( pub fn parse_crate_from_source_str( name: @str, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, sess: @mut ParseSess -) -> @ast::crate { +) -> @ast::Crate { let p = new_parser_from_source_str(sess, /*bad*/ cfg.clone(), name, @@ -99,7 +99,7 @@ pub fn parse_crate_from_source_str( pub fn parse_expr_from_source_str( name: @str, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, sess: @mut ParseSess ) -> @ast::expr { let p = new_parser_from_source_str( @@ -114,7 +114,7 @@ pub fn parse_expr_from_source_str( pub fn parse_item_from_source_str( name: @str, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, attrs: ~[ast::Attribute], sess: @mut ParseSess ) -> Option<@ast::item> { @@ -130,7 +130,7 @@ pub fn parse_item_from_source_str( pub fn parse_meta_from_source_str( name: @str, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, sess: @mut ParseSess ) -> @ast::MetaItem { let p = new_parser_from_source_str( @@ -145,7 +145,7 @@ pub fn parse_meta_from_source_str( pub fn parse_stmt_from_source_str( name: @str, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, attrs: ~[ast::Attribute], sess: @mut ParseSess ) -> @ast::stmt { @@ -161,7 +161,7 @@ pub fn parse_stmt_from_source_str( pub fn parse_tts_from_source_str( name: @str, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, sess: @mut ParseSess ) -> ~[ast::token_tree] { let p = new_parser_from_source_str( @@ -184,7 +184,7 @@ pub fn parse_from_source_str( f: &fn(&Parser) -> T, name: @str, ss: codemap::FileSubstr, source: @str, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, sess: @mut ParseSess ) -> T { let p = new_parser_from_source_substr( @@ -212,7 +212,7 @@ pub fn next_node_id(sess: @mut ParseSess) -> node_id { // Create a new parser from a source string pub fn new_parser_from_source_str(sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, name: @str, source: @str) -> Parser { @@ -222,7 +222,7 @@ pub fn new_parser_from_source_str(sess: @mut ParseSess, // Create a new parser from a source string where the origin // is specified as a substring of another file. pub fn new_parser_from_source_substr(sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, name: @str, ss: codemap::FileSubstr, source: @str) @@ -234,7 +234,7 @@ pub fn new_parser_from_source_substr(sess: @mut ParseSess, /// if the file doesn't exist pub fn new_parser_from_file( sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, path: &Path ) -> Parser { filemap_to_parser(sess,file_to_filemap(sess,path,None),cfg) @@ -245,7 +245,7 @@ pub fn new_parser_from_file( /// On an error, use the given span as the source of the problem. pub fn new_sub_parser_from_file( sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, path: &Path, sp: span ) -> Parser { @@ -255,14 +255,14 @@ pub fn new_sub_parser_from_file( /// Given a filemap and config, return a parser pub fn filemap_to_parser(sess: @mut ParseSess, filemap: @FileMap, - cfg: ast::crate_cfg) -> Parser { + cfg: ast::CrateConfig) -> Parser { tts_to_parser(sess,filemap_to_tts(sess,filemap),cfg) } // must preserve old name for now, because quote! from the *existing* // compiler expands into it pub fn new_parser_from_tts(sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, tts: ~[ast::token_tree]) -> Parser { tts_to_parser(sess,tts,cfg) } @@ -313,7 +313,7 @@ pub fn filemap_to_tts(sess: @mut ParseSess, filemap: @FileMap) // given tts and cfg, produce a parser pub fn tts_to_parser(sess: @mut ParseSess, tts: ~[ast::token_tree], - cfg: ast::crate_cfg) -> Parser { + cfg: ast::CrateConfig) -> Parser { let trdr = lexer::new_tt_reader(sess.span_diagnostic, None, tts); Parser(sess, cfg, trdr as @reader) } @@ -551,7 +551,7 @@ mod test { lifetimes: opt_vec::Empty, ty_params: opt_vec::Empty, }, - ast::blk { + ast::Block { view_items: ~[], stmts: ~[@spanned{ node: ast::stmt_semi(@ast::expr{ diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b2a1a8a73bd..2e8e69561e8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -16,9 +16,9 @@ use ast::{TyBareFn, TyClosure}; use ast::{RegionTyParamBound, TraitTyParamBound}; use ast::{provided, public, purity}; use ast::{_mod, add, arg, arm, Attribute, bind_by_ref, bind_infer}; -use ast::{bitand, bitor, bitxor, blk}; +use ast::{bitand, bitor, bitxor, Block}; use ast::{blk_check_mode, box}; -use ast::{crate, crate_cfg, decl, decl_item}; +use ast::{Crate, CrateConfig, decl, decl_item}; use ast::{decl_local, default_blk, deref, div, enum_def, explicit_self}; use ast::{expr, expr_, expr_addr_of, expr_match, expr_again}; use ast::{expr_assign, expr_assign_op, expr_binary, expr_block}; @@ -36,7 +36,7 @@ use ast::{ident, impure_fn, inherited, item, item_, item_static}; use ast::{item_enum, item_fn, item_foreign_mod, item_impl}; use ast::{item_mac, item_mod, item_struct, item_trait, item_ty, lit, lit_}; use ast::{lit_bool, lit_float, lit_float_unsuffixed, lit_int}; -use ast::{lit_int_unsuffixed, lit_nil, lit_str, lit_uint, local, m_const}; +use ast::{lit_int_unsuffixed, lit_nil, lit_str, lit_uint, Local, m_const}; use ast::{m_imm, m_mutbl, mac_, mac_invoc_tt, matcher, match_nonterminal}; use ast::{match_seq, match_tok, method, mt, mul, mutability}; use ast::{named_field, neg, node_id, noreturn, not, pat, pat_box, pat_enum}; @@ -261,7 +261,7 @@ struct ParsedItemsAndViewItems { /* ident is handled by common.rs */ pub fn Parser(sess: @mut ParseSess, - cfg: ast::crate_cfg, + cfg: ast::CrateConfig, rdr: @reader) -> Parser { let tok0 = rdr.next_token(); @@ -299,7 +299,7 @@ pub fn Parser(sess: @mut ParseSess, // ooh, nasty mutable fields everywhere.... pub struct Parser { sess: @mut ParseSess, - cfg: crate_cfg, + cfg: CrateConfig, // the current token: token: @mut token::Token, // the span of the current token: @@ -2294,7 +2294,7 @@ impl Parser { let lo = self.last_span.lo; let decl = parse_decl(); let body = parse_body(); - let fakeblock = ast::blk { + let fakeblock = ast::Block { view_items: ~[], stmts: ~[], expr: Some(body), @@ -2460,7 +2460,7 @@ impl Parser { self.eat(&token::COMMA); } - let blk = ast::blk { + let blk = ast::Block { view_items: ~[], stmts: ~[], expr: Some(expr), @@ -2916,7 +2916,7 @@ impl Parser { } // parse a local variable declaration - fn parse_local(&self, is_mutbl: bool) -> @local { + fn parse_local(&self, is_mutbl: bool) -> @Local { let lo = self.span.lo; let pat = self.parse_pat(); @@ -2931,17 +2931,14 @@ impl Parser { }; if self.eat(&token::COLON) { ty = self.parse_ty(false); } let init = self.parse_initializer(); - @spanned( - lo, - self.last_span.hi, - ast::local_ { - is_mutbl: is_mutbl, - ty: ty, - pat: pat, - init: init, - id: self.get_id(), - } - ) + @ast::Local { + is_mutbl: is_mutbl, + ty: ty, + pat: pat, + init: init, + id: self.get_id(), + span: mk_sp(lo, self.last_span.hi), + } } // parse a "let" stmt @@ -3077,7 +3074,7 @@ impl Parser { } // parse a block. No inner attrs are allowed. - pub fn parse_block(&self) -> blk { + pub fn parse_block(&self) -> Block { maybe_whole!(self, nt_block); let lo = self.span.lo; @@ -3091,7 +3088,7 @@ impl Parser { // parse a block. Inner attrs are allowed. fn parse_inner_attrs_and_block(&self) - -> (~[Attribute], blk) { + -> (~[Attribute], Block) { maybe_whole!(pair_empty self, nt_block); @@ -3109,13 +3106,13 @@ impl Parser { // I guess that also means "already parsed the 'impure'" if // necessary, and this should take a qualifier. // some blocks start with "#{"... - fn parse_block_tail(&self, lo: BytePos, s: blk_check_mode) -> blk { + fn parse_block_tail(&self, lo: BytePos, s: blk_check_mode) -> Block { self.parse_block_tail_(lo, s, ~[]) } // parse the rest of a block expression or function body fn parse_block_tail_(&self, lo: BytePos, s: blk_check_mode, - first_item_attrs: ~[Attribute]) -> blk { + first_item_attrs: ~[Attribute]) -> Block { let mut stmts = ~[]; let mut expr = None; @@ -3237,7 +3234,7 @@ impl Parser { let hi = self.span.hi; self.bump(); - ast::blk { + ast::Block { view_items: view_items, stmts: stmts, expr: expr, @@ -4946,7 +4943,7 @@ impl Parser { // Parses a source module as a crate. This is the main // entry point for the parser. - pub fn parse_crate_mod(&self) -> @crate { + pub fn parse_crate_mod(&self) -> @Crate { let lo = self.span.lo; // parse the crate's inner attrs, maybe (oops) one // of the attrs of an item: @@ -4954,10 +4951,13 @@ impl Parser { let first_item_outer_attrs = next; // parse the items inside the crate: let m = self.parse_mod_items(token::EOF, first_item_outer_attrs); - @spanned(lo, self.span.lo, - ast::crate_ { module: m, - attrs: inner, - config: self.cfg.clone() }) + + @ast::Crate { + module: m, + attrs: inner, + config: self.cfg.clone(), + span: mk_sp(lo, self.span.lo) + } } pub fn parse_str(&self) -> @str { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 322424b90fb..2d15d0ab7e8 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -99,7 +99,7 @@ pub enum Token { /// For interpolation during macro expansion. pub enum nonterminal { nt_item(@ast::item), - nt_block(ast::blk), + nt_block(ast::Block), nt_stmt(@ast::stmt), nt_pat( @ast::pat), nt_expr(@ast::expr), diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index f5e66bfd898..7918e503957 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -33,7 +33,7 @@ use std::uint; // The @ps is stored here to prevent recursive type. pub enum ann_node<'self> { - node_block(@ps, &'self ast::blk), + node_block(@ps, &'self ast::Block), node_item(@ps, &'self ast::item), node_expr(@ps, &'self ast::expr), node_pat(@ps, &'self ast::pat), @@ -106,7 +106,7 @@ pub static default_columns: uint = 78u; pub fn print_crate(cm: @CodeMap, intr: @ident_interner, span_diagnostic: @diagnostic::span_handler, - crate: &ast::crate, + crate: &ast::Crate, filename: @str, in: @io::Reader, out: @io::Writer, @@ -140,8 +140,8 @@ pub fn print_crate(cm: @CodeMap, print_crate_(s, crate); } -pub fn print_crate_(s: @ps, crate: &ast::crate) { - print_mod(s, &crate.node.module, crate.node.attrs); +pub fn print_crate_(s: @ps, crate: &ast::Crate) { + print_mod(s, &crate.module, crate.attrs); print_remaining_comments(s); eof(s.s); } @@ -200,7 +200,7 @@ pub fn fun_to_str(decl: &ast::fn_decl, purity: ast::purity, name: ast::ident, } } -pub fn block_to_str(blk: &ast::blk, intr: @ident_interner) -> ~str { +pub fn block_to_str(blk: &ast::Block, intr: @ident_interner) -> ~str { do io::with_str_writer |wr| { let s = rust_printer(wr, intr); // containing cbox, will be closed by print-block at } @@ -910,22 +910,22 @@ pub fn print_stmt(s: @ps, st: &ast::stmt) { maybe_print_trailing_comment(s, st.span, None); } -pub fn print_block(s: @ps, blk: &ast::blk) { +pub fn print_block(s: @ps, blk: &ast::Block) { print_possibly_embedded_block(s, blk, block_normal, indent_unit); } -pub fn print_block_unclosed(s: @ps, blk: &ast::blk) { +pub fn print_block_unclosed(s: @ps, blk: &ast::Block) { print_possibly_embedded_block_(s, blk, block_normal, indent_unit, &[], false); } -pub fn print_block_unclosed_indent(s: @ps, blk: &ast::blk, indented: uint) { +pub fn print_block_unclosed_indent(s: @ps, blk: &ast::Block, indented: uint) { print_possibly_embedded_block_(s, blk, block_normal, indented, &[], false); } pub fn print_block_with_attrs(s: @ps, - blk: &ast::blk, + blk: &ast::Block, attrs: &[ast::Attribute]) { print_possibly_embedded_block_(s, blk, block_normal, indent_unit, attrs, true); @@ -934,7 +934,7 @@ pub fn print_block_with_attrs(s: @ps, pub enum embed_type { block_block_fn, block_normal, } pub fn print_possibly_embedded_block(s: @ps, - blk: &ast::blk, + blk: &ast::Block, embedded: embed_type, indented: uint) { print_possibly_embedded_block_( @@ -942,7 +942,7 @@ pub fn print_possibly_embedded_block(s: @ps, } pub fn print_possibly_embedded_block_(s: @ps, - blk: &ast::blk, + blk: &ast::Block, embedded: embed_type, indented: uint, attrs: &[ast::Attribute], @@ -977,7 +977,7 @@ pub fn print_possibly_embedded_block_(s: @ps, (s.ann.post)(ann_node); } -pub fn print_if(s: @ps, test: &ast::expr, blk: &ast::blk, +pub fn print_if(s: @ps, test: &ast::expr, blk: &ast::Block, elseopt: Option<@ast::expr>, chk: bool) { head(s, "if"); if chk { word_nbsp(s, "check"); } @@ -1447,11 +1447,11 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { end(s); } -pub fn print_local_decl(s: @ps, loc: &ast::local) { - print_pat(s, loc.node.pat); - match loc.node.ty.node { +pub fn print_local_decl(s: @ps, loc: &ast::Local) { + print_pat(s, loc.pat); + match loc.ty.node { ast::ty_infer => (), - _ => { word_space(s, ":"); print_type(s, &loc.node.ty); } + _ => { word_space(s, ":"); print_type(s, &loc.ty); } } } @@ -1463,15 +1463,15 @@ pub fn print_decl(s: @ps, decl: &ast::decl) { ibox(s, indent_unit); word_nbsp(s, "let"); - if loc.node.is_mutbl { + if loc.is_mutbl { word_nbsp(s, "mut"); } - fn print_local(s: @ps, loc: &ast::local) { + fn print_local(s: @ps, loc: &ast::Local) { ibox(s, indent_unit); print_local_decl(s, loc); end(s); - match loc.node.init { + match loc.init { Some(init) => { nbsp(s); word_space(s, "="); @@ -1492,7 +1492,7 @@ pub fn print_ident(s: @ps, ident: ast::ident) { word(s.s, ident_to_str(&ident)); } -pub fn print_for_decl(s: @ps, loc: &ast::local, coll: &ast::expr) { +pub fn print_for_decl(s: @ps, loc: &ast::Local, coll: &ast::expr) { print_local_decl(s, loc); space(s.s); word_space(s, "in"); diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs index 4340d6bb6a2..de97396e453 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -33,7 +33,7 @@ pub fn string_to_parser(source_str: @str) -> Parser { p } -pub fn string_to_crate (source_str : @str) -> @ast::crate { +pub fn string_to_crate (source_str : @str) -> @ast::Crate { string_to_parser(source_str).parse_crate_mod() } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index f57dcb1588e..ce707979c06 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -75,8 +75,8 @@ pub struct Visitor { visit_view_item: @fn(&view_item, (E, vt)), visit_foreign_item: @fn(@foreign_item, (E, vt)), visit_item: @fn(@item, (E, vt)), - visit_local: @fn(@local, (E, vt)), - visit_block: @fn(&blk, (E, vt)), + visit_local: @fn(@Local, (E, vt)), + visit_block: @fn(&Block, (E, vt)), visit_stmt: @fn(@stmt, (E, vt)), visit_arm: @fn(&arm, (E, vt)), visit_pat: @fn(@pat, (E, vt)), @@ -85,7 +85,7 @@ pub struct Visitor { visit_expr_post: @fn(@expr, (E, vt)), visit_ty: @fn(&Ty, (E, vt)), visit_generics: @fn(&Generics, (E, vt)), - visit_fn: @fn(&fn_kind, &fn_decl, &blk, span, node_id, (E, vt)), + visit_fn: @fn(&fn_kind, &fn_decl, &Block, span, node_id, (E, vt)), visit_ty_method: @fn(&ty_method, (E, vt)), visit_trait_method: @fn(&trait_method, (E, vt)), visit_struct_def: @fn(@struct_def, ident, &Generics, node_id, (E, vt)), @@ -118,8 +118,8 @@ pub fn default_visitor() -> visitor { }; } -pub fn visit_crate(c: &crate, (e, v): (E, vt)) { - (v.visit_mod)(&c.node.module, c.span, crate_node_id, (e, v)); +pub fn visit_crate(c: &Crate, (e, v): (E, vt)) { + (v.visit_mod)(&c.module, c.span, crate_node_id, (e, v)); } pub fn visit_mod(m: &_mod, @@ -136,10 +136,10 @@ pub fn visit_mod(m: &_mod, pub fn visit_view_item(_vi: &view_item, (_e, _v): (E, vt)) { } -pub fn visit_local(loc: &local, (e, v): (E, vt)) { - (v.visit_pat)(loc.node.pat, (e.clone(), v)); - (v.visit_ty)(&loc.node.ty, (e.clone(), v)); - match loc.node.init { +pub fn visit_local(loc: &Local, (e, v): (E, vt)) { + (v.visit_pat)(loc.pat, (e.clone(), v)); + (v.visit_ty)(&loc.ty, (e.clone(), v)); + match loc.init { None => (), Some(ex) => (v.visit_expr)(ex, (e, v)) } @@ -386,7 +386,7 @@ pub fn visit_method_helper(m: &method, (e, v): (E, vt)) { (e, v)); } -pub fn visit_fn(fk: &fn_kind, decl: &fn_decl, body: &blk, _sp: span, +pub fn visit_fn(fk: &fn_kind, decl: &fn_decl, body: &Block, _sp: span, _id: node_id, (e, v): (E, vt)) { visit_fn_decl(decl, (e.clone(), v)); let generics = generics_of_fn(fk); @@ -425,7 +425,7 @@ pub fn visit_struct_field(sf: &struct_field, (e, v): (E, vt)) { (v.visit_ty)(&sf.node.ty, (e, v)); } -pub fn visit_block(b: &blk, (e, v): (E, vt)) { +pub fn visit_block(b: &Block, (e, v): (E, vt)) { for b.view_items.iter().advance |vi| { (v.visit_view_item)(vi, (e.clone(), v)); } @@ -583,8 +583,8 @@ pub struct SimpleVisitor { visit_view_item: @fn(&view_item), visit_foreign_item: @fn(@foreign_item), visit_item: @fn(@item), - visit_local: @fn(@local), - visit_block: @fn(&blk), + visit_local: @fn(@Local), + visit_block: @fn(&Block), visit_stmt: @fn(@stmt), visit_arm: @fn(&arm), visit_pat: @fn(@pat), @@ -593,7 +593,7 @@ pub struct SimpleVisitor { visit_expr_post: @fn(@expr), visit_ty: @fn(&Ty), visit_generics: @fn(&Generics), - visit_fn: @fn(&fn_kind, &fn_decl, &blk, span, node_id), + visit_fn: @fn(&fn_kind, &fn_decl, &Block, span, node_id), visit_ty_method: @fn(&ty_method), visit_trait_method: @fn(&trait_method), visit_struct_def: @fn(@struct_def, ident, &Generics, node_id), @@ -653,11 +653,11 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> { f(i); visit_item(i, (e, v)); } - fn v_local(f: @fn(@local), l: @local, (e, v): ((), vt<()>)) { + fn v_local(f: @fn(@Local), l: @Local, (e, v): ((), vt<()>)) { f(l); visit_local(l, (e, v)); } - fn v_block(f: @fn(&ast::blk), bl: &ast::blk, (e, v): ((), vt<()>)) { + fn v_block(f: @fn(&ast::Block), bl: &ast::Block, (e, v): ((), vt<()>)) { f(bl); visit_block(bl, (e, v)); } @@ -718,10 +718,10 @@ pub fn mk_simple_visitor(v: simple_visitor) -> vt<()> { visit_generics(ps, (e, v)); } fn v_fn( - f: @fn(&fn_kind, &fn_decl, &blk, span, node_id), + f: @fn(&fn_kind, &fn_decl, &Block, span, node_id), fk: &fn_kind, decl: &fn_decl, - body: &blk, + body: &Block, sp: span, id: node_id, (e, v): ((), vt<()>) -- cgit 1.4.1-3-g733a5 From 5aee3e01a02e0b31ad225e70899a671937ab65ee Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Fri, 19 Jul 2013 16:24:22 +0200 Subject: De-spanned and renamed ast::field (now ast::Field) --- src/librustc/middle/cfg/construct.rs | 2 +- src/librustc/middle/const_eval.rs | 2 +- src/librustc/middle/dataflow.rs | 2 +- src/librustc/middle/liveness.rs | 2 +- src/librustc/middle/moves.rs | 4 ++-- src/librustc/middle/privacy.rs | 17 +++++------------ src/librustc/middle/trans/consts.rs | 4 ++-- src/librustc/middle/trans/expr.rs | 6 +++--- src/librustc/middle/typeck/check/mod.rs | 16 ++++++++-------- src/librustc/util/common.rs | 6 +++--- src/libsyntax/ast.rs | 7 +++---- src/libsyntax/ext/build.rs | 14 +++++++------- src/libsyntax/fold.rs | 10 ++++------ src/libsyntax/parse/parser.rs | 11 ++++++----- src/libsyntax/print/pprust.rs | 8 ++++---- src/libsyntax/visit.rs | 2 +- 16 files changed, 52 insertions(+), 61 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index e250a223157..aee8ae32178 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -374,7 +374,7 @@ impl CFGBuilder { ast::expr_struct(_, ref fields, base) => { let base_exit = self.opt_expr(base, pred); let field_exprs: ~[@ast::expr] = - fields.iter().transform(|f| f.node.expr).collect(); + fields.iter().transform(|f| f.expr).collect(); self.straightline(expr, base_exit, field_exprs) } diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 01350869fc1..59dbc7251da 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -117,7 +117,7 @@ pub fn classify(e: &expr, ast::expr_struct(_, ref fs, None) => { let cs = do fs.iter().transform |f| { - classify(f.node.expr, tcx) + classify(f.expr, tcx) }; join_all(cs) } diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index 53622b667ff..2cdae04478c 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -705,7 +705,7 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> { ast::expr_struct(_, ref fields, with_expr) => { for fields.iter().advance |field| { - self.walk_expr(field.node.expr, in_out, loop_scopes); + self.walk_expr(field.expr, in_out, loop_scopes); } self.walk_opt_expr(with_expr, in_out, loop_scopes); } diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 20497755e17..f9b42d593c2 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -1161,7 +1161,7 @@ impl Liveness { expr_struct(_, ref fields, with_expr) => { let succ = self.propagate_through_opt_expr(with_expr, succ); do fields.rev_iter().fold(succ) |succ, field| { - self.propagate_through_expr(field.node.expr, succ) + self.propagate_through_expr(field.expr, succ) } } diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index 2e2178df66e..d8ce0a96636 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -394,7 +394,7 @@ impl VisitContext { expr_struct(_, ref fields, opt_with) => { for fields.iter().advance |field| { - self.consume_expr(field.node.expr, visitor); + self.consume_expr(field.expr, visitor); } for opt_with.iter().advance |with_expr| { @@ -417,7 +417,7 @@ impl VisitContext { // specified and (2) have a type that // moves-by-default: let consume_with = with_fields.iter().any(|tf| { - !fields.iter().any(|f| f.node.ident == tf.ident) && + !fields.iter().any(|f| f.ident == tf.ident) && ty::type_moves_by_default(self.tcx, tf.mt.ty) }); diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 0b747caea81..1ea32b3f404 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -413,9 +413,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt, Some(ref entry) => { debug!("(privacy checking) checking \ impl method"); - check_method(expr.span, - &entry.origin, - ident); + check_method(expr.span, &entry.origin, ident); } } } @@ -433,8 +431,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt, for (*fields).iter().advance |field| { debug!("(privacy checking) checking \ field in struct literal"); - check_field(expr.span, id, - field.node.ident); + check_field(expr.span, id, field.ident); } } } @@ -448,8 +445,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt, checking field in \ struct variant \ literal"); - check_field(expr.span, variant_id, - field.node.ident); + check_field(expr.span, variant_id, field.ident); } } _ => { @@ -499,8 +495,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt, for fields.iter().advance |field| { debug!("(privacy checking) checking \ struct pattern"); - check_field(pattern.span, id, - field.ident); + check_field(pattern.span, id, field.ident); } } } @@ -513,9 +508,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt, debug!("(privacy checking) \ checking field in \ struct variant pattern"); - check_field(pattern.span, - variant_id, - field.ident); + check_field(pattern.span, variant_id, field.ident); } } _ => { diff --git a/src/librustc/middle/trans/consts.rs b/src/librustc/middle/trans/consts.rs index 69c8331bc9f..9246ca1f641 100644 --- a/src/librustc/middle/trans/consts.rs +++ b/src/librustc/middle/trans/consts.rs @@ -488,8 +488,8 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::expr) -> ValueRef { do expr::with_field_tys(tcx, ety, Some(e.id)) |discr, field_tys| { let cs = field_tys.map(|field_ty| { - match fs.iter().find_(|f| field_ty.ident == f.node.ident) { - Some(f) => const_expr(cx, (*f).node.expr), + match fs.iter().find_(|f| field_ty.ident == f.ident) { + Some(f) => const_expr(cx, (*f).expr), None => { cx.tcx.sess.span_bug(e.span, "missing struct field"); } diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index adfc0b58485..d9fdf8d52c7 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -1124,7 +1124,7 @@ pub fn with_field_tys(tcx: ty::ctxt, } fn trans_rec_or_struct(bcx: block, - fields: &[ast::field], + fields: &[ast::Field], base: Option<@ast::expr>, expr_span: codemap::span, id: ast::node_id, @@ -1139,11 +1139,11 @@ fn trans_rec_or_struct(bcx: block, let mut need_base = vec::from_elem(field_tys.len(), true); let numbered_fields = do fields.map |field| { - let opt_pos = field_tys.iter().position(|field_ty| field_ty.ident == field.node.ident); + let opt_pos = field_tys.iter().position(|field_ty| field_ty.ident == field.ident); match opt_pos { Some(i) => { need_base[i] = false; - (i, field.node.expr) + (i, field.expr) } None => { tcx.sess.span_bug(field.span, diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index d4066767ab8..c04e1c2515c 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1872,7 +1872,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, node_id: ast::node_id, substitutions: ty::substs, field_types: &[ty::field_ty], - ast_fields: &[ast::field], + ast_fields: &[ast::Field], check_completeness: bool) { let tcx = fcx.ccx.tcx; @@ -1888,21 +1888,21 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, for ast_fields.iter().advance |field| { let mut expected_field_type = ty::mk_err(); - let pair = class_field_map.find(&field.node.ident). + let pair = class_field_map.find(&field.ident). map_consume(|x| *x); match pair { None => { tcx.sess.span_err( field.span, fmt!("structure has no field named `%s`", - tcx.sess.str_of(field.node.ident))); + tcx.sess.str_of(field.ident))); error_happened = true; } Some((_, true)) => { tcx.sess.span_err( field.span, fmt!("field `%s` specified more than once", - tcx.sess.str_of(field.node.ident))); + tcx.sess.str_of(field.ident))); error_happened = true; } Some((field_id, false)) => { @@ -1910,7 +1910,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, ty::lookup_field_type( tcx, class_id, field_id, &substitutions); class_field_map.insert( - field.node.ident, (field_id, true)); + field.ident, (field_id, true)); fields_found += 1; } } @@ -1918,7 +1918,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, // an error, so we can continue typechecking check_expr_coercable_to_type( fcx, - field.node.expr, + field.expr, expected_field_type); } @@ -1961,7 +1961,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, id: ast::node_id, span: codemap::span, class_id: ast::def_id, - fields: &[ast::field], + fields: &[ast::Field], base_expr: Option<@ast::expr>) { let tcx = fcx.ccx.tcx; @@ -2051,7 +2051,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, span: codemap::span, enum_id: ast::def_id, variant_id: ast::def_id, - fields: &[ast::field]) { + fields: &[ast::Field]) { let tcx = fcx.ccx.tcx; // Look up the number of type parameters and the raw type, and diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs index d15e47e61b5..733e8093a9d 100644 --- a/src/librustc/util/common.rs +++ b/src/librustc/util/common.rs @@ -54,10 +54,10 @@ pub fn indenter() -> _indenter { _indenter(()) } -pub fn field_expr(f: ast::field) -> @ast::expr { return f.node.expr; } +pub fn field_expr(f: ast::Field) -> @ast::expr { return f.expr; } -pub fn field_exprs(fields: ~[ast::field]) -> ~[@ast::expr] { - fields.map(|f| f.node.expr) +pub fn field_exprs(fields: ~[ast::Field]) -> ~[@ast::expr] { + fields.map(|f| f.expr) } // Takes a predicate p, returns true iff p is true for any subexpressions diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 0874163118a..95691c334b1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -409,13 +409,12 @@ pub struct arm { } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub struct field_ { +pub struct Field { ident: ident, expr: @expr, + span: span, } -pub type field = spanned; - #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum blk_check_mode { default_blk, @@ -495,7 +494,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), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 3b32173dfb5..b3d65dfa9e2 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -107,9 +107,9 @@ pub trait AstBuilder { args: ~[@ast::expr]) -> @ast::expr; fn expr_blk(&self, b: ast::Block) -> @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_ident(&self, span: span, id: ast::ident, fields: ~[ast::field]) -> @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_ident(&self, span: span, id: ast::ident, fields: ~[ast::Field]) -> @ast::expr; fn expr_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr; @@ -477,14 +477,14 @@ impl AstBuilder for @ExtCtxt { fn expr_blk(&self, b: ast::Block) -> @ast::expr { self.expr(b.span, ast::expr_block(b)) } - fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::field { - respan(span, ast::field_ { ident: name, expr: e }) + fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::Field { + ast::Field { ident: name, expr: e, span: span } } - 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, - id: ast::ident, fields: ~[ast::field]) -> @ast::expr { + id: ast::ident, fields: ~[ast::Field]) -> @ast::expr { self.expr_struct(span, self.path_ident(span, id), fields) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 6af08d0a8d5..f27e68641e3 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -488,12 +488,10 @@ pub fn wrap(f: @fn(&T, @ast_fold) -> T) } pub fn noop_fold_expr(e: &expr_, fld: @ast_fold) -> expr_ { - fn fold_field_(field: field, fld: @ast_fold) -> field { - spanned { - node: ast::field_ { - ident: fld.fold_ident(field.node.ident), - expr: fld.fold_expr(field.node.expr), - }, + fn fold_field_(field: Field, fld: @ast_fold) -> Field { + ast::Field { + ident: fld.fold_ident(field.ident), + expr: fld.fold_expr(field.expr), span: fld.new_span(field.span), } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2e8e69561e8..a4fd4929400 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -29,7 +29,7 @@ use ast::{expr_method_call, expr_paren, expr_path, expr_repeat}; use ast::{expr_ret, expr_self, expr_struct, expr_tup, expr_unary}; use ast::{expr_vec, expr_vstore, expr_vstore_mut_box}; use ast::{expr_vstore_slice, expr_vstore_box}; -use ast::{expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl}; +use ast::{expr_vstore_mut_slice, expr_while, extern_fn, Field, fn_decl}; use ast::{expr_vstore_uniq, Onceness, Once, Many}; use ast::{foreign_item, foreign_item_static, foreign_item_fn, foreign_mod}; use ast::{ident, impure_fn, inherited, item, item_, item_static}; @@ -1498,15 +1498,16 @@ impl Parser { } // parse ident COLON expr - pub fn parse_field(&self) -> field { + pub fn parse_field(&self) -> Field { let lo = self.span.lo; let i = self.parse_ident(); self.expect(&token::COLON); let e = self.parse_expr(); - spanned(lo, e.span.hi, ast::field_ { + ast::Field { ident: i, - expr: e - }) + expr: e, + span: mk_sp(lo, e.span.hi), + } } pub fn mk_expr(&self, lo: BytePos, hi: BytePos, node: expr_) -> @expr { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 7918e503957..8e2c24cacfe 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1103,14 +1103,14 @@ pub fn print_call_post(s: @ps, } pub fn print_expr(s: @ps, expr: &ast::expr) { - fn print_field(s: @ps, field: &ast::field) { + fn print_field(s: @ps, field: &ast::Field) { ibox(s, indent_unit); - print_ident(s, field.node.ident); + print_ident(s, field.ident); word_space(s, ":"); - print_expr(s, field.node.expr); + print_expr(s, field.expr); end(s); } - fn get_span(field: &ast::field) -> codemap::span { return field.span; } + fn get_span(field: &ast::Field) -> codemap::span { return field.span; } maybe_print_comment(s, expr.span.lo); ibox(s, indent_unit); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index ce707979c06..7e86adfcb63 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -474,7 +474,7 @@ pub fn visit_expr(ex: @expr, (e, v): (E, vt)) { expr_struct(ref p, ref flds, base) => { visit_path(p, (e.clone(), v)); for flds.iter().advance |f| { - (v.visit_expr)(f.node.expr, (e.clone(), v)); + (v.visit_expr)(f.expr, (e.clone(), v)); } visit_expr_opt(base, (e.clone(), v)); } -- cgit 1.4.1-3-g733a5