Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f34eae88
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,发现更多精彩内容 >>
提交
f34eae88
编写于
4月 10, 2012
作者:
G
Graydon Hoare
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Translate slice-strings and make fixed-strings carry their null.
上级
c720ffdb
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
39 addition
and
31 deletion
+39
-31
src/rustc/middle/trans/base.rs
src/rustc/middle/trans/base.rs
+9
-2
src/rustc/middle/trans/tvec.rs
src/rustc/middle/trans/tvec.rs
+17
-15
src/rustc/middle/trans/type_of.rs
src/rustc/middle/trans/type_of.rs
+1
-1
src/rustc/middle/ty.rs
src/rustc/middle/ty.rs
+8
-8
src/test/run-pass/estr-slice.rs
src/test/run-pass/estr-slice.rs
+4
-5
未找到文件。
src/rustc/middle/trans/base.rs
浏览文件 @
f34eae88
...
...
@@ -1236,7 +1236,7 @@ fn copy_val_no_check(bcx: block, action: copy_action, dst: ValueRef,
let
_
icx
=
bcx
.insn_ctxt
(
"copy_val_no_check"
);
let
ccx
=
bcx
.ccx
();
let
mut
bcx
=
bcx
;
if
ty
::
type_is_scalar
(
t
)
{
if
ty
::
type_is_scalar
(
t
)
||
ty
::
type_is_slice
(
t
)
{
Store
(
bcx
,
src
,
dst
);
ret
bcx
;
}
...
...
@@ -1268,7 +1268,7 @@ fn move_val(cx: block, action: copy_action, dst: ValueRef,
let
mut
src_val
=
src
.val
;
let
tcx
=
cx
.tcx
();
let
mut
cx
=
cx
;
if
ty
::
type_is_scalar
(
t
)
{
if
ty
::
type_is_scalar
(
t
)
||
ty
::
type_is_slice
(
t
)
{
if
src
.kind
==
owned
{
src_val
=
Load
(
cx
,
src_val
);
}
Store
(
cx
,
src_val
,
dst
);
ret
cx
;
...
...
@@ -2294,6 +2294,13 @@ fn trans_index(cx: block, ex: @ast::expr, base: @ast::expr,
let
body
=
GEPi
(
bcx
,
v
,
[
0
,
0
]);
(
lim
,
body
)
}
ty
::
ty_estr
(
ty
::
vstore_slice
(
_
))
|
ty
::
ty_evec
(
_
,
ty
::
vstore_slice
(
_
))
{
let
body
=
Load
(
bcx
,
GEPi
(
bcx
,
v
,
[
0
,
0
]));
let
lim
=
Load
(
bcx
,
GEPi
(
bcx
,
v
,
[
0
,
1
]));
(
lim
,
body
)
}
ty
::
ty_estr
(
_
)
|
ty
::
ty_evec
(
_
,
_
)
{
bcx
.sess
()
.unimpl
(
#
fmt
(
"unsupported evec/estr type trans_index"
));
}
...
...
src/rustc/middle/trans/tvec.rs
浏览文件 @
f34eae88
...
...
@@ -148,28 +148,30 @@ fn trans_vstore(bcx: block, e: @ast::expr,
fn
trans_estr
(
bcx
:
block
,
s
:
str
,
vstore
:
ast
::
vstore
,
sp
:
span
,
dest
:
dest
)
->
block
{
let
_
icx
=
bcx
.insn_ctxt
(
"tvec::trans_estr"
);
alt
vstore
{
let
ccx
=
bcx
.ccx
();
let
c
=
alt
vstore
{
ast
::
vstore_fixed
(
_
)
{
let
c
=
str
::
as_bytes
(
s
)
{|
bytes
|
// NB: The byte vector we have here includes the trailing \0,
// but we are doing a fixed-size str, meaning we _exclude_
// the trailing \0. And we don't let LLVM null-terminate
// either.
unsafe
{
lib
::
llvm
::
llvm
::
LLVMConstString
(
unsafe
::
reinterpret_cast
(
vec
::
unsafe
::
to_ptr
(
bytes
)),
(
bytes
.len
()
-
1u
)
as
libc
::
c_uint
,
lib
::
llvm
::
True
)
}
};
// "hello"/_ => [i8 x 6] in llvm
#
debug
(
"trans_estr: fixed: %s"
,
s
);
C_postr
(
s
)
}
#
debug
(
"trans_estr: src %s"
,
val_str
(
bcx
.ccx
()
.tn
,
c
));
ret
base
::
store_in_dest
(
bcx
,
c
,
dest
);
ast
::
vstore_slice
(
_
)
{
// "hello" => (*i8,uint) in llvm
#
debug
(
"trans_estr: slice '%s'"
,
s
);
let
cs
=
PointerCast
(
bcx
,
C_cstr
(
ccx
,
s
),
T_ptr
(
T_i8
()));
C_struct
([
cs
,
C_uint
(
ccx
,
str
::
len
(
s
))])
}
_
{
bcx
.ccx
()
.sess
.span_unimpl
(
sp
,
"unhandled tvec::trans_estr"
);
}
}
};
#
debug
(
"trans_estr: type: %s"
,
val_str
(
ccx
.tn
,
c
));
base
::
store_in_dest
(
bcx
,
c
,
dest
)
}
fn
trans_str
(
bcx
:
block
,
s
:
str
,
dest
:
dest
)
->
block
{
...
...
src/rustc/middle/trans/type_of.rs
浏览文件 @
f34eae88
...
...
@@ -72,7 +72,7 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
}
ty
::
ty_estr
(
ty
::
vstore_fixed
(
n
))
{
T_array
(
T_i8
(),
n
)
T_array
(
T_i8
(),
n
+
1u
/* +1 for trailing null */
)
}
ty
::
ty_evec
(
mt
,
ty
::
vstore_fixed
(
n
))
{
...
...
src/rustc/middle/ty.rs
浏览文件 @
f34eae88
...
...
@@ -118,7 +118,7 @@
export
type_is_signed
;
export
type_is_structural
;
export
type_is_copyable
;
export
type_is_
tup_lik
e
;
export
type_is_
slic
e
;
export
type_is_unique
;
export
type_is_c_like_enum
;
export
type_structurally_contains
;
...
...
@@ -858,13 +858,6 @@ fn sequence_element_type(cx: ctxt, ty: t) -> t {
}
}
pure
fn
type_is_tup_like
(
ty
:
t
)
->
bool
{
alt
get
(
ty
)
.struct
{
ty_rec
(
_
)
|
ty_tup
(
_
)
{
true
}
_
{
false
}
}
}
fn
get_element_type
(
ty
:
t
,
i
:
uint
)
->
t
{
alt
get
(
ty
)
.struct
{
ty_rec
(
flds
)
{
ret
flds
[
i
]
.mt.ty
;
}
...
...
@@ -887,6 +880,13 @@ fn get_element_type(ty: t, i: uint) -> t {
}
}
pure
fn
type_is_slice
(
ty
:
t
)
->
bool
{
alt
get
(
ty
)
.struct
{
ty_evec
(
_
,
vstore_slice
(
_
))
|
ty_estr
(
vstore_slice
(
_
))
{
true
}
_
{
ret
false
;
}
}
}
pure
fn
type_is_unique_box
(
ty
:
t
)
->
bool
{
alt
get
(
ty
)
.struct
{
ty_uniq
(
_
)
{
ret
true
;
}
...
...
src/test/run-pass/estr-slice.rs
浏览文件 @
f34eae88
// xfail-test
fn
main
()
{
let
x
:
str
/&
=
"hello"
;
let
mut
y
=
"there"
;
let
x
=
"hello"
/&
;
let
mut
y
=
"there"
/&
;
y
=
x
;
assert
y
[
1
]
==
'h'
as
u8
;
assert
y
[
4
]
==
'
e
'
as
u8
;
assert
y
[
0
]
==
'h'
as
u8
;
assert
y
[
4
]
==
'
o
'
as
u8
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录