From 298ab6f45957591d13104e8c667e83928d2276a4 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 21 Sep 2012 19:04:06 -0700 Subject: [PATCH] Revert "core: De-export at_vec and extfmt" This reverts commit 6267d8a94a7a215be446f5a431a1aae029a4e357. --- src/libcore/at_vec.rs | 45 ++++++++++++-------- src/libcore/extfmt.rs | 98 +++++++++++++++++++++---------------------- 2 files changed, 75 insertions(+), 68 deletions(-) diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 9c348b9f90f..7864983bde2 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -2,24 +2,34 @@ use ptr::addr_of; +export init_op; +export capacity; +export build_sized, build, build_sized_opt; +export map; +export from_fn, from_elem; +export raw; +export traits; + /// Code for dealing with @-vectors. This is pretty incomplete, and /// contains a bunch of duplication from the code for ~-vectors. #[abi = "cdecl"] extern mod rustrt { - pub fn vec_reserve_shared_actual(++t: *sys::TypeDesc, + #[legacy_exports]; + fn vec_reserve_shared_actual(++t: *sys::TypeDesc, ++v: **vec::raw::VecRepr, ++n: libc::size_t); } #[abi = "rust-intrinsic"] extern mod rusti { - pub fn move_val_init(&dst: T, -src: T); + #[legacy_exports]; + fn move_val_init(&dst: T, -src: T); } /// Returns the number of elements the vector can hold without reallocating #[inline(always)] -pub pure fn capacity(&&v: @[const T]) -> uint { +pure fn capacity(&&v: @[const T]) -> uint { unsafe { let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(v)); @@ -40,8 +50,7 @@ pub pure fn capacity(&&v: @[const T]) -> uint { * onto the vector being constructed. */ #[inline(always)] -pub pure fn build_sized(size: uint, - builder: fn(push: pure fn(+A))) -> @[A] { +pure fn build_sized(size: uint, builder: fn(push: pure fn(+A))) -> @[A] { let mut vec = @[]; unsafe { raw::reserve(vec, size); } builder(|+x| unsafe { raw::push(vec, move x) }); @@ -59,7 +68,7 @@ pub pure fn build_sized(size: uint, * onto the vector being constructed. */ #[inline(always)] -pub pure fn build(builder: fn(push: pure fn(+A))) -> @[A] { +pure fn build(builder: fn(push: pure fn(+A))) -> @[A] { build_sized(4, builder) } @@ -76,7 +85,7 @@ pub pure fn build(builder: fn(push: pure fn(+A))) -> @[A] { * onto the vector being constructed. */ #[inline(always)] -pub pure fn build_sized_opt(size: Option, +pure fn build_sized_opt(size: Option, builder: fn(push: pure fn(+A))) -> @[A] { build_sized(size.get_default(4), builder) } @@ -92,7 +101,7 @@ pure fn append(lhs: @[T], rhs: &[const T]) -> @[T] { /// Apply a function to each element of a vector and return the results -pub pure fn map(v: &[T], f: fn(T) -> U) -> @[U] { +pure fn map(v: &[T], f: fn(T) -> U) -> @[U] { do build_sized(v.len()) |push| { for vec::each(v) |elem| { push(f(*elem)); @@ -106,7 +115,7 @@ pub pure fn map(v: &[T], f: fn(T) -> U) -> @[U] { * Creates an immutable vector of size `n_elts` and initializes the elements * to the value returned by the function `op`. */ -pub pure fn from_fn(n_elts: uint, op: iter::InitOp) -> @[T] { +pure fn from_fn(n_elts: uint, op: iter::InitOp) -> @[T] { do build_sized(n_elts) |push| { let mut i: uint = 0u; while i < n_elts { push(op(i)); i += 1u; } @@ -119,7 +128,7 @@ pub pure fn from_fn(n_elts: uint, op: iter::InitOp) -> @[T] { * Creates an immutable vector of size `n_elts` and initializes the elements * to the value `t`. */ -pub pure fn from_elem(n_elts: uint, t: T) -> @[T] { +pure fn from_elem(n_elts: uint, t: T) -> @[T] { do build_sized(n_elts) |push| { let mut i: uint = 0u; while i < n_elts { push(t); i += 1u; } @@ -128,6 +137,7 @@ pub pure fn from_elem(n_elts: uint, t: T) -> @[T] { #[cfg(notest)] mod traits { + #[legacy_exports]; #[cfg(stage0)] impl @[T]: Add<&[const T],@[T]> { #[inline(always)] @@ -149,9 +159,10 @@ mod traits { mod traits { #[legacy_exports];} -pub mod raw { - pub type VecRepr = vec::raw::VecRepr; - pub type SliceRepr = vec::raw::SliceRepr; +mod raw { + #[legacy_exports]; + type VecRepr = vec::raw::VecRepr; + type SliceRepr = vec::raw::SliceRepr; /** * Sets the length of a vector @@ -161,13 +172,13 @@ pub mod raw { * the vector is actually the specified size. */ #[inline(always)] - pub unsafe fn set_len(&&v: @[const T], new_len: uint) { + unsafe fn set_len(&&v: @[const T], new_len: uint) { let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v)); (**repr).unboxed.fill = new_len * sys::size_of::(); } #[inline(always)] - pub unsafe fn push(&v: @[const T], +initval: T) { + unsafe fn push(&v: @[const T], +initval: T) { let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v)); let fill = (**repr).unboxed.fill; if (**repr).unboxed.alloc > fill { @@ -204,7 +215,7 @@ pub mod raw { * * v - A vector * * n - The number of elements to reserve space for */ - pub unsafe fn reserve(&v: @[const T], n: uint) { + unsafe fn reserve(&v: @[const T], n: uint) { // Only make the (slow) call into the runtime if we have to if capacity(v) < n { let ptr = addr_of(v) as **VecRepr; @@ -228,7 +239,7 @@ pub mod raw { * * v - A vector * * n - The number of elements to reserve space for */ - pub unsafe fn reserve_at_least(&v: @[const T], n: uint) { + unsafe fn reserve_at_least(&v: @[const T], n: uint) { reserve(v, uint::next_power_of_two(n)); } diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 8cf097c9e83..624cb97dbca 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -41,36 +41,37 @@ use option::{Some, None}; */ // Functions used by the fmt extension at compile time -pub mod ct { - pub enum Signedness { pub Signed, pub Unsigned, } - pub enum Caseness { pub CaseUpper, pub CaseLower, } - pub enum Ty { - pub TyBool, - pub TyStr, - pub TyChar, - pub TyInt(Signedness), - pub TyBits, - pub TyHex(Caseness), - pub TyOctal, - pub TyFloat, - pub TyPoly, +mod ct { + #[legacy_exports]; + enum Signedness { Signed, Unsigned, } + enum Caseness { CaseUpper, CaseLower, } + enum Ty { + TyBool, + TyStr, + TyChar, + TyInt(Signedness), + TyBits, + TyHex(Caseness), + TyOctal, + TyFloat, + TyPoly, } - pub enum Flag { - pub FlagLeftJustify, - pub FlagLeftZeroPad, - pub FlagSpaceForSign, - pub FlagSignAlways, - pub FlagAlternate, + enum Flag { + FlagLeftJustify, + FlagLeftZeroPad, + FlagSpaceForSign, + FlagSignAlways, + FlagAlternate, } - pub enum Count { - pub CountIs(int), - pub CountIsParam(int), - pub CountIsNextParam, - pub CountImplied, + enum Count { + CountIs(int), + CountIsParam(int), + CountIsNextParam, + CountImplied, } // A formatted conversion from an expression to a string - pub type Conv = + type Conv = {param: Option, flags: ~[Flag], width: Count, @@ -79,10 +80,10 @@ pub mod ct { // A fragment of the output sequence - pub enum Piece { PieceString(~str), PieceConv(Conv), } - pub type ErrorFn = fn@(~str) -> ! ; + enum Piece { PieceString(~str), PieceConv(Conv), } + type ErrorFn = fn@(~str) -> ! ; - pub fn parse_fmt_string(s: ~str, error: ErrorFn) -> ~[Piece] { + fn parse_fmt_string(s: ~str, error: ErrorFn) -> ~[Piece] { let mut pieces: ~[Piece] = ~[]; let lim = str::len(s); let mut buf = ~""; @@ -272,26 +273,21 @@ pub mod ct { // decisions made a runtime. If it proves worthwhile then some of these // conditions can be evaluated at compile-time. For now though it's cleaner to // implement it 0this way, I think. -pub mod rt { - pub const flag_none: u32 = 0u32; - pub const flag_left_justify : u32 = 0b00000000000000000000000000000001u32; - pub const flag_left_zero_pad: u32 = 0b00000000000000000000000000000010u32; - pub const flag_space_for_sign:u32 = 0b00000000000000000000000000000100u32; - pub const flag_sign_always : u32 = 0b00000000000000000000000000001000u32; - pub const flag_alternate : u32 = 0b00000000000000000000000000010000u32; +mod rt { + #[legacy_exports]; + const flag_none : u32 = 0u32; + const flag_left_justify : u32 = 0b00000000000000000000000000000001u32; + const flag_left_zero_pad : u32 = 0b00000000000000000000000000000010u32; + const flag_space_for_sign : u32 = 0b00000000000000000000000000000100u32; + const flag_sign_always : u32 = 0b00000000000000000000000000001000u32; + const flag_alternate : u32 = 0b00000000000000000000000000010000u32; - pub enum Count { pub CountIs(int), pub CountImplied, } - pub enum Ty { - pub TyDefault, - pub TyBits, - pub TyHexUpper, - pub TyHexLower, - pub TyOctal - } + enum Count { CountIs(int), CountImplied, } + enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, } - pub type Conv = {flags: u32, width: Count, precision: Count, ty: Ty}; + type Conv = {flags: u32, width: Count, precision: Count, ty: Ty}; - pub pure fn conv_int(cv: Conv, i: int) -> ~str { + pure fn conv_int(cv: Conv, i: int) -> ~str { let radix = 10u; let prec = get_int_precision(cv); let mut s : ~str = int_to_str_prec(i, radix, prec); @@ -304,7 +300,7 @@ pub mod rt { } return unsafe { pad(cv, s, PadSigned) }; } - pub pure fn conv_uint(cv: Conv, u: uint) -> ~str { + pure fn conv_uint(cv: Conv, u: uint) -> ~str { let prec = get_int_precision(cv); let mut rs = match cv.ty { @@ -316,17 +312,17 @@ pub mod rt { }; return unsafe { pad(cv, rs, PadUnsigned) }; } - pub pure fn conv_bool(cv: Conv, b: bool) -> ~str { + pure fn conv_bool(cv: Conv, b: bool) -> ~str { let s = if b { ~"true" } else { ~"false" }; // run the boolean conversion through the string conversion logic, // giving it the same rules for precision, etc. return conv_str(cv, s); } - pub pure fn conv_char(cv: Conv, c: char) -> ~str { + pure fn conv_char(cv: Conv, c: char) -> ~str { let mut s = str::from_char(c); return unsafe { pad(cv, s, PadNozero) }; } - pub pure fn conv_str(cv: Conv, s: &str) -> ~str { + pure fn conv_str(cv: Conv, s: &str) -> ~str { // For strings, precision is the maximum characters // displayed let mut unpadded = match cv.precision { @@ -339,7 +335,7 @@ pub mod rt { }; return unsafe { pad(cv, unpadded, PadNozero) }; } - pub pure fn conv_float(cv: Conv, f: float) -> ~str { + pure fn conv_float(cv: Conv, f: float) -> ~str { let (to_str, digits) = match cv.precision { CountIs(c) => (float::to_str_exact, c as uint), CountImplied => (float::to_str, 6u) @@ -354,7 +350,7 @@ pub mod rt { } return unsafe { pad(cv, s, PadFloat) }; } - pub pure fn conv_poly(cv: Conv, v: T) -> ~str { + pure fn conv_poly(cv: Conv, v: T) -> ~str { let s = sys::log_str(&v); return conv_str(cv, s); }