Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
76aabbe9
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,发现更多精彩内容 >>
提交
76aabbe9
编写于
1月 25, 2012
作者:
M
Marijn Haverbeke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename tag to enum throughout the compiler
This should reduce confusion of people trying to read the code.
上级
8420f8c5
变更
27
隐藏空白更改
内联
并排
Showing
27 changed file
with
314 addition
and
329 deletion
+314
-329
src/comp/metadata/common.rs
src/comp/metadata/common.rs
+1
-1
src/comp/metadata/csearch.rs
src/comp/metadata/csearch.rs
+3
-3
src/comp/metadata/decoder.rs
src/comp/metadata/decoder.rs
+8
-8
src/comp/metadata/encoder.rs
src/comp/metadata/encoder.rs
+10
-10
src/comp/metadata/tydecode.rs
src/comp/metadata/tydecode.rs
+1
-1
src/comp/metadata/tyencode.rs
src/comp/metadata/tyencode.rs
+1
-1
src/comp/middle/alias.rs
src/comp/middle/alias.rs
+3
-3
src/comp/middle/check_alt.rs
src/comp/middle/check_alt.rs
+4
-4
src/comp/middle/check_const.rs
src/comp/middle/check_const.rs
+1
-1
src/comp/middle/gc.rs
src/comp/middle/gc.rs
+2
-17
src/comp/middle/mut.rs
src/comp/middle/mut.rs
+3
-3
src/comp/middle/pat_util.rs
src/comp/middle/pat_util.rs
+5
-5
src/comp/middle/resolve.rs
src/comp/middle/resolve.rs
+31
-30
src/comp/middle/shape.rs
src/comp/middle/shape.rs
+37
-36
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+62
-65
src/comp/middle/trans_alt.rs
src/comp/middle/trans_alt.rs
+18
-18
src/comp/middle/trans_common.rs
src/comp/middle/trans_common.rs
+13
-13
src/comp/middle/tstate/pre_post_conditions.rs
src/comp/middle/tstate/pre_post_conditions.rs
+1
-1
src/comp/middle/ty.rs
src/comp/middle/ty.rs
+45
-45
src/comp/middle/typeck.rs
src/comp/middle/typeck.rs
+21
-21
src/comp/syntax/ast.rs
src/comp/syntax/ast.rs
+6
-6
src/comp/syntax/ast_util.rs
src/comp/syntax/ast_util.rs
+12
-11
src/comp/syntax/fold.rs
src/comp/syntax/fold.rs
+4
-4
src/comp/syntax/parse/parser.rs
src/comp/syntax/parse/parser.rs
+15
-15
src/comp/syntax/print/pprust.rs
src/comp/syntax/print/pprust.rs
+4
-4
src/comp/syntax/visit.rs
src/comp/syntax/visit.rs
+2
-2
src/comp/util/ppaux.rs
src/comp/util/ppaux.rs
+1
-1
未找到文件。
src/comp/metadata/common.rs
浏览文件 @
76aabbe9
...
...
@@ -30,7 +30,7 @@
const
tag_items_data_item_variant
:
uint
=
0x0eu
;
const
tag_items_data_item_
tag
_id
:
uint
=
0x0fu
;
const
tag_items_data_item_
enum
_id
:
uint
=
0x0fu
;
const
tag_index
:
uint
=
0x11u
;
...
...
src/comp/metadata/csearch.rs
浏览文件 @
76aabbe9
...
...
@@ -9,7 +9,7 @@
export
get_symbol
;
export
get_type_param_count
;
export
lookup_defs
;
export
get_
tag
_variants
;
export
get_
enum
_variants
;
export
get_impls_for_mod
;
export
get_iface_methods
;
export
get_type
;
...
...
@@ -56,10 +56,10 @@ fn resolve_path(cstore: cstore::cstore, cnum: ast::crate_num,
ret
result
;
}
fn
get_
tag
_variants
(
tcx
:
ty
::
ctxt
,
def
:
ast
::
def_id
)
->
[
ty
::
variant_info
]
{
fn
get_
enum
_variants
(
tcx
:
ty
::
ctxt
,
def
:
ast
::
def_id
)
->
[
ty
::
variant_info
]
{
let
cstore
=
tcx
.sess.cstore
;
let
cdata
=
cstore
::
get_crate_data
(
cstore
,
def
.crate
);
ret
decoder
::
get_
tag
_variants
(
cdata
,
def
.node
,
tcx
)
ret
decoder
::
get_
enum
_variants
(
cdata
,
def
.node
,
tcx
)
}
fn
get_impls_for_mod
(
cstore
:
cstore
::
cstore
,
def
:
ast
::
def_id
,
...
...
src/comp/metadata/decoder.rs
浏览文件 @
76aabbe9
...
...
@@ -11,7 +11,7 @@
import
cmd
=
cstore
::
crate_metadata
;
export
get_symbol
;
export
get_
tag
_variants
;
export
get_
enum
_variants
;
export
get_type
;
export
get_type_param_count
;
export
get_impl_iface
;
...
...
@@ -86,8 +86,8 @@ fn item_symbol(item: ebml::doc) -> str {
ret
str
::
unsafe_from_bytes
(
ebml
::
doc_data
(
sym
));
}
fn
variant_
tag
_id
(
d
:
ebml
::
doc
)
->
ast
::
def_id
{
let
tagdoc
=
ebml
::
get_doc
(
d
,
tag_items_data_item_
tag
_id
);
fn
variant_
enum
_id
(
d
:
ebml
::
doc
)
->
ast
::
def_id
{
let
tagdoc
=
ebml
::
get_doc
(
d
,
tag_items_data_item_
enum
_id
);
ret
parse_def_id
(
ebml
::
doc_data
(
tagdoc
));
}
...
...
@@ -147,7 +147,7 @@ fn item_ty_param_count(item: ebml::doc) -> uint {
n
}
fn
tag
_variant_ids
(
item
:
ebml
::
doc
,
cdata
:
cmd
)
->
[
ast
::
def_id
]
{
fn
enum
_variant_ids
(
item
:
ebml
::
doc
,
cdata
:
cmd
)
->
[
ast
::
def_id
]
{
let
ids
:
[
ast
::
def_id
]
=
[];
let
v
=
tag_items_data_item_variant
;
ebml
::
tagged_docs
(
item
,
v
)
{|
p
|
...
...
@@ -189,7 +189,7 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
let
item
=
lookup_item
(
did_
.node
,
data
);
let
fam_ch
=
item_family
(
item
);
let
did
=
{
crate
:
cnum
,
node
:
did_
.node
};
// We treat references to
tag
s as references to types.
// We treat references to
enum
s as references to types.
let
def
=
alt
fam_ch
as
char
{
'c'
{
ast
::
def_const
(
did
)
}
...
...
@@ -205,7 +205,7 @@ fn lookup_def(cnum: ast::crate_num, data: @[u8], did_: ast::def_id) ->
'm'
{
ast
::
def_mod
(
did
)
}
'n'
{
ast
::
def_native_mod
(
did
)
}
'v'
{
let
tid
=
variant_
tag
_id
(
item
);
let
tid
=
variant_
enum
_id
(
item
);
tid
=
{
crate
:
cnum
,
node
:
tid
.node
};
ast
::
def_variant
(
tid
,
did
)
}
...
...
@@ -237,13 +237,13 @@ fn get_symbol(data: @[u8], id: ast::node_id) -> str {
ret
item_symbol
(
lookup_item
(
id
,
data
));
}
fn
get_
tag
_variants
(
cdata
:
cmd
,
id
:
ast
::
node_id
,
tcx
:
ty
::
ctxt
)
fn
get_
enum
_variants
(
cdata
:
cmd
,
id
:
ast
::
node_id
,
tcx
:
ty
::
ctxt
)
->
[
ty
::
variant_info
]
{
let
data
=
cdata
.data
;
let
items
=
ebml
::
get_doc
(
ebml
::
new_doc
(
data
),
tag_items
);
let
item
=
find_item
(
id
,
items
);
let
infos
:
[
ty
::
variant_info
]
=
[];
let
variant_ids
=
tag
_variant_ids
(
item
,
cdata
);
let
variant_ids
=
enum
_variant_ids
(
item
,
cdata
);
let
disr_val
=
0
;
for
did
:
ast
::
def_id
in
variant_ids
{
let
item
=
find_item
(
did
.node
,
items
);
...
...
src/comp/metadata/encoder.rs
浏览文件 @
76aabbe9
...
...
@@ -33,7 +33,7 @@ fn encode_def_id(ebml_w: ebml::writer, id: def_id) {
type
entry
<
T
>
=
{
val
:
T
,
pos
:
uint
};
fn
encode_
tag
_variant_paths
(
ebml_w
:
ebml
::
writer
,
variants
:
[
variant
],
fn
encode_
enum
_variant_paths
(
ebml_w
:
ebml
::
writer
,
variants
:
[
variant
],
path
:
[
str
],
&
index
:
[
entry
<
str
>
])
{
for
variant
:
variant
in
variants
{
add_to_index
(
ebml_w
,
path
,
index
,
variant
.node.name
);
...
...
@@ -118,13 +118,13 @@ fn encode_module_item_paths(ebml_w: ebml::writer, module: _mod, path: [str],
encode_def_id
(
ebml_w
,
local_def
(
it
.id
));
ebml
::
end_tag
(
ebml_w
);
}
item_
tag
(
variants
,
tps
)
{
item_
enum
(
variants
,
tps
)
{
add_to_index
(
ebml_w
,
path
,
index
,
it
.ident
);
ebml
::
start_tag
(
ebml_w
,
tag_paths_data_item
);
encode_name
(
ebml_w
,
it
.ident
);
encode_def_id
(
ebml_w
,
local_def
(
it
.id
));
ebml
::
end_tag
(
ebml_w
);
encode_
tag
_variant_paths
(
ebml_w
,
variants
,
path
,
index
);
encode_
enum
_variant_paths
(
ebml_w
,
variants
,
path
,
index
);
}
item_iface
(
_
,
_
)
{
add_to_index
(
ebml_w
,
path
,
index
,
it
.ident
);
...
...
@@ -222,25 +222,25 @@ fn encode_disr_val(_ecx: @encode_ctxt, ebml_w: ebml::writer, disr_val: int) {
ebml
::
end_tag
(
ebml_w
);
}
fn
encode_
tag
_id
(
ebml_w
:
ebml
::
writer
,
id
:
def_id
)
{
ebml
::
start_tag
(
ebml_w
,
tag_items_data_item_
tag
_id
);
fn
encode_
enum
_id
(
ebml_w
:
ebml
::
writer
,
id
:
def_id
)
{
ebml
::
start_tag
(
ebml_w
,
tag_items_data_item_
enum
_id
);
ebml_w
.writer
.write
(
str
::
bytes
(
def_to_str
(
id
)));
ebml
::
end_tag
(
ebml_w
);
}
fn
encode_
tag
_variant_info
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
writer
,
fn
encode_
enum
_variant_info
(
ecx
:
@
encode_ctxt
,
ebml_w
:
ebml
::
writer
,
id
:
node_id
,
variants
:
[
variant
],
&
index
:
[
entry
<
int
>
],
ty_params
:
[
ty_param
])
{
let
disr_val
=
0
;
let
i
=
0
;
let
vi
=
ty
::
tag
_variants
(
ecx
.ccx.tcx
,
{
crate
:
local_crate
,
node
:
id
});
let
vi
=
ty
::
enum
_variants
(
ecx
.ccx.tcx
,
{
crate
:
local_crate
,
node
:
id
});
for
variant
:
variant
in
variants
{
index
+=
[{
val
:
variant
.node.id
,
pos
:
ebml_w
.writer
.tell
()}];
ebml
::
start_tag
(
ebml_w
,
tag_items_data_item
);
encode_def_id
(
ebml_w
,
local_def
(
variant
.node.id
));
encode_family
(
ebml_w
,
'v'
as
u8
);
encode_name
(
ebml_w
,
variant
.node.name
);
encode_
tag
_id
(
ebml_w
,
local_def
(
id
));
encode_
enum
_id
(
ebml_w
,
local_def
(
id
));
encode_type
(
ecx
,
ebml_w
,
node_id_to_monotype
(
ecx
.ccx.tcx
,
variant
.node.id
));
if
vec
::
len
::
<
variant_arg
>
(
variant
.node.args
)
>
0u
{
...
...
@@ -324,7 +324,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
encode_name
(
ebml_w
,
item
.ident
);
ebml
::
end_tag
(
ebml_w
);
}
item_
tag
(
variants
,
tps
)
{
item_
enum
(
variants
,
tps
)
{
ebml
::
start_tag
(
ebml_w
,
tag_items_data_item
);
encode_def_id
(
ebml_w
,
local_def
(
item
.id
));
encode_family
(
ebml_w
,
't'
as
u8
);
...
...
@@ -335,7 +335,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
encode_variant_id
(
ebml_w
,
local_def
(
v
.node.id
));
}
ebml
::
end_tag
(
ebml_w
);
encode_
tag
_variant_info
(
ecx
,
ebml_w
,
item
.id
,
variants
,
index
,
tps
);
encode_
enum
_variant_info
(
ecx
,
ebml_w
,
item
.id
,
variants
,
index
,
tps
);
}
item_res
(
_
,
tps
,
_
,
_
,
ctor_id
)
{
let
fn_ty
=
node_id_to_monotype
(
tcx
,
ctor_id
);
...
...
src/comp/metadata/tydecode.rs
浏览文件 @
76aabbe9
...
...
@@ -202,7 +202,7 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
let
params
:
[
ty
::
t
]
=
[];
while
peek
(
st
)
as
char
!=
']'
{
params
+=
[
parse_ty
(
st
,
conv
)];
}
st
.pos
=
st
.pos
+
1u
;
ret
ty
::
mk_
tag
(
st
.tcx
,
def
,
params
);
ret
ty
::
mk_
enum
(
st
.tcx
,
def
,
params
);
}
'x'
{
assert
(
next
(
st
)
as
char
==
'['
);
...
...
src/comp/metadata/tyencode.rs
浏览文件 @
76aabbe9
...
...
@@ -117,7 +117,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
}
}
ty
::
ty_str
{
w
.write_char
(
'S'
);
}
ty
::
ty_
tag
(
def
,
tys
)
{
ty
::
ty_
enum
(
def
,
tys
)
{
w
.write_str
(
"t["
);
w
.write_str
(
cx
.ds
(
def
));
w
.write_char
(
'|'
);
...
...
src/comp/middle/alias.rs
浏览文件 @
76aabbe9
...
...
@@ -502,7 +502,7 @@ fn helper(tcx: ty::ctxt, needle: unsafe_ty, haystack: ty::t, mut: bool)
mut_contains
(
ty
)
{
mut
&&
ty
==
haystack
}
}
{
ret
true
;
}
alt
ty
::
struct
(
tcx
,
haystack
)
{
ty
::
ty_
tag
(
_
,
ts
)
{
ty
::
ty_
enum
(
_
,
ts
)
{
for
t
:
ty
::
t
in
ts
{
if
helper
(
tcx
,
needle
,
t
,
mut
)
{
ret
true
;
}
}
...
...
@@ -565,7 +565,7 @@ fn score_ty(tcx: ty::ctxt, ty: ty::t) -> uint {
ty
::
ty_fn
(
_
)
|
ty
::
ty_native_fn
(
_
,
_
)
{
4u
}
ty
::
ty_str
|
ty
::
ty_vec
(
_
)
|
ty
::
ty_param
(
_
,
_
)
{
50u
}
ty
::
ty_uniq
(
mt
)
{
1u
+
score_ty
(
tcx
,
mt
.ty
)
}
ty
::
ty_
tag
(
_
,
ts
)
|
ty
::
ty_tup
(
ts
)
{
ty
::
ty_
enum
(
_
,
ts
)
|
ty
::
ty_tup
(
ts
)
{
let
sum
=
0u
;
for
t
in
ts
{
sum
+=
score_ty
(
tcx
,
t
);
}
sum
...
...
@@ -596,7 +596,7 @@ fn walk(tcx: ty::ctxt, mut: option::t<unsafe_ty>, pat: @ast::pat,
span
:
pat
.span
}];
alt
sub
{
some
(
p
)
{
walk
(
tcx
,
mut
,
p
,
set
);
}
_
{}
}
}
ast
::
pat_
tag
(
_
,
ps
)
|
ast
::
pat_tup
(
ps
)
{
ast
::
pat_
enum
(
_
,
ps
)
|
ast
::
pat_tup
(
ps
)
{
for
p
in
ps
{
walk
(
tcx
,
mut
,
p
,
set
);
}
}
ast
::
pat_rec
(
fs
,
_
)
{
...
...
src/comp/middle/check_alt.rs
浏览文件 @
76aabbe9
...
...
@@ -80,9 +80,9 @@ fn field_patterns_supersede(tcx: ty::ctxt, fas: [field_pat],
_
{
false
}
}
}
pat_
tag
(
va
,
suba
)
{
pat_
enum
(
va
,
suba
)
{
alt
b
.node
{
pat_
tag
(
vb
,
subb
)
{
pat_
enum
(
vb
,
subb
)
{
tcx
.def_map
.get
(
a
.id
)
==
tcx
.def_map
.get
(
b
.id
)
&&
patterns_supersede
(
tcx
,
suba
,
subb
)
}
...
...
@@ -154,9 +154,9 @@ fn is_refutable(tcx: ty::ctxt, pat: @pat) -> bool {
for
elt
in
elts
{
if
is_refutable
(
tcx
,
elt
)
{
ret
true
;
}
}
false
}
pat_
tag
(
_
,
args
)
{
pat_
enum
(
_
,
args
)
{
let
vdef
=
variant_def_ids
(
tcx
.def_map
.get
(
pat
.id
));
if
vec
::
len
(
*
ty
::
tag
_variants
(
tcx
,
vdef
.tg
))
!=
1u
{
ret
true
;
}
if
vec
::
len
(
*
ty
::
enum
_variants
(
tcx
,
vdef
.tg
))
!=
1u
{
ret
true
;
}
for
p
:
@
pat
in
args
{
if
is_refutable
(
tcx
,
p
)
{
ret
true
;
}
}
false
}
...
...
src/comp/middle/check_const.rs
浏览文件 @
76aabbe9
...
...
@@ -15,7 +15,7 @@ fn check_crate(sess: session, crate: @crate) {
fn
check_item
(
it
:
@
item
,
&&
_
is_const
:
bool
,
v
:
visit
::
vt
<
bool
>
)
{
alt
it
.node
{
item_const
(
_
,
ex
)
{
v
.visit_expr
(
ex
,
true
,
v
);
}
item_
tag
(
vs
,
_
)
{
item_
enum
(
vs
,
_
)
{
for
var
in
vs
{
option
::
may
(
var
.node.disr_expr
)
{|
ex
|
v
.visit_expr
(
ex
,
true
,
v
);
...
...
src/comp/middle/gc.rs
浏览文件 @
76aabbe9
...
...
@@ -108,11 +108,6 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
ty
::
ty_type
|
ty
::
ty_ptr
(
_
)
|
ty
::
ty_native
(
_
)
{
ret
false
;
}
ty
::
ty_rec
(
fields
)
{
for
f
in
fields
{
if
type_is_gc_relevant
(
cx
,
f
.mt.ty
)
{
ret
true
;
}
}
ret
false
;
...
...
@@ -121,13 +116,8 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
for
elt
in
elts
{
if
type_is_gc_relevant
(
cx
,
elt
)
{
ret
true
;
}
}
ret
false
;
}
ty
::
ty_tag
(
did
,
tps
)
{
let
variants
=
ty
::
tag_variants
(
cx
,
did
);
ty
::
ty_enum
(
did
,
tps
)
{
let
variants
=
ty
::
enum_variants
(
cx
,
did
);
for
variant
in
*
variants
{
for
aty
in
variant
.args
{
let
arg_ty
=
ty
::
substitute_type_params
(
cx
,
tps
,
aty
);
...
...
@@ -136,11 +126,6 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
}
ret
false
;
}
ty
::
ty_vec
(
tm
)
{
ret
type_is_gc_relevant
(
cx
,
tm
.ty
);
}
...
...
src/comp/middle/mut.rs
浏览文件 @
76aabbe9
...
...
@@ -31,8 +31,8 @@ fn maybe_auto_unbox(tcx: ty::ctxt, t: ty::t) -> {t: ty::t, ds: [deref]} {
ds
+=
[
@
{
mut
:
false
,
kind
:
unbox
,
outer_t
:
t
}];
t
=
ty
::
substitute_type_params
(
tcx
,
tps
,
inner
);
}
ty
::
ty_
tag
(
did
,
tps
)
{
let
variants
=
ty
::
tag
_variants
(
tcx
,
did
);
ty
::
ty_
enum
(
did
,
tps
)
{
let
variants
=
ty
::
enum
_variants
(
tcx
,
did
);
if
vec
::
len
(
*
variants
)
!=
1u
||
vec
::
len
(
variants
[
0
]
.args
)
!=
1u
{
break
;
...
...
@@ -90,7 +90,7 @@ fn maybe_auto_unbox(tcx: ty::ctxt, t: ty::t) -> {t: ty::t, ds: [deref]} {
ty
::
ty_box
(
mt
)
{
is_mut
=
mt
.mut
==
mut
;
}
ty
::
ty_uniq
(
mt
)
{
is_mut
=
mt
.mut
==
mut
;
}
ty
::
ty_res
(
_
,
_
,
_
)
{
}
ty
::
ty_
tag
(
_
,
_
)
{
}
ty
::
ty_
enum
(
_
,
_
)
{
}
ty
::
ty_ptr
(
mt
)
{
is_mut
=
mt
.mut
==
mut
;
}
}
ds
+=
[
@
{
mut
:
is_mut
,
kind
:
unbox
,
outer_t
:
base_t
}];
...
...
src/comp/middle/pat_util.rs
浏览文件 @
76aabbe9
...
...
@@ -22,8 +22,8 @@ fn normalize_pat_def_map(dm: resolve::def_map, p: @pat) -> @pat {
@
{
node
:
pat_ident
(
q
,
some
(
normalize_pat_def_map
(
dm
,
r
)))
with
*
p
}
}
pat_
tag
(
a_path
,
subs
)
{
@
{
node
:
pat_
tag
(
a_path
,
pat_
enum
(
a_path
,
subs
)
{
@
{
node
:
pat_
enum
(
a_path
,
vec
::
map
(
subs
,
{|
p
|
normalize_pat_def_map
(
dm
,
p
)}))
with
*
p
}
}
pat_rec
(
field_pats
,
b
)
{
...
...
@@ -52,8 +52,8 @@ fn normalize_one(dm: resolve::def_map, p: @pat) -> @pat {
alt
dm
.find
(
p
.id
)
{
some
(
d
)
{
alt
p
.node
{
pat_ident
(
tag
_path
,
_
)
{
@
{
id
:
p
.id
,
node
:
pat_
tag
(
tag
_path
,
[]),
pat_ident
(
enum
_path
,
_
)
{
@
{
id
:
p
.id
,
node
:
pat_
enum
(
enum
_path
,
[]),
span
:
p
.span
}
}
_
{
p
}
}
...
...
@@ -95,7 +95,7 @@ fn pat_bindings(pat: @pat, it: fn(@pat)) {
alt
pat
.node
{
pat_ident
(
_
,
option
::
none
)
{
it
(
pat
);
}
pat_ident
(
_
,
option
::
some
(
sub
))
{
it
(
pat
);
pat_bindings
(
sub
,
it
);
}
pat_
tag
(
_
,
sub
)
{
for
p
in
sub
{
pat_bindings
(
p
,
it
);
}
}
pat_
enum
(
_
,
sub
)
{
for
p
in
sub
{
pat_bindings
(
p
,
it
);
}
}
pat_rec
(
fields
,
_
)
{
for
f
in
fields
{
pat_bindings
(
f
.pat
,
it
);
}
}
pat_tup
(
elts
)
{
for
elt
in
elts
{
pat_bindings
(
elt
,
it
);
}
}
pat_box
(
sub
)
{
pat_bindings
(
sub
,
it
);
}
...
...
src/comp/middle/resolve.rs
浏览文件 @
76aabbe9
...
...
@@ -103,7 +103,7 @@ enum mod_index_entry {
mie_import_ident
(
node_id
,
codemap
::
span
),
mie_item
(
@
ast
::
item
),
mie_native_item
(
@
ast
::
native_item
),
mie_
tag
_variant
(
/* enum item */
@
ast
::
item
,
/* variant index */
uint
),
mie_
enum
_variant
(
/* enum item */
@
ast
::
item
,
/* variant index */
uint
),
}
type
mod_index
=
hashmap
<
ident
,
list
<
mod_index_entry
>>
;
...
...
@@ -119,8 +119,9 @@ enum mod_index_entry {
path
:
str
};
/* native modules can't contain tags, and we don't store their ASTs because we
only need to look at them to determine exports, which they can't control.*/
/* native modules can't contain enums, and we don't store their ASTs because
we only need to look at them to determine exports, which they can't
control.*/
type
def_map
=
hashmap
<
node_id
,
def
>
;
type
ext_map
=
hashmap
<
def_id
,
[
ident
]
>
;
...
...
@@ -158,7 +159,7 @@ enum dir { inside, outside, }
// when looking up a variable name that's not yet in scope to check
// if it's already bound to a enum.
enum
namespace
{
ns_val
(
ns_value_type
),
ns_type
,
ns_module
,
}
enum
ns_value_type
{
ns_a_
tag
,
ns_any_value
,
}
enum
ns_value_type
{
ns_a_
enum
,
ns_any_value
,
}
fn
resolve_crate
(
sess
:
session
,
amap
:
ast_map
::
map
,
crate
:
@
ast
::
crate
)
->
{
def_map
:
def_map
,
exp_map
:
exp_map
,
impl_map
:
impl_map
}
{
...
...
@@ -406,7 +407,7 @@ fn walk_constr(e: @env, p: @ast::path, sp: span, id: node_id, sc: scopes,
fn
walk_pat
(
e
:
@
env
,
pat
:
@
ast
::
pat
,
sc
:
scopes
,
v
:
vt
<
scopes
>
)
{
visit
::
visit_pat
(
pat
,
sc
,
v
);
alt
pat
.node
{
ast
::
pat_
tag
(
p
,
_
)
{
ast
::
pat_
enum
(
p
,
_
)
{
let
fnd
=
lookup_path_strict
(
*
e
,
sc
,
p
.span
,
p
.node
,
ns_val
(
ns_any_value
));
alt
option
::
get
(
fnd
)
{
...
...
@@ -424,7 +425,7 @@ fn walk_pat(e: @env, pat: @ast::pat, sc: scopes, v: vt<scopes>) {
variable a refers to a nullary enum. */
ast
::
pat_ident
(
p
,
none
)
{
let
fnd
=
lookup_in_scope
(
*
e
,
sc
,
p
.span
,
path_to_ident
(
p
),
ns_val
(
ns_a_
tag
));
ns_val
(
ns_a_
enum
));
alt
fnd
{
some
(
ast
::
def_variant
(
did
,
vid
))
{
e
.def_map
.insert
(
pat
.id
,
ast
::
def_variant
(
did
,
vid
));
...
...
@@ -566,11 +567,11 @@ fn visit_local_with_scope(e: @env, loc: @local, sc:scopes, v:vt<scopes>) {
// to enum foo, or is it binding a new name foo?)
alt
loc
.node.pat.node
{
pat_ident
(
an_ident
,
_
)
{
// Be sure to pass ns_a_
tag
to lookup_in_scope so that
// Be sure to pass ns_a_
enum
to lookup_in_scope so that
// if this is a name that's being shadowed, we don't die
alt
lookup_in_scope
(
*
e
,
sc
,
loc
.span
,
path_to_ident
(
an_ident
),
ns_val
(
ns_a_
tag
))
{
some
(
ast
::
def_variant
(
tag
_id
,
variant_id
))
{
path_to_ident
(
an_ident
),
ns_val
(
ns_a_
enum
))
{
some
(
ast
::
def_variant
(
enum
_id
,
variant_id
))
{
// Declaration shadows a enum that's in scope.
// That's an error.
e
.sess
.span_err
(
loc
.span
,
...
...
@@ -742,7 +743,7 @@ fn ns_name(ns: namespace) -> str {
ns_val
(
v
)
{
alt
(
v
)
{
ns_any_value
{
"name"
}
ns_a_
tag
{
"enum"
}
ns_a_
enum
{
"enum"
}
}
}
ns_module
{
ret
"modulename"
}
...
...
@@ -893,7 +894,7 @@ fn in_scope(e: env, sp: span, name: ident, s: scope, ns: namespace) ->
ast
::
item_impl
(
tps
,
_
,
_
,
_
)
{
if
ns
==
ns_type
{
ret
lookup_in_ty_params
(
e
,
name
,
tps
);
}
}
ast
::
item_iface
(
tps
,
_
)
|
ast
::
item_
tag
(
_
,
tps
)
|
ast
::
item_iface
(
tps
,
_
)
|
ast
::
item_
enum
(
_
,
tps
)
|
ast
::
item_ty
(
_
,
tps
)
{
if
ns
==
ns_type
{
ret
lookup_in_ty_params
(
e
,
name
,
tps
);
}
}
...
...
@@ -970,7 +971,7 @@ fn in_scope(e: env, sp: span, name: ident, s: scope, ns: namespace) ->
/* If we were looking for a enum, at this point
we know it's bound to a non-enum value, and
we can return none instead of failing */
ns_a_
tag
{
ret
none
;
}
ns_a_
enum
{
ret
none
;
}
_
{
"attempted dynamic environment-capture"
}
}
}
...
...
@@ -1074,7 +1075,7 @@ fn lookup_in_block(e: env, name: ident, sp: span, b: ast::blk_, pos: uint,
}
ast
::
decl_item
(
it
)
{
alt
it
.node
{
ast
::
item_
tag
(
variants
,
_
)
{
ast
::
item_
enum
(
variants
,
_
)
{
if
ns
==
ns_type
{
if
str
::
eq
(
it
.ident
,
name
)
{
ret
some
(
ast
::
def_ty
(
local_def
(
it
.id
)));
...
...
@@ -1150,7 +1151,7 @@ fn found_def_item(i: @ast::item, ns: namespace) -> option::t<def> {
ast
::
item_native_mod
(
_
)
{
if
ns
==
ns_module
{
ret
some
(
ast
::
def_native_mod
(
local_def
(
i
.id
)));
}
}
ast
::
item_ty
(
_
,
_
)
|
item_iface
(
_
,
_
)
|
item_
tag
(
_
,
_
)
{
ast
::
item_ty
(
_
,
_
)
|
item_iface
(
_
,
_
)
|
item_
enum
(
_
,
_
)
{
if
ns
==
ns_type
{
ret
some
(
ast
::
def_ty
(
local_def
(
i
.id
)));
}
}
ast
::
item_res
(
_
,
_
,
_
,
_
,
ctor_id
)
{
...
...
@@ -1292,7 +1293,7 @@ fn lookup_in_mod_(e: env, def: glob_imp_def, sp: span, name: ident,
if
vec
::
len
(
matches
)
==
0u
{
ret
none
;
}
else
if
vec
::
len
(
matches
)
==
1u
||
ns
==
ns_val
(
ns_a_
tag
)
{
else
if
vec
::
len
(
matches
)
==
1u
||
ns
==
ns_val
(
ns_a_
enum
)
{
ret
some
(
matches
[
0
]
.def
);
}
else
{
for
match
:
glob_imp_def
in
matches
{
...
...
@@ -1312,8 +1313,8 @@ fn lookup_glob_in_mod(e: env, info: @indexed_mod, sp: span, id: ident,
info
.glob_imported_names
.insert
(
id
,
glob_resolving
(
sp
));
let
val
=
lookup_in_globs
(
e
,
info
.glob_imports
,
sp
,
id
,
// kludge
(
if
wanted_ns
==
ns_val
(
ns_a_
tag
)
{
ns_val
(
ns_a_
tag
)
}
(
if
wanted_ns
==
ns_val
(
ns_a_
enum
)
{
ns_val
(
ns_a_
enum
)
}
else
{
ns_val
(
ns_any_value
)
}),
dr
);
let
typ
=
lookup_in_globs
(
e
,
info
.glob_imports
,
sp
,
id
,
ns_type
,
dr
);
let
md
=
lookup_in_globs
(
e
,
info
.glob_imports
,
sp
,
id
,
ns_module
,
dr
);
...
...
@@ -1341,9 +1342,9 @@ fn lookup_in_mie(e: env, mie: mod_index_entry, ns: namespace) ->
}
mie_import_ident
(
id
,
_
)
{
ret
lookup_import
(
e
,
local_def
(
id
),
ns
);
}
mie_item
(
item
)
{
ret
found_def_item
(
item
,
ns
);
}
mie_
tag
_variant
(
item
,
variant_idx
)
{
mie_
enum
_variant
(
item
,
variant_idx
)
{
alt
item
.node
{
ast
::
item_
tag
(
variants
,
_
)
{
ast
::
item_
enum
(
variants
,
_
)
{
alt
ns
{
ns_val
(
_
)
{
let
vid
=
variants
[
variant_idx
]
.node.id
;
...
...
@@ -1415,12 +1416,12 @@ fn index_mod(md: ast::_mod) -> mod_index {
ast
::
item_impl
(
_
,
_
,
_
,
_
)
|
ast
::
item_iface
(
_
,
_
)
{
add_to_index
(
index
,
it
.ident
,
mie_item
(
it
));
}
ast
::
item_
tag
(
variants
,
_
)
{
ast
::
item_
enum
(
variants
,
_
)
{
add_to_index
(
index
,
it
.ident
,
mie_item
(
it
));
let
variant_idx
:
uint
=
0u
;
for
v
:
ast
::
variant
in
variants
{
add_to_index
(
index
,
v
.node.name
,
mie_
tag
_variant
(
it
,
variant_idx
));
mie_
enum
_variant
(
it
,
variant_idx
));
variant_idx
+=
1u
;
}
}
...
...
@@ -1458,7 +1459,7 @@ fn index_nmod(md: ast::native_mod) -> mod_index {
// External lookups
fn
ns_for_def
(
d
:
def
)
->
namespace
{
alt
d
{
ast
::
def_variant
(
_
,
_
)
{
ns_val
(
ns_a_
tag
)
}
ast
::
def_variant
(
_
,
_
)
{
ns_val
(
ns_a_
enum
)
}
ast
::
def_fn
(
_
,
_
)
|
ast
::
def_self
(
_
)
|
ast
::
def_const
(
_
)
|
ast
::
def_arg
(
_
,
_
)
|
ast
::
def_local
(
_
,
_
)
|
ast
::
def_upvar
(
_
,
_
,
_
)
|
ast
::
def_native_fn
(
_
,
_
)
|
ast
::
def_self
(
_
)
...
...
@@ -1473,7 +1474,7 @@ fn ns_for_def(d: def) -> namespace {
// a enum
fn
ns_ok
(
wanted
:
namespace
,
actual
:
namespace
)
->
bool
{
alt
actual
{
ns_val
(
ns_a_
tag
)
{
ns_val
(
ns_a_
enum
)
{
alt
wanted
{
ns_val
(
_
)
{
true
}
_
{
false
}
...
...
@@ -1548,7 +1549,7 @@ fn mie_span(mie: mod_index_entry) -> span {
mie_view_item
(
item
)
{
item
.span
}
mie_import_ident
(
_
,
span
)
{
span
}
mie_item
(
item
)
{
item
.span
}
mie_
tag
_variant
(
item
,
_
)
{
item
.span
}
mie_
enum
_variant
(
item
,
_
)
{
item
.span
}
mie_native_item
(
item
)
{
item
.span
}
};
}
...
...
@@ -1566,7 +1567,7 @@ fn typaram_names(tps: [ast::ty_param]) -> [ident] {
ensure_unique
(
*
e
,
i
.span
,
typaram_names
(
ty_params
),
ident_id
,
"type parameter"
);
}
ast
::
item_
tag
(
_
,
ty_params
)
{
ast
::
item_
enum
(
_
,
ty_params
)
{
ensure_unique
(
*
e
,
i
.span
,
typaram_names
(
ty_params
),
ident_id
,
"type parameter"
);
}
...
...
@@ -1635,7 +1636,7 @@ fn check_block(e: @env, b: ast::blk, &&x: (), v: vt<()>) {
}
ast
::
decl_item
(
it
)
{
alt
it
.node
{
ast
::
item_
tag
(
variants
,
_
)
{
ast
::
item_
enum
(
variants
,
_
)
{
add_name
(
types
,
it
.span
,
it
.ident
);
for
v
:
ast
::
variant
in
variants
{
add_name
(
values
,
v
.span
,
v
.node.name
);
...
...
@@ -1776,7 +1777,7 @@ fn check_enum_ok(e: @env, sp:span, id: ident, val: @indexed_mod)
alt
m
{
mie_item
(
an_item
)
{
alt
an_item
.node
{
item_
tag
(
_
,
_
)
{
/* OK */
some
(
an_item
.id
)
}
item_
enum
(
_
,
_
)
{
/* OK */
some
(
an_item
.id
)
}
_
{
none
}
}
}
...
...
@@ -1802,10 +1803,10 @@ fn check_enum_ok(e: @env, sp:span, id: ident, val: @indexed_mod)
check_export
(
e
,
ident
,
val
,
vi
);
}
}
ast
::
view_item_export_
tag
_none
(
id
,
_
)
{
ast
::
view_item_export_
enum
_none
(
id
,
_
)
{
let
_
=
check_enum_ok
(
e
,
vi
.span
,
id
,
val
);
}
ast
::
view_item_export_
tag
_some
(
id
,
ids
,
_
)
{
ast
::
view_item_export_
enum
_some
(
id
,
ids
,
_
)
{
// Check that it's an enum and all the given variants
// belong to it
let
parent_id
=
check_enum_ok
(
e
,
vi
.span
,
id
,
val
);
...
...
@@ -1814,7 +1815,7 @@ fn check_enum_ok(e: @env, sp:span, id: ident, val: @indexed_mod)
some
(
ms
)
{
list
::
iter
(
ms
)
{|
m
|
alt
m
{
mie_
tag
_variant
(
parent_item
,
_
)
{
mie_
enum
_variant
(
parent_item
,
_
)
{
if
parent_item
.id
!=
parent_id
{
e
.sess
.span_err
(
vi
.span
,
#
fmt
(
"variant %s
\
...
...
src/comp/middle/shape.rs
浏览文件 @
76aabbe9
...
...
@@ -8,7 +8,7 @@
import
driver
::
session
::
session
;
import
middle
::{
trans
,
trans_common
};
import
middle
::
trans_common
::{
crate_ctxt
,
val_ty
,
C_bytes
,
C_int
,
C_named_struct
,
C_struct
,
T_
tag
_variant
,
C_named_struct
,
C_struct
,
T_
enum
_variant
,
block_ctxt
,
result
,
rslt
,
bcx_ccx
,
bcx_tcx
,
type_has_static_size
,
umax
,
umin
,
align_to
,
tydesc_info
};
...
...
@@ -51,7 +51,7 @@
const
shape_f64
:
u8
=
9u8
;
// (10 is currently unused, was evec)
const
shape_vec
:
u8
=
11u8
;
const
shape_
tag
:
u8
=
12u8
;
const
shape_
enum
:
u8
=
12u8
;
const
shape_box
:
u8
=
13u8
;
const
shape_struct
:
u8
=
17u8
;
const
shape_box_fn
:
u8
=
18u8
;
...
...
@@ -119,7 +119,7 @@ fn largest_variants(ccx: @crate_ctxt, tag_id: ast::def_id) -> [uint] {
// contains (T,T) must be as least as large as any variant that contains
// just T.
let
ranges
=
[];
let
variants
=
ty
::
tag
_variants
(
ccx
.tcx
,
tag_id
);
let
variants
=
ty
::
enum
_variants
(
ccx
.tcx
,
tag_id
);
for
variant
:
ty
::
variant_info
in
*
variants
{
let
bounded
=
true
;
let
{
a
:
min_size
,
b
:
min_align
}
=
{
a
:
0u
,
b
:
0u
};
...
...
@@ -201,17 +201,17 @@ fn round_up(size: u16, align: u8) -> u16 {
type
size_align
=
{
size
:
u16
,
align
:
u8
};
fn
compute_static_
tag
_size
(
ccx
:
@
crate_ctxt
,
largest_variants
:
[
uint
],
fn
compute_static_
enum
_size
(
ccx
:
@
crate_ctxt
,
largest_variants
:
[
uint
],
did
:
ast
::
def_id
)
->
size_align
{
let
max_size
=
0u16
;
let
max_align
=
1u8
;
let
variants
=
ty
::
tag
_variants
(
ccx
.tcx
,
did
);
let
variants
=
ty
::
enum
_variants
(
ccx
.tcx
,
did
);
for
vid
:
uint
in
largest_variants
{
// We increment a "virtual data pointer" to compute the size.
let
lltys
=
[];
for
typ
:
ty
::
t
in
variants
[
vid
]
.args
{
// FIXME: there should really be a postcondition
// on
tag
_variants that would obviate the need for
// on
enum
_variants that would obviate the need for
// this check. (Issue #586)
check
(
trans_common
::
type_has_static_size
(
ccx
,
typ
));
lltys
+=
[
trans
::
type_of
(
ccx
,
dummy_sp
(),
typ
)];
...
...
@@ -229,7 +229,7 @@ fn compute_static_tag_size(ccx: @crate_ctxt, largest_variants: [uint],
// FIXME (issue #792): This is wrong. If the enum starts with an 8 byte
// aligned quantity, we don't align it.
if
vec
::
len
(
*
variants
)
>
1u
{
let
variant_t
=
T_
tag
_variant
(
ccx
);
let
variant_t
=
T_
enum
_variant
(
ccx
);
max_size
+=
llsize_of_real
(
ccx
,
variant_t
)
as
u16
;
let
align
=
llalign_of_real
(
ccx
,
variant_t
)
as
u8
;
if
max_align
<
align
{
max_align
=
align
;
}
...
...
@@ -238,15 +238,15 @@ fn compute_static_tag_size(ccx: @crate_ctxt, largest_variants: [uint],
ret
{
size
:
max_size
,
align
:
max_align
};
}
enum
tag
_kind
{
enum
enum
_kind
{
tk_unit
,
// 1 variant, no data
tk_enum
,
// N variants, no data
tk_newtype
,
// 1 variant, data
tk_complex
// N variants, no data
}
fn
tag_kind
(
ccx
:
@
crate_ctxt
,
did
:
ast
::
def_id
)
->
tag
_kind
{
let
variants
=
ty
::
tag
_variants
(
ccx
.tcx
,
did
);
fn
enum_kind
(
ccx
:
@
crate_ctxt
,
did
:
ast
::
def_id
)
->
enum
_kind
{
let
variants
=
ty
::
enum
_variants
(
ccx
.tcx
,
did
);
if
vec
::
any
(
*
variants
)
{|
v
|
vec
::
len
(
v
.args
)
>
0u
}
{
if
vec
::
len
(
*
variants
)
==
1u
{
tk_newtype
}
else
{
tk_complex
}
...
...
@@ -281,7 +281,7 @@ fn s_float(tcx: ty_ctxt) -> u8 {
};
}
fn
s_variant_
tag
_t
(
tcx
:
ty_ctxt
)
->
u8
{
fn
s_variant_
enum
_t
(
tcx
:
ty_ctxt
)
->
u8
{
ret
s_int
(
tcx
);
}
...
...
@@ -349,15 +349,15 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint]) -> [u8] {
let
unit_ty
=
ty
::
mk_mach_uint
(
ccx
.tcx
,
ast
::
ty_u8
);
add_substr
(
s
,
shape_of
(
ccx
,
unit_ty
,
ty_param_map
));
}
ty
::
ty_
tag
(
did
,
tps
)
{
alt
tag
_kind
(
ccx
,
did
)
{
ty
::
ty_
enum
(
did
,
tps
)
{
alt
enum
_kind
(
ccx
,
did
)
{
tk_unit
{
// FIXME: For now we do this.
s
+=
[
s_variant_
tag
_t
(
ccx
.tcx
)];
s
+=
[
s_variant_
enum
_t
(
ccx
.tcx
)];
}
tk_enum
{
s
+=
[
s_variant_
tag
_t
(
ccx
.tcx
)];
}
tk_enum
{
s
+=
[
s_variant_
enum
_t
(
ccx
.tcx
)];
}
tk_newtype
|
tk_complex
{
s
+=
[
shape_
tag
];
s
+=
[
shape_
enum
];
let
sub
=
[];
...
...
@@ -481,16 +481,16 @@ fn shape_of_variant(ccx: @crate_ctxt, v: ty::variant_info,
// }
//}
fn
gen_
tag
_shapes
(
ccx
:
@
crate_ctxt
)
->
ValueRef
{
// Loop over all the enum variants and write their shapes into a
data
//
buffer. As we do this, it's possible for us to discover new tags, so we
// must do this first.
fn
gen_
enum
_shapes
(
ccx
:
@
crate_ctxt
)
->
ValueRef
{
// Loop over all the enum variants and write their shapes into a
//
data buffer. As we do this, it's possible for us to discover
//
new enums, so we
must do this first.
let
i
=
0u
;
let
data
=
[];
let
offsets
=
[];
while
i
<
vec
::
len
(
ccx
.shape_cx.tag_order
)
{
let
did
=
ccx
.shape_cx.tag_order
[
i
];
let
variants
=
ty
::
tag
_variants
(
ccx
.tcx
,
did
);
let
variants
=
ty
::
enum
_variants
(
ccx
.tcx
,
did
);
let
item_tyt
=
ty
::
lookup_item_type
(
ccx
.tcx
,
did
);
let
ty_param_count
=
vec
::
len
(
*
item_tyt
.bounds
);
...
...
@@ -519,7 +519,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
let
info_sz
=
0u16
;
for
did_
:
ast
::
def_id
in
ccx
.shape_cx.tag_order
{
let
did
=
did_
;
// Satisfy alias checker.
let
num_variants
=
vec
::
len
(
*
ty
::
tag
_variants
(
ccx
.tcx
,
did
))
as
u16
;
let
num_variants
=
vec
::
len
(
*
ty
::
enum
_variants
(
ccx
.tcx
,
did
))
as
u16
;
add_u16
(
header
,
header_sz
+
info_sz
);
info_sz
+=
2u16
*
(
num_variants
+
2u16
)
+
3u16
;
}
...
...
@@ -532,7 +532,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
i
=
0u
;
for
did_
:
ast
::
def_id
in
ccx
.shape_cx.tag_order
{
let
did
=
did_
;
// Satisfy alias checker.
let
variants
=
ty
::
tag
_variants
(
ccx
.tcx
,
did
);
let
variants
=
ty
::
enum
_variants
(
ccx
.tcx
,
did
);
add_u16
(
info
,
vec
::
len
(
*
variants
)
as
u16
);
// Construct the largest-variants table.
...
...
@@ -556,7 +556,7 @@ fn gen_tag_shapes(ccx: @crate_ctxt) -> ValueRef {
let
size_align
;
if
dynamic
{
size_align
=
{
size
:
0u16
,
align
:
0u8
};
}
else
{
size_align
=
compute_static_
tag
_size
(
ccx
,
lv
,
did
);
}
}
else
{
size_align
=
compute_static_
enum
_size
(
ccx
,
lv
,
did
);
}
add_u16
(
info
,
size_align
.size
);
info
+=
[
size_align
.align
];
...
...
@@ -593,7 +593,7 @@ fn gen_resource_shapes(ccx: @crate_ctxt) -> ValueRef {
}
fn
gen_shape_tables
(
ccx
:
@
crate_ctxt
)
{
let
lltagstable
=
gen_
tag
_shapes
(
ccx
);
let
lltagstable
=
gen_
enum
_shapes
(
ccx
);
let
llresourcestable
=
gen_resource_shapes
(
ccx
);
trans_common
::
set_struct_body
(
ccx
.shape_cx.llshapetablesty
,
[
val_ty
(
lltagstable
),
...
...
@@ -676,15 +676,15 @@ fn llalign_of(cx: @crate_ctxt, t: TypeRef) -> ValueRef {
}
// Computes the size of the data part of a non-dynamically-sized enum.
fn
static_size_of_
tag
(
cx
:
@
crate_ctxt
,
sp
:
span
,
t
:
ty
::
t
)
fn
static_size_of_
enum
(
cx
:
@
crate_ctxt
,
sp
:
span
,
t
:
ty
::
t
)
:
type_has_static_size
(
cx
,
t
)
->
uint
{
if
cx
.
tag_sizes
.contains_key
(
t
)
{
ret
cx
.tag
_sizes
.get
(
t
);
}
if
cx
.
enum_sizes
.contains_key
(
t
)
{
ret
cx
.enum
_sizes
.get
(
t
);
}
alt
ty
::
struct
(
cx
.tcx
,
t
)
{
ty
::
ty_
tag
(
tid
,
subtys
)
{
ty
::
ty_
enum
(
tid
,
subtys
)
{
// Compute max(variant sizes).
let
max_size
=
0u
;
let
variants
=
ty
::
tag
_variants
(
cx
.tcx
,
tid
);
let
variants
=
ty
::
enum
_variants
(
cx
.tcx
,
tid
);
for
variant
:
ty
::
variant_info
in
*
variants
{
let
tup_ty
=
simplify_type
(
cx
,
ty
::
mk_tup
(
cx
.tcx
,
variant
.args
));
// Perform any type parameter substitutions.
...
...
@@ -700,11 +700,12 @@ fn static_size_of_tag(cx: @crate_ctxt, sp: span, t: ty::t)
llsize_of_real
(
cx
,
trans
::
type_of
(
cx
,
sp
,
tup_ty
));
if
max_size
<
this_size
{
max_size
=
this_size
;
}
}
cx
.
tag
_sizes
.insert
(
t
,
max_size
);
cx
.
enum
_sizes
.insert
(
t
,
max_size
);
ret
max_size
;
}
_
{
cx
.tcx.sess
.span_fatal
(
sp
,
"non-enum passed to static_size_of_tag()"
);
cx
.tcx.sess
.span_fatal
(
sp
,
"non-enum passed to static_size_of_enum()"
);
}
}
}
...
...
@@ -754,7 +755,7 @@ fn align_elements(cx: @block_ctxt, elts: [ty::t]) -> metrics {
for
tp
in
elts
{
tys
+=
[
tp
];
}
align_elements
(
cx
,
tys
)
}
ty
::
ty_
tag
(
tid
,
tps
)
{
ty
::
ty_
enum
(
tid
,
tps
)
{
let
bcx
=
cx
;
let
ccx
=
bcx_ccx
(
bcx
);
...
...
@@ -762,7 +763,7 @@ fn align_elements(cx: @block_ctxt, elts: [ty::t]) -> metrics {
// Compute max(variant sizes).
let
bcx
=
bcx
;
let
max_size
:
ValueRef
=
C_int
(
ccx
,
0
);
let
variants
=
ty
::
tag
_variants
(
bcx_tcx
(
bcx
),
tid
);
let
variants
=
ty
::
enum
_variants
(
bcx_tcx
(
bcx
),
tid
);
for
variant
:
ty
::
variant_info
in
*
variants
{
// Perform type substitution on the raw argument types.
let
tys
=
vec
::
map
(
variant
.args
)
{|
raw_ty
|
...
...
@@ -775,12 +776,12 @@ fn align_elements(cx: @block_ctxt, elts: [ty::t]) -> metrics {
rslt
(
bcx
,
max_size
)
};
let
{
bcx
,
val
:
sz
}
=
alt
tag
_kind
(
ccx
,
tid
)
{
tk_unit
|
tk_enum
{
rslt
(
bcx
,
llsize_of
(
ccx
,
T_
tag
_variant
(
ccx
)))
}
let
{
bcx
,
val
:
sz
}
=
alt
enum
_kind
(
ccx
,
tid
)
{
tk_unit
|
tk_enum
{
rslt
(
bcx
,
llsize_of
(
ccx
,
T_
enum
_variant
(
ccx
)))
}
tk_newtype
{
compute_max_variant_size
(
bcx
)
}
tk_complex
{
let
{
bcx
,
val
}
=
compute_max_variant_size
(
bcx
);
rslt
(
bcx
,
Add
(
bcx
,
val
,
llsize_of
(
ccx
,
T_
tag
_variant
(
ccx
))))
rslt
(
bcx
,
Add
(
bcx
,
val
,
llsize_of
(
ccx
,
T_
enum
_variant
(
ccx
))))
}
};
...
...
src/comp/middle/trans.rs
浏览文件 @
76aabbe9
...
...
@@ -135,7 +135,7 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
ty
::
ty_uint
(
t
)
{
T_uint_ty
(
cx
,
t
)
}
ty
::
ty_float
(
t
)
{
T_float_ty
(
cx
,
t
)
}
ty
::
ty_str
{
T_ptr
(
T_vec
(
cx
,
T_i8
()))
}
ty
::
ty_
tag
(
did
,
_
)
{
type_of_tag
(
cx
,
sp
,
did
,
t
)
}
ty
::
ty_
enum
(
did
,
_
)
{
type_of_enum
(
cx
,
sp
,
did
,
t
)
}
ty
::
ty_box
(
mt
)
{
let
mt_ty
=
mt
.ty
;
check
non_ty_var
(
cx
,
mt_ty
);
...
...
@@ -213,18 +213,18 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
ret
llty
;
}
fn
type_of_
tag
(
cx
:
@
crate_ctxt
,
sp
:
span
,
did
:
ast
::
def_id
,
t
:
ty
::
t
)
fn
type_of_
enum
(
cx
:
@
crate_ctxt
,
sp
:
span
,
did
:
ast
::
def_id
,
t
:
ty
::
t
)
->
TypeRef
{
let
degen
=
vec
::
len
(
*
ty
::
tag
_variants
(
cx
.tcx
,
did
))
==
1u
;
let
degen
=
vec
::
len
(
*
ty
::
enum
_variants
(
cx
.tcx
,
did
))
==
1u
;
if
check
type_has_static_size
(
cx
,
t
)
{
let
size
=
static_size_of_
tag
(
cx
,
sp
,
t
);
if
!
degen
{
T_
tag
(
cx
,
size
)
}
else
if
size
==
0u
{
T_struct
([
T_
tag
_variant
(
cx
)])
}
let
size
=
static_size_of_
enum
(
cx
,
sp
,
t
);
if
!
degen
{
T_
enum
(
cx
,
size
)
}
else
if
size
==
0u
{
T_struct
([
T_
enum
_variant
(
cx
)])
}
else
{
T_array
(
T_i8
(),
size
)
}
}
else
{
if
degen
{
T_struct
([
T_
tag
_variant
(
cx
)])
}
else
{
T_opaque_
tag
(
cx
)
}
if
degen
{
T_struct
([
T_
enum
_variant
(
cx
)])
}
else
{
T_opaque_
enum
(
cx
)
}
}
}
...
...
@@ -498,16 +498,16 @@ fn simplifier(ccx: @crate_ctxt, typ: ty::t) -> ty::t {
}
// Computes the size of the data part of a non-dynamically-sized
tag
.
fn
static_size_of_
tag
(
cx
:
@
crate_ctxt
,
sp
:
span
,
t
:
ty
::
t
)
// Computes the size of the data part of a non-dynamically-sized
enum
.
fn
static_size_of_
enum
(
cx
:
@
crate_ctxt
,
sp
:
span
,
t
:
ty
::
t
)
:
type_has_static_size
(
cx
,
t
)
->
uint
{
if
cx
.
tag_sizes
.contains_key
(
t
)
{
ret
cx
.tag
_sizes
.get
(
t
);
}
if
cx
.
enum_sizes
.contains_key
(
t
)
{
ret
cx
.enum
_sizes
.get
(
t
);
}
alt
ty
::
struct
(
cx
.tcx
,
t
)
{
ty
::
ty_
tag
(
tid
,
subtys
)
{
ty
::
ty_
enum
(
tid
,
subtys
)
{
// Compute max(variant sizes).
let
max_size
=
0u
;
let
variants
=
ty
::
tag
_variants
(
cx
.tcx
,
tid
);
let
variants
=
ty
::
enum
_variants
(
cx
.tcx
,
tid
);
for
variant
:
ty
::
variant_info
in
*
variants
{
let
tup_ty
=
simplify_type
(
cx
,
ty
::
mk_tup
(
cx
.tcx
,
variant
.args
));
// Perform any type parameter substitutions.
...
...
@@ -522,12 +522,9 @@ fn static_size_of_tag(cx: @crate_ctxt, sp: span, t: ty::t)
let
this_size
=
llsize_of_real
(
cx
,
type_of
(
cx
,
sp
,
tup_ty
));
if
max_size
<
this_size
{
max_size
=
this_size
;
}
}
cx
.
tag
_sizes
.insert
(
t
,
max_size
);
cx
.
enum
_sizes
.insert
(
t
,
max_size
);
ret
max_size
;
}
_
{
cx
.tcx.sess
.span_fatal
(
sp
,
"non-tag passed to static_size_of_tag()"
);
}
}
}
...
...
@@ -581,14 +578,14 @@ fn align_elements(cx: @block_ctxt, elts: [ty::t]) -> result {
for
tp
in
elts
{
tys
+=
[
tp
];
}
ret
align_elements
(
cx
,
tys
);
}
ty
::
ty_
tag
(
tid
,
tps
)
{
ty
::
ty_
enum
(
tid
,
tps
)
{
let
bcx
=
cx
;
let
ccx
=
bcx_ccx
(
bcx
);
// Compute max(variant sizes).
let
max_size
:
ValueRef
=
alloca
(
bcx
,
ccx
.int_type
);
Store
(
bcx
,
C_int
(
ccx
,
0
),
max_size
);
let
variants
=
ty
::
tag
_variants
(
bcx_tcx
(
bcx
),
tid
);
let
variants
=
ty
::
enum
_variants
(
bcx_tcx
(
bcx
),
tid
);
for
variant
:
ty
::
variant_info
in
*
variants
{
// Perform type substitution on the raw argument types.
...
...
@@ -632,7 +629,7 @@ fn dynamic_align_of(cx: @block_ctxt, t: ty::t) -> result {
}
ret
rslt
(
bcx
,
a
);
}
ty
::
ty_
tag
(
_
,
_
)
{
ty
::
ty_
enum
(
_
,
_
)
{
ret
rslt
(
cx
,
C_int
(
bcx_ccx
(
cx
),
1
));
// FIXME: stub
}
ty
::
ty_tup
(
elts
)
{
...
...
@@ -740,11 +737,11 @@ fn compute_off(bcx: @block_ctxt,
// This function uses GEP_tup_like() above and automatically performs casts as
// appropriate. @llblobptr is the data part of a enum value; its actual type
// is meaningless, as it will be cast away.
fn
GEP_
tag
(
cx
:
@
block_ctxt
,
llblobptr
:
ValueRef
,
tag
_id
:
ast
::
def_id
,
fn
GEP_
enum
(
cx
:
@
block_ctxt
,
llblobptr
:
ValueRef
,
enum
_id
:
ast
::
def_id
,
variant_id
:
ast
::
def_id
,
ty_substs
:
[
ty
::
t
],
ix
:
uint
)
:
valid_variant_index
(
ix
,
cx
,
tag
_id
,
variant_id
)
->
ix
:
uint
)
:
valid_variant_index
(
ix
,
cx
,
enum
_id
,
variant_id
)
->
result
{
let
variant
=
ty
::
tag_variant_with_id
(
bcx_tcx
(
cx
),
tag
_id
,
variant_id
);
let
variant
=
ty
::
enum_variant_with_id
(
bcx_tcx
(
cx
),
enum
_id
,
variant_id
);
// Synthesize a tuple type so that GEP_tup_like() can work its magic.
// Separately, store the type of the element we're interested in.
...
...
@@ -1592,7 +1589,7 @@ fn iter_variant(cx: @block_ctxt, a_tup: ValueRef,
let
v_id
=
variant
.id
;
for
a
:
ty
::
arg
in
args
{
check
(
valid_variant_index
(
j
,
cx
,
tid
,
v_id
));
let
rslt
=
GEP_
tag
(
cx
,
a_tup
,
tid
,
v_id
,
tps
,
j
);
let
rslt
=
GEP_
enum
(
cx
,
a_tup
,
tid
,
v_id
,
tps
,
j
);
let
llfldp_a
=
rslt
.val
;
cx
=
rslt
.bcx
;
let
ty_subst
=
ty
::
substitute_type_params
(
ccx
.tcx
,
tps
,
a
.ty
);
...
...
@@ -1639,20 +1636,20 @@ fn iter_variant(cx: @block_ctxt, a_tup: ValueRef,
let
{
bcx
:
bcx
,
val
:
llfld_a
}
=
GEP_tup_like
(
cx
,
tup_t
,
av
,
[
0
,
1
]);
ret
f
(
bcx
,
llfld_a
,
inner1
);
}
ty
::
ty_
tag
(
tid
,
tps
)
{
let
variants
=
ty
::
tag
_variants
(
bcx_tcx
(
cx
),
tid
);
ty
::
ty_
enum
(
tid
,
tps
)
{
let
variants
=
ty
::
enum
_variants
(
bcx_tcx
(
cx
),
tid
);
let
n_variants
=
vec
::
len
(
*
variants
);
// Cast the
tag
s to types we can GEP into.
// Cast the
enum
s to types we can GEP into.
if
n_variants
==
1u
{
ret
iter_variant
(
cx
,
av
,
variants
[
0
],
tps
,
tid
,
f
);
}
let
ccx
=
bcx_ccx
(
cx
);
let
ll
tagty
=
T_opaque_tag
_ptr
(
ccx
);
let
av_
tag
=
PointerCast
(
cx
,
av
,
lltag
ty
);
let
lldiscrim_a_ptr
=
GEPi
(
cx
,
av_
tag
,
[
0
,
0
]);
let
llunion_a_ptr
=
GEPi
(
cx
,
av_
tag
,
[
0
,
1
]);
let
ll
enumty
=
T_opaque_enum
_ptr
(
ccx
);
let
av_
enum
=
PointerCast
(
cx
,
av
,
llenum
ty
);
let
lldiscrim_a_ptr
=
GEPi
(
cx
,
av_
enum
,
[
0
,
0
]);
let
llunion_a_ptr
=
GEPi
(
cx
,
av_
enum
,
[
0
,
1
]);
let
lldiscrim_a
=
Load
(
cx
,
lldiscrim_a_ptr
);
// NB: we must hit the discriminant first so that structural
...
...
@@ -2098,7 +2095,7 @@ fn trans_unary(bcx: @block_ctxt, op: ast::unop, e: @ast::expr,
let
{
bcx
,
box
,
body
}
=
trans_malloc_boxed
(
bcx
,
e_ty
);
add_clean_free
(
bcx
,
box
,
false
);
// Cast the body type to the type of the value. This is needed to
// make
tags work, since tag
s have a different LLVM type depending
// make
enums work, since enum
s have a different LLVM type depending
// on whether they're boxed or not
let
ccx
=
bcx_ccx
(
bcx
);
if
check
type_has_static_size
(
ccx
,
e_ty
)
{
...
...
@@ -2262,8 +2259,8 @@ fn autoderef(cx: @block_ctxt, v: ValueRef, t: ty::t) -> result_t {
t1
=
ty
::
substitute_type_params
(
ccx
.tcx
,
tps
,
inner
);
v1
=
GEPi
(
cx
,
v1
,
[
0
,
1
]);
}
ty
::
ty_
tag
(
did
,
tps
)
{
let
variants
=
ty
::
tag
_variants
(
ccx
.tcx
,
did
);
ty
::
ty_
enum
(
did
,
tps
)
{
let
variants
=
ty
::
enum
_variants
(
ccx
.tcx
,
did
);
if
vec
::
len
(
*
variants
)
!=
1u
||
vec
::
len
(
variants
[
0
]
.args
)
!=
1u
{
break
;
...
...
@@ -2644,22 +2641,22 @@ fn trans_var(cx: @block_ctxt, sp: span, def: ast::def, id: ast::node_id)
ret
lval_static_fn
(
cx
,
did
,
id
);
}
ast
::
def_variant
(
tid
,
vid
)
{
if
vec
::
len
(
ty
::
tag
_variant_with_id
(
ccx
.tcx
,
tid
,
vid
)
.args
)
>
0u
{
if
vec
::
len
(
ty
::
enum
_variant_with_id
(
ccx
.tcx
,
tid
,
vid
)
.args
)
>
0u
{
// N-ary variant.
ret
lval_static_fn
(
cx
,
vid
,
id
);
}
else
{
// Nullary variant.
let
tag
_ty
=
node_id_type
(
ccx
,
id
);
let
alloc_result
=
alloc_ty
(
cx
,
tag
_ty
);
let
ll
tag
blob
=
alloc_result
.val
;
let
ll
tagty
=
type_of_tag
(
ccx
,
sp
,
tid
,
tag
_ty
);
let
enum
_ty
=
node_id_type
(
ccx
,
id
);
let
alloc_result
=
alloc_ty
(
cx
,
enum
_ty
);
let
ll
enum
blob
=
alloc_result
.val
;
let
ll
enumty
=
type_of_enum
(
ccx
,
sp
,
tid
,
enum
_ty
);
let
bcx
=
alloc_result
.bcx
;
let
ll
tagptr
=
PointerCast
(
bcx
,
lltagblob
,
T_ptr
(
lltag
ty
));
let
lldiscrimptr
=
GEPi
(
bcx
,
ll
tag
ptr
,
[
0
,
0
]);
let
ll
enumptr
=
PointerCast
(
bcx
,
llenumblob
,
T_ptr
(
llenum
ty
));
let
lldiscrimptr
=
GEPi
(
bcx
,
ll
enum
ptr
,
[
0
,
0
]);
let
lldiscrim_gv
=
lookup_discriminant
(
bcx
.fcx.lcx
,
vid
);
let
lldiscrim
=
Load
(
bcx
,
lldiscrim_gv
);
Store
(
bcx
,
lldiscrim
,
lldiscrimptr
);
ret
lval_no_env
(
bcx
,
ll
tag
ptr
,
temporary
);
ret
lval_no_env
(
bcx
,
ll
enum
ptr
,
temporary
);
}
}
ast
::
def_const
(
did
)
{
...
...
@@ -2800,7 +2797,7 @@ fn trans_lval(cx: @block_ctxt, e: @ast::expr) -> lval_result {
ty
::
ty_res
(
_
,
_
,
_
)
{
GEPi
(
sub
.bcx
,
sub
.val
,
[
0
,
1
])
}
ty
::
ty_
tag
(
_
,
_
)
{
ty
::
ty_
enum
(
_
,
_
)
{
let
ety
=
ty
::
expr_ty
(
ccx
.tcx
,
e
);
let
sp
=
e
.span
;
let
ellty
=
...
...
@@ -2896,7 +2893,7 @@ fn trans_cast(cx: @block_ctxt, e: @ast::expr, id: ast::node_id,
check
(
type_has_static_size
(
ccx
,
t_out
));
let
ll_t_out
=
type_of
(
ccx
,
e
.span
,
t_out
);
enum
kind
{
pointer
,
integral
,
float
,
tag
_
,
other
,
}
enum
kind
{
pointer
,
integral
,
float
,
enum
_
,
other
,
}
fn
t_kind
(
tcx
:
ty
::
ctxt
,
t
:
ty
::
t
)
->
kind
{
ret
if
ty
::
type_is_fp
(
tcx
,
t
)
{
float
...
...
@@ -2905,8 +2902,8 @@ fn t_kind(tcx: ty::ctxt, t: ty::t) -> kind {
pointer
}
else
if
ty
::
type_is_integral
(
tcx
,
t
)
{
integral
}
else
if
ty
::
type_is_
tag
(
tcx
,
t
)
{
tag
_
}
else
if
ty
::
type_is_
enum
(
tcx
,
t
)
{
enum
_
}
else
{
other
};
}
let
k_in
=
t_kind
(
ccx
.tcx
,
t_in
);
...
...
@@ -2940,11 +2937,11 @@ fn t_kind(tcx: ty::ctxt, t: ty::t) -> kind {
{
in
:
pointer
,
out
:
pointer
}
{
PointerCast
(
e_res
.bcx
,
e_res
.val
,
ll_t_out
)
}
{
in
:
tag_
,
out
:
integral
}
|
{
in
:
tag
_
,
out
:
float
}
{
{
in
:
enum_
,
out
:
integral
}
|
{
in
:
enum
_
,
out
:
float
}
{
let
cx
=
e_res
.bcx
;
let
ll
tagty
=
T_opaque_tag
_ptr
(
ccx
);
let
av_
tag
=
PointerCast
(
cx
,
e_res
.val
,
lltag
ty
);
let
lldiscrim_a_ptr
=
GEPi
(
cx
,
av_
tag
,
[
0
,
0
]);
let
ll
enumty
=
T_opaque_enum
_ptr
(
ccx
);
let
av_
enum
=
PointerCast
(
cx
,
e_res
.val
,
llenum
ty
);
let
lldiscrim_a_ptr
=
GEPi
(
cx
,
av_
enum
,
[
0
,
0
]);
let
lldiscrim_a
=
Load
(
cx
,
lldiscrim_a_ptr
);
alt
k_out
{
integral
{
int_cast
(
e_res
.bcx
,
ll_t_out
,
...
...
@@ -4520,7 +4517,7 @@ fn trans_res_ctor(cx: @local_ctxt, sp: span, dtor: ast::fn_decl,
}
fn
trans_
tag_variant
(
cx
:
@
local_ctxt
,
tag
_id
:
ast
::
node_id
,
fn
trans_
enum_variant
(
cx
:
@
local_ctxt
,
enum
_id
:
ast
::
node_id
,
variant
:
ast
::
variant
,
disr
:
int
,
is_degen
:
bool
,
ty_params
:
[
ast
::
ty_param
])
{
let
ccx
=
cx
.ccx
;
...
...
@@ -4546,7 +4543,7 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
some
(
x
)
{
llfndecl
=
x
;
}
_
{
ccx
.sess
.span_fatal
(
variant
.span
,
"unbound variant id in trans_
tag
_variant"
);
"unbound variant id in trans_
enum
_variant"
);
}
}
let
fcx
=
new_fn_ctxt
(
cx
,
variant
.span
,
llfndecl
);
...
...
@@ -4568,18 +4565,18 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
if
is_degen
{
fcx
.llretptr
}
else
{
let
ll
tag
ptr
=
PointerCast
(
bcx
,
fcx
.llretptr
,
T_opaque_
tag
_ptr
(
ccx
));
let
lldiscrimptr
=
GEPi
(
bcx
,
ll
tag
ptr
,
[
0
,
0
]);
let
ll
enum
ptr
=
PointerCast
(
bcx
,
fcx
.llretptr
,
T_opaque_
enum
_ptr
(
ccx
));
let
lldiscrimptr
=
GEPi
(
bcx
,
ll
enum
ptr
,
[
0
,
0
]);
Store
(
bcx
,
C_int
(
ccx
,
disr
),
lldiscrimptr
);
GEPi
(
bcx
,
ll
tag
ptr
,
[
0
,
1
])
GEPi
(
bcx
,
ll
enum
ptr
,
[
0
,
1
])
};
i
=
0u
;
let
t_id
=
ast_util
::
local_def
(
tag
_id
);
let
t_id
=
ast_util
::
local_def
(
enum
_id
);
let
v_id
=
ast_util
::
local_def
(
variant
.node.id
);
for
va
:
ast
::
variant_arg
in
variant
.node.args
{
check
(
valid_variant_index
(
i
,
bcx
,
t_id
,
v_id
));
let
rslt
=
GEP_
tag
(
bcx
,
llblobptr
,
t_id
,
v_id
,
ty_param_substs
,
i
);
let
rslt
=
GEP_
enum
(
bcx
,
llblobptr
,
t_id
,
v_id
,
ty_param_substs
,
i
);
bcx
=
rslt
.bcx
;
let
lldestptr
=
rslt
.val
;
// If this argument to this function is a enum, it'll have come in to
...
...
@@ -4915,14 +4912,14 @@ fn trans_item(cx: @local_ctxt, item: ast::item) {
module_path
:
cx
.module_path
+
[
item
.ident
]
with
*
cx
};
trans_mod
(
sub_cx
,
m
);
}
ast
::
item_
tag
(
variants
,
tps
)
{
ast
::
item_
enum
(
variants
,
tps
)
{
let
sub_cx
=
extend_path
(
cx
,
item
.ident
);
let
degen
=
vec
::
len
(
variants
)
==
1u
;
let
vi
=
ty
::
tag
_variants
(
cx
.ccx.tcx
,
{
crate
:
ast
::
local_crate
,
let
vi
=
ty
::
enum
_variants
(
cx
.ccx.tcx
,
{
crate
:
ast
::
local_crate
,
node
:
item
.id
});
let
i
=
0
;
for
variant
:
ast
::
variant
in
variants
{
trans_
tag
_variant
(
sub_cx
,
item
.id
,
variant
,
trans_
enum
_variant
(
sub_cx
,
item
.id
,
variant
,
vi
[
i
]
.disr_val
,
degen
,
tps
);
i
+=
1
;
}
...
...
@@ -5224,7 +5221,7 @@ fn collect_item(ccx: @crate_ctxt, abi: @mutable option::t<ast::native_abi>,
check
returns_non_ty_var
(
ccx
,
t
);
register_fn_full
(
ccx
,
i
.span
,
new_pt
,
"res_dtor"
,
tps
,
i
.id
,
t
);
}
ast
::
item_
tag
(
variants
,
tps
)
{
ast
::
item_
enum
(
variants
,
tps
)
{
for
variant
in
variants
{
if
vec
::
len
(
variant
.node.args
)
!=
0u
{
register_fn
(
ccx
,
i
.span
,
new_pt
+
[
variant
.node.name
],
...
...
@@ -5252,8 +5249,8 @@ fn trans_constant(ccx: @crate_ctxt, it: @ast::item, &&pt: [str],
let
new_pt
=
pt
+
[
it
.ident
];
visit
::
visit_item
(
it
,
new_pt
,
v
);
alt
it
.node
{
ast
::
item_
tag
(
variants
,
_
)
{
let
vi
=
ty
::
tag
_variants
(
ccx
.tcx
,
{
crate
:
ast
::
local_crate
,
ast
::
item_
enum
(
variants
,
_
)
{
let
vi
=
ty
::
enum
_variants
(
ccx
.tcx
,
{
crate
:
ast
::
local_crate
,
node
:
it
.id
});
let
i
=
0
;
for
variant
in
variants
{
...
...
@@ -5517,7 +5514,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
item_symbols
:
new_int_hash
::
<
str
>
(),
mutable
main_fn
:
none
::
<
ValueRef
>
,
link_meta
:
link_meta
,
tag
_sizes
:
ty
::
new_ty_hash
(),
enum
_sizes
:
ty
::
new_ty_hash
(),
discrims
:
ast_util
::
new_def_id_hash
::
<
ValueRef
>
(),
discrim_symbols
:
new_int_hash
::
<
str
>
(),
consts
:
new_int_hash
::
<
ValueRef
>
(),
...
...
src/comp/middle/trans_alt.rs
浏览文件 @
76aabbe9
...
...
@@ -68,7 +68,7 @@ fn trans_opt(bcx: @block_ctxt, o: opt) -> opt_result {
// FIXME: invariant -- pat_id is bound in the def_map?
fn
variant_opt
(
ccx
:
@
crate_ctxt
,
pat_id
:
ast
::
node_id
)
->
opt
{
let
vdef
=
ast_util
::
variant_def_ids
(
ccx
.tcx.def_map
.get
(
pat_id
));
let
variants
=
ty
::
tag
_variants
(
ccx
.tcx
,
vdef
.tg
);
let
variants
=
ty
::
enum
_variants
(
ccx
.tcx
,
vdef
.tg
);
for
v
:
ty
::
variant_info
in
*
variants
{
if
vdef
.var
==
v
.id
{
ret
var
(
v
.disr_val
,
vdef
);
}
}
...
...
@@ -158,13 +158,13 @@ fn e(p: @ast::pat) -> option::t<[@ast::pat]> {
ret
enter_match
(
m
,
col
,
val
,
e
);
}
fn
enter_opt
(
ccx
:
@
crate_ctxt
,
m
:
match
,
opt
:
opt
,
col
:
uint
,
tag
_size
:
uint
,
fn
enter_opt
(
ccx
:
@
crate_ctxt
,
m
:
match
,
opt
:
opt
,
col
:
uint
,
enum
_size
:
uint
,
val
:
ValueRef
)
->
match
{
let
dummy
=
@
{
id
:
0
,
node
:
ast
::
pat_wild
,
span
:
dummy_sp
()};
fn
e
(
ccx
:
@
crate_ctxt
,
dummy
:
@
ast
::
pat
,
opt
:
opt
,
size
:
uint
,
p
:
@
ast
::
pat
)
->
option
::
t
<
[
@
ast
::
pat
]
>
{
alt
p
.node
{
ast
::
pat_
tag
(
ctor
,
subpats
)
{
ast
::
pat_
enum
(
ctor
,
subpats
)
{
ret
if
opt_eq
(
variant_opt
(
ccx
,
p
.id
),
opt
)
{
some
(
subpats
)
}
else
{
none
};
...
...
@@ -178,7 +178,7 @@ fn e(ccx: @crate_ctxt, dummy: @ast::pat, opt: opt, size: uint,
_
{
ret
some
(
vec
::
init_elt
(
size
,
dummy
));
}
}
}
ret
enter_match
(
m
,
col
,
val
,
bind
e
(
ccx
,
dummy
,
opt
,
tag
_size
,
_
));
ret
enter_match
(
m
,
col
,
val
,
bind
e
(
ccx
,
dummy
,
opt
,
enum
_size
,
_
));
}
fn
enter_rec
(
m
:
match
,
col
:
uint
,
fields
:
[
ast
::
ident
],
val
:
ValueRef
)
->
...
...
@@ -251,7 +251,7 @@ fn add_to_set(&set: [opt], val: opt) {
ast
::
pat_range
(
l1
,
l2
)
{
add_to_set
(
found
,
range
(
l1
,
l2
));
}
ast
::
pat_
tag
(
_
,
_
)
{
ast
::
pat_
enum
(
_
,
_
)
{
add_to_set
(
found
,
variant_opt
(
ccx
,
br
.pats
[
col
]
.id
));
}
_
{
}
...
...
@@ -268,14 +268,14 @@ fn extract_variant_args(bcx: @block_ctxt, pat_id: ast::node_id,
// pat_id must have the same length ty_param_substs as vdefs?
let
ty_param_substs
=
ty
::
node_id_to_type_params
(
ccx
.tcx
,
pat_id
);
let
blobptr
=
val
;
let
variants
=
ty
::
tag
_variants
(
ccx
.tcx
,
vdefs
.tg
);
let
variants
=
ty
::
enum
_variants
(
ccx
.tcx
,
vdefs
.tg
);
let
args
=
[];
let
size
=
vec
::
len
(
ty
::
tag
_variant_with_id
(
ccx
.tcx
,
vdefs
.tg
,
vdefs
.var
)
.args
);
vec
::
len
(
ty
::
enum
_variant_with_id
(
ccx
.tcx
,
vdefs
.tg
,
vdefs
.var
)
.args
);
if
size
>
0u
&&
vec
::
len
(
*
variants
)
!=
1u
{
let
tag
ptr
=
PointerCast
(
bcx
,
val
,
trans_common
::
T_opaque_
tag
_ptr
(
ccx
));
blobptr
=
GEPi
(
bcx
,
tag
ptr
,
[
0
,
1
]);
let
enum
ptr
=
PointerCast
(
bcx
,
val
,
trans_common
::
T_opaque_
enum
_ptr
(
ccx
));
blobptr
=
GEPi
(
bcx
,
enum
ptr
,
[
0
,
1
]);
}
let
i
=
0u
;
let
vdefs_tg
=
vdefs
.tg
;
...
...
@@ -286,8 +286,8 @@ fn extract_variant_args(bcx: @block_ctxt, pat_id: ast::node_id,
// invariant needed:
// how do we know it even makes sense to pass in ty_param_substs
// here? What if it's [] and the enum type has variables in it?
trans
::
GEP_
tag
(
bcx
,
blobptr
,
vdefs_tg
,
vdefs_var
,
ty_param_substs
,
i
);
trans
::
GEP_
enum
(
bcx
,
blobptr
,
vdefs_tg
,
vdefs_var
,
ty_param_substs
,
i
);
bcx
=
r
.bcx
;
args
+=
[
r
.val
];
i
+=
1u
;
...
...
@@ -339,7 +339,7 @@ fn any_tup_pat(m: match, col: uint) -> bool {
fn
pick_col
(
m
:
match
)
->
uint
{
fn
score
(
p
:
@
ast
::
pat
)
->
uint
{
alt
p
.node
{
ast
::
pat_lit
(
_
)
|
ast
::
pat_
tag
(
_
,
_
)
|
ast
::
pat_range
(
_
,
_
)
{
1u
}
ast
::
pat_lit
(
_
)
|
ast
::
pat_
enum
(
_
,
_
)
|
ast
::
pat_range
(
_
,
_
)
{
1u
}
ast
::
pat_ident
(
_
,
some
(
p
))
{
score
(
p
)
}
_
{
0u
}
}
...
...
@@ -479,13 +479,13 @@ enum branch_kind { no_branch, single, switch, compare, }
if
vec
::
len
(
opts
)
>
0u
{
alt
opts
[
0
]
{
var
(
_
,
vdef
)
{
if
vec
::
len
(
*
ty
::
tag
_variants
(
ccx
.tcx
,
vdef
.tg
))
==
1u
{
if
vec
::
len
(
*
ty
::
enum
_variants
(
ccx
.tcx
,
vdef
.tg
))
==
1u
{
kind
=
single
;
}
else
{
let
tag
ptr
=
let
enum
ptr
=
PointerCast
(
bcx
,
val
,
trans_common
::
T_opaque_
tag
_ptr
(
ccx
));
let
discrimptr
=
GEPi
(
bcx
,
tag
ptr
,
[
0
,
0
]);
trans_common
::
T_opaque_
enum
_ptr
(
ccx
));
let
discrimptr
=
GEPi
(
bcx
,
enum
ptr
,
[
0
,
0
]);
test_val
=
Load
(
bcx
,
discrimptr
);
kind
=
switch
;
}
...
...
@@ -725,7 +725,7 @@ fn bind_irrefutable_pat(bcx: @block_ctxt, pat: @ast::pat, val: ValueRef,
_
{}
}
}
ast
::
pat_
tag
(
_
,
sub
)
{
ast
::
pat_
enum
(
_
,
sub
)
{
if
vec
::
len
(
sub
)
==
0u
{
ret
bcx
;
}
let
vdefs
=
ast_util
::
variant_def_ids
(
ccx
.tcx.def_map
.get
(
pat
.id
));
let
args
=
extract_variant_args
(
bcx
,
pat
.id
,
vdefs
,
val
);
...
...
src/comp/middle/trans_common.rs
浏览文件 @
76aabbe9
...
...
@@ -92,7 +92,7 @@ enum tydesc_kind {
item_symbols
:
hashmap
<
ast
::
node_id
,
str
>
,
mutable
main_fn
:
option
::
t
<
ValueRef
>
,
link_meta
:
link
::
link_meta
,
tag
_sizes
:
hashmap
<
ty
::
t
,
uint
>
,
enum
_sizes
:
hashmap
<
ty
::
t
,
uint
>
,
discrims
:
hashmap
<
ast
::
def_id
,
ValueRef
>
,
discrim_symbols
:
hashmap
<
ast
::
node_id
,
str
>
,
consts
:
hashmap
<
ast
::
node_id
,
ValueRef
>
,
...
...
@@ -701,31 +701,31 @@ fn T_opaque_cbox_ptr(cx: @crate_ctxt) -> TypeRef {
ret
t
;
}
fn
T_
tag
_variant
(
cx
:
@
crate_ctxt
)
->
TypeRef
{
fn
T_
enum
_variant
(
cx
:
@
crate_ctxt
)
->
TypeRef
{
ret
cx
.int_type
;
}
fn
T_
tag
(
cx
:
@
crate_ctxt
,
size
:
uint
)
->
TypeRef
{
let
s
=
"
tag
_"
+
uint
::
to_str
(
size
,
10u
);
fn
T_
enum
(
cx
:
@
crate_ctxt
,
size
:
uint
)
->
TypeRef
{
let
s
=
"
enum
_"
+
uint
::
to_str
(
size
,
10u
);
alt
name_has_type
(
cx
.tn
,
s
)
{
some
(
t
)
{
ret
t
;
}
_
{}
}
let
t
=
if
size
==
0u
{
T_struct
([
T_
tag
_variant
(
cx
)])
}
else
{
T_struct
([
T_
tag
_variant
(
cx
),
T_array
(
T_i8
(),
size
)])
};
T_struct
([
T_
enum
_variant
(
cx
)])
}
else
{
T_struct
([
T_
enum
_variant
(
cx
),
T_array
(
T_i8
(),
size
)])
};
associate_type
(
cx
.tn
,
s
,
t
);
ret
t
;
}
fn
T_opaque_
tag
(
cx
:
@
crate_ctxt
)
->
TypeRef
{
let
s
=
"opaque_
tag
"
;
fn
T_opaque_
enum
(
cx
:
@
crate_ctxt
)
->
TypeRef
{
let
s
=
"opaque_
enum
"
;
alt
name_has_type
(
cx
.tn
,
s
)
{
some
(
t
)
{
ret
t
;
}
_
{}
}
let
t
=
T_struct
([
T_
tag
_variant
(
cx
),
T_i8
()]);
let
t
=
T_struct
([
T_
enum
_variant
(
cx
),
T_i8
()]);
associate_type
(
cx
.tn
,
s
,
t
);
ret
t
;
}
fn
T_opaque_
tag
_ptr
(
cx
:
@
crate_ctxt
)
->
TypeRef
{
ret
T_ptr
(
T_opaque_
tag
(
cx
));
fn
T_opaque_
enum
_ptr
(
cx
:
@
crate_ctxt
)
->
TypeRef
{
ret
T_ptr
(
T_opaque_
enum
(
cx
));
}
fn
T_captured_tydescs
(
cx
:
@
crate_ctxt
,
n
:
uint
)
->
TypeRef
{
...
...
@@ -850,7 +850,7 @@ fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {
}
pure
fn
valid_variant_index
(
ix
:
uint
,
cx
:
@
block_ctxt
,
tag
_id
:
ast
::
def_id
,
pure
fn
valid_variant_index
(
ix
:
uint
,
cx
:
@
block_ctxt
,
enum
_id
:
ast
::
def_id
,
variant_id
:
ast
::
def_id
)
->
bool
{
// Handwaving: it's ok to pretend this code is referentially
...
...
@@ -858,7 +858,7 @@ fn C_shape(ccx: @crate_ctxt, bytes: [u8]) -> ValueRef {
// change. (We're not adding new variants during trans.)
unchecked
{
let
variant
=
ty
::
tag_variant_with_id
(
bcx_tcx
(
cx
),
tag
_id
,
variant_id
);
ty
::
enum_variant_with_id
(
bcx_tcx
(
cx
),
enum
_id
,
variant_id
);
ix
<
vec
::
len
(
variant
.args
)
}
}
...
...
src/comp/middle/tstate/pre_post_conditions.rs
浏览文件 @
76aabbe9
...
...
@@ -67,7 +67,7 @@ fn find_pre_post_item(ccx: crate_ctxt, i: item) {
}
item_mod
(
m
)
{
find_pre_post_mod
(
m
);
}
item_native_mod
(
nm
)
{
find_pre_post_native_mod
(
nm
);
}
item_ty
(
_
,
_
)
|
item_
tag
(
_
,
_
)
|
item_iface
(
_
,
_
)
{
ret
;
}
item_ty
(
_
,
_
)
|
item_
enum
(
_
,
_
)
|
item_iface
(
_
,
_
)
{
ret
;
}
item_res
(
_
,
_
,
body
,
dtor_id
,
_
)
{
let
fcx
=
{
enclosing
:
ccx
.fm
.get
(
dtor_id
),
...
...
src/comp/middle/ty.rs
浏览文件 @
76aabbe9
...
...
@@ -77,7 +77,7 @@
export
mk_param
;
export
mk_ptr
;
export
mk_rec
;
export
mk_
tag
;
export
mk_
enum
;
export
mk_tup
;
export
mk_type
;
export
mk_send_type
;
...
...
@@ -101,9 +101,9 @@
export
substitute_type_params
;
export
t
;
export
new_ty_hash
;
export
tag
_variants
;
export
enum
_variants
;
export
iface_methods
,
store_iface_methods
,
impl_iface
;
export
tag
_variant_with_id
;
export
enum
_variant_with_id
;
export
ty_param_substs_opt_and_ty
;
export
ty_param_bounds_and_ty
;
export
ty_native_fn
;
...
...
@@ -128,7 +128,7 @@
export
ty_param
;
export
ty_ptr
;
export
ty_rec
;
export
ty_
tag
;
export
ty_
enum
;
export
ty_tup
;
export
ty_type
;
export
ty_send_type
;
...
...
@@ -172,7 +172,7 @@
export
type_is_tup_like
;
export
type_is_str
;
export
type_is_unique
;
export
type_is_
tag
;
export
type_is_
enum
;
export
type_is_c_like_enum
;
export
type_structurally_contains_uniques
;
export
type_autoderef
;
...
...
@@ -221,7 +221,7 @@
needs_drop_cache
:
hashmap
<
t
,
bool
>
,
kind_cache
:
hashmap
<
t
,
kind
>
,
ast_ty_to_ty_cache
:
hashmap
<@
ast
::
ty
,
option
::
t
<
t
>>
,
tag
_var_cache
:
hashmap
<
def_id
,
@
[
variant_info
]
>
,
enum
_var_cache
:
hashmap
<
def_id
,
@
[
variant_info
]
>
,
iface_method_cache
:
hashmap
<
def_id
,
@
[
method
]
>
,
ty_param_bounds
:
hashmap
<
ast
::
node_id
,
param_bounds
>
};
...
...
@@ -258,7 +258,7 @@ enum sty {
ty_uint
(
ast
::
uint_ty
),
ty_float
(
ast
::
float_ty
),
ty_str
,
ty_
tag
(
def_id
,
[
t
]),
ty_
enum
(
def_id
,
[
t
]),
ty_box
(
mt
),
ty_uniq
(
mt
),
ty_vec
(
mt
),
...
...
@@ -437,7 +437,7 @@ fn eq_raw_ty(&&a: @raw_t, &&b: @raw_t) -> bool {
kind_cache
:
new_ty_hash
(),
ast_ty_to_ty_cache
:
map
::
mk_hashmap
(
ast_util
::
hash_ty
,
ast_util
::
eq_ty
),
tag
_var_cache
:
new_def_hash
(),
enum
_var_cache
:
new_def_hash
(),
iface_method_cache
:
new_def_hash
(),
ty_param_bounds
:
map
::
new_int_hash
()};
populate_type_store
(
cx
);
...
...
@@ -475,7 +475,7 @@ fn derive_flags_sig(cx: ctxt, &has_params: bool, &has_vars: bool,
}
ty_param
(
_
,
_
)
{
has_params
=
true
;
}
ty_var
(
_
)
{
has_vars
=
true
;
}
ty_
tag
(
_
,
tys
)
|
ty_iface
(
_
,
tys
)
{
ty_
enum
(
_
,
tys
)
|
ty_iface
(
_
,
tys
)
{
for
tt
:
t
in
tys
{
derive_flags_t
(
cx
,
has_params
,
has_vars
,
tt
);
}
}
ty_box
(
m
)
{
derive_flags_mt
(
cx
,
has_params
,
has_vars
,
m
);
}
...
...
@@ -567,8 +567,8 @@ fn mk_mach_float(_cx: ctxt, tm: ast::float_ty) -> t {
fn
mk_str
(
_
cx
:
ctxt
)
->
t
{
ret
idx_str
;
}
fn
mk_
tag
(
cx
:
ctxt
,
did
:
ast
::
def_id
,
tys
:
[
t
])
->
t
{
ret
gen_ty
(
cx
,
ty_
tag
(
did
,
tys
));
fn
mk_
enum
(
cx
:
ctxt
,
did
:
ast
::
def_id
,
tys
:
[
t
])
->
t
{
ret
gen_ty
(
cx
,
ty_
enum
(
did
,
tys
));
}
fn
mk_box
(
cx
:
ctxt
,
tm
:
mt
)
->
t
{
ret
gen_ty
(
cx
,
ty_box
(
tm
));
}
...
...
@@ -685,7 +685,7 @@ fn walk_ty(cx: ctxt, walker: ty_walk, ty: t) {
/* no-op */
}
ty_box
(
tm
)
|
ty_vec
(
tm
)
|
ty_ptr
(
tm
)
{
walk_ty
(
cx
,
walker
,
tm
.ty
);
}
ty_
tag
(
_
,
subtys
)
|
ty_iface
(
_
,
subtys
)
{
ty_
enum
(
_
,
subtys
)
|
ty_iface
(
_
,
subtys
)
{
for
subty
:
t
in
subtys
{
walk_ty
(
cx
,
walker
,
subty
);
}
}
ty_rec
(
fields
)
{
...
...
@@ -748,8 +748,8 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
ty_vec
(
tm
)
{
ty
=
mk_vec
(
cx
,
{
ty
:
fold_ty
(
cx
,
fld
,
tm
.ty
),
mut
:
tm
.mut
});
}
ty_
tag
(
tid
,
subtys
)
{
ty
=
mk_
tag
(
cx
,
tid
,
vec
::
map
(
subtys
,
{|
t
|
fold_ty
(
cx
,
fld
,
t
)
}));
ty_
enum
(
tid
,
subtys
)
{
ty
=
mk_
enum
(
cx
,
tid
,
vec
::
map
(
subtys
,
{|
t
|
fold_ty
(
cx
,
fld
,
t
)
}));
}
ty_iface
(
did
,
subtys
)
{
ty
=
mk_iface
(
cx
,
did
,
vec
::
map
(
subtys
,
{|
t
|
fold_ty
(
cx
,
fld
,
t
)
}));
...
...
@@ -826,7 +826,7 @@ fn type_is_bool(cx: ctxt, ty: t) -> bool {
fn
type_is_structural
(
cx
:
ctxt
,
ty
:
t
)
->
bool
{
alt
struct
(
cx
,
ty
)
{
ty_rec
(
_
)
|
ty_tup
(
_
)
|
ty_
tag
(
_
,
_
)
|
ty_fn
(
_
)
|
ty_rec
(
_
)
|
ty_tup
(
_
)
|
ty_
enum
(
_
,
_
)
|
ty_fn
(
_
)
|
ty_native_fn
(
_
,
_
)
|
ty_res
(
_
,
_
,
_
)
{
true
}
_
{
false
}
}
...
...
@@ -954,8 +954,8 @@ fn type_needs_drop(cx: ctxt, ty: t) -> bool {
for
m
in
elts
{
if
type_needs_drop
(
cx
,
m
)
{
accum
=
true
;
}
}
accum
}
ty_
tag
(
did
,
tps
)
{
let
variants
=
tag
_variants
(
cx
,
did
);
ty_
enum
(
did
,
tps
)
{
let
variants
=
enum
_variants
(
cx
,
did
);
for
variant
in
*
variants
{
for
aty
in
variant
.args
{
// Perform any type parameter substitutions.
...
...
@@ -1052,10 +1052,10 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
for
ty
in
tys
{
lowest
=
lower_kind
(
lowest
,
type_kind
(
cx
,
ty
));
}
lowest
}
//
Tag
s lower to the lowest of their variants.
ty_
tag
(
did
,
tps
)
{
//
Enum
s lower to the lowest of their variants.
ty_
enum
(
did
,
tps
)
{
let
lowest
=
kind_sendable
;
for
variant
in
*
tag
_variants
(
cx
,
did
)
{
for
variant
in
*
enum
_variants
(
cx
,
did
)
{
for
aty
in
variant
.args
{
// Perform any type parameter substitutions.
let
arg_ty
=
substitute_type_params
(
cx
,
tps
,
aty
);
...
...
@@ -1088,8 +1088,8 @@ fn type_structurally_contains(cx: ctxt, ty: t, test: fn(sty) -> bool) ->
let
sty
=
struct
(
cx
,
ty
);
if
test
(
sty
)
{
ret
true
;
}
alt
sty
{
ty_
tag
(
did
,
tps
)
{
for
variant
in
*
tag
_variants
(
cx
,
did
)
{
ty_
enum
(
did
,
tps
)
{
for
variant
in
*
enum
_variants
(
cx
,
did
)
{
for
aty
in
variant
.args
{
let
sty
=
substitute_type_params
(
cx
,
tps
,
aty
);
if
type_structurally_contains
(
cx
,
sty
,
test
)
{
ret
true
;
}
...
...
@@ -1207,8 +1207,8 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
ty_str
|
ty_box
(
_
)
|
ty_uniq
(
_
)
|
ty_vec
(
_
)
|
ty_fn
(
_
)
|
ty_native_fn
(
_
,
_
)
|
ty_iface
(
_
,
_
)
{
result
=
false
;
}
// Structural types
ty_
tag
(
did
,
tps
)
{
let
variants
=
tag
_variants
(
cx
,
did
);
ty_
enum
(
did
,
tps
)
{
let
variants
=
enum
_variants
(
cx
,
did
);
for
variant
:
variant_info
in
*
variants
{
let
tup_ty
=
mk_tup
(
cx
,
variant
.args
);
...
...
@@ -1238,9 +1238,9 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
ret
result
;
}
fn
type_is_
tag
(
cx
:
ctxt
,
ty
:
t
)
->
bool
{
fn
type_is_
enum
(
cx
:
ctxt
,
ty
:
t
)
->
bool
{
alt
struct
(
cx
,
ty
)
{
ty_
tag
(
_
,
_
)
{
ret
true
;
}
ty_
enum
(
_
,
_
)
{
ret
true
;
}
_
{
ret
false
;}
}
}
...
...
@@ -1249,8 +1249,8 @@ fn type_is_tag(cx: ctxt, ty: t) -> bool {
// constructors
fn
type_is_c_like_enum
(
cx
:
ctxt
,
ty
:
t
)
->
bool
{
alt
struct
(
cx
,
ty
)
{
ty_
tag
(
did
,
tps
)
{
let
variants
=
tag
_variants
(
cx
,
did
);
ty_
enum
(
did
,
tps
)
{
let
variants
=
enum
_variants
(
cx
,
did
);
let
some_n_ary
=
vec
::
any
(
*
variants
,
{|
v
|
vec
::
len
(
v
.args
)
>
0u
});
ret
!
some_n_ary
;
}
...
...
@@ -1287,8 +1287,8 @@ fn type_autoderef(cx: ctxt, t: ty::t) -> ty::t {
ty_res
(
_
,
inner
,
tps
)
{
t1
=
substitute_type_params
(
cx
,
tps
,
inner
);
}
ty_
tag
(
did
,
tps
)
{
let
variants
=
tag
_variants
(
cx
,
did
);
ty_
enum
(
did
,
tps
)
{
let
variants
=
enum
_variants
(
cx
,
did
);
if
vec
::
len
(
*
variants
)
!=
1u
||
vec
::
len
(
variants
[
0
]
.args
)
!=
1u
{
break
;
}
...
...
@@ -1372,7 +1372,7 @@ fn hash_fn(id: uint, args: [arg], rty: t) -> uint {
alt
t
{
ast
::
ty_f
{
13u
}
ast
::
ty_f32
{
14u
}
ast
::
ty_f64
{
15u
}
}
}
ty_str
{
ret
17u
;
}
ty_
tag
(
did
,
tys
)
{
ty_
enum
(
did
,
tys
)
{
let
h
=
hash_def
(
18u
,
did
);
for
typ
:
t
in
tys
{
h
+=
(
h
<<
5u
)
+
typ
;
}
ret
h
;
...
...
@@ -2182,14 +2182,14 @@ fn unify_step(cx: @ctxt, expected: t, actual: t,
_
{
ret
ures_err
(
terr_mismatch
);
}
}
}
ty
::
ty_
tag
(
expected_id
,
expected_tps
)
{
ty
::
ty_
enum
(
expected_id
,
expected_tps
)
{
alt
struct
(
cx
.tcx
,
actual
)
{
ty
::
ty_
tag
(
actual_id
,
actual_tps
)
{
ty
::
ty_
enum
(
actual_id
,
actual_tps
)
{
if
expected_id
!=
actual_id
{
ret
ures_err
(
terr_mismatch
);
}
ret
unify_tps
(
cx
,
expected_tps
,
actual_tps
,
variance
,
{|
tps
|
ures_ok
(
mk_
tag
(
cx
.tcx
,
expected_id
,
tps
))
ures_ok
(
mk_
enum
(
cx
.tcx
,
expected_id
,
tps
))
});
}
_
{
/* fall through */
}
...
...
@@ -2628,23 +2628,23 @@ fn impl_iface(cx: ctxt, id: ast::def_id) -> option::t<t> {
}
}
//
Tag
information
//
Enum
information
type
variant_info
=
@
{
args
:
[
ty
::
t
],
ctor_ty
:
ty
::
t
,
name
:
str
,
id
:
ast
::
def_id
,
disr_val
:
int
};
fn
tag
_variants
(
cx
:
ctxt
,
id
:
ast
::
def_id
)
->
@
[
variant_info
]
{
alt
cx
.
tag
_var_cache
.find
(
id
)
{
fn
enum
_variants
(
cx
:
ctxt
,
id
:
ast
::
def_id
)
->
@
[
variant_info
]
{
alt
cx
.
enum
_var_cache
.find
(
id
)
{
some
(
variants
)
{
ret
variants
;
}
_
{
/* fallthrough */
}
}
let
result
=
if
ast
::
local_crate
!=
id
.crate
{
@
csearch
::
get_
tag
_variants
(
cx
,
id
)
@
csearch
::
get_
enum
_variants
(
cx
,
id
)
}
else
{
// FIXME: Now that the variants are run through the type checker (to
// check the disr_expr if it exists), this code should likely be
// moved there to avoid having to call eval_const_expr twice.
alt
cx
.items
.get
(
id
.node
)
{
ast_map
::
node_item
(
@
{
node
:
ast
::
item_
tag
(
variants
,
_
),
_
})
{
ast_map
::
node_item
(
@
{
node
:
ast
::
item_
enum
(
variants
,
_
),
_
})
{
let
disr_val
=
-
1
;
@
vec
::
map
(
variants
,
{|
variant
|
let
ctor_ty
=
node_id_to_monotype
(
cx
,
variant
.node.id
);
...
...
@@ -2670,22 +2670,22 @@ fn tag_variants(cx: ctxt, id: ast::def_id) -> @[variant_info] {
}
}
};
cx
.
tag
_var_cache
.insert
(
id
,
result
);
cx
.
enum
_var_cache
.insert
(
id
,
result
);
result
}
// Returns information about the enum variant with the given ID:
fn
tag_variant_with_id
(
cx
:
ctxt
,
tag_id
:
ast
::
def_id
,
variant_id
:
ast
::
def_id
)
->
variant_info
{
let
variants
=
tag_variants
(
cx
,
tag
_id
);
fn
enum_variant_with_id
(
cx
:
ctxt
,
enum_id
:
ast
::
def_id
,
variant_id
:
ast
::
def_id
)
->
variant_info
{
let
variants
=
enum_variants
(
cx
,
enum
_id
);
let
i
=
0u
;
while
i
<
vec
::
len
::
<
variant_info
>
(
*
variants
)
{
let
variant
=
variants
[
i
];
if
def_eq
(
variant
.id
,
variant_id
)
{
ret
variant
;
}
i
+=
1u
;
}
cx
.sess
.bug
(
"
tag
_variant_with_id(): no variant exists with that ID"
);
cx
.sess
.bug
(
"
enum
_variant_with_id(): no variant exists with that ID"
);
}
...
...
@@ -2766,7 +2766,7 @@ fn tycat(cx: ctxt, ty: t) -> int {
ty_vec
(
_
)
{
tycat_vec
}
ty_rec
(
_
)
{
tycat_struct
}
ty_tup
(
_
)
{
tycat_struct
}
ty_
tag
(
_
,
_
)
{
tycat_struct
}
ty_
enum
(
_
,
_
)
{
tycat_struct
}
ty_bot
{
tycat_bot
}
_
{
tycat_other
}
}
...
...
src/comp/middle/typeck.rs
浏览文件 @
76aabbe9
...
...
@@ -405,10 +405,10 @@ fn ty_of_item(tcx: ty::ctxt, mode: mode, it: @ast::item)
tcx
.tcache
.insert
(
local_def
(
it
.id
),
t_res
);
ret
t_res
;
}
ast
::
item_
tag
(
_
,
tps
)
{
ast
::
item_
enum
(
_
,
tps
)
{
// Create a new generic polytype.
let
{
bounds
,
params
}
=
mk_ty_params
(
tcx
,
tps
);
let
t
=
ty
::
mk_named
(
tcx
,
ty
::
mk_
tag
(
tcx
,
local_def
(
it
.id
),
params
),
let
t
=
ty
::
mk_named
(
tcx
,
ty
::
mk_
enum
(
tcx
,
local_def
(
it
.id
),
params
),
@
it
.ident
);
let
tpt
=
{
bounds
:
bounds
,
ty
:
t
};
tcx
.tcache
.insert
(
local_def
(
it
.id
),
tpt
);
...
...
@@ -644,7 +644,7 @@ fn compare_impl_method(tcx: ty::ctxt, sp: span, impl_m: ty::method,
mod
collect
{
type
ctxt
=
{
tcx
:
ty
::
ctxt
};
fn
get_
tag_variant_types
(
cx
:
@
ctxt
,
tag
_ty
:
ty
::
t
,
fn
get_
enum_variant_types
(
cx
:
@
ctxt
,
enum
_ty
:
ty
::
t
,
variants
:
[
ast
::
variant
],
ty_params
:
[
ast
::
ty_param
])
{
// Create a set of parameter types shared among all the variants.
...
...
@@ -654,7 +654,7 @@ fn get_tag_variant_types(cx: @ctxt, tag_ty: ty::t,
// constructors get turned into functions.
let
result_ty
=
if
vec
::
len
(
variant
.node.args
)
==
0u
{
tag
_ty
enum
_ty
}
else
{
// As above, tell ast_ty_to_ty() that trans_ty_item_to_ty()
// should be called to resolve named types.
...
...
@@ -666,7 +666,7 @@ fn get_tag_variant_types(cx: @ctxt, tag_ty: ty::t,
// FIXME: this will be different for constrained types
ty
::
mk_fn
(
cx
.tcx
,
{
proto
:
ast
::
proto_box
,
inputs
:
args
,
output
:
tag
_ty
,
inputs
:
args
,
output
:
enum
_ty
,
ret_style
:
ast
::
return_val
,
constraints
:
[]})
};
let
tpt
=
{
bounds
:
ty_param_bounds
(
cx
.tcx
,
m_collect
,
ty_params
),
...
...
@@ -679,10 +679,10 @@ fn convert(cx: @ctxt, it: @ast::item) {
alt
it
.node
{
// These don't define types.
ast
::
item_mod
(
_
)
|
ast
::
item_native_mod
(
_
)
{}
ast
::
item_
tag
(
variants
,
ty_params
)
{
ast
::
item_
enum
(
variants
,
ty_params
)
{
let
tpt
=
ty_of_item
(
cx
.tcx
,
m_collect
,
it
);
write
::
ty_only
(
cx
.tcx
,
it
.id
,
tpt
.ty
);
get_
tag
_variant_types
(
cx
,
tpt
.ty
,
variants
,
ty_params
);
get_
enum
_variant_types
(
cx
,
tpt
.ty
,
variants
,
ty_params
);
}
ast
::
item_impl
(
tps
,
ifce
,
selfty
,
ms
)
{
let
i_bounds
=
ty_param_bounds
(
cx
.tcx
,
m_collect
,
tps
);
...
...
@@ -826,8 +826,8 @@ fn do_autoderef(fcx: @fn_ctxt, sp: span, t: ty::t) -> ty::t {
ty
::
ty_res
(
_
,
inner
,
tps
)
{
t1
=
ty
::
substitute_type_params
(
fcx
.ccx.tcx
,
tps
,
inner
);
}
ty
::
ty_
tag
(
did
,
tps
)
{
let
variants
=
ty
::
tag
_variants
(
fcx
.ccx.tcx
,
did
);
ty
::
ty_
enum
(
did
,
tps
)
{
let
variants
=
ty
::
enum
_variants
(
fcx
.ccx.tcx
,
did
);
if
vec
::
len
(
*
variants
)
!=
1u
||
vec
::
len
(
variants
[
0
]
.args
)
!=
1u
{
ret
t1
;
}
...
...
@@ -923,7 +923,7 @@ fn are_compatible(fcx: @fn_ctxt, expected: ty::t, actual: ty::t) -> bool {
// Returns the types of the arguments to a enum variant.
fn
variant_arg_types
(
ccx
:
@
crate_ctxt
,
_
sp
:
span
,
vid
:
ast
::
def_id
,
tag
_ty_params
:
[
ty
::
t
])
->
[
ty
::
t
]
{
enum
_ty_params
:
[
ty
::
t
])
->
[
ty
::
t
]
{
let
result
:
[
ty
::
t
]
=
[];
let
tpt
=
ty
::
lookup_item_type
(
ccx
.tcx
,
vid
);
alt
ty
::
struct
(
ccx
.tcx
,
tpt
.ty
)
{
...
...
@@ -931,7 +931,7 @@ fn variant_arg_types(ccx: @crate_ctxt, _sp: span, vid: ast::def_id,
// N-ary variant.
for
arg
:
ty
::
arg
in
f
.inputs
{
let
arg_ty
=
ty
::
substitute_type_params
(
ccx
.tcx
,
tag
_ty_params
,
arg
.ty
);
ty
::
substitute_type_params
(
ccx
.tcx
,
enum
_ty_params
,
arg
.ty
);
result
+=
[
arg_ty
];
}
}
...
...
@@ -1187,7 +1187,7 @@ fn check_pat(fcx: @fn_ctxt, map: pat_util::pat_id_map, pat: @ast::pat,
alt
normalize_pat
(
fcx
.ccx.tcx
,
pat
)
.node
{
ast
::
pat_wild
{
alt
structure_of
(
fcx
,
pat
.span
,
expected
)
{
ty
::
ty_
tag
(
_
,
expected_tps
)
{
ty
::
ty_
enum
(
_
,
expected_tps
)
{
let
path_tpt
=
{
substs
:
some
(
expected_tps
),
ty
:
expected
};
write
::
ty_fixup
(
fcx
,
pat
.id
,
path_tpt
);
...
...
@@ -1236,16 +1236,16 @@ fn check_pat(fcx: @fn_ctxt, map: pat_util::pat_id_map, pat: @ast::pat,
_
{}
}
}
ast
::
pat_
tag
(
path
,
subpats
)
{
ast
::
pat_
enum
(
path
,
subpats
)
{
// Typecheck the path.
let
v_def
=
lookup_def
(
fcx
,
path
.span
,
pat
.id
);
let
v_def_ids
=
ast_util
::
variant_def_ids
(
v_def
);
let
tag
_tpt
=
ty
::
lookup_item_type
(
fcx
.ccx.tcx
,
v_def_ids
.tg
);
let
path_tpot
=
instantiate_path
(
fcx
,
path
,
tag
_tpt
,
pat
.span
);
let
enum
_tpt
=
ty
::
lookup_item_type
(
fcx
.ccx.tcx
,
v_def_ids
.tg
);
let
path_tpot
=
instantiate_path
(
fcx
,
path
,
enum
_tpt
,
pat
.span
);
// Take the enum type params out of `expected`.
alt
structure_of
(
fcx
,
pat
.span
,
expected
)
{
ty
::
ty_
tag
(
_
,
expected_tps
)
{
ty
::
ty_
enum
(
_
,
expected_tps
)
{
// Unify with the expected enum type.
let
ctor_ty
=
ty
::
ty_param_substs_opt_and_ty_to_monotype
(
fcx
.ccx.tcx
,
...
...
@@ -1837,12 +1837,12 @@ fn check_binop_type_compat(fcx: @fn_ctxt, span: span, ty: ty::t,
ty
::
ty_box
(
inner
)
{
oper_t
=
inner
.ty
;
}
ty
::
ty_uniq
(
inner
)
{
oper_t
=
inner
.ty
;
}
ty
::
ty_res
(
_
,
inner
,
_
)
{
oper_t
=
inner
;
}
ty
::
ty_
tag
(
id
,
tps
)
{
let
variants
=
ty
::
tag
_variants
(
tcx
,
id
);
ty
::
ty_
enum
(
id
,
tps
)
{
let
variants
=
ty
::
enum
_variants
(
tcx
,
id
);
if
vec
::
len
(
*
variants
)
!=
1u
||
vec
::
len
(
variants
[
0
]
.args
)
!=
1u
{
tcx
.sess
.span_fatal
(
expr
.span
,
"can only dereference
tag
s "
+
"can only dereference
enum
s "
+
"with a single variant which has a "
+
"single argument"
);
}
...
...
@@ -2463,7 +2463,7 @@ fn check_const(ccx: @crate_ctxt, _sp: span, e: @ast::expr, id: ast::node_id) {
demand
::
simple
(
fcx
,
e
.span
,
declty
,
cty
);
}
fn
check_
tag
_variants
(
ccx
:
@
crate_ctxt
,
_
sp
:
span
,
vs
:
[
ast
::
variant
],
fn
check_
enum
_variants
(
ccx
:
@
crate_ctxt
,
_
sp
:
span
,
vs
:
[
ast
::
variant
],
id
:
ast
::
node_id
)
{
// FIXME: this is kinda a kludge; we manufacture a fake function context
// and statement context for checking the initializer expression.
...
...
@@ -2683,7 +2683,7 @@ fn check_method(ccx: @crate_ctxt, method: @ast::method) {
fn
check_item
(
ccx
:
@
crate_ctxt
,
it
:
@
ast
::
item
)
{
alt
it
.node
{
ast
::
item_const
(
_
,
e
)
{
check_const
(
ccx
,
it
.span
,
e
,
it
.id
);
}
ast
::
item_
tag
(
vs
,
_
)
{
check_tag
_variants
(
ccx
,
it
.span
,
vs
,
it
.id
);
}
ast
::
item_
enum
(
vs
,
_
)
{
check_enum
_variants
(
ccx
,
it
.span
,
vs
,
it
.id
);
}
ast
::
item_fn
(
decl
,
tps
,
body
)
{
check_fn
(
ccx
,
ast
::
proto_bare
,
decl
,
body
,
it
.id
,
none
);
}
...
...
src/comp/syntax/ast.rs
浏览文件 @
76aabbe9
...
...
@@ -103,12 +103,12 @@ enum pat_ {
// In the nullary enum case, the parser can't determine
// which it is. The resolver determines this, and
// records this pattern's node_id in an auxiliary
// set (of "pat_idents that refer to nullary
tag
s")
// set (of "pat_idents that refer to nullary
enum
s")
// After the resolution phase, code should never pattern-
// match on a pat directly! Always call pat_util::normalize_pat --
// it turns any pat_idents that refer to nullary
tags into pat_tag
s.
// it turns any pat_idents that refer to nullary
enums into pat_enum
s.
pat_ident
(
@
path
,
option
::
t
<@
pat
>
),
pat_
tag
(
@
path
,
[
@
pat
]),
pat_
enum
(
@
path
,
[
@
pat
]),
pat_rec
([
field_pat
],
bool
),
pat_tup
([
@
pat
]),
pat_box
(
@
pat
),
...
...
@@ -440,9 +440,9 @@ enum view_item_ {
view_item_import_from
(
@
simple_path
,
[
import_ident
],
node_id
),
view_item_export
([
ident
],
node_id
),
// export foo::{}
view_item_export_
tag
_none
(
ident
,
node_id
),
view_item_export_
enum
_none
(
ident
,
node_id
),
// export foo::{bar, baz, blat}
view_item_export_
tag
_some
(
ident
,
[
import_ident
],
node_id
)
view_item_export_
enum
_some
(
ident
,
[
import_ident
],
node_id
)
}
// Meta-data associated with an item
...
...
@@ -465,7 +465,7 @@ enum item_ {
item_mod
(
_
mod
),
item_native_mod
(
native_mod
),
item_ty
(
@
ty
,
[
ty_param
]),
item_
tag
([
variant
],
[
ty_param
]),
item_
enum
([
variant
],
[
ty_param
]),
item_res
(
fn_decl
/* dtor */
,
[
ty_param
],
blk
,
node_id
/* dtor id */
,
node_id
/* ctor id */
),
item_iface
([
ty_param
],
[
ty_method
]),
...
...
src/comp/syntax/ast_util.rs
浏览文件 @
76aabbe9
...
...
@@ -20,7 +20,7 @@ fn path_name_i(idents: [ident]) -> str { str::connect(idents, "::") }
fn
local_def
(
id
:
node_id
)
->
def_id
{
ret
{
crate
:
local_crate
,
node
:
id
};
}
fn
variant_def_ids
(
d
:
def
)
->
{
tg
:
def_id
,
var
:
def_id
}
{
alt
d
{
def_variant
(
tag_id
,
var_id
)
{
ret
{
tg
:
tag
_id
,
var
:
var_id
};
}
}
alt
d
{
def_variant
(
enum_id
,
var_id
)
{
ret
{
tg
:
enum
_id
,
var
:
var_id
};
}
}
}
fn
def_id_of_def
(
d
:
def
)
->
def_id
{
...
...
@@ -113,15 +113,15 @@ fn float_ty_to_str(t: float_ty) -> str {
fn
is_exported
(
i
:
ident
,
m
:
_
mod
)
->
bool
{
let
nonlocal
=
true
;
let
parent_
tag
:
option
<
ident
>
=
none
;
let
parent_
enum
:
option
<
ident
>
=
none
;
for
it
:
@
item
in
m
.items
{
if
it
.ident
==
i
{
nonlocal
=
false
;
}
alt
it
.node
{
item_
tag
(
variants
,
_
)
{
item_
enum
(
variants
,
_
)
{
for
v
:
variant
in
variants
{
if
v
.node.name
==
i
{
nonlocal
=
false
;
parent_
tag
=
some
(
it
.ident
);
parent_
enum
=
some
(
it
.ident
);
}
}
}
...
...
@@ -133,24 +133,24 @@ fn is_exported(i: ident, m: _mod) -> bool {
for
vi
:
@
view_item
in
m
.view_items
{
alt
vi
.node
{
view_item_export
(
ids
,
_
)
{
// If any of ids is a
tag
, we want to consider
// If any of ids is a
enum
, we want to consider
// all the variants to be exported
for
id
in
ids
{
if
str
::
eq
(
i
,
id
)
{
ret
true
;
}
alt
parent_
tag
{
some
(
parent_
tag
_id
)
{
if
str
::
eq
(
id
,
parent_
tag
_id
)
{
ret
true
;
}
alt
parent_
enum
{
some
(
parent_
enum
_id
)
{
if
str
::
eq
(
id
,
parent_
enum
_id
)
{
ret
true
;
}
}
_
{
}
}
}
count
+=
1u
;
}
view_item_export_
tag
_none
(
id
,
_
)
{
view_item_export_
enum
_none
(
id
,
_
)
{
if
str
::
eq
(
i
,
id
)
{
ret
true
;
}
count
+=
1u
;
}
view_item_export_
tag
_some
(
id
,
ids
,
_
)
{
view_item_export_
enum
_some
(
id
,
ids
,
_
)
{
if
str
::
eq
(
i
,
id
)
{
ret
true
;
}
for
id
in
ids
{
if
str
::
eq
(
i
,
id
.node.name
)
{
ret
true
;
}
}
count
+=
1u
;
...
...
@@ -278,7 +278,8 @@ fn fromb(b: bool) -> const_val { const_int(b as i64) }
mul
{
const_uint
(
a
*
b
)
}
div
{
const_uint
(
a
/
b
)
}
rem
{
const_uint
(
a
%
b
)
}
and
|
bitand
{
const_uint
(
a
&
b
)
}
or
|
bitor
{
const_uint
(
a
|
b
)
}
bitxor
{
const_uint
(
a
^
b
)
}
lsl
{
const_int
(
a
<<
b
as
i64
)
}
lsr
{
const_int
(
a
>>
b
as
i64
)
}
lsl
{
const_int
(
a
<<
b
as
i64
)
}
lsr
{
const_int
(
a
>>
b
as
i64
)
}
asr
{
const_int
(
a
>>>
b
as
i64
)
}
eq
{
fromb
(
a
==
b
)
}
lt
{
fromb
(
a
<
b
)
}
le
{
fromb
(
a
<=
b
)
}
ne
{
fromb
(
a
!=
b
)
}
...
...
src/comp/syntax/fold.rs
浏览文件 @
76aabbe9
...
...
@@ -226,8 +226,8 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
item_mod
(
m
)
{
item_mod
(
fld
.fold_mod
(
m
))
}
item_native_mod
(
nm
)
{
item_native_mod
(
fld
.fold_native_mod
(
nm
))
}
item_ty
(
t
,
typms
)
{
item_ty
(
fld
.fold_ty
(
t
),
typms
)
}
item_
tag
(
variants
,
typms
)
{
item_
tag
(
vec
::
map
(
variants
,
fld
.fold_variant
),
typms
)
item_
enum
(
variants
,
typms
)
{
item_
enum
(
vec
::
map
(
variants
,
fld
.fold_variant
),
typms
)
}
item_impl
(
tps
,
ifce
,
ty
,
methods
)
{
item_impl
(
tps
,
option
::
map
(
ifce
,
fld
.fold_ty
),
fld
.fold_ty
(
ty
),
...
...
@@ -279,8 +279,8 @@ fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
pat_ident
(
fld
.fold_path
(
pth
),
option
::
map
(
sub
,
fld
.fold_pat
))
}
pat_lit
(
_
)
{
p
}
pat_
tag
(
pth
,
pats
)
{
pat_
tag
(
fld
.fold_path
(
pth
),
vec
::
map
(
pats
,
fld
.fold_pat
))
pat_
enum
(
pth
,
pats
)
{
pat_
enum
(
fld
.fold_path
(
pth
),
vec
::
map
(
pats
,
fld
.fold_pat
))
}
pat_rec
(
fields
,
etc
)
{
let
fs
=
[];
...
...
src/comp/syntax/parse/parser.rs
浏览文件 @
76aabbe9
...
...
@@ -1501,8 +1501,8 @@ fn parse_pat(p: parser) -> @ast::pat {
let
sub
=
eat
(
p
,
token
::
AT
)
?
some
(
parse_pat
(
p
))
:
none
;
pat
=
ast
::
pat_ident
(
name
,
sub
);
}
else
{
let
tag
_path
=
parse_path_and_ty_param_substs
(
p
,
true
);
hi
=
tag
_path
.span.hi
;
let
enum
_path
=
parse_path_and_ty_param_substs
(
p
,
true
);
hi
=
enum
_path
.span.hi
;
let
args
:
[
@
ast
::
pat
];
alt
p
.token
{
token
::
LPAREN
{
...
...
@@ -1516,11 +1516,11 @@ fn parse_pat(p: parser) -> @ast::pat {
}
// at this point, we're not sure whether it's a enum or a bind
if
vec
::
len
(
args
)
==
0u
&&
vec
::
len
(
tag
_path
.node.idents
)
==
1u
{
pat
=
ast
::
pat_ident
(
tag
_path
,
none
);
vec
::
len
(
enum
_path
.node.idents
)
==
1u
{
pat
=
ast
::
pat_ident
(
enum
_path
,
none
);
}
else
{
pat
=
ast
::
pat_
tag
(
tag
_path
,
args
);
pat
=
ast
::
pat_
enum
(
enum
_path
,
args
);
}
}
}
...
...
@@ -2024,7 +2024,7 @@ fn parse_item_type(p: parser, attrs: [ast::attribute]) -> @ast::item {
ret
mk_item
(
p
,
t
.lo
,
hi
,
t
.ident
,
ast
::
item_ty
(
ty
,
tps
),
attrs
);
}
fn
parse_item_
tag
(
p
:
parser
,
attrs
:
[
ast
::
attribute
])
->
@
ast
::
item
{
fn
parse_item_
enum
(
p
:
parser
,
attrs
:
[
ast
::
attribute
])
->
@
ast
::
item
{
let
lo
=
p
.last_span.lo
;
let
id
=
parse_ident
(
p
);
let
ty_params
=
parse_ty_params
(
p
);
...
...
@@ -2044,7 +2044,7 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
id
:
p
.get_id
(),
disr_expr
:
none
});
ret
mk_item
(
p
,
lo
,
ty
.span.hi
,
id
,
ast
::
item_
tag
([
variant
],
ty_params
),
attrs
);
ast
::
item_
enum
([
variant
],
ty_params
),
attrs
);
}
expect
(
p
,
token
::
LBRACE
);
let
all_nullary
=
true
,
have_disr
=
false
;
...
...
@@ -2077,7 +2077,7 @@ fn parse_item_tag(p: parser, attrs: [ast::attribute]) -> @ast::item {
p
.fatal
(
"discriminator values can only be used with a c-like enum"
);
}
ret
mk_item
(
p
,
lo
,
p
.last_span.hi
,
id
,
ast
::
item_
tag
(
variants
,
ty_params
),
attrs
);
ast
::
item_
enum
(
variants
,
ty_params
),
attrs
);
}
fn
parse_fn_ty_proto
(
p
:
parser
)
->
ast
::
proto
{
...
...
@@ -2134,7 +2134,7 @@ fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> {
}
if
eat_word
(
p
,
"type"
)
{
ret
some
(
parse_item_type
(
p
,
attrs
));
}
else
if
eat_word
(
p
,
"enum"
)
{
ret
some
(
parse_item_
tag
(
p
,
attrs
));
ret
some
(
parse_item_
enum
(
p
,
attrs
));
}
else
if
eat_word
(
p
,
"iface"
)
{
ret
some
(
parse_item_iface
(
p
,
attrs
));
}
else
if
eat_word
(
p
,
"impl"
)
{
...
...
@@ -2364,16 +2364,16 @@ fn parse_import(p: parser) -> ast::view_item_ {
}
}
fn
parse_
tag
_export
(
p
:
parser
,
tyname
:
ast
::
ident
)
->
ast
::
view_item_
{
let
tag
names
:[
ast
::
import_ident
]
=
fn
parse_
enum
_export
(
p
:
parser
,
tyname
:
ast
::
ident
)
->
ast
::
view_item_
{
let
enum
names
:[
ast
::
import_ident
]
=
parse_seq
(
token
::
LBRACE
,
token
::
RBRACE
,
seq_sep
(
token
::
COMMA
),
{|
p
|
parse_import_ident
(
p
)
},
p
)
.node
;
let
id
=
p
.get_id
();
if
vec
::
is_empty
(
tag
names
)
{
ret
ast
::
view_item_export_
tag
_none
(
tyname
,
id
);
if
vec
::
is_empty
(
enum
names
)
{
ret
ast
::
view_item_export_
enum
_none
(
tyname
,
id
);
}
else
{
ret
ast
::
view_item_export_
tag_some
(
tyname
,
tag
names
,
id
);
ret
ast
::
view_item_export_
enum_some
(
tyname
,
enum
names
,
id
);
}
}
...
...
@@ -2382,7 +2382,7 @@ fn parse_export(p: parser) -> ast::view_item_ {
alt
p
.token
{
token
::
MOD_SEP
{
p
.bump
();
ret
parse_
tag
_export
(
p
,
first
);
ret
parse_
enum
_export
(
p
,
first
);
}
t
{
if
t
==
token
::
COMMA
{
p
.bump
();
}
...
...
src/comp/syntax/print/pprust.rs
浏览文件 @
76aabbe9
...
...
@@ -412,7 +412,7 @@ fn print_item(s: ps, &&item: @ast::item) {
word
(
s
.s
,
";"
);
end
(
s
);
// end the outer ibox
}
ast
::
item_
tag
(
variants
,
params
)
{
ast
::
item_
enum
(
variants
,
params
)
{
let
newtype
=
vec
::
len
(
variants
)
==
1u
&&
str
::
eq
(
item
.ident
,
variants
[
0
]
.node.name
)
&&
...
...
@@ -1081,7 +1081,7 @@ fn print_pat(s: ps, &&pat: @ast::pat) {
_
{}
}
}
ast
::
pat_
tag
(
path
,
args
)
{
ast
::
pat_
enum
(
path
,
args
)
{
print_path
(
s
,
path
,
true
);
if
vec
::
len
(
args
)
>
0u
{
popen
(
s
);
...
...
@@ -1304,12 +1304,12 @@ fn print_view_item(s: ps, item: @ast::view_item) {
commasep
(
s
,
inconsistent
,
ids
,
fn
@
(
s
:
ps
,
&&
w
:
ast
::
ident
)
{
word
(
s
.s
,
w
)
});
}
ast
::
view_item_export_
tag
_none
(
id
,
_
)
{
ast
::
view_item_export_
enum
_none
(
id
,
_
)
{
head
(
s
,
"export"
);
word
(
s
.s
,
id
);
word
(
s
.s
,
"::{}"
);
}
ast
::
view_item_export_
tag
_some
(
id
,
ids
,
_
)
{
ast
::
view_item_export_
enum
_some
(
id
,
ids
,
_
)
{
head
(
s
,
"export"
);
word
(
s
.s
,
id
);
word
(
s
.s
,
"::{"
);
...
...
src/comp/syntax/visit.rs
浏览文件 @
76aabbe9
...
...
@@ -120,7 +120,7 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
v
.visit_fn
(
fk_res
(
i
.ident
,
tps
),
decl
,
body
,
i
.span
,
dtor_id
,
e
,
v
);
}
item_
tag
(
variants
,
tps
)
{
item_
enum
(
variants
,
tps
)
{
v
.visit_ty_params
(
tps
,
e
,
v
);
for
vr
:
variant
in
variants
{
for
va
:
variant_arg
in
vr
.node.args
{
v
.visit_ty
(
va
.ty
,
e
,
v
);
}
...
...
@@ -187,7 +187,7 @@ fn visit_path<E>(p: @path, e: E, v: vt<E>) {
fn
visit_pat
<
E
>
(
p
:
@
pat
,
e
:
E
,
v
:
vt
<
E
>
)
{
alt
p
.node
{
pat_
tag
(
path
,
children
)
{
pat_
enum
(
path
,
children
)
{
visit_path
(
path
,
e
,
v
);
for
child
:
@
pat
in
children
{
v
.visit_pat
(
child
,
e
,
v
);
}
}
...
...
src/comp/util/ppaux.rs
浏览文件 @
76aabbe9
...
...
@@ -72,7 +72,7 @@ fn mt_to_str(cx: ctxt, m: mt) -> str {
alt
ty_name
(
cx
,
typ
)
{
some
(
cs
)
{
alt
struct
(
cx
,
typ
)
{
ty_
tag
(
_
,
tps
)
|
ty_res
(
_
,
_
,
tps
)
{
ty_
enum
(
_
,
tps
)
|
ty_res
(
_
,
_
,
tps
)
{
if
vec
::
len
(
tps
)
>
0u
{
let
strs
=
vec
::
map
(
tps
,
{|
t
|
ty_to_str
(
cx
,
t
)});
ret
*
cs
+
"<"
+
str
::
connect
(
strs
,
","
)
+
">"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录