@@ -29,63 +29,63 @@ use std::str;
29
29
30
30
/* line!(): expands to the current line number */
31
31
pub fn expand_line ( cx : & mut ExtCtxt , sp : Span , tts : & [ ast:: TokenTree ] )
32
- -> base:: MacResult {
32
+ -> ~ base:: MacResult {
33
33
base:: check_zero_tts ( cx, sp, tts, "line!" ) ;
34
34
35
35
let topmost = topmost_expn_info ( cx. backtrace ( ) . unwrap ( ) ) ;
36
36
let loc = cx. codemap ( ) . lookup_char_pos ( topmost. call_site . lo ) ;
37
37
38
- base:: MRExpr ( cx. expr_uint ( topmost. call_site , loc. line ) )
38
+ base:: MacExpr :: new ( cx. expr_uint ( topmost. call_site , loc. line ) )
39
39
}
40
40
41
41
/* col!(): expands to the current column number */
42
42
pub fn expand_col ( cx : & mut ExtCtxt , sp : Span , tts : & [ ast:: TokenTree ] )
43
- -> base:: MacResult {
43
+ -> ~ base:: MacResult {
44
44
base:: check_zero_tts ( cx, sp, tts, "col!" ) ;
45
45
46
46
let topmost = topmost_expn_info ( cx. backtrace ( ) . unwrap ( ) ) ;
47
47
let loc = cx. codemap ( ) . lookup_char_pos ( topmost. call_site . lo ) ;
48
- base:: MRExpr ( cx. expr_uint ( topmost. call_site , loc. col . to_uint ( ) ) )
48
+ base:: MacExpr :: new ( cx. expr_uint ( topmost. call_site , loc. col . to_uint ( ) ) )
49
49
}
50
50
51
51
/* file!(): expands to the current filename */
52
52
/* The filemap (`loc.file`) contains a bunch more information we could spit
53
53
* out if we wanted. */
54
54
pub fn expand_file ( cx : & mut ExtCtxt , sp : Span , tts : & [ ast:: TokenTree ] )
55
- -> base:: MacResult {
55
+ -> ~ base:: MacResult {
56
56
base:: check_zero_tts ( cx, sp, tts, "file!" ) ;
57
57
58
58
let topmost = topmost_expn_info ( cx. backtrace ( ) . unwrap ( ) ) ;
59
59
let loc = cx. codemap ( ) . lookup_char_pos ( topmost. call_site . lo ) ;
60
60
let filename = token:: intern_and_get_ident ( loc. file . name ) ;
61
- base:: MRExpr ( cx. expr_str ( topmost. call_site , filename) )
61
+ base:: MacExpr :: new ( cx. expr_str ( topmost. call_site , filename) )
62
62
}
63
63
64
64
pub fn expand_stringify ( cx : & mut ExtCtxt , sp : Span , tts : & [ ast:: TokenTree ] )
65
- -> base:: MacResult {
65
+ -> ~ base:: MacResult {
66
66
let s = pprust:: tts_to_str ( tts) ;
67
- base:: MRExpr ( cx. expr_str ( sp, token:: intern_and_get_ident ( s) ) )
67
+ base:: MacExpr :: new ( cx. expr_str ( sp, token:: intern_and_get_ident ( s) ) )
68
68
}
69
69
70
70
pub fn expand_mod ( cx : & mut ExtCtxt , sp : Span , tts : & [ ast:: TokenTree ] )
71
- -> base:: MacResult {
71
+ -> ~ base:: MacResult {
72
72
base:: check_zero_tts ( cx, sp, tts, "module_path!" ) ;
73
73
let string = cx. mod_path ( )
74
74
. iter ( )
75
75
. map ( |x| token:: get_ident ( * x) . get ( ) . to_str ( ) )
76
76
. collect :: < Vec < ~str > > ( )
77
77
. connect ( "::" ) ;
78
- base:: MRExpr ( cx. expr_str ( sp, token:: intern_and_get_ident ( string) ) )
78
+ base:: MacExpr :: new ( cx. expr_str ( sp, token:: intern_and_get_ident ( string) ) )
79
79
}
80
80
81
81
// include! : parse the given file as an expr
82
82
// This is generally a bad idea because it's going to behave
83
83
// unhygienically.
84
84
pub fn expand_include ( cx : & mut ExtCtxt , sp : Span , tts : & [ ast:: TokenTree ] )
85
- -> base:: MacResult {
85
+ -> ~ base:: MacResult {
86
86
let file = match get_single_str_from_tts ( cx, sp, tts, "include!" ) {
87
87
Some ( f) => f,
88
- None => return MacResult :: dummy_expr ( sp) ,
88
+ None => return DummyResult :: expr ( sp) ,
89
89
} ;
90
90
// The file will be added to the code map by the parser
91
91
let mut p =
@@ -95,21 +95,21 @@ pub fn expand_include(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
95
95
sp,
96
96
& Path :: new ( file) ) ,
97
97
sp) ;
98
- base:: MRExpr ( p. parse_expr ( ) )
98
+ base:: MacExpr :: new ( p. parse_expr ( ) )
99
99
}
100
100
101
101
// include_str! : read the given file, insert it as a literal string expr
102
102
pub fn expand_include_str ( cx : & mut ExtCtxt , sp : Span , tts : & [ ast:: TokenTree ] )
103
- -> base:: MacResult {
103
+ -> ~ base:: MacResult {
104
104
let file = match get_single_str_from_tts ( cx, sp, tts, "include_str!" ) {
105
105
Some ( f) => f,
106
- None => return MacResult :: dummy_expr ( sp)
106
+ None => return DummyResult :: expr ( sp)
107
107
} ;
108
108
let file = res_rel_file ( cx, sp, & Path :: new ( file) ) ;
109
109
let bytes = match File :: open ( & file) . read_to_end ( ) {
110
110
Err ( e) => {
111
111
cx. span_err ( sp, format ! ( "couldn't read {}: {}" , file. display( ) , e) ) ;
112
- return MacResult :: dummy_expr ( sp) ;
112
+ return DummyResult :: expr ( sp) ;
113
113
}
114
114
Ok ( bytes) => bytes,
115
115
} ;
@@ -121,31 +121,31 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
121
121
let interned = token:: intern_and_get_ident ( src) ;
122
122
cx. codemap ( ) . new_filemap ( filename, src. to_owned ( ) ) ;
123
123
124
- base:: MRExpr ( cx. expr_str ( sp, interned) )
124
+ base:: MacExpr :: new ( cx. expr_str ( sp, interned) )
125
125
}
126
126
None => {
127
127
cx. span_err ( sp, format ! ( "{} wasn't a utf-8 file" , file. display( ) ) ) ;
128
- return MacResult :: dummy_expr ( sp) ;
128
+ return DummyResult :: expr ( sp) ;
129
129
}
130
130
}
131
131
}
132
132
133
133
pub fn expand_include_bin ( cx : & mut ExtCtxt , sp : Span , tts : & [ ast:: TokenTree ] )
134
- -> base:: MacResult
134
+ -> ~ base:: MacResult
135
135
{
136
136
let file = match get_single_str_from_tts ( cx, sp, tts, "include_bin!" ) {
137
137
Some ( f) => f,
138
- None => return MacResult :: dummy_expr ( sp)
138
+ None => return DummyResult :: expr ( sp)
139
139
} ;
140
140
let file = res_rel_file ( cx, sp, & Path :: new ( file) ) ;
141
141
match File :: open ( & file) . read_to_end ( ) {
142
142
Err ( e) => {
143
143
cx. span_err ( sp, format ! ( "couldn't read {}: {}" , file. display( ) , e) ) ;
144
- return MacResult :: dummy_expr ( sp) ;
144
+ return DummyResult :: expr ( sp) ;
145
145
}
146
146
Ok ( bytes) => {
147
147
let bytes = bytes. iter ( ) . map ( |x| * x) . collect ( ) ;
148
- base:: MRExpr ( cx. expr_lit ( sp, ast:: LitBinary ( Rc :: new ( bytes) ) ) )
148
+ base:: MacExpr :: new ( cx. expr_lit ( sp, ast:: LitBinary ( Rc :: new ( bytes) ) ) )
149
149
}
150
150
}
151
151
}
5 commit comments
bors commentedon Apr 16, 2014
saw approval from sfackler
at huonw@99dd591
bors commentedon Apr 16, 2014
merging huonw/rust/macro-expander-trait = 99dd591 into auto
bors commentedon Apr 16, 2014
huonw/rust/macro-expander-trait = 99dd591 merged ok, testing candidate = 61f788c
bors commentedon Apr 16, 2014
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/5270
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/5266
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/4359
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/4372
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/5368
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/4455
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/4463
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/5370
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/4455
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/4461
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android/builds/4525
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/2255
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/5365
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/4462
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/4475
bors commentedon Apr 16, 2014
fast-forwarding master to auto = 61f788c