@@ -58,12 +58,12 @@ pub enum SyntaxContext_ {
58
58
pub type RenameList = Vec < ( Ident , Name ) > ;
59
59
60
60
/// Extend a syntax context with a given mark
61
- pub fn new_mark ( m : Mrk , ctxt : SyntaxContext ) -> SyntaxContext {
62
- with_sctable ( |table| new_mark_internal ( m, ctxt, table) )
61
+ pub fn apply_mark ( m : Mrk , ctxt : SyntaxContext ) -> SyntaxContext {
62
+ with_sctable ( |table| apply_mark_internal ( m, ctxt, table) )
63
63
}
64
64
65
65
// Extend a syntax context with a given mark and sctable (explicit memoization)
66
- fn new_mark_internal ( m : Mrk , ctxt : SyntaxContext , table : & SCTable ) -> SyntaxContext {
66
+ fn apply_mark_internal ( m : Mrk , ctxt : SyntaxContext , table : & SCTable ) -> SyntaxContext {
67
67
let key = ( ctxt, m) ;
68
68
let new_ctxt = |_: & ( SyntaxContext , Mrk ) |
69
69
idx_push ( & mut * table. table . borrow_mut ( ) , Mark ( m, ctxt) ) ;
@@ -72,13 +72,13 @@ fn new_mark_internal(m: Mrk, ctxt: SyntaxContext, table: &SCTable) -> SyntaxCont
72
72
}
73
73
74
74
/// Extend a syntax context with a given rename
75
- pub fn new_rename ( id : Ident , to : Name ,
75
+ pub fn apply_rename ( id : Ident , to : Name ,
76
76
ctxt : SyntaxContext ) -> SyntaxContext {
77
- with_sctable ( |table| new_rename_internal ( id, to, ctxt, table) )
77
+ with_sctable ( |table| apply_rename_internal ( id, to, ctxt, table) )
78
78
}
79
79
80
80
// Extend a syntax context with a given rename and sctable (explicit memoization)
81
- fn new_rename_internal ( id : Ident ,
81
+ fn apply_rename_internal ( id : Ident ,
82
82
to : Name ,
83
83
ctxt : SyntaxContext ,
84
84
table : & SCTable ) -> SyntaxContext {
@@ -93,10 +93,10 @@ fn new_rename_internal(id: Ident,
93
93
// if these rename lists get long, it would make sense
94
94
// to consider memoizing this fold. This may come up
95
95
// when we add hygiene to item names.
96
- pub fn new_renames ( renames : & RenameList , ctxt : SyntaxContext ) -> SyntaxContext {
96
+ pub fn apply_renames ( renames : & RenameList , ctxt : SyntaxContext ) -> SyntaxContext {
97
97
renames. iter ( ) . fold ( ctxt, |ctxt, & ( from, to) | {
98
- new_rename ( from, to, ctxt)
99
- } )
98
+ apply_rename ( from, to, ctxt)
99
+ } )
100
100
}
101
101
102
102
/// Fetch the SCTable from TLS, create one if it doesn't yet exist.
@@ -277,8 +277,8 @@ fn xor_push(marks: &mut Vec<Mrk>, mark: Mrk) {
277
277
#[ cfg( test) ]
278
278
mod tests {
279
279
use ast:: { EMPTY_CTXT , Ident , Mrk , Name , SyntaxContext } ;
280
- use super :: { resolve, xor_push, new_mark_internal , new_sctable_internal} ;
281
- use super :: { new_rename_internal , new_renames , marksof_internal, resolve_internal} ;
280
+ use super :: { resolve, xor_push, apply_mark_internal , new_sctable_internal} ;
281
+ use super :: { apply_rename_internal , apply_renames , marksof_internal, resolve_internal} ;
282
282
use super :: { SCTable , EmptyCtxt , Mark , Rename , IllegalCtxt } ;
283
283
use std:: collections:: HashMap ;
284
284
@@ -319,8 +319,8 @@ mod tests {
319
319
-> SyntaxContext {
320
320
tscs. iter ( ) . rev ( ) . fold ( tail, |tail : SyntaxContext , tsc : & TestSC |
321
321
{ match * tsc {
322
- M ( mrk) => new_mark_internal ( mrk, tail, table) ,
323
- R ( ident, name) => new_rename_internal ( ident, name, tail, table) } } )
322
+ M ( mrk) => apply_mark_internal ( mrk, tail, table) ,
323
+ R ( ident, name) => apply_rename_internal ( ident, name, tail, table) } } )
324
324
}
325
325
326
326
// gather a SyntaxContext back into a vector of TestSCs
@@ -365,7 +365,7 @@ mod tests {
365
365
fn unfold_marks ( mrks : Vec < Mrk > , tail : SyntaxContext , table : & SCTable )
366
366
-> SyntaxContext {
367
367
mrks. iter ( ) . rev ( ) . fold ( tail, |tail : SyntaxContext , mrk : & Mrk |
368
- { new_mark_internal ( * mrk, tail, table) } )
368
+ { apply_mark_internal ( * mrk, tail, table) } )
369
369
}
370
370
371
371
#[ test] fn unfold_marks_test ( ) {
@@ -397,13 +397,13 @@ mod tests {
397
397
// rename where stop doesn't match:
398
398
{ let chain = vec ! ( M ( 9 ) ,
399
399
R ( id( name1,
400
- new_mark_internal ( 4 , EMPTY_CTXT , & mut t) ) ,
400
+ apply_mark_internal ( 4 , EMPTY_CTXT , & mut t) ) ,
401
401
100101102 ) ,
402
402
M ( 14 ) ) ;
403
403
let ans = unfold_test_sc ( chain, EMPTY_CTXT , & mut t) ;
404
404
assert_eq ! ( marksof_internal ( ans, stopname, & t) , vec!( 9 , 14 ) ) ; }
405
405
// rename where stop does match
406
- { let name1sc = new_mark_internal ( 4 , EMPTY_CTXT , & mut t) ;
406
+ { let name1sc = apply_mark_internal ( 4 , EMPTY_CTXT , & mut t) ;
407
407
let chain = vec ! ( M ( 9 ) ,
408
408
R ( id( name1, name1sc) ,
409
409
stopname) ,
@@ -427,7 +427,7 @@ mod tests {
427
427
{ let sc = unfold_test_sc ( vec ! ( R ( id( 50 , EMPTY_CTXT ) , 51 ) , M ( 12 ) ) , EMPTY_CTXT , & mut t) ;
428
428
assert_eq ! ( resolve_internal( id( a, sc) , & mut t, & mut rt) , a) ; }
429
429
// - rename where names do match, but marks don't
430
- { let sc1 = new_mark_internal ( 1 , EMPTY_CTXT , & mut t) ;
430
+ { let sc1 = apply_mark_internal ( 1 , EMPTY_CTXT , & mut t) ;
431
431
let sc = unfold_test_sc ( vec ! ( R ( id( a, sc1) , 50 ) ,
432
432
M ( 1 ) ,
433
433
M ( 2 ) ) ,
@@ -450,11 +450,11 @@ mod tests {
450
450
EMPTY_CTXT , & mut t) ;
451
451
assert_eq ! ( resolve_internal( id( a, sc) , & mut t, & mut rt) , 51 ) ; }
452
452
// the simplest double-rename:
453
- { let a_to_a50 = new_rename_internal ( id ( a, EMPTY_CTXT ) , 50 , EMPTY_CTXT , & mut t) ;
454
- let a50_to_a51 = new_rename_internal ( id ( a, a_to_a50) , 51 , a_to_a50, & mut t) ;
453
+ { let a_to_a50 = apply_rename_internal ( id ( a, EMPTY_CTXT ) , 50 , EMPTY_CTXT , & mut t) ;
454
+ let a50_to_a51 = apply_rename_internal ( id ( a, a_to_a50) , 51 , a_to_a50, & mut t) ;
455
455
assert_eq ! ( resolve_internal( id( a, a50_to_a51) , & mut t, & mut rt) , 51 ) ;
456
456
// mark on the outside doesn't stop rename:
457
- let sc = new_mark_internal ( 9 , a50_to_a51, & mut t) ;
457
+ let sc = apply_mark_internal ( 9 , a50_to_a51, & mut t) ;
458
458
assert_eq ! ( resolve_internal( id( a, sc) , & mut t, & mut rt) , 51 ) ;
459
459
// but mark on the inside does:
460
460
let a50_to_a51_b = unfold_test_sc ( vec ! ( R ( id( a, a_to_a50) , 51 ) ,
@@ -474,10 +474,10 @@ mod tests {
474
474
#[ test]
475
475
fn hashing_tests ( ) {
476
476
let mut t = new_sctable_internal ( ) ;
477
- assert_eq ! ( new_mark_internal ( 12 , EMPTY_CTXT , & mut t) , 2 ) ;
478
- assert_eq ! ( new_mark_internal ( 13 , EMPTY_CTXT , & mut t) , 3 ) ;
477
+ assert_eq ! ( apply_mark_internal ( 12 , EMPTY_CTXT , & mut t) , 2 ) ;
478
+ assert_eq ! ( apply_mark_internal ( 13 , EMPTY_CTXT , & mut t) , 3 ) ;
479
479
// using the same one again should result in the same index:
480
- assert_eq ! ( new_mark_internal ( 12 , EMPTY_CTXT , & mut t) , 2 ) ;
480
+ assert_eq ! ( apply_mark_internal ( 12 , EMPTY_CTXT , & mut t) , 2 ) ;
481
481
// I'm assuming that the rename table will behave the same....
482
482
}
483
483
@@ -498,7 +498,7 @@ mod tests {
498
498
fn new_resolves_test ( ) {
499
499
let renames = vec ! ( ( Ident { name: 23 , ctxt: EMPTY_CTXT } , 24 ) ,
500
500
( Ident { name: 29 , ctxt: EMPTY_CTXT } , 29 ) ) ;
501
- let new_ctxt1 = new_renames ( & renames, EMPTY_CTXT ) ;
501
+ let new_ctxt1 = apply_renames ( & renames, EMPTY_CTXT ) ;
502
502
assert_eq ! ( resolve( Ident { name: 23 , ctxt: new_ctxt1} ) , 24 ) ;
503
503
assert_eq ! ( resolve( Ident { name: 29 , ctxt: new_ctxt1} ) , 29 ) ;
504
504
}
0 commit comments