Skip to content

Commit 074184d

Browse files
committed
---
yaml --- r: 64193 b: refs/heads/snap-stage3 c: f091a1e h: refs/heads/master i: 64191: 91e4ac4 v: v3
1 parent 531ecf3 commit 074184d

File tree

11 files changed

+40
-171
lines changed

11 files changed

+40
-171
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 9b5d52312622fb301d9e102b3eeca5a7afcdeb9b
4+
refs/heads/snap-stage3: f091a1e075b46b22f9df92acd2cf177e84ca1834
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libextra/json.rs

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616

1717
//! json serialization
1818
19-
20-
use std::char;
19+
use std::iterator;
2120
use std::float;
2221
use std::hashmap::HashMap;
23-
use std::io::{WriterUtil, ReaderUtil};
22+
use std::io::WriterUtil;
2423
use std::io;
2524
use std::str;
2625
use std::to_str;
@@ -481,24 +480,17 @@ pub fn to_pretty_str(json: &Json) -> ~str {
481480
io::with_str_writer(|wr| to_pretty_writer(wr, json))
482481
}
483482

484-
static BUF_SIZE : uint = 64000;
485-
486-
#[allow(missing_doc)]
487-
pub struct Parser {
488-
priv rdr: @io::Reader,
489-
priv buf: ~[char],
490-
priv buf_idx: uint,
483+
pub struct Parser<T> {
484+
priv rdr: ~T,
491485
priv ch: char,
492486
priv line: uint,
493487
priv col: uint,
494488
}
495489

496-
/// Decode a json value from an io::reader
497-
pub fn Parser(rdr: @io::Reader) -> Parser {
490+
/// Decode a json value from an Iterator<char>
491+
pub fn Parser<T : iterator::Iterator<char>>(rdr: ~T) -> Parser<T> {
498492
let mut p = Parser {
499493
rdr: rdr,
500-
buf: rdr.read_chars(BUF_SIZE),
501-
buf_idx: 0,
502494
ch: 0 as char,
503495
line: 1,
504496
col: 0,
@@ -507,7 +499,7 @@ pub fn Parser(rdr: @io::Reader) -> Parser {
507499
p
508500
}
509501

510-
impl Parser {
502+
impl<T: iterator::Iterator<char>> Parser<T> {
511503
pub fn parse(&mut self) -> Result<Json, Error> {
512504
match self.parse_value() {
513505
Ok(value) => {
@@ -525,30 +517,20 @@ impl Parser {
525517
}
526518
}
527519

528-
impl Parser {
520+
impl<T : iterator::Iterator<char>> Parser<T> {
529521
fn eof(&self) -> bool { self.ch == -1 as char }
530522

531523
fn bump(&mut self) {
532-
if self.eof() {
533-
return;
534-
}
535-
536-
self.col += 1u;
537-
538-
if self.buf_idx >= self.buf.len() {
539-
self.buf = self.rdr.read_chars(BUF_SIZE);
540-
if self.buf.len() == 0 {
541-
self.ch = -1 as char;
542-
return;
543-
}
544-
self.buf_idx = 0;
524+
match self.rdr.next() {
525+
Some(ch) => self.ch = ch,
526+
None() => self.ch = -1 as char,
545527
}
546-
self.ch = self.buf[self.buf_idx];
547-
self.buf_idx += 1;
548528

549529
if self.ch == '\n' {
550530
self.line += 1u;
551531
self.col = 1u;
532+
} else {
533+
self.col += 1u;
552534
}
553535
}
554536

@@ -583,7 +565,10 @@ impl Parser {
583565
}
584566

585567
fn parse_whitespace(&mut self) {
586-
while char::is_whitespace(self.ch) { self.bump(); }
568+
while self.ch == ' ' ||
569+
self.ch == '\n' ||
570+
self.ch == '\t' ||
571+
self.ch == '\r' { self.bump(); }
587572
}
588573

589574
fn parse_ident(&mut self, ident: &str, value: Json) -> Result<Json, Error> {
@@ -727,8 +712,11 @@ impl Parser {
727712
let mut escape = false;
728713
let mut res = ~"";
729714

730-
while !self.eof() {
715+
loop {
731716
self.bump();
717+
if self.eof() {
718+
return self.error(~"EOF while parsing string");
719+
}
732720

733721
if (escape) {
734722
match self.ch {
@@ -783,8 +771,6 @@ impl Parser {
783771
res.push_char(self.ch);
784772
}
785773
}
786-
787-
self.error(~"EOF while parsing string")
788774
}
789775

790776
fn parse_list(&mut self) -> Result<Json, Error> {
@@ -870,15 +856,15 @@ impl Parser {
870856

871857
/// Decodes a json value from an @io::Reader
872858
pub fn from_reader(rdr: @io::Reader) -> Result<Json, Error> {
873-
let mut parser = Parser(rdr);
859+
let s = str::from_bytes(rdr.read_whole_stream());
860+
let mut parser = Parser(~s.iter());
874861
parser.parse()
875862
}
876863

877864
/// Decodes a json value from a string
878865
pub fn from_str(s: &str) -> Result<Json, Error> {
879-
do io::with_str_reader(s) |rdr| {
880-
from_reader(rdr)
881-
}
866+
let mut parser = Parser(~s.iter());
867+
parser.parse()
882868
}
883869

884870
/// A structure to decode JSON to values in rust.
@@ -1744,7 +1730,7 @@ mod tests {
17441730
assert_eq!(v, 0.4e-01f);
17451731
}
17461732
1747-
// FIXME: #7611: xfailed for now
1733+
#[test]
17481734
fn test_read_str() {
17491735
assert_eq!(from_str("\""),
17501736
Err(Error {line: 1u, col: 2u, msg: @~"EOF while parsing string"

branches/snap-stage3/src/librustc/metadata/tydecode.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,8 +543,7 @@ pub fn parse_type_param_def_data(data: &[u8], start: uint,
543543
}
544544

545545
fn parse_type_param_def(st: &mut PState, conv: conv_did) -> ty::TypeParameterDef {
546-
ty::TypeParameterDef {ident: parse_ident(st, ':'),
547-
def_id: parse_def(st, NominalType, |x,y| conv(x,y)),
546+
ty::TypeParameterDef {def_id: parse_def(st, NominalType, |x,y| conv(x,y)),
548547
bounds: @parse_bounds(st, |x,y| conv(x,y))}
549548
}
550549

branches/snap-stage3/src/librustc/metadata/tyencode.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,6 @@ fn enc_bounds(w: @io::Writer, cx: @ctxt, bs: &ty::ParamBounds) {
416416
}
417417

418418
pub fn enc_type_param_def(w: @io::Writer, cx: @ctxt, v: &ty::TypeParameterDef) {
419-
w.write_str(cx.tcx.sess.str_of(v.ident));
420-
w.write_char(':');
421419
w.write_str((cx.ds)(v.def_id));
422420
w.write_char('|');
423421
enc_bounds(w, cx, v.bounds);

branches/snap-stage3/src/librustc/middle/subst.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ impl Subst for ty::ParamBounds {
130130
impl Subst for ty::TypeParameterDef {
131131
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> ty::TypeParameterDef {
132132
ty::TypeParameterDef {
133-
ident: self.ident,
134133
def_id: self.def_id,
135134
bounds: self.bounds.subst(tcx, substs)
136135
}

branches/snap-stage3/src/librustc/middle/ty.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,6 @@ impl ToStr for IntVarValue {
794794
}
795795

796796
pub struct TypeParameterDef {
797-
ident: ast::ident,
798797
def_id: ast::def_id,
799798
bounds: @ParamBounds
800799
}

branches/snap-stage3/src/librustc/middle/typeck/collect.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ use syntax::print::pprust::{path_to_str, explicit_self_to_str};
5959
use syntax::visit;
6060
use syntax::opt_vec::OptVec;
6161
use syntax::opt_vec;
62-
use syntax::parse::token::special_idents;
6362

6463
pub fn collect_item_types(ccx: @mut CrateCtxt, crate: &ast::crate) {
6564
fn collect_intrinsic_type(ccx: &CrateCtxt,
@@ -319,7 +318,6 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
319318
let self_trait_def = get_trait_def(ccx, local_def(trait_id));
320319
let self_trait_ref = self_trait_def.trait_ref.subst(tcx, &substs);
321320
new_type_param_defs.push(ty::TypeParameterDef {
322-
ident: special_idents::self_,
323321
def_id: dummy_defid,
324322
bounds: @ty::ParamBounds {
325323
builtin_bounds: ty::EmptyBuiltinBounds(),
@@ -1153,7 +1151,6 @@ pub fn ty_generics(ccx: &CrateCtxt,
11531151
let bounds = @compute_bounds(ccx, rp, generics,
11541152
param_ty, &param.bounds);
11551153
let def = ty::TypeParameterDef {
1156-
ident: param.ident,
11571154
def_id: local_def(param.id),
11581155
bounds: bounds
11591156
};

branches/snap-stage3/src/librustc/util/ppaux.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -435,17 +435,16 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
435435
ty_infer(infer_ty) => infer_ty.to_str(),
436436
ty_err => ~"[type error]",
437437
ty_param(param_ty {idx: id, def_id: did}) => {
438-
let param_def = cx.ty_param_defs.find(&did.node);
439-
let ident = match param_def {
440-
Some(def) => {
441-
cx.sess.str_of(def.ident).to_owned()
442-
}
443-
None => {
444-
// This should not happen...
445-
fmt!("BUG[%?]", id)
446-
}
447-
};
448-
if !cx.sess.verbose() { ident } else { fmt!("%s:%?", ident, did) }
438+
let mut parm = (('T' as uint) + id) as char;
439+
if (parm as uint) > ('Z' as uint) {
440+
parm = (parm as uint - 26) as char;
441+
}
442+
443+
if cx.sess.verbose() {
444+
fmt!("%c:%?", parm, did)
445+
} else {
446+
fmt!("%c", parm)
447+
}
449448
}
450449
ty_self(*) => ~"Self",
451450
ty_enum(did, ref substs) | ty_struct(did, ref substs) => {

branches/snap-stage3/src/libstd/ptr.rs

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ use option::{Option, Some, None};
1515
use sys;
1616
use unstable::intrinsics;
1717
use util::swap;
18-
use ops::{Add,Sub};
19-
use num::Int;
2018

2119
#[cfg(not(test))] use cmp::{Eq, Ord};
2220
use uint;
@@ -386,46 +384,6 @@ impl<T> Ord for *const T {
386384
}
387385
}
388386

389-
#[cfg(not(test))]
390-
impl<T, I: Int> Add<I, *T> for *T {
391-
/// Add an integer value to a pointer to get an offset pointer.
392-
/// Is calculated according to the size of the type pointed to.
393-
#[inline]
394-
pub fn add(&self, rhs: &I) -> *T {
395-
self.offset(rhs.to_int() as uint)
396-
}
397-
}
398-
399-
#[cfg(not(test))]
400-
impl<T, I: Int> Sub<I, *T> for *T {
401-
/// Subtract an integer value from a pointer to get an offset pointer.
402-
/// Is calculated according to the size of the type pointed to.
403-
#[inline]
404-
pub fn sub(&self, rhs: &I) -> *T {
405-
self.offset(-rhs.to_int() as uint)
406-
}
407-
}
408-
409-
#[cfg(not(test))]
410-
impl<T, I: Int> Add<I, *mut T> for *mut T {
411-
/// Add an integer value to a pointer to get an offset pointer.
412-
/// Is calculated according to the size of the type pointed to.
413-
#[inline]
414-
pub fn add(&self, rhs: &I) -> *mut T {
415-
self.offset(rhs.to_int() as uint)
416-
}
417-
}
418-
419-
#[cfg(not(test))]
420-
impl<T, I: Int> Sub<I, *mut T> for *mut T {
421-
/// Subtract an integer value from a pointer to get an offset pointer.
422-
/// Is calculated according to the size of the type pointed to.
423-
#[inline]
424-
pub fn sub(&self, rhs: &I) -> *mut T {
425-
self.offset(-rhs.to_int() as uint)
426-
}
427-
}
428-
429387
#[cfg(test)]
430388
pub mod ptr_tests {
431389
use super::*;
@@ -543,60 +501,6 @@ pub mod ptr_tests {
543501
}
544502
}
545503

546-
#[test]
547-
fn test_ptr_addition() {
548-
use vec::raw::*;
549-
550-
unsafe {
551-
let xs = ~[5, ..16];
552-
let mut ptr = to_ptr(xs);
553-
let end = ptr + 16;
554-
555-
while ptr < end {
556-
assert_eq!(*ptr, 5);
557-
ptr = ptr + 1u;
558-
}
559-
560-
let mut xs_mut = xs.clone();
561-
let mut m_ptr = to_mut_ptr(xs_mut);
562-
let m_end = m_ptr + 16i16;
563-
564-
while m_ptr < m_end {
565-
*m_ptr += 5;
566-
m_ptr = m_ptr + 1u8;
567-
}
568-
569-
assert_eq!(xs_mut, ~[10, ..16]);
570-
}
571-
}
572-
573-
#[test]
574-
fn test_ptr_subtraction() {
575-
use vec::raw::*;
576-
577-
unsafe {
578-
let xs = ~[0,1,2,3,4,5,6,7,8,9];
579-
let mut idx = 9i8;
580-
let ptr = to_ptr(xs);
581-
582-
while idx >= 0i8 {
583-
assert_eq!(*(ptr + idx), idx as int);
584-
idx = idx - 1i8;
585-
}
586-
587-
let mut xs_mut = xs.clone();
588-
let mut m_start = to_mut_ptr(xs_mut);
589-
let mut m_ptr = m_start + 9u32;
590-
591-
while m_ptr >= m_start {
592-
*m_ptr += *m_ptr;
593-
m_ptr = m_ptr - 1i8;
594-
}
595-
596-
assert_eq!(xs_mut, ~[0,2,4,6,8,10,12,14,16,18]);
597-
}
598-
}
599-
600504
#[test]
601505
fn test_ptr_array_each_with_len() {
602506
unsafe {

branches/snap-stage3/src/libstd/repr.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,11 @@ impl ReprVisitor {
206206
inner: *TyDesc)
207207
-> bool {
208208
let mut p = ptr;
209+
let end = ptr::offset(p, len);
209210
let (sz, al) = unsafe { ((*inner).size, (*inner).align) };
210211
self.writer.write_char('[');
211212
let mut first = true;
212-
let mut left = len;
213-
// unit structs have 0 size, and don't loop forever.
214-
let dec = if sz == 0 {1} else {sz};
215-
while left > 0 {
213+
while (p as uint) < (end as uint) {
216214
if first {
217215
first = false;
218216
} else {
@@ -221,7 +219,6 @@ impl ReprVisitor {
221219
self.write_mut_qualifier(mtbl);
222220
self.visit_ptr_inner(p as *c_void, inner);
223221
p = align(ptr::offset(p, sz) as uint, al) as *u8;
224-
left -= dec;
225222
}
226223
self.writer.write_char(']');
227224
true
@@ -638,7 +635,4 @@ fn test_repr() {
638635
"(10, ~\"hello\")");
639636
exact_test(&(10_u64, ~"hello"),
640637
"(10, ~\"hello\")");
641-
642-
struct Foo;
643-
exact_test(&(~[Foo, Foo, Foo]), "~[{}, {}, {}]");
644638
}

0 commit comments

Comments
 (0)