9
9
// except according to those terms.
10
10
11
11
use ast:: { Block , Crate , Ident , Mac_ , Name , PatKind } ;
12
- use ast:: { MacStmtStyle , Mrk , Stmt , StmtKind , ItemKind } ;
12
+ use ast:: { MacStmtStyle , Stmt , StmtKind , ItemKind } ;
13
13
use ast;
14
- use attr:: HasAttrs ;
15
- use ext:: mtwt;
16
- use attr;
14
+ use ext:: hygiene:: Mark ;
15
+ use attr:: { self , HasAttrs } ;
17
16
use attr:: AttrMetaMethods ;
18
- use codemap:: { dummy_spanned, Spanned , ExpnInfo , NameAndSpan , MacroBang , MacroAttribute } ;
17
+ use codemap:: { dummy_spanned, ExpnInfo , NameAndSpan , MacroBang , MacroAttribute } ;
19
18
use syntax_pos:: { self , Span , ExpnId } ;
20
19
use config:: StripUnconfigured ;
21
20
use ext:: base:: * ;
22
21
use feature_gate:: { self , Features } ;
23
22
use fold;
24
23
use fold:: * ;
25
- use parse:: token:: { fresh_mark , intern, keywords} ;
24
+ use parse:: token:: { intern, keywords} ;
26
25
use ptr:: P ;
27
26
use tokenstream:: TokenTree ;
28
27
use util:: small_vector:: SmallVector ;
@@ -130,9 +129,9 @@ fn expand_mac_invoc<T>(mac: ast::Mac, ident: Option<Ident>, attrs: Vec<ast::Attr
130
129
// It would almost certainly be cleaner to pass the whole macro invocation in,
131
130
// rather than pulling it apart and marking the tts and the ctxt separately.
132
131
let Mac_ { path, tts, .. } = mac. node ;
133
- let mark = fresh_mark ( ) ;
132
+ let mark = Mark :: fresh ( ) ;
134
133
135
- fn mac_result < ' a > ( path : & ast:: Path , ident : Option < Ident > , tts : Vec < TokenTree > , mark : Mrk ,
134
+ fn mac_result < ' a > ( path : & ast:: Path , ident : Option < Ident > , tts : Vec < TokenTree > , mark : Mark ,
136
135
attrs : Vec < ast:: Attribute > , call_site : Span , fld : & ' a mut MacroExpander )
137
136
-> Option < Box < MacResult + ' a > > {
138
137
// Detect use of feature-gated or invalid attributes on macro invoations
@@ -708,30 +707,17 @@ pub fn expand_crate(mut cx: ExtCtxt,
708
707
return ( ret, cx. syntax_env . names ) ;
709
708
}
710
709
711
- // HYGIENIC CONTEXT EXTENSION:
712
- // all of these functions are for walking over
713
- // ASTs and making some change to the context of every
714
- // element that has one. a CtxtFn is a trait-ified
715
- // version of a closure in (SyntaxContext -> SyntaxContext).
716
- // the ones defined here include:
717
- // Marker - add a mark to a context
718
-
719
710
// A Marker adds the given mark to the syntax context and
720
711
// sets spans' `expn_id` to the given expn_id (unless it is `None`).
721
- struct Marker { mark : Mrk , expn_id : Option < ExpnId > }
712
+ struct Marker { mark : Mark , expn_id : Option < ExpnId > }
722
713
723
714
impl Folder for Marker {
724
- fn fold_ident ( & mut self , id : Ident ) -> Ident {
725
- ast:: Ident :: new ( id. name , mtwt:: apply_mark ( self . mark , id. ctxt ) )
726
- }
727
- fn fold_mac ( & mut self , Spanned { node, span} : ast:: Mac ) -> ast:: Mac {
728
- Spanned {
729
- node : Mac_ {
730
- path : self . fold_path ( node. path ) ,
731
- tts : self . fold_tts ( & node. tts ) ,
732
- } ,
733
- span : self . new_span ( span) ,
734
- }
715
+ fn fold_ident ( & mut self , mut ident : Ident ) -> Ident {
716
+ ident. ctxt = ident. ctxt . apply_mark ( self . mark ) ;
717
+ ident
718
+ }
719
+ fn fold_mac ( & mut self , mac : ast:: Mac ) -> ast:: Mac {
720
+ noop_fold_mac ( mac, self )
735
721
}
736
722
737
723
fn new_span ( & mut self , mut span : Span ) -> Span {
@@ -743,7 +729,7 @@ impl Folder for Marker {
743
729
}
744
730
745
731
// apply a given mark to the given token trees. Used prior to expansion of a macro.
746
- fn mark_tts ( tts : & [ TokenTree ] , m : Mrk ) -> Vec < TokenTree > {
732
+ fn mark_tts ( tts : & [ TokenTree ] , m : Mark ) -> Vec < TokenTree > {
747
733
noop_fold_tts ( tts, & mut Marker { mark : m, expn_id : None } )
748
734
}
749
735
0 commit comments