Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
0e2fff53
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,发现更多精彩内容 >>
提交
0e2fff53
编写于
7月 06, 2011
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: Change lots of AST nodes to use interior vectors
上级
bbcbaa66
变更
23
展开全部
隐藏空白更改
内联
并排
Showing
23 changed file
with
400 addition
and
373 deletion
+400
-373
src/comp/front/config.rs
src/comp/front/config.rs
+2
-2
src/comp/front/test.rs
src/comp/front/test.rs
+3
-3
src/comp/metadata/encoder.rs
src/comp/metadata/encoder.rs
+6
-5
src/comp/middle/alias.rs
src/comp/middle/alias.rs
+3
-3
src/comp/middle/resolve.rs
src/comp/middle/resolve.rs
+24
-13
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+76
-74
src/comp/middle/tstate/annotate.rs
src/comp/middle/tstate/annotate.rs
+3
-3
src/comp/middle/tstate/ck.rs
src/comp/middle/tstate/ck.rs
+3
-3
src/comp/middle/tstate/collect_locals.rs
src/comp/middle/tstate/collect_locals.rs
+5
-7
src/comp/middle/tstate/pre_post_conditions.rs
src/comp/middle/tstate/pre_post_conditions.rs
+40
-43
src/comp/middle/tstate/states.rs
src/comp/middle/tstate/states.rs
+15
-6
src/comp/middle/typeck.rs
src/comp/middle/typeck.rs
+39
-39
src/comp/syntax/ast.rs
src/comp/syntax/ast.rs
+22
-22
src/comp/syntax/ext/base.rs
src/comp/syntax/ext/base.rs
+2
-2
src/comp/syntax/ext/env.rs
src/comp/syntax/ext/env.rs
+3
-2
src/comp/syntax/ext/fmt.rs
src/comp/syntax/ext/fmt.rs
+15
-14
src/comp/syntax/ext/simplext.rs
src/comp/syntax/ext/simplext.rs
+11
-10
src/comp/syntax/fold.rs
src/comp/syntax/fold.rs
+21
-20
src/comp/syntax/parse/parser.rs
src/comp/syntax/parse/parser.rs
+62
-60
src/comp/syntax/print/pprust.rs
src/comp/syntax/print/pprust.rs
+19
-18
src/comp/syntax/visit.rs
src/comp/syntax/visit.rs
+7
-7
src/comp/syntax/walk.rs
src/comp/syntax/walk.rs
+9
-9
src/comp/util/common.rs
src/comp/util/common.rs
+10
-8
未找到文件。
src/comp/front/config.rs
浏览文件 @
0e2fff53
...
...
@@ -82,8 +82,8 @@ fn filter_stmt(&ast::crate_cfg cfg,
fn
fold_block
(
&
ast
::
crate_cfg
cfg
,
&
ast
::
block_
b
,
fold
::
ast_fold
fld
)
->
ast
::
block_
{
auto
filter
=
bind
filter_stmt
(
cfg
,
_
);
auto
filtered_stmts
=
vec
::
filter_map
(
filter
,
b
.stmts
);
ret
rec
(
stmts
=
vec
::
map
(
fld
.fold_stmt
,
filtered_stmts
),
auto
filtered_stmts
=
i
vec
::
filter_map
(
filter
,
b
.stmts
);
ret
rec
(
stmts
=
i
vec
::
map
(
fld
.fold_stmt
,
filtered_stmts
),
expr
=
option
::
map
(
fld
.fold_expr
,
b
.expr
),
id
=
b
.id
);
}
...
...
src/comp/front/test.rs
浏览文件 @
0e2fff53
...
...
@@ -71,14 +71,14 @@ fn mk_main(&test_ctxt cx) -> @ast::item {
auto
ret_ty
=
@
rec
(
node
=
ast
::
ty_nil
,
span
=
rec
(
lo
=
0u
,
hi
=
0u
));
let
ast
::
fn_decl
decl
=
rec
(
inputs
=
[],
let
ast
::
fn_decl
decl
=
rec
(
inputs
=
~
[],
output
=
ret_ty
,
purity
=
ast
::
impure_fn
,
cf
=
ast
::
return
,
constraints
=
~
[]);
auto
proto
=
ast
::
proto_fn
;
let
ast
::
block_
body_
=
rec
(
stmts
=
[],
let
ast
::
block_
body_
=
rec
(
stmts
=
~
[],
expr
=
option
::
none
,
id
=
cx
.next_node_id
());
auto
body
=
rec
(
node
=
body_
,
span
=
rec
(
lo
=
0u
,
hi
=
0u
));
...
...
@@ -87,7 +87,7 @@ fn mk_main(&test_ctxt cx) -> @ast::item {
proto
=
proto
,
body
=
body
);
auto
item_
=
ast
::
item_fn
(
fn_
,
[]);
auto
item_
=
ast
::
item_fn
(
fn_
,
~
[]);
let
ast
::
item
item
=
rec
(
ident
=
"main"
,
attrs
=
~
[],
id
=
cx
.next_node_id
(),
...
...
src/comp/metadata/encoder.rs
浏览文件 @
0e2fff53
// Metadata encoding
import
std
::
ivec
;
import
std
::
str
;
import
std
::
vec
;
import
std
::
uint
;
...
...
@@ -33,7 +34,7 @@ fn encode_def_id(&ebml::writer ebml_w, &def_id id) {
ebml
::
end_tag
(
ebml_w
);
}
fn
encode_tag_variant_paths
(
&
ebml
::
writer
ebml_w
,
&
v
ec
[
variant
]
variants
,
fn
encode_tag_variant_paths
(
&
ebml
::
writer
ebml_w
,
&
v
ariant
[
]
variants
,
&
vec
[
str
]
path
,
&
mutable
vec
[
tup
(
str
,
uint
)]
index
)
{
for
(
variant
variant
in
variants
)
{
...
...
@@ -164,9 +165,9 @@ fn encode_kind(&ebml::writer ebml_w, u8 c) {
fn
def_to_str
(
&
def_id
did
)
->
str
{
ret
#
fmt
(
"%d:%d"
,
did
._0
,
did
._1
);
}
fn
encode_type_param_count
(
&
ebml
::
writer
ebml_w
,
&
vec
[
ty_param
]
tps
)
{
fn
encode_type_param_count
(
&
ebml
::
writer
ebml_w
,
&
ty_param
[
]
tps
)
{
ebml
::
start_tag
(
ebml_w
,
tag_items_data_item_ty_param_count
);
ebml
::
write_vint
(
ebml_w
.writer
,
vec
::
len
[
ty_param
](
tps
));
ebml
::
write_vint
(
ebml_w
.writer
,
i
vec
::
len
[
ty_param
](
tps
));
ebml
::
end_tag
(
ebml_w
);
}
...
...
@@ -207,9 +208,9 @@ fn encode_tag_id(&ebml::writer ebml_w, &def_id id) {
}
fn
encode_tag_variant_info
(
&@
crate_ctxt
cx
,
&
ebml
::
writer
ebml_w
,
node_id
id
,
&
v
ec
[
variant
]
variants
,
node_id
id
,
&
v
ariant
[
]
variants
,
&
mutable
vec
[
tup
(
int
,
uint
)]
index
,
&
vec
[
ty_param
]
ty_params
)
{
&
ty_param
[
]
ty_params
)
{
for
(
variant
variant
in
variants
)
{
index
+=
[
tup
(
variant
.node.id
,
ebml_w
.writer
.tell
())];
ebml
::
start_tag
(
ebml_w
,
tag_items_data_item
);
...
...
src/comp/middle/alias.rs
浏览文件 @
0e2fff53
...
...
@@ -53,7 +53,7 @@ fn check_crate(@ty::ctxt tcx, &@ast::crate crate) {
tcx
.sess
.abort_if_errors
();
}
fn
visit_fn
(
@
ctx
cx
,
&
ast
::
_
fn
f
,
&
vec
[
ast
::
ty_param
]
tp
,
&
span
sp
,
fn
visit_fn
(
@
ctx
cx
,
&
ast
::
_
fn
f
,
&
ast
::
ty_param
[
]
tp
,
&
span
sp
,
&
fn_ident
name
,
ast
::
node_id
id
,
&
scope
sc
,
&
vt
[
scope
]
v
)
{
visit
::
visit_fn_decl
(
f
.decl
,
sc
,
v
);
for
(
ast
::
arg
arg_
in
f
.decl.inputs
)
{
...
...
@@ -132,7 +132,7 @@ fn visit_expr(@ctx cx, &@ast::expr ex, &scope sc, &vt[scope] v) {
if
(
!
handled
)
{
visit
::
visit_expr
(
ex
,
sc
,
v
);
}
}
fn
check_call
(
&
ctx
cx
,
&@
ast
::
expr
f
,
&
vec
[
@
ast
::
expr
]
args
,
&
scope
sc
)
->
fn
check_call
(
&
ctx
cx
,
&@
ast
::
expr
f
,
&
(
@
ast
::
expr
)[
]
args
,
&
scope
sc
)
->
rec
(
vec
[
node_id
]
root_vars
,
vec
[
ty
::
t
]
unsafe_ts
)
{
auto
fty
=
ty
::
expr_ty
(
*
cx
.tcx
,
f
);
auto
arg_ts
=
fty_args
(
cx
,
fty
);
...
...
@@ -261,7 +261,7 @@ fn check_tail_call(&ctx cx, &@ast::expr call) {
}
}
fn
check_alt
(
&
ctx
cx
,
&@
ast
::
expr
input
,
&
vec
[
ast
::
arm
]
arms
,
&
scope
sc
,
fn
check_alt
(
&
ctx
cx
,
&@
ast
::
expr
input
,
&
ast
::
arm
[
]
arms
,
&
scope
sc
,
&
vt
[
scope
]
v
)
{
visit
::
visit_expr
(
input
,
sc
,
v
);
auto
root
=
expr_root
(
cx
,
input
,
true
);
...
...
src/comp/middle/resolve.rs
浏览文件 @
0e2fff53
...
...
@@ -47,7 +47,7 @@
tag
scope
{
scope_crate
(
@
ast
::
crate
);
scope_item
(
@
ast
::
item
);
scope_fn
(
ast
::
fn_decl
,
vec
[
ast
::
ty_param
]);
scope_fn
(
ast
::
fn_decl
,
ast
::
ty_param
[
]);
scope_native_item
(
@
ast
::
native_item
);
scope_loop
(
@
ast
::
local
);
// there's only 1 decl per loop.
scope_block
(
ast
::
block
);
...
...
@@ -346,7 +346,7 @@ fn visit_native_item_with_scope(&@ast::native_item ni, &scopes sc,
visit
::
visit_native_item
(
ni
,
cons
(
scope_native_item
(
ni
),
@
sc
),
v
);
}
fn
visit_fn_with_scope
(
&@
env
e
,
&
ast
::
_
fn
f
,
&
vec
[
ast
::
ty_param
]
tp
,
&
span
sp
,
fn
visit_fn_with_scope
(
&@
env
e
,
&
ast
::
_
fn
f
,
&
ast
::
ty_param
[
]
tp
,
&
span
sp
,
&
fn_ident
name
,
node_id
id
,
&
scopes
sc
,
&
vt
[
scopes
]
v
)
{
// here's where we need to set up the mapping
...
...
@@ -376,7 +376,7 @@ fn visit_expr_with_scope(&@ast::expr x, &scopes sc, &vt[scopes] v) {
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
);
...
...
@@ -638,8 +638,7 @@ fn in_scope(&env e, &span sp, &ident name, &scope s, namespace ns) ->
}
case
(
scope_native_item
(
?
it
))
{
alt
(
it
.node
)
{
case
(
ast
::
native_item_fn
(
_
,
?
decl
,
?
ty_params
))
{
case
(
ast
::
native_item_fn
(
_
,
?
decl
,
?
ty_params
))
{
ret
lookup_in_fn
(
name
,
decl
,
ty_params
,
ns
);
}
}
...
...
@@ -690,7 +689,7 @@ fn in_scope(&env e, &span sp, &ident name, &scope s, namespace ns) ->
}
fn
lookup_in_ty_params
(
&
ident
name
,
&
vec
[
ast
::
ty_param
]
ty_params
)
->
fn
lookup_in_ty_params
(
&
ident
name
,
&
ast
::
ty_param
[
]
ty_params
)
->
option
::
t
[
def
]
{
auto
i
=
0u
;
for
(
ast
::
ty_param
tp
in
ty_params
)
{
...
...
@@ -720,7 +719,7 @@ fn lookup_in_pat(&ident name, &ast::pat pat) -> option::t[def] {
}
fn
lookup_in_fn
(
&
ident
name
,
&
ast
::
fn_decl
decl
,
&
vec
[
ast
::
ty_param
]
ty_params
,
&
ast
::
ty_param
[
]
ty_params
,
namespace
ns
)
->
option
::
t
[
def
]
{
alt
(
ns
)
{
case
(
ns_value
)
{
...
...
@@ -736,7 +735,7 @@ fn lookup_in_fn(&ident name, &ast::fn_decl decl,
}
}
fn
lookup_in_obj
(
&
ident
name
,
&
ast
::
_
obj
ob
,
&
vec
[
ast
::
ty_param
]
ty_params
,
fn
lookup_in_obj
(
&
ident
name
,
&
ast
::
_
obj
ob
,
&
ast
::
ty_param
[
]
ty_params
,
namespace
ns
)
->
option
::
t
[
def
]
{
alt
(
ns
)
{
case
(
ns_value
)
{
...
...
@@ -1229,18 +1228,22 @@ fn check_item(@env e, &@ast::item i, &() x, &vt[()] v) {
alt
(
i
.node
)
{
case
(
ast
::
item_fn
(
?
f
,
?
ty_params
))
{
check_fn
(
*
e
,
i
.span
,
f
);
ensure_unique
(
*
e
,
i
.span
,
ty_params
,
ident_id
,
"type parameter"
);
ensure_unique_ivec
(
*
e
,
i
.span
,
ty_params
,
ident_id
,
"type parameter"
);
}
case
(
ast
::
item_obj
(
?
ob
,
?
ty_params
,
_
))
{
fn
field_name
(
&
ast
::
obj_field
field
)
->
ident
{
ret
field
.ident
;
}
ensure_unique
(
*
e
,
i
.span
,
ob
.fields
,
field_name
,
"object field"
);
ensure_unique_ivec
(
*
e
,
i
.span
,
ob
.fields
,
field_name
,
"object field"
);
for
(
@
ast
::
method
m
in
ob
.methods
)
{
check_fn
(
*
e
,
m
.span
,
m
.node.meth
);
}
ensure_unique
(
*
e
,
i
.span
,
ty_params
,
ident_id
,
"type parameter"
);
ensure_unique_ivec
(
*
e
,
i
.span
,
ty_params
,
ident_id
,
"type parameter"
);
}
case
(
ast
::
item_tag
(
_
,
?
ty_params
))
{
ensure_unique
(
*
e
,
i
.span
,
ty_params
,
ident_id
,
"type parameter"
);
ensure_unique_ivec
(
*
e
,
i
.span
,
ty_params
,
ident_id
,
"type parameter"
);
}
case
(
_
)
{
}
}
...
...
@@ -1315,7 +1318,7 @@ fn check_block(@env e, &ast::block b, &() x, &vt[()] v) {
fn
check_fn
(
&
env
e
,
&
span
sp
,
&
ast
::
_
fn
f
)
{
fn
arg_name
(
&
ast
::
arg
a
)
->
ident
{
ret
a
.ident
;
}
ensure_unique
(
e
,
sp
,
f
.decl.inputs
,
arg_name
,
"argument"
);
ensure_unique
_ivec
(
e
,
sp
,
f
.decl.inputs
,
arg_name
,
"argument"
);
}
type
checker
=
@
rec
(
mutable
vec
[
ident
]
seen
,
str
kind
,
session
sess
);
...
...
@@ -1341,6 +1344,14 @@ fn ensure_unique[T](&env e, &span sp, &vec[T] elts, fn(&T) -> ident id,
auto
ch
=
checker
(
e
,
kind
);
for
(
T
elt
in
elts
)
{
add_name
(
ch
,
sp
,
id
(
elt
));
}
}
// FIXME: Remove me.
fn
ensure_unique_ivec
[
T
](
&
env
e
,
&
span
sp
,
&
T
[]
elts
,
fn
(
&
T
)
->
ident
id
,
&
str
kind
)
{
auto
ch
=
checker
(
e
,
kind
);
for
(
T
elt
in
elts
)
{
add_name
(
ch
,
sp
,
id
(
elt
));
}
}
// Local Variables:
// mode: rust
// fill-column: 78;
...
...
src/comp/middle/trans.rs
浏览文件 @
0e2fff53
此差异已折叠。
点击以展开。
src/comp/middle/tstate/annotate.rs
浏览文件 @
0e2fff53
...
...
@@ -52,7 +52,7 @@ fn collect_ids_local(&@local l, @mutable node_id[] rs) {
*
rs
+=
~
[
l
.node.id
];
}
fn
node_ids_in_fn
(
&
_
fn
f
,
&
vec
[
ty_param
]
tps
,
&
span
sp
,
&
fn_ident
i
,
fn
node_ids_in_fn
(
&
_
fn
f
,
&
ty_param
[
]
tps
,
&
span
sp
,
&
fn_ident
i
,
node_id
id
,
@
mutable
node_id
[]
rs
)
{
auto
collect_ids
=
walk
::
default_visitor
();
collect_ids
=
...
...
@@ -70,7 +70,7 @@ fn init_vecs(&crate_ctxt ccx, &node_id[] node_ids, uint len) {
}
}
fn
visit_fn
(
&
crate_ctxt
ccx
,
uint
num_constraints
,
&
_
fn
f
,
&
vec
[
ty_param
]
tps
,
fn
visit_fn
(
&
crate_ctxt
ccx
,
uint
num_constraints
,
&
_
fn
f
,
&
ty_param
[
]
tps
,
&
span
sp
,
&
fn_ident
i
,
node_id
id
)
{
let
@
mutable
node_id
[]
node_ids
=
@
mutable
~
[];
node_ids_in_fn
(
f
,
tps
,
sp
,
i
,
id
,
node_ids
);
...
...
@@ -78,7 +78,7 @@ fn visit_fn(&crate_ctxt ccx, uint num_constraints, &_fn f, &vec[ty_param] tps,
init_vecs
(
ccx
,
node_id_vec
,
num_constraints
);
}
fn
annotate_in_fn
(
&
crate_ctxt
ccx
,
&
_
fn
f
,
&
vec
[
ty_param
]
tps
,
fn
annotate_in_fn
(
&
crate_ctxt
ccx
,
&
_
fn
f
,
&
ty_param
[
]
tps
,
&
span
sp
,
&
fn_ident
i
,
node_id
id
)
{
auto
f_info
=
get_fn_info
(
ccx
,
id
);
visit_fn
(
ccx
,
num_constraints
(
f_info
),
f
,
tps
,
sp
,
i
,
id
);
...
...
src/comp/middle/tstate/ck.rs
浏览文件 @
0e2fff53
...
...
@@ -120,7 +120,7 @@ fn check_states_stmt(&fn_ctxt fcx, &@stmt s) {
}
fn
check_states_against_conditions
(
&
fn_ctxt
fcx
,
&
_
fn
f
,
&
vec
[
ast
::
ty_param
]
tps
,
&
ast
::
ty_param
[
]
tps
,
node_id
id
,
&
span
sp
,
&
fn_ident
i
)
{
/* Postorder traversal instead of pre is important
because we want the smallest possible erroneous statement
...
...
@@ -176,7 +176,7 @@ fn kg(@mutable bool keepgoing) -> bool {
check_unused_vars
(
fcx
);
}
fn
check_fn_states
(
&
fn_ctxt
fcx
,
&
_
fn
f
,
&
vec
[
ast
::
ty_param
]
tps
,
fn
check_fn_states
(
&
fn_ctxt
fcx
,
&
_
fn
f
,
&
ast
::
ty_param
[
]
tps
,
node_id
id
,
&
span
sp
,
&
fn_ident
i
)
{
/* Compute the pre- and post-states for this function */
...
...
@@ -189,7 +189,7 @@ fn check_fn_states(&fn_ctxt fcx, &_fn f, &vec[ast::ty_param] tps,
check_states_against_conditions
(
fcx
,
f
,
tps
,
id
,
sp
,
i
);
}
fn
fn_states
(
&
crate_ctxt
ccx
,
&
_
fn
f
,
&
vec
[
ast
::
ty_param
]
tps
,
fn
fn_states
(
&
crate_ctxt
ccx
,
&
_
fn
f
,
&
ast
::
ty_param
[
]
tps
,
&
span
sp
,
&
fn_ident
i
,
node_id
id
)
{
/* Look up the var-to-bit-num map for this function */
...
...
src/comp/middle/tstate/collect_locals.rs
浏览文件 @
0e2fff53
...
...
@@ -64,13 +64,12 @@ fn collect_pred(&@expr e, &ctxt cx, &visit::vt[ctxt] v) {
visit
::
visit_expr
(
e
,
cx
,
v
);
}
fn
do_nothing
(
&
_
fn
f
,
&
vec
[
ty_param
]
tp
,
&
span
sp
,
&
fn_ident
i
,
fn
do_nothing
(
&
_
fn
f
,
&
ty_param
[
]
tp
,
&
span
sp
,
&
fn_ident
i
,
node_id
iid
,
&
ctxt
cx
,
&
visit
::
vt
[
ctxt
]
v
)
{
}
fn
find_locals
(
&
ty
::
ctxt
tcx
,
&
_
fn
f
,
&
vec
[
ty_param
]
tps
,
&
span
sp
,
&
fn_ident
i
,
node_id
id
)
->
ctxt
{
fn
find_locals
(
&
ty
::
ctxt
tcx
,
&
_
fn
f
,
&
ty_param
[]
tps
,
&
span
sp
,
&
fn_ident
i
,
node_id
id
)
->
ctxt
{
let
ctxt
cx
=
rec
(
cs
=@
mutable
~
[],
tcx
=
tcx
);
auto
visitor
=
visit
::
default_visitor
[
ctxt
]();
...
...
@@ -118,9 +117,8 @@ fn add_constraint(&ty::ctxt tcx, aux::constr c, uint next, constr_map tbl) ->
/* builds a table mapping each local var defined in f
to a bit number in the precondition/postcondition vectors */
fn
mk_fn_info
(
&
crate_ctxt
ccx
,
&
_
fn
f
,
&
vec
[
ty_param
]
tp
,
&
span
f_sp
,
&
fn_ident
f_name
,
node_id
id
)
{
fn
mk_fn_info
(
&
crate_ctxt
ccx
,
&
_
fn
f
,
&
ty_param
[]
tp
,
&
span
f_sp
,
&
fn_ident
f_name
,
node_id
id
)
{
auto
res_map
=
@
new_int_hash
[
constraint
]();
let
uint
next
=
0u
;
...
...
src/comp/middle/tstate/pre_post_conditions.rs
浏览文件 @
0e2fff53
...
...
@@ -102,9 +102,8 @@ fn do_a_method(crate_ctxt ccx, &@method m) {
ccx
=
ccx
);
find_pre_post_fn
(
fcx
,
m
.node.meth
);
}
auto
f
=
bind
do_a_method
(
ccx
,
_
);
vec
::
map
[
@
method
,
()](
f
,
o
.methods
);
option
::
map
[
@
method
,
()](
f
,
o
.dtor
);
for
(
@
method
m
in
o
.methods
)
{
do_a_method
(
ccx
,
m
);
}
option
::
map
[
@
method
,
()](
bind
do_a_method
(
ccx
,
_
),
o
.dtor
);
}
fn
find_pre_post_item
(
&
crate_ctxt
ccx
,
&
item
i
)
{
...
...
@@ -151,26 +150,21 @@ fn find_pre_post_item(&crate_ctxt ccx, &item i) {
sets the precondition in a to be the result of combining
the preconditions for <args>, and the postcondition in a to
be the union of all postconditions for <args> */
fn
find_pre_post_exprs
(
&
fn_ctxt
fcx
,
&
vec
[
@
expr
]
args
,
node_id
id
)
{
if
(
vec
::
len
[
@
expr
](
args
)
>
0u
)
{
fn
find_pre_post_exprs
(
&
fn_ctxt
fcx
,
&
(
@
expr
)[
]
args
,
node_id
id
)
{
if
(
i
vec
::
len
[
@
expr
](
args
)
>
0u
)
{
log
"find_pre_post_exprs: oper ="
;
log_expr
(
*
args
.
(
0
));
}
fn
do_one
(
fn_ctxt
fcx
,
&@
expr
e
)
{
find_pre_post_expr
(
fcx
,
e
);
}
auto
f
=
bind
do_one
(
fcx
,
_
);
vec
::
map
[
@
expr
,
()](
f
,
args
);
for
(
@
expr
e
in
args
)
{
do_one
(
fcx
,
e
);
}
fn
get_pp
(
crate_ctxt
ccx
,
&@
expr
e
)
->
pre_and_post
{
ret
expr_pp
(
ccx
,
e
);
}
auto
g
=
bind
get_pp
(
fcx
.ccx
,
_
);
auto
pps
=
vec
::
map
[
@
expr
,
pre_and_post
](
g
,
args
);
// TODO: Remove this vec->ivec conversion.
auto
pps_ivec
=
~
[];
for
(
pre_and_post
pp
in
pps
)
{
pps_ivec
+=
~
[
pp
];
}
auto
pps
=
ivec
::
map
[
@
expr
,
pre_and_post
](
bind
get_pp
(
fcx
.ccx
,
_
),
args
);
set_pre_and_post
(
fcx
.ccx
,
id
,
seq_preconds
(
fcx
,
pps
_ivec
),
seq_postconds
(
fcx
,
ivec
::
map
(
get_post
,
pps
_ivec
)));
set_pre_and_post
(
fcx
.ccx
,
id
,
seq_preconds
(
fcx
,
pps
),
seq_postconds
(
fcx
,
ivec
::
map
(
get_post
,
pps
)));
}
fn
find_pre_post_loop
(
&
fn_ctxt
fcx
,
&@
local
l
,
&@
expr
index
,
&
block
body
,
...
...
@@ -264,10 +258,10 @@ fn gen_if_local(&fn_ctxt fcx, @expr lhs, @expr rhs, node_id larger_id,
rec
(
id
=
d_id
._1
,
c
=
ninit
(
path_to_ident
(
fcx
.ccx.tcx
,
pth
))));
}
case
(
_
)
{
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
larger_id
);
}
case
(
_
)
{
find_pre_post_exprs
(
fcx
,
~
[
lhs
,
rhs
],
larger_id
);
}
}
}
case
(
_
)
{
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
larger_id
);
}
case
(
_
)
{
find_pre_post_exprs
(
fcx
,
~
[
lhs
,
rhs
],
larger_id
);
}
}
}
...
...
@@ -280,12 +274,8 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
alt
(
e
.node
)
{
case
(
expr_call
(
?
operator
,
?
operands
))
{
auto
args
=
vec
::
clone
(
operands
);
vec
::
push
(
args
,
operator
);
// TODO: Remove this vec->ivec conversion.
auto
operands_ivec
=
~
[];
for
(
@
expr
e
in
operands
)
{
operands_ivec
+=
~
[
e
];
}
auto
args
=
/* copy */
operands
;
args
+=
~
[
operator
];
find_pre_post_exprs
(
fcx
,
args
,
e
.id
);
/* see if the call has any constraints on its type */
...
...
@@ -295,8 +285,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
bit_num
(
fcx
,
rec
(
id
=
c
.node.id._1
,
c
=
substitute_constr_args
(
fcx
.ccx.tcx
,
operands_ivec
,
c
)));
args
,
c
)));
require
(
i
,
expr_pp
(
fcx
.ccx
,
e
));
}
...
...
@@ -307,8 +296,8 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
}
}
case
(
expr_spawn
(
_
,
_
,
?
operator
,
?
operands
))
{
auto
args
=
vec
::
clone
(
operands
)
;
vec
::
push
(
args
,
operator
)
;
auto
args
=
/* copy */
operands
;
args
+=
~
[
operator
]
;
find_pre_post_exprs
(
fcx
,
args
,
e
.id
);
}
case
(
expr_vec
(
?
args
,
_
,
_
))
{
...
...
@@ -359,7 +348,10 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
}
case
(
expr_rec
(
?
fields
,
?
maybe_base
))
{
auto
es
=
field_exprs
(
fields
);
vec
::
plus_option
(
es
,
maybe_base
);
alt
(
maybe_base
)
{
case
(
none
)
{
/* no-op */
}
case
(
some
(
?
b
))
{
es
+=
~
[
b
];
}
}
find_pre_post_exprs
(
fcx
,
es
,
e
.id
);
}
case
(
expr_move
(
?
lhs
,
?
rhs
))
{
...
...
@@ -367,7 +359,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
case
(
expr_path
(
?
p
))
{
gen_if_local
(
fcx
,
lhs
,
rhs
,
e
.id
,
lhs
.id
,
p
);
}
case
(
_
)
{
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
e
.id
);
}
case
(
_
)
{
find_pre_post_exprs
(
fcx
,
~
[
lhs
,
rhs
],
e
.id
);
}
}
if
(
is_path
(
rhs
))
{
forget_in_postcond
(
fcx
,
e
.id
,
rhs
.id
);
...
...
@@ -375,7 +367,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
}
case
(
expr_swap
(
?
lhs
,
?
rhs
))
{
// Both sides must already be initialized
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
e
.id
);
find_pre_post_exprs
(
fcx
,
~
[
lhs
,
rhs
],
e
.id
);
forget_in_postcond_still_init
(
fcx
,
e
.id
,
lhs
.id
);
forget_in_postcond_still_init
(
fcx
,
e
.id
,
rhs
.id
);
// Could be more precise and swap the roles of lhs and rhs
...
...
@@ -387,7 +379,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
gen_if_local
(
fcx
,
lhs
,
rhs
,
e
.id
,
lhs
.id
,
p
);
forget_in_postcond_still_init
(
fcx
,
e
.id
,
lhs
.id
);
}
case
(
_
)
{
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
e
.id
);
}
case
(
_
)
{
find_pre_post_exprs
(
fcx
,
~
[
lhs
,
rhs
],
e
.id
);
}
}
}
case
(
expr_recv
(
?
lhs
,
?
rhs
))
{
...
...
@@ -400,7 +392,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
// doesn't check that rhs is an lval, but
// that's probably ok
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
e
.id
);
find_pre_post_exprs
(
fcx
,
~
[
lhs
,
rhs
],
e
.id
);
}
}
}
...
...
@@ -408,7 +400,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
/* Different from expr_assign in that the lhs *must*
already be initialized */
find_pre_post_exprs
(
fcx
,
[
lhs
,
rhs
],
e
.id
);
find_pre_post_exprs
(
fcx
,
~
[
lhs
,
rhs
],
e
.id
);
forget_in_postcond_still_init
(
fcx
,
e
.id
,
lhs
.id
);
}
case
(
expr_lit
(
_
))
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
...
...
@@ -449,11 +441,11 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
expr_postcond
(
fcx
.ccx
,
l
));
}
else
{
find_pre_post_exprs
(
fcx
,
[
l
,
r
],
e
.id
);
find_pre_post_exprs
(
fcx
,
~
[
l
,
r
],
e
.id
);
}
}
case
(
expr_send
(
?
l
,
?
r
))
{
find_pre_post_exprs
(
fcx
,
[
l
,
r
],
e
.id
);
find_pre_post_exprs
(
fcx
,
~
[
l
,
r
],
e
.id
);
}
case
(
expr_unary
(
_
,
?
operand
))
{
find_pre_post_expr
(
fcx
,
operand
);
...
...
@@ -497,7 +489,7 @@ fn find_pre_post_expr(&fn_ctxt fcx, @expr e) {
find_pre_post_loop
(
fcx
,
d
,
index
,
body
,
e
.id
);
}
case
(
expr_index
(
?
val
,
?
sub
))
{
find_pre_post_exprs
(
fcx
,
[
val
,
sub
],
e
.id
);
find_pre_post_exprs
(
fcx
,
~
[
val
,
sub
],
e
.id
);
}
case
(
expr_alt
(
?
ex
,
?
alts
))
{
find_pre_post_expr
(
fcx
,
ex
);
...
...
@@ -505,8 +497,8 @@ fn do_an_alt(&fn_ctxt fcx, &arm an_alt) -> pre_and_post {
find_pre_post_block
(
fcx
,
an_alt
.block
);
ret
block_pp
(
fcx
.ccx
,
an_alt
.block
);
}
auto
f
=
bind
do_an_alt
(
fcx
,
_
)
;
auto
alt_pps
=
vec
::
map
[
arm
,
pre_and_post
](
f
,
alts
);
auto
alt_pps
=
[]
;
for
(
arm
a
in
alts
)
{
alt_pps
+=
[
do_an_alt
(
fcx
,
a
)];
}
fn
combine_pp
(
pre_and_post
antec
,
fn_ctxt
fcx
,
&
pre_and_post
pp
,
&
pre_and_post
next
)
->
pre_and_post
{
union
(
pp
.precondition
,
seq_preconds
(
fcx
,
~
[
antec
,
next
]));
...
...
@@ -559,8 +551,14 @@ fn combine_pp(pre_and_post antec, fn_ctxt fcx, &pre_and_post pp,
}
case
(
expr_bind
(
?
operator
,
?
maybe_args
))
{
auto
args
=
vec
::
cat_options
[
@
expr
](
maybe_args
);
vec
::
push
[
@
expr
](
args
,
operator
);
/* ??? order of eval? */
auto
args
=
~
[];
for
(
option
::
t
[
@
expr
]
expr_opt
in
maybe_args
)
{
alt
(
expr_opt
)
{
case
(
none
)
{
/* no-op */
}
case
(
some
(
?
expr
))
{
args
+=
~
[
expr
];
}
}
}
args
+=
~
[
operator
];
/* ??? order of eval? */
find_pre_post_exprs
(
fcx
,
args
,
e
.id
);
}
...
...
@@ -659,8 +657,7 @@ fn do_one_(fn_ctxt fcx, &@stmt s) {
log
"is:"
;
log_pp
(
stmt_pp
(
fcx
.ccx
,
*
s
));
}
auto
do_one
=
bind
do_one_
(
fcx
,
_
);
vec
::
map
[
@
stmt
,
()](
do_one
,
b
.node.stmts
);
for
(
@
stmt
s
in
b
.node.stmts
)
{
do_one_
(
fcx
,
s
);
}
fn
do_inner_
(
fn_ctxt
fcx
,
&@
expr
e
)
{
find_pre_post_expr
(
fcx
,
e
);
}
auto
do_inner
=
bind
do_inner_
(
fcx
,
_
);
option
::
map
[
@
expr
,
()](
do_inner
,
b
.node.expr
);
...
...
@@ -705,7 +702,7 @@ fn find_pre_post_fn(&fn_ctxt fcx, &_fn f) {
}
}
fn
fn_pre_post
(
crate_ctxt
ccx
,
&
_
fn
f
,
&
vec
[
ty_param
]
tps
,
fn
fn_pre_post
(
crate_ctxt
ccx
,
&
_
fn
f
,
&
ty_param
[
]
tps
,
&
span
sp
,
&
fn_ident
i
,
node_id
id
)
{
assert
(
ccx
.fm
.contains_key
(
id
));
auto
fcx
=
rec
(
enclosing
=
ccx
.fm
.get
(
id
),
id
=
id
,
...
...
src/comp/middle/tstate/states.rs
浏览文件 @
0e2fff53
import
std
::
ivec
;
import
std
::
vec
;
import
std
::
vec
::
plus_option
;
import
std
::
vec
::
cat_options
;
...
...
@@ -100,7 +101,7 @@
oper_pure
;
}
fn
seq_states
(
&
fn_ctxt
fcx
,
prestate
pres
,
vec
[
@
expr
]
exprs
)
->
fn
seq_states
(
&
fn_ctxt
fcx
,
prestate
pres
,
&
(
@
expr
)[
]
exprs
)
->
tup
(
bool
,
poststate
)
{
auto
changed
=
false
;
auto
post
=
pres
;
...
...
@@ -162,7 +163,7 @@ fn find_pre_post_state_two(&fn_ctxt fcx, &prestate pres, &@expr a, &@expr b,
}
fn
find_pre_post_state_call
(
&
fn_ctxt
fcx
,
&
prestate
pres
,
&@
expr
a
,
node_id
id
,
&
vec
[
@
expr
]
bs
,
node_id
id
,
&
(
@
expr
)[
]
bs
,
controlflow
cf
)
->
bool
{
auto
changed
=
find_pre_post_state_expr
(
fcx
,
pres
,
a
);
ret
find_pre_post_state_exprs
(
fcx
,
...
...
@@ -170,7 +171,7 @@ fn find_pre_post_state_call(&fn_ctxt fcx, &prestate pres, &@expr a,
}
fn
find_pre_post_state_exprs
(
&
fn_ctxt
fcx
,
&
prestate
pres
,
node_id
id
,
&
vec
[
@
expr
]
es
,
controlflow
cf
)
->
bool
{
&
(
@
expr
)[
]
es
,
controlflow
cf
)
->
bool
{
auto
rs
=
seq_states
(
fcx
,
pres
,
es
);
auto
changed
=
rs
._0
|
set_prestate_ann
(
fcx
.ccx
,
id
,
pres
);
/* if this is a failing call, it sets everything as initialized */
...
...
@@ -313,8 +314,16 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
return
);
}
case
(
expr_bind
(
?
operator
,
?
maybe_args
))
{
ret
find_pre_post_state_call
(
fcx
,
pres
,
operator
,
e
.id
,
cat_options
(
maybe_args
),
return
);
auto
args
=
~
[];
for
(
option
::
t
[
@
expr
]
a_opt
in
maybe_args
)
{
alt
(
a_opt
)
{
case
(
none
)
{
/* no-op */
}
case
(
some
(
?
a
))
{
args
+=
~
[
a
];
}
}
}
ret
find_pre_post_state_call
(
fcx
,
pres
,
operator
,
e
.id
,
args
,
return
);
}
case
(
expr_path
(
_
))
{
ret
pure_exp
(
fcx
.ccx
,
e
.id
,
pres
);
}
case
(
expr_log
(
_
,
?
ex
))
{
...
...
@@ -514,7 +523,7 @@ fn find_pre_post_state_expr(&fn_ctxt fcx, &prestate pres, @expr e) -> bool {
find_pre_post_state_expr
(
fcx
,
pres
,
val
);
auto
e_post
=
expr_poststate
(
fcx
.ccx
,
val
);
auto
a_post
;
if
(
vec
::
len
(
alts
)
>
0u
)
{
if
(
i
vec
::
len
(
alts
)
>
0u
)
{
a_post
=
false_postcond
(
num_constrs
);
for
(
arm
an_alt
in
alts
)
{
changed
|
=
find_pre_post_state_block
...
...
src/comp/middle/typeck.rs
浏览文件 @
0e2fff53
...
...
@@ -52,7 +52,7 @@
type
ty_table
=
hashmap
[
ast
::
def_id
,
ty
::
t
];
type
obj_info
=
rec
(
vec
[
ast
::
obj_field
]
obj_fields
,
ast
::
node_id
this_obj
);
type
obj_info
=
rec
(
ast
::
obj_field
[
]
obj_fields
,
ast
::
node_id
this_obj
);
type
crate_ctxt
=
rec
(
mutable
vec
[
obj_info
]
obj_infos
,
...
...
@@ -481,7 +481,7 @@ fn mk_ty_params(&@ctxt cx, uint n) -> ty::t[] {
}
fn
ty_of_fn_decl
(
&@
ctxt
cx
,
&
fn
(
&@
ast
::
ty
)
->
ty
::
t
convert
,
&
fn
(
&
ast
::
arg
)
->
arg
ty_of_arg
,
&
ast
::
fn_decl
decl
,
ast
::
proto
proto
,
&
vec
[
ast
::
ty_param
]
ty_params
,
ast
::
proto
proto
,
&
ast
::
ty_param
[
]
ty_params
,
&
option
::
t
[
ast
::
def_id
]
def_id
)
->
ty
::
ty_param_count_and_ty
{
auto
input_tys
=
~
[];
...
...
@@ -495,7 +495,7 @@ fn ty_of_fn_decl(&@ctxt cx, &fn(&@ast::ty) -> ty::t convert,
auto
t_fn
=
ty
::
mk_fn
(
cx
.tcx
,
proto
,
input_tys
,
output_ty
,
decl
.cf
,
out_constrs
);
auto
ty_param_count
=
vec
::
len
[
ast
::
ty_param
](
ty_params
);
auto
ty_param_count
=
i
vec
::
len
[
ast
::
ty_param
](
ty_params
);
auto
tpt
=
tup
(
ty_param_count
,
t_fn
);
alt
(
def_id
)
{
case
(
some
(
?
did
))
{
cx
.tcx.tcache
.insert
(
did
,
tpt
);
}
...
...
@@ -506,7 +506,7 @@ fn ty_of_fn_decl(&@ctxt cx, &fn(&@ast::ty) -> ty::t convert,
fn
ty_of_native_fn_decl
(
&@
ctxt
cx
,
&
fn
(
&@
ast
::
ty
)
->
ty
::
t
convert
,
&
fn
(
&
ast
::
arg
)
->
arg
ty_of_arg
,
&
ast
::
fn_decl
decl
,
ast
::
native_abi
abi
,
&
vec
[
ast
::
ty_param
]
ty_params
,
&
ast
::
ty_param
[
]
ty_params
,
&
ast
::
def_id
def_id
)
->
ty
::
ty_param_count_and_ty
{
auto
input_tys
=
~
[];
...
...
@@ -514,7 +514,7 @@ fn ty_of_native_fn_decl(&@ctxt cx, &fn(&@ast::ty) -> ty::t convert,
auto
output_ty
=
convert
(
decl
.output
);
auto
t_fn
=
ty
::
mk_native_fn
(
cx
.tcx
,
abi
,
input_tys
,
output_ty
);
auto
ty_param_count
=
vec
::
len
[
ast
::
ty_param
](
ty_params
);
auto
ty_param_count
=
i
vec
::
len
[
ast
::
ty_param
](
ty_params
);
auto
tpt
=
tup
(
ty_param_count
,
t_fn
);
cx
.tcx.tcache
.insert
(
def_id
,
tpt
);
ret
tpt
;
...
...
@@ -577,14 +577,14 @@ fn ty_of_method(@ctxt cx, &@ast::method m) -> ty::method {
constrs
=
out_constrs
);
}
fn
ty_of_obj
(
@
ctxt
cx
,
&
ast
::
ident
id
,
&
ast
::
_
obj
obj_info
,
&
vec
[
ast
::
ty_param
]
ty_params
)
->
ty
::
ty_param_count_and_ty
{
&
ast
::
ty_param
[
]
ty_params
)
->
ty
::
ty_param_count_and_ty
{
auto
methods
=
get_obj_method_types
(
cx
,
obj_info
);
auto
t_obj
=
ty
::
mk_obj
(
cx
.tcx
,
ty
::
sort_methods
(
methods
));
t_obj
=
ty
::
rename
(
cx
.tcx
,
t_obj
,
id
);
ret
tup
(
vec
::
len
(
ty_params
),
t_obj
);
ret
tup
(
i
vec
::
len
(
ty_params
),
t_obj
);
}
fn
ty_of_obj_ctor
(
@
ctxt
cx
,
&
ast
::
ident
id
,
&
ast
::
_
obj
obj_info
,
ast
::
node_id
ctor_id
,
&
vec
[
ast
::
ty_param
]
ty_params
)
->
ast
::
node_id
ctor_id
,
&
ast
::
ty_param
[
]
ty_params
)
->
ty
::
ty_param_count_and_ty
{
auto
t_obj
=
ty_of_obj
(
cx
,
id
,
obj_info
,
ty_params
);
...
...
@@ -630,23 +630,23 @@ fn ty_of_item(&@ctxt cx, &@ast::item it) -> ty::ty_param_count_and_ty {
// call to resolve any named types.
auto
typ
=
convert
(
t
);
auto
ty_param_count
=
vec
::
len
[
ast
::
ty_param
](
tps
);
auto
ty_param_count
=
i
vec
::
len
[
ast
::
ty_param
](
tps
);
auto
tpt
=
tup
(
ty_param_count
,
typ
);
cx
.tcx.tcache
.insert
(
local_def
(
it
.id
),
tpt
);
ret
tpt
;
}
case
(
ast
::
item_res
(
?
f
,
_
,
?
tps
,
_
))
{
auto
t_arg
=
ty_of_arg
(
cx
,
f
.decl.inputs
.
(
0
));
auto
t_res
=
tup
(
vec
::
len
(
tps
),
ty
::
mk_res
auto
t_res
=
tup
(
i
vec
::
len
(
tps
),
ty
::
mk_res
(
cx
.tcx
,
local_def
(
it
.id
),
t_arg
.ty
,
mk_ty_params
(
cx
,
vec
::
len
(
tps
))));
mk_ty_params
(
cx
,
i
vec
::
len
(
tps
))));
cx
.tcx.tcache
.insert
(
local_def
(
it
.id
),
t_res
);
ret
t_res
;
}
case
(
ast
::
item_tag
(
_
,
?
tps
))
{
// Create a new generic polytype.
auto
ty_param_count
=
vec
::
len
[
ast
::
ty_param
](
tps
);
auto
ty_param_count
=
i
vec
::
len
[
ast
::
ty_param
](
tps
);
let
ty
::
t
[]
subtys
=
mk_ty_params
(
cx
,
ty_param_count
);
auto
t
=
ty
::
mk_tag
(
cx
.tcx
,
local_def
(
it
.id
),
subtys
);
...
...
@@ -681,11 +681,11 @@ fn ty_of_native_item(&@ctxt cx, &@ast::native_item it,
}
}
fn
get_tag_variant_types
(
&@
ctxt
cx
,
&
ast
::
def_id
tag_id
,
&
vec
[
ast
::
variant
]
variants
,
&
vec
[
ast
::
ty_param
]
ty_params
)
{
&
ast
::
variant
[
]
variants
,
&
ast
::
ty_param
[
]
ty_params
)
{
// Create a set of parameter types shared among all the variants.
auto
ty_param_count
=
vec
::
len
[
ast
::
ty_param
](
ty_params
);
auto
ty_param_count
=
i
vec
::
len
[
ast
::
ty_param
](
ty_params
);
let
ty
::
t
[]
ty_param_tys
=
mk_ty_params
(
cx
,
ty_param_count
);
for
(
ast
::
variant
variant
in
variants
)
{
// Nullary tag constructors get turned into constants; n-ary tag
...
...
@@ -757,7 +757,7 @@ fn convert(@ctxt cx, @mutable option::t[ast::native_abi] abi,
auto
method_types
=
get_obj_method_types
(
cx
,
object
);
auto
i
=
0u
;
while
(
i
<
vec
::
len
[
@
ast
::
method
](
object
.methods
))
{
while
(
i
<
i
vec
::
len
[
@
ast
::
method
](
object
.methods
))
{
write
::
ty_only
(
cx
.tcx
,
object
.methods
.
(
i
)
.node.id
,
ty
::
method_ty_to_fn_ty
(
cx
.tcx
,
method_types
.
(
i
)));
...
...
@@ -789,7 +789,7 @@ fn convert(@ctxt cx, @mutable option::t[ast::native_abi] abi,
case
(
ast
::
item_res
(
?
f
,
?
dtor_id
,
?
tps
,
?
ctor_id
))
{
auto
t_arg
=
ty_of_arg
(
cx
,
f
.decl.inputs
.
(
0
));
auto
t_res
=
ty
::
mk_res
(
cx
.tcx
,
local_def
(
it
.id
),
t_arg
.ty
,
mk_ty_params
(
cx
,
vec
::
len
(
tps
)));
mk_ty_params
(
cx
,
i
vec
::
len
(
tps
)));
auto
t_ctor
=
ty
::
mk_fn
(
cx
.tcx
,
ast
::
proto_fn
,
~
[
t_arg
],
t_res
,
ast
::
return
,
~
[]);
auto
t_dtor
=
ty
::
mk_fn
(
cx
.tcx
,
ast
::
proto_fn
,
~
[
t_arg
],
...
...
@@ -797,7 +797,7 @@ fn convert(@ctxt cx, @mutable option::t[ast::native_abi] abi,
write
::
ty_only
(
cx
.tcx
,
it
.id
,
t_res
);
write
::
ty_only
(
cx
.tcx
,
ctor_id
,
t_ctor
);
cx
.tcx.tcache
.insert
(
local_def
(
ctor_id
),
tup
(
vec
::
len
(
tps
),
t_ctor
));
tup
(
i
vec
::
len
(
tps
),
t_ctor
));
write
::
ty_only
(
cx
.tcx
,
dtor_id
,
t_dtor
);
}
case
(
_
)
{
...
...
@@ -995,8 +995,8 @@ fn are_compatible(&@fn_ctxt fcx, &ty::t expected, &ty::t actual) -> bool {
// Returns the types of the arguments to a tag variant.
fn
variant_arg_types
(
&@
crate_ctxt
ccx
,
&
span
sp
,
&
ast
::
def_id
vid
,
&
ty
::
t
[]
tag_ty_params
)
->
vec
[
ty
::
t
]
{
let
vec
[
ty
::
t
]
result
=
[];
&
ty
::
t
[]
tag_ty_params
)
->
ty
::
t
[
]
{
let
ty
::
t
[]
result
=
~
[];
auto
tpt
=
ty
::
lookup_item_type
(
ccx
.tcx
,
vid
);
alt
(
ty
::
struct
(
ccx
.tcx
,
tpt
._1
))
{
case
(
ty
::
ty_fn
(
_
,
?
ins
,
_
,
_
,
_
))
{
...
...
@@ -1006,7 +1006,7 @@ fn variant_arg_types(&@crate_ctxt ccx, &span sp, &ast::def_id vid,
auto
arg_ty
=
ty
::
substitute_type_params
(
ccx
.tcx
,
tag_ty_params
,
arg
.ty
);
result
+=
[
arg_ty
];
result
+=
~
[
arg_ty
];
}
}
case
(
_
)
{
...
...
@@ -1121,12 +1121,12 @@ fn visit_item_post(@wb_ctxt wbcx, &@ast::item item) {
wbcx
.ignore
=
false
;
}
fn
visit_fn_pre
(
@
wb_ctxt
wbcx
,
&
ast
::
_
fn
f
,
&
vec
[
ast
::
ty_param
]
tps
,
&
span
sp
,
&
ast
::
ty_param
[
]
tps
,
&
span
sp
,
&
ast
::
fn_ident
i
,
ast
::
node_id
d
)
{
wbcx
.ignore
=
true
;
}
fn
visit_fn_post
(
@
wb_ctxt
wbcx
,
&
ast
::
_
fn
f
,
&
vec
[
ast
::
ty_param
]
tps
,
&
span
sp
,
&
ast
::
ty_param
[
]
tps
,
&
span
sp
,
&
ast
::
fn_ident
i
,
ast
::
node_id
d
)
{
wbcx
.ignore
=
false
;
}
...
...
@@ -1335,11 +1335,11 @@ fn check_pat(&@fn_ctxt fcx, &@ast::pat pat, ty::t expected) {
auto
arg_types
=
variant_arg_types
(
fcx
.ccx
,
pat
.span
,
v_def_ids
._1
,
expected_tps
);
auto
subpats_len
=
vec
::
len
[
@
ast
::
pat
](
subpats
);
if
(
vec
::
len
[
ty
::
t
](
arg_types
)
>
0u
)
{
auto
subpats_len
=
std
::
i
vec
::
len
[
@
ast
::
pat
](
subpats
);
if
(
std
::
i
vec
::
len
[
ty
::
t
](
arg_types
)
>
0u
)
{
// N-ary variant.
auto
arg_len
=
vec
::
len
[
ty
::
t
](
arg_types
);
auto
arg_len
=
i
vec
::
len
[
ty
::
t
](
arg_types
);
if
(
arg_len
!=
subpats_len
)
{
// TODO: note definition of tag variant
// TODO (issue #448): Wrap a #fmt string over multiple
...
...
@@ -1430,7 +1430,7 @@ fn check_expr(&@fn_ctxt fcx, &@ast::expr expr) {
// expressions.
fn
check_call_or_bind
(
&@
fn_ctxt
fcx
,
&
span
sp
,
&@
ast
::
expr
f
,
&
vec
[
option
::
t
[
@
ast
::
expr
]
]
args
,
bool
is_call
)
{
&
(
option
::
t
[
@
ast
::
expr
])[
]
args
,
bool
is_call
)
{
// Check the function.
check_expr
(
fcx
,
f
);
...
...
@@ -1458,7 +1458,7 @@ fn check_call_or_bind(&@fn_ctxt fcx, &span sp, &@ast::expr f,
// Check that the correct number of arguments were supplied.
auto
expected_arg_count
=
ivec
::
len
[
ty
::
arg
](
arg_tys
);
auto
supplied_arg_count
=
vec
::
len
[
option
::
t
[
@
ast
::
expr
]](
args
);
auto
supplied_arg_count
=
i
vec
::
len
[
option
::
t
[
@
ast
::
expr
]](
args
);
if
(
expected_arg_count
!=
supplied_arg_count
)
{
fcx
.ccx.tcx.sess
.span_fatal
(
sp
,
#
fmt
(
"this function takes %u
\
...
...
@@ -1501,10 +1501,10 @@ fn check_assignment(&@fn_ctxt fcx, &span sp, &@ast::expr lhs,
// A generic function for checking call expressions
fn
check_call
(
&@
fn_ctxt
fcx
,
&
span
sp
,
&@
ast
::
expr
f
,
&
vec
[
@
ast
::
expr
]
args
)
{
let
vec
[
option
::
t
[
@
ast
::
expr
]]
args_opt_0
=
[];
&
(
@
ast
::
expr
)[
]
args
)
{
let
(
option
::
t
[
@
ast
::
expr
])[]
args_opt_0
=
~
[];
for
(
@
ast
::
expr
arg
in
args
)
{
args_opt_0
+=
[
some
[
@
ast
::
expr
](
arg
)];
args_opt_0
+=
~
[
some
[
@
ast
::
expr
](
arg
)];
}
// Call the generic checker.
...
...
@@ -1909,7 +1909,7 @@ fn check_binop_type_compat(&@fn_ctxt fcx, span span,
auto
ty_of_arg
=
bind
collect
::
ty_of_arg
(
cx
,
_
);
auto
fty
=
collect
::
ty_of_fn_decl
(
cx
,
convert
,
ty_of_arg
,
f
.decl
,
f
.proto
,
[],
none
)
._1
;
f
.proto
,
~
[],
none
)
._1
;
write
::
ty_only_fixup
(
fcx
,
id
,
fty
);
check_fn
(
fcx
.ccx
,
f
.decl
,
f
.proto
,
f
.body
,
id
);
}
...
...
@@ -1949,7 +1949,7 @@ fn check_binop_type_compat(&@fn_ctxt fcx, span span,
// to the resulting function type.
auto
i
=
0u
;
while
(
i
<
vec
::
len
[
option
::
t
[
@
ast
::
expr
]](
args
))
{
while
(
i
<
i
vec
::
len
[
option
::
t
[
@
ast
::
expr
]](
args
))
{
alt
(
args
.
(
i
))
{
case
(
some
(
_
))
{
/* no-op */
}
case
(
none
)
{
arg_tys_1
+=
~
[
arg_tys
.
(
i
)];
}
...
...
@@ -2051,7 +2051,7 @@ fn check_binop_type_compat(&@fn_ctxt fcx, span span,
}
case
(
ast
::
expr_vec
(
?
args
,
?
mut
,
?
kind
))
{
let
ty
::
t
t
;
if
(
vec
::
len
[
@
ast
::
expr
](
args
)
==
0u
)
{
if
(
i
vec
::
len
[
@
ast
::
expr
](
args
)
==
0u
)
{
t
=
next_ty_var
(
fcx
);
}
else
{
check_expr
(
fcx
,
args
.
(
0
));
...
...
@@ -2075,7 +2075,7 @@ fn check_binop_type_compat(&@fn_ctxt fcx, span span,
}
case
(
ast
::
expr_tup
(
?
elts
))
{
let
ty
::
mt
[]
elts_mt
=
~
[];
ivec
::
reserve
(
elts_mt
,
vec
::
len
(
elts
));
ivec
::
reserve
(
elts_mt
,
i
vec
::
len
(
elts
));
for
(
ast
::
elt
e
in
elts
)
{
check_expr
(
fcx
,
e
.expr
);
auto
ety
=
expr_ty
(
fcx
.ccx.tcx
,
e
.expr
);
...
...
@@ -2250,7 +2250,7 @@ fn check_binop_type_compat(&@fn_ctxt fcx, span span,
// We're entering an object, so gather up the info we need.
let
vec
[
ast
::
anon_obj_field
]
fields
=
[];
let
ast
::
anon_obj_field
[]
fields
=
~
[];
alt
(
anon_obj
.fields
)
{
case
(
none
)
{
}
case
(
some
(
?
v
))
{
fields
=
v
;
}
...
...
@@ -2265,8 +2265,8 @@ fn anon_obj_field_to_obj_field(&ast::anon_obj_field f)
vec
::
push
[
obj_info
](
fcx
.ccx.obj_infos
,
rec
(
obj_fields
=
vec
::
map
(
anon_obj_field_to_obj_field
,
fields
),
i
vec
::
map
(
anon_obj_field_to_obj_field
,
fields
),
this_obj
=
id
));
// FIXME: These next three functions are largely ripped off from
...
...
@@ -2343,7 +2343,7 @@ fn get_anon_obj_method_types(@fn_ctxt fcx,
// collect::convert for regular objects.)
auto
i
=
0u
;
while
(
i
<
vec
::
len
[
@
ast
::
method
](
anon_obj
.methods
))
{
while
(
i
<
i
vec
::
len
[
@
ast
::
method
](
anon_obj
.methods
))
{
write
::
ty_only
(
fcx
.ccx.tcx
,
anon_obj
.methods
.
(
i
)
.node.id
,
ty
::
method_ty_to_fn_ty
(
fcx
.ccx.tcx
,
method_types
.
(
i
)));
...
...
src/comp/syntax/ast.rs
浏览文件 @
0e2fff53
...
...
@@ -111,7 +111,7 @@ fn def_id_of_def(def d) -> def_id {
type
block
=
spanned
[
block_
];
type
block_
=
rec
(
vec
[
@
stmt
]
stmts
,
option
::
t
[
@
expr
]
expr
,
node_id
id
);
type
block_
=
rec
(
(
@
stmt
)[
]
stmts
,
option
::
t
[
@
expr
]
expr
,
node_id
id
);
type
pat
=
rec
(
node_id
id
,
pat_
node
,
...
...
@@ -121,7 +121,7 @@ fn def_id_of_def(def d) -> def_id {
pat_wild
;
pat_bind
(
ident
);
pat_lit
(
@
lit
);
pat_tag
(
path
,
vec
[
@
pat
]);
pat_tag
(
path
,
(
@
pat
)[
]);
}
tag
mutability
{
mut
;
imm
;
maybe_mut
;
}
...
...
@@ -246,13 +246,13 @@ fn unop_to_str(unop op) -> str {
span
span
);
tag
expr_
{
expr_vec
(
vec
[
@
expr
],
mutability
,
seq_kind
);
expr_tup
(
vec
[
elt
]);
expr_rec
(
vec
[
field
],
option
::
t
[
@
expr
]);
expr_call
(
@
expr
,
vec
[
@
expr
]);
expr_vec
(
(
@
expr
)[
],
mutability
,
seq_kind
);
expr_tup
(
elt
[
]);
expr_rec
(
field
[
],
option
::
t
[
@
expr
]);
expr_call
(
@
expr
,
(
@
expr
)[
]);
expr_self_method
(
ident
);
expr_bind
(
@
expr
,
vec
[
option
::
t
[
@
expr
]
]);
expr_spawn
(
spawn_dom
,
option
::
t
[
str
],
@
expr
,
vec
[
@
expr
]);
expr_bind
(
@
expr
,
(
option
::
t
[
@
expr
])[
]);
expr_spawn
(
spawn_dom
,
option
::
t
[
str
],
@
expr
,
(
@
expr
)[
]);
expr_binary
(
binop
,
@
expr
,
@
expr
);
expr_unary
(
unop
,
@
expr
);
expr_lit
(
@
lit
);
...
...
@@ -263,7 +263,7 @@ fn unop_to_str(unop op) -> str {
expr_for
(
@
local
,
@
expr
,
block
);
expr_for_each
(
@
local
,
@
expr
,
block
);
expr_do_while
(
block
,
@
expr
);
expr_alt
(
@
expr
,
vec
[
arm
]);
expr_alt
(
@
expr
,
arm
[
]);
expr_fn
(
_
fn
);
expr_block
(
block
);
/*
...
...
@@ -279,7 +279,7 @@ fn unop_to_str(unop op) -> str {
expr_field
(
@
expr
,
ident
);
expr_index
(
@
expr
,
@
expr
);
expr_path
(
path
);
expr_ext
(
path
,
vec
[
@
expr
],
option
::
t
[
str
],
@
expr
);
expr_ext
(
path
,
(
@
expr
)[
],
option
::
t
[
str
],
@
expr
);
expr_fail
(
option
::
t
[
@
expr
]);
expr_break
;
expr_cont
;
...
...
@@ -298,7 +298,7 @@ fn unop_to_str(unop op) -> str {
expr_if_check
(
@
expr
,
block
,
option
::
t
[
@
expr
]);
expr_port
(
option
::
t
[
@
ty
]);
expr_chan
(
@
expr
);
expr_anon_obj
(
anon_obj
,
vec
[
ty_param
]);
expr_anon_obj
(
anon_obj
,
ty_param
[
]);
}
type
lit
=
spanned
[
lit_
];
...
...
@@ -438,7 +438,7 @@ fn ty_mach_to_str(ty_mach tm) -> str {
type
arg
=
rec
(
mode
mode
,
@
ty
ty
,
ident
ident
,
node_id
id
);
type
fn_decl
=
rec
(
vec
[
arg
]
inputs
,
rec
(
arg
[
]
inputs
,
@
ty
output
,
purity
purity
,
controlflow
cf
,
...
...
@@ -470,13 +470,13 @@ fn ty_mach_to_str(ty_mach tm) -> str {
node_id
id
);
type
_
obj
=
rec
(
vec
[
obj_field
]
fields
,
vec
[
@
method
]
methods
,
option
::
t
[
@
method
]
dtor
);
rec
(
obj_field
[]
fields
,
(
@
method
)[
]
methods
,
option
::
t
[
@
method
]
dtor
);
type
anon_obj
=
rec
(
// New fields and methods, if they exist.
option
::
t
[
vec
[
anon_obj_field
]]
fields
,
vec
[
@
method
]
methods
,
option
::
t
[
anon_obj_field
[
]]
fields
,
(
@
method
)[
]
methods
,
// with_obj: the original object being extended, if it exists.
option
::
t
[
@
expr
]
with_obj
);
...
...
@@ -533,14 +533,14 @@ fn ty_mach_to_str(ty_mach tm) -> str {
tag
item_
{
item_const
(
@
ty
,
@
expr
);
item_fn
(
_
fn
,
vec
[
ty_param
]);
item_fn
(
_
fn
,
ty_param
[
]);
item_mod
(
_
mod
);
item_native_mod
(
native_mod
);
item_ty
(
@
ty
,
vec
[
ty_param
]);
item_tag
(
v
ec
[
variant
],
vec
[
ty_param
]);
item_obj
(
_
obj
,
vec
[
ty_param
],
node_id
/* constructor id */
);
item_ty
(
@
ty
,
ty_param
[
]);
item_tag
(
v
ariant
[],
ty_param
[
]);
item_obj
(
_
obj
,
ty_param
[
],
node_id
/* constructor id */
);
item_res
(
_
fn
/* dtor */
,
node_id
/* dtor id */
,
vec
[
ty_param
],
node_id
/* ctor id */
);
ty_param
[
],
node_id
/* ctor id */
);
}
type
native_item
=
rec
(
ident
ident
,
...
...
@@ -551,7 +551,7 @@ fn ty_mach_to_str(ty_mach tm) -> str {
tag
native_item_
{
native_item_ty
;
native_item_fn
(
option
::
t
[
str
],
fn_decl
,
vec
[
ty_param
]);
native_item_fn
(
option
::
t
[
str
],
fn_decl
,
ty_param
[
]);
}
fn
is_exported
(
ident
i
,
_
mod
m
)
->
bool
{
...
...
@@ -609,7 +609,7 @@ fn is_constraint_arg(@expr e) -> bool {
fn
block_from_expr
(
@
expr
e
)
->
block
{
let
block_
blk_
=
rec
(
stmts
=
[],
rec
(
stmts
=
~
[],
expr
=
option
::
some
[
@
expr
](
e
),
id
=
e
.id
);
ret
rec
(
node
=
blk_
,
span
=
e
.span
);
...
...
src/comp/syntax/ext/base.rs
浏览文件 @
0e2fff53
...
...
@@ -8,8 +8,8 @@
import
codemap
;
type
syntax_expander
=
fn
(
&
ext_ctxt
,
span
,
&
vec
[
@
ast
::
expr
],
option
::
t
[
str
])
->
@
ast
::
expr
;
type
macro_definer
=
fn
(
&
ext_ctxt
,
span
,
&
vec
[
@
ast
::
expr
],
fn
(
&
ext_ctxt
,
span
,
&
(
@
ast
::
expr
)[
],
option
::
t
[
str
])
->
@
ast
::
expr
;
type
macro_definer
=
fn
(
&
ext_ctxt
,
span
,
&
(
@
ast
::
expr
)[
],
option
::
t
[
str
])
->
tup
(
str
,
syntax_extension
);
tag
syntax_extension
{
...
...
src/comp/syntax/ext/env.rs
浏览文件 @
0e2fff53
...
...
@@ -5,6 +5,7 @@
* should all get sucked into either the compiler syntax extension plugin
* interface.
*/
import
std
::
ivec
;
import
std
::
str
;
import
std
::
vec
;
import
std
::
option
;
...
...
@@ -12,9 +13,9 @@
import
base
::
*
;
export
expand_syntax_ext
;
fn
expand_syntax_ext
(
&
ext_ctxt
cx
,
codemap
::
span
sp
,
&
vec
[
@
ast
::
expr
]
args
,
fn
expand_syntax_ext
(
&
ext_ctxt
cx
,
codemap
::
span
sp
,
&
(
@
ast
::
expr
)[
]
args
,
option
::
t
[
str
]
body
)
->
@
ast
::
expr
{
if
(
vec
::
len
[
@
ast
::
expr
](
args
)
!=
1u
)
{
if
(
i
vec
::
len
[
@
ast
::
expr
](
args
)
!=
1u
)
{
cx
.span_fatal
(
sp
,
"malformed #env call"
);
}
// FIXME: if this was more thorough it would manufacture an
...
...
src/comp/syntax/ext/fmt.rs
浏览文件 @
0e2fff53
...
...
@@ -5,6 +5,7 @@
* should all get sucked into either the standard library extfmt module or the
* compiler syntax extension plugin interface.
*/
import
std
::
ivec
;
import
std
::
str
;
import
std
::
vec
;
import
std
::
option
;
...
...
@@ -15,9 +16,9 @@
import
codemap
::
span
;
export
expand_syntax_ext
;
fn
expand_syntax_ext
(
&
ext_ctxt
cx
,
span
sp
,
&
vec
[
@
ast
::
expr
]
args
,
fn
expand_syntax_ext
(
&
ext_ctxt
cx
,
span
sp
,
&
(
@
ast
::
expr
)[
]
args
,
option
::
t
[
str
]
body
)
->
@
ast
::
expr
{
if
(
vec
::
len
[
@
ast
::
expr
](
args
)
==
0u
)
{
if
(
i
vec
::
len
[
@
ast
::
expr
](
args
)
==
0u
)
{
cx
.span_fatal
(
sp
,
"#fmt requires a format string"
);
}
auto
fmt
=
expr_to_str
(
cx
,
args
.
(
0
),
"first argument to #fmt must be a "
...
...
@@ -37,7 +38,7 @@ fn parse_fmt_err_(&ext_ctxt cx, span sp, str msg) -> ! {
// be factored out in common with other code that builds expressions.
// FIXME: Cleanup the naming of these functions
fn
pieces_to_expr
(
&
ext_ctxt
cx
,
span
sp
,
vec
[
piece
]
pieces
,
vec
[
@
ast
::
expr
]
args
)
->
@
ast
::
expr
{
&
(
@
ast
::
expr
)[
]
args
)
->
@
ast
::
expr
{
fn
make_new_lit
(
&
ext_ctxt
cx
,
span
sp
,
ast
::
lit_
lit
)
->
@
ast
::
expr
{
auto
sp_lit
=
@
rec
(
node
=
lit
,
span
=
sp
);
...
...
@@ -67,26 +68,26 @@ fn make_path_expr(&ext_ctxt cx, span sp, &ast::ident[] idents)
auto
pathexpr
=
ast
::
expr_path
(
sp_path
);
ret
@
rec
(
id
=
cx
.next_id
(),
node
=
pathexpr
,
span
=
sp
);
}
fn
make_vec_expr
(
&
ext_ctxt
cx
,
span
sp
,
vec
[
@
ast
::
expr
]
exprs
)
->
fn
make_vec_expr
(
&
ext_ctxt
cx
,
span
sp
,
&
(
@
ast
::
expr
)[
]
exprs
)
->
@
ast
::
expr
{
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
,
span
sp
,
&
ast
::
ident
[]
fn_path
,
vec
[
@
ast
::
expr
]
args
)
->
@
ast
::
expr
{
&
(
@
ast
::
expr
)[
]
args
)
->
@
ast
::
expr
{
auto
pathexpr
=
make_path_expr
(
cx
,
sp
,
fn_path
);
auto
callexpr
=
ast
::
expr_call
(
pathexpr
,
args
);
ret
@
rec
(
id
=
cx
.next_id
(),
node
=
callexpr
,
span
=
sp
);
}
fn
make_rec_expr
(
&
ext_ctxt
cx
,
span
sp
,
vec
[
tup
(
ast
::
ident
,
@
ast
::
expr
)]
fields
)
->
@
ast
::
expr
{
let
vec
[
ast
::
field
]
astfields
=
[];
let
ast
::
field
[]
astfields
=
~
[];
for
(
tup
(
ast
::
ident
,
@
ast
::
expr
)
field
in
fields
)
{
auto
ident
=
field
._0
;
auto
val
=
field
._1
;
auto
astfield
=
rec
(
node
=
rec
(
mut
=
ast
::
imm
,
ident
=
ident
,
expr
=
val
),
span
=
sp
);
astfields
+=
[
astfield
];
astfields
+=
~
[
astfield
];
}
auto
recexpr
=
ast
::
expr_rec
(
astfields
,
option
::
none
[
@
ast
::
expr
]);
ret
@
rec
(
id
=
cx
.next_id
(),
node
=
recexpr
,
span
=
sp
);
...
...
@@ -109,7 +110,7 @@ fn make_rt_conv_expr(&ext_ctxt cx, span sp, &conv cnv) ->
@
ast
::
expr
{
fn
make_flags
(
&
ext_ctxt
cx
,
span
sp
,
vec
[
flag
]
flags
)
->
@
ast
::
expr
{
let
vec
[
@
ast
::
expr
]
flagexprs
=
[];
let
(
@
ast
::
expr
)[]
flagexprs
=
~
[];
for
(
flag
f
in
flags
)
{
auto
fstr
;
alt
(
f
)
{
...
...
@@ -121,14 +122,14 @@ fn make_flags(&ext_ctxt cx, span sp, vec[flag] flags) ->
case
(
flag_sign_always
)
{
fstr
=
"flag_sign_always"
;
}
case
(
flag_alternate
)
{
fstr
=
"flag_alternate"
;
}
}
flagexprs
+=
[
make_rt_path_expr
(
cx
,
sp
,
fstr
)];
flagexprs
+=
~
[
make_rt_path_expr
(
cx
,
sp
,
fstr
)];
}
// FIXME: 0-length vectors can't have their type inferred
// through the rec that these flags are a member of, so
// this is a hack placeholder flag
if
(
vec
::
len
[
@
ast
::
expr
](
flagexprs
)
==
0u
)
{
flagexprs
+=
[
make_rt_path_expr
(
cx
,
sp
,
"flag_none"
)];
if
(
i
vec
::
len
[
@
ast
::
expr
](
flagexprs
)
==
0u
)
{
flagexprs
+=
~
[
make_rt_path_expr
(
cx
,
sp
,
"flag_none"
)];
}
ret
make_vec_expr
(
cx
,
sp
,
flagexprs
);
}
...
...
@@ -141,7 +142,7 @@ fn make_count(&ext_ctxt cx, span sp, &count cnt) ->
case
(
count_is
(
?
c
))
{
auto
count_lit
=
make_new_int
(
cx
,
sp
,
c
);
auto
count_is_path
=
make_path_vec
(
"count_is"
);
auto
count_is_args
=
[
count_lit
];
auto
count_is_args
=
~
[
count_lit
];
ret
make_call
(
cx
,
sp
,
count_is_path
,
count_is_args
);
}
case
(
_
)
{
...
...
@@ -185,7 +186,7 @@ fn make_conv_call(&ext_ctxt cx, span sp, str conv_type, &conv cnv,
auto
fname
=
"conv_"
+
conv_type
;
auto
path
=
make_path_vec
(
fname
);
auto
cnv_expr
=
make_rt_conv_expr
(
cx
,
sp
,
cnv
);
auto
args
=
[
cnv_expr
,
arg
];
auto
args
=
~
[
cnv_expr
,
arg
];
ret
make_call
(
cx
,
arg
.span
,
path
,
args
);
}
fn
make_new_conv
(
&
ext_ctxt
cx
,
span
sp
,
conv
cnv
,
@
ast
::
expr
arg
)
...
...
@@ -328,7 +329,7 @@ fn log_conv(conv c) {
auto
fmt_sp
=
args
.
(
0
)
.span
;
auto
n
=
0u
;
auto
tmp_expr
=
make_new_str
(
cx
,
sp
,
""
);
auto
nargs
=
vec
::
len
[
@
ast
::
expr
](
args
);
auto
nargs
=
i
vec
::
len
[
@
ast
::
expr
](
args
);
for
(
piece
pc
in
pieces
)
{
alt
(
pc
)
{
case
(
piece_string
(
?
s
))
{
...
...
src/comp/syntax/ext/simplext.rs
浏览文件 @
0e2fff53
...
...
@@ -34,7 +34,7 @@ fn position[T](&T x, &vec[T] v) -> option::t[uint] {
}
// substitute, in a position that's required to be an ident
fn
subst_ident
(
&
ext_ctxt
cx
,
&
vec
[
@
ast
::
expr
]
args
,
fn
subst_ident
(
&
ext_ctxt
cx
,
&
(
@
ast
::
expr
)[
]
args
,
@
vec
[
ident
]
param_names
,
&
ident
i
,
ast_fold
fld
)
->
ident
{
alt
(
position
(
i
,
*
param_names
))
{
case
(
some
[
uint
](
?
idx
))
{
...
...
@@ -48,7 +48,7 @@ fn subst_ident(&ext_ctxt cx, &vec[@ast::expr] args,
}
}
fn
subst_path
(
&
ext_ctxt
cx
,
&
vec
[
@
ast
::
expr
]
args
,
fn
subst_path
(
&
ext_ctxt
cx
,
&
(
@
ast
::
expr
)[
]
args
,
@
vec
[
ident
]
param_names
,
&
path_
p
,
ast_fold
fld
)
->
path_
{
// Don't substitute into qualified names.
if
(
ivec
::
len
(
p
.types
)
>
0u
||
ivec
::
len
(
p
.idents
)
!=
1u
)
{
ret
p
;
}
...
...
@@ -70,7 +70,7 @@ fn subst_path(&ext_ctxt cx, &vec[@ast::expr] args,
}
fn
subst_expr
(
&
ext_ctxt
cx
,
&
vec
[
@
ast
::
expr
]
args
,
@
vec
[
ident
]
param_names
,
fn
subst_expr
(
&
ext_ctxt
cx
,
&
(
@
ast
::
expr
)[
]
args
,
@
vec
[
ident
]
param_names
,
&
ast
::
expr_
e
,
ast_fold
fld
,
fn
(
&
ast
::
expr_
,
ast_fold
)
->
ast
::
expr_
orig
)
->
ast
::
expr_
{
ret
alt
(
e
)
{
...
...
@@ -90,20 +90,21 @@ fn subst_expr(&ext_ctxt cx, &vec[@ast::expr] args, @vec[ident] param_names,
}
fn
add_new_extension
(
&
ext_ctxt
cx
,
span
sp
,
&
vec
[
@
ast
::
expr
]
args
,
fn
add_new_extension
(
&
ext_ctxt
cx
,
span
sp
,
&
(
@
ast
::
expr
)[
]
args
,
option
::
t
[
str
]
body
)
->
tup
(
str
,
syntax_extension
)
{
if
(
len
(
args
)
<
2u
)
{
if
(
ivec
::
len
(
args
)
<
2u
)
{
cx
.span_fatal
(
sp
,
"malformed extension description"
);
}
fn
generic_extension
(
&
ext_ctxt
cx
,
span
sp
,
&
vec
[
@
ast
::
expr
]
args
,
fn
generic_extension
(
&
ext_ctxt
cx
,
span
sp
,
&
(
@
ast
::
expr
)[
]
args
,
option
::
t
[
str
]
body
,
@
vec
[
ident
]
param_names
,
@
ast
::
expr
dest_form
)
->
@
ast
::
expr
{
if
(
len
(
args
)
!=
len
(
*
param_names
))
{
if
(
ivec
::
len
(
args
)
!=
len
(
*
param_names
))
{
cx
.span_fatal
(
sp
,
#
fmt
(
"extension expects %u arguments, got %u"
,
len
(
*
param_names
),
len
(
args
)));
len
(
*
param_names
),
ivec
::
len
(
args
)));
}
// FIXME: This binds to alias arguments.
auto
afp
=
default_ast_fold
();
auto
f_pre
=
rec
(
fold_ident
=
bind
subst_ident
(
cx
,
args
,
param_names
,
_
,
_
),
...
...
@@ -120,7 +121,7 @@ fn generic_extension(&ext_ctxt cx, span sp, &vec[@ast::expr] args,
let
vec
[
ident
]
param_names
=
vec
::
empty
[
ident
]();
let
uint
idx
=
1u
;
while
(
1u
+
idx
<
len
(
args
))
{
while
(
1u
+
idx
<
ivec
::
len
(
args
))
{
param_names
+=
[
expr_to_ident
(
cx
,
args
.
(
idx
),
"this parameter name must be an identifier."
)];
...
...
@@ -129,7 +130,7 @@ fn generic_extension(&ext_ctxt cx, span sp, &vec[@ast::expr] args,
ret
tup
(
expr_to_str
(
cx
,
args
.
(
0
),
"first arg must be a literal string."
),
normal
(
bind
generic_extension
(
_
,
_
,
_
,
_
,
@
param_names
,
args
.
(
len
(
args
)
-
1u
))));
args
.
(
ivec
::
len
(
args
)
-
1u
))));
}
...
...
src/comp/syntax/fold.rs
浏览文件 @
0e2fff53
...
...
@@ -172,7 +172,8 @@ fn noop_fold_native_item(&@native_item ni, ast_fold fld) -> @native_item {
case
(
native_item_ty
)
{
native_item_ty
}
case
(
native_item_fn
(
?
st
,
?
fdec
,
?
typms
))
{
native_item_fn
(
st
,
rec
(
inputs
=
map
(
fold_arg
,
fdec
.inputs
),
rec
(
inputs
=
ivec
::
map
(
fold_arg
,
fdec
.inputs
),
output
=
fld
.fold_ty
(
fdec
.output
),
purity
=
fdec
.purity
,
cf
=
fdec
.cf
,
constraints
=
ivec
::
map
(
fld
.fold_constr
,
...
...
@@ -216,11 +217,11 @@ fn fold_obj_field_(&obj_field of, ast_fold fld) -> obj_field {
item_ty
(
fld
.fold_ty
(
t
),
typms
)
}
case
(
item_tag
(
?
variants
,
?
typms
))
{
item_tag
(
map
(
fld
.fold_variant
,
variants
),
typms
)
item_tag
(
ivec
::
map
(
fld
.fold_variant
,
variants
),
typms
)
}
case
(
item_obj
(
?
o
,
?
typms
,
?
d
))
{
item_obj
(
rec
(
fields
=
map
(
fold_obj_field
,
o
.fields
),
methods
=
map
(
fld
.fold_method
,
o
.methods
),
item_obj
(
rec
(
fields
=
ivec
::
map
(
fold_obj_field
,
o
.fields
),
methods
=
ivec
::
map
(
fld
.fold_method
,
o
.methods
),
dtor
=
option
::
map
(
fld
.fold_method
,
o
.dtor
)),
typms
,
d
)
}
...
...
@@ -237,7 +238,7 @@ fn noop_fold_method(&method_ m, ast_fold fld) -> method_ {
fn
noop_fold_block
(
&
block_
b
,
ast_fold
fld
)
->
block_
{
ret
rec
(
stmts
=
map
(
fld
.fold_stmt
,
b
.stmts
),
ret
rec
(
stmts
=
ivec
::
map
(
fld
.fold_stmt
,
b
.stmts
),
expr
=
option
::
map
(
fld
.fold_expr
,
b
.expr
),
id
=
b
.id
);
}
...
...
@@ -261,7 +262,7 @@ fn noop_fold_pat(&pat_ p, ast_fold fld) -> pat_ {
case
(
pat_bind
(
?
ident
))
{
pat_bind
(
fld
.fold_ident
(
ident
))}
case
(
pat_lit
(
_
))
{
p
}
case
(
pat_tag
(
?
pth
,
?
pats
))
{
pat_tag
(
fld
.fold_path
(
pth
),
map
(
fld
.fold_pat
,
pats
))
pat_tag
(
fld
.fold_path
(
pth
),
ivec
::
map
(
fld
.fold_pat
,
pats
))
}
};
}
...
...
@@ -298,12 +299,12 @@ fn fold_anon_obj_field_(&anon_obj_field aof, ast_fold fld)
auto
fold_anon_obj_field
=
bind
fold_anon_obj_field_
(
_
,
fld
);
ret
rec
(
fields
=
alt
(
ao
.fields
)
{
case
(
option
::
none
[
vec
[
anon_obj_field
]])
{
ao
.fields
}
case
(
option
::
some
[
vec
[
anon_obj_field
]](
?
v
))
{
option
::
some
[
vec
[
anon_obj_field
]]
(
map
(
fold_anon_obj_field
,
v
))
case
(
option
::
none
[
anon_obj_field
[
]])
{
ao
.fields
}
case
(
option
::
some
[
anon_obj_field
[
]](
?
v
))
{
option
::
some
[
anon_obj_field
[
]]
(
ivec
::
map
(
fold_anon_obj_field
,
v
))
}},
methods
=
map
(
fld
.fold_method
,
ao
.methods
),
methods
=
ivec
::
map
(
fld
.fold_method
,
ao
.methods
),
with_obj
=
option
::
map
(
fld
.fold_expr
,
ao
.with_obj
))
}
auto
fold_anon_obj
=
bind
fold_anon_obj_
(
_
,
fld
);
...
...
@@ -311,28 +312,28 @@ fn fold_anon_obj_field_(&anon_obj_field aof, ast_fold fld)
ret
alt
(
e
)
{
case
(
expr_vec
(
?
exprs
,
?
mut
,
?
seq_kind
))
{
expr_vec
(
map
(
fld
.fold_expr
,
exprs
),
mut
,
seq_kind
)
expr_vec
(
ivec
::
map
(
fld
.fold_expr
,
exprs
),
mut
,
seq_kind
)
}
case
(
expr_tup
(
?
elts
))
{
expr_tup
(
map
(
fold_elt
,
elts
))
expr_tup
(
ivec
::
map
(
fold_elt
,
elts
))
}
case
(
expr_rec
(
?
fields
,
?
maybe_expr
))
{
expr_rec
(
map
(
fold_field
,
fields
),
expr_rec
(
ivec
::
map
(
fold_field
,
fields
),
option
::
map
(
fld
.fold_expr
,
maybe_expr
))
}
case
(
expr_call
(
?
f
,
?
args
))
{
expr_call
(
fld
.fold_expr
(
f
),
map
(
fld
.fold_expr
,
args
))
expr_call
(
fld
.fold_expr
(
f
),
ivec
::
map
(
fld
.fold_expr
,
args
))
}
case
(
expr_self_method
(
?
id
))
{
expr_self_method
(
fld
.fold_ident
(
id
))
}
case
(
expr_bind
(
?
f
,
?
args
))
{
auto
opt_map_se
=
bind
option
::
map
(
fld
.fold_expr
,
_
);
expr_bind
(
fld
.fold_expr
(
f
),
map
(
opt_map_se
,
args
))
expr_bind
(
fld
.fold_expr
(
f
),
ivec
::
map
(
opt_map_se
,
args
))
}
case
(
expr_spawn
(
?
spawn_dom
,
?
name
,
?
f
,
?
args
))
{
expr_spawn
(
spawn_dom
,
name
,
fld
.fold_expr
(
f
),
map
(
fld
.fold_expr
,
args
))
ivec
::
map
(
fld
.fold_expr
,
args
))
}
case
(
expr_binary
(
?
binop
,
?
lhs
,
?
rhs
))
{
expr_binary
(
binop
,
fld
.fold_expr
(
lhs
),
fld
.fold_expr
(
rhs
))
...
...
@@ -368,7 +369,7 @@ fn fold_anon_obj_field_(&anon_obj_field aof, ast_fold fld)
expr_do_while
(
fld
.fold_block
(
block
),
fld
.fold_expr
(
expr
))
}
case
(
expr_alt
(
?
expr
,
?
arms
))
{
expr_alt
(
fld
.fold_expr
(
expr
),
map
(
fld
.fold_arm
,
arms
))
expr_alt
(
fld
.fold_expr
(
expr
),
ivec
::
map
(
fld
.fold_arm
,
arms
))
}
case
(
expr_fn
(
?
f
))
{
expr_fn
(
fld
.fold_fn
(
f
))
...
...
@@ -404,7 +405,7 @@ fn fold_anon_obj_field_(&anon_obj_field aof, ast_fold fld)
expr_path
(
fld
.fold_path
(
pth
))
}
case
(
expr_ext
(
?
pth
,
?
args
,
?
body
,
?
expanded
))
{
expr_ext
(
fld
.fold_path
(
pth
),
map
(
fld
.fold_expr
,
args
),
expr_ext
(
fld
.fold_path
(
pth
),
ivec
::
map
(
fld
.fold_expr
,
args
),
body
,
fld
.fold_expr
(
expanded
))
}
case
(
expr_fail
(
_
))
{
e
}
...
...
@@ -450,7 +451,7 @@ fn noop_fold_constr(&constr_ c, ast_fold fld) -> constr_ {
fn
noop_fold_fn
(
&
_
fn
f
,
ast_fold
fld
)
->
_
fn
{
auto
fold_arg
=
bind
fold_arg_
(
_
,
fld
);
ret
rec
(
decl
=
rec
(
inputs
=
vec
::
map
(
fold_arg
,
f
.decl.inputs
),
ret
rec
(
decl
=
rec
(
inputs
=
i
vec
::
map
(
fold_arg
,
f
.decl.inputs
),
output
=
fld
.fold_ty
(
f
.decl.output
),
purity
=
f
.decl.purity
,
cf
=
f
.decl.cf
,
...
...
src/comp/syntax/parse/parser.rs
浏览文件 @
0e2fff53
...
...
@@ -260,7 +260,7 @@ fn parse_fn_input_ty(&parser p) -> ast::ty_arg {
auto
inputs
=
parse_seq_ivec
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_fn_input_ty
,
p
);
auto
constrs
=
parse_constrs
([],
p
);
auto
constrs
=
parse_constrs
(
~
[],
p
);
let
@
ast
::
ty
output
;
auto
cf
=
ast
::
return
;
if
(
p
.peek
()
==
token
::
RARROW
)
{
...
...
@@ -329,13 +329,13 @@ fn parse_ty_field(&parser p) -> ast::ty_field {
// if i is the jth ident in args, return j
// otherwise, fail
fn
ident_index
(
&
parser
p
,
&
vec
[
ast
::
arg
]
args
,
&
ast
::
ident
i
)
->
uint
{
fn
ident_index
(
&
parser
p
,
&
ast
::
arg
[
]
args
,
&
ast
::
ident
i
)
->
uint
{
auto
j
=
0u
;
for
(
ast
::
arg
a
in
args
)
{
if
(
a
.ident
==
i
)
{
ret
j
;
}
j
+=
1u
;
}
p
.fatal
(
"Unbound variable "
+
i
+
" in constraint arg"
);
}
fn
parse_constr_arg
(
vec
[
ast
::
arg
]
args
,
&
parser
p
)
->
@
ast
::
constr_arg
{
fn
parse_constr_arg
(
&
ast
::
arg
[
]
args
,
&
parser
p
)
->
@
ast
::
constr_arg
{
auto
sp
=
p
.get_span
();
auto
carg
=
ast
::
carg_base
;
if
(
p
.peek
()
==
token
::
BINOP
(
token
::
STAR
))
{
...
...
@@ -347,7 +347,7 @@ fn parse_constr_arg(vec[ast::arg] args, &parser p) -> @ast::constr_arg {
ret
@
rec
(
node
=
carg
,
span
=
sp
);
}
fn
parse_ty_constr
(
&
vec
[
ast
::
arg
]
fn_args
,
&
parser
p
)
->
@
ast
::
constr
{
fn
parse_ty_constr
(
&
ast
::
arg
[
]
fn_args
,
&
parser
p
)
->
@
ast
::
constr
{
auto
lo
=
p
.get_lo_pos
();
auto
path
=
parse_path
(
p
);
auto
pf
=
bind
parse_constr_arg
(
fn_args
,
_
);
...
...
@@ -364,7 +364,7 @@ fn parse_ty_constr(&vec[ast::arg] fn_args, &parser p) -> @ast::constr {
// Use the args list to translate each bound variable
// mentioned in a constraint to an arg index.
// Seems weird to do this in the parser, but I'm not sure how else to.
fn
parse_constrs
(
&
vec
[
ast
::
arg
]
args
,
&
parser
p
)
fn
parse_constrs
(
&
ast
::
arg
[
]
args
,
&
parser
p
)
->
ast
::
spanned
[(
@
ast
::
constr
)[]]
{
auto
lo
=
p
.get_lo_pos
();
auto
hi
=
p
.get_hi_pos
();
...
...
@@ -383,7 +383,7 @@ fn parse_constrs(&vec[ast::arg] args, &parser p)
fn
parse_ty_constrs
(
@
ast
::
ty
t
,
&
parser
p
)
->
@
ast
::
ty
{
if
(
p
.peek
()
==
token
::
COLON
)
{
auto
constrs
=
parse_constrs
([],
p
);
auto
constrs
=
parse_constrs
(
~
[],
p
);
ret
@
spanned
(
t
.span.lo
,
constrs
.span.hi
,
ast
::
ty_constr
(
t
,
constrs
.node
));
}
...
...
@@ -776,16 +776,16 @@ fn parse_elt(&parser p) -> ast::elt {
ret
rec
(
mut
=
m
,
expr
=
e
);
}
auto
es
=
parse_seq
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_elt
,
p
);
parse_seq
_ivec
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_elt
,
p
);
hi
=
es
.span.hi
;
ex
=
ast
::
expr_tup
(
es
.node
);
}
else
if
(
p
.peek
()
==
token
::
LBRACKET
)
{
p
.bump
();
auto
mut
=
parse_mutability
(
p
);
auto
es
=
parse_seq_to_end
(
token
::
RBRACKET
,
some
(
token
::
COMMA
),
parse_expr
,
p
);
parse_seq_to_end
_ivec
(
token
::
RBRACKET
,
some
(
token
::
COMMA
)
,
parse_expr
,
p
);
ex
=
ast
::
expr_vec
(
es
,
mut
,
ast
::
sk_rc
);
}
else
if
(
p
.peek
()
==
token
::
TILDE
)
{
p
.bump
();
...
...
@@ -795,8 +795,8 @@ fn parse_elt(&parser p) -> ast::elt {
p
.bump
();
auto
mut
=
parse_mutability
(
p
);
auto
es
=
parse_seq_to_end
(
token
::
RBRACKET
,
some
(
token
::
COMMA
),
parse_expr
,
p
);
parse_seq_to_end
_ivec
(
token
::
RBRACKET
,
some
(
token
::
COMMA
),
parse_expr
,
p
);
ex
=
ast
::
expr_vec
(
es
,
mut
,
ast
::
sk_unique
);
}
case
(
token
::
LIT_STR
(
?
s
))
{
...
...
@@ -817,20 +817,22 @@ fn parse_elt(&parser p) -> ast::elt {
auto
ty_params
=
parse_ty_params
(
p
);
// Only make people type () if they're actually adding new fields
let
option
::
t
[
vec
[
ast
::
anon_obj_field
]]
fields
=
none
;
let
option
::
t
[
ast
::
anon_obj_field
[
]]
fields
=
none
;
if
(
p
.peek
()
==
token
::
LPAREN
)
{
p
.bump
();
fields
=
some
(
parse_seq_to_end
(
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_anon_obj_field
,
p
));
some
(
parse_seq_to_end
_ivec
(
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_anon_obj_field
,
p
));
}
let
vec
[
@
ast
::
method
]
meths
=
[];
let
(
@
ast
::
method
)[]
meths
=
~
[];
let
option
::
t
[
@
ast
::
expr
]
with_obj
=
none
;
expect
(
p
,
token
::
LBRACE
);
while
(
p
.peek
()
!=
token
::
RBRACE
)
{
if
(
eat_word
(
p
,
"with"
))
{
with_obj
=
some
(
parse_expr
(
p
));
}
else
{
vec
::
push
(
meths
,
parse_method
(
p
));
}
}
else
{
meths
+=
~
[
parse_method
(
p
)];
}
}
hi
=
p
.get_hi_pos
();
expect
(
p
,
token
::
RBRACE
);
...
...
@@ -845,7 +847,7 @@ fn parse_elt(&parser p) -> ast::elt {
ex
=
ast
::
expr_anon_obj
(
ob
,
ty_params
);
}
else
if
(
eat_word
(
p
,
"rec"
))
{
expect
(
p
,
token
::
LPAREN
);
auto
fields
=
[
parse_field
(
p
)];
auto
fields
=
~
[
parse_field
(
p
)];
auto
more
=
true
;
auto
base
=
none
;
while
(
more
)
{
...
...
@@ -860,7 +862,7 @@ fn parse_elt(&parser p) -> ast::elt {
more
=
false
;
}
else
if
(
p
.peek
()
==
token
::
COMMA
)
{
p
.bump
();
fields
+=
[
parse_field
(
p
)];
fields
+=
~
[
parse_field
(
p
)];
}
else
{
unexpected
(
p
,
p
.peek
());
}
}
ex
=
ast
::
expr_rec
(
fields
,
base
);
...
...
@@ -873,8 +875,8 @@ fn parse_expr_opt(&parser p) -> option::t[@ast::expr] {
}
}
auto
es
=
parse_seq
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_expr_opt
,
p
);
parse_seq
_ivec
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_expr_opt
,
p
);
hi
=
es
.span.hi
;
ex
=
ast
::
expr_bind
(
e
,
es
.node
);
}
else
if
(
p
.peek
()
==
token
::
POUND
)
{
...
...
@@ -969,8 +971,8 @@ fn parse_expr_opt(&parser p) -> option::t[@ast::expr] {
let
@
ast
::
expr
f
=
parse_self_method
(
p
);
auto
es
=
parse_seq
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_expr
,
p
);
parse_seq
_ivec
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_expr
,
p
);
hi
=
es
.span.hi
;
ex
=
ast
::
expr_call
(
f
,
es
.node
);
}
else
if
(
is_ident
(
p
.peek
())
&&
!
is_word
(
p
,
"true"
)
&&
...
...
@@ -998,8 +1000,8 @@ fn parse_syntax_ext_naked(&parser p, uint lo) -> @ast::expr {
if
(
ivec
::
len
(
pth
.node.idents
)
==
0u
)
{
p
.fatal
(
"expected a syntax expander name"
);
}
auto
es
=
parse_seq
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_expr
,
p
);
auto
es
=
parse_seq
_ivec
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_expr
,
p
);
auto
hi
=
es
.span.hi
;
auto
ext_span
=
rec
(
lo
=
lo
,
hi
=
hi
);
auto
ex
=
expand_syntax_ext
(
p
,
ext_span
,
pth
,
es
.node
,
none
);
...
...
@@ -1013,7 +1015,7 @@ fn parse_syntax_ext_naked(&parser p, uint lo) -> @ast::expr {
* loading rust crates to process extensions.
*/
fn
expand_syntax_ext
(
&
parser
p
,
span
sp
,
&
ast
::
path
path
,
vec
[
@
ast
::
expr
]
args
,
option
::
t
[
str
]
body
)
->
&
(
@
ast
::
expr
)[
]
args
,
option
::
t
[
str
]
body
)
->
ast
::
expr_
{
assert
(
ivec
::
len
(
path
.node.idents
)
>
0u
);
auto
extname
=
path
.node.idents
.
(
0
);
...
...
@@ -1030,7 +1032,7 @@ fn expand_syntax_ext(&parser p, span sp, &ast::path path,
auto
name_and_extension
=
ext
(
ext_cx
,
sp
,
args
,
body
);
p
.get_syntax_expanders
()
.insert
(
name_and_extension
._0
,
name_and_extension
._1
);
ret
ast
::
expr_tup
(
vec
::
empty
[
ast
::
elt
]()
);
ret
ast
::
expr_tup
(
~
[]
);
}
}
}
...
...
@@ -1057,8 +1059,8 @@ fn parse_dot_or_call_expr_with(&parser p, @ast::expr e) -> @ast::expr {
// Call expr.
auto
es
=
parse_seq
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_expr
,
p
);
parse_seq
_ivec
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_expr
,
p
);
hi
=
es
.span.hi
;
e
=
mk_expr
(
p
,
lo
,
hi
,
ast
::
expr_call
(
e
,
es
.node
));
}
...
...
@@ -1349,7 +1351,7 @@ fn parse_alt_expr(&parser p) -> @ast::expr {
auto
lo
=
p
.get_last_lo_pos
();
auto
discriminant
=
parse_expr
(
p
);
expect
(
p
,
token
::
LBRACE
);
let
vec
[
ast
::
arm
]
arms
=
[];
let
ast
::
arm
[]
arms
=
~
[];
while
(
p
.peek
()
!=
token
::
RBRACE
)
{
// Optionally eat the case keyword.
// FIXME remove this (and the optional parens) once we've updated our
...
...
@@ -1360,7 +1362,7 @@ fn parse_alt_expr(&parser p) -> @ast::expr {
auto
pat
=
parse_pat
(
p
);
if
(
parens
)
{
expect
(
p
,
token
::
RPAREN
);
}
auto
block
=
parse_block
(
p
);
arms
+=
[
rec
(
pat
=
pat
,
block
=
block
)];
arms
+=
~
[
rec
(
pat
=
pat
,
block
=
block
)];
}
auto
hi
=
p
.get_hi_pos
();
p
.bump
();
...
...
@@ -1374,8 +1376,8 @@ fn parse_spawn_expr(&parser p) -> @ast::expr {
auto
fn_expr
=
parse_bottom_expr
(
p
);
auto
es
=
parse_seq
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_expr
,
p
);
parse_seq
_ivec
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_expr
,
p
);
auto
hi
=
es
.span.hi
;
ret
mk_expr
(
p
,
lo
,
hi
,
ast
::
expr_spawn
(
ast
::
dom_implicit
,
option
::
none
,
fn_expr
,
es
.node
));
...
...
@@ -1449,17 +1451,17 @@ fn parse_pat(&parser p) -> @ast::pat {
}
else
{
auto
tag_path
=
parse_path_and_ty_param_substs
(
p
);
hi
=
tag_path
.span.hi
;
let
vec
[
@
ast
::
pat
]
args
;
let
(
@
ast
::
pat
)[
]
args
;
alt
(
p
.peek
())
{
case
(
token
::
LPAREN
)
{
auto
f
=
parse_pat
;
auto
a
=
parse_seq
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
f
,
p
);
parse_seq
_ivec
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
f
,
p
);
args
=
a
.node
;
hi
=
a
.span.hi
;
}
case
(
_
)
{
args
=
[];
}
case
(
_
)
{
args
=
~
[];
}
}
pat
=
ast
::
pat_tag
(
tag_path
,
args
);
}
...
...
@@ -1645,7 +1647,7 @@ fn stmt_ends_with_semi(&ast::stmt stmt) -> bool {
fn
parse_block
(
&
parser
p
)
->
ast
::
block
{
auto
lo
=
p
.get_lo_pos
();
let
vec
[
@
ast
::
stmt
]
stmts
=
[];
let
(
@
ast
::
stmt
)[]
stmts
=
~
[];
let
option
::
t
[
@
ast
::
expr
]
expr
=
none
;
expect
(
p
,
token
::
LBRACE
);
while
(
p
.peek
()
!=
token
::
RBRACE
)
{
...
...
@@ -1658,7 +1660,7 @@ fn parse_block(&parser p) -> ast::block {
alt
(
stmt_to_expr
(
stmt
))
{
case
(
some
(
?
e
))
{
alt
(
p
.peek
())
{
case
(
token
::
SEMI
)
{
p
.bump
();
stmts
+=
[
stmt
];
}
case
(
token
::
SEMI
)
{
p
.bump
();
stmts
+=
~
[
stmt
];
}
case
(
token
::
RBRACE
)
{
expr
=
some
(
e
);
}
case
(
?
t
)
{
if
(
stmt_ends_with_semi
(
*
stmt
))
{
...
...
@@ -1668,13 +1670,13 @@ fn parse_block(&parser p) -> ast::block {
t
));
fail
;
}
stmts
+=
[
stmt
];
stmts
+=
~
[
stmt
];
}
}
}
case
(
none
)
{
// Not an expression statement.
stmts
+=
[
stmt
];
stmts
+=
~
[
stmt
];
if
(
p
.get_file_type
()
==
SOURCE_FILE
&&
stmt_ends_with_semi
(
*
stmt
))
{
...
...
@@ -1693,20 +1695,20 @@ fn parse_block(&parser p) -> ast::block {
fn
parse_ty_param
(
&
parser
p
)
->
ast
::
ty_param
{
ret
parse_ident
(
p
);
}
fn
parse_ty_params
(
&
parser
p
)
->
vec
[
ast
::
ty_param
]
{
let
vec
[
ast
::
ty_param
]
ty_params
=
[];
fn
parse_ty_params
(
&
parser
p
)
->
ast
::
ty_param
[
]
{
let
ast
::
ty_param
[]
ty_params
=
~
[];
if
(
p
.peek
()
==
token
::
LBRACKET
)
{
ty_params
=
parse_seq
(
token
::
LBRACKET
,
token
::
RBRACKET
,
some
(
token
::
COMMA
)
,
parse_ty_param
,
p
)
.node
;
parse_seq
_ivec
(
token
::
LBRACKET
,
token
::
RBRACKET
,
some
(
token
::
COMMA
),
parse_ty_param
,
p
)
.node
;
}
ret
ty_params
;
}
fn
parse_fn_decl
(
&
parser
p
,
ast
::
purity
purity
)
->
ast
::
fn_decl
{
let
ast
::
spanned
[
vec
[
ast
::
arg
]]
inputs
=
parse_seq
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_arg
,
p
);
let
ast
::
spanned
[
ast
::
arg
[
]]
inputs
=
parse_seq
_ivec
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
)
,
parse_arg
,
p
);
let
ty_or_bang
rslt
;
auto
constrs
=
parse_constrs
(
inputs
.node
,
p
)
.node
;
if
(
p
.peek
()
==
token
::
RARROW
)
{
...
...
@@ -1740,7 +1742,7 @@ fn parse_fn(&parser p, ast::proto proto, ast::purity purity) -> ast::_fn {
ret
rec
(
decl
=
decl
,
proto
=
proto
,
body
=
body
);
}
fn
parse_fn_header
(
&
parser
p
)
->
tup
(
ast
::
ident
,
vec
[
ast
::
ty_param
])
{
fn
parse_fn_header
(
&
parser
p
)
->
tup
(
ast
::
ident
,
ast
::
ty_param
[
])
{
auto
id
=
parse_value_ident
(
p
);
auto
ty_params
=
parse_ty_params
(
p
);
ret
tup
(
id
,
ty_params
);
...
...
@@ -1791,7 +1793,7 @@ fn parse_method(&parser p) -> @ast::method {
fn
parse_dtor
(
&
parser
p
)
->
@
ast
::
method
{
auto
lo
=
p
.get_last_lo_pos
();
let
ast
::
block
b
=
parse_block
(
p
);
let
vec
[
ast
::
arg
]
inputs
=
[];
let
ast
::
arg
[]
inputs
=
~
[];
let
@
ast
::
ty
output
=
@
spanned
(
lo
,
lo
,
ast
::
ty_nil
);
let
ast
::
fn_decl
d
=
rec
(
inputs
=
inputs
,
...
...
@@ -1812,16 +1814,16 @@ fn parse_item_obj(&parser p, ast::layer lyr, &ast::attribute[] attrs) ->
auto
lo
=
p
.get_last_lo_pos
();
auto
ident
=
parse_value_ident
(
p
);
auto
ty_params
=
parse_ty_params
(
p
);
let
ast
::
spanned
[
vec
[
ast
::
obj_field
]]
fields
=
parse_seq
[
ast
::
obj_field
](
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
),
parse_obj_field
,
p
);
let
vec
[
@
ast
::
method
]
meths
=
[];
let
ast
::
spanned
[
ast
::
obj_field
[
]]
fields
=
parse_seq
_ivec
(
token
::
LPAREN
,
token
::
RPAREN
,
some
(
token
::
COMMA
)
,
parse_obj_field
,
p
);
let
(
@
ast
::
method
)[]
meths
=
~
[];
let
option
::
t
[
@
ast
::
method
]
dtor
=
none
;
expect
(
p
,
token
::
LBRACE
);
while
(
p
.peek
()
!=
token
::
RBRACE
)
{
if
(
eat_word
(
p
,
"drop"
))
{
dtor
=
some
(
parse_dtor
(
p
));
}
else
{
vec
::
push
(
meths
,
parse_method
(
p
))
;
}
}
else
{
meths
+=
~
[
parse_method
(
p
)]
;
}
}
auto
hi
=
p
.get_hi_pos
();
expect
(
p
,
token
::
RBRACE
);
...
...
@@ -1840,8 +1842,8 @@ fn parse_item_res(&parser p, ast::layer lyr, &ast::attribute[] attrs) ->
auto
arg_ident
=
parse_value_ident
(
p
);
expect
(
p
,
token
::
RPAREN
);
auto
dtor
=
parse_block
(
p
);
auto
decl
=
rec
(
inputs
=
[
rec
(
mode
=
ast
::
alias
(
false
),
ty
=
t
,
ident
=
arg_iden
t
,
id
=
p
.get_id
())],
auto
decl
=
rec
(
inputs
=
~
[
rec
(
mode
=
ast
::
alias
(
false
),
ty
=
t
,
ident
=
arg_ident
,
id
=
p
.get_id
())],
output
=@
spanned
(
lo
,
lo
,
ast
::
ty_nil
),
purity
=
ast
::
impure_fn
,
cf
=
ast
::
return
,
...
...
@@ -2015,7 +2017,7 @@ fn parse_item_tag(&parser p, &ast::attribute[] attrs) -> @ast::item {
auto
lo
=
p
.get_last_lo_pos
();
auto
id
=
parse_ident
(
p
);
auto
ty_params
=
parse_ty_params
(
p
);
let
vec
[
ast
::
variant
]
variants
=
[];
let
ast
::
variant
[]
variants
=
~
[];
// Newtype syntax
if
(
p
.peek
()
==
token
::
EQ
)
{
if
(
p
.get_bad_expr_words
()
.contains_key
(
id
))
{
...
...
@@ -2029,7 +2031,7 @@ fn parse_item_tag(&parser p, &ast::attribute[] attrs) -> @ast::item {
args
=
[
rec
(
ty
=
ty
,
id
=
p
.get_id
())],
id
=
p
.get_id
()));
ret
mk_item
(
p
,
lo
,
ty
.span.hi
,
id
,
ast
::
item_tag
([
variant
],
ty_params
),
attrs
);
ast
::
item_tag
(
~
[
variant
],
ty_params
),
attrs
);
}
expect
(
p
,
token
::
LBRACE
);
while
(
p
.peek
()
!=
token
::
RBRACE
)
{
...
...
@@ -2058,7 +2060,7 @@ fn parse_item_tag(&parser p, &ast::attribute[] attrs) -> @ast::item {
rec
(
name
=
p
.get_str
(
name
),
args
=
args
,
id
=
p
.get_id
());
variants
+=
[
spanned
(
vlo
,
vhi
,
vr
)];
variants
+=
~
[
spanned
(
vlo
,
vhi
,
vr
)];
}
case
(
token
::
RBRACE
)
{
/* empty */
}
case
(
_
)
{
...
...
src/comp/syntax/print/pprust.rs
浏览文件 @
0e2fff53
...
...
@@ -103,7 +103,7 @@ fn print_crate(&codemap cm, @ast::crate crate, str filename,
fn
path_to_str
(
&
ast
::
path
p
)
->
str
{
be
to_str
(
p
,
print_path
);
}
fn
fun_to_str
(
&
ast
::
_
fn
f
,
str
name
,
vec
[
ast
::
ty_param
]
params
)
->
str
{
fn
fun_to_str
(
&
ast
::
_
fn
f
,
str
name
,
&
ast
::
ty_param
[
]
params
)
->
str
{
auto
writer
=
io
::
string_writer
();
auto
s
=
rust_printer
(
writer
.get_writer
());
print_fn
(
s
,
f
.decl
,
f
.proto
,
name
,
params
);
...
...
@@ -257,9 +257,9 @@ fn commasep_cmnt_ivec[IN](&ps s, breaks b, &IN[] elts, fn(&ps, &IN) op,
end
(
s
);
}
fn
commasep_exprs
(
&
ps
s
,
breaks
b
,
vec
[
@
ast
::
expr
]
exprs
)
{
fn
commasep_exprs
(
&
ps
s
,
breaks
b
,
&
(
@
ast
::
expr
)[
]
exprs
)
{
fn
expr_span
(
&@
ast
::
expr
expr
)
->
codemap
::
span
{
ret
expr
.span
;
}
commasep_cmnt
(
s
,
b
,
exprs
,
print_expr
,
expr_span
);
commasep_cmnt
_ivec
(
s
,
b
,
exprs
,
print_expr
,
expr_span
);
}
fn
print_mod
(
&
ps
s
,
ast
::
_
mod
_
mod
,
&
ast
::
attribute
[]
attrs
)
{
...
...
@@ -463,7 +463,7 @@ fn print_item(&ps s, &@ast::item item) {
break_offset
(
s
.s
,
0u
,
0
);
}
case
(
ast
::
item_tag
(
?
variants
,
?
params
))
{
auto
newtype
=
vec
::
len
(
variants
)
==
1u
&&
auto
newtype
=
i
vec
::
len
(
variants
)
==
1u
&&
str
::
eq
(
item
.ident
,
variants
.
(
0
)
.node.name
)
&&
vec
::
len
(
variants
.
(
0
)
.node.args
)
==
1u
;
if
(
newtype
)
{
...
...
@@ -515,12 +515,13 @@ fn print_field(&ps s, &ast::obj_field field) {
end
(
s
);
}
fn
get_span
(
&
ast
::
obj_field
f
)
->
codemap
::
span
{
ret
f
.ty.span
;
}
commasep_cmnt
(
s
,
consistent
,
_
obj
.fields
,
print_field
,
get_span
);
commasep_cmnt_ivec
(
s
,
consistent
,
_
obj
.fields
,
print_field
,
get_span
);
pclose
(
s
);
space
(
s
.s
);
bopen
(
s
);
for
(
@
ast
::
method
meth
in
_
obj
.methods
)
{
let
vec
[
ast
::
ty_param
]
typarams
=
[];
let
ast
::
ty_param
[]
typarams
=
~
[];
hardbreak_if_not_bol
(
s
);
maybe_print_comment
(
s
,
meth
.span.lo
);
print_fn
(
s
,
meth
.node.meth.decl
,
meth
.node.meth.proto
,
...
...
@@ -687,7 +688,7 @@ fn printElt(&ps s, &ast::elt elt) {
fn
get_span
(
&
ast
::
elt
elt
)
->
codemap
::
span
{
ret
elt
.expr.span
;
}
word
(
s
.s
,
"tup"
);
popen
(
s
);
commasep_cmnt
(
s
,
inconsistent
,
exprs
,
printElt
,
get_span
);
commasep_cmnt
_ivec
(
s
,
inconsistent
,
exprs
,
printElt
,
get_span
);
pclose
(
s
);
}
case
(
ast
::
expr_rec
(
?
fields
,
?
wth
))
{
...
...
@@ -704,10 +705,10 @@ fn get_span(&ast::field field) -> codemap::span {
}
word
(
s
.s
,
"rec"
);
popen
(
s
);
commasep_cmnt
(
s
,
consistent
,
fields
,
print_field
,
get_span
);
commasep_cmnt
_ivec
(
s
,
consistent
,
fields
,
print_field
,
get_span
);
alt
(
wth
)
{
case
(
some
(
?
expr
))
{
if
(
vec
::
len
(
fields
)
>
0u
)
{
space
(
s
.s
);
}
if
(
i
vec
::
len
(
fields
)
>
0u
)
{
space
(
s
.s
);
}
ibox
(
s
,
indent_unit
);
word_space
(
s
,
"with"
);
print_expr
(
s
,
expr
);
...
...
@@ -737,7 +738,7 @@ fn print_opt(&ps s, &option::t[@ast::expr] expr) {
word_nbsp
(
s
,
"bind"
);
print_expr
(
s
,
func
);
popen
(
s
);
commasep
(
s
,
inconsistent
,
args
,
print_opt
);
commasep
_ivec
(
s
,
inconsistent
,
args
,
print_opt
);
pclose
(
s
);
}
case
(
ast
::
expr_spawn
(
_
,
_
,
?
e
,
?
es
))
{
...
...
@@ -959,7 +960,7 @@ fn print_opt(&ps s, &option::t[@ast::expr] expr) {
case
(
ast
::
expr_ext
(
?
path
,
?
args
,
?
body
,
_
))
{
word
(
s
.s
,
"#"
);
print_path
(
s
,
path
);
if
(
vec
::
len
(
args
)
>
0u
)
{
if
(
i
vec
::
len
(
args
)
>
0u
)
{
popen
(
s
);
commasep_exprs
(
s
,
inconsistent
,
args
);
pclose
(
s
);
...
...
@@ -1062,9 +1063,9 @@ fn print_pat(&ps s, &@ast::pat pat) {
case
(
ast
::
pat_lit
(
?
lit
))
{
print_literal
(
s
,
lit
);
}
case
(
ast
::
pat_tag
(
?
path
,
?
args
))
{
print_path
(
s
,
path
);
if
(
vec
::
len
(
args
)
>
0u
)
{
if
(
i
vec
::
len
(
args
)
>
0u
)
{
popen
(
s
);
commasep
(
s
,
inconsistent
,
args
,
print_pat
);
commasep
_ivec
(
s
,
inconsistent
,
args
,
print_pat
);
pclose
(
s
);
}
}
...
...
@@ -1073,7 +1074,7 @@ fn print_pat(&ps s, &@ast::pat pat) {
}
fn
print_fn
(
&
ps
s
,
ast
::
fn_decl
decl
,
ast
::
proto
proto
,
str
name
,
vec
[
ast
::
ty_param
]
typarams
)
{
&
ast
::
ty_param
[
]
typarams
)
{
alt
(
decl
.purity
)
{
case
(
ast
::
impure_fn
)
{
if
(
proto
==
ast
::
proto_iter
)
{
...
...
@@ -1097,7 +1098,7 @@ fn print_arg(&ps s, &ast::arg x) {
word
(
s
.s
,
x
.ident
);
end
(
s
);
}
commasep
(
s
,
inconsistent
,
decl
.inputs
,
print_arg
);
commasep
_ivec
(
s
,
inconsistent
,
decl
.inputs
,
print_arg
);
pclose
(
s
);
maybe_print_comment
(
s
,
decl
.output.span.lo
);
if
(
decl
.output.node
!=
ast
::
ty_nil
)
{
...
...
@@ -1115,11 +1116,11 @@ fn print_alias(&ps s, ast::mode m) {
}
}
fn
print_type_params
(
&
ps
s
,
&
vec
[
ast
::
ty_param
]
params
)
{
if
(
vec
::
len
(
params
)
>
0u
)
{
fn
print_type_params
(
&
ps
s
,
&
ast
::
ty_param
[
]
params
)
{
if
(
i
vec
::
len
(
params
)
>
0u
)
{
word
(
s
.s
,
"["
);
fn
printParam
(
&
ps
s
,
&
ast
::
ty_param
param
)
{
word
(
s
.s
,
param
);
}
commasep
(
s
,
inconsistent
,
params
,
printParam
);
commasep
_ivec
(
s
,
inconsistent
,
params
,
printParam
);
word
(
s
.s
,
"]"
);
}
}
...
...
src/comp/syntax/visit.rs
浏览文件 @
0e2fff53
...
...
@@ -33,7 +33,7 @@
fn
(
&@
expr
,
&
E
,
&
vt
[
E
])
visit_expr
,
fn
(
&@
ty
,
&
E
,
&
vt
[
E
])
visit_ty
,
fn
(
&@
constr
,
&
E
,
&
vt
[
E
])
visit_constr
,
fn
(
&
_
fn
,
&
vec
[
ty_param
],
&
span
,
&
fn_ident
,
node_id
,
&
E
,
&
vt
[
E
])
fn
(
&
_
fn
,
&
ty_param
[
],
&
span
,
&
fn_ident
,
node_id
,
&
E
,
&
vt
[
E
])
visit_fn
);
fn
default_visitor
[
E
]()
->
visitor
[
E
]
{
...
...
@@ -121,13 +121,13 @@ fn visit_item[E](&@item i, &E e, &vt[E] v) {
case
(
item_obj
(
?
ob
,
_
,
_
))
{
for
(
obj_field
f
in
ob
.fields
)
{
vt
(
v
)
.visit_ty
(
f
.ty
,
e
,
v
);
}
for
(
@
method
m
in
ob
.methods
)
{
vt
(
v
)
.visit_fn
(
m
.node.meth
,
[],
m
.span
,
some
(
m
.node.ident
),
vt
(
v
)
.visit_fn
(
m
.node.meth
,
~
[],
m
.span
,
some
(
m
.node.ident
),
m
.node.id
,
e
,
v
);
}
alt
(
ob
.dtor
)
{
case
(
none
)
{
}
case
(
some
(
?
m
))
{
vt
(
v
)
.visit_fn
(
m
.node.meth
,
[],
m
.span
,
vt
(
v
)
.visit_fn
(
m
.node.meth
,
~
[],
m
.span
,
some
(
m
.node.ident
),
m
.node.id
,
e
,
v
);
}
...
...
@@ -210,7 +210,7 @@ fn visit_fn_decl[E](&fn_decl fd, &E e, &vt[E] v) {
vt
(
v
)
.visit_ty
(
fd
.output
,
e
,
v
);
}
fn
visit_fn
[
E
](
&
_
fn
f
,
&
vec
[
ty_param
]
tp
,
&
span
sp
,
&
fn_ident
i
,
fn
visit_fn
[
E
](
&
_
fn
f
,
&
ty_param
[
]
tp
,
&
span
sp
,
&
fn_ident
i
,
node_id
id
,
&
E
e
,
&
vt
[
E
]
v
)
{
visit_fn_decl
(
f
.decl
,
e
,
v
);
vt
(
v
)
.visit_block
(
f
.body
,
e
,
v
);
...
...
@@ -245,7 +245,7 @@ fn visit_expr_opt[E](option::t[@expr] eo, &E e, &vt[E] v) {
}
}
fn
visit_exprs
[
E
](
vec
[
@
expr
]
exprs
,
&
E
e
,
&
vt
[
E
]
v
)
{
fn
visit_exprs
[
E
](
&
(
@
expr
)[
]
exprs
,
&
E
e
,
&
vt
[
E
]
v
)
{
for
(
@
expr
ex
in
exprs
)
{
vt
(
v
)
.visit_expr
(
ex
,
e
,
v
);
}
}
...
...
@@ -320,7 +320,7 @@ fn visit_expr[E](&@expr ex, &E e, &vt[E] v) {
for
(
arm
a
in
arms
)
{
vt
(
v
)
.visit_arm
(
a
,
e
,
v
);
}
}
case
(
expr_fn
(
?
f
))
{
vt
(
v
)
.visit_fn
(
f
,
[],
ex
.span
,
none
,
ex
.id
,
e
,
v
);
vt
(
v
)
.visit_fn
(
f
,
~
[],
ex
.span
,
none
,
ex
.id
,
e
,
v
);
}
case
(
expr_block
(
?
b
))
{
vt
(
v
)
.visit_block
(
b
,
e
,
v
);
}
case
(
expr_assign
(
?
a
,
?
b
))
{
...
...
@@ -386,7 +386,7 @@ fn visit_expr[E](&@expr ex, &E e, &vt[E] v) {
case
(
some
(
?
ex
))
{
vt
(
v
)
.visit_expr
(
ex
,
e
,
v
);
}
}
for
(
@
method
m
in
anon_obj
.methods
)
{
vt
(
v
)
.visit_fn
(
m
.node.meth
,
[],
m
.span
,
some
(
m
.node.ident
),
vt
(
v
)
.visit_fn
(
m
.node.meth
,
~
[],
m
.span
,
some
(
m
.node.ident
),
m
.node.id
,
e
,
v
);
}
}
...
...
src/comp/syntax/walk.rs
浏览文件 @
0e2fff53
...
...
@@ -39,9 +39,9 @@
fn
(
&@
ast
::
ty
)
visit_ty_pre
,
fn
(
&@
ast
::
ty
)
visit_ty_post
,
fn
(
&@
ast
::
constr
)
visit_constr
,
fn
(
&
ast
::
_
fn
,
&
vec
[
ast
::
ty_param
],
&
span
,
&
ast
::
fn_ident
,
fn
(
&
ast
::
_
fn
,
&
ast
::
ty_param
[
],
&
span
,
&
ast
::
fn_ident
,
ast
::
node_id
)
visit_fn_pre
,
fn
(
&
ast
::
_
fn
,
&
vec
[
ast
::
ty_param
],
&
span
,
&
ast
::
fn_ident
,
fn
(
&
ast
::
_
fn
,
&
ast
::
ty_param
[
],
&
span
,
&
ast
::
fn_ident
,
ast
::
node_id
)
visit_fn_post
);
fn
walk_crate
(
&
ast_visitor
v
,
&
ast
::
crate
c
)
{
...
...
@@ -117,14 +117,14 @@ fn walk_item(&ast_visitor v, @ast::item i) {
for
(
@
ast
::
method
m
in
ob
.methods
)
{
v
.visit_method_pre
(
m
);
// Methods don't have ty params?
walk_fn
(
v
,
m
.node.meth
,
[],
m
.span
,
walk_fn
(
v
,
m
.node.meth
,
~
[],
m
.span
,
some
(
m
.node.ident
),
m
.node.id
);
v
.visit_method_post
(
m
);
}
alt
(
ob
.dtor
)
{
case
(
none
)
{
}
case
(
some
(
?
m
))
{
walk_fn
(
v
,
m
.node.meth
,
[],
m
.span
,
walk_fn
(
v
,
m
.node.meth
,
~
[],
m
.span
,
some
(
m
.node.ident
),
m
.node.id
);
}
}
...
...
@@ -218,7 +218,7 @@ fn walk_fn_decl(&ast_visitor v, &ast::fn_decl fd) {
walk_ty
(
v
,
fd
.output
);
}
fn
walk_fn
(
&
ast_visitor
v
,
&
ast
::
_
fn
f
,
&
vec
[
ast
::
ty_param
]
tps
,
fn
walk_fn
(
&
ast_visitor
v
,
&
ast
::
_
fn
f
,
&
ast
::
ty_param
[
]
tps
,
&
span
sp
,
&
ast
::
fn_ident
i
,
ast
::
node_id
d
)
{
if
(
!
v
.keep_going
())
{
ret
;
}
v
.visit_fn_pre
(
f
,
tps
,
sp
,
i
,
d
);
...
...
@@ -262,7 +262,7 @@ fn walk_expr_opt(&ast_visitor v, option::t[@ast::expr] eo) {
alt
(
eo
)
{
case
(
none
)
{
}
case
(
some
(
?
e
))
{
walk_expr
(
v
,
e
);
}
}
}
fn
walk_exprs
(
&
ast_visitor
v
,
vec
[
@
ast
::
expr
]
exprs
)
{
fn
walk_exprs
(
&
ast_visitor
v
,
&
(
@
ast
::
expr
)[
]
exprs
)
{
for
(
@
ast
::
expr
e
in
exprs
)
{
walk_expr
(
v
,
e
);
}
}
...
...
@@ -341,7 +341,7 @@ fn walk_expr(&ast_visitor v, @ast::expr e) {
}
}
case
(
ast
::
expr_fn
(
?
f
))
{
walk_fn
(
v
,
f
,
[],
e
.span
,
none
,
e
.id
);
walk_fn
(
v
,
f
,
~
[],
e
.span
,
none
,
e
.id
);
}
case
(
ast
::
expr_block
(
?
b
))
{
walk_block
(
v
,
b
);
}
case
(
ast
::
expr_assign
(
?
a
,
?
b
))
{
...
...
@@ -402,7 +402,7 @@ fn walk_expr(&ast_visitor v, @ast::expr e) {
// Methods
for
(
@
ast
::
method
m
in
anon_obj
.methods
)
{
v
.visit_method_pre
(
m
);
walk_fn
(
v
,
m
.node.meth
,
[],
m
.span
,
some
(
m
.node.ident
),
walk_fn
(
v
,
m
.node.meth
,
~
[],
m
.span
,
some
(
m
.node.ident
),
m
.node.id
);
v
.visit_method_post
(
m
);
}
...
...
@@ -445,7 +445,7 @@ fn def_visit_ty(&@ast::ty t) { }
fn
def_visit_constr
(
&@
ast
::
constr
c
)
{
}
fn
def_visit_fn
(
&
ast
::
_
fn
f
,
&
vec
[
ast
::
ty_param
]
tps
,
fn
def_visit_fn
(
&
ast
::
_
fn
f
,
&
ast
::
ty_param
[
]
tps
,
&
span
sp
,
&
ast
::
fn_ident
i
,
ast
::
node_id
d
)
{
}
fn
default_visitor
()
->
ast_visitor
{
...
...
src/comp/util/common.rs
浏览文件 @
0e2fff53
...
...
@@ -50,16 +50,18 @@ fn new_def_hash[V]() -> std::map::hashmap[ast::def_id, V] {
fn
elt_expr
(
&
ast
::
elt
e
)
->
@
ast
::
expr
{
ret
e
.expr
;
}
fn
elt_exprs
(
&
vec
[
ast
::
elt
]
elts
)
->
vec
[
@
ast
::
expr
]
{
auto
f
=
elt_expr
;
ret
vec
::
map
[
ast
::
elt
,
@
ast
::
expr
](
f
,
elts
);
fn
elt_exprs
(
&
ast
::
elt
[]
elts
)
->
(
@
ast
::
expr
)[]
{
auto
es
=
~
[];
for
(
ast
::
elt
e
in
elts
)
{
es
+=
~
[
e
.expr
];
}
ret
es
;
}
fn
field_expr
(
&
ast
::
field
f
)
->
@
ast
::
expr
{
ret
f
.node.expr
;
}
fn
field_exprs
(
vec
[
ast
::
field
]
fields
)
->
vec
[
@
ast
::
expr
]
{
auto
f
=
field_expr
;
ret
vec
::
map
[
ast
::
field
,
@
ast
::
expr
](
f
,
fields
);
fn
field_exprs
(
&
ast
::
field
[]
fields
)
->
(
@
ast
::
expr
)[]
{
auto
es
=
~
[];
for
(
ast
::
field
f
in
fields
)
{
es
+=
~
[
f
.node.expr
];
}
ret
es
;
}
fn
log_expr
(
&
ast
::
expr
e
)
{
log
print
::
pprust
::
expr_to_str
(
@
e
);
}
...
...
@@ -76,11 +78,11 @@ fn field_exprs(vec[ast::field] fields) -> vec[@ast::expr] {
fn
log_item_err
(
&@
ast
::
item
i
)
{
log_err
print
::
pprust
::
item_to_str
(
i
);
}
fn
log_fn
(
&
ast
::
_
fn
f
,
str
name
,
vec
[
ast
::
ty_param
]
params
)
{
fn
log_fn
(
&
ast
::
_
fn
f
,
str
name
,
&
ast
::
ty_param
[
]
params
)
{
log
print
::
pprust
::
fun_to_str
(
f
,
name
,
params
);
}
fn
log_fn_err
(
&
ast
::
_
fn
f
,
str
name
,
vec
[
ast
::
ty_param
]
params
)
{
fn
log_fn_err
(
&
ast
::
_
fn
f
,
str
name
,
&
ast
::
ty_param
[
]
params
)
{
log_err
print
::
pprust
::
fun_to_str
(
f
,
name
,
params
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录