@@ -603,7 +603,7 @@ fn expand_non_macro_stmt (exts: SyntaxEnv,
603
603
}
604
604
605
605
// a visitor that extracts the pat_ident paths
606
- // from a given pattern and puts them in a mutable
606
+ // from a given thingy and puts them in a mutable
607
607
// array (passed in to the traversal)
608
608
#[ deriving( Clone ) ]
609
609
struct NewNameFinderContext {
@@ -748,15 +748,14 @@ impl Visitor<()> for NewNameFinderContext {
748
748
}
749
749
}
750
750
751
- // a visitor that extracts the path exprs from
752
- // a crate/expression/whatever and puts them in a mutable
751
+ // a visitor that extracts the paths
752
+ // from a given thingy and puts them in a mutable
753
753
// array (passed in to the traversal)
754
754
#[ deriving( Clone ) ]
755
755
struct NewPathExprFinderContext {
756
756
path_accumulator : @mut ~[ ast:: Path ] ,
757
757
}
758
758
759
-
760
759
// XXX : YIKES a lot of boilerplate again....
761
760
impl Visitor < ( ) > for NewPathExprFinderContext {
762
761
@@ -875,7 +874,7 @@ impl Visitor<()> for NewPathExprFinderContext {
875
874
}
876
875
877
876
// return a visitor that extracts the pat_ident paths
878
- // from a given pattern and puts them in a mutable
877
+ // from a given thingy and puts them in a mutable
879
878
// array (passed in to the traversal)
880
879
pub fn new_name_finder ( idents : @mut ~[ ast:: Ident ] ) -> @mut Visitor < ( ) > {
881
880
let context = @mut NewNameFinderContext {
@@ -913,6 +912,7 @@ pub fn renames_to_fold(renames : @mut ~[(ast::Ident,ast::Name)]) -> @ast_fold {
913
912
make_fold ( f_pre)
914
913
}
915
914
915
+ // expand a block. pushes a new exts_frame, then calls expand_block_elts
916
916
pub fn expand_block ( extsbox : @mut SyntaxEnv ,
917
917
_cx : @ExtCtxt ,
918
918
blk : & Block ,
@@ -924,7 +924,7 @@ pub fn expand_block(extsbox: @mut SyntaxEnv,
924
924
expand_block_elts( * extsbox, blk, fld) )
925
925
}
926
926
927
-
927
+ // expand the elements of a block.
928
928
pub fn expand_block_elts ( exts : SyntaxEnv , b : & Block , fld : @ast_fold ) -> Block {
929
929
let block_info = get_block_info ( exts) ;
930
930
let pending_renames = block_info. pending_renames ;
@@ -949,6 +949,7 @@ pub fn expand_block_elts(exts: SyntaxEnv, b: &Block, fld: @ast_fold) -> Block {
949
949
}
950
950
951
951
// rename_fold should never return "None".
952
+ // (basically, just .get() with a better message...)
952
953
fn mustbesome < T > ( val : Option < T > ) -> T {
953
954
match val {
954
955
Some ( v) => v,
@@ -971,8 +972,8 @@ pub fn new_span(cx: @ExtCtxt, sp: Span) -> Span {
971
972
}
972
973
973
974
// FIXME (#2247): this is a moderately bad kludge to inject some macros into
974
- // the default compilation environment. It would be much nicer to use
975
- // a mechanism like syntax_quote to ensure hygiene .
975
+ // the default compilation environment in that it injects strings, rather than
976
+ // syntax elements .
976
977
977
978
pub fn std_macros ( ) -> @str {
978
979
return
@@ -1453,6 +1454,10 @@ pub fn fun_to_ctxt_folder<T : 'static + CtxtFn>(cf: @T) -> @AstFoldFns {
1453
1454
|ast:: Ident { name, ctxt} , _| {
1454
1455
ast:: Ident { name : name, ctxt : cf. f ( ctxt) }
1455
1456
} ;
1457
+ // we've also got to pick up macro invocations; they can
1458
+ // appear as exprs, stmts, items, and types. urg, it's going
1459
+ // to be easier just to add a fold_mac, I think.
1460
+ //let fold_ex : @
1456
1461
@AstFoldFns {
1457
1462
fold_ident : fi,
1458
1463
// check that it works, then add the fold_expr clause....
@@ -1631,14 +1636,15 @@ mod test {
1631
1636
1632
1637
// try a double-rename, with pending_renames.
1633
1638
let a3_name = gensym ( "a3" ) ;
1639
+ // a context that renames from ("a",empty) to "a2" :
1634
1640
let ctxt2 = new_rename ( ast:: Ident :: new ( a_name) , a2_name, EMPTY_CTXT ) ;
1635
1641
let pending_renames = @mut ~[ ( ast:: Ident :: new ( a_name) , a2_name) ,
1636
1642
( ast:: Ident { name : a_name, ctxt : ctxt2} , a3_name) ] ;
1637
1643
let double_renamed = renames_to_fold ( pending_renames) . fold_crate ( item_ast) ;
1638
1644
let varrefs = @mut ~[ ] ;
1639
1645
visit:: walk_crate ( & mut new_path_finder ( varrefs) , & double_renamed, ( ) ) ;
1640
1646
match varrefs {
1641
- @[ Path { segments : [ ref seg] , _} ] => assert_eq ! ( mtwt_resolve( seg. identifier) , a2_name ) ,
1647
+ @[ Path { segments : [ ref seg] , _} ] => assert_eq ! ( mtwt_resolve( seg. identifier) , a3_name ) ,
1642
1648
_ => assert_eq ! ( 0 , 1 )
1643
1649
}
1644
1650
}
0 commit comments