Skip to content

Commit be03313

Browse files
committed
---
yaml --- r: 40279 b: refs/heads/dist-snap c: 4876eb7 h: refs/heads/master i: 40277: 7cf9a17 40275: b88e0f2 40271: 6a17365 v: v3
1 parent f59cf12 commit be03313

File tree

3 files changed

+83
-20
lines changed

3 files changed

+83
-20
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
99
refs/heads/incoming: e90142e536c150df0d9b4b2f11352152177509b5
10-
refs/heads/dist-snap: caf68038dd5bc129a3a9b6972a64c0752b73a004
10+
refs/heads/dist-snap: 4876eb708c122567a9b4bb47667d14d262b181e4
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libcore/extfmt.rs

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,38 @@ pub mod ct {
6565
FlagSignAlways,
6666
FlagAlternate,
6767
}
68+
#[cfg(stage0)]
6869
pub enum Count {
6970
CountIs(int),
7071
CountIsParam(int),
7172
CountIsNextParam,
7273
CountImplied,
7374
}
75+
#[cfg(stage1)]
76+
#[cfg(stage2)]
77+
pub enum Count {
78+
CountIs(uint),
79+
CountIsParam(uint),
80+
CountIsNextParam,
81+
CountImplied,
82+
}
7483

75-
// A formatted conversion from an expression to a string
84+
#[cfg(stage0)]
7685
pub type Conv =
7786
{param: Option<int>,
7887
flags: ~[Flag],
7988
width: Count,
8089
precision: Count,
8190
ty: Ty};
91+
#[cfg(stage1)]
92+
#[cfg(stage2)]
93+
// A formatted conversion from an expression to a string
94+
pub type Conv =
95+
{param: Option<uint>,
96+
flags: ~[Flag],
97+
width: Count,
98+
precision: Count,
99+
ty: Ty};
82100

83101

84102
// A fragment of the output sequence
@@ -158,8 +176,26 @@ pub mod ct {
158176
ty: ty.ty}),
159177
next: ty.next};
160178
}
179+
#[cfg(stage0)]
161180
pub fn parse_parameter(s: &str, i: uint, lim: uint) ->
162181
{param: Option<int>, next: uint} {
182+
if i >= lim { return {param: None, next: i}; }
183+
let num = peek_num(s, i, lim);
184+
return match num {
185+
None => {param: None, next: i},
186+
Some(t) => {
187+
let n = t.num as int;
188+
let j = t.next;
189+
if j < lim && s[j] == '$' as u8 {
190+
{param: Some(n), next: j + 1}
191+
} else { {param: None, next: i} }
192+
}
193+
};
194+
}
195+
#[cfg(stage1)]
196+
#[cfg(stage2)]
197+
pub fn parse_parameter(s: &str, i: uint, lim: uint) ->
198+
{param: Option<uint>, next: uint} {
163199
if i >= lim { return {param: None, next: i}; }
164200
let num = peek_num(s, i, lim);
165201
return match num {
@@ -168,7 +204,7 @@ pub mod ct {
168204
let n = t.num;
169205
let j = t.next;
170206
if j < lim && s[j] == '$' as u8 {
171-
{param: Some(n as int), next: j + 1u}
207+
{param: Some(n), next: j + 1}
172208
} else { {param: None, next: i} }
173209
}
174210
};
@@ -201,12 +237,13 @@ pub mod ct {
201237
more(FlagAlternate, s, i, lim)
202238
} else { {flags: move noflags, next: i} };
203239
}
240+
#[cfg(stage0)]
204241
pub fn parse_count(s: &str, i: uint, lim: uint)
205242
-> {count: Count, next: uint} {
206243
return if i >= lim {
207244
{count: CountImplied, next: i}
208245
} else if s[i] == '*' as u8 {
209-
let param = parse_parameter(s, i + 1u, lim);
246+
let param = parse_parameter(s, i + 1, lim);
210247
let j = param.next;
211248
match param.param {
212249
None => {count: CountIsNextParam, next: j},
@@ -223,6 +260,30 @@ pub mod ct {
223260
}
224261
};
225262
}
263+
#[cfg(stage1)]
264+
#[cfg(stage2)]
265+
pub fn parse_count(s: &str, i: uint, lim: uint)
266+
-> {count: Count, next: uint} {
267+
return if i >= lim {
268+
{count: CountImplied, next: i}
269+
} else if s[i] == '*' as u8 {
270+
let param = parse_parameter(s, i + 1, lim);
271+
let j = param.next;
272+
match param.param {
273+
None => {count: CountIsNextParam, next: j},
274+
Some(n) => {count: CountIsParam(n), next: j}
275+
}
276+
} else {
277+
let num = peek_num(s, i, lim);
278+
match num {
279+
None => {count: CountImplied, next: i},
280+
Some(num) => {
281+
count: CountIs(num.num),
282+
next: num.next
283+
}
284+
}
285+
};
286+
}
226287
pub fn parse_precision(s: &str, i: uint, lim: uint) ->
227288
{count: Count, next: uint} {
228289
return if i >= lim {
@@ -285,7 +346,12 @@ pub mod rt {
285346
pub const flag_sign_always : u32 = 0b00000000001000u32;
286347
pub const flag_alternate : u32 = 0b00000000010000u32;
287348
349+
#[cfg(stage0)]
288350
pub enum Count { CountIs(int), CountImplied, }
351+
#[cfg(stage1)]
352+
#[cfg(stage2)]
353+
pub enum Count { CountIs(uint), CountImplied, }
354+
289355
pub enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, }
290356
291357
pub type Conv = {flags: u32, width: Count, precision: Count, ty: Ty};
@@ -307,11 +373,11 @@ pub mod rt {
307373
let prec = get_int_precision(cv);
308374
let mut rs =
309375
match cv.ty {
310-
TyDefault => uint_to_str_prec(u, 10u, prec),
311-
TyHexLower => uint_to_str_prec(u, 16u, prec),
312-
TyHexUpper => str::to_upper(uint_to_str_prec(u, 16u, prec)),
313-
TyBits => uint_to_str_prec(u, 2u, prec),
314-
TyOctal => uint_to_str_prec(u, 8u, prec)
376+
TyDefault => uint_to_str_prec(u, 10, prec),
377+
TyHexLower => uint_to_str_prec(u, 16, prec),
378+
TyHexUpper => str::to_upper(uint_to_str_prec(u, 16, prec)),
379+
TyBits => uint_to_str_prec(u, 2, prec),
380+
TyOctal => uint_to_str_prec(u, 8, prec)
315381
};
316382
return unsafe { pad(cv, move rs, PadUnsigned) };
317383
}
@@ -331,7 +397,7 @@ pub mod rt {
331397
let mut unpadded = match cv.precision {
332398
CountImplied => s.to_owned(),
333399
CountIs(max) => if max as uint < str::char_len(s) {
334-
str::substr(s, 0u, max as uint)
400+
str::substr(s, 0, max as uint)
335401
} else {
336402
s.to_owned()
337403
}
@@ -412,10 +478,7 @@ pub mod rt {
412478
let mut s = move s; // sadtimes
413479
let uwidth : uint = match cv.width {
414480
CountImplied => return (move s),
415-
CountIs(width) => {
416-
// FIXME: width should probably be uint (see Issue #1996)
417-
width as uint
418-
}
481+
CountIs(width) => { width as uint }
419482
};
420483
let strlen = str::char_len(s);
421484
if uwidth <= strlen { return (move s); }

branches/dist-snap/src/libsyntax/ext/fmt.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
7171
return make_rt_path_expr(cx, sp, @~"CountImplied");
7272
}
7373
CountIs(c) => {
74-
let count_lit = mk_int(cx, sp, c);
74+
let count_lit = mk_uint(cx, sp, c as uint);
7575
let count_is_path = make_path_vec(cx, @~"CountIs");
7676
let count_is_args = ~[count_lit];
7777
return mk_call(cx, sp, count_is_path, count_is_args);
@@ -193,7 +193,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
193193
}
194194
fn log_conv(c: Conv) {
195195
match c.param {
196-
Some(p) => { log(debug, ~"param: " + int::to_str(p, 10u)); }
196+
Some(p) => { log(debug, ~"param: " + p.to_str()); }
197197
_ => debug!("param: none")
198198
}
199199
for c.flags.each |f| {
@@ -207,17 +207,17 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
207207
}
208208
match c.width {
209209
CountIs(i) => log(
210-
debug, ~"width: count is " + int::to_str(i, 10u)),
210+
debug, ~"width: count is " + i.to_str()),
211211
CountIsParam(i) => log(
212-
debug, ~"width: count is param " + int::to_str(i, 10u)),
212+
debug, ~"width: count is param " + i.to_str()),
213213
CountIsNextParam => debug!("width: count is next param"),
214214
CountImplied => debug!("width: count is implied")
215215
}
216216
match c.precision {
217217
CountIs(i) => log(
218-
debug, ~"prec: count is " + int::to_str(i, 10u)),
218+
debug, ~"prec: count is " + i.to_str()),
219219
CountIsParam(i) => log(
220-
debug, ~"prec: count is param " + int::to_str(i, 10u)),
220+
debug, ~"prec: count is param " + i.to_str()),
221221
CountIsNextParam => debug!("prec: count is next param"),
222222
CountImplied => debug!("prec: count is implied")
223223
}

0 commit comments

Comments
 (0)