Skip to content

Commit 3911e0e

Browse files
committed
---
yaml --- r: 57323 b: refs/heads/incoming c: 0ca1885 h: refs/heads/master i: 57321: c4616db 57319: 965b97d v: v3
1 parent 5e64394 commit 3911e0e

File tree

15 files changed

+92
-125
lines changed

15 files changed

+92
-125
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: bf67eb2362b7d0f37012f2d6dac604c3bbacd2c6
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/incoming: 0c2ceb1a2e93e2e7624d384e19da6783cbb720ba
9+
refs/heads/incoming: 0ca1885da133cb7e4a1f4d557cfde5d16ac68231
1010
refs/heads/dist-snap: 00dbbd01c2aee72982b3e0f9511ae1d4428c3ba9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/num/f32.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ impl num::ToStrRadix for f32 {
507507
#[inline(always)]
508508
pub fn from_str(num: &str) -> Option<f32> {
509509
strconv::from_str_common(num, 10u, true, true, true,
510-
strconv::ExpDec, false, false)
510+
strconv::ExpDec, false)
511511
}
512512

513513
/**
@@ -540,7 +540,7 @@ pub fn from_str(num: &str) -> Option<f32> {
540540
#[inline(always)]
541541
pub fn from_str_hex(num: &str) -> Option<f32> {
542542
strconv::from_str_common(num, 16u, true, true, true,
543-
strconv::ExpBin, false, false)
543+
strconv::ExpBin, false)
544544
}
545545

546546
/**
@@ -565,7 +565,7 @@ pub fn from_str_hex(num: &str) -> Option<f32> {
565565
#[inline(always)]
566566
pub fn from_str_radix(num: &str, rdx: uint) -> Option<f32> {
567567
strconv::from_str_common(num, rdx, true, true, false,
568-
strconv::ExpNone, false, false)
568+
strconv::ExpNone, false)
569569
}
570570

571571
impl from_str::FromStr for f32 {

branches/incoming/src/libcore/num/f64.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ impl num::ToStrRadix for f64 {
529529
#[inline(always)]
530530
pub fn from_str(num: &str) -> Option<f64> {
531531
strconv::from_str_common(num, 10u, true, true, true,
532-
strconv::ExpDec, false, false)
532+
strconv::ExpDec, false)
533533
}
534534

535535
/**
@@ -562,7 +562,7 @@ pub fn from_str(num: &str) -> Option<f64> {
562562
#[inline(always)]
563563
pub fn from_str_hex(num: &str) -> Option<f64> {
564564
strconv::from_str_common(num, 16u, true, true, true,
565-
strconv::ExpBin, false, false)
565+
strconv::ExpBin, false)
566566
}
567567

568568
/**
@@ -587,7 +587,7 @@ pub fn from_str_hex(num: &str) -> Option<f64> {
587587
#[inline(always)]
588588
pub fn from_str_radix(num: &str, rdx: uint) -> Option<f64> {
589589
strconv::from_str_common(num, rdx, true, true, false,
590-
strconv::ExpNone, false, false)
590+
strconv::ExpNone, false)
591591
}
592592

593593
impl from_str::FromStr for f64 {

branches/incoming/src/libcore/num/float.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl num::ToStrRadix for float {
242242
#[inline(always)]
243243
pub fn from_str(num: &str) -> Option<float> {
244244
strconv::from_str_common(num, 10u, true, true, true,
245-
strconv::ExpDec, false, false)
245+
strconv::ExpDec, false)
246246
}
247247
248248
/**
@@ -275,7 +275,7 @@ pub fn from_str(num: &str) -> Option<float> {
275275
#[inline(always)]
276276
pub fn from_str_hex(num: &str) -> Option<float> {
277277
strconv::from_str_common(num, 16u, true, true, true,
278-
strconv::ExpBin, false, false)
278+
strconv::ExpBin, false)
279279
}
280280
281281
/**
@@ -300,7 +300,7 @@ pub fn from_str_hex(num: &str) -> Option<float> {
300300
#[inline(always)]
301301
pub fn from_str_radix(num: &str, radix: uint) -> Option<float> {
302302
strconv::from_str_common(num, radix, true, true, false,
303-
strconv::ExpNone, false, false)
303+
strconv::ExpNone, false)
304304
}
305305
306306
impl from_str::FromStr for float {

branches/incoming/src/libcore/num/int-template.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,21 @@ impl ops::Neg<T> for T {
202202
#[inline(always)]
203203
pub fn from_str(s: &str) -> Option<T> {
204204
strconv::from_str_common(s, 10u, true, false, false,
205-
strconv::ExpNone, false, false)
205+
strconv::ExpNone, false)
206206
}
207207
208208
/// Parse a string as a number in the given base.
209209
#[inline(always)]
210210
pub fn from_str_radix(s: &str, radix: uint) -> Option<T> {
211211
strconv::from_str_common(s, radix, true, false, false,
212-
strconv::ExpNone, false, false)
212+
strconv::ExpNone, false)
213213
}
214214
215215
/// Parse a byte slice as a number in the given base.
216216
#[inline(always)]
217217
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
218218
strconv::from_str_bytes_common(buf, radix, true, false, false,
219-
strconv::ExpNone, false, false)
219+
strconv::ExpNone, false)
220220
}
221221
222222
impl FromStr for T {

branches/incoming/src/libcore/num/strconv.rs

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -429,8 +429,6 @@ priv static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u;
429429
* `FFp128`. The exponent string itself is always base 10.
430430
* Can conflict with `radix`, see Failure.
431431
* - `empty_zero` - Whether to accept a empty `buf` as a 0 or not.
432-
* - `ignore_underscores` - Whether all underscores within the string should
433-
* be ignored.
434432
*
435433
* # Return value
436434
* Returns `Some(n)` if `buf` parses to a number n without overflowing, and
@@ -445,13 +443,16 @@ priv static DIGIT_E_RADIX: uint = ('e' as uint) - ('a' as uint) + 11u;
445443
* between digit and exponent sign `'p'`.
446444
* - Fails if `radix` > 18 and `special == true` due to conflict
447445
* between digit and lowest first character in `inf` and `NaN`, the `'i'`.
446+
*
447+
* # Possible improvements
448+
* - Could accept option to allow ignoring underscores, allowing for numbers
449+
* formated like `FF_AE_FF_FF`.
448450
*/
449-
pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
451+
pub fn from_str_bytes_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+
450452
Mul<T,T>+Sub<T,T>+Neg<T>+Add<T,T>+
451453
NumStrConv>(
452454
buf: &[u8], radix: uint, negative: bool, fractional: bool,
453-
special: bool, exponent: ExponentFormat, empty_zero: bool,
454-
ignore_underscores: bool
455+
special: bool, exponent: ExponentFormat, empty_zero: bool
455456
) -> Option<T> {
456457
match exponent {
457458
ExpDec if radix >= DIGIT_E_RADIX // decimal exponent 'e'
@@ -530,16 +531,12 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
530531
accum -= cast(digit as int);
531532
}
532533

533-
// Detect overflow by comparing to last value, except
534-
// if we've not seen any non-zero digits.
535-
if last_accum != _0 {
536-
if accum_positive && accum <= last_accum { return None; }
537-
if !accum_positive && accum >= last_accum { return None; }
538-
}
534+
// Detect overflow by comparing to last value
535+
if accum_positive && accum < last_accum { return None; }
536+
if !accum_positive && accum > last_accum { return None; }
539537
last_accum = accum;
540538
}
541539
None => match c {
542-
'_' if ignore_underscores => {}
543540
'e' | 'E' | 'p' | 'P' => {
544541
exp_found = true;
545542
break; // start of exponent
@@ -583,7 +580,6 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
583580
last_accum = accum;
584581
}
585582
None => match c {
586-
'_' if ignore_underscores => {}
587583
'e' | 'E' | 'p' | 'P' => {
588584
exp_found = true;
589585
break; // start of exponent
@@ -611,7 +607,6 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
611607
if exp_found {
612608
let c = buf[i] as char;
613609
let base = match (c, exponent) {
614-
// c is never _ so don't need to handle specially
615610
('e', ExpDec) | ('E', ExpDec) => 10u,
616611
('p', ExpBin) | ('P', ExpBin) => 2u,
617612
_ => return None // char doesn't fit given exponent format
@@ -620,8 +615,7 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
620615
// parse remaining bytes as decimal integer,
621616
// skipping the exponent char
622617
let exp: Option<int> = from_str_bytes_common(
623-
buf.slice(i+1, len), 10, true, false, false, ExpNone, false,
624-
ignore_underscores);
618+
buf.slice(i+1, len), 10, true, false, false, ExpNone, false);
625619

626620
match exp {
627621
Some(exp_pow) => {
@@ -643,44 +637,11 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+
643637
* `from_str_bytes_common()`, for details see there.
644638
*/
645639
#[inline(always)]
646-
pub fn from_str_common<T:NumCast+Zero+One+Eq+Ord+Copy+Div<T,T>+Mul<T,T>+
640+
pub fn from_str_common<T:NumCast+Zero+One+Ord+Copy+Div<T,T>+Mul<T,T>+
647641
Sub<T,T>+Neg<T>+Add<T,T>+NumStrConv>(
648642
buf: &str, radix: uint, negative: bool, fractional: bool,
649-
special: bool, exponent: ExponentFormat, empty_zero: bool,
650-
ignore_underscores: bool
643+
special: bool, exponent: ExponentFormat, empty_zero: bool
651644
) -> Option<T> {
652645
from_str_bytes_common(str::to_bytes(buf), radix, negative,
653-
fractional, special, exponent, empty_zero,
654-
ignore_underscores)
655-
}
656-
657-
#[cfg(test)]
658-
mod test {
659-
use super::*;
660-
use option::*;
661-
662-
#[test]
663-
fn from_str_ignore_underscores() {
664-
let s : Option<u8> = from_str_common("__1__", 2, false, false, false,
665-
ExpNone, false, true);
666-
assert_eq!(s, Some(1u8));
667-
668-
let n : Option<u8> = from_str_common("__1__", 2, false, false, false,
669-
ExpNone, false, false);
670-
assert_eq!(n, None);
671-
672-
let f : Option<f32> = from_str_common("_1_._1_e_1_", 10, false, true, false,
673-
ExpDec, false, true);
674-
assert_eq!(f, Some(1.1e1f32));
675-
}
676-
677-
#[test]
678-
fn from_str_issue5770() {
679-
// try to parse 0b1_1111_1111 = 511 as a u8. Caused problems
680-
// since 255*2+1 == 255 (mod 256) so the overflow wasn't
681-
// detected.
682-
let n : Option<u8> = from_str_common("111111111", 2, false, false, false,
683-
ExpNone, false, false);
684-
assert_eq!(n, None);
685-
}
646+
fractional, special, exponent, empty_zero)
686647
}

branches/incoming/src/libcore/num/uint-template.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,21 @@ impl ops::Neg<T> for T {
168168
#[inline(always)]
169169
pub fn from_str(s: &str) -> Option<T> {
170170
strconv::from_str_common(s, 10u, false, false, false,
171-
strconv::ExpNone, false, false)
171+
strconv::ExpNone, false)
172172
}
173173
174174
/// Parse a string as a number in the given base.
175175
#[inline(always)]
176176
pub fn from_str_radix(s: &str, radix: uint) -> Option<T> {
177177
strconv::from_str_common(s, radix, false, false, false,
178-
strconv::ExpNone, false, false)
178+
strconv::ExpNone, false)
179179
}
180180
181181
/// Parse a byte slice as a number in the given base.
182182
#[inline(always)]
183183
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
184184
strconv::from_str_bytes_common(buf, radix, false, false, false,
185-
strconv::ExpNone, false, false)
185+
strconv::ExpNone, false)
186186
}
187187
188188
impl FromStr for T {

branches/incoming/src/libcore/reflect.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,21 +406,31 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
406406
disr_val: int,
407407
n_fields: uint,
408408
name: &str) -> bool {
409-
self.inner.push_ptr();
409+
self.inner.push_ptr(); // NOTE remove after next snapshot
410410
if ! self.inner.visit_enter_enum_variant(variant, disr_val,
411411
n_fields, name) {
412412
return false;
413413
}
414414
true
415415
}
416416

417+
#[cfg(stage0)]
417418
fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool {
418419
unsafe { self.align((*inner).align); }
419420
if ! self.inner.visit_enum_variant_field(i, inner) { return false; }
420421
unsafe { self.bump((*inner).size); }
421422
true
422423
}
423424

425+
#[cfg(not(stage0))]
426+
fn visit_enum_variant_field(&self, i: uint, offset: uint, inner: *TyDesc) -> bool {
427+
self.inner.push_ptr();
428+
self.bump(offset);
429+
if ! self.inner.visit_enum_variant_field(i, offset, inner) { return false; }
430+
self.inner.pop_ptr();
431+
true
432+
}
433+
424434
fn visit_leave_enum_variant(&self, variant: uint,
425435
disr_val: int,
426436
n_fields: uint,
@@ -429,7 +439,7 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
429439
n_fields, name) {
430440
return false;
431441
}
432-
self.inner.pop_ptr();
442+
self.inner.pop_ptr(); // NOTE remove after next snapshot
433443
true
434444
}
435445

branches/incoming/src/libcore/repr.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,14 @@ pub impl ReprVisitor {
193193
self.bump(sys::size_of::<T>());
194194
}
195195

196+
#[cfg(stage0)] #[inline(always)]
197+
fn stage0_bump_past<T>(&self) {
198+
self.bump_past::<T>();
199+
}
200+
#[cfg(not(stage0))] #[inline(always)]
201+
fn stage0_bump_past<T>(&self) {
202+
}
203+
196204
#[inline(always)]
197205
fn visit_inner(&self, inner: *TyDesc) -> bool {
198206
self.visit_ptr_inner(self.ptr, inner)
@@ -487,7 +495,7 @@ impl TyVisitor for ReprVisitor {
487495
self.var_stk.push(TagMismatch);
488496
}
489497
};
490-
self.bump_past::<int>();
498+
self.stage0_bump_past::<int>();
491499
}
492500
}
493501

@@ -500,6 +508,7 @@ impl TyVisitor for ReprVisitor {
500508
true
501509
}
502510

511+
#[cfg(stage0)]
503512
fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool {
504513
match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] {
505514
Degenerate | TagMatch => {
@@ -515,6 +524,22 @@ impl TyVisitor for ReprVisitor {
515524
true
516525
}
517526

527+
#[cfg(not(stage0))]
528+
fn visit_enum_variant_field(&self, i: uint, _offset: uint, inner: *TyDesc) -> bool {
529+
match self.var_stk[vec::uniq_len(&const self.var_stk) - 1] {
530+
Degenerate | TagMatch => {
531+
if i != 0 {
532+
self.writer.write_str(", ");
533+
}
534+
if ! self.visit_inner(inner) {
535+
return false;
536+
}
537+
}
538+
TagMismatch => ()
539+
}
540+
true
541+
}
542+
518543
fn visit_leave_enum_variant(&self, _variant: uint,
519544
_disr_val: int,
520545
n_fields: uint,

branches/incoming/src/librustc/front/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub mod intrinsic {
9696
disr_val: int,
9797
n_fields: uint,
9898
name: &str) -> bool;
99-
fn visit_enum_variant_field(&self, i: uint, inner: *TyDesc) -> bool;
99+
fn visit_enum_variant_field(&self, i: uint, offset: uint, inner: *TyDesc) -> bool;
100100
fn visit_leave_enum_variant(&self, variant: uint,
101101
disr_val: int,
102102
n_fields: uint,

0 commit comments

Comments
 (0)