Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
731ff93a
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,发现更多精彩内容 >>
提交
731ff93a
编写于
11月 24, 2015
作者:
S
Steve Klabnik
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #30004 - michaelwoerister:primitive-ty-to-str, r=alexcrichton
Good candidate for a rollup, this one.
上级
ff885988
3be1d8ca
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
44 addition
and
110 deletion
+44
-110
src/librustc/util/ppaux.rs
src/librustc/util/ppaux.rs
+4
-46
src/librustc_trans/trans/debuginfo/metadata.rs
src/librustc_trans/trans/debuginfo/metadata.rs
+10
-19
src/librustc_trans/trans/debuginfo/type_names.rs
src/librustc_trans/trans/debuginfo/type_names.rs
+7
-16
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+2
-2
src/libsyntax/ast_util.rs
src/libsyntax/ast_util.rs
+18
-24
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+3
-3
未找到文件。
src/librustc/util/ppaux.rs
浏览文件 @
731ff93a
...
...
@@ -24,8 +24,7 @@
use
middle
::
ty
::
fold
::
TypeFoldable
;
use
std
::
fmt
;
use
syntax
::
abi
;
use
syntax
::
ast
;
use
syntax
::{
abi
,
ast_util
};
use
syntax
::
parse
::
token
;
use
syntax
::
ast
::
CRATE_NODE_ID
;
use
rustc_front
::
hir
;
...
...
@@ -774,55 +773,14 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
}
}
pub
fn
int_ty_to_string
(
t
:
ast
::
IntTy
,
val
:
Option
<
i64
>
)
->
String
{
let
s
=
match
t
{
ast
::
TyIs
=>
"isize"
,
ast
::
TyI8
=>
"i8"
,
ast
::
TyI16
=>
"i16"
,
ast
::
TyI32
=>
"i32"
,
ast
::
TyI64
=>
"i64"
};
match
val
{
// cast to a u64 so we can correctly print INT64_MIN. All integral types
// are parsed as u64, so we wouldn't want to print an extra negative
// sign.
Some
(
n
)
=>
format!
(
"{}{}"
,
n
as
u64
,
s
),
None
=>
s
.to_string
()
}
}
pub
fn
uint_ty_to_string
(
t
:
ast
::
UintTy
,
val
:
Option
<
u64
>
)
->
String
{
let
s
=
match
t
{
ast
::
TyUs
=>
"usize"
,
ast
::
TyU8
=>
"u8"
,
ast
::
TyU16
=>
"u16"
,
ast
::
TyU32
=>
"u32"
,
ast
::
TyU64
=>
"u64"
};
match
val
{
Some
(
n
)
=>
format!
(
"{}{}"
,
n
,
s
),
None
=>
s
.to_string
()
}
}
pub
fn
float_ty_to_string
(
t
:
ast
::
FloatTy
)
->
String
{
match
t
{
ast
::
TyF32
=>
"f32"
.to_string
(),
ast
::
TyF64
=>
"f64"
.to_string
(),
}
}
impl
<
'tcx
>
fmt
::
Display
for
ty
::
TypeVariants
<
'tcx
>
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
match
*
self
{
TyBool
=>
write!
(
f
,
"bool"
),
TyChar
=>
write!
(
f
,
"char"
),
TyInt
(
t
)
=>
write!
(
f
,
"{}"
,
int_ty_to_string
(
t
,
None
)),
TyUint
(
t
)
=>
write!
(
f
,
"{}"
,
uint_ty_to_string
(
t
,
None
)),
TyFloat
(
t
)
=>
write!
(
f
,
"{}"
,
float_ty_to_string
(
t
)),
TyInt
(
t
)
=>
write!
(
f
,
"{}"
,
ast_util
::
int_ty_to_string
(
t
)),
TyUint
(
t
)
=>
write!
(
f
,
"{}"
,
ast_util
::
uint_ty_to_string
(
t
)),
TyFloat
(
t
)
=>
write!
(
f
,
"{}"
,
ast_util
::
float_ty_to_string
(
t
)),
TyBox
(
typ
)
=>
write!
(
f
,
"Box<{}>"
,
typ
),
TyRawPtr
(
ref
tm
)
=>
{
write!
(
f
,
"*{} {}"
,
match
tm
.mutbl
{
...
...
src/librustc_trans/trans/debuginfo/metadata.rs
浏览文件 @
731ff93a
...
...
@@ -46,7 +46,7 @@
use
syntax
;
use
syntax
::
util
::
interner
::
Interner
;
use
syntax
::
codemap
::
Span
;
use
syntax
::{
ast
,
codemap
};
use
syntax
::{
ast
,
ast_util
,
codemap
};
use
syntax
::
parse
::
token
;
...
...
@@ -932,26 +932,17 @@ fn basic_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let
(
name
,
encoding
)
=
match
t
.sty
{
ty
::
TyTuple
(
ref
elements
)
if
elements
.is_empty
()
=>
(
"()"
.to_string
(),
DW_ATE_unsigned
),
ty
::
TyBool
=>
(
"bool"
.to_string
(),
DW_ATE_boolean
),
ty
::
TyChar
=>
(
"char"
.to_string
(),
DW_ATE_unsigned_char
),
ty
::
TyInt
(
int_ty
)
=>
match
int_ty
{
ast
::
TyIs
=>
(
"isize"
.to_string
(),
DW_ATE_signed
),
ast
::
TyI8
=>
(
"i8"
.to_string
(),
DW_ATE_signed
),
ast
::
TyI16
=>
(
"i16"
.to_string
(),
DW_ATE_signed
),
ast
::
TyI32
=>
(
"i32"
.to_string
(),
DW_ATE_signed
),
ast
::
TyI64
=>
(
"i64"
.to_string
(),
DW_ATE_signed
)
(
"()"
,
DW_ATE_unsigned
),
ty
::
TyBool
=>
(
"bool"
,
DW_ATE_boolean
),
ty
::
TyChar
=>
(
"char"
,
DW_ATE_unsigned_char
),
ty
::
TyInt
(
int_ty
)
=>
{
(
ast_util
::
int_ty_to_string
(
int_ty
),
DW_ATE_signed
)
},
ty
::
TyUint
(
uint_ty
)
=>
match
uint_ty
{
ast
::
TyUs
=>
(
"usize"
.to_string
(),
DW_ATE_unsigned
),
ast
::
TyU8
=>
(
"u8"
.to_string
(),
DW_ATE_unsigned
),
ast
::
TyU16
=>
(
"u16"
.to_string
(),
DW_ATE_unsigned
),
ast
::
TyU32
=>
(
"u32"
.to_string
(),
DW_ATE_unsigned
),
ast
::
TyU64
=>
(
"u64"
.to_string
(),
DW_ATE_unsigned
)
ty
::
TyUint
(
uint_ty
)
=>
{
(
ast_util
::
uint_ty_to_string
(
uint_ty
),
DW_ATE_unsigned
)
},
ty
::
TyFloat
(
float_ty
)
=>
match
float_ty
{
ast
::
TyF32
=>
(
"f32"
.to_string
(),
DW_ATE_float
),
ast
::
TyF64
=>
(
"f64"
.to_string
(),
DW_ATE_float
),
ty
::
TyFloat
(
float_ty
)
=>
{
(
ast_util
::
float_ty_to_string
(
float_ty
),
DW_ATE_float
)
},
_
=>
cx
.sess
()
.bug
(
"debuginfo::basic_type_metadata - t is invalid type"
)
};
...
...
src/librustc_trans/trans/debuginfo/type_names.rs
浏览文件 @
731ff93a
...
...
@@ -19,7 +19,7 @@
use
middle
::
ty
::{
self
,
Ty
};
use
rustc_front
::
hir
;
use
syntax
::
ast
;
use
syntax
::
ast
_util
;
// Compute the name of the type as it should be stored in debuginfo. Does not do
// any caching, i.e. calling the function twice with the same type will also do
...
...
@@ -41,21 +41,12 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
qualified
:
bool
,
output
:
&
mut
String
)
{
match
t
.sty
{
ty
::
TyBool
=>
output
.push_str
(
"bool"
),
ty
::
TyChar
=>
output
.push_str
(
"char"
),
ty
::
TyStr
=>
output
.push_str
(
"str"
),
ty
::
TyInt
(
ast
::
TyIs
)
=>
output
.push_str
(
"isize"
),
ty
::
TyInt
(
ast
::
TyI8
)
=>
output
.push_str
(
"i8"
),
ty
::
TyInt
(
ast
::
TyI16
)
=>
output
.push_str
(
"i16"
),
ty
::
TyInt
(
ast
::
TyI32
)
=>
output
.push_str
(
"i32"
),
ty
::
TyInt
(
ast
::
TyI64
)
=>
output
.push_str
(
"i64"
),
ty
::
TyUint
(
ast
::
TyUs
)
=>
output
.push_str
(
"usize"
),
ty
::
TyUint
(
ast
::
TyU8
)
=>
output
.push_str
(
"u8"
),
ty
::
TyUint
(
ast
::
TyU16
)
=>
output
.push_str
(
"u16"
),
ty
::
TyUint
(
ast
::
TyU32
)
=>
output
.push_str
(
"u32"
),
ty
::
TyUint
(
ast
::
TyU64
)
=>
output
.push_str
(
"u64"
),
ty
::
TyFloat
(
ast
::
TyF32
)
=>
output
.push_str
(
"f32"
),
ty
::
TyFloat
(
ast
::
TyF64
)
=>
output
.push_str
(
"f64"
),
ty
::
TyBool
=>
output
.push_str
(
"bool"
),
ty
::
TyChar
=>
output
.push_str
(
"char"
),
ty
::
TyStr
=>
output
.push_str
(
"str"
),
ty
::
TyInt
(
int_ty
)
=>
output
.push_str
(
ast_util
::
int_ty_to_string
(
int_ty
)),
ty
::
TyUint
(
uint_ty
)
=>
output
.push_str
(
ast_util
::
uint_ty_to_string
(
uint_ty
)),
ty
::
TyFloat
(
float_ty
)
=>
output
.push_str
(
ast_util
::
float_ty_to_string
(
float_ty
)),
ty
::
TyStruct
(
def
,
substs
)
|
ty
::
TyEnum
(
def
,
substs
)
=>
{
push_item_name
(
cx
,
def
.did
,
qualified
,
output
);
...
...
src/libsyntax/ast.rs
浏览文件 @
731ff93a
...
...
@@ -1258,7 +1258,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl
fmt
::
Display
for
IntTy
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
write!
(
f
,
"{}"
,
ast_util
::
int_ty_to_string
(
*
self
,
None
))
write!
(
f
,
"{}"
,
ast_util
::
int_ty_to_string
(
*
self
))
}
}
...
...
@@ -1303,7 +1303,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl
fmt
::
Display
for
UintTy
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
write!
(
f
,
"{}"
,
ast_util
::
uint_ty_to_string
(
*
self
,
None
))
write!
(
f
,
"{}"
,
ast_util
::
uint_ty_to_string
(
*
self
))
}
}
...
...
src/libsyntax/ast_util.rs
浏览文件 @
731ff93a
...
...
@@ -111,26 +111,23 @@ pub fn is_path(e: P<Expr>) -> bool {
match
e
.node
{
ExprPath
(
..
)
=>
true
,
_
=>
false
}
}
/// Get a string representation of a signed int type, with its value.
/// We want to avoid "45int" and "-3int" in favor of "45" and "-3"
pub
fn
int_ty_to_string
(
t
:
IntTy
,
val
:
Option
<
i64
>
)
->
String
{
let
s
=
match
t
{
pub
fn
int_ty_to_string
(
t
:
IntTy
)
->
&
'static
str
{
match
t
{
TyIs
=>
"isize"
,
TyI8
=>
"i8"
,
TyI16
=>
"i16"
,
TyI32
=>
"i32"
,
TyI64
=>
"i64"
};
match
val
{
// cast to a u64 so we can correctly print INT64_MIN. All integral types
// are parsed as u64, so we wouldn't want to print an extra negative
// sign.
Some
(
n
)
=>
format!
(
"{}{}"
,
n
as
u64
,
s
),
None
=>
s
.to_string
()
}
}
pub
fn
int_val_to_string
(
t
:
IntTy
,
val
:
i64
)
->
String
{
// cast to a u64 so we can correctly print INT64_MIN. All integral types
// are parsed as u64, so we wouldn't want to print an extra negative
// sign.
format!
(
"{}{}"
,
val
as
u64
,
int_ty_to_string
(
t
))
}
pub
fn
int_ty_max
(
t
:
IntTy
)
->
u64
{
match
t
{
TyI8
=>
0x80
,
...
...
@@ -140,23 +137,20 @@ pub fn int_ty_max(t: IntTy) -> u64 {
}
}
/// Get a string representation of an unsigned int type, with its value.
/// We want to avoid "42u" in favor of "42us". "42uint" is right out.
pub
fn
uint_ty_to_string
(
t
:
UintTy
,
val
:
Option
<
u64
>
)
->
String
{
let
s
=
match
t
{
pub
fn
uint_ty_to_string
(
t
:
UintTy
)
->
&
'static
str
{
match
t
{
TyUs
=>
"usize"
,
TyU8
=>
"u8"
,
TyU16
=>
"u16"
,
TyU32
=>
"u32"
,
TyU64
=>
"u64"
};
match
val
{
Some
(
n
)
=>
format!
(
"{}{}"
,
n
,
s
),
None
=>
s
.to_string
()
}
}
pub
fn
uint_val_to_string
(
t
:
UintTy
,
val
:
u64
)
->
String
{
format!
(
"{}{}"
,
val
,
uint_ty_to_string
(
t
))
}
pub
fn
uint_ty_max
(
t
:
UintTy
)
->
u64
{
match
t
{
TyU8
=>
0xff
,
...
...
@@ -166,10 +160,10 @@ pub fn uint_ty_max(t: UintTy) -> u64 {
}
}
pub
fn
float_ty_to_string
(
t
:
FloatTy
)
->
String
{
pub
fn
float_ty_to_string
(
t
:
FloatTy
)
->
&
'static
str
{
match
t
{
TyF32
=>
"f32"
.to_string
()
,
TyF64
=>
"f64"
.to_string
()
,
TyF32
=>
"f32"
,
TyF64
=>
"f64"
,
}
}
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
731ff93a
...
...
@@ -651,15 +651,15 @@ fn print_literal(&mut self, lit: &ast::Lit) -> io::Result<()> {
match
t
{
ast
::
SignedIntLit
(
st
,
ast
::
Plus
)
=>
{
word
(
self
.writer
(),
&
ast_util
::
int_
ty_to_string
(
st
,
Some
(
i
as
i64
)
))
&
ast_util
::
int_
val_to_string
(
st
,
i
as
i64
))
}
ast
::
SignedIntLit
(
st
,
ast
::
Minus
)
=>
{
let
istr
=
ast_util
::
int_
ty_to_string
(
st
,
Some
(
-
(
i
as
i64
)
));
let
istr
=
ast_util
::
int_
val_to_string
(
st
,
-
(
i
as
i64
));
word
(
self
.writer
(),
&
format!
(
"-{}"
,
istr
))
}
ast
::
UnsignedIntLit
(
ut
)
=>
{
word
(
self
.writer
(),
&
ast_util
::
uint_
ty_to_string
(
ut
,
Some
(
i
)
))
word
(
self
.writer
(),
&
ast_util
::
uint_
val_to_string
(
ut
,
i
))
}
ast
::
UnsuffixedIntLit
(
ast
::
Plus
)
=>
{
word
(
self
.writer
(),
&
format!
(
"{}"
,
i
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录