Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
c34e9b33
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,发现更多精彩内容 >>
提交
c34e9b33
编写于
6月 21, 2011
作者:
M
Marijn Haverbeke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move expr ids into the expr record type
This simplifies the tag variants a bit and makes expr_node_id obsolete.
上级
edf73f05
变更
20
展开全部
隐藏空白更改
内联
并排
Showing
20 changed file
with
814 addition
and
938 deletion
+814
-938
src/comp/front/ast.rs
src/comp/front/ast.rs
+48
-46
src/comp/front/eval.rs
src/comp/front/eval.rs
+7
-7
src/comp/front/extenv.rs
src/comp/front/extenv.rs
+2
-3
src/comp/front/extfmt.rs
src/comp/front/extfmt.rs
+12
-19
src/comp/front/parser.rs
src/comp/front/parser.rs
+115
-127
src/comp/middle/alias.rs
src/comp/middle/alias.rs
+25
-25
src/comp/middle/ast_map.rs
src/comp/middle/ast_map.rs
+1
-1
src/comp/middle/resolve.rs
src/comp/middle/resolve.rs
+5
-5
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+84
-84
src/comp/middle/tstate/annotate.rs
src/comp/middle/tstate/annotate.rs
+1
-2
src/comp/middle/tstate/auxiliary.rs
src/comp/middle/tstate/auxiliary.rs
+9
-10
src/comp/middle/tstate/collect_locals.rs
src/comp/middle/tstate/collect_locals.rs
+5
-5
src/comp/middle/tstate/pre_post_conditions.rs
src/comp/middle/tstate/pre_post_conditions.rs
+94
-102
src/comp/middle/tstate/states.rs
src/comp/middle/tstate/states.rs
+209
-256
src/comp/middle/ty.rs
src/comp/middle/ty.rs
+8
-56
src/comp/middle/typeck.rs
src/comp/middle/typeck.rs
+54
-53
src/comp/middle/visit.rs
src/comp/middle/visit.rs
+42
-42
src/comp/middle/walk.rs
src/comp/middle/walk.rs
+42
-42
src/comp/pretty/pprust.rs
src/comp/pretty/pprust.rs
+49
-51
src/comp/util/common.rs
src/comp/util/common.rs
+2
-2
未找到文件。
src/comp/front/ast.rs
浏览文件 @
c34e9b33
...
...
@@ -220,61 +220,63 @@ fn unop_to_str(unop op) -> str {
// FIXME: temporary
tag
seq_kind
{
sk_unique
;
sk_rc
;
}
type
expr
=
spanned
[
expr_
];
type
expr
=
rec
(
node_id
id
,
expr_
node
,
span
span
);
tag
expr_
{
expr_vec
(
vec
[
@
expr
],
mutability
,
seq_kind
,
node_id
);
expr_tup
(
vec
[
elt
]
,
node_id
);
expr_rec
(
vec
[
field
],
option
::
t
[
@
expr
]
,
node_id
);
expr_call
(
@
expr
,
vec
[
@
expr
]
,
node_id
);
expr_self_method
(
ident
,
node_id
);
expr_bind
(
@
expr
,
vec
[
option
::
t
[
@
expr
]]
,
node_id
);
expr_spawn
(
spawn_dom
,
option
::
t
[
str
],
@
expr
,
vec
[
@
expr
]
,
node_id
);
expr_binary
(
binop
,
@
expr
,
@
expr
,
node_id
);
expr_unary
(
unop
,
@
expr
,
node_id
);
expr_lit
(
@
lit
,
node_id
);
expr_cast
(
@
expr
,
@
ty
,
node_id
);
expr_if
(
@
expr
,
block
,
option
::
t
[
@
expr
]
,
node_id
);
expr_while
(
@
expr
,
block
,
node_id
);
expr_for
(
@
local
,
@
expr
,
block
,
node_id
);
expr_for_each
(
@
local
,
@
expr
,
block
,
node_id
);
expr_do_while
(
block
,
@
expr
,
node_id
);
expr_alt
(
@
expr
,
vec
[
arm
]
,
node_id
);
expr_fn
(
_
fn
,
node_id
);
expr_block
(
block
,
node_id
);
expr_vec
(
vec
[
@
expr
],
mutability
,
seq_kind
);
expr_tup
(
vec
[
elt
]);
expr_rec
(
vec
[
field
],
option
::
t
[
@
expr
]);
expr_call
(
@
expr
,
vec
[
@
expr
]);
expr_self_method
(
ident
);
expr_bind
(
@
expr
,
vec
[
option
::
t
[
@
expr
]]);
expr_spawn
(
spawn_dom
,
option
::
t
[
str
],
@
expr
,
vec
[
@
expr
]);
expr_binary
(
binop
,
@
expr
,
@
expr
);
expr_unary
(
unop
,
@
expr
);
expr_lit
(
@
lit
);
expr_cast
(
@
expr
,
@
ty
);
expr_if
(
@
expr
,
block
,
option
::
t
[
@
expr
]);
expr_while
(
@
expr
,
block
);
expr_for
(
@
local
,
@
expr
,
block
);
expr_for_each
(
@
local
,
@
expr
,
block
);
expr_do_while
(
block
,
@
expr
);
expr_alt
(
@
expr
,
vec
[
arm
]);
expr_fn
(
_
fn
);
expr_block
(
block
);
/*
* FIXME: many of these @exprs should be constrained with
* is_lval once we have constrained types working.
*/
expr_move
(
@
expr
,
@
expr
,
node_id
);
expr_assign
(
@
expr
,
@
expr
,
node_id
);
expr_swap
(
@
expr
,
@
expr
,
node_id
);
expr_assign_op
(
binop
,
@
expr
,
@
expr
,
node_id
);
expr_send
(
@
expr
,
@
expr
,
node_id
);
expr_recv
(
@
expr
,
@
expr
,
node_id
);
expr_field
(
@
expr
,
ident
,
node_id
);
expr_index
(
@
expr
,
@
expr
,
node_id
);
expr_path
(
path
,
node_id
);
expr_ext
(
path
,
vec
[
@
expr
],
option
::
t
[
str
],
@
expr
,
node_id
);
expr_fail
(
node_id
,
option
::
t
[
str
]);
expr_break
(
node_id
)
;
expr_cont
(
node_id
)
;
expr_ret
(
option
::
t
[
@
expr
]
,
node_id
);
expr_put
(
option
::
t
[
@
expr
]
,
node_id
);
expr_be
(
@
expr
,
node_id
);
expr_log
(
int
,
@
expr
,
node_id
);
expr_move
(
@
expr
,
@
expr
);
expr_assign
(
@
expr
,
@
expr
);
expr_swap
(
@
expr
,
@
expr
);
expr_assign_op
(
binop
,
@
expr
,
@
expr
);
expr_send
(
@
expr
,
@
expr
);
expr_recv
(
@
expr
,
@
expr
);
expr_field
(
@
expr
,
ident
);
expr_index
(
@
expr
,
@
expr
);
expr_path
(
path
);
expr_ext
(
path
,
vec
[
@
expr
],
option
::
t
[
str
],
@
expr
);
expr_fail
(
option
::
t
[
str
]);
expr_break
;
expr_cont
;
expr_ret
(
option
::
t
[
@
expr
]);
expr_put
(
option
::
t
[
@
expr
]);
expr_be
(
@
expr
);
expr_log
(
int
,
@
expr
);
/* just an assert, no significance to typestate */
expr_assert
(
@
expr
,
node_id
);
expr_assert
(
@
expr
);
/* preds that typestate is aware of */
expr_check
(
@
expr
,
node_id
);
expr_check
(
@
expr
);
/* FIXME Would be nice if expr_check desugared
to expr_if_check. */
expr_if_check
(
@
expr
,
block
,
option
::
t
[
@
expr
]
,
node_id
);
expr_port
(
node_id
)
;
expr_chan
(
@
expr
,
node_id
);
expr_anon_obj
(
anon_obj
,
vec
[
ty_param
],
obj_def_ids
,
node_id
);
expr_if_check
(
@
expr
,
block
,
option
::
t
[
@
expr
]);
expr_port
;
expr_chan
(
@
expr
);
expr_anon_obj
(
anon_obj
,
vec
[
ty_param
],
obj_def_ids
);
}
type
lit
=
spanned
[
lit_
];
...
...
@@ -527,15 +529,15 @@ fn is_exported(ident i, _mod m) -> bool {
fn
is_call_expr
(
@
expr
e
)
->
bool
{
alt
(
e
.node
)
{
case
(
expr_call
(
_
,
_
,
_
))
{
ret
true
;
}
case
(
expr_call
(
_
,
_
))
{
ret
true
;
}
case
(
_
)
{
ret
false
;
}
}
}
fn
is_constraint_arg
(
@
expr
e
)
->
bool
{
alt
(
e
.node
)
{
case
(
expr_lit
(
_
,
_
))
{
ret
true
;
}
case
(
expr_path
(
_
,
_
))
{
ret
true
;
}
case
(
expr_lit
(
_
))
{
ret
true
;
}
case
(
expr_path
(
_
))
{
ret
true
;
}
case
(
_
)
{
ret
false
;
}
}
}
...
...
src/comp/front/eval.rs
浏览文件 @
c34e9b33
...
...
@@ -77,15 +77,15 @@ fn eval_lit(ctx cx, span sp, @ast::lit lit) -> val {
fn
eval_expr
(
ctx
cx
,
env
e
,
@
ast
::
expr
x
)
->
val
{
alt
(
x
.node
)
{
case
(
ast
::
expr_path
(
?
pth
,
_
))
{
case
(
ast
::
expr_path
(
?
pth
))
{
if
(
vec
::
len
[
ident
](
pth
.node.idents
)
==
1u
&&
vec
::
len
[
@
ast
::
ty
](
pth
.node.types
)
==
0u
)
{
ret
lookup
(
cx
.sess
,
e
,
x
.span
,
pth
.node.idents
.
(
0
));
}
cx
.sess
.span_fatal
(
x
.span
,
"evaluating structured path-name"
);
}
case
(
ast
::
expr_lit
(
?
lit
,
_
))
{
ret
eval_lit
(
cx
,
x
.span
,
lit
);
}
case
(
ast
::
expr_unary
(
?
op
,
?
a
,
_
))
{
case
(
ast
::
expr_lit
(
?
lit
))
{
ret
eval_lit
(
cx
,
x
.span
,
lit
);
}
case
(
ast
::
expr_unary
(
?
op
,
?
a
))
{
auto
av
=
eval_expr
(
cx
,
e
,
a
);
alt
(
op
)
{
case
(
ast
::
not
)
{
...
...
@@ -97,7 +97,7 @@ fn eval_expr(ctx cx, env e, @ast::expr x) -> val {
}
}
}
case
(
ast
::
expr_binary
(
?
op
,
?
a
,
?
b
,
_
))
{
case
(
ast
::
expr_binary
(
?
op
,
?
a
,
?
b
))
{
auto
av
=
eval_expr
(
cx
,
e
,
a
);
auto
bv
=
eval_expr
(
cx
,
e
,
b
);
alt
(
op
)
{
...
...
@@ -214,7 +214,7 @@ fn eval_crate_directive_expr(ctx cx, env e, @ast::expr x, str prefix,
&
mutable
vec
[
@
ast
::
view_item
]
view_items
,
&
mutable
vec
[
@
ast
::
item
]
items
)
{
alt
(
x
.node
)
{
case
(
ast
::
expr_if
(
?
cond
,
?
thn
,
?
elopt
,
_
))
{
case
(
ast
::
expr_if
(
?
cond
,
?
thn
,
?
elopt
))
{
auto
cv
=
eval_expr
(
cx
,
e
,
cond
);
if
(
!
val_is_bool
(
cv
))
{
cx
.sess
.span_fatal
(
x
.span
,
"bad cond type in 'if'"
);
...
...
@@ -234,7 +234,7 @@ fn eval_crate_directive_expr(ctx cx, env e, @ast::expr x, str prefix,
}
}
}
case
(
ast
::
expr_alt
(
?
v
,
?
arms
,
_
))
{
case
(
ast
::
expr_alt
(
?
v
,
?
arms
))
{
auto
vv
=
eval_expr
(
cx
,
e
,
v
);
for
(
ast
::
arm
arm
in
arms
)
{
alt
(
arm
.pat.node
)
{
...
...
@@ -259,7 +259,7 @@ fn eval_crate_directive_expr(ctx cx, env e, @ast::expr x, str prefix,
}
cx
.sess
.span_fatal
(
x
.span
,
"no cases matched in 'alt'"
);
}
case
(
ast
::
expr_block
(
?
block
,
_
))
{
case
(
ast
::
expr_block
(
?
block
))
{
ret
eval_crate_directive_block
(
cx
,
e
,
block
,
prefix
,
view_items
,
items
);
}
...
...
src/comp/front/extenv.rs
浏览文件 @
c34e9b33
...
...
@@ -32,7 +32,7 @@ fn expand_syntax_ext(&ext_ctxt cx, common::span sp, &vec[@ast::expr] args,
// FIXME: duplicate code copied from extfmt:
fn
expr_to_str
(
&
ext_ctxt
cx
,
@
ast
::
expr
expr
)
->
str
{
alt
(
expr
.node
)
{
case
(
ast
::
expr_lit
(
?
l
,
_
))
{
case
(
ast
::
expr_lit
(
?
l
))
{
alt
(
l
.node
)
{
case
(
ast
::
lit_str
(
?
s
,
_
))
{
ret
s
;
}
case
(
_
)
{
cx
.span_fatal
(
l
.span
,
"malformed #env call"
);
}
...
...
@@ -44,8 +44,7 @@ fn expr_to_str(&ext_ctxt cx, @ast::expr expr) -> str {
fn
make_new_lit
(
&
ext_ctxt
cx
,
common
::
span
sp
,
ast
::
lit_
lit
)
->
@
ast
::
expr
{
auto
sp_lit
=
@
rec
(
node
=
lit
,
span
=
sp
);
auto
expr
=
ast
::
expr_lit
(
sp_lit
,
cx
.next_id
());
ret
@
rec
(
node
=
expr
,
span
=
sp
);
ret
@
rec
(
id
=
cx
.next_id
(),
node
=
ast
::
expr_lit
(
sp_lit
),
span
=
sp
);
}
fn
make_new_str
(
&
ext_ctxt
cx
,
common
::
span
sp
,
str
s
)
->
@
ast
::
expr
{
...
...
src/comp/front/extfmt.rs
浏览文件 @
c34e9b33
...
...
@@ -35,7 +35,7 @@ fn parse_fmt_err_(&ext_ctxt cx, common::span sp, str msg) -> ! {
fn
expr_to_str
(
&
ext_ctxt
cx
,
@
ast
::
expr
expr
)
->
str
{
auto
err_msg
=
"first argument to #fmt must be a string literal"
;
alt
(
expr
.node
)
{
case
(
ast
::
expr_lit
(
?
l
,
_
))
{
case
(
ast
::
expr_lit
(
?
l
))
{
alt
(
l
.node
)
{
case
(
ast
::
lit_str
(
?
s
,
_
))
{
ret
s
;
}
case
(
_
)
{
cx
.span_fatal
(
l
.span
,
err_msg
);
}
...
...
@@ -54,8 +54,7 @@ fn pieces_to_expr(&ext_ctxt cx, common::span sp, vec[piece] pieces,
fn
make_new_lit
(
&
ext_ctxt
cx
,
common
::
span
sp
,
ast
::
lit_
lit
)
->
@
ast
::
expr
{
auto
sp_lit
=
@
rec
(
node
=
lit
,
span
=
sp
);
auto
expr
=
ast
::
expr_lit
(
sp_lit
,
cx
.next_id
());
ret
@
rec
(
node
=
expr
,
span
=
sp
);
ret
@
rec
(
id
=
cx
.next_id
(),
node
=
ast
::
expr_lit
(
sp_lit
),
span
=
sp
);
}
fn
make_new_str
(
&
ext_ctxt
cx
,
common
::
span
sp
,
str
s
)
->
@
ast
::
expr
{
auto
lit
=
ast
::
lit_str
(
s
,
ast
::
sk_rc
);
...
...
@@ -71,31 +70,27 @@ fn make_new_uint(&ext_ctxt cx, common::span sp, uint u) -> @ast::expr {
}
fn
make_add_expr
(
&
ext_ctxt
cx
,
common
::
span
sp
,
@
ast
::
expr
lhs
,
@
ast
::
expr
rhs
)
->
@
ast
::
expr
{
auto
binexpr
=
ast
::
expr_binary
(
ast
::
add
,
lhs
,
rhs
,
cx
.next_id
()
);
ret
@
rec
(
node
=
binexpr
,
span
=
sp
);
auto
binexpr
=
ast
::
expr_binary
(
ast
::
add
,
lhs
,
rhs
);
ret
@
rec
(
id
=
cx
.next_id
(),
node
=
binexpr
,
span
=
sp
);
}
fn
make_path_expr
(
&
ext_ctxt
cx
,
common
::
span
sp
,
vec
[
ast
::
ident
]
idents
)
->
@
ast
::
expr
{
let
vec
[
@
ast
::
ty
]
types
=
[];
auto
path
=
rec
(
idents
=
idents
,
types
=
types
);
auto
sp_path
=
rec
(
node
=
path
,
span
=
sp
);
auto
pathexpr
=
ast
::
expr_path
(
sp_path
,
cx
.next_id
());
auto
sp_pathexpr
=
@
rec
(
node
=
pathexpr
,
span
=
sp
);
ret
sp_pathexpr
;
auto
pathexpr
=
ast
::
expr_path
(
sp_path
);
ret
@
rec
(
id
=
cx
.next_id
(),
node
=
pathexpr
,
span
=
sp
);
}
fn
make_vec_expr
(
&
ext_ctxt
cx
,
common
::
span
sp
,
vec
[
@
ast
::
expr
]
exprs
)
->
@
ast
::
expr
{
auto
vecexpr
=
ast
::
expr_vec
(
exprs
,
ast
::
imm
,
ast
::
sk_rc
,
cx
.next_id
());
auto
sp_vecexpr
=
@
rec
(
node
=
vecexpr
,
span
=
sp
);
ret
sp_vecexpr
;
auto
vecexpr
=
ast
::
expr_vec
(
exprs
,
ast
::
imm
,
ast
::
sk_rc
);
ret
@
rec
(
id
=
cx
.next_id
(),
node
=
vecexpr
,
span
=
sp
);
}
fn
make_call
(
&
ext_ctxt
cx
,
common
::
span
sp
,
vec
[
ast
::
ident
]
fn_path
,
vec
[
@
ast
::
expr
]
args
)
->
@
ast
::
expr
{
auto
pathexpr
=
make_path_expr
(
cx
,
sp
,
fn_path
);
auto
callexpr
=
ast
::
expr_call
(
pathexpr
,
args
,
cx
.next_id
());
auto
sp_callexpr
=
@
rec
(
node
=
callexpr
,
span
=
sp
);
ret
sp_callexpr
;
auto
callexpr
=
ast
::
expr_call
(
pathexpr
,
args
);
ret
@
rec
(
id
=
cx
.next_id
(),
node
=
callexpr
,
span
=
sp
);
}
fn
make_rec_expr
(
&
ext_ctxt
cx
,
common
::
span
sp
,
vec
[
tup
(
ast
::
ident
,
@
ast
::
expr
)]
fields
)
->
@
ast
::
expr
{
...
...
@@ -107,10 +102,8 @@ fn make_rec_expr(&ext_ctxt cx, common::span sp,
rec
(
node
=
rec
(
mut
=
ast
::
imm
,
ident
=
ident
,
expr
=
val
),
span
=
sp
);
astfields
+=
[
astfield
];
}
auto
recexpr
=
ast
::
expr_rec
(
astfields
,
option
::
none
[
@
ast
::
expr
],
cx
.next_id
());
auto
sp_recexpr
=
@
rec
(
node
=
recexpr
,
span
=
sp
);
ret
sp_recexpr
;
auto
recexpr
=
ast
::
expr_rec
(
astfields
,
option
::
none
[
@
ast
::
expr
]);
ret
@
rec
(
id
=
cx
.next_id
(),
node
=
recexpr
,
span
=
sp
);
}
fn
make_path_vec
(
str
ident
)
->
vec
[
str
]
{
// FIXME: #fmt can't currently be used from within std
...
...
src/comp/front/parser.rs
浏览文件 @
c34e9b33
此差异已折叠。
点击以展开。
src/comp/middle/alias.rs
浏览文件 @
c34e9b33
...
...
@@ -76,18 +76,18 @@ fn visit_item(@ctx cx, &@ast::item i, &scope sc, &vt[scope] v) {
fn
visit_expr
(
@
ctx
cx
,
&@
ast
::
expr
ex
,
&
scope
sc
,
&
vt
[
scope
]
v
)
{
auto
handled
=
true
;
alt
(
ex
.node
)
{
case
(
ast
::
expr_call
(
?
f
,
?
args
,
_
))
{
case
(
ast
::
expr_call
(
?
f
,
?
args
))
{
check_call
(
*
cx
,
f
,
args
,
sc
);
handled
=
false
;
}
case
(
ast
::
expr_be
(
?
cl
,
_
))
{
case
(
ast
::
expr_be
(
?
cl
))
{
check_tail_call
(
*
cx
,
cl
);
visit
::
visit_expr
(
cl
,
sc
,
v
);
}
case
(
ast
::
expr_alt
(
?
input
,
?
arms
,
_
))
{
case
(
ast
::
expr_alt
(
?
input
,
?
arms
))
{
check_alt
(
*
cx
,
input
,
arms
,
sc
,
v
);
}
case
(
ast
::
expr_put
(
?
val
,
_
))
{
case
(
ast
::
expr_put
(
?
val
))
{
alt
(
val
)
{
case
(
some
(
?
ex
))
{
auto
root
=
expr_root
(
*
cx
,
ex
,
false
);
...
...
@@ -101,23 +101,23 @@ fn visit_expr(@ctx cx, &@ast::expr ex, &scope sc, &vt[scope] v) {
case
(
_
)
{
}
}
}
case
(
ast
::
expr_for_each
(
?
decl
,
?
call
,
?
block
,
_
))
{
case
(
ast
::
expr_for_each
(
?
decl
,
?
call
,
?
block
))
{
check_for_each
(
*
cx
,
decl
,
call
,
block
,
sc
,
v
);
}
case
(
ast
::
expr_for
(
?
decl
,
?
seq
,
?
block
,
_
))
{
case
(
ast
::
expr_for
(
?
decl
,
?
seq
,
?
block
))
{
check_for
(
*
cx
,
decl
,
seq
,
block
,
sc
,
v
);
}
case
(
ast
::
expr_path
(
?
pt
,
?
id
))
{
check_var
(
*
cx
,
ex
,
pt
,
id
,
false
,
sc
);
case
(
ast
::
expr_path
(
?
pt
))
{
check_var
(
*
cx
,
ex
,
pt
,
ex
.
id
,
false
,
sc
);
handled
=
false
;
}
case
(
ast
::
expr_move
(
?
dest
,
?
src
,
_
))
{
case
(
ast
::
expr_move
(
?
dest
,
?
src
))
{
check_assign
(
cx
,
dest
,
src
,
sc
,
v
);
}
case
(
ast
::
expr_assign
(
?
dest
,
?
src
,
_
))
{
case
(
ast
::
expr_assign
(
?
dest
,
?
src
))
{
check_assign
(
cx
,
dest
,
src
,
sc
,
v
);
}
case
(
ast
::
expr_assign_op
(
_
,
?
dest
,
?
src
,
_
))
{
case
(
ast
::
expr_assign_op
(
_
,
?
dest
,
?
src
))
{
check_assign
(
cx
,
dest
,
src
,
sc
,
v
);
}
case
(
_
)
{
handled
=
false
;
}
...
...
@@ -169,8 +169,8 @@ fn check_call(&ctx cx, &@ast::expr f, &vec[@ast::expr] args, &scope sc) ->
}
if
(
vec
::
len
(
unsafe_ts
)
>
0u
)
{
alt
(
f
.node
)
{
case
(
ast
::
expr_path
(
_
,
?
id
))
{
if
(
def_is_local
(
cx
.tcx.def_map
.get
(
id
),
true
))
{
case
(
ast
::
expr_path
(
_
))
{
if
(
def_is_local
(
cx
.tcx.def_map
.get
(
f
.
id
),
true
))
{
cx
.tcx.sess
.span_fatal
(
f
.span
,
#
fmt
(
"function may alias with
\
argument %u, which is not immutably rooted"
,
...
...
@@ -220,7 +220,7 @@ fn check_tail_call(&ctx cx, &@ast::expr call) {
auto
args
;
auto
f
=
alt
(
call
.node
)
{
case
(
ast
::
expr_call
(
?
f
,
?
args_
,
_
))
{
args
=
args_
;
f
}
case
(
ast
::
expr_call
(
?
f
,
?
args_
))
{
args
=
args_
;
f
}
};
auto
i
=
0u
;
for
(
ty
::
arg
arg_t
in
fty_args
(
cx
,
ty
::
expr_ty
(
*
cx
.tcx
,
f
)))
{
...
...
@@ -228,8 +228,8 @@ fn check_tail_call(&ctx cx, &@ast::expr call) {
auto
mut_a
=
arg_t
.mode
==
ty
::
mo_alias
(
true
);
auto
ok
=
true
;
alt
(
args
.
(
i
)
.node
)
{
case
(
ast
::
expr_path
(
_
,
?
id
))
{
auto
def
=
cx
.tcx.def_map
.get
(
id
);
case
(
ast
::
expr_path
(
_
))
{
auto
def
=
cx
.tcx.def_map
.get
(
args
.
(
i
)
.
id
);
auto
dnum
=
ast
::
def_id_of_def
(
def
)
._1
;
alt
(
cx
.local_map
.find
(
dnum
))
{
case
(
some
(
arg
(
ast
::
alias
(
?
mut
))))
{
...
...
@@ -301,7 +301,7 @@ fn check_for_each(&ctx cx, &@ast::local local, &@ast::expr call,
&
ast
::
block
block
,
&
scope
sc
,
&
vt
[
scope
]
v
)
{
visit
::
visit_expr
(
call
,
sc
,
v
);
alt
(
call
.node
)
{
case
(
ast
::
expr_call
(
?
f
,
?
args
,
_
))
{
case
(
ast
::
expr_call
(
?
f
,
?
args
))
{
auto
data
=
check_call
(
cx
,
f
,
args
,
sc
);
auto
defnum
=
local
.node.id
;
auto
new_sc
=
...
...
@@ -382,8 +382,8 @@ fn check_assign(&@ctx cx, &@ast::expr dest, &@ast::expr src, &scope sc,
&
vt
[
scope
]
v
)
{
visit_expr
(
cx
,
src
,
sc
,
v
);
alt
(
dest
.node
)
{
case
(
ast
::
expr_path
(
?
p
,
?
id
))
{
auto
dnum
=
ast
::
def_id_of_def
(
cx
.tcx.def_map
.get
(
id
))
._1
;
case
(
ast
::
expr_path
(
?
p
))
{
auto
dnum
=
ast
::
def_id_of_def
(
cx
.tcx.def_map
.get
(
dest
.
id
))
._1
;
if
(
is_immutable_alias
(
cx
,
sc
,
dnum
))
{
cx
.tcx.sess
.span_fatal
(
dest
.span
,
"assigning to immutable alias"
);
...
...
@@ -397,7 +397,7 @@ fn check_assign(&@ctx cx, &@ast::expr dest, &@ast::expr src, &scope sc,
r
.ok
=
overwritten
(
dest
.span
,
p
);
}
}
check_var
(
*
cx
,
dest
,
p
,
id
,
true
,
sc
);
check_var
(
*
cx
,
dest
,
p
,
dest
.
id
,
true
,
sc
);
}
case
(
_
)
{
auto
root
=
expr_root
(
*
cx
,
dest
,
false
);
...
...
@@ -496,7 +496,7 @@ fn maybe_push_auto_unbox(&option::t[deref] d, &mutable vec[deref] ds) {
let
vec
[
deref
]
ds
=
[];
while
(
true
)
{
alt
({
ex
.node
})
{
case
(
ast
::
expr_field
(
?
base
,
?
ident
,
_
))
{
case
(
ast
::
expr_field
(
?
base
,
?
ident
))
{
auto
auto_unbox
=
maybe_auto_unbox
(
cx
,
ty
::
expr_ty
(
*
cx
.tcx
,
base
));
auto
mut
=
false
;
...
...
@@ -519,7 +519,7 @@ fn maybe_push_auto_unbox(&option::t[deref] d, &mutable vec[deref] ds) {
maybe_push_auto_unbox
(
auto_unbox
.d
,
ds
);
ex
=
base
;
}
case
(
ast
::
expr_index
(
?
base
,
_
,
_
))
{
case
(
ast
::
expr_index
(
?
base
,
_
))
{
auto
auto_unbox
=
maybe_auto_unbox
(
cx
,
ty
::
expr_ty
(
*
cx
.tcx
,
base
));
alt
(
ty
::
struct
(
*
cx
.tcx
,
auto_unbox
.t
))
{
...
...
@@ -539,7 +539,7 @@ fn maybe_push_auto_unbox(&option::t[deref] d, &mutable vec[deref] ds) {
maybe_push_auto_unbox
(
auto_unbox
.d
,
ds
);
ex
=
base
;
}
case
(
ast
::
expr_unary
(
?
op
,
?
base
,
_
))
{
case
(
ast
::
expr_unary
(
?
op
,
?
base
))
{
if
(
op
==
ast
::
deref
)
{
auto
base_t
=
ty
::
expr_ty
(
*
cx
.tcx
,
base
);
alt
(
ty
::
struct
(
*
cx
.tcx
,
base_t
))
{
...
...
@@ -575,8 +575,8 @@ fn inner_mut(&vec[deref] ds) -> option::t[ty::t] {
fn
path_def_id
(
&
ctx
cx
,
&@
ast
::
expr
ex
)
->
option
::
t
[
ast
::
def_id
]
{
alt
(
ex
.node
)
{
case
(
ast
::
expr_path
(
_
,
?
id
))
{
ret
some
(
ast
::
def_id_of_def
(
cx
.tcx.def_map
.get
(
id
)));
case
(
ast
::
expr_path
(
_
))
{
ret
some
(
ast
::
def_id_of_def
(
cx
.tcx.def_map
.get
(
ex
.
id
)));
}
case
(
_
)
{
ret
none
;
}
}
...
...
src/comp/middle/ast_map.rs
浏览文件 @
c34e9b33
...
...
@@ -42,7 +42,7 @@ fn map_native_item(&map map, &@native_item i, &() e, &vt[()] v) {
}
fn
map_expr
(
&
map
map
,
&@
expr
ex
,
&
()
e
,
&
vt
[()]
v
)
{
map
.insert
(
ty
::
expr_node_id
(
ex
)
,
node_expr
(
ex
));
map
.insert
(
ex
.id
,
node_expr
(
ex
));
visit
::
visit_expr
(
ex
,
e
,
v
);
}
...
...
src/comp/middle/resolve.rs
浏览文件 @
c34e9b33
...
...
@@ -269,8 +269,8 @@ fn resolve_names(&@env e, &@ast::crate c) {
fn
walk_expr
(
@
env
e
,
&@
ast
::
expr
exp
,
&
scopes
sc
,
&
vt
[
scopes
]
v
)
{
visit_expr_with_scope
(
exp
,
sc
,
v
);
alt
(
exp
.node
)
{
case
(
ast
::
expr_path
(
?
p
,
?
id
))
{
maybe_insert
(
e
,
id
,
case
(
ast
::
expr_path
(
?
p
))
{
maybe_insert
(
e
,
exp
.
id
,
lookup_path_strict
(
*
e
,
sc
,
exp
.span
,
p
.node.idents
,
ns_value
));
}
...
...
@@ -366,13 +366,13 @@ fn visit_arm_with_scope(&ast::arm a, &scopes sc, &vt[scopes] v) {
fn
visit_expr_with_scope
(
&@
ast
::
expr
x
,
&
scopes
sc
,
&
vt
[
scopes
]
v
)
{
auto
new_sc
=
alt
(
x
.node
)
{
case
(
ast
::
expr_for
(
?
d
,
_
,
_
,
_
))
{
case
(
ast
::
expr_for
(
?
d
,
_
,
_
))
{
cons
[
scope
](
scope_loop
(
d
),
@
sc
)
}
case
(
ast
::
expr_for_each
(
?
d
,
_
,
_
,
_
))
{
case
(
ast
::
expr_for_each
(
?
d
,
_
,
_
))
{
cons
[
scope
](
scope_loop
(
d
),
@
sc
)
}
case
(
ast
::
expr_fn
(
?
f
,
_
))
{
cons
(
scope_fn
(
f
.decl
,
[]),
@
sc
)
}
case
(
ast
::
expr_fn
(
?
f
))
{
cons
(
scope_fn
(
f
.decl
,
[]),
@
sc
)
}
case
(
_
)
{
sc
}
};
visit
::
visit_expr
(
x
,
new_sc
,
v
);
...
...
src/comp/middle/trans.rs
浏览文件 @
c34e9b33
...
...
@@ -4077,18 +4077,20 @@ fn trans_if(&@block_ctxt cx, &@ast::expr cond, &ast::block thn,
alt
(
els
)
{
case
(
some
(
?
elexpr
))
{
alt
(
elexpr
.node
)
{
case
(
ast
::
expr_if
(
_
,
_
,
_
,
?
id
))
{
case
(
ast
::
expr_if
(
_
,
_
,
_
))
{
// Synthesize a block here to act as the else block
// containing an if expression. Needed in order for the
// else scope to behave like a normal block scope. A tad
// ugly.
let
ast
::
block_
elseif_blk_
=
rec
(
stmts
=
[],
expr
=
some
[
@
ast
::
expr
](
elexpr
),
id
=
id
);
rec
(
stmts
=
[],
expr
=
some
[
@
ast
::
expr
](
elexpr
),
id
=
elexpr
.id
);
auto
elseif_blk
=
rec
(
node
=
elseif_blk_
,
span
=
elexpr
.span
);
else_res
=
trans_block
(
else_cx
,
elseif_blk
,
output
);
}
case
(
ast
::
expr_block
(
?
blk
,
_
))
{
case
(
ast
::
expr_block
(
?
blk
))
{
// Calling trans_block directly instead of trans_expr
// because trans_expr will create another scope block
// context for the block, but we've already got the
...
...
@@ -4155,8 +4157,8 @@ fn collect_upvars(&@block_ctxt cx, &ast::block bloc,
fn
walk_expr
(
env
e
,
&@
ast
::
expr
expr
)
{
alt
(
expr
.node
)
{
case
(
ast
::
expr_path
(
?
path
,
?
id
))
{
alt
(
e
.def_map
.get
(
id
))
{
case
(
ast
::
expr_path
(
?
path
))
{
alt
(
e
.def_map
.get
(
expr
.
id
))
{
case
(
ast
::
def_arg
(
?
did
))
{
vec
::
push
(
e
.refs
,
did
._1
);
}
...
...
@@ -4354,7 +4356,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
// Step 3: Call iter passing [lliterbody, llenv], plus other args.
alt
(
seq
.node
)
{
case
(
ast
::
expr_call
(
?
f
,
?
args
,
?
id
))
{
case
(
ast
::
expr_call
(
?
f
,
?
args
))
{
auto
pair
=
alloca
(
cx
,
T_fn_pair
(
lcx
.ccx.tn
,
iter_body_llty
));
auto
code_cell
=
cx
.build
.GEP
(
pair
,
[
C_int
(
0
),
C_int
(
abi
::
fn_field_code
)]);
...
...
@@ -4369,7 +4371,7 @@ fn trans_for_each(&@block_ctxt cx, &@ast::local local, &@ast::expr seq,
r
=
trans_call
(
cx
,
f
,
some
[
ValueRef
](
cx
.build
.Load
(
pair
)),
args
,
id
);
seq
.
id
);
ret
res
(
r
.bcx
,
C_nil
());
}
}
...
...
@@ -4856,16 +4858,16 @@ fn trans_index(&@block_ctxt cx, &span sp, &@ast::expr base, &@ast::expr idx,
// immediate).
fn
trans_lval
(
&@
block_ctxt
cx
,
&@
ast
::
expr
e
)
->
lval_result
{
alt
(
e
.node
)
{
case
(
ast
::
expr_path
(
?
p
,
?
id
))
{
ret
trans_path
(
cx
,
p
,
id
);
}
case
(
ast
::
expr_field
(
?
base
,
?
ident
,
?
id
))
{
case
(
ast
::
expr_path
(
?
p
))
{
ret
trans_path
(
cx
,
p
,
e
.
id
);
}
case
(
ast
::
expr_field
(
?
base
,
?
ident
))
{
auto
r
=
trans_expr
(
cx
,
base
);
auto
t
=
ty
::
expr_ty
(
cx
.fcx.lcx.ccx.tcx
,
base
);
ret
trans_field
(
r
.bcx
,
e
.span
,
r
.val
,
t
,
ident
,
id
);
ret
trans_field
(
r
.bcx
,
e
.span
,
r
.val
,
t
,
ident
,
e
.
id
);
}
case
(
ast
::
expr_index
(
?
base
,
?
idx
,
?
id
))
{
ret
trans_index
(
cx
,
e
.span
,
base
,
idx
,
id
);
case
(
ast
::
expr_index
(
?
base
,
?
idx
))
{
ret
trans_index
(
cx
,
e
.span
,
base
,
idx
,
e
.
id
);
}
case
(
ast
::
expr_unary
(
?
unop
,
?
base
,
?
id
))
{
case
(
ast
::
expr_unary
(
?
unop
,
?
base
))
{
assert
(
unop
==
ast
::
deref
);
auto
sub
=
trans_expr
(
cx
,
base
);
auto
val
=
...
...
@@ -4873,12 +4875,12 @@ fn trans_lval(&@block_ctxt cx, &@ast::expr e) -> lval_result {
[
C_int
(
0
),
C_int
(
abi
::
box_rc_field_body
)]);
ret
lval_mem
(
sub
.bcx
,
val
);
}
case
(
ast
::
expr_self_method
(
?
ident
,
?
id
))
{
case
(
ast
::
expr_self_method
(
?
ident
))
{
alt
({
cx
.fcx.llself
})
{
case
(
some
(
?
pair
))
{
auto
r
=
pair
.v
;
auto
t
=
pair
.t
;
ret
trans_field
(
cx
,
e
.span
,
r
,
t
,
ident
,
id
);
ret
trans_field
(
cx
,
e
.span
,
r
,
t
,
ident
,
e
.
id
);
}
case
(
_
)
{
// Shouldn't happen.
...
...
@@ -4999,10 +5001,9 @@ fn trans_bind_thunk(&@local_ctxt cx, &span sp, &ty::t incoming_fty,
auto
out_arg
=
outgoing_args
.
(
outgoing_arg_index
);
auto
llout_arg_ty
=
llout_arg_tys
.
(
outgoing_arg_index
);
alt
(
arg
)
{
case
(
// Arg provided at binding time; thunk copies it from
// closure.
some
(
?
e
))
{
// Arg provided at binding time; thunk copies it from
// closure.
case
(
some
(
?
e
))
{
auto
e_ty
=
ty
::
expr_ty
(
cx
.ccx.tcx
,
e
);
auto
bound_arg
=
GEP_tup_like
(
bcx
,
closure_ty
,
llclosure
,
...
...
@@ -5671,43 +5672,43 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
// FIXME Fill in cx.sp
alt
(
e
.node
)
{
case
(
ast
::
expr_lit
(
?
lit
,
?
id
))
{
ret
res
(
cx
,
trans_lit
(
cx
.fcx.lcx.ccx
,
*
lit
,
id
));
case
(
ast
::
expr_lit
(
?
lit
))
{
ret
res
(
cx
,
trans_lit
(
cx
.fcx.lcx.ccx
,
*
lit
,
e
.
id
));
}
case
(
ast
::
expr_unary
(
?
op
,
?
x
,
?
id
))
{
if
(
op
!=
ast
::
deref
)
{
ret
trans_unary
(
cx
,
op
,
x
,
id
);
}
case
(
ast
::
expr_unary
(
?
op
,
?
x
))
{
if
(
op
!=
ast
::
deref
)
{
ret
trans_unary
(
cx
,
op
,
x
,
e
.
id
);
}
}
case
(
ast
::
expr_binary
(
?
op
,
?
x
,
?
y
,
_
))
{
case
(
ast
::
expr_binary
(
?
op
,
?
x
,
?
y
))
{
ret
trans_binary
(
cx
,
op
,
x
,
y
);
}
case
(
ast
::
expr_if
(
?
cond
,
?
thn
,
?
els
,
?
id
))
{
ret
with_out_method
(
bind
trans_if
(
cx
,
cond
,
thn
,
els
,
id
,
_
),
cx
,
id
,
output
);
case
(
ast
::
expr_if
(
?
cond
,
?
thn
,
?
els
))
{
ret
with_out_method
(
bind
trans_if
(
cx
,
cond
,
thn
,
els
,
e
.id
,
_
)
,
cx
,
e
.
id
,
output
);
}
case
(
ast
::
expr_if_check
(
?
cond
,
?
thn
,
?
els
,
?
ann
))
{
ret
with_out_method
(
bind
trans_if
(
cx
,
cond
,
thn
,
els
,
ann
,
_
),
cx
,
ann
,
output
);
case
(
ast
::
expr_if_check
(
?
cond
,
?
thn
,
?
els
))
{
ret
with_out_method
(
bind
trans_if
(
cx
,
cond
,
thn
,
els
,
e
.id
,
_
)
,
cx
,
e
.id
,
output
);
}
case
(
ast
::
expr_for
(
?
decl
,
?
seq
,
?
body
,
_
))
{
case
(
ast
::
expr_for
(
?
decl
,
?
seq
,
?
body
))
{
ret
trans_for
(
cx
,
decl
,
seq
,
body
);
}
case
(
ast
::
expr_for_each
(
?
decl
,
?
seq
,
?
body
,
_
))
{
case
(
ast
::
expr_for_each
(
?
decl
,
?
seq
,
?
body
))
{
ret
trans_for_each
(
cx
,
decl
,
seq
,
body
);
}
case
(
ast
::
expr_while
(
?
cond
,
?
body
,
_
))
{
case
(
ast
::
expr_while
(
?
cond
,
?
body
))
{
ret
trans_while
(
cx
,
cond
,
body
);
}
case
(
ast
::
expr_do_while
(
?
body
,
?
cond
,
_
))
{
case
(
ast
::
expr_do_while
(
?
body
,
?
cond
))
{
ret
trans_do_while
(
cx
,
body
,
cond
);
}
case
(
ast
::
expr_alt
(
?
expr
,
?
arms
,
?
id
))
{
ret
with_out_method
(
bind
trans_alt
(
cx
,
expr
,
arms
,
id
,
_
),
cx
,
id
,
output
);
case
(
ast
::
expr_alt
(
?
expr
,
?
arms
))
{
ret
with_out_method
(
bind
trans_alt
(
cx
,
expr
,
arms
,
e
.id
,
_
)
,
cx
,
e
.
id
,
output
);
}
case
(
ast
::
expr_fn
(
?
f
,
?
id
))
{
case
(
ast
::
expr_fn
(
?
f
))
{
auto
ccx
=
cx
.fcx.lcx.ccx
;
let
TypeRef
llfnty
=
alt
(
ty
::
struct
(
ccx
.tcx
,
node_id_type
(
ccx
,
id
)))
{
alt
(
ty
::
struct
(
ccx
.tcx
,
node_id_type
(
ccx
,
e
.
id
)))
{
case
(
ty
::
ty_fn
(
?
proto
,
?
inputs
,
?
output
,
_
,
_
))
{
type_of_fn_full
(
ccx
,
e
.span
,
proto
,
none
,
inputs
,
output
,
0u
)
...
...
@@ -5716,20 +5717,20 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
auto
sub_cx
=
extend_path
(
cx
.fcx.lcx
,
ccx
.names
.next
(
"anon"
));
auto
s
=
mangle_internal_name_by_path
(
ccx
,
sub_cx
.path
);
auto
llfn
=
decl_internal_fastcall_fn
(
ccx
.llmod
,
s
,
llfnty
);
trans_fn
(
sub_cx
,
e
.span
,
f
,
llfn
,
none
,
[],
id
);
trans_fn
(
sub_cx
,
e
.span
,
f
,
llfn
,
none
,
[],
e
.
id
);
ret
res
(
cx
,
create_fn_pair
(
ccx
,
s
,
llfnty
,
llfn
,
false
));
}
case
(
ast
::
expr_block
(
?
blk
,
?
id
))
{
case
(
ast
::
expr_block
(
?
blk
))
{
auto
sub_cx
=
new_scope_block_ctxt
(
cx
,
"block-expr body"
);
auto
next_cx
=
new_sub_block_ctxt
(
cx
,
"next"
);
auto
sub
=
with_out_method
(
bind
trans_block
(
sub_cx
,
blk
,
_
),
cx
,
id
,
with_out_method
(
bind
trans_block
(
sub_cx
,
blk
,
_
),
cx
,
e
.
id
,
output
);
cx
.build
.Br
(
sub_cx
.llbb
);
sub
.bcx.build
.Br
(
next_cx
.llbb
);
ret
res
(
next_cx
,
sub
.val
);
}
case
(
ast
::
expr_move
(
?
dst
,
?
src
,
_
))
{
case
(
ast
::
expr_move
(
?
dst
,
?
src
))
{
auto
lhs_res
=
trans_lval
(
cx
,
dst
);
assert
(
lhs_res
.is_mem
);
// FIXME Fill in lhs_res.res.bcx.sp
...
...
@@ -5743,7 +5744,7 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
rhs_res
.res.val
,
t
);
ret
res
(
move_res
.bcx
,
C_nil
());
}
case
(
ast
::
expr_assign
(
?
dst
,
?
src
,
_
))
{
case
(
ast
::
expr_assign
(
?
dst
,
?
src
))
{
auto
lhs_res
=
trans_lval
(
cx
,
dst
);
assert
(
lhs_res
.is_mem
);
// FIXME Fill in lhs_res.res.bcx.sp
...
...
@@ -5757,7 +5758,7 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
rhs_res
.val
,
t
);
ret
res
(
copy_res
.bcx
,
C_nil
());
}
case
(
ast
::
expr_swap
(
?
dst
,
?
src
,
_
))
{
case
(
ast
::
expr_swap
(
?
dst
,
?
src
))
{
auto
lhs_res
=
trans_lval
(
cx
,
dst
);
assert
(
lhs_res
.is_mem
);
// FIXME Fill in lhs_res.res.bcx.sp
...
...
@@ -5776,7 +5777,7 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
memmove_ty
(
move2_res
.bcx
,
rhs_res
.res.val
,
tmp_res
.val
,
t
);
ret
res
(
move3_res
.bcx
,
C_nil
());
}
case
(
ast
::
expr_assign_op
(
?
op
,
?
dst
,
?
src
,
_
))
{
case
(
ast
::
expr_assign_op
(
?
op
,
?
dst
,
?
src
))
{
auto
t
=
ty
::
expr_ty
(
cx
.fcx.lcx.ccx.tcx
,
src
);
auto
lhs_res
=
trans_lval
(
cx
,
dst
);
assert
(
lhs_res
.is_mem
);
...
...
@@ -5806,27 +5807,27 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
copy_val
(
v
.bcx
,
DROP_EXISTING
,
lhs_res
.res.val
,
v
.val
,
t
);
ret
res
(
copy_res
.bcx
,
C_nil
());
}
case
(
ast
::
expr_bind
(
?
f
,
?
args
,
?
id
))
{
ret
trans_bind
(
cx
,
f
,
args
,
id
);
case
(
ast
::
expr_bind
(
?
f
,
?
args
))
{
ret
trans_bind
(
cx
,
f
,
args
,
e
.
id
);
}
case
(
ast
::
expr_call
(
?
f
,
?
args
,
?
id
))
{
ret
trans_call
(
cx
,
f
,
none
[
ValueRef
],
args
,
id
);
case
(
ast
::
expr_call
(
?
f
,
?
args
))
{
ret
trans_call
(
cx
,
f
,
none
[
ValueRef
],
args
,
e
.
id
);
}
case
(
ast
::
expr_cast
(
?
e
,
_
,
?
id
))
{
ret
trans_cast
(
cx
,
e
,
id
);
}
case
(
ast
::
expr_vec
(
?
args
,
_
,
ast
::
sk_rc
,
?
id
))
{
ret
trans_vec
(
cx
,
args
,
id
);
case
(
ast
::
expr_cast
(
?
val
,
_
))
{
ret
trans_cast
(
cx
,
val
,
e
.
id
);
}
case
(
ast
::
expr_vec
(
?
args
,
_
,
ast
::
sk_rc
))
{
ret
trans_vec
(
cx
,
args
,
e
.
id
);
}
case
(
ast
::
expr_vec
(
?
args
,
_
,
ast
::
sk_unique
,
?
id
))
{
ret
trans_ivec
(
cx
,
args
,
id
);
case
(
ast
::
expr_vec
(
?
args
,
_
,
ast
::
sk_unique
))
{
ret
trans_ivec
(
cx
,
args
,
e
.
id
);
}
case
(
ast
::
expr_tup
(
?
args
,
?
id
))
{
ret
trans_tup
(
cx
,
args
,
id
);
}
case
(
ast
::
expr_rec
(
?
args
,
?
base
,
?
id
))
{
ret
trans_rec
(
cx
,
args
,
base
,
id
);
case
(
ast
::
expr_tup
(
?
args
))
{
ret
trans_tup
(
cx
,
args
,
e
.
id
);
}
case
(
ast
::
expr_rec
(
?
args
,
?
base
))
{
ret
trans_rec
(
cx
,
args
,
base
,
e
.
id
);
}
case
(
ast
::
expr_ext
(
_
,
_
,
_
,
?
expanded
,
_
))
{
case
(
ast
::
expr_ext
(
_
,
_
,
_
,
?
expanded
))
{
ret
trans_expr
(
cx
,
expanded
);
}
case
(
ast
::
expr_fail
(
_
,
?
str
))
{
case
(
ast
::
expr_fail
(
?
str
))
{
auto
failmsg
;
alt
(
str
)
{
case
(
some
(
?
msg
))
{
failmsg
=
msg
;
}
...
...
@@ -5834,31 +5835,31 @@ fn trans_expr_out(&@block_ctxt cx, &@ast::expr e, out_method output) ->
}
ret
trans_fail
(
cx
,
some
(
e
.span
),
failmsg
);
}
case
(
ast
::
expr_log
(
?
lvl
,
?
a
,
_
))
{
ret
trans_log
(
lvl
,
cx
,
a
);
}
case
(
ast
::
expr_assert
(
?
a
,
_
))
{
case
(
ast
::
expr_log
(
?
lvl
,
?
a
))
{
ret
trans_log
(
lvl
,
cx
,
a
);
}
case
(
ast
::
expr_assert
(
?
a
))
{
ret
trans_check_expr
(
cx
,
a
,
"Assertion"
);
}
case
(
ast
::
expr_check
(
?
a
,
_
))
{
case
(
ast
::
expr_check
(
?
a
))
{
ret
trans_check_expr
(
cx
,
a
,
"Predicate"
);
}
case
(
ast
::
expr_break
(
?
a
)
)
{
ret
trans_break
(
e
.span
,
cx
);
}
case
(
ast
::
expr_cont
(
?
a
)
)
{
ret
trans_cont
(
e
.span
,
cx
);
}
case
(
ast
::
expr_ret
(
?
e
,
_
))
{
ret
trans_ret
(
cx
,
e
);
}
case
(
ast
::
expr_put
(
?
e
,
_
))
{
ret
trans_put
(
cx
,
e
);
}
case
(
ast
::
expr_be
(
?
e
,
_
))
{
ret
trans_be
(
cx
,
e
);
}
case
(
ast
::
expr_port
(
?
id
))
{
ret
trans_port
(
cx
,
id
);
}
case
(
ast
::
expr_chan
(
?
e
,
?
id
))
{
ret
trans_chan
(
cx
,
e
,
id
);
}
case
(
ast
::
expr_send
(
?
lhs
,
?
rhs
,
?
id
))
{
ret
trans_send
(
cx
,
lhs
,
rhs
,
id
);
case
(
ast
::
expr_break
)
{
ret
trans_break
(
e
.span
,
cx
);
}
case
(
ast
::
expr_cont
)
{
ret
trans_cont
(
e
.span
,
cx
);
}
case
(
ast
::
expr_ret
(
?
e
x
))
{
ret
trans_ret
(
cx
,
ex
);
}
case
(
ast
::
expr_put
(
?
e
x
))
{
ret
trans_put
(
cx
,
ex
);
}
case
(
ast
::
expr_be
(
?
e
x
))
{
ret
trans_be
(
cx
,
ex
);
}
case
(
ast
::
expr_port
)
{
ret
trans_port
(
cx
,
e
.
id
);
}
case
(
ast
::
expr_chan
(
?
e
x
))
{
ret
trans_chan
(
cx
,
ex
,
e
.
id
);
}
case
(
ast
::
expr_send
(
?
lhs
,
?
rhs
))
{
ret
trans_send
(
cx
,
lhs
,
rhs
,
e
.
id
);
}
case
(
ast
::
expr_recv
(
?
lhs
,
?
rhs
,
?
id
))
{
ret
trans_recv
(
cx
,
lhs
,
rhs
,
id
);
case
(
ast
::
expr_recv
(
?
lhs
,
?
rhs
))
{
ret
trans_recv
(
cx
,
lhs
,
rhs
,
e
.
id
);
}
case
(
ast
::
expr_spawn
(
?
dom
,
?
name
,
?
func
,
?
args
,
?
id
))
{
ret
trans_spawn
(
cx
,
dom
,
name
,
func
,
args
,
id
);
case
(
ast
::
expr_spawn
(
?
dom
,
?
name
,
?
func
,
?
args
))
{
ret
trans_spawn
(
cx
,
dom
,
name
,
func
,
args
,
e
.
id
);
}
case
(
ast
::
expr_anon_obj
(
?
anon_obj
,
?
tps
,
?
odid
,
?
id
))
{
ret
trans_anon_obj
(
cx
,
e
.span
,
anon_obj
,
tps
,
odid
.ctor
,
id
);
case
(
ast
::
expr_anon_obj
(
?
anon_obj
,
?
tps
,
?
odid
))
{
ret
trans_anon_obj
(
cx
,
e
.span
,
anon_obj
,
tps
,
odid
.ctor
,
e
.
id
);
}
case
(
_
)
{
// The expression is an lvalue. Fall through.
...
...
@@ -6600,8 +6601,7 @@ fn init_local(&@block_ctxt cx, &@ast::local local) -> result {
// the value.
ty
=
node_id_type
(
cx
.fcx.lcx.ccx
,
ty
::
expr_node_id
(
init
.expr
));
node_id_type
(
cx
.fcx.lcx.ccx
,
init
.expr.id
);
auto
sub
=
trans_expr
(
bcx
,
init
.expr
);
bcx
=
copy_val
(
sub
.bcx
,
INIT
,
llptr
,
sub
.val
,
ty
)
.bcx
;
}
...
...
@@ -6836,9 +6836,9 @@ fn trans_block(&@block_ctxt cx, &ast::block b, &out_method output) -> result {
}
fn
accept_out_method
(
&@
ast
::
expr
expr
)
->
bool
{
ret
alt
(
expr
.node
)
{
case
(
ast
::
expr_if
(
_
,
_
,
_
,
_
))
{
true
}
case
(
ast
::
expr_alt
(
_
,
_
,
_
))
{
true
}
case
(
ast
::
expr_block
(
_
,
_
))
{
true
}
case
(
ast
::
expr_if
(
_
,
_
,
_
))
{
true
}
case
(
ast
::
expr_alt
(
_
,
_
))
{
true
}
case
(
ast
::
expr_block
(
_
))
{
true
}
case
(
_
)
{
false
}
};
}
...
...
@@ -7506,7 +7506,7 @@ fn trans_tag_variant(@local_ctxt cx, ast::node_id tag_id,
// that does so later on?
fn
trans_const_expr
(
&@
crate_ctxt
cx
,
@
ast
::
expr
e
)
->
ValueRef
{
alt
(
e
.node
)
{
case
(
ast
::
expr_lit
(
?
lit
,
?
id
))
{
ret
trans_lit
(
cx
,
*
lit
,
id
);
}
case
(
ast
::
expr_lit
(
?
lit
))
{
ret
trans_lit
(
cx
,
*
lit
,
e
.
id
);
}
case
(
_
)
{
cx
.sess
.span_unimpl
(
e
.span
,
"consts that's not a plain literal"
);
}
...
...
src/comp/middle/tstate/annotate.rs
浏览文件 @
c34e9b33
...
...
@@ -4,7 +4,6 @@
import
std
::
option
::
some
;
import
std
::
option
::
none
;
import
front
::
ast
::
*
;
import
middle
::
ty
::
expr_node_id
;
import
util
::
common
::
istr
;
import
util
::
common
::
uistr
;
import
util
::
common
::
span
;
...
...
@@ -25,7 +24,7 @@
import
middle
::
tstate
::
ann
::
empty_ann
;
fn
collect_ids_expr
(
&@
expr
e
,
@
mutable
vec
[
node_id
]
res
)
{
vec
::
push
(
*
res
,
e
xpr_node_id
(
e
)
);
vec
::
push
(
*
res
,
e
.id
);
}
fn
collect_ids_block
(
&
block
b
,
@
mutable
vec
[
node_id
]
res
)
{
...
...
src/comp/middle/tstate/auxiliary.rs
浏览文件 @
c34e9b33
...
...
@@ -10,7 +10,6 @@
import
std
::
option
::
maybe
;
import
front
::
ast
;
import
front
::
ast
::
*
;
import
middle
::
ty
::
expr_node_id
;
import
util
::
common
;
import
util
::
common
::
span
;
import
util
::
common
::
respan
;
...
...
@@ -284,14 +283,14 @@ fn stmt_to_ann(&crate_ctxt ccx, &stmt s) -> ts_ann {
/* fails if e has no annotation */
fn
expr_states
(
&
crate_ctxt
ccx
,
@
expr
e
)
->
pre_and_post_state
{
log
"expr_states"
;
ret
node_id_to_ts_ann
(
ccx
,
e
xpr_node_id
(
e
)
)
.states
;
ret
node_id_to_ts_ann
(
ccx
,
e
.id
)
.states
;
}
/* fails if e has no annotation */
fn
expr_pp
(
&
crate_ctxt
ccx
,
@
expr
e
)
->
pre_and_post
{
log
"expr_pp"
;
ret
node_id_to_ts_ann
(
ccx
,
e
xpr_node_id
(
e
)
)
.conditions
;
ret
node_id_to_ts_ann
(
ccx
,
e
.id
)
.conditions
;
}
fn
stmt_pp
(
&
crate_ctxt
ccx
,
&
stmt
s
)
->
pre_and_post
{
...
...
@@ -461,14 +460,14 @@ fn new_crate_ctxt(ty::ctxt cx) -> crate_ctxt {
If it has a function type with a ! annotation,
the answer is noreturn. */
fn
controlflow_expr
(
&
crate_ctxt
ccx
,
@
expr
e
)
->
controlflow
{
alt
(
ty
::
struct
(
ccx
.tcx
,
ty
::
node_id_to_type
(
ccx
.tcx
,
e
xpr_node_id
(
e
)
)))
{
alt
(
ty
::
struct
(
ccx
.tcx
,
ty
::
node_id_to_type
(
ccx
.tcx
,
e
.id
)))
{
case
(
ty
::
ty_fn
(
_
,
_
,
_
,
?
cf
,
_
))
{
ret
cf
;
}
case
(
_
)
{
ret
return
;
}
}
}
fn
constraints_expr
(
&
ty
::
ctxt
cx
,
@
expr
e
)
->
vec
[
@
ty
::
constr_def
]
{
alt
(
ty
::
struct
(
cx
,
ty
::
node_id_to_type
(
cx
,
e
xpr_node_id
(
e
)
)))
{
alt
(
ty
::
struct
(
cx
,
ty
::
node_id_to_type
(
cx
,
e
.id
)))
{
case
(
ty
::
ty_fn
(
_
,
_
,
_
,
_
,
?
cs
))
{
ret
cs
;
}
case
(
_
)
{
ret
[];
}
}
...
...
@@ -547,7 +546,7 @@ fn node_id_for_constr(ty::ctxt tcx, node_id t) -> node_id {
fn
expr_to_constr_arg
(
ty
::
ctxt
tcx
,
&@
expr
e
)
->
@
constr_arg_use
{
alt
(
e
.node
)
{
case
(
expr_path
(
?
p
,
_
))
{
case
(
expr_path
(
?
p
))
{
if
(
vec
::
len
(
p
.node.idents
)
==
1u
)
{
ret
@
respan
(
p
.span
,
carg_ident
[
ident
](
p
.node.idents
.
(
0
)));
}
else
{
...
...
@@ -555,7 +554,7 @@ fn expr_to_constr_arg(ty::ctxt tcx, &@expr e) -> @constr_arg_use {
"as pred arg"
);
}
}
case
(
expr_lit
(
?
l
,
_
))
{
ret
@
respan
(
e
.span
,
carg_lit
(
l
));
}
case
(
expr_lit
(
?
l
))
{
ret
@
respan
(
e
.span
,
carg_lit
(
l
));
}
case
(
_
)
{
tcx
.sess
.span_fatal
(
e
.span
,
"Arguments to constrained functions must be "
...
...
@@ -575,11 +574,11 @@ fn expr_to_constr(ty::ctxt tcx, &@expr e) -> constr {
case
(
// FIXME change the first pattern to expr_path to test a
// typechecker bug
expr_call
(
?
operator
,
?
args
,
_
))
{
expr_call
(
?
operator
,
?
args
))
{
alt
(
operator
.node
)
{
case
(
expr_path
(
?
p
,
?
id
))
{
case
(
expr_path
(
?
p
))
{
ret
respan
(
e
.span
,
rec
(
id
=
node_id_for_constr
(
tcx
,
id
),
rec
(
id
=
node_id_for_constr
(
tcx
,
operator
.
id
),
c
=
npred
(
p
,
exprs_to_constr_args
(
tcx
,
args
))));
}
...
...
src/comp/middle/tstate/collect_locals.rs
浏览文件 @
c34e9b33
...
...
@@ -35,15 +35,15 @@ fn collect_local(&ctxt cx, &@local loc) {
fn
collect_pred
(
&
ctxt
cx
,
&@
expr
e
)
{
alt
(
e
.node
)
{
case
(
expr_check
(
?
e
,
_
))
{
vec
::
push
(
*
cx
.cs
,
expr_to_constr
(
cx
.tcx
,
e
));
case
(
expr_check
(
?
ch
))
{
vec
::
push
(
*
cx
.cs
,
expr_to_constr
(
cx
.tcx
,
ch
));
}
case
(
expr_if_check
(
?
e
,
_
,
_
,
_
))
{
vec
::
push
(
*
cx
.cs
,
expr_to_constr
(
cx
.tcx
,
e
));
case
(
expr_if_check
(
?
e
x
,
_
,
_
))
{
vec
::
push
(
*
cx
.cs
,
expr_to_constr
(
cx
.tcx
,
e
x
));
}
// If it's a call, generate appropriate instances of the
// call's constraints.
case
(
expr_call
(
?
operator
,
?
operands
,
_
))
{
case
(
expr_call
(
?
operator
,
?
operands
))
{
for
(
@
ty
::
constr_def
c
in
constraints_expr
(
cx
.tcx
,
operator
))
{
let
aux
::
constr
ct
=
respan
(
c
.span
,
rec
(
id
=
c
.node.id._1
,
...
...
src/comp/middle/tstate/pre_post_conditions.rs
浏览文件 @
c34e9b33
...
...
@@ -60,7 +60,6 @@
import
bitvectors
::
gen
;
import
bitvectors
::
relax_precond_block
;
import
front
::
ast
::
*
;
import
middle
::
ty
::
expr_node_id
;
import
util
::
common
::
new_int_hash
;
import
util
::
common
::
new_def_hash
;
import
util
::
common
::
uistr
;
...
...
@@ -189,7 +188,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq,
alt
(
chck
)
{
case
(
if_check
)
{
let
aux
::
constr
c
=
expr_to_constr
(
fcx
.ccx.tcx
,
antec
);
gen
(
fcx
,
expr_node_id
(
antec
)
,
c
.node
);
gen
(
fcx
,
antec
.id
,
c
.node
);
}
case
(
_
)
{}
}
...
...
@@ -222,7 +221,7 @@ fn join_then_else(&fn_ctxt fcx, &@expr antec, &block conseq,
alt
(
chck
)
{
case
(
if_check
)
{
let
aux
::
constr
c
=
expr_to_constr
(
fcx
.ccx.tcx
,
antec
);
gen
(
fcx
,
expr_node_id
(
antec
)
,
c
.node
);
gen
(
fcx
,
antec
.id
,
c
.node
);
}
case
(
_
)
{}
}
...
...
@@ -278,10 +277,10 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
"):"
;
log_expr
(
*
e
);
alt
(
e
.node
)
{
case
(
expr_call
(
?
operator
,
?
operands
,
?
id
))
{
case
(
expr_call
(
?
operator
,
?
operands
))
{
auto
args
=
vec
::
clone
[
@
expr
](
operands
);
vec
::
push
[
@
expr
](
args
,
operator
);
find_pre_post_exprs
(
fcx
,
args
,
id
);
find_pre_post_exprs
(
fcx
,
args
,
e
.
id
);
/* see if the call has any constraints on its type */
log
"a function: "
;
...
...
@@ -299,25 +298,25 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
/* if this is a failing call, its postcondition sets everything */
alt
(
controlflow_expr
(
fcx
.ccx
,
operator
))
{
case
(
noreturn
)
{
set_postcond_false
(
fcx
.ccx
,
id
);
}
case
(
noreturn
)
{
set_postcond_false
(
fcx
.ccx
,
e
.
id
);
}
case
(
_
)
{
}
}
}
case
(
expr_spawn
(
_
,
_
,
?
operator
,
?
operands
,
?
id
))
{
case
(
expr_spawn
(
_
,
_
,
?
operator
,
?
operands
))
{
auto
args
=
vec
::
clone
[
@
expr
](
operands
);
vec
::
push
[
@
expr
](
args
,
operator
);
find_pre_post_exprs
(
fcx
,
args
,
id
);
find_pre_post_exprs
(
fcx
,
args
,
e
.
id
);
}
case
(
expr_vec
(
?
args
,
_
,
_
,
?
id
))
{
find_pre_post_exprs
(
fcx
,
args
,
id
);
case
(
expr_vec
(
?
args
,
_
,
_
))
{
find_pre_post_exprs
(
fcx
,
args
,
e
.
id
);
}
case
(
expr_tup
(
?
elts
,
?
id
))
{
find_pre_post_exprs
(
fcx
,
elt_exprs
(
elts
),
id
);
case
(
expr_tup
(
?
elts
))
{
find_pre_post_exprs
(
fcx
,
elt_exprs
(
elts
),
e
.
id
);
}
case
(
expr_path
(
?
p
,
?
id
))
{
case
(
expr_path
(
?
p
))
{
auto
res
=
expr_pp
(
fcx
.ccx
,
e
);
clear_pp
(
res
);
auto
df
=
node_id_to_def_strict
(
fcx
.ccx.tcx
,
id
);
auto
df
=
node_id_to_def_strict
(
fcx
.ccx.tcx
,
e
.
id
);
alt
(
df
)
{
case
(
def_local
(
?
d_id
))
{
auto
i
=
...
...
@@ -329,126 +328,121 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
case
(
_
)
{
/* nothing to check */
}
}
}
case
(
expr_self_method
(
?
v
,
?
id
))
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
case
(
expr_log
(
_
,
?
arg
,
?
id
))
{
case
(
expr_self_method
(
?
v
))
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
case
(
expr_log
(
_
,
?
arg
))
{
find_pre_post_expr
(
fcx
,
arg
);
copy_pre_post
(
fcx
.ccx
,
id
,
arg
);
copy_pre_post
(
fcx
.ccx
,
e
.
id
,
arg
);
}
case
(
expr_chan
(
?
arg
,
?
id
))
{
case
(
expr_chan
(
?
arg
))
{
find_pre_post_expr
(
fcx
,
arg
);
copy_pre_post
(
fcx
.ccx
,
id
,
arg
);
copy_pre_post
(
fcx
.ccx
,
e
.
id
,
arg
);
}
case
(
expr_put
(
?
opt
,
?
id
))
{
case
(
expr_put
(
?
opt
))
{
alt
(
opt
)
{
case
(
some
(
?
arg
))
{
find_pre_post_expr
(
fcx
,
arg
);
copy_pre_post
(
fcx
.ccx
,
id
,
arg
);
copy_pre_post
(
fcx
.ccx
,
e
.
id
,
arg
);
}
case
(
none
)
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
}
}
case
(
// FIXME this was just put in here as a placeholder
expr_fn
(
?
f
,
?
id
))
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
case
(
expr_block
(
?
b
,
?
id
))
{
// FIXME this was just put in here as a placeholder
case
(
expr_fn
(
?
f
))
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
case
(
expr_block
(
?
b
))
{
find_pre_post_block
(
fcx
,
b
);
auto
p
=
block_pp
(
fcx
.ccx
,
b
);
set_pre_and_post
(
fcx
.ccx
,
id
,
p
.precondition
,
p
.postcondition
);
set_pre_and_post
(
fcx
.ccx
,
e
.
id
,
p
.precondition
,
p
.postcondition
);
}
case
(
expr_rec
(
?
fields
,
?
maybe_base
,
?
id
))
{
case
(
expr_rec
(
?
fields
,
?
maybe_base
))
{
auto
es
=
field_exprs
(
fields
);
vec
::
plus_option
[
@
expr
](
es
,
maybe_base
);
find_pre_post_exprs
(
fcx
,
es
,
id
);
find_pre_post_exprs
(
fcx
,
es
,
e
.
id
);
}
case
(
expr_move
(
?
lhs
,
?
rhs
,
?
id
))
{
case
(
expr_move
(
?
lhs
,
?
rhs
))
{
// FIXME: this needs to deinitialize the rhs
alt
(
lhs
.node
)
{
case
(
expr_path
(
?
p
,
?
a_lhs
))
{
gen_if_local
(
fcx
,
lhs
,
rhs
,
id
,
a_lhs
,
p
);
case
(
expr_path
(
?
p
))
{
gen_if_local
(
fcx
,
lhs
,
rhs
,
e
.id
,
lhs
.id
,
p
);
}
case
(
_
)
{
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
id
);
}
case
(
_
)
{
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
e
.
id
);
}
}
}
case
(
expr_swap
(
?
lhs
,
?
rhs
,
?
id
))
{
case
(
expr_swap
(
?
lhs
,
?
rhs
))
{
// Both sides must already be initialized
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
id
);
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
e
.
id
);
}
case
(
expr_assign
(
?
lhs
,
?
rhs
,
?
id
))
{
case
(
expr_assign
(
?
lhs
,
?
rhs
))
{
alt
(
lhs
.node
)
{
case
(
expr_path
(
?
p
,
?
a_lhs
))
{
gen_if_local
(
fcx
,
lhs
,
rhs
,
id
,
a_lhs
,
p
);
case
(
expr_path
(
?
p
))
{
gen_if_local
(
fcx
,
lhs
,
rhs
,
e
.id
,
lhs
.id
,
p
);
}
case
(
_
)
{
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
id
);
}
case
(
_
)
{
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
e
.
id
);
}
}
}
case
(
expr_recv
(
?
lhs
,
?
rhs
,
?
id
))
{
case
(
expr_recv
(
?
lhs
,
?
rhs
))
{
alt
(
rhs
.node
)
{
case
(
expr_path
(
?
p
,
?
id_rhs
))
{
gen_if_local
(
fcx
,
rhs
,
lhs
,
id
,
id_rhs
,
p
);
case
(
expr_path
(
?
p
))
{
gen_if_local
(
fcx
,
rhs
,
lhs
,
e
.id
,
rhs
.id
,
p
);
}
case
(
_
)
{
// doesn't check that rhs is an lval, but
// that's probably ok
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
id
);
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
e
.
id
);
}
}
}
case
(
expr_assign_op
(
_
,
?
lhs
,
?
rhs
,
?
id
))
{
case
(
expr_assign_op
(
_
,
?
lhs
,
?
rhs
))
{
/* Different from expr_assign in that the lhs *must*
already be initialized */
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
id
);
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
e
.
id
);
}
case
(
expr_lit
(
_
,
?
id
))
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
case
(
expr_ret
(
?
maybe_val
,
?
id
))
{
case
(
expr_lit
(
_
))
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
case
(
expr_ret
(
?
maybe_val
))
{
alt
(
maybe_val
)
{
case
(
none
)
{
clear_precond
(
fcx
.ccx
,
id
);
set_postcond_false
(
fcx
.ccx
,
id
);
clear_precond
(
fcx
.ccx
,
e
.
id
);
set_postcond_false
(
fcx
.ccx
,
e
.
id
);
}
case
(
some
(
?
ret_val
))
{
find_pre_post_expr
(
fcx
,
ret_val
);
set_precondition
(
node_id_to_ts_ann
(
fcx
.ccx
,
id
),
set_precondition
(
node_id_to_ts_ann
(
fcx
.ccx
,
e
.
id
),
expr_precond
(
fcx
.ccx
,
ret_val
));
set_postcond_false
(
fcx
.ccx
,
id
);
set_postcond_false
(
fcx
.ccx
,
e
.
id
);
}
}
}
case
(
expr_be
(
?
e
,
?
id
))
{
find_pre_post_expr
(
fcx
,
e
);
set_pre_and_post
(
fcx
.ccx
,
id
,
expr_prestate
(
fcx
.ccx
,
e
),
case
(
expr_be
(
?
val
))
{
find_pre_post_expr
(
fcx
,
val
);
set_pre_and_post
(
fcx
.ccx
,
e
.id
,
expr_prestate
(
fcx
.ccx
,
val
),
false_postcond
(
num_local_vars
));
}
case
(
expr_if
(
?
antec
,
?
conseq
,
?
maybe_alt
,
?
id
))
{
join_then_else
(
fcx
,
antec
,
conseq
,
maybe_alt
,
id
,
plain_if
);
case
(
expr_if
(
?
antec
,
?
conseq
,
?
maybe_alt
))
{
join_then_else
(
fcx
,
antec
,
conseq
,
maybe_alt
,
e
.
id
,
plain_if
);
}
case
(
expr_binary
(
?
bop
,
?
l
,
?
r
,
?
id
))
{
case
(
expr_binary
(
?
bop
,
?
l
,
?
r
))
{
/* *unless* bop is lazy (e.g. and, or)?
FIXME */
find_pre_post_exprs
(
fcx
,
[
l
,
r
],
id
);
find_pre_post_exprs
(
fcx
,
[
l
,
r
],
e
.
id
);
}
case
(
expr_send
(
?
l
,
?
r
,
?
id
))
{
find_pre_post_exprs
(
fcx
,
[
l
,
r
],
id
);
case
(
expr_send
(
?
l
,
?
r
))
{
find_pre_post_exprs
(
fcx
,
[
l
,
r
],
e
.
id
);
}
case
(
expr_unary
(
_
,
?
operand
,
?
id
))
{
case
(
expr_unary
(
_
,
?
operand
))
{
find_pre_post_expr
(
fcx
,
operand
);
copy_pre_post
(
fcx
.ccx
,
id
,
operand
);
copy_pre_post
(
fcx
.ccx
,
e
.
id
,
operand
);
}
case
(
expr_cast
(
?
operand
,
_
,
?
id
))
{
case
(
expr_cast
(
?
operand
,
_
))
{
find_pre_post_expr
(
fcx
,
operand
);
copy_pre_post
(
fcx
.ccx
,
id
,
operand
);
copy_pre_post
(
fcx
.ccx
,
e
.
id
,
operand
);
}
case
(
expr_while
(
?
test
,
?
body
,
?
id
))
{
case
(
expr_while
(
?
test
,
?
body
))
{
find_pre_post_expr
(
fcx
,
test
);
find_pre_post_block
(
fcx
,
body
);
log
"666"
;
set_pre_and_post
(
fcx
.ccx
,
id
,
set_pre_and_post
(
fcx
.ccx
,
e
.id
,
seq_preconds
(
fcx
,
[
expr_pp
(
fcx
.ccx
,
test
),
block_pp
(
fcx
.ccx
,
body
)]),
...
...
@@ -457,7 +451,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
block_postcond
(
fcx
.ccx
,
body
)]));
}
case
(
expr_do_while
(
?
body
,
?
test
,
?
id
))
{
case
(
expr_do_while
(
?
body
,
?
test
))
{
find_pre_post_block
(
fcx
,
body
);
find_pre_post_expr
(
fcx
,
test
);
auto
loop_postcond
=
...
...
@@ -470,22 +464,22 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
if
(
has_nonlocal_exits
(
body
))
{
loop_postcond
=
empty_poststate
(
num_local_vars
);
}
set_pre_and_post
(
fcx
.ccx
,
id
,
set_pre_and_post
(
fcx
.ccx
,
e
.
id
,
seq_preconds
(
fcx
,
[
block_pp
(
fcx
.ccx
,
body
),
expr_pp
(
fcx
.ccx
,
test
)]),
loop_postcond
);
}
case
(
expr_for
(
?
d
,
?
index
,
?
body
,
?
id
))
{
find_pre_post_loop
(
fcx
,
d
,
index
,
body
,
id
);
case
(
expr_for
(
?
d
,
?
index
,
?
body
))
{
find_pre_post_loop
(
fcx
,
d
,
index
,
body
,
e
.
id
);
}
case
(
expr_for_each
(
?
d
,
?
index
,
?
body
,
?
id
))
{
find_pre_post_loop
(
fcx
,
d
,
index
,
body
,
id
);
case
(
expr_for_each
(
?
d
,
?
index
,
?
body
))
{
find_pre_post_loop
(
fcx
,
d
,
index
,
body
,
e
.
id
);
}
case
(
expr_index
(
?
e
,
?
sub
,
?
id
))
{
find_pre_post_exprs
(
fcx
,
[
e
,
sub
],
id
);
case
(
expr_index
(
?
val
,
?
sub
))
{
find_pre_post_exprs
(
fcx
,
[
val
,
sub
],
e
.
id
);
}
case
(
expr_alt
(
?
ex
,
?
alts
,
?
id
))
{
case
(
expr_alt
(
?
ex
,
?
alts
))
{
find_pre_post_expr
(
fcx
,
ex
);
fn
do_an_alt
(
&
fn_ctxt
fcx
,
&
arm
an_alt
)
->
pre_and_post
{
find_pre_post_block
(
fcx
,
an_alt
.block
);
...
...
@@ -495,7 +489,6 @@ fn do_an_alt(&fn_ctxt fcx, &arm an_alt) -> pre_and_post {
auto
alt_pps
=
vec
::
map
[
arm
,
pre_and_post
](
f
,
alts
);
fn
combine_pp
(
pre_and_post
antec
,
fn_ctxt
fcx
,
&
pre_and_post
pp
,
&
pre_and_post
next
)
->
pre_and_post
{
log
"777"
;
union
(
pp
.precondition
,
seq_preconds
(
fcx
,
[
antec
,
next
]));
intersect
(
pp
.postcondition
,
next
.postcondition
);
ret
pp
;
...
...
@@ -507,54 +500,54 @@ fn combine_pp(pre_and_post antec, fn_ctxt fcx, &pre_and_post pp,
auto
g
=
bind
combine_pp
(
antec_pp
,
fcx
,
_
,
_
);
auto
alts_overall_pp
=
vec
::
foldl
[
pre_and_post
,
pre_and_post
](
g
,
e_pp
,
alt_pps
);
set_pre_and_post
(
fcx
.ccx
,
id
,
alts_overall_pp
.precondition
,
set_pre_and_post
(
fcx
.ccx
,
e
.
id
,
alts_overall_pp
.precondition
,
alts_overall_pp
.postcondition
);
}
case
(
expr_field
(
?
operator
,
_
,
?
id
))
{
case
(
expr_field
(
?
operator
,
_
))
{
find_pre_post_expr
(
fcx
,
operator
);
copy_pre_post
(
fcx
.ccx
,
id
,
operator
);
copy_pre_post
(
fcx
.ccx
,
e
.
id
,
operator
);
}
case
(
expr_fail
(
?
id
,
_
))
{
set_pre_and_post
(
fcx
.ccx
,
id
,
case
(
expr_fail
(
_
))
{
set_pre_and_post
(
fcx
.ccx
,
e
.
id
,
/* if execution continues after fail,
then everything is true! */
empty_prestate
(
num_local_vars
),
false_postcond
(
num_local_vars
));
}
case
(
expr_assert
(
?
p
,
?
id
))
{
case
(
expr_assert
(
?
p
))
{
find_pre_post_expr
(
fcx
,
p
);
copy_pre_post
(
fcx
.ccx
,
id
,
p
);
copy_pre_post
(
fcx
.ccx
,
e
.
id
,
p
);
}
case
(
expr_check
(
?
p
,
?
id
))
{
case
(
expr_check
(
?
p
))
{
find_pre_post_expr
(
fcx
,
p
);
copy_pre_post
(
fcx
.ccx
,
id
,
p
);
copy_pre_post
(
fcx
.ccx
,
e
.
id
,
p
);
/* predicate p holds after this expression executes */
let
aux
::
constr
c
=
expr_to_constr
(
fcx
.ccx.tcx
,
p
);
gen
(
fcx
,
id
,
c
.node
);
gen
(
fcx
,
e
.
id
,
c
.node
);
}
case
(
expr_if_check
(
?
p
,
?
conseq
,
?
maybe_alt
,
?
id
))
{
join_then_else
(
fcx
,
p
,
conseq
,
maybe_alt
,
id
,
if_check
);
case
(
expr_if_check
(
?
p
,
?
conseq
,
?
maybe_alt
))
{
join_then_else
(
fcx
,
p
,
conseq
,
maybe_alt
,
e
.
id
,
if_check
);
}
case
(
expr_bind
(
?
operator
,
?
maybe_args
,
?
id
))
{
case
(
expr_bind
(
?
operator
,
?
maybe_args
))
{
auto
args
=
vec
::
cat_options
[
@
expr
](
maybe_args
);
vec
::
push
[
@
expr
](
args
,
operator
);
/* ??? order of eval? */
find_pre_post_exprs
(
fcx
,
args
,
id
);
find_pre_post_exprs
(
fcx
,
args
,
e
.
id
);
}
case
(
expr_break
(
?
id
)
)
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
case
(
expr_cont
(
?
id
)
)
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
case
(
expr_port
(
?
id
)
)
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
case
(
expr_ext
(
_
,
_
,
_
,
?
expanded
,
?
id
))
{
case
(
expr_break
)
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
case
(
expr_cont
)
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
case
(
expr_port
)
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
case
(
expr_ext
(
_
,
_
,
_
,
?
expanded
))
{
find_pre_post_expr
(
fcx
,
expanded
);
copy_pre_post
(
fcx
.ccx
,
id
,
expanded
);
copy_pre_post
(
fcx
.ccx
,
e
.
id
,
expanded
);
}
case
(
expr_anon_obj
(
?
anon_obj
,
_
,
_
,
?
id
))
{
case
(
expr_anon_obj
(
?
anon_obj
,
_
,
_
))
{
alt
(
anon_obj
.with_obj
)
{
case
(
some
(
?
ex
))
{
find_pre_post_expr
(
fcx
,
ex
);
copy_pre_post
(
fcx
.ccx
,
id
,
ex
);
copy_pre_post
(
fcx
.ccx
,
e
.
id
,
ex
);
}
case
(
none
)
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
}
...
...
@@ -672,8 +665,7 @@ fn find_pre_post_fn(&fn_ctxt fcx, &_fn f) {
// Treat the tail expression as a return statement
alt
(
f
.body.node.expr
)
{
case
(
some
(
?
tailexpr
))
{
auto
tailann
=
expr_node_id
(
tailexpr
);
set_postcond_false
(
fcx
.ccx
,
tailann
);
set_postcond_false
(
fcx
.ccx
,
tailexpr
.id
);
}
case
(
none
)
{
/* fallthrough */
}
}
...
...
src/comp/middle/tstate/states.rs
浏览文件 @
c34e9b33
此差异已折叠。
点击以展开。
src/comp/middle/ty.rs
浏览文件 @
c34e9b33
...
...
@@ -42,7 +42,6 @@
export
decl_local_ty
;
export
def_has_ty_params
;
export
eq_ty
;
export
expr_node_id
;
export
expr_has_ty_params
;
export
expr_ty
;
export
fold_ty
;
...
...
@@ -1730,53 +1729,6 @@ fn pat_ty(&ctxt cx, &@ast::pat pat) -> t {
ret
node_id_to_monotype
(
cx
,
pat_node_id
(
pat
));
}
fn
expr_node_id
(
&@
ast
::
expr
e
)
->
ast
::
node_id
{
ret
alt
(
e
.node
)
{
case
(
ast
::
expr_vec
(
_
,
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_tup
(
_
,
?
id
))
{
id
}
case
(
ast
::
expr_rec
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_call
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_bind
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_binary
(
_
,
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_unary
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_lit
(
_
,
?
id
))
{
id
}
case
(
ast
::
expr_cast
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_if
(
_
,
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_if_check
(
_
,
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_while
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_for
(
_
,
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_for_each
(
_
,
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_do_while
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_alt
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_fn
(
_
,
?
id
))
{
id
}
case
(
ast
::
expr_block
(
_
,
?
id
))
{
id
}
case
(
ast
::
expr_move
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_assign
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_swap
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_assign_op
(
_
,
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_send
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_recv
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_field
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_index
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_path
(
_
,
?
id
))
{
id
}
case
(
ast
::
expr_ext
(
_
,
_
,
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_fail
(
?
id
,
_
))
{
id
}
case
(
ast
::
expr_ret
(
_
,
?
id
))
{
id
}
case
(
ast
::
expr_put
(
_
,
?
id
))
{
id
}
case
(
ast
::
expr_be
(
_
,
?
id
))
{
id
}
case
(
ast
::
expr_log
(
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_assert
(
_
,
?
id
))
{
id
}
case
(
ast
::
expr_check
(
_
,
?
id
))
{
id
}
case
(
ast
::
expr_port
(
?
id
))
{
id
}
case
(
ast
::
expr_chan
(
_
,
?
id
))
{
id
}
case
(
ast
::
expr_anon_obj
(
_
,
_
,
_
,
?
id
))
{
id
}
case
(
ast
::
expr_break
(
?
id
))
{
id
}
case
(
ast
::
expr_cont
(
?
id
))
{
id
}
case
(
ast
::
expr_self_method
(
_
,
?
id
))
{
id
}
case
(
ast
::
expr_spawn
(
_
,
_
,
_
,
_
,
?
id
))
{
id
}
}
}
// Returns the type of an expression as a monotype.
//
...
...
@@ -1785,16 +1737,16 @@ fn expr_node_id(&@ast::expr e) -> ast::node_id {
// instead of "fn(&T) -> T with T = int". If this isn't what you want, see
// expr_ty_params_and_ty() below.
fn
expr_ty
(
&
ctxt
cx
,
&@
ast
::
expr
expr
)
->
t
{
ret
node_id_to_monotype
(
cx
,
expr
_node_id
(
expr
)
);
ret
node_id_to_monotype
(
cx
,
expr
.id
);
}
fn
expr_ty_params_and_ty
(
&
ctxt
cx
,
&@
ast
::
expr
expr
)
->
tup
(
vec
[
t
],
t
)
{
auto
a
=
expr_node_id
(
expr
);
ret
tup
(
node_id_to_type_params
(
cx
,
a
),
node_id_to_type
(
cx
,
a
));
ret
tup
(
node_id_to_type_params
(
cx
,
expr
.id
),
node_id_to_type
(
cx
,
expr
.id
));
}
fn
expr_has_ty_params
(
&
ctxt
cx
,
&@
ast
::
expr
expr
)
->
bool
{
ret
node_id_has_type_params
(
cx
,
expr
_node_id
(
expr
)
);
ret
node_id_has_type_params
(
cx
,
expr
.id
);
}
fn
decl_local_ty
(
&
ctxt
cx
,
&@
ast
::
local
l
)
->
t
{
...
...
@@ -1873,10 +1825,10 @@ fn method_lteq(&method a, &method b) -> bool {
fn
is_lval
(
&@
ast
::
expr
expr
)
->
bool
{
alt
(
expr
.node
)
{
case
(
ast
::
expr_field
(
_
,
_
,
_
))
{
ret
true
;
}
case
(
ast
::
expr_index
(
_
,
_
,
_
))
{
ret
true
;
}
case
(
ast
::
expr_path
(
_
,
_
))
{
ret
true
;
}
case
(
ast
::
expr_unary
(
ast
::
deref
,
_
,
_
))
{
ret
true
;
}
case
(
ast
::
expr_field
(
_
,
_
))
{
ret
true
;
}
case
(
ast
::
expr_index
(
_
,
_
))
{
ret
true
;
}
case
(
ast
::
expr_path
(
_
))
{
ret
true
;
}
case
(
ast
::
expr_unary
(
ast
::
deref
,
_
))
{
ret
true
;
}
case
(
_
)
{
ret
false
;
}
}
}
...
...
src/comp/middle/typeck.rs
浏览文件 @
c34e9b33
...
...
@@ -976,7 +976,7 @@ fn visit_stmt_pre(@fn_ctxt fcx, &@ast::stmt s) {
resolve_type_vars_for_node
(
fcx
,
s
.span
,
ty
::
stmt_node_id
(
s
));
}
fn
visit_expr_pre
(
@
fn_ctxt
fcx
,
&@
ast
::
expr
e
)
{
resolve_type_vars_for_node
(
fcx
,
e
.span
,
ty
::
expr_node_id
(
e
)
);
resolve_type_vars_for_node
(
fcx
,
e
.span
,
e
.id
);
}
fn
visit_block_pre
(
@
fn_ctxt
fcx
,
&
ast
::
block
b
)
{
resolve_type_vars_for_node
(
fcx
,
b
.span
,
b
.node.id
);
...
...
@@ -1139,7 +1139,7 @@ fn replace_expr_type(&@fn_ctxt fcx, &@ast::expr expr,
if
(
ty
::
expr_has_ty_params
(
fcx
.ccx.tcx
,
expr
))
{
new_tps
=
some
[
vec
[
ty
::
t
]](
new_tyt
._0
);
}
else
{
new_tps
=
none
[
vec
[
ty
::
t
]];
}
write
::
ty_fixup
(
fcx
,
ty
::
expr_node_id
(
expr
)
,
tup
(
new_tps
,
new_tyt
._1
));
write
::
ty_fixup
(
fcx
,
expr
.id
,
tup
(
new_tps
,
new_tyt
._1
));
}
...
...
@@ -1282,9 +1282,9 @@ fn require_pure_call(@crate_ctxt ccx, &ast::purity caller_purity,
case
(
ast
::
impure_fn
)
{
ret
;
}
case
(
ast
::
pure_fn
)
{
alt
(
callee
.node
)
{
case
(
ast
::
expr_path
(
_
,
?
id
))
{
case
(
ast
::
expr_path
(
_
))
{
auto
d_id
;
alt
(
ccx
.tcx.def_map
.get
(
id
))
{
alt
(
ccx
.tcx.def_map
.get
(
callee
.
id
))
{
case
(
ast
::
def_fn
(
?
_
d_id
))
{
d_id
=
_
d_id
;
}
}
alt
(
get_function_purity
(
ccx
,
d_id
))
{
...
...
@@ -1425,11 +1425,11 @@ fn check_pred_expr(&@fn_ctxt fcx, &@ast::expr e) {
/* e must be a call expr where all arguments are either
literals or slots */
alt
(
e
.node
)
{
case
(
ast
::
expr_call
(
?
operator
,
?
operands
,
_
))
{
case
(
ast
::
expr_call
(
?
operator
,
?
operands
))
{
alt
(
operator
.node
)
{
case
(
ast
::
expr_path
(
?
oper_name
,
?
id
))
{
case
(
ast
::
expr_path
(
?
oper_name
))
{
auto
d_id
;
alt
(
fcx
.ccx.tcx.def_map
.get
(
id
))
{
alt
(
fcx
.ccx.tcx.def_map
.get
(
operator
.
id
))
{
case
(
ast
::
def_fn
(
?
_
d_id
))
{
d_id
=
_
d_id
;
}
}
for
(
@
ast
::
expr
operand
in
operands
)
{
...
...
@@ -1440,7 +1440,7 @@ fn check_pred_expr(&@fn_ctxt fcx, &@ast::expr e) {
}
}
require_pure_function
(
fcx
.ccx
,
d_id
,
e
.span
);
}
}
case
(
_
)
{
auto
s
=
"In a constraint, expected the
\
constraint name to be an explicit name"
;
...
...
@@ -1477,12 +1477,13 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
write
::
ty_only_fixup
(
fcx
,
id
,
if_t
);
}
auto
id
=
expr
.id
;
alt
(
expr
.node
)
{
case
(
ast
::
expr_lit
(
?
lit
,
?
id
))
{
case
(
ast
::
expr_lit
(
?
lit
))
{
auto
typ
=
check_lit
(
fcx
.ccx
,
lit
);
write
::
ty_only_fixup
(
fcx
,
id
,
typ
);
}
case
(
ast
::
expr_binary
(
?
binop
,
?
lhs
,
?
rhs
,
?
id
))
{
case
(
ast
::
expr_binary
(
?
binop
,
?
lhs
,
?
rhs
))
{
check_expr
(
fcx
,
lhs
);
check_expr
(
fcx
,
rhs
);
...
...
@@ -1505,7 +1506,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
write
::
ty_only_fixup
(
fcx
,
id
,
t
);
}
case
(
ast
::
expr_unary
(
?
unop
,
?
oper
,
?
id
))
{
case
(
ast
::
expr_unary
(
?
unop
,
?
oper
))
{
check_expr
(
fcx
,
oper
);
auto
oper_t
=
expr_ty
(
fcx
.ccx.tcx
,
oper
);
alt
(
unop
)
{
...
...
@@ -1538,13 +1539,13 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
write
::
ty_only_fixup
(
fcx
,
id
,
oper_t
);
}
case
(
ast
::
expr_path
(
?
pth
,
?
old_id
))
{
case
(
ast
::
expr_path
(
?
pth
))
{
auto
t
=
ty
::
mk_nil
(
fcx
.ccx.tcx
);
auto
defn
=
fcx
.ccx.tcx.def_map
.get
(
old_
id
);
auto
defn
=
fcx
.ccx.tcx.def_map
.get
(
id
);
auto
tpt
=
ty_param_count_and_ty_for_def
(
fcx
,
expr
.span
,
defn
);
if
(
ty
::
def_has_ty_params
(
defn
))
{
auto
path_tpot
=
instantiate_path
(
fcx
,
pth
,
tpt
,
expr
.span
);
write
::
ty_fixup
(
fcx
,
old_
id
,
path_tpot
);
write
::
ty_fixup
(
fcx
,
id
,
path_tpot
);
ret
;
}
// The definition doesn't take type parameters. If the programmer
...
...
@@ -1555,17 +1556,17 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
"this kind of value does not
\
take type parameters"
);
}
write
::
ty_only_fixup
(
fcx
,
old_
id
,
tpt
._1
);
write
::
ty_only_fixup
(
fcx
,
id
,
tpt
._1
);
}
case
(
ast
::
expr_ext
(
?
p
,
?
args
,
?
body
,
?
expanded
,
?
id
))
{
case
(
ast
::
expr_ext
(
?
p
,
?
args
,
?
body
,
?
expanded
))
{
check_expr
(
fcx
,
expanded
);
auto
t
=
expr_ty
(
fcx
.ccx.tcx
,
expanded
);
write
::
ty_only_fixup
(
fcx
,
id
,
t
);
}
case
(
ast
::
expr_fail
(
?
id
,
_
))
{
write
::
bot_ty
(
fcx
.ccx.tcx
,
id
);
}
case
(
ast
::
expr_break
(
?
id
)
)
{
write
::
bot_ty
(
fcx
.ccx.tcx
,
id
);
}
case
(
ast
::
expr_cont
(
?
id
)
)
{
write
::
bot_ty
(
fcx
.ccx.tcx
,
id
);
}
case
(
ast
::
expr_ret
(
?
expr_opt
,
?
id
))
{
case
(
ast
::
expr_fail
(
_
))
{
write
::
bot_ty
(
fcx
.ccx.tcx
,
id
);
}
case
(
ast
::
expr_break
)
{
write
::
bot_ty
(
fcx
.ccx.tcx
,
id
);
}
case
(
ast
::
expr_cont
)
{
write
::
bot_ty
(
fcx
.ccx.tcx
,
id
);
}
case
(
ast
::
expr_ret
(
?
expr_opt
))
{
alt
(
expr_opt
)
{
case
(
none
)
{
auto
nil
=
ty
::
mk_nil
(
fcx
.ccx.tcx
);
...
...
@@ -1584,7 +1585,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
}
}
case
(
ast
::
expr_put
(
?
expr_opt
,
?
id
))
{
case
(
ast
::
expr_put
(
?
expr_opt
))
{
require_impure
(
fcx
.ccx.tcx.sess
,
fcx
.purity
,
expr
.span
);
alt
(
expr_opt
)
{
case
(
none
)
{
...
...
@@ -1602,7 +1603,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
}
}
case
(
ast
::
expr_be
(
?
e
,
?
id
))
{
case
(
ast
::
expr_be
(
?
e
))
{
// FIXME: prove instead of assert
assert
(
ast
::
is_call_expr
(
e
));
...
...
@@ -1610,41 +1611,41 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
demand
::
simple
(
fcx
,
e
.span
,
fcx
.ret_ty
,
expr_ty
(
fcx
.ccx.tcx
,
e
));
write
::
nil_ty
(
fcx
.ccx.tcx
,
id
);
}
case
(
ast
::
expr_log
(
?
l
,
?
e
,
?
id
))
{
case
(
ast
::
expr_log
(
?
l
,
?
e
))
{
auto
expr_t
=
check_expr
(
fcx
,
e
);
write
::
nil_ty
(
fcx
.ccx.tcx
,
id
);
}
case
(
ast
::
expr_check
(
?
e
,
?
id
))
{
case
(
ast
::
expr_check
(
?
e
))
{
check_pred_expr
(
fcx
,
e
);
write
::
nil_ty
(
fcx
.ccx.tcx
,
id
);
}
case
(
ast
::
expr_if_check
(
?
cond
,
?
thn
,
?
elsopt
,
?
id
))
{
case
(
ast
::
expr_if_check
(
?
cond
,
?
thn
,
?
elsopt
))
{
check_pred_expr
(
fcx
,
cond
);
check_then_else
(
fcx
,
thn
,
elsopt
,
id
,
expr
.span
);
}
case
(
ast
::
expr_assert
(
?
e
,
?
id
))
{
case
(
ast
::
expr_assert
(
?
e
))
{
check_expr
(
fcx
,
e
);
auto
ety
=
expr_ty
(
fcx
.ccx.tcx
,
e
);
demand
::
simple
(
fcx
,
expr
.span
,
ty
::
mk_bool
(
fcx
.ccx.tcx
),
ety
);
write
::
nil_ty
(
fcx
.ccx.tcx
,
id
);
}
case
(
ast
::
expr_move
(
?
lhs
,
?
rhs
,
?
id
))
{
case
(
ast
::
expr_move
(
?
lhs
,
?
rhs
))
{
require_impure
(
fcx
.ccx.tcx.sess
,
fcx
.purity
,
expr
.span
);
check_assignment
(
fcx
,
expr
.span
,
lhs
,
rhs
,
id
);
}
case
(
ast
::
expr_assign
(
?
lhs
,
?
rhs
,
?
id
))
{
case
(
ast
::
expr_assign
(
?
lhs
,
?
rhs
))
{
require_impure
(
fcx
.ccx.tcx.sess
,
fcx
.purity
,
expr
.span
);
check_assignment
(
fcx
,
expr
.span
,
lhs
,
rhs
,
id
);
}
case
(
ast
::
expr_swap
(
?
lhs
,
?
rhs
,
?
id
))
{
case
(
ast
::
expr_swap
(
?
lhs
,
?
rhs
))
{
require_impure
(
fcx
.ccx.tcx.sess
,
fcx
.purity
,
expr
.span
);
check_assignment
(
fcx
,
expr
.span
,
lhs
,
rhs
,
id
);
}
case
(
ast
::
expr_assign_op
(
?
op
,
?
lhs
,
?
rhs
,
?
id
))
{
case
(
ast
::
expr_assign_op
(
?
op
,
?
lhs
,
?
rhs
))
{
require_impure
(
fcx
.ccx.tcx.sess
,
fcx
.purity
,
expr
.span
);
check_assignment
(
fcx
,
expr
.span
,
lhs
,
rhs
,
id
);
}
case
(
ast
::
expr_send
(
?
lhs
,
?
rhs
,
?
id
))
{
case
(
ast
::
expr_send
(
?
lhs
,
?
rhs
))
{
require_impure
(
fcx
.ccx.tcx.sess
,
fcx
.purity
,
expr
.span
);
check_expr
(
fcx
,
lhs
);
check_expr
(
fcx
,
rhs
);
...
...
@@ -1664,7 +1665,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
write
::
ty_only_fixup
(
fcx
,
id
,
chan_t
);
}
case
(
ast
::
expr_recv
(
?
lhs
,
?
rhs
,
?
id
))
{
case
(
ast
::
expr_recv
(
?
lhs
,
?
rhs
))
{
require_impure
(
fcx
.ccx.tcx.sess
,
fcx
.purity
,
expr
.span
);
check_expr
(
fcx
,
lhs
);
check_expr
(
fcx
,
rhs
);
...
...
@@ -1673,14 +1674,14 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
demand
::
simple
(
fcx
,
expr
.span
,
port_t
,
expr_ty
(
fcx
.ccx.tcx
,
lhs
));
write
::
ty_only_fixup
(
fcx
,
id
,
item_t
);
}
case
(
ast
::
expr_if
(
?
cond
,
?
thn
,
?
elsopt
,
?
id
))
{
case
(
ast
::
expr_if
(
?
cond
,
?
thn
,
?
elsopt
))
{
check_expr
(
fcx
,
cond
);
demand
::
simple
(
fcx
,
cond
.span
,
ty
::
mk_bool
(
fcx
.ccx.tcx
),
expr_ty
(
fcx
.ccx.tcx
,
cond
));
check_then_else
(
fcx
,
thn
,
elsopt
,
id
,
expr
.span
);
}
case
(
ast
::
expr_for
(
?
decl
,
?
seq
,
?
body
,
?
id
))
{
case
(
ast
::
expr_for
(
?
decl
,
?
seq
,
?
body
))
{
check_expr
(
fcx
,
seq
);
auto
elt_ty
;
auto
ety
=
expr_ty
(
fcx
.ccx.tcx
,
seq
);
...
...
@@ -1701,12 +1702,12 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
check_for_or_for_each
(
fcx
,
decl
,
elt_ty
,
body
,
id
);
}
case
(
ast
::
expr_for_each
(
?
decl
,
?
seq
,
?
body
,
?
id
))
{
case
(
ast
::
expr_for_each
(
?
decl
,
?
seq
,
?
body
))
{
check_expr
(
fcx
,
seq
);
check_for_or_for_each
(
fcx
,
decl
,
expr_ty
(
fcx
.ccx.tcx
,
seq
),
body
,
id
);
}
case
(
ast
::
expr_while
(
?
cond
,
?
body
,
?
id
))
{
case
(
ast
::
expr_while
(
?
cond
,
?
body
))
{
check_expr
(
fcx
,
cond
);
check_block
(
fcx
,
body
);
demand
::
simple
(
fcx
,
cond
.span
,
ty
::
mk_bool
(
fcx
.ccx.tcx
),
...
...
@@ -1714,13 +1715,13 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
auto
typ
=
ty
::
mk_nil
(
fcx
.ccx.tcx
);
write
::
ty_only_fixup
(
fcx
,
id
,
typ
);
}
case
(
ast
::
expr_do_while
(
?
body
,
?
cond
,
?
id
))
{
case
(
ast
::
expr_do_while
(
?
body
,
?
cond
))
{
check_expr
(
fcx
,
cond
);
check_block
(
fcx
,
body
);
auto
typ
=
block_ty
(
fcx
.ccx.tcx
,
body
);
write
::
ty_only_fixup
(
fcx
,
id
,
typ
);
}
case
(
ast
::
expr_alt
(
?
expr
,
?
arms
,
?
id
))
{
case
(
ast
::
expr_alt
(
?
expr
,
?
arms
))
{
check_expr
(
fcx
,
expr
);
// Typecheck the patterns first, so that we get types for all the
// bindings.
...
...
@@ -1747,7 +1748,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
write
::
ty_only_fixup
(
fcx
,
id
,
result_ty
);
}
case
(
ast
::
expr_fn
(
?
f
,
?
id
))
{
case
(
ast
::
expr_fn
(
?
f
))
{
auto
cx
=
@
rec
(
tcx
=
fcx
.ccx.tcx
);
auto
convert
=
bind
ast_ty_to_ty
(
cx
.tcx
,
bind
collect
::
getter
(
cx
,
_
),
_
);
...
...
@@ -1758,7 +1759,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
write
::
ty_only_fixup
(
fcx
,
id
,
fty
);
check_fn
(
fcx
.ccx
,
f
.decl
,
f
.proto
,
f
.body
,
id
);
}
case
(
ast
::
expr_block
(
?
b
,
?
id
))
{
case
(
ast
::
expr_block
(
?
b
))
{
check_block
(
fcx
,
b
);
alt
(
b
.node.expr
)
{
case
(
some
(
?
expr
))
{
...
...
@@ -1771,7 +1772,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
}
}
case
(
ast
::
expr_bind
(
?
f
,
?
args
,
?
id
))
{
case
(
ast
::
expr_bind
(
?
f
,
?
args
))
{
// Call the generic checker.
check_call_or_bind
(
fcx
,
expr
.span
,
f
,
args
);
...
...
@@ -1812,7 +1813,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
write
::
ty_only_fixup
(
fcx
,
id
,
t_1
);
}
case
(
ast
::
expr_call
(
?
f
,
?
args
,
?
id
))
{
case
(
ast
::
expr_call
(
?
f
,
?
args
))
{
/* here we're kind of hosed, as f can be any expr
need to restrict it to being an explicit expr_path if we're
inside a pure function, and need an environment mapping from
...
...
@@ -1834,7 +1835,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
write
::
ty_only_fixup
(
fcx
,
id
,
rt_1
);
}
case
(
ast
::
expr_self_method
(
?
ident
,
?
id
))
{
case
(
ast
::
expr_self_method
(
?
ident
))
{
auto
t
=
ty
::
mk_nil
(
fcx
.ccx.tcx
);
let
ty
::
t
this_obj_ty
;
let
option
::
t
[
obj_info
]
this_obj_info
=
get_obj_info
(
fcx
.ccx
);
...
...
@@ -1867,7 +1868,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
write
::
ty_only_fixup
(
fcx
,
id
,
t
);
require_impure
(
fcx
.ccx.tcx.sess
,
fcx
.purity
,
expr
.span
);
}
case
(
ast
::
expr_spawn
(
_
,
_
,
?
f
,
?
args
,
?
id
))
{
case
(
ast
::
expr_spawn
(
_
,
_
,
?
f
,
?
args
))
{
check_call
(
fcx
,
expr
.span
,
f
,
args
);
auto
fty
=
expr_ty
(
fcx
.ccx.tcx
,
f
);
auto
ret_ty
=
ty
::
ret_ty_of_fn_ty
(
fcx
.ccx.tcx
,
fty
);
...
...
@@ -1877,7 +1878,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
auto
typ
=
ty
::
mk_task
(
fcx
.ccx.tcx
);
write
::
ty_only_fixup
(
fcx
,
id
,
typ
);
}
case
(
ast
::
expr_cast
(
?
e
,
?
t
,
?
id
))
{
case
(
ast
::
expr_cast
(
?
e
,
?
t
))
{
check_expr
(
fcx
,
e
);
auto
t_1
=
ast_ty_to_ty_crate
(
fcx
.ccx
,
t
);
// FIXME: there are more forms of cast to support, eventually.
...
...
@@ -1893,7 +1894,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
write
::
ty_only_fixup
(
fcx
,
id
,
t_1
);
}
case
(
ast
::
expr_vec
(
?
args
,
?
mut
,
?
kind
,
?
id
))
{
case
(
ast
::
expr_vec
(
?
args
,
?
mut
,
?
kind
))
{
let
ty
::
t
t
;
if
(
vec
::
len
[
@
ast
::
expr
](
args
)
==
0u
)
{
t
=
next_ty_var
(
fcx
);
...
...
@@ -1917,7 +1918,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
write
::
ty_only_fixup
(
fcx
,
id
,
typ
);
}
case
(
ast
::
expr_tup
(
?
elts
,
?
id
))
{
case
(
ast
::
expr_tup
(
?
elts
))
{
let
vec
[
ty
::
mt
]
elts_mt
=
[];
for
(
ast
::
elt
e
in
elts
)
{
check_expr
(
fcx
,
e
.expr
);
...
...
@@ -1927,7 +1928,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
auto
typ
=
ty
::
mk_tup
(
fcx
.ccx.tcx
,
elts_mt
);
write
::
ty_only_fixup
(
fcx
,
id
,
typ
);
}
case
(
ast
::
expr_rec
(
?
fields
,
?
base
,
?
id
))
{
case
(
ast
::
expr_rec
(
?
fields
,
?
base
))
{
alt
(
base
)
{
case
(
none
)
{
/* no-op */
}
case
(
some
(
?
b_0
))
{
check_expr
(
fcx
,
b_0
);
}
...
...
@@ -1977,7 +1978,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
}
}
case
(
ast
::
expr_field
(
?
base
,
?
field
,
?
id
))
{
case
(
ast
::
expr_field
(
?
base
,
?
field
))
{
check_expr
(
fcx
,
base
);
auto
base_t
=
expr_ty
(
fcx
.ccx.tcx
,
base
);
base_t
=
strip_boxes
(
fcx
,
expr
.span
,
base_t
);
...
...
@@ -2024,7 +2025,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
}
}
case
(
ast
::
expr_index
(
?
base
,
?
idx
,
?
id
))
{
case
(
ast
::
expr_index
(
?
base
,
?
idx
))
{
check_expr
(
fcx
,
base
);
auto
base_t
=
expr_ty
(
fcx
.ccx.tcx
,
base
);
base_t
=
strip_boxes
(
fcx
,
expr
.span
,
base_t
);
...
...
@@ -2059,12 +2060,12 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
}
}
case
(
ast
::
expr_port
(
?
id
)
)
{
case
(
ast
::
expr_port
)
{
auto
t
=
next_ty_var
(
fcx
);
auto
pt
=
ty
::
mk_port
(
fcx
.ccx.tcx
,
t
);
write
::
ty_only_fixup
(
fcx
,
id
,
pt
);
}
case
(
ast
::
expr_chan
(
?
x
,
?
id
))
{
case
(
ast
::
expr_chan
(
?
x
))
{
check_expr
(
fcx
,
x
);
auto
port_t
=
expr_ty
(
fcx
.ccx.tcx
,
x
);
alt
(
structure_of
(
fcx
,
expr
.span
,
port_t
))
{
...
...
@@ -2080,7 +2081,7 @@ fn check_then_else(&@fn_ctxt fcx, &ast::block thn,
}
}
}
case
(
ast
::
expr_anon_obj
(
?
anon_obj
,
?
tps
,
?
obj_def_ids
,
?
id
))
{
case
(
ast
::
expr_anon_obj
(
?
anon_obj
,
?
tps
,
?
obj_def_ids
))
{
// TODO: We probably need to do more work here to be able to
// handle additional methods that use 'self'
...
...
src/comp/middle/visit.rs
浏览文件 @
c34e9b33
...
...
@@ -254,121 +254,121 @@ fn visit_exprs[E](vec[@expr] exprs, &E e, &vt[E] v) {
fn
visit_expr
[
E
](
&@
expr
ex
,
&
E
e
,
&
vt
[
E
]
v
)
{
alt
(
ex
.node
)
{
case
(
expr_vec
(
?
es
,
_
,
_
,
_
))
{
visit_exprs
(
es
,
e
,
v
);
}
case
(
expr_tup
(
?
elts
,
_
))
{
case
(
expr_vec
(
?
es
,
_
,
_
))
{
visit_exprs
(
es
,
e
,
v
);
}
case
(
expr_tup
(
?
elts
))
{
for
(
elt
el
in
elts
)
{
vt
(
v
)
.visit_expr
(
el
.expr
,
e
,
v
);
}
}
case
(
expr_rec
(
?
flds
,
?
base
,
_
))
{
case
(
expr_rec
(
?
flds
,
?
base
))
{
for
(
field
f
in
flds
)
{
vt
(
v
)
.visit_expr
(
f
.node.expr
,
e
,
v
);
}
visit_expr_opt
(
base
,
e
,
v
);
}
case
(
expr_call
(
?
callee
,
?
args
,
_
))
{
case
(
expr_call
(
?
callee
,
?
args
))
{
vt
(
v
)
.visit_expr
(
callee
,
e
,
v
);
visit_exprs
(
args
,
e
,
v
);
}
case
(
expr_self_method
(
_
,
_
))
{
}
case
(
expr_bind
(
?
callee
,
?
args
,
_
))
{
case
(
expr_self_method
(
_
))
{
}
case
(
expr_bind
(
?
callee
,
?
args
))
{
vt
(
v
)
.visit_expr
(
callee
,
e
,
v
);
for
(
option
::
t
[
@
expr
]
eo
in
args
)
{
visit_expr_opt
(
eo
,
e
,
v
);
}
}
case
(
expr_spawn
(
_
,
_
,
?
callee
,
?
args
,
_
))
{
case
(
expr_spawn
(
_
,
_
,
?
callee
,
?
args
))
{
vt
(
v
)
.visit_expr
(
callee
,
e
,
v
);
visit_exprs
(
args
,
e
,
v
);
}
case
(
expr_binary
(
_
,
?
a
,
?
b
,
_
))
{
case
(
expr_binary
(
_
,
?
a
,
?
b
))
{
vt
(
v
)
.visit_expr
(
a
,
e
,
v
);
vt
(
v
)
.visit_expr
(
b
,
e
,
v
);
}
case
(
expr_unary
(
_
,
?
a
,
_
))
{
vt
(
v
)
.visit_expr
(
a
,
e
,
v
);
}
case
(
expr_lit
(
_
,
_
))
{
}
case
(
expr_cast
(
?
x
,
?
t
,
_
))
{
case
(
expr_unary
(
_
,
?
a
))
{
vt
(
v
)
.visit_expr
(
a
,
e
,
v
);
}
case
(
expr_lit
(
_
))
{
}
case
(
expr_cast
(
?
x
,
?
t
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
vt
(
v
)
.visit_ty
(
t
,
e
,
v
);
}
case
(
expr_if
(
?
x
,
?
b
,
?
eo
,
_
))
{
case
(
expr_if
(
?
x
,
?
b
,
?
eo
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
vt
(
v
)
.visit_block
(
b
,
e
,
v
);
visit_expr_opt
(
eo
,
e
,
v
);
}
case
(
expr_if_check
(
?
x
,
?
b
,
?
eo
,
_
))
{
case
(
expr_if_check
(
?
x
,
?
b
,
?
eo
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
vt
(
v
)
.visit_block
(
b
,
e
,
v
);
visit_expr_opt
(
eo
,
e
,
v
);
}
case
(
expr_while
(
?
x
,
?
b
,
_
))
{
case
(
expr_while
(
?
x
,
?
b
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
vt
(
v
)
.visit_block
(
b
,
e
,
v
);
}
case
(
expr_for
(
?
dcl
,
?
x
,
?
b
,
_
))
{
case
(
expr_for
(
?
dcl
,
?
x
,
?
b
))
{
vt
(
v
)
.visit_local
(
dcl
,
e
,
v
);
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
vt
(
v
)
.visit_block
(
b
,
e
,
v
);
}
case
(
expr_for_each
(
?
dcl
,
?
x
,
?
b
,
_
))
{
case
(
expr_for_each
(
?
dcl
,
?
x
,
?
b
))
{
vt
(
v
)
.visit_local
(
dcl
,
e
,
v
);
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
vt
(
v
)
.visit_block
(
b
,
e
,
v
);
}
case
(
expr_do_while
(
?
b
,
?
x
,
_
))
{
case
(
expr_do_while
(
?
b
,
?
x
))
{
vt
(
v
)
.visit_block
(
b
,
e
,
v
);
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
}
case
(
expr_alt
(
?
x
,
?
arms
,
_
))
{
case
(
expr_alt
(
?
x
,
?
arms
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
for
(
arm
a
in
arms
)
{
vt
(
v
)
.visit_arm
(
a
,
e
,
v
);
}
}
case
(
expr_fn
(
?
f
,
_
))
{
case
(
expr_fn
(
?
f
))
{
visit_fn_decl
(
f
.decl
,
e
,
v
);
vt
(
v
)
.visit_block
(
f
.body
,
e
,
v
);
}
case
(
expr_block
(
?
b
,
_
))
{
vt
(
v
)
.visit_block
(
b
,
e
,
v
);
}
case
(
expr_assign
(
?
a
,
?
b
,
_
))
{
case
(
expr_block
(
?
b
))
{
vt
(
v
)
.visit_block
(
b
,
e
,
v
);
}
case
(
expr_assign
(
?
a
,
?
b
))
{
vt
(
v
)
.visit_expr
(
b
,
e
,
v
);
vt
(
v
)
.visit_expr
(
a
,
e
,
v
);
}
case
(
expr_move
(
?
a
,
?
b
,
_
))
{
case
(
expr_move
(
?
a
,
?
b
))
{
vt
(
v
)
.visit_expr
(
b
,
e
,
v
);
vt
(
v
)
.visit_expr
(
a
,
e
,
v
);
}
case
(
expr_swap
(
?
a
,
?
b
,
_
))
{
case
(
expr_swap
(
?
a
,
?
b
))
{
vt
(
v
)
.visit_expr
(
a
,
e
,
v
);
vt
(
v
)
.visit_expr
(
b
,
e
,
v
);
}
case
(
expr_assign_op
(
_
,
?
a
,
?
b
,
_
))
{
case
(
expr_assign_op
(
_
,
?
a
,
?
b
))
{
vt
(
v
)
.visit_expr
(
b
,
e
,
v
);
vt
(
v
)
.visit_expr
(
a
,
e
,
v
);
}
case
(
expr_send
(
?
a
,
?
b
,
_
))
{
case
(
expr_send
(
?
a
,
?
b
))
{
vt
(
v
)
.visit_expr
(
a
,
e
,
v
);
vt
(
v
)
.visit_expr
(
b
,
e
,
v
);
}
case
(
expr_recv
(
?
a
,
?
b
,
_
))
{
case
(
expr_recv
(
?
a
,
?
b
))
{
vt
(
v
)
.visit_expr
(
a
,
e
,
v
);
vt
(
v
)
.visit_expr
(
b
,
e
,
v
);
}
case
(
expr_field
(
?
x
,
_
,
_
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
}
case
(
expr_index
(
?
a
,
?
b
,
_
))
{
case
(
expr_field
(
?
x
,
_
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
}
case
(
expr_index
(
?
a
,
?
b
))
{
vt
(
v
)
.visit_expr
(
a
,
e
,
v
);
vt
(
v
)
.visit_expr
(
b
,
e
,
v
);
}
case
(
expr_path
(
?
p
,
_
))
{
case
(
expr_path
(
?
p
))
{
for
(
@
ty
tp
in
p
.node.types
)
{
vt
(
v
)
.visit_ty
(
tp
,
e
,
v
);
}
}
case
(
expr_ext
(
_
,
_
,
_
,
?
expansion
,
_
))
{
case
(
expr_ext
(
_
,
_
,
_
,
?
expansion
))
{
vt
(
v
)
.visit_expr
(
expansion
,
e
,
v
);
}
case
(
expr_fail
(
_
,
_
))
{
}
case
(
expr_break
(
_
)
)
{
}
case
(
expr_cont
(
_
)
)
{
}
case
(
expr_ret
(
?
eo
,
_
))
{
visit_expr_opt
(
eo
,
e
,
v
);
}
case
(
expr_put
(
?
eo
,
_
))
{
visit_expr_opt
(
eo
,
e
,
v
);
}
case
(
expr_be
(
?
x
,
_
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
}
case
(
expr_log
(
_
,
?
x
,
_
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
}
case
(
expr_check
(
?
x
,
_
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
}
case
(
expr_assert
(
?
x
,
_
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
}
case
(
expr_port
(
_
)
)
{
}
case
(
expr_chan
(
?
x
,
_
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
}
case
(
expr_anon_obj
(
?
anon_obj
,
_
,
_
,
_
))
{
case
(
expr_fail
(
_
))
{
}
case
(
expr_break
)
{
}
case
(
expr_cont
)
{
}
case
(
expr_ret
(
?
eo
))
{
visit_expr_opt
(
eo
,
e
,
v
);
}
case
(
expr_put
(
?
eo
))
{
visit_expr_opt
(
eo
,
e
,
v
);
}
case
(
expr_be
(
?
x
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
}
case
(
expr_log
(
_
,
?
x
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
}
case
(
expr_check
(
?
x
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
}
case
(
expr_assert
(
?
x
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
}
case
(
expr_port
)
{
}
case
(
expr_chan
(
?
x
))
{
vt
(
v
)
.visit_expr
(
x
,
e
,
v
);
}
case
(
expr_anon_obj
(
?
anon_obj
,
_
,
_
))
{
alt
(
anon_obj
.fields
)
{
case
(
none
)
{
}
case
(
some
(
?
fields
))
{
...
...
src/comp/middle/walk.rs
浏览文件 @
c34e9b33
...
...
@@ -269,64 +269,64 @@ fn walk_expr(&ast_visitor v, @ast::expr e) {
if
(
!
v
.keep_going
())
{
ret
;
}
v
.visit_expr_pre
(
e
);
alt
(
e
.node
)
{
case
(
ast
::
expr_vec
(
?
es
,
_
,
_
,
_
))
{
walk_exprs
(
v
,
es
);
}
case
(
ast
::
expr_tup
(
?
elts
,
_
))
{
case
(
ast
::
expr_vec
(
?
es
,
_
,
_
))
{
walk_exprs
(
v
,
es
);
}
case
(
ast
::
expr_tup
(
?
elts
))
{
for
(
ast
::
elt
e
in
elts
)
{
walk_expr
(
v
,
e
.expr
);
}
}
case
(
ast
::
expr_rec
(
?
flds
,
?
base
,
_
))
{
case
(
ast
::
expr_rec
(
?
flds
,
?
base
))
{
for
(
ast
::
field
f
in
flds
)
{
walk_expr
(
v
,
f
.node.expr
);
}
walk_expr_opt
(
v
,
base
);
}
case
(
ast
::
expr_call
(
?
callee
,
?
args
,
_
))
{
case
(
ast
::
expr_call
(
?
callee
,
?
args
))
{
walk_expr
(
v
,
callee
);
walk_exprs
(
v
,
args
);
}
case
(
ast
::
expr_self_method
(
_
,
_
))
{
}
case
(
ast
::
expr_bind
(
?
callee
,
?
args
,
_
))
{
case
(
ast
::
expr_self_method
(
_
))
{
}
case
(
ast
::
expr_bind
(
?
callee
,
?
args
))
{
walk_expr
(
v
,
callee
);
for
(
option
::
t
[
@
ast
::
expr
]
eo
in
args
)
{
walk_expr_opt
(
v
,
eo
);
}
}
case
(
ast
::
expr_spawn
(
_
,
_
,
?
callee
,
?
args
,
_
))
{
case
(
ast
::
expr_spawn
(
_
,
_
,
?
callee
,
?
args
))
{
walk_expr
(
v
,
callee
);
walk_exprs
(
v
,
args
);
}
case
(
ast
::
expr_binary
(
_
,
?
a
,
?
b
,
_
))
{
case
(
ast
::
expr_binary
(
_
,
?
a
,
?
b
))
{
walk_expr
(
v
,
a
);
walk_expr
(
v
,
b
);
}
case
(
ast
::
expr_unary
(
_
,
?
a
,
_
))
{
walk_expr
(
v
,
a
);
}
case
(
ast
::
expr_lit
(
_
,
_
))
{
}
case
(
ast
::
expr_cast
(
?
x
,
?
t
,
_
))
{
walk_expr
(
v
,
x
);
walk_ty
(
v
,
t
);
}
case
(
ast
::
expr_if
(
?
x
,
?
b
,
?
eo
,
_
))
{
case
(
ast
::
expr_unary
(
_
,
?
a
))
{
walk_expr
(
v
,
a
);
}
case
(
ast
::
expr_lit
(
_
))
{
}
case
(
ast
::
expr_cast
(
?
x
,
?
t
))
{
walk_expr
(
v
,
x
);
walk_ty
(
v
,
t
);
}
case
(
ast
::
expr_if
(
?
x
,
?
b
,
?
eo
))
{
walk_expr
(
v
,
x
);
walk_block
(
v
,
b
);
walk_expr_opt
(
v
,
eo
);
}
case
(
ast
::
expr_if_check
(
?
x
,
?
b
,
?
eo
,
_
))
{
case
(
ast
::
expr_if_check
(
?
x
,
?
b
,
?
eo
))
{
walk_expr
(
v
,
x
);
walk_block
(
v
,
b
);
walk_expr_opt
(
v
,
eo
);
}
case
(
ast
::
expr_while
(
?
x
,
?
b
,
_
))
{
case
(
ast
::
expr_while
(
?
x
,
?
b
))
{
walk_expr
(
v
,
x
);
walk_block
(
v
,
b
);
}
case
(
ast
::
expr_for
(
?
dcl
,
?
x
,
?
b
,
_
))
{
case
(
ast
::
expr_for
(
?
dcl
,
?
x
,
?
b
))
{
walk_local
(
v
,
dcl
);
walk_expr
(
v
,
x
);
walk_block
(
v
,
b
);
}
case
(
ast
::
expr_for_each
(
?
dcl
,
?
x
,
?
b
,
_
))
{
case
(
ast
::
expr_for_each
(
?
dcl
,
?
x
,
?
b
))
{
walk_local
(
v
,
dcl
);
walk_expr
(
v
,
x
);
walk_block
(
v
,
b
);
}
case
(
ast
::
expr_do_while
(
?
b
,
?
x
,
_
))
{
case
(
ast
::
expr_do_while
(
?
b
,
?
x
))
{
walk_block
(
v
,
b
);
walk_expr
(
v
,
x
);
}
case
(
ast
::
expr_alt
(
?
x
,
?
arms
,
_
))
{
case
(
ast
::
expr_alt
(
?
x
,
?
arms
))
{
walk_expr
(
v
,
x
);
for
(
ast
::
arm
a
in
arms
)
{
walk_pat
(
v
,
a
.pat
);
...
...
@@ -335,48 +335,48 @@ fn walk_expr(&ast_visitor v, @ast::expr e) {
v
.visit_arm_post
(
a
);
}
}
case
(
ast
::
expr_fn
(
?
f
,
?
a
))
{
case
(
ast
::
expr_fn
(
?
f
))
{
walk_fn_decl
(
v
,
f
.decl
);
walk_block
(
v
,
f
.body
);
}
case
(
ast
::
expr_block
(
?
b
,
_
))
{
walk_block
(
v
,
b
);
}
case
(
ast
::
expr_assign
(
?
a
,
?
b
,
_
))
{
case
(
ast
::
expr_block
(
?
b
))
{
walk_block
(
v
,
b
);
}
case
(
ast
::
expr_assign
(
?
a
,
?
b
))
{
walk_expr
(
v
,
a
);
walk_expr
(
v
,
b
);
}
case
(
ast
::
expr_move
(
?
a
,
?
b
,
_
))
{
walk_expr
(
v
,
a
);
walk_expr
(
v
,
b
);
}
case
(
ast
::
expr_swap
(
?
a
,
?
b
,
_
))
{
walk_expr
(
v
,
a
);
walk_expr
(
v
,
b
);
}
case
(
ast
::
expr_assign_op
(
_
,
?
a
,
?
b
,
_
))
{
case
(
ast
::
expr_move
(
?
a
,
?
b
))
{
walk_expr
(
v
,
a
);
walk_expr
(
v
,
b
);
}
case
(
ast
::
expr_swap
(
?
a
,
?
b
))
{
walk_expr
(
v
,
a
);
walk_expr
(
v
,
b
);
}
case
(
ast
::
expr_assign_op
(
_
,
?
a
,
?
b
))
{
walk_expr
(
v
,
a
);
walk_expr
(
v
,
b
);
}
case
(
ast
::
expr_send
(
?
a
,
?
b
,
_
))
{
walk_expr
(
v
,
a
);
walk_expr
(
v
,
b
);
}
case
(
ast
::
expr_recv
(
?
a
,
?
b
,
_
))
{
walk_expr
(
v
,
a
);
walk_expr
(
v
,
b
);
}
case
(
ast
::
expr_field
(
?
x
,
_
,
_
))
{
walk_expr
(
v
,
x
);
}
case
(
ast
::
expr_index
(
?
a
,
?
b
,
_
))
{
case
(
ast
::
expr_send
(
?
a
,
?
b
))
{
walk_expr
(
v
,
a
);
walk_expr
(
v
,
b
);
}
case
(
ast
::
expr_recv
(
?
a
,
?
b
))
{
walk_expr
(
v
,
a
);
walk_expr
(
v
,
b
);
}
case
(
ast
::
expr_field
(
?
x
,
_
))
{
walk_expr
(
v
,
x
);
}
case
(
ast
::
expr_index
(
?
a
,
?
b
))
{
walk_expr
(
v
,
a
);
walk_expr
(
v
,
b
);
}
case
(
ast
::
expr_path
(
?
p
,
_
))
{
case
(
ast
::
expr_path
(
?
p
))
{
for
(
@
ast
::
ty
tp
in
p
.node.types
)
{
walk_ty
(
v
,
tp
);
}
}
case
(
ast
::
expr_ext
(
_
,
?
args
,
?
body
,
?
expansion
,
_
))
{
case
(
ast
::
expr_ext
(
_
,
?
args
,
?
body
,
?
expansion
))
{
// Only walk expansion, not args/body.
walk_expr
(
v
,
expansion
);
}
case
(
ast
::
expr_fail
(
_
,
_
))
{
}
case
(
ast
::
expr_break
(
_
)
)
{
}
case
(
ast
::
expr_cont
(
_
)
)
{
}
case
(
ast
::
expr_ret
(
?
eo
,
_
))
{
walk_expr_opt
(
v
,
eo
);
}
case
(
ast
::
expr_put
(
?
eo
,
_
))
{
walk_expr_opt
(
v
,
eo
);
}
case
(
ast
::
expr_be
(
?
x
,
_
))
{
walk_expr
(
v
,
x
);
}
case
(
ast
::
expr_log
(
_
,
?
x
,
_
))
{
walk_expr
(
v
,
x
);
}
case
(
ast
::
expr_check
(
?
x
,
_
))
{
walk_expr
(
v
,
x
);
}
case
(
ast
::
expr_assert
(
?
x
,
_
))
{
walk_expr
(
v
,
x
);
}
case
(
ast
::
expr_port
(
_
)
)
{
}
case
(
ast
::
expr_chan
(
?
x
,
_
))
{
walk_expr
(
v
,
x
);
}
case
(
ast
::
expr_anon_obj
(
?
anon_obj
,
_
,
_
,
_
))
{
case
(
ast
::
expr_fail
(
_
))
{
}
case
(
ast
::
expr_break
)
{
}
case
(
ast
::
expr_cont
)
{
}
case
(
ast
::
expr_ret
(
?
eo
))
{
walk_expr_opt
(
v
,
eo
);
}
case
(
ast
::
expr_put
(
?
eo
))
{
walk_expr_opt
(
v
,
eo
);
}
case
(
ast
::
expr_be
(
?
x
))
{
walk_expr
(
v
,
x
);
}
case
(
ast
::
expr_log
(
_
,
?
x
))
{
walk_expr
(
v
,
x
);
}
case
(
ast
::
expr_check
(
?
x
))
{
walk_expr
(
v
,
x
);
}
case
(
ast
::
expr_assert
(
?
x
))
{
walk_expr
(
v
,
x
);
}
case
(
ast
::
expr_port
)
{
}
case
(
ast
::
expr_chan
(
?
x
))
{
walk_expr
(
v
,
x
);
}
case
(
ast
::
expr_anon_obj
(
?
anon_obj
,
_
,
_
))
{
// Fields
let
option
::
t
[
vec
[
ast
::
obj_field
]]
fields
=
...
...
src/comp/pretty/pprust.rs
浏览文件 @
c34e9b33
...
...
@@ -519,9 +519,8 @@ fn do_else(&ps s, option::t[@ast::expr] els) {
alt
(
els
)
{
case
(
some
(
?
_
else
))
{
alt
(
_
else
.node
)
{
case
(
// "another else-if"
ast
::
expr_if
(
?
i
,
?
t
,
?
e
,
_
))
{
// "another else-if"
case
(
ast
::
expr_if
(
?
i
,
?
t
,
?
e
))
{
cbox
(
s
,
indent_unit
-
1u
);
ibox
(
s
,
0u
);
word
(
s
.s
,
" else if "
);
...
...
@@ -532,9 +531,8 @@ fn do_else(&ps s, option::t[@ast::expr] els) {
print_block
(
s
,
t
);
do_else
(
s
,
e
);
}
case
(
// "final else"
ast
::
expr_block
(
?
b
,
_
))
{
// "final else"
case
(
ast
::
expr_block
(
?
b
))
{
cbox
(
s
,
indent_unit
-
1u
);
ibox
(
s
,
0u
);
word
(
s
.s
,
" else "
);
...
...
@@ -557,7 +555,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
case
(
mo_identified
)
{
popen
(
s
);
}
}
alt
(
expr
.node
)
{
case
(
ast
::
expr_vec
(
?
exprs
,
?
mut
,
?
kind
,
_
))
{
case
(
ast
::
expr_vec
(
?
exprs
,
?
mut
,
?
kind
))
{
ibox
(
s
,
indent_unit
);
alt
(
kind
)
{
case
(
ast
::
sk_rc
)
{
word
(
s
.s
,
"["
);
}
...
...
@@ -568,7 +566,7 @@ fn print_expr(&ps s, &@ast::expr expr) {
word
(
s
.s
,
"]"
);
end
(
s
);
}
case
(
ast
::
expr_tup
(
?
exprs
,
_
))
{
case
(
ast
::
expr_tup
(
?
exprs
))
{
fn
printElt
(
&
ps
s
,
&
ast
::
elt
elt
)
{
ibox
(
s
,
indent_unit
);
if
(
elt
.mut
==
ast
::
mut
)
{
word_nbsp
(
s
,
"mutable"
);
}
...
...
@@ -581,7 +579,7 @@ fn printElt(&ps s, &ast::elt elt) {
commasep_cmnt
(
s
,
inconsistent
,
exprs
,
printElt
,
get_span
);
pclose
(
s
);
}
case
(
ast
::
expr_rec
(
?
fields
,
?
wth
,
_
))
{
case
(
ast
::
expr_rec
(
?
fields
,
?
wth
))
{
fn
print_field
(
&
ps
s
,
&
ast
::
field
field
)
{
ibox
(
s
,
indent_unit
);
if
(
field
.node.mut
==
ast
::
mut
)
{
word_nbsp
(
s
,
"mutable"
);
}
...
...
@@ -606,17 +604,17 @@ fn print_field(&ps s, &ast::field field) {
}
pclose
(
s
);
}
case
(
ast
::
expr_call
(
?
func
,
?
args
,
_
))
{
case
(
ast
::
expr_call
(
?
func
,
?
args
))
{
print_expr
(
s
,
func
);
popen
(
s
);
commasep_exprs
(
s
,
inconsistent
,
args
);
pclose
(
s
);
}
case
(
ast
::
expr_self_method
(
?
ident
,
_
))
{
case
(
ast
::
expr_self_method
(
?
ident
))
{
word
(
s
.s
,
"self."
);
print_ident
(
s
,
ident
);
}
case
(
ast
::
expr_bind
(
?
func
,
?
args
,
_
))
{
case
(
ast
::
expr_bind
(
?
func
,
?
args
))
{
fn
print_opt
(
&
ps
s
,
&
option
::
t
[
@
ast
::
expr
]
expr
)
{
alt
(
expr
)
{
case
(
some
(
?
expr
))
{
print_expr
(
s
,
expr
);
}
...
...
@@ -629,38 +627,38 @@ fn print_opt(&ps s, &option::t[@ast::expr] expr) {
commasep
(
s
,
inconsistent
,
args
,
print_opt
);
pclose
(
s
);
}
case
(
ast
::
expr_spawn
(
_
,
_
,
?
e
,
?
es
,
_
))
{
case
(
ast
::
expr_spawn
(
_
,
_
,
?
e
,
?
es
))
{
word_nbsp
(
s
,
"spawn"
);
print_expr
(
s
,
e
);
popen
(
s
);
commasep_exprs
(
s
,
inconsistent
,
es
);
pclose
(
s
);
}
case
(
ast
::
expr_binary
(
?
op
,
?
lhs
,
?
rhs
,
_
))
{
case
(
ast
::
expr_binary
(
?
op
,
?
lhs
,
?
rhs
))
{
auto
prec
=
operator_prec
(
op
);
print_maybe_parens
(
s
,
lhs
,
prec
);
space
(
s
.s
);
word_space
(
s
,
ast
::
binop_to_str
(
op
));
print_maybe_parens
(
s
,
rhs
,
prec
+
1
);
}
case
(
ast
::
expr_unary
(
?
op
,
?
expr
,
_
))
{
case
(
ast
::
expr_unary
(
?
op
,
?
expr
))
{
word
(
s
.s
,
ast
::
unop_to_str
(
op
));
print_maybe_parens
(
s
,
expr
,
front
::
parser
::
unop_prec
);
}
case
(
ast
::
expr_lit
(
?
lit
,
_
))
{
print_literal
(
s
,
lit
);
}
case
(
ast
::
expr_cast
(
?
expr
,
?
ty
,
_
))
{
case
(
ast
::
expr_lit
(
?
lit
))
{
print_literal
(
s
,
lit
);
}
case
(
ast
::
expr_cast
(
?
expr
,
?
ty
))
{
print_maybe_parens
(
s
,
expr
,
front
::
parser
::
as_prec
);
space
(
s
.s
);
word_space
(
s
,
"as"
);
print_type
(
s
,
*
ty
);
}
case
(
ast
::
expr_if
(
?
test
,
?
block
,
?
elseopt
,
_
))
{
case
(
ast
::
expr_if
(
?
test
,
?
block
,
?
elseopt
))
{
print_if
(
s
,
test
,
block
,
elseopt
,
false
);
}
case
(
ast
::
expr_if_check
(
?
test
,
?
block
,
?
elseopt
,
_
))
{
case
(
ast
::
expr_if_check
(
?
test
,
?
block
,
?
elseopt
))
{
print_if
(
s
,
test
,
block
,
elseopt
,
true
);
}
case
(
ast
::
expr_while
(
?
test
,
?
block
,
_
))
{
case
(
ast
::
expr_while
(
?
test
,
?
block
))
{
head
(
s
,
"while"
);
popen
(
s
);
print_expr
(
s
,
test
);
...
...
@@ -668,7 +666,7 @@ fn print_opt(&ps s, &option::t[@ast::expr] expr) {
space
(
s
.s
);
print_block
(
s
,
block
);
}
case
(
ast
::
expr_for
(
?
decl
,
?
expr
,
?
block
,
_
))
{
case
(
ast
::
expr_for
(
?
decl
,
?
expr
,
?
block
))
{
head
(
s
,
"for"
);
popen
(
s
);
print_for_decl
(
s
,
decl
);
...
...
@@ -679,7 +677,7 @@ fn print_opt(&ps s, &option::t[@ast::expr] expr) {
space
(
s
.s
);
print_block
(
s
,
block
);
}
case
(
ast
::
expr_for_each
(
?
decl
,
?
expr
,
?
block
,
_
))
{
case
(
ast
::
expr_for_each
(
?
decl
,
?
expr
,
?
block
))
{
head
(
s
,
"for each"
);
popen
(
s
);
print_for_decl
(
s
,
decl
);
...
...
@@ -690,7 +688,7 @@ fn print_opt(&ps s, &option::t[@ast::expr] expr) {
space
(
s
.s
);
print_block
(
s
,
block
);
}
case
(
ast
::
expr_do_while
(
?
block
,
?
expr
,
_
))
{
case
(
ast
::
expr_do_while
(
?
block
,
?
expr
))
{
head
(
s
,
"do"
);
space
(
s
.s
);
print_block
(
s
,
block
);
...
...
@@ -700,7 +698,7 @@ fn print_opt(&ps s, &option::t[@ast::expr] expr) {
print_expr
(
s
,
expr
);
pclose
(
s
);
}
case
(
ast
::
expr_alt
(
?
expr
,
?
arms
,
_
))
{
case
(
ast
::
expr_alt
(
?
expr
,
?
arms
))
{
head
(
s
,
"alt"
);
popen
(
s
);
print_expr
(
s
,
expr
);
...
...
@@ -718,13 +716,13 @@ fn print_opt(&ps s, &option::t[@ast::expr] expr) {
}
bclose
(
s
,
expr
.span
);
}
case
(
ast
::
expr_fn
(
?
f
,
_
))
{
case
(
ast
::
expr_fn
(
?
f
))
{
head
(
s
,
"fn"
);
print_fn_args_and_ret
(
s
,
f
.decl
);
space
(
s
.s
);
print_block
(
s
,
f
.body
);
}
case
(
ast
::
expr_block
(
?
block
,
_
))
{
case
(
ast
::
expr_block
(
?
block
))
{
// containing cbox, will be closed by print-block at }
cbox
(
s
,
indent_unit
);
...
...
@@ -733,103 +731,103 @@ fn print_opt(&ps s, &option::t[@ast::expr] expr) {
ibox
(
s
,
0u
);
print_block
(
s
,
block
);
}
case
(
ast
::
expr_move
(
?
lhs
,
?
rhs
,
_
))
{
case
(
ast
::
expr_move
(
?
lhs
,
?
rhs
))
{
print_expr
(
s
,
lhs
);
space
(
s
.s
);
word_space
(
s
,
"<-"
);
print_expr
(
s
,
rhs
);
}
case
(
ast
::
expr_assign
(
?
lhs
,
?
rhs
,
_
))
{
case
(
ast
::
expr_assign
(
?
lhs
,
?
rhs
))
{
print_expr
(
s
,
lhs
);
space
(
s
.s
);
word_space
(
s
,
"="
);
print_expr
(
s
,
rhs
);
}
case
(
ast
::
expr_swap
(
?
lhs
,
?
rhs
,
_
))
{
case
(
ast
::
expr_swap
(
?
lhs
,
?
rhs
))
{
print_expr
(
s
,
lhs
);
space
(
s
.s
);
word_space
(
s
,
"<->"
);
print_expr
(
s
,
rhs
);
}
case
(
ast
::
expr_assign_op
(
?
op
,
?
lhs
,
?
rhs
,
_
))
{
case
(
ast
::
expr_assign_op
(
?
op
,
?
lhs
,
?
rhs
))
{
print_expr
(
s
,
lhs
);
space
(
s
.s
);
word
(
s
.s
,
ast
::
binop_to_str
(
op
));
word_space
(
s
,
"="
);
print_expr
(
s
,
rhs
);
}
case
(
ast
::
expr_send
(
?
lhs
,
?
rhs
,
_
))
{
case
(
ast
::
expr_send
(
?
lhs
,
?
rhs
))
{
print_expr
(
s
,
lhs
);
space
(
s
.s
);
word_space
(
s
,
"<|"
);
print_expr
(
s
,
rhs
);
}
case
(
ast
::
expr_recv
(
?
lhs
,
?
rhs
,
_
))
{
case
(
ast
::
expr_recv
(
?
lhs
,
?
rhs
))
{
print_expr
(
s
,
lhs
);
space
(
s
.s
);
word_space
(
s
,
"|>"
);
print_expr
(
s
,
rhs
);
}
case
(
ast
::
expr_field
(
?
expr
,
?
id
,
_
))
{
case
(
ast
::
expr_field
(
?
expr
,
?
id
))
{
print_expr
(
s
,
expr
);
word
(
s
.s
,
"."
);
word
(
s
.s
,
id
);
}
case
(
ast
::
expr_index
(
?
expr
,
?
index
,
_
))
{
case
(
ast
::
expr_index
(
?
expr
,
?
index
))
{
print_expr
(
s
,
expr
);
word
(
s
.s
,
"."
);
popen
(
s
);
print_expr
(
s
,
index
);
pclose
(
s
);
}
case
(
ast
::
expr_path
(
?
path
,
_
))
{
print_path
(
s
,
path
);
}
case
(
ast
::
expr_fail
(
_
,
?
str
))
{
case
(
ast
::
expr_path
(
?
path
))
{
print_path
(
s
,
path
);
}
case
(
ast
::
expr_fail
(
?
str
))
{
word
(
s
.s
,
"fail"
);
alt
(
str
)
{
case
(
some
(
?
msg
))
{
word
(
s
.s
,
#
fmt
(
"
\"
%s
\"
"
,
msg
));
}
case
(
_
)
{
}
}
}
case
(
ast
::
expr_break
(
_
)
)
{
word
(
s
.s
,
"break"
);
}
case
(
ast
::
expr_cont
(
_
)
)
{
word
(
s
.s
,
"cont"
);
}
case
(
ast
::
expr_ret
(
?
result
,
_
))
{
case
(
ast
::
expr_break
)
{
word
(
s
.s
,
"break"
);
}
case
(
ast
::
expr_cont
)
{
word
(
s
.s
,
"cont"
);
}
case
(
ast
::
expr_ret
(
?
result
))
{
word
(
s
.s
,
"ret"
);
alt
(
result
)
{
case
(
some
(
?
expr
))
{
word
(
s
.s
,
" "
);
print_expr
(
s
,
expr
);
}
case
(
_
)
{
}
}
}
case
(
ast
::
expr_put
(
?
result
,
_
))
{
case
(
ast
::
expr_put
(
?
result
))
{
word
(
s
.s
,
"put"
);
alt
(
result
)
{
case
(
some
(
?
expr
))
{
word
(
s
.s
,
" "
);
print_expr
(
s
,
expr
);
}
case
(
_
)
{
}
}
}
case
(
ast
::
expr_be
(
?
result
,
_
))
{
case
(
ast
::
expr_be
(
?
result
))
{
word_nbsp
(
s
,
"be"
);
print_expr
(
s
,
result
);
}
case
(
ast
::
expr_log
(
?
lvl
,
?
expr
,
_
))
{
case
(
ast
::
expr_log
(
?
lvl
,
?
expr
))
{
alt
(
lvl
)
{
case
(
1
)
{
word_nbsp
(
s
,
"log"
);
}
case
(
0
)
{
word_nbsp
(
s
,
"log_err"
);
}
}
print_expr
(
s
,
expr
);
}
case
(
ast
::
expr_check
(
?
expr
,
_
))
{
case
(
ast
::
expr_check
(
?
expr
))
{
word_nbsp
(
s
,
"check"
);
popen
(
s
);
print_expr
(
s
,
expr
);
pclose
(
s
);
}
case
(
ast
::
expr_assert
(
?
expr
,
_
))
{
case
(
ast
::
expr_assert
(
?
expr
))
{
word_nbsp
(
s
,
"assert"
);
popen
(
s
);
print_expr
(
s
,
expr
);
pclose
(
s
);
}
case
(
ast
::
expr_ext
(
?
path
,
?
args
,
?
body
,
_
,
_
))
{
case
(
ast
::
expr_ext
(
?
path
,
?
args
,
?
body
,
_
))
{
word
(
s
.s
,
"#"
);
print_path
(
s
,
path
);
if
(
vec
::
len
(
args
)
>
0u
)
{
...
...
@@ -840,14 +838,14 @@ fn print_opt(&ps s, &option::t[@ast::expr] expr) {
// FIXME: extension 'body'
}
case
(
ast
::
expr_port
(
_
)
)
{
word
(
s
.s
,
"port"
);
popen
(
s
);
pclose
(
s
);
}
case
(
ast
::
expr_chan
(
?
expr
,
_
))
{
case
(
ast
::
expr_port
)
{
word
(
s
.s
,
"port"
);
popen
(
s
);
pclose
(
s
);
}
case
(
ast
::
expr_chan
(
?
expr
))
{
word
(
s
.s
,
"chan"
);
popen
(
s
);
print_expr
(
s
,
expr
);
pclose
(
s
);
}
case
(
ast
::
expr_anon_obj
(
_
,
_
,
_
,
_
))
{
case
(
ast
::
expr_anon_obj
(
_
,
_
,
_
))
{
word
(
s
.s
,
"anon obj"
);
// FIXME (issue #499): nicer pretty-printing of anon objs
...
...
@@ -866,7 +864,7 @@ fn print_opt(&ps s, &option::t[@ast::expr] expr) {
}
case
(
mo_identified
)
{
space
(
s
.s
);
synth_comment
(
s
,
int
::
to_str
(
ty
::
expr_node_id
(
expr
)
,
10u
));
synth_comment
(
s
,
int
::
to_str
(
expr
.id
,
10u
));
pclose
(
s
);
}
}
...
...
@@ -1085,10 +1083,10 @@ fn operator_prec(ast::binop op) -> int {
fn
print_maybe_parens
(
&
ps
s
,
&@
ast
::
expr
expr
,
int
outer_prec
)
{
auto
add_them
;
alt
(
expr
.node
)
{
case
(
ast
::
expr_binary
(
?
op
,
_
,
_
,
_
))
{
case
(
ast
::
expr_binary
(
?
op
,
_
,
_
))
{
add_them
=
operator_prec
(
op
)
<
outer_prec
;
}
case
(
ast
::
expr_cast
(
_
,
_
,
_
))
{
case
(
ast
::
expr_cast
(
_
,
_
))
{
add_them
=
front
::
parser
::
as_prec
<
outer_prec
;
}
case
(
_
)
{
add_them
=
false
;
}
...
...
src/comp/util/common.rs
浏览文件 @
c34e9b33
...
...
@@ -152,8 +152,8 @@ fn has_nonlocal_exits(&ast::block b) -> bool {
auto
has_exits
=
@
mutable
false
;
fn
visit_expr
(
@
mutable
bool
flag
,
&@
ast
::
expr
e
)
{
alt
(
e
.node
)
{
case
(
ast
::
expr_break
(
_
)
)
{
*
flag
=
true
;
}
case
(
ast
::
expr_cont
(
_
)
)
{
*
flag
=
true
;
}
case
(
ast
::
expr_break
)
{
*
flag
=
true
;
}
case
(
ast
::
expr_cont
)
{
*
flag
=
true
;
}
case
(
_
)
{
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录