Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
67b03fbc
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
67b03fbc
编写于
2月 23, 2015
作者:
N
Nick Cameron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
int audit - libcore::fmt
上级
dcc6ce2c
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
73 addition
and
51 deletion
+73
-51
src/libcore/fmt/float.rs
src/libcore/fmt/float.rs
+11
-11
src/libcore/fmt/mod.rs
src/libcore/fmt/mod.rs
+38
-23
src/libcore/fmt/num.rs
src/libcore/fmt/num.rs
+1
-1
src/libcore/fmt/rt/v1.rs
src/libcore/fmt/rt/v1.rs
+5
-1
src/libfmt_macros/lib.rs
src/libfmt_macros/lib.rs
+12
-13
src/libsyntax/ext/build.rs
src/libsyntax/ext/build.rs
+4
-0
src/libsyntax/ext/format.rs
src/libsyntax/ext/format.rs
+2
-2
未找到文件。
src/libcore/fmt/float.rs
浏览文件 @
67b03fbc
...
...
@@ -40,10 +40,10 @@ pub enum ExponentFormat {
pub
enum
SignificantDigits
{
/// At most the given number of digits will be printed, truncating any
/// trailing zeroes.
DigMax
(
u
int
),
DigMax
(
u
size
),
/// Precisely the given number of digits will be printed.
DigExact
(
u
int
)
DigExact
(
u
size
)
}
/// How to emit the sign of a number.
...
...
@@ -240,27 +240,27 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
// If reached left end of number, have to
// insert additional digit:
if
i
<
0
||
buf
[
i
as
u
int
]
==
b
'-'
||
buf
[
i
as
u
int
]
==
b
'+'
{
for
j
in
(
i
as
u
int
+
1
..
end
)
.rev
()
{
||
buf
[
i
as
u
size
]
==
b
'-'
||
buf
[
i
as
u
size
]
==
b
'+'
{
for
j
in
(
i
as
u
size
+
1
..
end
)
.rev
()
{
buf
[
j
+
1
]
=
buf
[
j
];
}
buf
[(
i
+
1
)
as
u
int
]
=
value2ascii
(
1
);
buf
[(
i
+
1
)
as
u
size
]
=
value2ascii
(
1
);
end
+=
1
;
break
;
}
// Skip the '.'
if
buf
[
i
as
u
int
]
==
b
'.'
{
i
-=
1
;
continue
;
}
if
buf
[
i
as
u
size
]
==
b
'.'
{
i
-=
1
;
continue
;
}
// Either increment the digit,
// or set to 0 if max and carry the 1.
let
current_digit
=
ascii2value
(
buf
[
i
as
u
int
]);
let
current_digit
=
ascii2value
(
buf
[
i
as
u
size
]);
if
current_digit
<
(
radix
-
1
)
{
buf
[
i
as
u
int
]
=
value2ascii
(
current_digit
+
1
);
buf
[
i
as
u
size
]
=
value2ascii
(
current_digit
+
1
);
break
;
}
else
{
buf
[
i
as
u
int
]
=
value2ascii
(
0
);
buf
[
i
as
u
size
]
=
value2ascii
(
0
);
i
-=
1
;
}
}
...
...
@@ -311,7 +311,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
struct
Filler
<
'a
>
{
buf
:
&
'a
mut
[
u8
],
end
:
&
'a
mut
u
int
,
end
:
&
'a
mut
u
size
,
}
impl
<
'a
>
fmt
::
Write
for
Filler
<
'a
>
{
...
...
src/libcore/fmt/mod.rs
浏览文件 @
67b03fbc
...
...
@@ -110,11 +110,14 @@ fn write_fmt(&mut self, args: Arguments) -> Result {
/// traits.
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
struct
Formatter
<
'a
>
{
flags
:
uint
,
#[cfg(not(stage0))]
flags
:
u32
,
#[cfg(stage0)]
flags
:
usize
,
fill
:
char
,
align
:
rt
::
v1
::
Alignment
,
width
:
Option
<
u
int
>
,
precision
:
Option
<
u
int
>
,
width
:
Option
<
u
size
>
,
precision
:
Option
<
u
size
>
,
buf
:
&
'a
mut
(
Write
+
'a
),
curarg
:
slice
::
Iter
<
'a
,
ArgumentV1
<
'a
>>
,
...
...
@@ -140,7 +143,7 @@ pub struct ArgumentV1<'a> {
impl
<
'a
>
ArgumentV1
<
'a
>
{
#[inline(never)]
fn
show_u
int
(
x
:
&
uint
,
f
:
&
mut
Formatter
)
->
Result
{
fn
show_u
size
(
x
:
&
usize
,
f
:
&
mut
Formatter
)
->
Result
{
Display
::
fmt
(
x
,
f
)
}
...
...
@@ -156,15 +159,22 @@ pub fn new<'b, T>(x: &'b T,
}
}
#[cfg(stage0)]
#[doc(hidden)]
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
fn
from_uint
(
x
:
&
uint
)
->
ArgumentV1
{
ArgumentV1
::
new
(
x
,
ArgumentV1
::
show_uint
)
ArgumentV1
::
new
(
x
,
ArgumentV1
::
show_usize
)
}
#[cfg(not(stage0))]
#[doc(hidden)]
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
fn
from_usize
(
x
:
&
usize
)
->
ArgumentV1
{
ArgumentV1
::
new
(
x
,
ArgumentV1
::
show_usize
)
}
fn
as_u
int
(
&
self
)
->
Option
<
uint
>
{
if
self
.formatter
as
u
int
==
ArgumentV1
::
show_uint
as
uint
{
Some
(
unsafe
{
*
(
self
.value
as
*
const
_
as
*
const
u
int
)
})
fn
as_u
size
(
&
self
)
->
Option
<
usize
>
{
if
self
.formatter
as
u
size
==
ArgumentV1
::
show_usize
as
usize
{
Some
(
unsafe
{
*
(
self
.value
as
*
const
_
as
*
const
u
size
)
})
}
else
{
None
}
...
...
@@ -194,7 +204,7 @@ pub fn new_v1(pieces: &'a [&'a str],
/// The `pieces` array must be at least as long as `fmt` to construct
/// a valid Arguments structure. Also, any `Count` within `fmt` that is
/// `CountIsParam` or `CountIsNextParam` has to point to an argument
/// created with `argumentu
int
`. However, failing to do so doesn't cause
/// created with `argumentu
size
`. However, failing to do so doesn't cause
/// unsafety, but will ignore invalid .
#[doc(hidden)]
#[inline]
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
...
...
@@ -434,15 +444,15 @@ fn run(&mut self, arg: &rt::v1::Argument) -> Result {
(
value
.formatter
)(
value
.value
,
self
)
}
fn
getcount
(
&
mut
self
,
cnt
:
&
rt
::
v1
::
Count
)
->
Option
<
u
int
>
{
fn
getcount
(
&
mut
self
,
cnt
:
&
rt
::
v1
::
Count
)
->
Option
<
u
size
>
{
match
*
cnt
{
rt
::
v1
::
Count
::
Is
(
n
)
=>
Some
(
n
),
rt
::
v1
::
Count
::
Implied
=>
None
,
rt
::
v1
::
Count
::
Param
(
i
)
=>
{
self
.args
[
i
]
.as_u
int
()
self
.args
[
i
]
.as_u
size
()
}
rt
::
v1
::
Count
::
NextParam
=>
{
self
.curarg
.next
()
.and_then
(|
arg
|
arg
.as_u
int
())
self
.curarg
.next
()
.and_then
(|
arg
|
arg
.as_u
size
())
}
}
}
...
...
@@ -476,12 +486,12 @@ pub fn pad_integral(&mut self,
let
mut
sign
=
None
;
if
!
is_positive
{
sign
=
Some
(
'-'
);
width
+=
1
;
}
else
if
self
.flags
&
(
1
<<
(
FlagV1
::
SignPlus
as
u
int
))
!=
0
{
}
else
if
self
.flags
&
(
1
<<
(
FlagV1
::
SignPlus
as
u
32
))
!=
0
{
sign
=
Some
(
'+'
);
width
+=
1
;
}
let
mut
prefixed
=
false
;
if
self
.flags
&
(
1
<<
(
FlagV1
::
Alternate
as
u
int
))
!=
0
{
if
self
.flags
&
(
1
<<
(
FlagV1
::
Alternate
as
u
32
))
!=
0
{
prefixed
=
true
;
width
+=
prefix
.char_len
();
}
...
...
@@ -511,7 +521,7 @@ pub fn pad_integral(&mut self,
}
// The sign and prefix goes before the padding if the fill character
// is zero
Some
(
min
)
if
self
.flags
&
(
1
<<
(
FlagV1
::
SignAwareZeroPad
as
u
int
))
!=
0
=>
{
Some
(
min
)
if
self
.flags
&
(
1
<<
(
FlagV1
::
SignAwareZeroPad
as
u
32
))
!=
0
=>
{
self
.fill
=
'0'
;
try!
(
write_prefix
(
self
));
self
.with_padding
(
min
-
width
,
Alignment
::
Right
,
|
f
|
{
...
...
@@ -581,7 +591,7 @@ pub fn pad(&mut self, s: &str) -> Result {
/// Runs a callback, emitting the correct padding either before or
/// afterwards depending on whether right or left alignment is requested.
fn
with_padding
<
F
>
(
&
mut
self
,
padding
:
u
int
,
default
:
Alignment
,
fn
with_padding
<
F
>
(
&
mut
self
,
padding
:
u
size
,
default
:
Alignment
,
f
:
F
)
->
Result
where
F
:
FnOnce
(
&
mut
Formatter
)
->
Result
,
{
...
...
@@ -627,6 +637,11 @@ pub fn write_fmt(&mut self, fmt: Arguments) -> Result {
write
(
self
.buf
,
fmt
)
}
#[cfg(not(stage0))]
/// Flags for formatting (packed version of rt::Flag)
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
fn
flags
(
&
self
)
->
u32
{
self
.flags
}
#[cfg(stage0)]
/// Flags for formatting (packed version of rt::Flag)
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
fn
flags
(
&
self
)
->
usize
{
self
.flags
}
...
...
@@ -641,11 +656,11 @@ pub fn align(&self) -> Alignment { self.align }
/// Optionally specified integer width that the output should be
#[unstable(feature
=
"core"
,
reason
=
"method was just created"
)]
pub
fn
width
(
&
self
)
->
Option
<
u
int
>
{
self
.width
}
pub
fn
width
(
&
self
)
->
Option
<
u
size
>
{
self
.width
}
/// Optionally specified precision for numeric types
#[unstable(feature
=
"core"
,
reason
=
"method was just created"
)]
pub
fn
precision
(
&
self
)
->
Option
<
u
int
>
{
self
.precision
}
pub
fn
precision
(
&
self
)
->
Option
<
u
size
>
{
self
.precision
}
}
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
...
...
@@ -731,9 +746,9 @@ fn fmt(&self, f: &mut Formatter) -> Result {
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
impl
<
T
>
Pointer
for
*
const
T
{
fn
fmt
(
&
self
,
f
:
&
mut
Formatter
)
->
Result
{
f
.flags
|
=
1
<<
(
FlagV1
::
Alternate
as
u
int
);
let
ret
=
LowerHex
::
fmt
(
&
(
*
self
as
u
int
),
f
);
f
.flags
&=
!
(
1
<<
(
FlagV1
::
Alternate
as
u
int
));
f
.flags
|
=
1
<<
(
FlagV1
::
Alternate
as
u
32
);
let
ret
=
LowerHex
::
fmt
(
&
(
*
self
as
u
32
),
f
);
f
.flags
&=
!
(
1
<<
(
FlagV1
::
Alternate
as
u
32
));
ret
}
}
...
...
@@ -889,7 +904,7 @@ fn fmt(&self, f: &mut Formatter) -> Result { f.pad("&Any") }
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
impl
<
T
:
Debug
>
Debug
for
[
T
]
{
fn
fmt
(
&
self
,
f
:
&
mut
Formatter
)
->
Result
{
if
f
.flags
&
(
1
<<
(
FlagV1
::
Alternate
as
u
int
))
==
0
{
if
f
.flags
&
(
1
<<
(
FlagV1
::
Alternate
as
u
32
))
==
0
{
try!
(
write!
(
f
,
"["
));
}
let
mut
is_first
=
true
;
...
...
@@ -901,7 +916,7 @@ fn fmt(&self, f: &mut Formatter) -> Result {
}
try!
(
write!
(
f
,
"{:?}"
,
*
x
))
}
if
f
.flags
&
(
1
<<
(
FlagV1
::
Alternate
as
u
int
))
==
0
{
if
f
.flags
&
(
1
<<
(
FlagV1
::
Alternate
as
u
32
))
==
0
{
try!
(
write!
(
f
,
"]"
));
}
Ok
(())
...
...
src/libcore/fmt/num.rs
浏览文件 @
67b03fbc
...
...
@@ -214,7 +214,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
show!
{
$Uint
with
$SU
}
}
}
integer!
{
i
nt
,
uint
,
"i"
,
"u"
}
integer!
{
i
size
,
usize
,
"i"
,
"u"
}
integer!
{
i8
,
u8
}
integer!
{
i16
,
u16
}
integer!
{
i32
,
u32
}
...
...
src/libcore/fmt/rt/v1.rs
浏览文件 @
67b03fbc
...
...
@@ -32,8 +32,12 @@ pub struct FormatSpec {
pub
fill
:
char
,
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
align
:
Alignment
,
#[cfg(stage0)]
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
flags
:
uint
,
pub
flags
:
usize
,
#[cfg(not(stage0))]
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
flags
:
u32
,
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
precision
:
Count
,
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
...
...
src/libfmt_macros/lib.rs
浏览文件 @
67b03fbc
...
...
@@ -24,7 +24,6 @@
html_root_url
=
"http://doc.rust-lang.org/nightly/"
,
html_playground_url
=
"http://play.rust-lang.org/"
)]
#![feature(int_uint)]
#![feature(staged_api)]
#![feature(unicode)]
...
...
@@ -65,7 +64,7 @@ pub struct FormatSpec<'a> {
/// Optionally specified alignment
pub
align
:
Alignment
,
/// Packed version of various flags provided
pub
flags
:
u
int
,
pub
flags
:
u
32
,
/// The integer precision to use
pub
precision
:
Count
<
'a
>
,
/// The string width requested for the resulting format
...
...
@@ -82,7 +81,7 @@ pub enum Position<'a> {
/// The argument will be in the next position. This is the default.
ArgumentNext
,
/// The argument is located at a specific index.
ArgumentIs
(
u
int
),
ArgumentIs
(
u
size
),
/// The argument has a name.
ArgumentNamed
(
&
'a
str
),
}
...
...
@@ -121,11 +120,11 @@ pub enum Flag {
#[derive(Copy,
PartialEq)]
pub
enum
Count
<
'a
>
{
/// The count is specified explicitly.
CountIs
(
u
int
),
CountIs
(
u
size
),
/// The count is specified by the argument with the given name.
CountIsName
(
&
'a
str
),
/// The count is specified by the argument at the given index.
CountIsParam
(
u
int
),
CountIsParam
(
u
size
),
/// The count is specified by the next parameter.
CountIsNextParam
,
/// The count is implied and cannot be explicitly specified.
...
...
@@ -237,7 +236,7 @@ fn ws(&mut self) {
/// Parses all of a string which is to be considered a "raw literal" in a
/// format string. This is everything outside of the braces.
fn
string
(
&
mut
self
,
start
:
u
int
)
->
&
'a
str
{
fn
string
(
&
mut
self
,
start
:
u
size
)
->
&
'a
str
{
loop
{
// we may not consume the character, so clone the iterator
match
self
.cur
.clone
()
.next
()
{
...
...
@@ -314,13 +313,13 @@ fn format(&mut self) -> FormatSpec<'a> {
}
// Sign flags
if
self
.consume
(
'+'
)
{
spec
.flags
|
=
1
<<
(
FlagSignPlus
as
u
int
);
spec
.flags
|
=
1
<<
(
FlagSignPlus
as
u
32
);
}
else
if
self
.consume
(
'-'
)
{
spec
.flags
|
=
1
<<
(
FlagSignMinus
as
u
int
);
spec
.flags
|
=
1
<<
(
FlagSignMinus
as
u
32
);
}
// Alternate marker
if
self
.consume
(
'#'
)
{
spec
.flags
|
=
1
<<
(
FlagAlternate
as
u
int
);
spec
.flags
|
=
1
<<
(
FlagAlternate
as
u
32
);
}
// Width and precision
let
mut
havewidth
=
false
;
...
...
@@ -333,7 +332,7 @@ fn format(&mut self) -> FormatSpec<'a> {
spec
.width
=
CountIsParam
(
0
);
havewidth
=
true
;
}
else
{
spec
.flags
|
=
1
<<
(
FlagSignAwareZeroPad
as
u
int
);
spec
.flags
|
=
1
<<
(
FlagSignAwareZeroPad
as
u
32
);
}
}
if
!
havewidth
{
...
...
@@ -413,7 +412,7 @@ fn word(&mut self) -> &'a str {
/// Optionally parses an integer at the current position. This doesn't deal
/// with overflow at all, it's just accumulating digits.
fn
integer
(
&
mut
self
)
->
Option
<
u
int
>
{
fn
integer
(
&
mut
self
)
->
Option
<
u
size
>
{
let
mut
cur
=
0
;
let
mut
found
=
false
;
loop
{
...
...
@@ -617,7 +616,7 @@ fn format_flags() {
format
:
FormatSpec
{
fill
:
None
,
align
:
AlignUnknown
,
flags
:
(
1
<<
FlagSignMinus
as
u
int
),
flags
:
(
1
<<
FlagSignMinus
as
u
32
),
precision
:
CountImplied
,
width
:
CountImplied
,
ty
:
""
,
...
...
@@ -628,7 +627,7 @@ fn format_flags() {
format
:
FormatSpec
{
fill
:
None
,
align
:
AlignUnknown
,
flags
:
(
1
<<
FlagSignPlus
as
u
int
)
|
(
1
<<
FlagAlternate
as
uint
),
flags
:
(
1
<<
FlagSignPlus
as
u
32
)
|
(
1
<<
FlagAlternate
as
u32
),
precision
:
CountImplied
,
width
:
CountImplied
,
ty
:
""
,
...
...
src/libsyntax/ext/build.rs
浏览文件 @
67b03fbc
...
...
@@ -148,6 +148,7 @@ fn expr_struct_ident(&self, span: Span, id: ast::Ident,
fn
expr_usize
(
&
self
,
span
:
Span
,
i
:
usize
)
->
P
<
ast
::
Expr
>
;
fn
expr_int
(
&
self
,
sp
:
Span
,
i
:
isize
)
->
P
<
ast
::
Expr
>
;
fn
expr_u8
(
&
self
,
sp
:
Span
,
u
:
u8
)
->
P
<
ast
::
Expr
>
;
fn
expr_u32
(
&
self
,
sp
:
Span
,
u
:
u32
)
->
P
<
ast
::
Expr
>
;
fn
expr_bool
(
&
self
,
sp
:
Span
,
value
:
bool
)
->
P
<
ast
::
Expr
>
;
fn
expr_vec
(
&
self
,
sp
:
Span
,
exprs
:
Vec
<
P
<
ast
::
Expr
>>
)
->
P
<
ast
::
Expr
>
;
...
...
@@ -701,6 +702,9 @@ fn expr_int(&self, sp: Span, i: isize) -> P<ast::Expr> {
self
.expr_lit
(
sp
,
ast
::
LitInt
(
i
as
u64
,
ast
::
SignedIntLit
(
ast
::
TyIs
(
false
),
ast
::
Sign
::
new
(
i
))))
}
fn
expr_u32
(
&
self
,
sp
:
Span
,
u
:
u32
)
->
P
<
ast
::
Expr
>
{
self
.expr_lit
(
sp
,
ast
::
LitInt
(
u
as
u64
,
ast
::
UnsignedIntLit
(
ast
::
TyU32
)))
}
fn
expr_u8
(
&
self
,
sp
:
Span
,
u
:
u8
)
->
P
<
ast
::
Expr
>
{
self
.expr_lit
(
sp
,
ast
::
LitInt
(
u
as
u64
,
ast
::
UnsignedIntLit
(
ast
::
TyU8
)))
}
...
...
src/libsyntax/ext/format.rs
浏览文件 @
67b03fbc
...
...
@@ -417,7 +417,7 @@ fn trans_piece(&mut self, piece: &parse::Piece) -> Option<P<ast::Expr>> {
parse
::
AlignUnknown
=>
align
(
"Unknown"
),
};
let
align
=
self
.ecx
.expr_path
(
align
);
let
flags
=
self
.ecx
.expr_u
size
(
sp
,
arg
.format.flags
);
let
flags
=
self
.ecx
.expr_u
32
(
sp
,
arg
.format.flags
);
let
prec
=
self
.trans_count
(
arg
.format.precision
);
let
width
=
self
.trans_count
(
arg
.format.width
);
let
path
=
self
.ecx
.path_global
(
sp
,
Context
::
rtpath
(
self
.ecx
,
"FormatSpec"
));
...
...
@@ -610,7 +610,7 @@ fn format_arg(ecx: &ExtCtxt, sp: Span,
ecx
.ident_of_std
(
"core"
),
ecx
.ident_of
(
"fmt"
),
ecx
.ident_of
(
"ArgumentV1"
),
ecx
.ident_of
(
"from_u
int
"
)],
vec!
[
arg
])
ecx
.ident_of
(
"from_u
size
"
)],
vec!
[
arg
])
}
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录