diff options
| author | bors <bors@rust-lang.org> | 2014-02-14 12:21:51 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-02-14 12:21:51 -0800 |
| commit | 3f717bbe96014c04c4c439ed0b0975ca36a73e53 (patch) | |
| tree | 8efaf70dc83bb23098e7d0e47a65cdeb963bba8a /src/libsyntax | |
| parent | 994747022a45b5c2b03f38dddbe8b43bf09679f3 (diff) | |
| parent | 2f8dbf210215039f39a80424d9c43f96ff79dad4 (diff) | |
| download | rust-3f717bbe96014c04c4c439ed0b0975ca36a73e53.tar.gz rust-3f717bbe96014c04c4c439ed0b0975ca36a73e53.zip | |
auto merge of #12267 : alexcrichton/rust/rollup, r=alexcrichton
The last commit has the closed PRs
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 85 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 11 | ||||
| -rw-r--r-- | src/libsyntax/lib.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/classify.rs | 16 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 44 | ||||
| -rw-r--r-- | src/libsyntax/util/small_vector.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 4 |
10 files changed, 75 insertions, 128 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 72330bb7f31..132cb396ddd 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -519,7 +519,7 @@ pub struct Expr { impl Expr { pub fn get_callee_id(&self) -> Option<NodeId> { match self.node { - ExprMethodCall(callee_id, _, _, _, _) | + ExprMethodCall(callee_id, _, _, _) | ExprIndex(callee_id, _, _) | ExprBinary(callee_id, _, _, _) | ExprAssignOp(callee_id, _, _, _) | @@ -530,19 +530,13 @@ impl Expr { } #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] -pub enum CallSugar { - NoSugar, - ForSugar -} - -#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] pub enum Expr_ { ExprVstore(@Expr, ExprVstore), // First expr is the place; second expr is the value. ExprBox(@Expr, @Expr), ExprVec(~[@Expr], Mutability), - ExprCall(@Expr, ~[@Expr], CallSugar), - ExprMethodCall(NodeId, Ident, ~[P<Ty>], ~[@Expr], CallSugar), + ExprCall(@Expr, ~[@Expr]), + ExprMethodCall(NodeId, Ident, ~[P<Ty>], ~[@Expr]), ExprTup(~[@Expr]), ExprBinary(NodeId, BinOp, @Expr, @Expr), ExprUnary(NodeId, UnOp, @Expr), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index e41decbd8ef..d311a542ac6 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -525,11 +525,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_call(&self, span: Span, expr: @ast::Expr, args: ~[@ast::Expr]) -> @ast::Expr { - self.expr(span, ast::ExprCall(expr, args, ast::NoSugar)) + self.expr(span, ast::ExprCall(expr, args)) } fn expr_call_ident(&self, span: Span, id: ast::Ident, args: ~[@ast::Expr]) -> @ast::Expr { - self.expr(span, - ast::ExprCall(self.expr_ident(span, id), args, ast::NoSugar)) + self.expr(span, ast::ExprCall(self.expr_ident(span, id), args)) } fn expr_call_global(&self, sp: Span, fn_path: ~[ast::Ident], args: ~[@ast::Expr]) -> @ast::Expr { @@ -541,7 +540,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { ident: ast::Ident, mut args: ~[@ast::Expr]) -> @ast::Expr { args.unshift(expr); - self.expr(span, ast::ExprMethodCall(ast::DUMMY_NODE_ID, ident, ~[], args, ast::NoSugar)) + self.expr(span, ast::ExprMethodCall(ast::DUMMY_NODE_ID, ident, ~[], args)) } fn expr_block(&self, b: P<ast::Block>) -> @ast::Expr { self.expr(b.span, ast::ExprBlock(b)) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index e59afc6ffa6..97766e1a14b 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -203,52 +203,6 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr { } } -// This is a secondary mechanism for invoking syntax extensions on items: -// "decorator" attributes, such as #[auto_encode]. These are invoked by an -// attribute prefixing an item, and are interpreted by feeding the item -// through the named attribute _as a syntax extension_ and splicing in the -// resulting item vec into place in favour of the decorator. Note that -// these do _not_ work for macro extensions, just ItemDecorator ones. -// -// NB: there is some redundancy between this and expand_item, below, and -// they might benefit from some amount of semantic and language-UI merger. -pub fn expand_mod_items(module_: &ast::Mod, fld: &mut MacroExpander) -> ast::Mod { - // Fold the contents first: - let module_ = noop_fold_mod(module_, fld); - - // For each item, look through the attributes. If any of them are - // decorated with "item decorators", then use that function to transform - // the item into a new set of items. - let mut new_items = module_.items.clone(); - for item in module_.items.iter() { - for attr in item.attrs.rev_iter() { - let mname = attr.name(); - - match fld.extsbox.find(&intern(mname.get())) { - Some(&ItemDecorator(dec_fn)) => { - fld.cx.bt_push(ExpnInfo { - call_site: attr.span, - callee: NameAndSpan { - name: mname.get().to_str(), - format: MacroAttribute, - span: None - } - }); - dec_fn(fld.cx, attr.span, attr.node.value, *item, - |item| new_items.push(item)); - fld.cx.bt_pop(); - }, - _ => {}, - } - } - } - - ast::Mod { - items: new_items, - ..module_ - } -} - // eval $e with a new exts frame: macro_rules! with_exts_frame ( ($extsboxexpr:expr,$macros_escape:expr,$e:expr) => @@ -263,7 +217,35 @@ macro_rules! with_exts_frame ( // When we enter a module, record it, for the sake of `module!` pub fn expand_item(it: @ast::Item, fld: &mut MacroExpander) -> SmallVector<@ast::Item> { - match it.node { + let mut decorator_items = SmallVector::zero(); + for attr in it.attrs.rev_iter() { + let mname = attr.name(); + + match fld.extsbox.find(&intern(mname.get())) { + Some(&ItemDecorator(dec_fn)) => { + fld.cx.bt_push(ExpnInfo { + call_site: attr.span, + callee: NameAndSpan { + name: mname.get().to_str(), + format: MacroAttribute, + span: None + } + }); + // we'd ideally decorator_items.push_all(expand_item(item, fld)), + // but that double-mut-borrows fld + dec_fn(fld.cx, attr.span, attr.node.value, it, + |item| decorator_items.push(item)); + fld.cx.bt_pop(); + } + _ => {} + } + } + + let decorator_items = decorator_items.move_iter() + .flat_map(|item| expand_item(item, fld).move_iter()) + .collect(); + + let mut new_items = match it.node { ast::ItemMac(..) => expand_item_mac(it, fld), ast::ItemMod(_) | ast::ItemForeignMod(_) => { fld.cx.mod_push(it.ident); @@ -275,7 +257,10 @@ pub fn expand_item(it: @ast::Item, fld: &mut MacroExpander) result }, _ => noop_fold_item(it, fld) - } + }; + + new_items.push_all(decorator_items); + new_items } // does this attribute list contain "macro_escape" ? @@ -778,10 +763,6 @@ impl<'a> Folder for MacroExpander<'a> { expand_expr(expr, self) } - fn fold_mod(&mut self, module: &ast::Mod) -> ast::Mod { - expand_mod_items(module, self) - } - fn fold_item(&mut self, item: @ast::Item) -> SmallVector<@ast::Item> { expand_item(item, self) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 6fb66a66f18..e150d1685de 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -727,19 +727,16 @@ pub fn noop_fold_expr<T: Folder>(e: @Expr, folder: &mut T) -> @Expr { ExprRepeat(folder.fold_expr(expr), folder.fold_expr(count), mutt) } ExprTup(ref elts) => ExprTup(elts.map(|x| folder.fold_expr(*x))), - ExprCall(f, ref args, blk) => { + ExprCall(f, ref args) => { ExprCall(folder.fold_expr(f), - args.map(|&x| folder.fold_expr(x)), - blk) + args.map(|&x| folder.fold_expr(x))) } - ExprMethodCall(callee_id, i, ref tps, ref args, blk) => { + ExprMethodCall(callee_id, i, ref tps, ref args) => { ExprMethodCall( folder.new_id(callee_id), folder.fold_ident(i), tps.map(|&x| folder.fold_ty(x)), - args.map(|&x| folder.fold_expr(x)), - blk - ) + args.map(|&x| folder.fold_expr(x))) } ExprBinary(callee_id, binop, lhs, rhs) => { ExprBinary(folder.new_id(callee_id), diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 613416bed1c..78e40a795db 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -32,7 +32,7 @@ This API is completely unstable and subject to change. #[deny(non_camel_case_types)]; -extern mod extra; +#[cfg(test)] extern mod extra; extern mod serialize; extern mod term; extern mod collections; diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index accf5e73540..d6dcb956f25 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -23,15 +23,13 @@ use ast; // isn't parsed as (if true {...} else {...} | x) | 5 pub fn expr_requires_semi_to_be_stmt(e: @ast::Expr) -> bool { match e.node { - ast::ExprIf(..) - | ast::ExprMatch(..) - | ast::ExprBlock(_) - | ast::ExprWhile(..) - | ast::ExprLoop(..) - | ast::ExprForLoop(..) - | ast::ExprCall(_, _, ast::ForSugar) - | ast::ExprMethodCall(_, _, _, _, ast::ForSugar) => false, - _ => true + ast::ExprIf(..) + | ast::ExprMatch(..) + | ast::ExprBlock(_) + | ast::ExprWhile(..) + | ast::ExprLoop(..) + | ast::ExprForLoop(..) => false, + _ => true } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 674d41e9dbe..a02971ae8ea 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -13,7 +13,6 @@ use abi; use abi::AbiSet; use ast::{Sigil, BorrowedSigil, ManagedSigil, OwnedSigil}; -use ast::{CallSugar, NoSugar}; use ast::{BareFnTy, ClosureTy}; use ast::{RegionTyParamBound, TraitTyParamBound}; use ast::{Provided, Public, Purity}; @@ -1690,13 +1689,12 @@ impl Parser { ExprBinary(ast::DUMMY_NODE_ID, binop, lhs, rhs) } - pub fn mk_call(&mut self, f: @Expr, args: ~[@Expr], sugar: CallSugar) -> ast::Expr_ { - ExprCall(f, args, sugar) + pub fn mk_call(&mut self, f: @Expr, args: ~[@Expr]) -> ast::Expr_ { + ExprCall(f, args) } - fn mk_method_call(&mut self, ident: Ident, tps: ~[P<Ty>], args: ~[@Expr], - sugar: CallSugar) -> ast::Expr_ { - ExprMethodCall(ast::DUMMY_NODE_ID, ident, tps, args, sugar) + fn mk_method_call(&mut self, ident: Ident, tps: ~[P<Ty>], args: ~[@Expr]) -> ast::Expr_ { + ExprMethodCall(ast::DUMMY_NODE_ID, ident, tps, args) } pub fn mk_index(&mut self, expr: @Expr, idx: @Expr) -> ast::Expr_ { @@ -1997,7 +1995,7 @@ impl Parser { hi = self.last_span.hi; es.unshift(e); - let nd = self.mk_method_call(i, tys, es, NoSugar); + let nd = self.mk_method_call(i, tys, es); e = self.mk_expr(lo, hi, nd); } _ => { @@ -2022,7 +2020,7 @@ impl Parser { ); hi = self.last_span.hi; - let nd = self.mk_call(e, es, NoSugar); + let nd = self.mk_call(e, es); e = self.mk_expr(lo, hi, nd); } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 85bc372b9c6..bb2f345ac28 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1141,33 +1141,10 @@ pub fn print_expr_vstore(s: &mut State, t: ast::ExprVstore) -> io::IoResult<()> } } -pub fn print_call_pre(s: &mut State, - sugar: ast::CallSugar, - base_args: &mut ~[@ast::Expr]) - -> io::IoResult<Option<@ast::Expr>> { - match sugar { - ast::ForSugar => { - if_ok!(head(s, "for")); - Ok(Some(base_args.pop().unwrap())) - } - ast::NoSugar => Ok(None) - } -} - -pub fn print_call_post(s: &mut State, - sugar: ast::CallSugar, - blk: &Option<@ast::Expr>, - base_args: &mut ~[@ast::Expr]) -> io::IoResult<()> { - if sugar == ast::NoSugar || !base_args.is_empty() { - if_ok!(popen(s)); - if_ok!(commasep_exprs(s, Inconsistent, *base_args)); - if_ok!(pclose(s)); - } - if sugar != ast::NoSugar { - if_ok!(nbsp(s)); - // not sure if this can happen - if_ok!(print_expr(s, blk.unwrap())); - } +fn print_call_post(s: &mut State, args: &[@ast::Expr]) -> io::IoResult<()> { + if_ok!(popen(s)); + if_ok!(commasep_exprs(s, Inconsistent, args)); + if_ok!(pclose(s)); Ok(()) } @@ -1254,15 +1231,12 @@ pub fn print_expr(s: &mut State, expr: &ast::Expr) -> io::IoResult<()> { } if_ok!(pclose(s)); } - ast::ExprCall(func, ref args, sugar) => { - let mut base_args = (*args).clone(); - let blk = if_ok!(print_call_pre(s, sugar, &mut base_args)); + ast::ExprCall(func, ref args) => { if_ok!(print_expr(s, func)); - if_ok!(print_call_post(s, sugar, &blk, &mut base_args)); + if_ok!(print_call_post(s, *args)); } - ast::ExprMethodCall(_, ident, ref tys, ref args, sugar) => { - let mut base_args = args.slice_from(1).to_owned(); - let blk = if_ok!(print_call_pre(s, sugar, &mut base_args)); + ast::ExprMethodCall(_, ident, ref tys, ref args) => { + let base_args = args.slice_from(1); if_ok!(print_expr(s, args[0])); if_ok!(word(&mut s.s, ".")); if_ok!(print_ident(s, ident)); @@ -1271,7 +1245,7 @@ pub fn print_expr(s: &mut State, expr: &ast::Expr) -> io::IoResult<()> { if_ok!(commasep(s, Inconsistent, *tys, print_type_ref)); if_ok!(word(&mut s.s, ">")); } - if_ok!(print_call_post(s, sugar, &blk, &mut base_args)); + if_ok!(print_call_post(s, base_args)); } ast::ExprBinary(_, op, lhs, rhs) => { if_ok!(print_expr(s, lhs)); diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index e0d7fdd8790..32e5b83ee04 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -64,6 +64,12 @@ impl<T> SmallVector<T> { } } + pub fn push_all(&mut self, other: SmallVector<T>) { + for v in other.move_iter() { + self.push(v); + } + } + pub fn get<'a>(&'a self, idx: uint) -> &'a T { match *self { One(ref v) if idx == 0 => v, diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index ce87c3d7591..feab4e0e84d 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -652,13 +652,13 @@ pub fn walk_expr<E: Clone, V: Visitor<E>>(visitor: &mut V, expression: &Expr, en visitor.visit_expr(*subexpression, env.clone()) } } - ExprCall(callee_expression, ref arguments, _) => { + ExprCall(callee_expression, ref arguments) => { for argument in arguments.iter() { visitor.visit_expr(*argument, env.clone()) } visitor.visit_expr(callee_expression, env.clone()) } - ExprMethodCall(_, _, ref types, ref arguments, _) => { + ExprMethodCall(_, _, ref types, ref arguments) => { walk_exprs(visitor, *arguments, env.clone()); for &typ in types.iter() { visitor.visit_ty(typ, env.clone()) |
