|
9 | 9 | // except according to those terms. |
10 | 10 |
|
11 | 11 | use ast::{Block, Crate, DeclLocal, ExprMac, PatMac}; |
12 | | -use ast::{Local, Ident, MacInvocTT}; |
| 12 | +use ast::{Local, Ident, Mac_}; |
13 | 13 | use ast::{ItemMac, MacStmtWithSemicolon, Mrk, Stmt, StmtDecl, StmtMac}; |
14 | 14 | use ast::{StmtExpr, StmtSemi}; |
15 | 15 | use ast::TokenTree; |
@@ -509,78 +509,75 @@ fn expand_mac_invoc<T, F, G>(mac: ast::Mac, |
509 | 509 | F: for<'a> FnOnce(Box<MacResult+'a>) -> Option<T>, |
510 | 510 | G: FnOnce(T, Mrk) -> T, |
511 | 511 | { |
512 | | - match mac.node { |
513 | | - // it would almost certainly be cleaner to pass the whole |
514 | | - // macro invocation in, rather than pulling it apart and |
515 | | - // marking the tts and the ctxt separately. This also goes |
516 | | - // for the other three macro invocation chunks of code |
517 | | - // in this file. |
518 | | - // Token-tree macros: |
519 | | - MacInvocTT(pth, tts, _) => { |
520 | | - if pth.segments.len() > 1 { |
521 | | - fld.cx.span_err(pth.span, |
522 | | - "expected macro name without module \ |
523 | | - separators"); |
524 | | - // let compilation continue |
525 | | - return None; |
526 | | - } |
527 | | - let extname = pth.segments[0].identifier.name; |
528 | | - match fld.cx.syntax_env.find(&extname) { |
529 | | - None => { |
530 | | - fld.cx.span_err( |
531 | | - pth.span, |
532 | | - &format!("macro undefined: '{}!'", |
533 | | - &extname)); |
| 512 | + // it would almost certainly be cleaner to pass the whole |
| 513 | + // macro invocation in, rather than pulling it apart and |
| 514 | + // marking the tts and the ctxt separately. This also goes |
| 515 | + // for the other three macro invocation chunks of code |
| 516 | + // in this file. |
| 517 | + |
| 518 | + let Mac_ { path: pth, tts, .. } = mac.node; |
| 519 | + if pth.segments.len() > 1 { |
| 520 | + fld.cx.span_err(pth.span, |
| 521 | + "expected macro name without module \ |
| 522 | + separators"); |
| 523 | + // let compilation continue |
| 524 | + return None; |
| 525 | + } |
| 526 | + let extname = pth.segments[0].identifier.name; |
| 527 | + match fld.cx.syntax_env.find(&extname) { |
| 528 | + None => { |
| 529 | + fld.cx.span_err( |
| 530 | + pth.span, |
| 531 | + &format!("macro undefined: '{}!'", |
| 532 | + &extname)); |
534 | 533 |
|
535 | | - // let compilation continue |
536 | | - None |
537 | | - } |
538 | | - Some(rc) => match *rc { |
539 | | - NormalTT(ref expandfun, exp_span, allow_internal_unstable) => { |
540 | | - fld.cx.bt_push(ExpnInfo { |
541 | | - call_site: span, |
542 | | - callee: NameAndSpan { |
543 | | - format: MacroBang(extname), |
544 | | - span: exp_span, |
545 | | - allow_internal_unstable: allow_internal_unstable, |
546 | | - }, |
547 | | - }); |
548 | | - let fm = fresh_mark(); |
549 | | - let marked_before = mark_tts(&tts[..], fm); |
550 | | - |
551 | | - // The span that we pass to the expanders we want to |
552 | | - // be the root of the call stack. That's the most |
553 | | - // relevant span and it's the actual invocation of |
554 | | - // the macro. |
555 | | - let mac_span = fld.cx.original_span(); |
556 | | - |
557 | | - let opt_parsed = { |
558 | | - let expanded = expandfun.expand(fld.cx, |
559 | | - mac_span, |
560 | | - &marked_before[..]); |
561 | | - parse_thunk(expanded) |
562 | | - }; |
563 | | - let parsed = match opt_parsed { |
564 | | - Some(e) => e, |
565 | | - None => { |
566 | | - fld.cx.span_err( |
567 | | - pth.span, |
568 | | - &format!("non-expression macro in expression position: {}", |
569 | | - extname |
570 | | - )); |
571 | | - return None; |
572 | | - } |
573 | | - }; |
574 | | - Some(mark_thunk(parsed,fm)) |
575 | | - } |
576 | | - _ => { |
| 534 | + // let compilation continue |
| 535 | + None |
| 536 | + } |
| 537 | + Some(rc) => match *rc { |
| 538 | + NormalTT(ref expandfun, exp_span, allow_internal_unstable) => { |
| 539 | + fld.cx.bt_push(ExpnInfo { |
| 540 | + call_site: span, |
| 541 | + callee: NameAndSpan { |
| 542 | + format: MacroBang(extname), |
| 543 | + span: exp_span, |
| 544 | + allow_internal_unstable: allow_internal_unstable, |
| 545 | + }, |
| 546 | + }); |
| 547 | + let fm = fresh_mark(); |
| 548 | + let marked_before = mark_tts(&tts[..], fm); |
| 549 | + |
| 550 | + // The span that we pass to the expanders we want to |
| 551 | + // be the root of the call stack. That's the most |
| 552 | + // relevant span and it's the actual invocation of |
| 553 | + // the macro. |
| 554 | + let mac_span = fld.cx.original_span(); |
| 555 | + |
| 556 | + let opt_parsed = { |
| 557 | + let expanded = expandfun.expand(fld.cx, |
| 558 | + mac_span, |
| 559 | + &marked_before[..]); |
| 560 | + parse_thunk(expanded) |
| 561 | + }; |
| 562 | + let parsed = match opt_parsed { |
| 563 | + Some(e) => e, |
| 564 | + None => { |
577 | 565 | fld.cx.span_err( |
578 | 566 | pth.span, |
579 | | - &format!("'{}' is not a tt-style macro", |
580 | | - extname)); |
581 | | - None |
| 567 | + &format!("non-expression macro in expression position: {}", |
| 568 | + extname |
| 569 | + )); |
| 570 | + return None; |
582 | 571 | } |
583 | | - } |
| 572 | + }; |
| 573 | + Some(mark_thunk(parsed,fm)) |
| 574 | + } |
| 575 | + _ => { |
| 576 | + fld.cx.span_err( |
| 577 | + pth.span, |
| 578 | + &format!("'{}' is not a tt-style macro", |
| 579 | + extname)); |
| 580 | + None |
584 | 581 | } |
585 | 582 | } |
586 | 583 | } |
@@ -684,15 +681,11 @@ fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool |
684 | 681 | // logic as for expression-position macro invocations. |
685 | 682 | pub fn expand_item_mac(it: P<ast::Item>, |
686 | 683 | fld: &mut MacroExpander) -> SmallVector<P<ast::Item>> { |
687 | | - let (extname, path_span, tts, span, attrs, ident) = it.and_then(|it| { match it.node { |
688 | | - ItemMac(codemap::Spanned { |
689 | | - node: MacInvocTT(pth, tts, _), |
690 | | - .. |
691 | | - }) => { |
692 | | - (pth.segments[0].identifier.name, pth.span, tts, it.span, it.attrs, it.ident) |
693 | | - } |
| 684 | + let (extname, path_span, tts, span, attrs, ident) = it.and_then(|it| match it.node { |
| 685 | + ItemMac(codemap::Spanned { node: Mac_ { path, tts, .. }, .. }) => |
| 686 | + (path.segments[0].identifier.name, path.span, tts, it.span, it.attrs, it.ident), |
694 | 687 | _ => fld.cx.span_bug(it.span, "invalid item macro invocation") |
695 | | - }}); |
| 688 | + }); |
696 | 689 |
|
697 | 690 | let fm = fresh_mark(); |
698 | 691 | let items = { |
@@ -1060,11 +1053,7 @@ fn expand_pat(p: P<ast::Pat>, fld: &mut MacroExpander) -> P<ast::Pat> { |
1060 | 1053 | } |
1061 | 1054 | p.map(|ast::Pat {node, span, ..}| { |
1062 | 1055 | let (pth, tts) = match node { |
1063 | | - PatMac(mac) => match mac.node { |
1064 | | - MacInvocTT(pth, tts, _) => { |
1065 | | - (pth, tts) |
1066 | | - } |
1067 | | - }, |
| 1056 | + PatMac(mac) => (mac.node.path, mac.node.tts), |
1068 | 1057 | _ => unreachable!() |
1069 | 1058 | }; |
1070 | 1059 | if pth.segments.len() > 1 { |
@@ -1646,12 +1635,10 @@ impl Folder for Marker { |
1646 | 1635 | } |
1647 | 1636 | fn fold_mac(&mut self, Spanned {node, span}: ast::Mac) -> ast::Mac { |
1648 | 1637 | Spanned { |
1649 | | - node: match node { |
1650 | | - MacInvocTT(path, tts, ctxt) => { |
1651 | | - MacInvocTT(self.fold_path(path), |
1652 | | - self.fold_tts(&tts[..]), |
1653 | | - mtwt::apply_mark(self.mark, ctxt)) |
1654 | | - } |
| 1638 | + node: Mac_ { |
| 1639 | + path: self.fold_path(node.path), |
| 1640 | + tts: self.fold_tts(&node.tts), |
| 1641 | + ctxt: mtwt::apply_mark(self.mark, node.ctxt), |
1655 | 1642 | }, |
1656 | 1643 | span: span, |
1657 | 1644 | } |
|
0 commit comments