Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
43753290
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,发现更多精彩内容 >>
提交
43753290
编写于
6月 11, 2011
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: Translate interior vector index expressions
上级
8b318be4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
57 addition
and
8 deletion
+57
-8
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+44
-8
src/comp/middle/ty.rs
src/comp/middle/ty.rs
+13
-0
未找到文件。
src/comp/middle/trans.rs
浏览文件 @
43753290
...
...
@@ -2662,7 +2662,8 @@ fn get_ivec_len_and_data(&@block_ctxt bcx, ValueRef v, ty::t unit_ty) ->
[
C_int
(
0
),
C_uint
(
abi
::
ivec_elt_len
)]));
auto
stack_elem
=
bcx
.build
.GEP
(
v
,
[
C_int
(
0
),
C_uint
(
abi
::
ivec_elt_elems
)]);
stack_elem
=
bcx
.build
.PointerCast
(
stack_elem
,
T_ptr
(
llunitty
));
stack_elem
=
bcx
.build
.PointerCast
(
stack_elem
,
T_ptr
(
T_array
(
llunitty
,
0u
)));
auto
on_heap
=
bcx
.build
.ICmp
(
lib
::
llvm
::
LLVMIntEQ
,
stack_len
,
C_int
(
0
));
...
...
@@ -2690,21 +2691,21 @@ fn get_ivec_len_and_data(&@block_ctxt bcx, ValueRef v, ty::t unit_ty) ->
// Technically this context is unnecessary, but it makes this function
// clearer.
auto
zero_len
=
C_int
(
0
);
auto
zero_elem
=
C_null
(
T_ptr
(
llunitty
));
auto
zero_elem
=
C_null
(
T_ptr
(
T_array
(
llunitty
,
0u
)
));
zero_len_cx
.build
.Br
(
next_cx
.llbb
);
// If we're here, then we actually have a heapified vector.
auto
heap_len
=
nonzero_len_cx
.build
.Load
(
nonzero_len_cx
.build
.GEP
(
heap_ptr
,
[
C_int
(
0
),
C_uint
(
abi
::
ivec_heap_elt_len
)]));
auto
heap_elem
=
nonzero_len_cx
.build
.GEP
(
heap_ptr
,
[
C_int
(
0
),
C_uint
(
abi
::
ivec_heap_elt_elems
)
,
C_int
(
0
)
]);
[
C_int
(
0
),
C_uint
(
abi
::
ivec_heap_elt_elems
)]);
nonzero_len_cx
.build
.Br
(
next_cx
.llbb
);
// Now we can figure out the length of `v` and get a pointer to its first
// element.
auto
len
=
next_cx
.build
.Phi
(
T_int
(),
[
stack_len
,
zero_len
,
heap_len
],
[
bcx
.llbb
,
zero_len_cx
.llbb
,
nonzero_len_cx
.llbb
]);
auto
elem
=
next_cx
.build
.Phi
(
T_ptr
(
llunitty
),
auto
elem
=
next_cx
.build
.Phi
(
T_ptr
(
T_array
(
llunitty
,
0u
)
),
[
stack_elem
,
zero_elem
,
heap_elem
],
[
bcx
.llbb
,
zero_len_cx
.llbb
,
nonzero_len_cx
.llbb
]);
ret
tup
(
len
,
elem
,
next_cx
);
...
...
@@ -4743,8 +4744,21 @@ fn trans_field(&@block_ctxt cx, &span sp, ValueRef v, &ty::t t0,
fn
trans_index
(
&@
block_ctxt
cx
,
&
span
sp
,
&@
ast
::
expr
base
,
&@
ast
::
expr
idx
,
&
ast
::
ann
ann
)
->
lval_result
{
// Is this an interior vector?
auto
base_ty
=
ty
::
expr_ty
(
cx
.fcx.lcx.ccx.tcx
,
base
);
auto
base_ty_no_boxes
=
ty
::
strip_boxes
(
cx
.fcx.lcx.ccx.tcx
,
base_ty
);
auto
is_interior
;
alt
(
ty
::
struct
(
cx
.fcx.lcx.ccx.tcx
,
base_ty_no_boxes
))
{
// TODO: Or-patterns
case
(
ty
::
ty_vec
(
_
))
{
is_interior
=
false
;
}
case
(
ty
::
ty_str
)
{
is_interior
=
false
;
}
case
(
ty
::
ty_ivec
(
_
))
{
is_interior
=
true
;
}
case
(
ty
::
ty_istr
)
{
is_interior
=
true
;
}
};
auto
lv
=
trans_expr
(
cx
,
base
);
lv
=
autoderef
(
lv
.bcx
,
lv
.val
,
ty
::
expr_ty
(
cx
.fcx.lcx.ccx.tcx
,
base
)
);
lv
=
autoderef
(
lv
.bcx
,
lv
.val
,
base_ty
);
auto
ix
=
trans_expr
(
lv
.bcx
,
idx
);
auto
v
=
lv
.val
;
auto
bcx
=
ix
.bcx
;
...
...
@@ -4769,8 +4783,23 @@ fn trans_index(&@block_ctxt cx, &span sp, &@ast::expr base,
auto
scaled_ix
=
bcx
.build
.Mul
(
ix_val
,
unit_sz
.val
);
maybe_name_value
(
cx
.fcx.lcx.ccx
,
scaled_ix
,
"scaled_ix"
);
auto
lim
=
bcx
.build
.GEP
(
v
,
[
C_int
(
0
),
C_int
(
abi
::
vec_elt_fill
)]);
lim
=
bcx
.build
.Load
(
lim
);
auto
interior_len_and_data
;
if
(
is_interior
)
{
auto
rslt
=
get_ivec_len_and_data
(
bcx
,
v
,
unit_ty
);
interior_len_and_data
=
some
(
tup
(
rslt
._0
,
rslt
._1
));
bcx
=
rslt
._2
;
}
else
{
interior_len_and_data
=
none
;
}
auto
lim
;
alt
(
interior_len_and_data
)
{
case
(
some
(
?
lad
))
{
lim
=
lad
._0
;
}
case
(
none
)
{
lim
=
bcx
.build
.GEP
(
v
,
[
C_int
(
0
),
C_int
(
abi
::
vec_elt_fill
)]);
lim
=
bcx
.build
.Load
(
lim
);
}
}
auto
bounds_check
=
bcx
.build
.ICmp
(
lib
::
llvm
::
LLVMIntULT
,
scaled_ix
,
lim
);
...
...
@@ -4783,7 +4812,14 @@ fn trans_index(&@block_ctxt cx, &span sp, &@ast::expr base,
auto
fail_res
=
trans_fail
(
fail_cx
,
some
[
common
::
span
](
sp
),
"bounds check"
);
auto
body
=
next_cx
.build
.GEP
(
v
,
[
C_int
(
0
),
C_int
(
abi
::
vec_elt_data
)]);
auto
body
;
alt
(
interior_len_and_data
)
{
case
(
some
(
?
lad
))
{
body
=
lad
._1
;
}
case
(
none
)
{
body
=
next_cx
.build
.GEP
(
v
,
[
C_int
(
0
),
C_int
(
abi
::
vec_elt_data
)]);
}
}
auto
elt
;
if
(
ty
::
type_has_dynamic_size
(
cx
.fcx.lcx.ccx.tcx
,
unit_ty
))
{
body
=
next_cx
.build
.PointerCast
(
body
,
T_ptr
(
T_array
(
T_i8
(),
0u
)));
...
...
src/comp/middle/ty.rs
浏览文件 @
43753290
...
...
@@ -2789,6 +2789,19 @@ fn ret_ty_of_fn(ctxt cx, ast::ann ann) -> t {
ret
ret_ty_of_fn_ty
(
cx
,
ann_to_type
(
cx
,
ann
));
}
// NB: This function requires that the given type has no variables. So, inside
// typeck, you should use typeck::strip_boxes() instead.
fn
strip_boxes
(
&
ctxt
cx
,
&
ty
::
t
t
)
->
ty
::
t
{
auto
t1
=
t
;
while
(
true
)
{
alt
(
struct
(
cx
,
t1
))
{
case
(
ty
::
ty_box
(
?
inner
))
{
t1
=
inner
.ty
;
}
case
(
_
)
{
ret
t1
;
}
}
}
fail
;
}
// Local Variables:
// mode: rust
// fill-column: 78;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录