1
Fork 0

De-export extfmt. Part of #3583.

This commit is contained in:
Graydon Hoare 2012-10-04 13:49:37 -07:00
parent a06b90322c
commit 6ffce1a1c3
2 changed files with 69 additions and 70 deletions

View file

@ -246,7 +246,6 @@ pub mod reflect;
// Modules supporting compiler-generated code
// Exported but not part of the public interface
#[legacy_exports]
pub mod extfmt;
// The test harness links against core, so don't include runtime in tests.
#[cfg(notest)]

View file

@ -41,11 +41,10 @@ use option::{Some, None};
*/
// Functions used by the fmt extension at compile time
mod ct {
#[legacy_exports];
enum Signedness { Signed, Unsigned, }
enum Caseness { CaseUpper, CaseLower, }
enum Ty {
pub mod ct {
pub enum Signedness { Signed, Unsigned, }
pub enum Caseness { CaseUpper, CaseLower, }
pub enum Ty {
TyBool,
TyStr,
TyChar,
@ -56,14 +55,14 @@ mod ct {
TyFloat,
TyPoly,
}
enum Flag {
pub enum Flag {
FlagLeftJustify,
FlagLeftZeroPad,
FlagSpaceForSign,
FlagSignAlways,
FlagAlternate,
}
enum Count {
pub enum Count {
CountIs(int),
CountIsParam(int),
CountIsNextParam,
@ -71,7 +70,7 @@ mod ct {
}
// A formatted conversion from an expression to a string
type Conv =
pub type Conv =
{param: Option<int>,
flags: ~[Flag],
width: Count,
@ -80,10 +79,10 @@ mod ct {
// A fragment of the output sequence
enum Piece { PieceString(~str), PieceConv(Conv), }
type ErrorFn = fn@(&str) -> ! ;
pub enum Piece { PieceString(~str), PieceConv(Conv), }
pub type ErrorFn = fn@(&str) -> ! ;
fn parse_fmt_string(s: &str, error: ErrorFn) -> ~[Piece] {
pub fn parse_fmt_string(s: &str, error: ErrorFn) -> ~[Piece] {
let mut pieces: ~[Piece] = ~[];
let lim = str::len(s);
let mut buf = ~"";
@ -118,7 +117,7 @@ mod ct {
flush_buf(move buf, &mut pieces);
move pieces
}
fn peek_num(s: &str, i: uint, lim: uint) ->
pub fn peek_num(s: &str, i: uint, lim: uint) ->
Option<{num: uint, next: uint}> {
let mut j = i;
let mut accum = 0u;
@ -140,7 +139,8 @@ mod ct {
None
}
}
fn parse_conversion(s: &str, i: uint, lim: uint, error: ErrorFn) ->
pub fn parse_conversion(s: &str, i: uint, lim: uint,
error: ErrorFn) ->
{piece: Piece, next: uint} {
let parm = parse_parameter(s, i, lim);
let flags = parse_flags(s, parm.next, lim);
@ -155,7 +155,7 @@ mod ct {
ty: ty.ty}),
next: ty.next};
}
fn parse_parameter(s: &str, i: uint, lim: uint) ->
pub fn parse_parameter(s: &str, i: uint, lim: uint) ->
{param: Option<int>, next: uint} {
if i >= lim { return {param: None, next: i}; }
let num = peek_num(s, i, lim);
@ -170,7 +170,7 @@ mod ct {
}
};
}
fn parse_flags(s: &str, i: uint, lim: uint) ->
pub fn parse_flags(s: &str, i: uint, lim: uint) ->
{flags: ~[Flag], next: uint} {
let noflags: ~[Flag] = ~[];
if i >= lim { return {flags: move noflags, next: i}; }
@ -198,7 +198,7 @@ mod ct {
more(FlagAlternate, s, i, lim)
} else { {flags: move noflags, next: i} };
}
fn parse_count(s: &str, i: uint, lim: uint)
pub fn parse_count(s: &str, i: uint, lim: uint)
-> {count: Count, next: uint} {
return if i >= lim {
{count: CountImplied, next: i}
@ -220,7 +220,7 @@ mod ct {
}
};
}
fn parse_precision(s: &str, i: uint, lim: uint) ->
pub fn parse_precision(s: &str, i: uint, lim: uint) ->
{count: Count, next: uint} {
return if i >= lim {
{count: CountImplied, next: i}
@ -236,7 +236,7 @@ mod ct {
}
} else { {count: CountImplied, next: i} };
}
fn parse_type(s: &str, i: uint, lim: uint, error: ErrorFn) ->
pub fn parse_type(s: &str, i: uint, lim: uint, error: ErrorFn) ->
{ty: Ty, next: uint} {
if i >= lim { error(~"missing type in conversion"); }
let tstr = str::slice(s, i, i+1u);
@ -274,21 +274,20 @@ 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.
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 mod rt {
pub const flag_none : u32 = 0u32;
pub const flag_left_justify : u32 = 0b00000000000001u32;
pub const flag_left_zero_pad : u32 = 0b00000000000010u32;
pub const flag_space_for_sign : u32 = 0b00000000000100u32;
pub const flag_sign_always : u32 = 0b00000000001000u32;
pub const flag_alternate : u32 = 0b00000000010000u32;
enum Count { CountIs(int), CountImplied, }
enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, }
pub enum Count { CountIs(int), CountImplied, }
pub enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, }
type Conv = {flags: u32, width: Count, precision: Count, ty: Ty};
pub type Conv = {flags: u32, width: Count, precision: Count, ty: Ty};
pure fn conv_int(cv: Conv, i: int) -> ~str {
pub pure fn conv_int(cv: Conv, i: int) -> ~str {
let radix = 10;
let prec = get_int_precision(cv);
let mut s : ~str = int_to_str_prec(i, radix, prec);
@ -301,7 +300,7 @@ mod rt {
}
return unsafe { pad(cv, s, PadSigned) };
}
pure fn conv_uint(cv: Conv, u: uint) -> ~str {
pub pure fn conv_uint(cv: Conv, u: uint) -> ~str {
let prec = get_int_precision(cv);
let mut rs =
match cv.ty {
@ -313,17 +312,17 @@ mod rt {
};
return unsafe { pad(cv, rs, PadUnsigned) };
}
pure fn conv_bool(cv: Conv, b: bool) -> ~str {
pub 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);
}
pure fn conv_char(cv: Conv, c: char) -> ~str {
pub pure fn conv_char(cv: Conv, c: char) -> ~str {
let mut s = str::from_char(c);
return unsafe { pad(cv, s, PadNozero) };
}
pure fn conv_str(cv: Conv, s: &str) -> ~str {
pub pure fn conv_str(cv: Conv, s: &str) -> ~str {
// For strings, precision is the maximum characters
// displayed
let mut unpadded = match cv.precision {
@ -336,7 +335,7 @@ mod rt {
};
return unsafe { pad(cv, unpadded, PadNozero) };
}
pure fn conv_float(cv: Conv, f: float) -> ~str {
pub 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)
@ -351,14 +350,14 @@ mod rt {
}
return unsafe { pad(cv, s, PadFloat) };
}
pure fn conv_poly<T>(cv: Conv, v: &T) -> ~str {
pub pure fn conv_poly<T>(cv: Conv, v: &T) -> ~str {
let s = sys::log_str(v);
return conv_str(cv, s);
}
// Convert an int to string with minimum number of digits. If precision is
// 0 and num is 0 then the result is the empty string.
pure fn int_to_str_prec(num: int, radix: uint, prec: uint) -> ~str {
pub pure fn int_to_str_prec(num: int, radix: uint, prec: uint) -> ~str {
return if num < 0 {
~"-" + uint_to_str_prec(-num as uint, radix, prec)
} else { uint_to_str_prec(num as uint, radix, prec) };
@ -367,7 +366,8 @@ mod rt {
// Convert a uint to string with a minimum number of digits. If precision
// is 0 and num is 0 then the result is the empty string. Could move this
// to uint: but it doesn't seem all that useful.
pure fn uint_to_str_prec(num: uint, radix: uint, prec: uint) -> ~str {
pub pure fn uint_to_str_prec(num: uint, radix: uint,
prec: uint) -> ~str {
return if prec == 0u && num == 0u {
~""
} else {
@ -380,16 +380,16 @@ mod rt {
} else { move s }
};
}
pure fn get_int_precision(cv: Conv) -> uint {
pub pure fn get_int_precision(cv: Conv) -> uint {
return match cv.precision {
CountIs(c) => c as uint,
CountImplied => 1u
};
}
enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat }
pub enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat }
impl PadMode : Eq {
pub impl PadMode : Eq {
pure fn eq(other: &PadMode) -> bool {
match (self, (*other)) {
(PadSigned, PadSigned) => true,
@ -405,7 +405,7 @@ mod rt {
pure fn ne(other: &PadMode) -> bool { !self.eq(other) }
}
fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
let mut s = move s; // sadtimes
let uwidth : uint = match cv.width {
CountImplied => return s,
@ -458,7 +458,7 @@ mod rt {
}
return padstr + s;
}
pure fn have_flag(flags: u32, f: u32) -> bool {
pub pure fn have_flag(flags: u32, f: u32) -> bool {
flags & f != 0
}
}
@ -469,21 +469,21 @@ mod rt {
// 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.
mod rt2 {
#[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 mod rt2 {
enum Count { CountIs(int), CountImplied, }
enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, }
pub const flag_none : u32 = 0u32;
pub const flag_left_justify : u32 = 0b00000000000001u32;
pub const flag_left_zero_pad : u32 = 0b00000000000010u32;
pub const flag_space_for_sign : u32 = 0b00000000000100u32;
pub const flag_sign_always : u32 = 0b00000000001000u32;
pub const flag_alternate : u32 = 0b00000000010000u32;
type Conv = {flags: u32, width: Count, precision: Count, ty: Ty};
pub enum Count { CountIs(int), CountImplied, }
pub enum Ty { TyDefault, TyBits, TyHexUpper, TyHexLower, TyOctal, }
pure fn conv_int(cv: Conv, i: int) -> ~str {
pub type Conv = {flags: u32, width: Count, precision: Count, ty: Ty};
pub pure fn conv_int(cv: Conv, i: int) -> ~str {
let radix = 10;
let prec = get_int_precision(cv);
let mut s : ~str = int_to_str_prec(i, radix, prec);
@ -496,7 +496,7 @@ mod rt2 {
}
return unsafe { pad(cv, s, PadSigned) };
}
pure fn conv_uint(cv: Conv, u: uint) -> ~str {
pub pure fn conv_uint(cv: Conv, u: uint) -> ~str {
let prec = get_int_precision(cv);
let mut rs =
match cv.ty {
@ -508,17 +508,17 @@ mod rt2 {
};
return unsafe { pad(cv, rs, PadUnsigned) };
}
pure fn conv_bool(cv: Conv, b: bool) -> ~str {
pub 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);
}
pure fn conv_char(cv: Conv, c: char) -> ~str {
pub pure fn conv_char(cv: Conv, c: char) -> ~str {
let mut s = str::from_char(c);
return unsafe { pad(cv, s, PadNozero) };
}
pure fn conv_str(cv: Conv, s: &str) -> ~str {
pub pure fn conv_str(cv: Conv, s: &str) -> ~str {
// For strings, precision is the maximum characters
// displayed
let mut unpadded = match cv.precision {
@ -531,7 +531,7 @@ mod rt2 {
};
return unsafe { pad(cv, unpadded, PadNozero) };
}
pure fn conv_float(cv: Conv, f: float) -> ~str {
pub 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)
@ -546,14 +546,14 @@ mod rt2 {
}
return unsafe { pad(cv, s, PadFloat) };
}
pure fn conv_poly<T>(cv: Conv, v: &T) -> ~str {
pub pure fn conv_poly<T>(cv: Conv, v: &T) -> ~str {
let s = sys::log_str(v);
return conv_str(cv, s);
}
// Convert an int to string with minimum number of digits. If precision is
// 0 and num is 0 then the result is the empty string.
pure fn int_to_str_prec(num: int, radix: uint, prec: uint) -> ~str {
pub pure fn int_to_str_prec(num: int, radix: uint, prec: uint) -> ~str {
return if num < 0 {
~"-" + uint_to_str_prec(-num as uint, radix, prec)
} else { uint_to_str_prec(num as uint, radix, prec) };
@ -562,7 +562,8 @@ mod rt2 {
// Convert a uint to string with a minimum number of digits. If precision
// is 0 and num is 0 then the result is the empty string. Could move this
// to uint: but it doesn't seem all that useful.
pure fn uint_to_str_prec(num: uint, radix: uint, prec: uint) -> ~str {
pub pure fn uint_to_str_prec(num: uint, radix: uint,
prec: uint) -> ~str {
return if prec == 0u && num == 0u {
~""
} else {
@ -575,16 +576,16 @@ mod rt2 {
} else { move s }
};
}
pure fn get_int_precision(cv: Conv) -> uint {
pub pure fn get_int_precision(cv: Conv) -> uint {
return match cv.precision {
CountIs(c) => c as uint,
CountImplied => 1u
};
}
enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat }
pub enum PadMode { PadSigned, PadUnsigned, PadNozero, PadFloat }
impl PadMode : Eq {
pub impl PadMode : Eq {
pure fn eq(other: &PadMode) -> bool {
match (self, (*other)) {
(PadSigned, PadSigned) => true,
@ -600,7 +601,7 @@ mod rt2 {
pure fn ne(other: &PadMode) -> bool { !self.eq(other) }
}
fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
pub fn pad(cv: Conv, s: ~str, mode: PadMode) -> ~str {
let mut s = move s; // sadtimes
let uwidth : uint = match cv.width {
CountImplied => return s,
@ -653,14 +654,13 @@ mod rt2 {
}
return padstr + s;
}
pure fn have_flag(flags: u32, f: u32) -> bool {
pub pure fn have_flag(flags: u32, f: u32) -> bool {
flags & f != 0
}
}
#[cfg(test)]
mod test {
#[legacy_exports];
#[test]
fn fmt_slice() {
let s = "abc";