@@ -65,59 +65,60 @@ fn expr_to_str(&ext_ctxt cx, @ast::expr expr) -> str {
65
65
fn pieces_to_expr( & ext_ctxt cx, parser p, common:: span sp,
66
66
vec[ piece] pieces , vec[ @ast:: expr] args ) -> @ast:: expr {
67
67
68
- fn make_new_lit ( parser p, common:: span sp, ast:: lit_ lit) -> @ast:: expr {
68
+ fn make_new_lit ( & ext_ctxt cx,
69
+ common:: span sp, ast:: lit_ lit) -> @ast:: expr {
69
70
auto sp_lit = @rec ( node=lit, span=sp) ;
70
- auto expr = ast:: expr_lit ( sp_lit, p . get_ann ( ) ) ;
71
+ auto expr = ast:: expr_lit ( sp_lit, cx . next_ann ( ) ) ;
71
72
ret @rec( node=expr, span=sp) ;
72
73
}
73
74
74
- fn make_new_str ( parser p , common:: span sp, str s) -> @ast:: expr {
75
+ fn make_new_str ( & ext_ctxt cx , common:: span sp, str s) -> @ast:: expr {
75
76
auto lit = ast:: lit_str ( s) ;
76
- ret make_new_lit ( p , sp, lit) ;
77
+ ret make_new_lit ( cx , sp, lit) ;
77
78
}
78
79
79
- fn make_new_int ( parser p , common:: span sp, int i) -> @ast:: expr {
80
+ fn make_new_int ( & ext_ctxt cx , common:: span sp, int i) -> @ast:: expr {
80
81
auto lit = ast:: lit_int ( i) ;
81
- ret make_new_lit ( p , sp, lit) ;
82
+ ret make_new_lit ( cx , sp, lit) ;
82
83
}
83
84
84
- fn make_new_uint ( parser p , common:: span sp, uint u) -> @ast:: expr {
85
+ fn make_new_uint ( & ext_ctxt cx , common:: span sp, uint u) -> @ast:: expr {
85
86
auto lit = ast:: lit_uint ( u) ;
86
- ret make_new_lit ( p , sp, lit) ;
87
+ ret make_new_lit ( cx , sp, lit) ;
87
88
}
88
89
89
- fn make_add_expr ( parser p , common:: span sp,
90
+ fn make_add_expr ( & ext_ctxt cx , common:: span sp,
90
91
@ast:: expr lhs, @ast:: expr rhs) -> @ast:: expr {
91
- auto binexpr = ast:: expr_binary ( ast:: add, lhs, rhs, p . get_ann ( ) ) ;
92
+ auto binexpr = ast:: expr_binary ( ast:: add, lhs, rhs, cx . next_ann ( ) ) ;
92
93
ret @rec( node=binexpr, span=sp) ;
93
94
}
94
95
95
- fn make_path_expr ( parser p , common:: span sp, vec[ ast:: ident ] idents )
96
+ fn make_path_expr ( & ext_ctxt cx , common:: span sp, vec[ ast:: ident ] idents )
96
97
-> @ast:: expr {
97
98
let vec[ @ast:: ty] types = [ ] ;
98
99
auto path = rec ( idents=idents, types=types) ;
99
100
auto sp_path = rec ( node=path, span=sp) ;
100
- auto pathexpr = ast:: expr_path ( sp_path, p . get_ann ( ) ) ;
101
+ auto pathexpr = ast:: expr_path ( sp_path, cx . next_ann ( ) ) ;
101
102
auto sp_pathexpr = @rec ( node=pathexpr, span=sp) ;
102
103
ret sp_pathexpr;
103
104
}
104
105
105
- fn make_vec_expr ( parser p , common:: span sp, vec[ @ast:: expr] exprs )
106
+ fn make_vec_expr ( & ext_ctxt cx , common:: span sp, vec[ @ast:: expr] exprs )
106
107
-> @ast:: expr {
107
- auto vecexpr = ast:: expr_vec ( exprs, ast:: imm, p . get_ann ( ) ) ;
108
+ auto vecexpr = ast:: expr_vec ( exprs, ast:: imm, cx . next_ann ( ) ) ;
108
109
auto sp_vecexpr = @rec ( node=vecexpr, span=sp) ;
109
110
ret sp_vecexpr;
110
111
}
111
112
112
- fn make_call ( parser p , common:: span sp, vec[ ast:: ident ] fn_path ,
113
+ fn make_call ( & ext_ctxt cx , common:: span sp, vec[ ast:: ident ] fn_path ,
113
114
vec[ @ast:: expr] args ) -> @ast:: expr {
114
- auto pathexpr = make_path_expr ( p , sp, fn_path) ;
115
- auto callexpr = ast:: expr_call ( pathexpr, args, p . get_ann ( ) ) ;
115
+ auto pathexpr = make_path_expr ( cx , sp, fn_path) ;
116
+ auto callexpr = ast:: expr_call ( pathexpr, args, cx . next_ann ( ) ) ;
116
117
auto sp_callexpr = @rec ( node=callexpr, span=sp) ;
117
118
ret sp_callexpr;
118
119
}
119
120
120
- fn make_rec_expr( parser p , common:: span sp,
121
+ fn make_rec_expr( & ext_ctxt cx , common:: span sp,
121
122
vec[ tup ( ast:: ident , @ast:: expr ) ] fields ) -> @ast:: expr {
122
123
let vec[ ast:: field] astfields = [ ] ;
123
124
for ( tup( ast:: ident, @ast:: expr) field in fields) {
@@ -131,7 +132,7 @@ fn pieces_to_expr(&ext_ctxt cx, parser p, common::span sp,
131
132
132
133
auto recexpr = ast:: expr_rec( astfields,
133
134
option:: none[ @ast:: expr] ,
134
- p . get_ann ( ) ) ;
135
+ cx . next_ann ( ) ) ;
135
136
auto sp_recexpr = @rec( node=recexpr, span=sp) ;
136
137
ret sp_recexpr;
137
138
}
@@ -142,17 +143,18 @@ fn pieces_to_expr(&ext_ctxt cx, parser p, common::span sp,
142
143
ret [ "std" , "extfmt" , "rt" , ident] ;
143
144
}
144
145
145
- fn make_rt_path_expr( parser p, common:: span sp, str ident) -> @ast:: expr {
146
+ fn make_rt_path_expr( & ext_ctxt cx,
147
+ common:: span sp, str ident) -> @ast:: expr {
146
148
auto path = make_path_vec( ident) ;
147
- ret make_path_expr( p , sp, path) ;
149
+ ret make_path_expr( cx , sp, path) ;
148
150
}
149
151
150
152
// Produces an AST expression that represents a RT::conv record,
151
153
// which tells the RT::conv* functions how to perform the conversion
152
154
fn make_rt_conv_expr( & ext_ctxt cx,
153
- parser p , common:: span sp, & conv cnv) -> @ast:: expr {
155
+ common:: span sp, & conv cnv) -> @ast:: expr {
154
156
155
- fn make_flags( parser p , common:: span sp, vec[ flag] flags)
157
+ fn make_flags( & ext_ctxt cx , common:: span sp, vec[ flag] flags)
156
158
-> @ast:: expr {
157
159
let vec[ @ast:: expr] flagexprs = [ ] ;
158
160
for ( flag f in flags) {
@@ -174,38 +176,38 @@ fn pieces_to_expr(&ext_ctxt cx, parser p, common::span sp,
174
176
fstr = "flag_alternate" ;
175
177
}
176
178
}
177
- flagexprs += [ make_rt_path_expr( p , sp, fstr) ] ;
179
+ flagexprs += [ make_rt_path_expr( cx , sp, fstr) ] ;
178
180
}
179
181
180
182
// FIXME: 0-length vectors can't have their type inferred
181
183
// through the rec that these flags are a member of, so
182
184
// this is a hack placeholder flag
183
185
if ( vec:: len[ @ast:: expr] ( flagexprs) == 0 u) {
184
- flagexprs += [ make_rt_path_expr( p , sp, "flag_none" ) ] ;
186
+ flagexprs += [ make_rt_path_expr( cx , sp, "flag_none" ) ] ;
185
187
}
186
188
187
- ret make_vec_expr( p , sp, flagexprs) ;
189
+ ret make_vec_expr( cx , sp, flagexprs) ;
188
190
}
189
191
190
192
fn make_count( & ext_ctxt cx,
191
- parser p , common:: span sp, & count cnt) -> @ast:: expr {
193
+ common:: span sp, & count cnt) -> @ast:: expr {
192
194
alt ( cnt) {
193
195
case ( count_implied) {
194
- ret make_rt_path_expr( p , sp, "count_implied" ) ;
196
+ ret make_rt_path_expr( cx , sp, "count_implied" ) ;
195
197
}
196
198
case ( count_is( ?c) ) {
197
- auto count_lit = make_new_int( p , sp, c) ;
199
+ auto count_lit = make_new_int( cx , sp, c) ;
198
200
auto count_is_path = make_path_vec( "count_is" ) ;
199
201
auto count_is_args = [ count_lit] ;
200
- ret make_call( p , sp, count_is_path, count_is_args) ;
202
+ ret make_call( cx , sp, count_is_path, count_is_args) ;
201
203
}
202
204
case ( _) {
203
205
cx. span_unimpl( sp, "unimplemented #fmt conversion" ) ;
204
206
}
205
207
}
206
208
}
207
209
208
- fn make_ty( parser p , common:: span sp, & ty t) -> @ast:: expr {
210
+ fn make_ty( & ext_ctxt cx , common:: span sp, & ty t) -> @ast:: expr {
209
211
auto rt_type;
210
212
alt ( t) {
211
213
case ( ty_hex( ?c) ) {
@@ -229,43 +231,43 @@ fn pieces_to_expr(&ext_ctxt cx, parser p, common::span sp,
229
231
}
230
232
}
231
233
232
- ret make_rt_path_expr( p , sp, rt_type) ;
234
+ ret make_rt_path_expr( cx , sp, rt_type) ;
233
235
}
234
236
235
- fn make_conv_rec( parser p ,
237
+ fn make_conv_rec( & ext_ctxt cx ,
236
238
common:: span sp,
237
239
@ast:: expr flags_expr,
238
240
@ast:: expr width_expr,
239
241
@ast:: expr precision_expr,
240
242
@ast:: expr ty_expr) -> @ast:: expr {
241
- ret make_rec_expr( p , sp, [ tup( "flags" , flags_expr) ,
243
+ ret make_rec_expr( cx , sp, [ tup( "flags" , flags_expr) ,
242
244
tup( "width" , width_expr) ,
243
245
tup( "precision" , precision_expr) ,
244
246
tup( "ty" , ty_expr) ] ) ;
245
247
}
246
248
247
- auto rt_conv_flags = make_flags( p , sp, cnv. flags) ;
248
- auto rt_conv_width = make_count( cx, p , sp, cnv. width) ;
249
- auto rt_conv_precision = make_count( cx, p , sp, cnv. precision) ;
250
- auto rt_conv_ty = make_ty( p , sp, cnv. ty) ;
251
- ret make_conv_rec( p ,
249
+ auto rt_conv_flags = make_flags( cx , sp, cnv. flags) ;
250
+ auto rt_conv_width = make_count( cx, sp, cnv. width) ;
251
+ auto rt_conv_precision = make_count( cx, sp, cnv. precision) ;
252
+ auto rt_conv_ty = make_ty( cx , sp, cnv. ty) ;
253
+ ret make_conv_rec( cx ,
252
254
sp,
253
255
rt_conv_flags,
254
256
rt_conv_width,
255
257
rt_conv_precision,
256
258
rt_conv_ty) ;
257
259
}
258
260
259
- fn make_conv_call( & ext_ctxt cx, parser p , common:: span sp, str conv_type,
261
+ fn make_conv_call( & ext_ctxt cx, common:: span sp, str conv_type,
260
262
& conv cnv, @ast:: expr arg) -> @ast:: expr {
261
263
auto fname = "conv_" + conv_type;
262
264
auto path = make_path_vec( fname) ;
263
- auto cnv_expr = make_rt_conv_expr( cx, p , sp, cnv) ;
265
+ auto cnv_expr = make_rt_conv_expr( cx, sp, cnv) ;
264
266
auto args = [ cnv_expr, arg] ;
265
- ret make_call( p , arg. span, path, args) ;
267
+ ret make_call( cx , arg. span, path, args) ;
266
268
}
267
269
268
- fn make_new_conv( & ext_ctxt cx, parser p , common:: span sp,
270
+ fn make_new_conv( & ext_ctxt cx, common:: span sp,
269
271
conv cnv, @ast:: expr arg) -> @ast:: expr {
270
272
271
273
// FIXME: Extract all this validation into extfmt::ct
@@ -343,32 +345,32 @@ fn pieces_to_expr(&ext_ctxt cx, parser p, common::span sp,
343
345
344
346
alt ( cnv. ty) {
345
347
case ( ty_str) {
346
- ret make_conv_call( cx, p , arg. span, "str" , cnv, arg) ;
348
+ ret make_conv_call( cx, arg. span, "str" , cnv, arg) ;
347
349
}
348
350
case ( ty_int( ?sign) ) {
349
351
alt ( sign) {
350
352
case ( signed) {
351
- ret make_conv_call( cx, p , arg. span, "int" , cnv, arg) ;
353
+ ret make_conv_call( cx, arg. span, "int" , cnv, arg) ;
352
354
}
353
355
case ( unsigned) {
354
- ret make_conv_call( cx, p , arg. span, "uint" , cnv, arg) ;
356
+ ret make_conv_call( cx, arg. span, "uint" , cnv, arg) ;
355
357
}
356
358
}
357
359
}
358
360
case ( ty_bool) {
359
- ret make_conv_call( cx, p , arg. span, "bool" , cnv, arg) ;
361
+ ret make_conv_call( cx, arg. span, "bool" , cnv, arg) ;
360
362
}
361
363
case ( ty_char) {
362
- ret make_conv_call( cx, p , arg. span, "char" , cnv, arg) ;
364
+ ret make_conv_call( cx, arg. span, "char" , cnv, arg) ;
363
365
}
364
366
case ( ty_hex( _) ) {
365
- ret make_conv_call( cx, p , arg. span, "uint" , cnv, arg) ;
367
+ ret make_conv_call( cx, arg. span, "uint" , cnv, arg) ;
366
368
}
367
369
case ( ty_bits) {
368
- ret make_conv_call( cx, p , arg. span, "uint" , cnv, arg) ;
370
+ ret make_conv_call( cx, arg. span, "uint" , cnv, arg) ;
369
371
}
370
372
case ( ty_octal) {
371
- ret make_conv_call( cx, p , arg. span, "uint" , cnv, arg) ;
373
+ ret make_conv_call( cx, arg. span, "uint" , cnv, arg) ;
372
374
}
373
375
case ( _) {
374
376
cx. span_unimpl( sp, unsupported) ;
@@ -470,14 +472,14 @@ fn pieces_to_expr(&ext_ctxt cx, parser p, common::span sp,
470
472
471
473
auto fmt_sp = args. ( 0 ) . span;
472
474
auto n = 0 u;
473
- auto tmp_expr = make_new_str( p , sp, "" ) ;
475
+ auto tmp_expr = make_new_str( cx , sp, "" ) ;
474
476
auto nargs = vec:: len[ @ast:: expr] ( args) ;
475
477
476
478
for ( piece pc in pieces) {
477
479
alt ( pc) {
478
480
case ( piece_string( ?s) ) {
479
- auto s_expr = make_new_str( p , fmt_sp, s) ;
480
- tmp_expr = make_add_expr( p , fmt_sp, tmp_expr, s_expr) ;
481
+ auto s_expr = make_new_str( cx , fmt_sp, s) ;
482
+ tmp_expr = make_add_expr( cx , fmt_sp, tmp_expr, s_expr) ;
481
483
}
482
484
case ( piece_conv( ?conv) ) {
483
485
n += 1 u;
@@ -492,8 +494,8 @@ fn pieces_to_expr(&ext_ctxt cx, parser p, common::span sp,
492
494
//log_conv(conv);
493
495
494
496
auto arg_expr = args. ( n) ;
495
- auto c_expr = make_new_conv( cx, p , fmt_sp, conv, arg_expr) ;
496
- tmp_expr = make_add_expr( p , fmt_sp, tmp_expr, c_expr) ;
497
+ auto c_expr = make_new_conv( cx, fmt_sp, conv, arg_expr) ;
498
+ tmp_expr = make_add_expr( cx , fmt_sp, tmp_expr, c_expr) ;
497
499
}
498
500
}
499
501
}
0 commit comments