Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
24102d50
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
24102d50
编写于
1月 13, 2012
作者:
M
Marijn Haverbeke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Obj system? What obj system?
Removes the obj system from the compiler. Closes #1484
上级
eb07fa4d
变更
30
展开全部
隐藏空白更改
内联
并排
Showing
30 changed file
with
139 addition
and
2020 deletion
+139
-2020
src/comp/back/abi.rs
src/comp/back/abi.rs
+1
-14
src/comp/metadata/encoder.rs
src/comp/metadata/encoder.rs
+0
-32
src/comp/metadata/tydecode.rs
src/comp/metadata/tydecode.rs
+0
-18
src/comp/metadata/tyencode.rs
src/comp/metadata/tyencode.rs
+0
-9
src/comp/middle/alias.rs
src/comp/middle/alias.rs
+6
-19
src/comp/middle/ast_map.rs
src/comp/middle/ast_map.rs
+0
-29
src/comp/middle/debuginfo.rs
src/comp/middle/debuginfo.rs
+0
-3
src/comp/middle/gc.rs
src/comp/middle/gc.rs
+3
-3
src/comp/middle/kind.rs
src/comp/middle/kind.rs
+2
-2
src/comp/middle/mut.rs
src/comp/middle/mut.rs
+1
-5
src/comp/middle/resolve.rs
src/comp/middle/resolve.rs
+9
-52
src/comp/middle/shape.rs
src/comp/middle/shape.rs
+16
-23
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+69
-230
src/comp/middle/trans_closure.rs
src/comp/middle/trans_closure.rs
+2
-2
src/comp/middle/trans_common.rs
src/comp/middle/trans_common.rs
+4
-37
src/comp/middle/trans_impl.rs
src/comp/middle/trans_impl.rs
+5
-7
src/comp/middle/trans_objects.rs
src/comp/middle/trans_objects.rs
+0
-951
src/comp/middle/trans_vec.rs
src/comp/middle/trans_vec.rs
+2
-2
src/comp/middle/tstate/pre_post_conditions.rs
src/comp/middle/tstate/pre_post_conditions.rs
+0
-10
src/comp/middle/tstate/states.rs
src/comp/middle/tstate/states.rs
+0
-6
src/comp/middle/ty.rs
src/comp/middle/ty.rs
+6
-103
src/comp/middle/typeck.rs
src/comp/middle/typeck.rs
+3
-206
src/comp/rustc.rc
src/comp/rustc.rc
+0
-1
src/comp/syntax/ast.rs
src/comp/syntax/ast.rs
+2
-22
src/comp/syntax/ast_util.rs
src/comp/syntax/ast_util.rs
+1
-5
src/comp/syntax/fold.rs
src/comp/syntax/fold.rs
+0
-38
src/comp/syntax/parse/parser.rs
src/comp/syntax/parse/parser.rs
+7
-77
src/comp/syntax/print/pprust.rs
src/comp/syntax/print/pprust.rs
+0
-76
src/comp/syntax/visit.rs
src/comp/syntax/visit.rs
+0
-33
src/comp/util/ppaux.rs
src/comp/util/ppaux.rs
+0
-5
未找到文件。
src/comp/back/abi.rs
浏览文件 @
24102d50
...
...
@@ -46,7 +46,7 @@
const
tydesc_field_shape
:
int
=
11
;
const
tydesc_field_shape_tables
:
int
=
12
;
const
tydesc_field_n_params
:
int
=
13
;
const
tydesc_field_obj_params
:
int
=
14
;
const
tydesc_field_obj_params
:
int
=
14
;
// FIXME unused
const
n_tydesc_fields
:
int
=
15
;
const
cmp_glue_op_eq
:
uint
=
0u
;
...
...
@@ -55,19 +55,6 @@
const
cmp_glue_op_le
:
uint
=
2u
;
const
obj_field_vtbl
:
int
=
0
;
const
obj_field_box
:
int
=
1
;
const
obj_body_elt_tydesc
:
int
=
0
;
const
obj_body_elt_typarams
:
int
=
1
;
const
obj_body_elt_fields
:
int
=
2
;
// The base object to which an anonymous object is attached.
const
obj_body_elt_inner_obj
:
int
=
3
;
// The two halves of a closure: code and environment.
const
fn_field_code
:
int
=
0
;
const
fn_field_box
:
int
=
1
;
...
...
src/comp/metadata/encoder.rs
浏览文件 @
24102d50
...
...
@@ -126,18 +126,6 @@ fn encode_module_item_paths(ebml_w: ebml::writer, module: _mod, path: [str],
ebml
::
end_tag
(
ebml_w
);
encode_tag_variant_paths
(
ebml_w
,
variants
,
path
,
index
);
}
item_obj
(
_
,
tps
,
ctor_id
)
{
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
(
ctor_id
));
ebml
::
end_tag
(
ebml_w
);
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
);
}
item_iface
(
_
,
_
)
{
add_to_index
(
ebml_w
,
path
,
index
,
it
.ident
);
ebml
::
start_tag
(
ebml_w
,
tag_paths_data_item
);
...
...
@@ -366,26 +354,6 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
encode_symbol
(
ecx
,
ebml_w
,
ctor_id
);
ebml
::
end_tag
(
ebml_w
);
}
item_obj
(
_
,
tps
,
ctor_id
)
{
let
fn_ty
=
node_id_to_monotype
(
tcx
,
ctor_id
);
ebml
::
start_tag
(
ebml_w
,
tag_items_data_item
);
encode_def_id
(
ebml_w
,
local_def
(
item
.id
));
encode_family
(
ebml_w
,
'y'
as
u8
);
encode_type_param_bounds
(
ebml_w
,
ecx
,
tps
);
encode_type
(
ecx
,
ebml_w
,
ty
::
ty_fn_ret
(
tcx
,
fn_ty
));
encode_name
(
ebml_w
,
item
.ident
);
ebml
::
end_tag
(
ebml_w
);
index
+=
[{
val
:
ctor_id
,
pos
:
ebml_w
.writer
.tell
()}];
ebml
::
start_tag
(
ebml_w
,
tag_items_data_item
);
encode_def_id
(
ebml_w
,
local_def
(
ctor_id
));
encode_family
(
ebml_w
,
'f'
as
u8
);
encode_type_param_bounds
(
ebml_w
,
ecx
,
tps
);
encode_type
(
ecx
,
ebml_w
,
fn_ty
);
encode_symbol
(
ecx
,
ebml_w
,
ctor_id
);
ebml
::
end_tag
(
ebml_w
);
}
item_impl
(
tps
,
ifce
,
_
,
methods
)
{
ebml
::
start_tag
(
ebml_w
,
tag_items_data_item
);
encode_def_id
(
ebml_w
,
local_def
(
item
.id
));
...
...
src/comp/metadata/tydecode.rs
浏览文件 @
24102d50
...
...
@@ -246,24 +246,6 @@ fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
let
func
=
parse_ty_fn
(
st
,
conv
);
ret
ty
::
mk_native_fn
(
st
.tcx
,
func
.inputs
,
func
.output
);
}
'O'
{
assert
(
next
(
st
)
as
char
==
'['
);
let
methods
:
[
ty
::
method
]
=
[];
while
peek
(
st
)
as
char
!=
']'
{
let
proto
;
alt
next
(
st
)
as
char
{
'f'
{
proto
=
ast
::
proto_bare
;
}
}
let
name
=
""
;
while
peek
(
st
)
as
char
!=
'['
{
name
+=
str
::
unsafe_from_byte
(
next
(
st
));
}
methods
+=
[{
ident
:
name
,
tps
:
@
[],
fty
:
{
proto
:
proto
with
parse_ty_fn
(
st
,
conv
)}}];
}
st
.pos
+=
1u
;
ret
ty
::
mk_obj
(
st
.tcx
,
methods
);
}
'r'
{
assert
(
next
(
st
)
as
char
==
'['
);
let
def
=
parse_def
(
st
,
conv
);
...
...
src/comp/metadata/tyencode.rs
浏览文件 @
24102d50
...
...
@@ -157,15 +157,6 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
enc_ty_fn
(
w
,
cx
,
{
proto
:
proto_bare
,
inputs
:
args
,
output
:
out
,
ret_style
:
return_val
,
constraints
:
[]});
}
ty
::
ty_obj
(
methods
)
{
w
.write_str
(
"O["
);
for
m
:
ty
::
method
in
methods
{
enc_proto
(
w
,
m
.fty.proto
);
w
.write_str
(
m
.ident
);
enc_ty_fn
(
w
,
cx
,
m
.fty
);
}
w
.write_char
(
']'
);
}
ty
::
ty_res
(
def
,
ty
,
tps
)
{
w
.write_str
(
"r["
);
w
.write_str
(
cx
.ds
(
def
));
...
...
src/comp/middle/alias.rs
浏览文件 @
24102d50
...
...
@@ -56,8 +56,8 @@ fn mk_binding(cx: ctx, id: node_id, span: span, root_var: option::t<node_id>,
mutable
silent
:
bool
};
fn
check_crate
(
tcx
:
ty
::
ctxt
,
crate
:
@
ast
::
crate
)
->
(
copy_map
,
ref_map
)
{
// Stores information about
object fields and function
// a
rguments that's otherwise not easily a
vailable.
// Stores information about
function arguments that's otherwise not easily
// available.
let
cx
=
@
{
tcx
:
tcx
,
copy_map
:
std
::
map
::
new_int_hash
(),
ref_map
:
std
::
map
::
new_int_hash
(),
...
...
@@ -521,7 +521,7 @@ fn helper(tcx: ty::ctxt, needle: unsafe_ty, haystack: ty::t, mut: bool)
}
ty
::
ty_fn
({
proto
:
ast
::
proto_bare
.
,
_
})
{
ret
false
;
}
// These may contain anything.
ty
::
ty_fn
(
_
)
|
ty
::
ty_
obj
(
_
)
{
ret
true
;
}
ty
::
ty_fn
(
_
)
|
ty
::
ty_
iface
(
_
,
_
)
{
ret
true
;
}
// A type param may include everything, but can only be
// treated as opaque downstream, and is thus safe unless we
// saw mutable fields, in which case the whole thing can be
...
...
@@ -536,8 +536,7 @@ fn helper(tcx: ty::ctxt, needle: unsafe_ty, haystack: ty::t, mut: bool)
fn
def_is_local
(
d
:
ast
::
def
)
->
bool
{
alt
d
{
ast
::
def_local
(
_
,
_
)
|
ast
::
def_arg
(
_
,
_
)
|
ast
::
def_binding
(
_
)
|
ast
::
def_upvar
(
_
,
_
,
_
)
|
ast
::
def_self
(
_
)
|
ast
::
def_obj_field
(
_
,
_
)
{
true
}
ast
::
def_upvar
(
_
,
_
,
_
)
|
ast
::
def_self
(
_
)
{
true
}
_
{
false
}
}
}
...
...
@@ -557,10 +556,9 @@ fn score_ty(tcx: ty::ctxt, ty: ty::t) -> uint {
ty
::
ty_nil
.
|
ty
::
ty_bot
.
|
ty
::
ty_bool
.
|
ty
::
ty_int
(
_
)
|
ty
::
ty_uint
(
_
)
|
ty
::
ty_float
(
_
)
|
ty
::
ty_type
.
|
ty
::
ty_native
(
_
)
|
ty
::
ty_ptr
(
_
)
{
1u
}
ty
::
ty_box
(
_
)
{
3u
}
ty
::
ty_box
(
_
)
|
ty
::
ty_iface
(
_
,
_
)
{
3u
}
ty
::
ty_constr
(
t
,
_
)
|
ty
::
ty_res
(
_
,
t
,
_
)
{
score_ty
(
tcx
,
t
)
}
ty
::
ty_fn
(
_
)
|
ty
::
ty_native_fn
(
_
,
_
)
|
ty
::
ty_obj
(
_
)
{
4u
}
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
)
{
...
...
@@ -633,17 +631,6 @@ fn expr_root(cx: ctx, ex: @ast::expr, autoderef: bool)
for
d
in
*
base_root
.ds
{
if
d
.mut
{
unsafe_ty
=
some
(
contains
(
d
.outer_t
));
break
;
}
}
alt
base_root
.ex.node
{
ast
::
expr_path
(
_
)
{
alt
cx
.tcx.def_map
.get
(
base_root
.ex.id
)
{
ast
::
def_obj_field
(
_
,
ast
::
mut
.
)
{
unsafe_ty
=
some
(
mut_contains
(
ty
::
expr_ty
(
cx
.tcx
,
base_root
.ex
)));
}
_
{}
}
}
_
{}
}
ret
{
ex
:
base_root
.ex
,
mut
:
unsafe_ty
};
}
...
...
src/comp/middle/ast_map.rs
浏览文件 @
24102d50
...
...
@@ -6,8 +6,6 @@
tag
ast_node
{
node_item
(
@
item
);
node_obj_ctor
(
@
item
);
node_obj_method
(
@
method
);
node_native_item
(
@
native_item
);
node_method
(
@
method
);
node_expr
(
@
expr
);
...
...
@@ -62,12 +60,6 @@ fn map_arm(cx: ctx, arm: arm) {
fn
map_item
(
cx
:
ctx
,
i
:
@
item
)
{
cx
.map
.insert
(
i
.id
,
node_item
(
i
));
alt
i
.node
{
item_obj
(
ob
,
_
,
ctor_id
)
{
cx
.map
.insert
(
ctor_id
,
node_obj_ctor
(
i
));
for
m
in
ob
.methods
{
cx
.map
.insert
(
m
.id
,
node_obj_method
(
m
));
}
}
item_impl
(
_
,
_
,
_
,
ms
)
{
for
m
in
ms
{
cx
.map
.insert
(
m
.id
,
node_method
(
m
));
}
}
...
...
@@ -85,20 +77,11 @@ fn map_native_item(cx: ctx, i: @native_item) {
fn
map_expr
(
cx
:
ctx
,
ex
:
@
expr
)
{
cx
.map
.insert
(
ex
.id
,
node_expr
(
ex
));
alt
ex
.node
{
expr_anon_obj
(
ao
)
{
for
m
in
ao
.methods
{
cx
.map
.insert
(
m
.id
,
node_obj_method
(
m
));
}
}
_
{}
}
}
fn
node_span
(
node
:
ast_node
)
->
codemap
::
span
{
alt
node
{
node_item
(
item
)
{
item
.span
}
node_obj_ctor
(
item
)
{
item
.span
}
node_native_item
(
nitem
)
{
nitem
.span
}
node_expr
(
expr
)
{
expr
.span
}
}
...
...
@@ -120,18 +103,6 @@ fn test_node_span_item() {
assert
(
node_span
(
node
)
==
expected
);
}
#[test]
fn
test_node_span_obj_ctor
()
{
let
expected
:
codemap
::
span
=
ast_util
::
mk_sp
(
20u
,
30u
);
let
node
=
node_obj_ctor
(
@
{
ident
:
"test"
,
attrs
:
[],
id
:
0
,
node
:
item_mod
({
view_items
:
[],
items
:
[]}),
span
:
expected
});
assert
(
node_span
(
node
)
==
expected
);
}
#[test]
fn
test_node_span_native_item
()
{
let
expected
:
codemap
::
span
=
ast_util
::
mk_sp
(
20u
,
30u
);
...
...
src/comp/middle/debuginfo.rs
浏览文件 @
24102d50
...
...
@@ -727,9 +727,6 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
}
}
}
ast_map
::
node_obj_method
(
method
)
|
ast_map
::
node_method
(
method
)
{
(
method
.ident
,
method
.decl.output
,
method
.id
)
}
ast_map
::
node_res_ctor
(
item
)
{
alt
item
.node
{
ast
::
item_res
(
decl
,
_
,
_
,
_
,
ctor_id
)
{
(
item
.ident
,
decl
.output
,
ctor_id
)
...
...
src/comp/middle/gc.rs
浏览文件 @
24102d50
...
...
@@ -3,7 +3,7 @@
import
lib
::
llvm
::
True
;
import
lib
::
llvm
::
llvm
::
ValueRef
;
import
middle
::
trans
;
import
middle
::
trans
::
{
get_tydesc
,
tps_normal
}
;
import
middle
::
trans
::
get_tydesc
;
import
middle
::
trans_common
::
*
;
import
middle
::
ty
;
import
option
::
none
;
...
...
@@ -43,7 +43,7 @@ fn add_gc_root(cx: @block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
bcx
=
trans
::
zero_alloca
(
bcx
,
llval
,
ty
);
let
ti
=
none
;
let
td_r
=
get_tydesc
(
bcx
,
ty
,
false
,
t
ps_normal
,
t
i
);
let
td_r
=
get_tydesc
(
bcx
,
ty
,
false
,
ti
);
bcx
=
td_r
.result.bcx
;
let
lltydesc
=
td_r
.result.val
;
...
...
@@ -147,7 +147,7 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
}
ty
::
ty_constr
(
sub
,
_
)
{
ret
type_is_gc_relevant
(
cx
,
sub
);
}
ty
::
ty_box
(
_
)
|
ty
::
ty_uniq
(
_
)
|
ty
::
ty_fn
(
_
)
|
ty
::
ty_native_fn
(
_
,
_
)
|
ty
::
ty_
obj
(
_
)
|
ty
::
ty_
param
(
_
,
_
)
|
ty
::
ty_native_fn
(
_
,
_
)
|
ty
::
ty_param
(
_
,
_
)
|
ty
::
ty_res
(
_
,
_
,
_
)
{
ret
true
;
}
ty
::
ty_var
(
_
)
{
fail
"ty_var in type_is_gc_relevant"
;
...
...
src/comp/middle/kind.rs
浏览文件 @
24102d50
...
...
@@ -8,7 +8,7 @@
// Kind analysis pass. There are three kinds:
//
// sendable: scalar types, and unique types containing only sendable types
// copyable: boxes,
objects,
closures, and uniques containing copyable types
// copyable: boxes, closures, and uniques containing copyable types
// noncopyable: resources, or unique types containing resources
//
// This pass ensures that type parameters are only instantiated with types
...
...
@@ -218,7 +218,7 @@ fn maybe_copy(cx: ctx, ex: @expr) {
}
fn
check_copy_ex
(
cx
:
ctx
,
ex
:
@
expr
,
_
warn
:
bool
)
{
if
ty
::
expr_is_lval
(
cx
.method_map
,
cx
.tcx
,
ex
)
&&
if
ty
::
expr_is_lval
(
cx
.method_map
,
ex
)
&&
!
cx
.last_uses
.contains_key
(
ex
.id
)
{
let
ty
=
ty
::
expr_ty
(
cx
.tcx
,
ex
);
check_copy
(
cx
,
ty
,
ex
.span
);
...
...
src/comp/middle/mut.rs
浏览文件 @
24102d50
...
...
@@ -60,7 +60,7 @@ fn maybe_auto_unbox(tcx: ty::ctxt, t: ty::t) -> {t: ty::t, ds: [deref]} {
}
}
}
ty
::
ty_obj
(
_
)
{
}
_
{
}
}
ds
+=
[
@
{
mut
:
is_mut
,
kind
:
field
,
outer_t
:
auto_unbox
.t
}];
ds
+=
auto_unbox
.ds
;
...
...
@@ -201,9 +201,6 @@ fn check_move_rhs(cx: @ctx, src: @expr) {
alt
src
.node
{
expr_path
(
p
)
{
alt
cx
.tcx.def_map
.get
(
src
.id
)
{
def_obj_field
(
_
,
_
)
{
mk_err
(
cx
,
src
.span
,
msg_move_out
,
"object field"
);
}
def_self
(
_
)
{
mk_err
(
cx
,
src
.span
,
msg_move_out
,
"method self"
);
}
...
...
@@ -267,7 +264,6 @@ fn is_immutable_def(cx: @ctx, def: def) -> option::t<str> {
}
def_arg
(
_
,
by_ref
.
)
|
def_arg
(
_
,
by_val
.
)
|
def_arg
(
_
,
mode_infer
.
)
{
some
(
"argument"
)
}
def_obj_field
(
_
,
imm
.
)
{
some
(
"immutable object field"
)
}
def_self
(
_
)
{
some
(
"self argument"
)
}
def_upvar
(
_
,
inner
,
node_id
)
{
let
ty
=
ty
::
node_id_to_monotype
(
cx
.tcx
,
node_id
);
...
...
src/comp/middle/resolve.rs
浏览文件 @
24102d50
...
...
@@ -535,9 +535,6 @@ fn visit_expr_with_scope(x: @ast::expr, sc: scopes, v: vt<scopes>) {
v
.visit_local
(
decl
,
new_sc
,
v
);
v
.visit_block
(
blk
,
new_sc
,
v
);
}
ast
::
expr_anon_obj
(
_
)
{
visit
::
visit_expr
(
x
,
cons
(
scope_method
(
x
.id
,
[]),
@
sc
),
v
);
}
_
{
visit
::
visit_expr
(
x
,
sc
,
v
);
}
}
}
...
...
@@ -852,9 +849,9 @@ fn def_is_local(d: def) -> bool {
}
}
fn
def_
has_obj_scope
(
d
:
def
)
->
bool
{
fn
def_
is_self
(
d
:
def
)
->
bool
{
alt
d
{
ast
::
def_
obj_field
(
_
,
_
)
|
ast
::
def_
self
(
_
)
{
true
}
ast
::
def_self
(
_
)
{
true
}
_
{
false
}
}
}
...
...
@@ -874,9 +871,6 @@ fn in_scope(e: env, sp: span, name: ident, s: scope, ns: namespace) ->
}
scope_item
(
it
)
{
alt
it
.node
{
ast
::
item_obj
(
ob
,
ty_params
,
_
)
{
ret
lookup_in_obj
(
e
,
name
,
ob
,
ty_params
,
ns
,
it
.id
);
}
ast
::
item_impl
(
tps
,
_
,
_
,
_
)
{
if
ns
==
ns_type
{
ret
lookup_in_ty_params
(
e
,
name
,
tps
);
}
}
...
...
@@ -935,7 +929,7 @@ fn in_scope(e: env, sp: span, name: ident, s: scope, ns: namespace) ->
}
let
left_fn
=
false
;
let
closing
=
[];
// Used to determine whether
obj fields are
in scope
// Used to determine whether
self is
in scope
let
left_fn_level2
=
false
;
let
sc
=
sc
;
while
true
{
...
...
@@ -945,9 +939,8 @@ fn in_scope(e: env, sp: span, name: ident, s: scope, ns: namespace) ->
let
fnd
=
in_scope
(
e
,
sp
,
name
,
hd
,
ns
);
if
!
is_none
(
fnd
)
{
let
df
=
option
::
get
(
fnd
);
let
local
=
def_is_local
(
df
),
obj_scope
=
def_has_obj_scope
(
df
);
if
left_fn
&&
local
||
left_fn_level2
&&
obj_scope
let
local
=
def_is_local
(
df
),
self_scope
=
def_is_self
(
df
);
if
left_fn
&&
local
||
left_fn_level2
&&
self_scope
||
scope_is_fn
(
hd
)
&&
left_fn
&&
def_is_ty_arg
(
df
)
{
let
msg
=
alt
ns
{
ns_type
.
{
...
...
@@ -965,7 +958,7 @@ fn in_scope(e: env, sp: span, name: ident, s: scope, ns: namespace) ->
_
{
"attempted dynamic environment-capture"
}
};
e
.sess
.span_fatal
(
sp
,
msg
);
}
else
if
local
||
obj
_scope
{
}
else
if
local
||
self
_scope
{
let
i
=
vec
::
len
(
closing
);
while
i
>
0u
{
i
-=
1u
;
...
...
@@ -1030,24 +1023,6 @@ fn lookup_in_fn(e: env, name: ident, decl: ast::fn_decl,
}
}
fn
lookup_in_obj
(
e
:
env
,
name
:
ident
,
ob
:
ast
::
_
obj
,
ty_params
:
[
ast
::
ty_param
],
ns
:
namespace
,
id
:
node_id
)
->
option
::
t
<
def
>
{
alt
ns
{
ns_val
(
val_ty
)
{
if
name
==
"self"
&&
val_ty
==
ns_any_value
{
ret
some
(
ast
::
def_self
(
local_def
(
id
)));
}
for
f
:
ast
::
obj_field
in
ob
.fields
{
if
str
::
eq
(
f
.ident
,
name
)
&&
val_ty
==
ns_any_value
{
ret
some
(
ast
::
def_obj_field
(
local_def
(
f
.id
),
f
.mut
));
}
}
ret
none
::
<
def
>
;
}
ns_type
.
{
ret
lookup_in_ty_params
(
e
,
name
,
ty_params
);
}
_
{
ret
none
::
<
def
>
;
}
}
}
fn
lookup_in_block
(
e
:
env
,
name
:
ident
,
sp
:
span
,
b
:
ast
::
blk_
,
pos
:
uint
,
loc_pos
:
uint
,
ns
:
namespace
)
->
option
::
t
<
def
>
{
...
...
@@ -1166,15 +1141,6 @@ fn found_def_item(i: @ast::item, ns: namespace) -> option::t<def> {
_
{
}
}
}
ast
::
item_obj
(
_
,
_
,
ctor_id
)
{
alt
ns
{
ns_val
(
ns_any_value
.
)
{
ret
some
(
ast
::
def_fn
(
local_def
(
ctor_id
),
ast
::
impure_fn
));
}
ns_type
.
{
ret
some
(
ast
::
def_ty
(
local_def
(
i
.id
)));
}
_
{
}
}
}
_
{
}
}
ret
none
;
...
...
@@ -1422,7 +1388,7 @@ fn index_mod(md: ast::_mod) -> mod_index {
alt
it
.node
{
ast
::
item_const
(
_
,
_
)
|
ast
::
item_fn
(
_
,
_
,
_
)
|
ast
::
item_mod
(
_
)
|
ast
::
item_native_mod
(
_
)
|
ast
::
item_ty
(
_
,
_
)
|
ast
::
item_res
(
_
,
_
,
_
,
_
,
_
)
|
ast
::
item_obj
(
_
,
_
,
_
)
|
ast
::
item_res
(
_
,
_
,
_
,
_
,
_
)
|
ast
::
item_impl
(
_
,
_
,
_
,
_
)
|
ast
::
item_iface
(
_
,
_
)
{
add_to_index
(
index
,
it
.ident
,
mie_item
(
it
));
}
...
...
@@ -1470,7 +1436,7 @@ fn index_nmod(md: ast::native_mod) -> mod_index {
fn
ns_for_def
(
d
:
def
)
->
namespace
{
alt
d
{
ast
::
def_variant
(
_
,
_
)
{
ns_val
(
ns_a_tag
)
}
ast
::
def_fn
(
_
,
_
)
|
ast
::
def_
obj_field
(
_
,
_
)
|
ast
::
def_
self
(
_
)
|
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
(
_
)
{
ns_val
(
ns_any_value
)
}
...
...
@@ -1597,15 +1563,6 @@ fn typaram_names(tps: [ast::ty_param]) -> [ident] {
ensure_unique
(
*
e
,
i
.span
,
typaram_names
(
ty_params
),
ident_id
,
"type parameter"
);
}
ast
::
item_obj
(
ob
,
ty_params
,
_
)
{
fn
field_name
(
field
:
ast
::
obj_field
)
->
ident
{
ret
field
.ident
;
}
ensure_unique
(
*
e
,
i
.span
,
ob
.fields
,
field_name
,
"object field"
);
for
m
:
@
ast
::
method
in
ob
.methods
{
check_fn
(
*
e
,
m
.span
,
m
.decl
);
}
ensure_unique
(
*
e
,
i
.span
,
typaram_names
(
ty_params
),
ident_id
,
"type parameter"
);
}
ast
::
item_tag
(
_
,
ty_params
)
{
ensure_unique
(
*
e
,
i
.span
,
typaram_names
(
ty_params
),
ident_id
,
"type parameter"
);
...
...
@@ -1687,7 +1644,7 @@ fn check_block(e: @env, b: ast::blk, &&x: (), v: vt<()>) {
ast
::
item_ty
(
_
,
_
)
|
ast
::
item_iface
(
_
,
_
)
{
add_name
(
types
,
it
.span
,
it
.ident
);
}
ast
::
item_res
(
_
,
_
,
_
,
_
,
_
)
|
ast
::
item_obj
(
_
,
_
,
_
)
{
ast
::
item_res
(
_
,
_
,
_
,
_
,
_
)
{
add_name
(
types
,
it
.span
,
it
.ident
);
add_name
(
values
,
it
.span
,
it
.ident
);
}
...
...
src/comp/middle/shape.rs
浏览文件 @
24102d50
...
...
@@ -47,7 +47,7 @@
const
shape_box
:
u8
=
13u8
;
const
shape_struct
:
u8
=
17u8
;
const
shape_box_fn
:
u8
=
18u8
;
const
shape_
obj
:
u8
=
19u8
;
const
shape_
UNUSED
:
u8
=
19u8
;
const
shape_res
:
u8
=
20u8
;
const
shape_var
:
u8
=
21u8
;
const
shape_uniq
:
u8
=
22u8
;
...
...
@@ -309,8 +309,7 @@ fn add_substr(&dest: [u8], src: [u8]) {
dest
+=
src
;
}
fn
shape_of
(
ccx
:
@
crate_ctxt
,
t
:
ty
::
t
,
ty_param_map
:
[
uint
],
is_obj_body
:
bool
)
->
[
u8
]
{
fn
shape_of
(
ccx
:
@
crate_ctxt
,
t
:
ty
::
t
,
ty_param_map
:
[
uint
])
->
[
u8
]
{
let
s
=
[];
alt
ty
::
struct
(
ccx
.tcx
,
t
)
{
...
...
@@ -335,7 +334,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
s
+=
[
shape_vec
];
add_bool
(
s
,
true
);
// type is POD
let
unit_ty
=
ty
::
mk_mach_uint
(
ccx
.tcx
,
ast
::
ty_u8
);
add_substr
(
s
,
shape_of
(
ccx
,
unit_ty
,
ty_param_map
,
is_obj_body
));
add_substr
(
s
,
shape_of
(
ccx
,
unit_ty
,
ty_param_map
));
}
ty
::
ty_tag
(
did
,
tps
)
{
alt
tag_kind
(
ccx
,
did
)
{
...
...
@@ -363,7 +362,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
add_u16
(
sub
,
vec
::
len
(
tps
)
as
u16
);
for
tp
:
ty
::
t
in
tps
{
let
subshape
=
shape_of
(
ccx
,
tp
,
ty_param_map
,
is_obj_body
);
let
subshape
=
shape_of
(
ccx
,
tp
,
ty_param_map
);
add_u16
(
sub
,
vec
::
len
(
subshape
)
as
u16
);
sub
+=
subshape
;
}
...
...
@@ -374,22 +373,22 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
}
ty
::
ty_box
(
mt
)
{
s
+=
[
shape_box
];
add_substr
(
s
,
shape_of
(
ccx
,
mt
.ty
,
ty_param_map
,
is_obj_body
));
add_substr
(
s
,
shape_of
(
ccx
,
mt
.ty
,
ty_param_map
));
}
ty
::
ty_uniq
(
mt
)
{
s
+=
[
shape_uniq
];
add_substr
(
s
,
shape_of
(
ccx
,
mt
.ty
,
ty_param_map
,
is_obj_body
));
add_substr
(
s
,
shape_of
(
ccx
,
mt
.ty
,
ty_param_map
));
}
ty
::
ty_vec
(
mt
)
{
s
+=
[
shape_vec
];
add_bool
(
s
,
ty
::
type_is_pod
(
ccx
.tcx
,
mt
.ty
));
add_substr
(
s
,
shape_of
(
ccx
,
mt
.ty
,
ty_param_map
,
is_obj_body
));
add_substr
(
s
,
shape_of
(
ccx
,
mt
.ty
,
ty_param_map
));
}
ty
::
ty_rec
(
fields
)
{
s
+=
[
shape_struct
];
let
sub
=
[];
for
f
:
field
in
fields
{
sub
+=
shape_of
(
ccx
,
f
.mt.ty
,
ty_param_map
,
is_obj_body
);
sub
+=
shape_of
(
ccx
,
f
.mt.ty
,
ty_param_map
);
}
add_substr
(
s
,
sub
);
}
...
...
@@ -397,12 +396,11 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
s
+=
[
shape_struct
];
let
sub
=
[];
for
elt
in
elts
{
sub
+=
shape_of
(
ccx
,
elt
,
ty_param_map
,
is_obj_body
);
sub
+=
shape_of
(
ccx
,
elt
,
ty_param_map
);
}
add_substr
(
s
,
sub
);
}
ty
::
ty_native_fn
(
_
,
_
)
{
s
+=
[
shape_u32
];
}
ty
::
ty_obj
(
_
)
{
s
+=
[
shape_obj
];
}
ty
::
ty_iface
(
_
,
_
)
{
s
+=
[
shape_iface
];
}
ty
::
ty_res
(
did
,
raw_subt
,
tps
)
{
let
subt
=
ty
::
substitute_type_params
(
ccx
.tcx
,
tps
,
raw_subt
);
...
...
@@ -413,24 +411,19 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
add_u16
(
s
,
id
as
u16
);
add_u16
(
s
,
vec
::
len
(
tps
)
as
u16
);
for
tp
:
ty
::
t
in
tps
{
add_substr
(
s
,
shape_of
(
ccx
,
tp
,
ty_param_map
,
is_obj_body
));
add_substr
(
s
,
shape_of
(
ccx
,
tp
,
ty_param_map
));
}
add_substr
(
s
,
shape_of
(
ccx
,
subt
,
ty_param_map
,
is_obj_body
));
add_substr
(
s
,
shape_of
(
ccx
,
subt
,
ty_param_map
));
}
ty
::
ty_var
(
n
)
{
fail
"shape_of ty_var"
;
}
ty
::
ty_param
(
n
,
_
)
{
if
is_obj_body
{
// Just write in the parameter number.
s
+=
[
shape_var
,
n
as
u8
];
}
else
{
// Find the type parameter in the parameter list.
alt
vec
::
position
(
n
,
ty_param_map
)
{
some
(
i
)
{
s
+=
[
shape_var
,
i
as
u8
];
}
none
.
{
fail
"ty param not found in ty_param_map"
;
}
}
// Find the type parameter in the parameter list.
alt
vec
::
position
(
n
,
ty_param_map
)
{
some
(
i
)
{
s
+=
[
shape_var
,
i
as
u8
];
}
none
.
{
fail
"ty param not found in ty_param_map"
;
}
}
}
ty
::
ty_fn
({
proto
:
ast
::
proto_box
.
,
_
})
{
...
...
@@ -461,7 +454,7 @@ fn shape_of_variant(ccx: @crate_ctxt, v: ty::variant_info,
while
i
<
ty_param_count
{
ty_param_map
+=
[
i
];
i
+=
1u
;
}
let
s
=
[];
for
t
:
ty
::
t
in
v
.args
{
s
+=
shape_of
(
ccx
,
t
,
ty_param_map
,
false
);
}
for
t
:
ty
::
t
in
v
.args
{
s
+=
shape_of
(
ccx
,
t
,
ty_param_map
);
}
ret
s
;
}
...
...
src/comp/middle/trans.rs
浏览文件 @
24102d50
此差异已折叠。
点击以展开。
src/comp/middle/trans_closure.rs
浏览文件 @
24102d50
...
...
@@ -222,7 +222,7 @@ fn allocate_cbox(bcx: @block_ctxt,
let
ti
=
none
;
let
tydesc_ty
=
if
xchgheap
{
cbox_ty
}
else
{
cbox_norc_ty
};
let
{
bcx
,
val
:
lltydesc
}
=
get_tydesc
(
bcx
,
tydesc_ty
,
true
,
t
ps_normal
,
t
i
)
.result
;
get_tydesc
(
bcx
,
tydesc_ty
,
true
,
ti
)
.result
;
let
malloc
=
{
if
xchgheap
{
ccx
.upcalls.shared_malloc
}
else
{
ccx
.upcalls.malloc
}
...
...
@@ -315,7 +315,7 @@ fn maybe_clone_tydesc(bcx: @block_ctxt,
let
ti
=
none
;
let
{
result
:
closure_td
,
_
}
=
trans
::
get_tydesc
(
bcx
,
cbox_ty
,
true
,
t
ps_normal
,
t
i
);
trans
::
get_tydesc
(
bcx
,
cbox_ty
,
true
,
ti
);
trans
::
lazily_emit_tydesc_glue
(
bcx
,
abi
::
tydesc_field_take_glue
,
ti
);
trans
::
lazily_emit_tydesc_glue
(
bcx
,
abi
::
tydesc_field_drop_glue
,
ti
);
trans
::
lazily_emit_tydesc_glue
(
bcx
,
abi
::
tydesc_field_free_glue
,
ti
);
...
...
src/comp/middle/trans_common.rs
浏览文件 @
24102d50
...
...
@@ -46,8 +46,7 @@ fn new_namegen() -> namegen {
mutable
drop_glue
:
option
::
t
<
ValueRef
>
,
mutable
free_glue
:
option
::
t
<
ValueRef
>
,
mutable
cmp_glue
:
option
::
t
<
ValueRef
>
,
ty_params
:
[
uint
],
is_obj_body
:
bool
};
ty_params
:
[
uint
]};
/*
* A note on nomenclature of linking: "upcall", "extern" and "native".
...
...
@@ -112,7 +111,6 @@ fn new_namegen() -> namegen {
dict_map
:
typeck
::
dict_map
,
stats
:
stats
,
upcalls
:
@
upcall
::
upcalls
,
rust_object_type
:
TypeRef
,
tydesc_type
:
TypeRef
,
int_type
:
TypeRef
,
float_type
:
TypeRef
,
...
...
@@ -127,8 +125,6 @@ fn new_namegen() -> namegen {
type
local_ctxt
=
{
path
:
[
str
],
module_path
:
[
str
],
obj_typarams
:
[
ast
::
ty_param
],
obj_fields
:
[
ast
::
obj_field
],
ccx
:
@
crate_ctxt
};
// Types used for llself.
...
...
@@ -156,8 +152,7 @@ fn new_namegen() -> namegen {
// Points to the current task.
// Points to the current environment (bindings of variables to
// values), if this is a regular function; points to the current
// object, if this is a method.
// values), if this is a regular function
// Points to where the return value of this function should end
// up.
...
...
@@ -185,7 +180,7 @@ fn new_namegen() -> namegen {
// The token used to clear the dynamic allocas at the end of this frame.
// The 'self'
object
currently in use in this function, if there
// The 'self'
value
currently in use in this function, if there
// is one.
// If this function is actually a iter, a block containing the
...
...
@@ -196,9 +191,6 @@ fn new_namegen() -> namegen {
// Maps arguments to allocas created for them in llallocas.
// Maps fields in objects to pointers into the interior of
// llself's body.
// Maps the def_ids for local variables to the allocas created for
// them in llallocas.
...
...
@@ -240,7 +232,6 @@ fn new_namegen() -> namegen {
mutable
llobstacktoken
:
option
::
t
<
ValueRef
>
,
mutable
llself
:
option
::
t
<
val_self_pair
>
,
llargs
:
hashmap
<
ast
::
node_id
,
local_val
>
,
llobjfields
:
hashmap
<
ast
::
node_id
,
ValueRef
>
,
lllocals
:
hashmap
<
ast
::
node_id
,
local_val
>
,
llupvars
:
hashmap
<
ast
::
node_id
,
ValueRef
>
,
mutable
lltyparams
:
[
fn_ty_param
],
...
...
@@ -331,7 +322,7 @@ fn get_res_dtor(ccx: @crate_ctxt, sp: span, did: ast::def_id, inner_t: ty::t)
let
nil_res
=
ty
::
mk_nil
(
ccx
.tcx
);
// FIXME: Silly check -- mk_nil should have a postcondition
check
non_ty_var
(
ccx
,
nil_res
);
let
f_t
=
type_of_fn
(
ccx
,
sp
,
false
,
let
f_t
=
type_of_fn
(
ccx
,
sp
,
[{
mode
:
ast
::
by_ref
,
ty
:
inner_t
}],
nil_res
,
*
param_bounds
);
ret
trans
::
get_extern_const
(
ccx
.externs
,
ccx
.llmod
,
...
...
@@ -566,17 +557,6 @@ fn set_struct_body(t: TypeRef, elts: [TypeRef]) unsafe {
fn
T_empty_struct
()
->
TypeRef
{
ret
T_struct
([]);
}
// NB: This will return something different every time it's called. If
// you need a generic object type that matches the type of your
// existing objects, use ccx.rust_object_type. Calling
// T_rust_object() again will return a different one.
fn
T_rust_object
()
->
TypeRef
{
let
t
=
T_named_struct
(
"rust_object"
);
let
e
=
T_ptr
(
T_empty_struct
());
set_struct_body
(
t
,
[
e
,
e
]);
ret
t
;
}
// A dict is, in reality, a vtable pointer followed by zero or more pointers
// to tydescs and other dicts that it closes over. But the types and number of
// those are rarely known to the code that needs to manipulate them, so they
...
...
@@ -745,19 +725,6 @@ fn T_captured_tydescs(cx: @crate_ctxt, n: uint) -> TypeRef {
ret
T_struct
(
vec
::
init_elt
::
<
TypeRef
>
(
T_ptr
(
cx
.tydesc_type
),
n
));
}
fn
T_obj_ptr
(
cx
:
@
crate_ctxt
,
n_captured_tydescs
:
uint
)
->
TypeRef
{
// This function is not publicly exposed because it returns an incomplete
// type. The dynamically-sized fields follow the captured tydescs.
fn
T_obj
(
cx
:
@
crate_ctxt
,
n_captured_tydescs
:
uint
)
->
TypeRef
{
ret
T_struct
([
T_ptr
(
cx
.tydesc_type
),
T_captured_tydescs
(
cx
,
n_captured_tydescs
)]);
}
ret
T_ptr
(
T_box
(
cx
,
T_obj
(
cx
,
n_captured_tydescs
)));
}
fn
T_opaque_obj_ptr
(
cx
:
@
crate_ctxt
)
->
TypeRef
{
ret
T_obj_ptr
(
cx
,
0u
);
}
fn
T_opaque_iface_ptr
(
cx
:
@
crate_ctxt
)
->
TypeRef
{
let
tdptr
=
T_ptr
(
cx
.tydesc_type
);
T_ptr
(
T_box
(
cx
,
T_struct
([
tdptr
,
tdptr
,
T_i8
()])))
...
...
src/comp/middle/trans_impl.rs
浏览文件 @
24102d50
...
...
@@ -65,7 +65,7 @@ fn trans_self_arg(bcx: @block_ctxt, base: @ast::expr) -> result {
fn
trans_static_callee
(
bcx
:
@
block_ctxt
,
e
:
@
ast
::
expr
,
base
:
@
ast
::
expr
,
did
:
ast
::
def_id
)
->
lval_maybe_callee
{
let
{
bcx
,
val
}
=
trans_self_arg
(
bcx
,
base
);
{
env
:
obj
_env
(
val
)
with
lval_static_fn
(
bcx
,
did
,
e
.id
)}
{
env
:
self
_env
(
val
)
with
lval_static_fn
(
bcx
,
did
,
e
.id
)}
}
fn
wrapper_fn_ty
(
ccx
:
@
crate_ctxt
,
dict_ty
:
TypeRef
,
m
:
ty
::
method
)
...
...
@@ -92,7 +92,7 @@ fn trans_vtable_callee(bcx: @block_ctxt, self: ValueRef, dict: ValueRef,
let
tptys
=
ty
::
node_id_to_type_params
(
tcx
,
fld_expr
.id
);
for
t
in
vec
::
tail_n
(
tptys
,
vec
::
len
(
tptys
)
-
vec
::
len
(
*
method
.tps
))
{
let
ti
=
none
;
let
td
=
get_tydesc
(
bcx
,
t
,
true
,
t
ps_normal
,
t
i
)
.result
;
let
td
=
get_tydesc
(
bcx
,
t
,
true
,
ti
)
.result
;
tis
+=
[
ti
];
tydescs
+=
[
td
.val
];
bcx
=
td
.bcx
;
...
...
@@ -158,8 +158,7 @@ fn trans_vtable(ccx: @crate_ctxt, id: ast::node_id, name: str,
fn
trans_wrapper
(
ccx
:
@
crate_ctxt
,
pt
:
[
ast
::
ident
],
llfty
:
TypeRef
,
fill
:
block
(
ValueRef
,
@
block_ctxt
)
->
@
block_ctxt
)
->
ValueRef
{
let
lcx
=
@
{
path
:
pt
,
module_path
:
[],
obj_typarams
:
[],
obj_fields
:
[],
ccx
:
ccx
};
let
lcx
=
@
{
path
:
pt
,
module_path
:
[],
ccx
:
ccx
};
let
name
=
link
::
mangle_internal_name_by_path
(
ccx
,
pt
);
let
llfn
=
decl_internal_cdecl_fn
(
ccx
.llmod
,
name
,
llfty
);
let
fcx
=
new_fn_ctxt
(
lcx
,
ast_util
::
dummy_sp
(),
llfn
);
...
...
@@ -370,7 +369,7 @@ fn get_vtable(ccx: @crate_ctxt, did: ast::def_id) -> ValueRef {
let
ptrs
=
[
get_vtable
(
ccx
,
impl_did
)];
let
origin
=
0u
,
ti
=
none
,
bcx
=
bcx
;
vec
::
iter2
(
*
impl_params
,
tys
)
{|
param
,
ty
|
let
rslt
=
get_tydesc
(
bcx
,
ty
,
true
,
t
ps_normal
,
t
i
)
.result
;
let
rslt
=
get_tydesc
(
bcx
,
ty
,
true
,
ti
)
.result
;
ptrs
+=
[
rslt
.val
];
bcx
=
rslt
.bcx
;
for
bound
in
*
param
{
...
...
@@ -401,8 +400,7 @@ fn trans_cast(bcx: @block_ctxt, val: @ast::expr, id: ast::node_id, dest: dest)
let
body_ty
=
ty
::
mk_tup
(
tcx
,
[
ty
::
mk_type
(
tcx
),
ty
::
mk_type
(
tcx
),
val_ty
]);
let
ti
=
none
;
let
{
bcx
,
val
:
tydesc
}
=
get_tydesc
(
bcx
,
body_ty
,
true
,
tps_normal
,
ti
)
.result
;
let
{
bcx
,
val
:
tydesc
}
=
get_tydesc
(
bcx
,
body_ty
,
true
,
ti
)
.result
;
lazily_emit_all_tydesc_glue
(
bcx
,
ti
);
let
{
bcx
,
box
,
body
:
box_body
}
=
trans_malloc_boxed
(
bcx
,
body_ty
);
Store
(
bcx
,
tydesc
,
GEPi
(
bcx
,
box_body
,
[
0
,
0
]));
...
...
src/comp/middle/trans_objects.rs
已删除
100644 → 0
浏览文件 @
eb07fa4d
此差异已折叠。
点击以展开。
src/comp/middle/trans_vec.rs
浏览文件 @
24102d50
...
...
@@ -6,7 +6,7 @@
import
trans
::{
call_memmove
,
trans_shared_malloc
,
llsize_of
,
type_of_or_i8
,
INIT
,
copy_val
,
load_if_immediate
,
size_of
,
get_tydesc
,
node_id_type
,
new_sub_block_ctxt
,
tps_normal
,
do_spill_noroot
,
node_id_type
,
new_sub_block_ctxt
,
do_spill_noroot
,
dest
};
import
trans_build
::
*
;
import
trans_common
::
*
;
...
...
@@ -201,7 +201,7 @@ fn trans_append_literal(bcx: @block_ctxt, vptrptr: ValueRef, vec_ty: ty::t,
let
elt_ty
=
ty
::
sequence_element_type
(
bcx_tcx
(
bcx
),
vec_ty
);
let
ti
=
none
;
let
{
bcx
:
bcx
,
val
:
td
}
=
get_tydesc
(
bcx
,
elt_ty
,
false
,
t
ps_normal
,
t
i
)
.result
;
get_tydesc
(
bcx
,
elt_ty
,
false
,
ti
)
.result
;
trans
::
lazily_emit_tydesc_glue
(
bcx
,
abi
::
tydesc_field_take_glue
,
ti
);
let
opaque_v
=
PointerCast
(
bcx
,
vptrptr
,
T_ptr
(
T_ptr
(
ccx
.opaque_vec_type
)));
...
...
src/comp/middle/tstate/pre_post_conditions.rs
浏览文件 @
24102d50
...
...
@@ -73,7 +73,6 @@ fn find_pre_post_item(ccx: crate_ctxt, i: item) {
ccx
:
ccx
};
find_pre_post_fn
(
fcx
,
body
);
}
item_obj
(
o
,
_
,
_
)
{
for
m
in
o
.methods
{
find_pre_post_method
(
ccx
,
m
);
}}
item_impl
(
_
,
_
,
_
,
ms
)
{
for
m
in
ms
{
find_pre_post_method
(
ccx
,
m
);
}
}
}
}
...
...
@@ -551,15 +550,6 @@ fn combine_pp(antec: pre_and_post, fcx: fn_ctxt, &&pp: pre_and_post,
expr_break
.
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
expr_cont
.
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
expr_mac
(
_
)
{
fcx
.ccx.tcx.sess
.bug
(
"unexpanded macro"
);
}
expr_anon_obj
(
anon_obj
)
{
alt
anon_obj
.inner_obj
{
some
(
ex
)
{
find_pre_post_expr
(
fcx
,
ex
);
copy_pre_post
(
fcx
.ccx
,
e
.id
,
ex
);
}
none
.
{
clear_pp
(
expr_pp
(
fcx
.ccx
,
e
));
}
}
}
}
}
...
...
src/comp/middle/tstate/states.rs
浏览文件 @
24102d50
...
...
@@ -609,12 +609,6 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
}
expr_break
.
{
ret
pure_exp
(
fcx
.ccx
,
e
.id
,
pres
);
}
expr_cont
.
{
ret
pure_exp
(
fcx
.ccx
,
e
.id
,
pres
);
}
expr_anon_obj
(
anon_obj
)
{
alt
anon_obj
.inner_obj
{
some
(
wt
)
{
ret
find_pre_post_state_sub
(
fcx
,
pres
,
wt
,
e
.id
,
none
);
}
none
.
{
ret
pure_exp
(
fcx
.ccx
,
e
.id
,
pres
);
}
}
}
}
}
...
...
src/comp/middle/ty.rs
浏览文件 @
24102d50
...
...
@@ -72,7 +72,6 @@
export
mk_native
;
export
mk_native_fn
;
export
mk_nil
;
export
mk_obj
;
export
mk_iface
;
export
mk_res
;
export
mk_param
;
...
...
@@ -124,7 +123,6 @@
export
ty_vec
;
export
ty_native
;
export
ty_nil
;
export
ty_obj
;
export
ty_iface
;
export
ty_res
;
export
ty_param
;
...
...
@@ -138,7 +136,7 @@
export
ty_uniq
;
export
ty_var
;
export
ty_named
;
export
same_type
,
same_method
;
export
same_type
;
export
ty_var_id
;
export
ty_param_substs_opt_and_ty_to_monotype
;
export
ty_fn_args
;
...
...
@@ -266,7 +264,6 @@
ty_rec
([
field
]);
ty_fn
(
fn_ty
);
ty_native_fn
([
arg
],
t
);
ty_obj
([
method
]);
ty_iface
(
def_id
,
[
t
]);
ty_res
(
def_id
,
t
,
[
t
]);
ty_tup
([
t
]);
...
...
@@ -298,8 +295,6 @@
terr_record_size
(
uint
,
uint
);
terr_record_mutability
;
terr_record_fields
(
ast
::
ident
,
ast
::
ident
);
terr_meth_count
;
terr_obj_meths
(
ast
::
ident
,
ast
::
ident
);
terr_arg_count
;
terr_mode_mismatch
(
mode
,
mode
);
terr_constr_len
(
uint
,
uint
);
...
...
@@ -497,12 +492,6 @@ fn derive_flags_sig(cx: ctxt, &has_params: bool, &has_vars: bool,
ty_native_fn
(
args
,
tt
)
{
derive_flags_sig
(
cx
,
has_params
,
has_vars
,
args
,
tt
);
}
ty_obj
(
meths
)
{
for
m
:
method
in
meths
{
derive_flags_sig
(
cx
,
has_params
,
has_vars
,
m
.fty.inputs
,
m
.fty.output
);
}
}
ty_res
(
_
,
tt
,
tps
)
{
derive_flags_t
(
cx
,
has_params
,
has_vars
,
tt
);
for
tt
:
t
in
tps
{
derive_flags_t
(
cx
,
has_params
,
has_vars
,
tt
);
}
...
...
@@ -614,8 +603,6 @@ fn mk_native_fn(cx: ctxt, args: [arg], ty: t) -> t {
ret
gen_ty
(
cx
,
ty_native_fn
(
args
,
ty
));
}
fn
mk_obj
(
cx
:
ctxt
,
meths
:
[
method
])
->
t
{
ret
gen_ty
(
cx
,
ty_obj
(
meths
));
}
fn
mk_iface
(
cx
:
ctxt
,
did
:
ast
::
def_id
,
tys
:
[
t
])
->
t
{
ret
gen_ty
(
cx
,
ty_iface
(
did
,
tys
));
}
...
...
@@ -705,12 +692,6 @@ fn walk_ty(cx: ctxt, walker: ty_walk, ty: t) {
for
a
:
arg
in
args
{
walk_ty
(
cx
,
walker
,
a
.ty
);
}
walk_ty
(
cx
,
walker
,
ret_ty
);
}
ty_obj
(
methods
)
{
for
m
:
method
in
methods
{
for
a
:
arg
in
m
.fty.inputs
{
walk_ty
(
cx
,
walker
,
a
.ty
);
}
walk_ty
(
cx
,
walker
,
m
.fty.output
);
}
}
ty_res
(
_
,
sub
,
tps
)
{
walk_ty
(
cx
,
walker
,
sub
);
for
tp
:
t
in
tps
{
walk_ty
(
cx
,
walker
,
tp
);
}
...
...
@@ -797,18 +778,6 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
}
ty
=
mk_native_fn
(
cx
,
new_args
,
fold_ty
(
cx
,
fld
,
ret_ty
));
}
ty_obj
(
methods
)
{
let
new_methods
=
vec
::
map
(
methods
,
{|
m
|
let
new_args
=
vec
::
map
(
m
.fty.inputs
,
{|
a
|
{
mode
:
a
.mode
,
ty
:
fold_ty
(
cx
,
fld
,
a
.ty
)}
});
{
ident
:
m
.ident
,
tps
:
m
.tps
,
fty
:
{
inputs
:
new_args
,
output
:
fold_ty
(
cx
,
fld
,
m
.fty.output
)
with
m
.fty
}}
});
ty
=
mk_obj
(
cx
,
new_methods
);
}
ty_res
(
did
,
subty
,
tps
)
{
let
new_tps
=
[];
for
tp
:
t
in
tps
{
new_tps
+=
[
fold_ty
(
cx
,
fld
,
tp
)];
}
...
...
@@ -850,7 +819,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_native_fn
(
_
,
_
)
|
ty_
obj
(
_
)
|
ty_
res
(
_
,
_
,
_
)
{
true
}
ty_native_fn
(
_
,
_
)
|
ty_res
(
_
,
_
,
_
)
{
true
}
_
{
false
}
}
}
...
...
@@ -1056,9 +1025,6 @@ fn type_kind(cx: ctxt, ty: t) -> kind {
ty_native
(
_
)
|
ty_ptr
(
_
)
|
ty_send_type
.
|
ty_str
.
|
ty_native_fn
(
_
,
_
)
{
kind_sendable
}
ty_type
.
{
kind_copyable
}
// FIXME: obj is broken for now, since we aren't asserting
// anything about its fields.
ty_obj
(
_
)
{
kind_copyable
}
ty_fn
(
f
)
{
proto_kind
(
f
.proto
)
}
ty_opaque_closure_ptr
(
ck_block
.
)
{
kind_noncopyable
}
ty_opaque_closure_ptr
(
ck_box
.
)
{
kind_copyable
}
...
...
@@ -1233,7 +1199,7 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
ty_send_type
.
|
ty_type
.
|
ty_native
(
_
)
|
ty_ptr
(
_
)
{
result
=
true
;
}
// Boxed types
ty_str
.
|
ty_box
(
_
)
|
ty_uniq
(
_
)
|
ty_vec
(
_
)
|
ty_fn
(
_
)
|
ty_native_fn
(
_
,
_
)
|
ty_
obj
(
_
)
|
ty_
iface
(
_
,
_
)
{
result
=
false
;
}
ty_native_fn
(
_
,
_
)
|
ty_iface
(
_
,
_
)
{
result
=
false
;
}
// Structural types
ty_tag
(
did
,
tps
)
{
let
variants
=
tag_variants
(
cx
,
did
);
...
...
@@ -1417,11 +1383,6 @@ fn hash_fn(id: uint, args: [arg], rty: t) -> uint {
// ???
ty_fn
(
f
)
{
ret
hash_fn
(
27u
,
f
.inputs
,
f
.output
);
}
ty_native_fn
(
args
,
rty
)
{
ret
hash_fn
(
28u
,
args
,
rty
);
}
ty_obj
(
methods
)
{
let
h
=
29u
;
for
m
:
method
in
methods
{
h
+=
(
h
<<
5u
)
+
str
::
hash
(
m
.ident
);
}
ret
h
;
}
ty_var
(
v
)
{
ret
hash_uint
(
30u
,
v
as
uint
);
}
ty_param
(
pid
,
_
)
{
ret
hash_uint
(
31u
,
pid
);
}
ty_type
.
{
ret
32u
;
}
...
...
@@ -1670,20 +1631,11 @@ fn expr_has_ty_params(cx: ctxt, expr: @ast::expr) -> bool {
ret
node_id_has_type_params
(
cx
,
expr
.id
);
}
fn
expr_is_lval
(
method_map
:
typeck
::
method_map
,
tcx
:
ty
::
ctxt
,
e
:
@
ast
::
expr
)
->
bool
{
fn
expr_is_lval
(
method_map
:
typeck
::
method_map
,
e
:
@
ast
::
expr
)
->
bool
{
alt
e
.node
{
ast
::
expr_path
(
_
)
|
ast
::
expr_index
(
_
,
_
)
|
ast
::
expr_unary
(
ast
::
deref
.
,
_
)
{
true
}
ast
::
expr_field
(
base
,
ident
,
_
)
{
method_map
.contains_key
(
e
.id
)
?
false
:
{
let
basety
=
type_autoderef
(
tcx
,
expr_ty
(
tcx
,
base
));
alt
struct
(
tcx
,
basety
)
{
ty_obj
(
_
)
{
false
}
ty_rec
(
_
)
{
true
}
}
}
}
ast
::
expr_field
(
base
,
ident
,
_
)
{
!
method_map
.contains_key
(
e
.id
)
}
_
{
false
}
}
}
...
...
@@ -2060,35 +2012,6 @@ fn unify_native_fn(cx: @ctxt, expected_inputs: [arg], expected_output: t,
err
{
err
}
}
}
fn
unify_obj
(
cx
:
@
ctxt
,
expected_meths
:
[
method
],
actual_meths
:
[
method
],
variance
:
variance
)
->
result
{
let
result_meths
:
[
method
]
=
[];
let
i
:
uint
=
0u
;
let
expected_len
:
uint
=
vec
::
len
(
expected_meths
);
let
actual_len
:
uint
=
vec
::
len
(
actual_meths
);
if
expected_len
!=
actual_len
{
ret
ures_err
(
terr_meth_count
);
}
while
i
<
expected_len
{
let
e_meth
=
expected_meths
[
i
];
let
a_meth
=
actual_meths
[
i
];
if
!
str
::
eq
(
e_meth
.ident
,
a_meth
.ident
)
{
ret
ures_err
(
terr_obj_meths
(
e_meth
.ident
,
a_meth
.ident
));
}
alt
unify_fn
(
cx
,
e_meth
.fty
,
a_meth
.fty
,
variance
)
{
ures_ok
(
tfn
)
{
alt
struct
(
cx
.tcx
,
tfn
)
{
ty_fn
(
f
)
{
result_meths
+=
[{
ident
:
e_meth
.ident
,
tps
:
a_meth
.tps
,
fty
:
f
}];
}
}
}
err
{
ret
err
;
}
}
i
+=
1u
;
}
let
t
=
mk_obj
(
cx
.tcx
,
result_meths
);
ret
ures_ok
(
t
);
}
// If the given type is a variable, returns the structure of that type.
fn
resolve_type_structure
(
tcx
:
ty_ctxt
,
vb
:
@
var_bindings
,
typ
:
t
)
->
...
...
@@ -2483,14 +2406,6 @@ fn unify_step(cx: @ctxt, expected: t, actual: t,
_
{
ret
ures_err
(
terr_mismatch
);
}
}
}
ty
::
ty_obj
(
expected_meths
)
{
alt
struct
(
cx
.tcx
,
actual
)
{
ty
::
ty_obj
(
actual_meths
)
{
ret
unify_obj
(
cx
,
expected_meths
,
actual_meths
,
variance
);
}
_
{
ret
ures_err
(
terr_mismatch
);
}
}
}
ty
::
ty_constr
(
expected_t
,
expected_constrs
)
{
// unify the base types...
...
...
@@ -2600,13 +2515,6 @@ fn same_type(cx: ctxt, a: t, b: t) -> bool {
_
{
false
}
}
}
fn
same_method
(
cx
:
ctxt
,
a
:
method
,
b
:
method
)
->
bool
{
a
.tps
==
b
.tps
&&
a
.fty.proto
==
b
.fty.proto
&&
a
.ident
==
b
.ident
&&
vec
::
all2
(
a
.fty.inputs
,
b
.fty.inputs
,
{|
a
,
b
|
a
.mode
==
b
.mode
&&
same_type
(
cx
,
a
.ty
,
b
.ty
)
})
&&
same_type
(
cx
,
a
.fty.output
,
b
.fty.output
)
&&
a
.fty.ret_style
==
b
.fty.ret_style
}
fn
type_err_to_str
(
err
:
ty
::
type_err
)
->
str
{
alt
err
{
...
...
@@ -2639,11 +2547,6 @@ fn to_str(s: ast::ret_style) -> str {
"' but found one with field '"
+
a_fld
+
"'"
;
}
terr_arg_count
.
{
ret
"incorrect number of function parameters"
;
}
terr_meth_count
.
{
ret
"incorrect number of object methods"
;
}
terr_obj_meths
(
e_meth
,
a_meth
)
{
ret
"expected an obj with method '"
+
e_meth
+
"' but found one with method '"
+
a_meth
+
"'"
;
}
terr_mode_mismatch
(
e_mode
,
a_mode
)
{
ret
"expected argument mode "
+
mode_str
(
e_mode
)
+
" but found "
+
mode_str
(
a_mode
);
...
...
@@ -2675,7 +2578,7 @@ fn substituter(_cx: ctxt, substs: @[ty::t], idx: uint, _did: def_id)
fn
def_has_ty_params
(
def
:
ast
::
def
)
->
bool
{
alt
def
{
ast
::
def_
obj_field
(
_
,
_
)
|
ast
::
def_
mod
(
_
)
|
ast
::
def_const
(
_
)
|
ast
::
def_mod
(
_
)
|
ast
::
def_const
(
_
)
|
ast
::
def_arg
(
_
,
_
)
|
ast
::
def_local
(
_
,
_
)
|
ast
::
def_upvar
(
_
,
_
,
_
)
|
ast
::
def_ty_param
(
_
,
_
)
|
ast
::
def_binding
(
_
)
|
ast
::
def_use
(
_
)
|
ast
::
def_native_ty
(
_
)
|
ast
::
def_self
(
_
)
|
ast
::
def_ty
(
_
)
{
false
}
...
...
src/comp/middle/typeck.rs
浏览文件 @
24102d50
...
...
@@ -42,9 +42,8 @@
type
ty_table
=
hashmap
<
ast
::
def_id
,
ty
::
t
>
;
// Used for typechecking the methods of an
object.
// Used for typechecking the methods of an
impl
tag
self_info
{
self_obj
([
ast
::
obj_field
],
ty
::
t
);
self_impl
(
ty
::
t
);
}
...
...
@@ -102,15 +101,10 @@ fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
let
typ
=
ty
::
mk_var
(
fcx
.ccx.tcx
,
lookup_local
(
fcx
,
sp
,
id
.node
));
ret
{
bounds
:
@
[],
ty
:
typ
};
}
ast
::
def_obj_field
(
id
,
_
)
{
assert
(
fcx
.locals
.contains_key
(
id
.node
));
let
typ
=
ty
::
mk_var
(
fcx
.ccx.tcx
,
lookup_local
(
fcx
,
sp
,
id
.node
));
ret
{
bounds
:
@
[],
ty
:
typ
};
}
ast
::
def_self
(
id
)
{
alt
get_self_info
(
fcx
.ccx
)
{
some
(
self_
obj
(
_
,
obj_t
))
|
some
(
self_impl
(
obj
_t
))
{
ret
{
bounds
:
@
[],
ty
:
obj
_t
};
some
(
self_
impl
(
impl
_t
))
{
ret
{
bounds
:
@
[],
ty
:
impl
_t
};
}
}
}
...
...
@@ -356,10 +350,6 @@ fn instantiate(tcx: ty::ctxt, sp: span, mode: mode,
}
}
}
ast
::
ty_obj
(
meths
)
{
let
ms
=
vec
::
map
(
meths
,
{|
m
|
ty_of_ty_method
(
tcx
,
mode
,
m
)
});
typ
=
ty
::
mk_obj
(
tcx
,
ty
::
sort_methods
(
ms
));
}
ast
::
ty_constr
(
t
,
cs
)
{
let
out_cs
=
[];
for
constr
:
@
ast
::
ty_constr
in
cs
{
...
...
@@ -391,11 +381,6 @@ fn ty_of_item(tcx: ty::ctxt, mode: mode, it: @ast::item)
ast
::
item_fn
(
decl
,
tps
,
_
)
{
ret
ty_of_fn
(
tcx
,
mode
,
decl
,
tps
,
local_def
(
it
.id
));
}
ast
::
item_obj
(
ob
,
tps
,
_
)
{
let
t_obj
=
ty_of_obj
(
tcx
,
mode
,
it
.ident
,
ob
,
tps
);
tcx
.tcache
.insert
(
local_def
(
it
.id
),
t_obj
);
ret
t_obj
;
}
ast
::
item_ty
(
t
,
tps
)
{
alt
tcx
.tcache
.find
(
local_def
(
it
.id
))
{
some
(
tpt
)
{
ret
tpt
;
}
...
...
@@ -541,30 +526,6 @@ fn ty_of_ty_method(tcx: ty::ctxt, mode: mode, m: ast::ty_method)
{
ident
:
m
.ident
,
tps
:
ty_param_bounds
(
tcx
,
mode
,
m
.tps
),
fty
:
ty_of_fn_decl
(
tcx
,
mode
,
ast
::
proto_bare
,
m
.decl
)}
}
fn
ty_of_obj
(
tcx
:
ty
::
ctxt
,
mode
:
mode
,
id
:
ast
::
ident
,
ob
:
ast
::
_
obj
,
ty_params
:
[
ast
::
ty_param
])
->
ty
::
ty_param_bounds_and_ty
{
let
bounds
=
ty_param_bounds
(
tcx
,
mode
,
ty_params
);
let
methods
=
vec
::
map
(
ob
.methods
,
{|
m
|
ty_of_method
(
tcx
,
mode
,
m
)});
let
t_obj
=
ty
::
mk_named
(
tcx
,
ty
::
mk_obj
(
tcx
,
ty
::
sort_methods
(
methods
)),
@
id
);
ret
{
bounds
:
bounds
,
ty
:
t_obj
};
}
fn
ty_of_obj_ctor
(
tcx
:
ty
::
ctxt
,
mode
:
mode
,
id
:
ast
::
ident
,
ob
:
ast
::
_
obj
,
ctor_id
:
ast
::
node_id
,
ty_params
:
[
ast
::
ty_param
])
->
ty
::
ty_param_bounds_and_ty
{
let
t_obj
=
ty_of_obj
(
tcx
,
mode
,
id
,
ob
,
ty_params
);
let
t_inputs
:
[
arg
]
=
[];
for
f
:
ast
::
obj_field
in
ob
.fields
{
let
t_field
=
ast_ty_to_ty
(
tcx
,
mode
,
f
.ty
);
t_inputs
+=
[{
mode
:
ast
::
by_copy
,
ty
:
t_field
}];
}
let
t_fn
=
ty
::
mk_fn
(
tcx
,
{
proto
:
ast
::
proto_box
,
inputs
:
t_inputs
,
output
:
t_obj
.ty
,
ret_style
:
ast
::
return_val
,
constraints
:
[]});
let
tpt
=
{
bounds
:
ty_param_bounds
(
tcx
,
mode
,
ty_params
),
ty
:
t_fn
};
tcx
.tcache
.insert
(
local_def
(
ctor_id
),
tpt
);
ret
tpt
;
}
// A convenience function to use a crate_ctxt to resolve names for
// ast_ty_to_ty.
...
...
@@ -766,38 +727,6 @@ fn convert(cx: @ctxt, it: @ast::item) {
_
{}
}
}
ast
::
item_obj
(
object
,
ty_params
,
ctor_id
)
{
// Now we need to call ty_of_obj_ctor(); this is the type that
// we write into the table for this item.
ty_of_item
(
cx
.tcx
,
m_collect
,
it
);
let
tpt
=
ty_of_obj_ctor
(
cx
.tcx
,
m_collect
,
it
.ident
,
object
,
ctor_id
,
ty_params
);
write
::
ty_only
(
cx
.tcx
,
ctor_id
,
tpt
.ty
);
// Write the methods into the type table.
//
// FIXME: Inefficient; this ends up calling
// get_obj_method_types() twice. (The first time was above in
// ty_of_obj().)
let
m_types
=
vec
::
map
(
object
.methods
,
{|
m
|
ty_of_method
(
cx
.tcx
,
m_collect
,
m
)});
let
i
=
0u
;
for
m
in
object
.methods
{
write
::
ty_only
(
cx
.tcx
,
m
.id
,
ty
::
mk_fn
(
cx
.tcx
,
m_types
[
i
]
.fty
));
i
+=
1u
;
}
// Write in the types of the object fields.
//
// FIXME: We want to use uint::range() here, but that causes
// an assertion in trans.
let
args
=
ty
::
ty_fn_args
(
cx
.tcx
,
tpt
.ty
);
i
=
0u
;
while
i
<
vec
::
len
::
<
ty
::
arg
>
(
args
)
{
let
fld
=
object
.fields
[
i
];
write
::
ty_only
(
cx
.tcx
,
fld
.id
,
args
[
i
]
.ty
);
i
+=
1u
;
}
}
ast
::
item_res
(
decl
,
tps
,
_
,
dtor_id
,
ctor_id
)
{
let
{
bounds
,
params
}
=
mk_ty_params
(
cx
.tcx
,
tps
);
let
t_arg
=
ty_of_arg
(
cx
.tcx
,
m_collect
,
decl
.inputs
[
0
]);
...
...
@@ -1190,16 +1119,6 @@ fn gather_locals(ccx: @crate_ctxt,
}
};
// Add object fields, if any.
alt
get_self_info
(
ccx
)
{
some
(
self_obj
(
ofs
,
_
))
{
for
f
in
ofs
{
assign
(
f
.id
,
some
(
ty
::
node_id_to_type
(
ccx
.tcx
,
f
.id
)));
}
}
_
{}
}
// Add formal parameters.
let
args
=
ty
::
ty_fn_args
(
ccx
.tcx
,
ty
::
node_id_to_type
(
ccx
.tcx
,
id
));
let
i
=
0u
;
...
...
@@ -2323,21 +2242,6 @@ fn get_node(f: spanned<field>) -> field { f.node }
_
{}
}
}
ty
::
ty_obj
(
methods
)
{
alt
ty
::
method_idx
(
field
,
methods
)
{
some
(
ix
)
{
if
n_tys
>
0u
{
tcx
.sess
.span_err
(
expr
.span
,
"can't provide type parameters
\
to an obj method"
);
}
write
::
ty_only_fixup
(
fcx
,
id
,
ty
::
mk_fn
(
tcx
,
methods
[
ix
]
.fty
));
handled
=
true
;
}
_
{}
}
}
_
{}
}
if
!
handled
{
...
...
@@ -2408,104 +2312,6 @@ fn get_node(f: spanned<field>) -> field { f.node }
}
}
}
ast
::
expr_anon_obj
(
ao
)
{
let
fields
:
[
ast
::
anon_obj_field
]
=
[];
alt
ao
.fields
{
none
.
{
}
some
(
v
)
{
fields
=
v
;
}
}
let
method_types
:
[
ty
::
method
]
=
[];
{
// Outer methods.
for
m
:
@
ast
::
method
in
ao
.methods
{
method_types
+=
[
ty_of_method
(
fcx
.ccx.tcx
,
m_check
,
m
)];
}
// Inner methods.
// Typecheck 'inner_obj'. If it exists, it had better have object
// type.
let
inner_obj_methods
:
[
ty
::
method
]
=
[];
let
inner_obj_sty
:
option
::
t
<
ty
::
sty
>
=
none
;
alt
ao
.inner_obj
{
none
.
{
}
some
(
e
)
{
// If there's a inner_obj, we push it onto the self_infos
// stack so that self-calls can be checked within its context
// later.
bot
|
=
check_expr
(
fcx
,
e
);
let
inner_obj_ty
=
expr_ty
(
tcx
,
e
);
inner_obj_sty
=
some
(
structure_of
(
fcx
,
e
.span
,
inner_obj_ty
));
alt
inner_obj_sty
{
none
.
{
}
some
(
sty
)
{
alt
sty
{
ty
::
ty_obj
(
ms
)
{
inner_obj_methods
=
ms
;
}
_
{
// The user is trying to extend a non-object.
tcx
.sess
.span_fatal
(
e
.span
,
syntax
::
print
::
pprust
::
expr_to_str
(
e
)
+
" does not have object type"
);
}
}
}
}
}
}
// Whenever an outer method overrides an inner, we need to remove
// that inner from the type. Filter inner_obj_methods to remove
// any methods that share a name with an outer method.
fn
filtering_fn
(
ccx
:
@
crate_ctxt
,
m
:
ty
::
method
,
outer_obj_methods
:
[
@
ast
::
method
])
->
option
::
t
<
ty
::
method
>
{
for
om
:
@
ast
::
method
in
outer_obj_methods
{
if
str
::
eq
(
om
.ident
,
m
.ident
)
{
// We'd better be overriding with one of the same
// type. Check to make sure.
let
new_type
=
ty_of_method
(
ccx
.tcx
,
m_check
,
om
);
if
!
ty
::
same_method
(
ccx
.tcx
,
new_type
,
m
)
{
ccx
.tcx.sess
.span_fatal
(
om
.span
,
"attempted to override method "
+
m
.ident
+
" with one of a different type"
);
}
ret
none
;
}
}
ret
some
(
m
);
}
let
f
=
bind
filtering_fn
(
fcx
.ccx
,
_
,
ao
.methods
);
inner_obj_methods
=
vec
::
filter_map
(
inner_obj_methods
,
f
);
method_types
+=
inner_obj_methods
;
}
let
ot
=
ty
::
mk_obj
(
tcx
,
ty
::
sort_methods
(
method_types
));
write
::
ty_only_fixup
(
fcx
,
id
,
ot
);
// Write the methods into the node type table. (This happens in
// collect::convert for regular objects.)
let
i
=
0u
;
while
i
<
vec
::
len
(
ao
.methods
)
{
write
::
ty_only
(
tcx
,
ao
.methods
[
i
]
.id
,
ty
::
mk_fn
(
tcx
,
method_types
[
i
]
.fty
));
i
+=
1u
;
}
fcx
.ccx.self_infos
+=
[
self_obj
(
vec
::
map
(
fields
,
ast_util
::
obj_field_from_anon_obj_field
),
ot
)];
// Typecheck the methods.
for
method
:
@
ast
::
method
in
ao
.methods
{
check_method
(
fcx
.ccx
,
method
);
}
// Now remove the info from the stack.
vec
::
pop
(
fcx
.ccx.self_infos
);
}
_
{
tcx
.sess
.unimpl
(
"expr type in typeck::check_expr"
);
}
}
if
bot
{
write
::
ty_only_fixup
(
fcx
,
expr
.id
,
ty
::
mk_bot
(
tcx
));
}
...
...
@@ -2832,15 +2638,6 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) {
ast
::
item_res
(
decl
,
tps
,
body
,
dtor_id
,
_
)
{
check_fn
(
ccx
,
ast
::
proto_bare
,
decl
,
body
,
dtor_id
,
none
);
}
ast
::
item_obj
(
ob
,
tps
,
_
)
{
// We're entering an object, so gather up the info we need.
ccx
.self_infos
+=
[
self_obj
(
ob
.fields
,
ccx
.tcx.tcache
.get
(
local_def
(
it
.id
))
.ty
)];
// Typecheck the methods.
for
method
:
@
ast
::
method
in
ob
.methods
{
check_method
(
ccx
,
method
);
}
// Now remove the info from the stack.
vec
::
pop
(
ccx
.self_infos
);
}
ast
::
item_impl
(
tps
,
_
,
ty
,
ms
)
{
ccx
.self_infos
+=
[
self_impl
(
ast_ty_to_ty
(
ccx
.tcx
,
m_check
,
ty
))];
for
m
in
ms
{
check_method
(
ccx
,
m
);
}
...
...
src/comp/rustc.rc
浏览文件 @
24102d50
...
...
@@ -18,7 +18,6 @@ mod middle {
mod
trans_build
;
mod
trans
;
mod
trans_alt
;
mod
trans_objects
;
mod
trans_uniq
;
mod
trans_closure
;
mod
trans_vec
;
...
...
src/comp/syntax/ast.rs
浏览文件 @
24102d50
...
...
@@ -34,7 +34,6 @@
tag
def
{
def_fn
(
def_id
,
purity
);
def_obj_field
(
def_id
,
mutability
);
def_self
(
def_id
);
def_mod
(
def_id
);
def_native_mod
(
def_id
);
...
...
@@ -234,7 +233,6 @@
/* FIXME Would be nice if expr_check desugared
to expr_if_check. */
expr_if_check
(
@
expr
,
blk
,
option
::
t
<@
expr
>
);
expr_anon_obj
(
anon_obj
);
expr_mac
(
mac
);
}
...
...
@@ -318,7 +316,6 @@
ty_chan
(
@
ty
);
ty_rec
([
ty_field
]);
ty_fn
(
proto
,
fn_decl
);
ty_obj
([
ty_method
]);
ty_tup
([
@
ty
]);
ty_path
(
@
path
,
node_id
);
ty_type
;
...
...
@@ -389,19 +386,6 @@
type
method
=
{
ident
:
ident
,
tps
:
[
ty_param
],
decl
:
fn_decl
,
body
:
blk
,
id
:
node_id
,
span
:
span
};
type
obj_field
=
{
mut
:
mutability
,
ty
:
@
ty
,
ident
:
ident
,
id
:
node_id
};
type
anon_obj_field
=
{
mut
:
mutability
,
ty
:
@
ty
,
expr
:
@
expr
,
ident
:
ident
,
id
:
node_id
};
type
_
obj
=
{
fields
:
[
obj_field
],
methods
:
[
@
method
]};
type
anon_obj
=
// New fields and methods, if they exist.
// inner_obj: the original object being extended, if it exists.
{
fields
:
option
::
t
<
[
anon_obj_field
]
>
,
methods
:
[
@
method
],
inner_obj
:
option
::
t
<@
expr
>
};
type
_
mod
=
{
view_items
:
[
@
view_item
],
items
:
[
@
item
]};
tag
native_abi
{
...
...
@@ -439,9 +423,6 @@
view_item_export
([
ident
],
node_id
);
}
type
obj_def_ids
=
{
ty
:
node_id
,
ctor
:
node_id
};
// Meta-data associated with an item
type
attribute
=
spanned
<
attribute_
>
;
...
...
@@ -453,8 +434,8 @@
type
attribute_
=
{
style
:
attr_style
,
value
:
meta_item
};
type
item
=
// For objs and resources, this is the type def_id
{
ident
:
ident
,
attrs
:
[
attribute
],
id
:
node_id
,
node
:
item_
,
span
:
span
};
type
item
=
{
ident
:
ident
,
attrs
:
[
attribute
],
id
:
node_id
,
node
:
item_
,
span
:
span
};
tag
item_
{
item_const
(
@
ty
,
@
expr
);
...
...
@@ -463,7 +444,6 @@
item_native_mod
(
native_mod
);
item_ty
(
@
ty
,
[
ty_param
]);
item_tag
([
variant
],
[
ty_param
]);
item_obj
(
_
obj
,
[
ty_param
],
/* constructor id */
node_id
);
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
浏览文件 @
24102d50
...
...
@@ -25,7 +25,7 @@ fn variant_def_ids(d: def) -> {tg: def_id, var: def_id} {
fn
def_id_of_def
(
d
:
def
)
->
def_id
{
alt
d
{
def_fn
(
id
,
_
)
|
def_
obj_field
(
id
,
_
)
|
def_
self
(
id
)
|
def_mod
(
id
)
|
def_fn
(
id
,
_
)
|
def_self
(
id
)
|
def_mod
(
id
)
|
def_native_mod
(
id
)
|
def_const
(
id
)
|
def_arg
(
id
,
_
)
|
def_local
(
id
,
_
)
|
def_variant
(
_
,
id
)
|
def_ty
(
id
)
|
def_ty_param
(
id
,
_
)
|
def_binding
(
id
)
|
def_use
(
id
)
|
def_native_ty
(
id
)
|
...
...
@@ -215,10 +215,6 @@ fn default_block(stmts1: [@stmt], expr1: option::t<@expr>, id1: node_id) ->
{
view_items
:
[],
stmts
:
stmts1
,
expr
:
expr1
,
id
:
id1
,
rules
:
default_blk
}
}
fn
obj_field_from_anon_obj_field
(
f
:
anon_obj_field
)
->
obj_field
{
ret
{
mut
:
f
.mut
,
ty
:
f
.ty
,
ident
:
f
.ident
,
id
:
f
.id
};
}
// This is a convenience function to transfor ternary expressions to if
// expressions so that they can be treated the same
fn
ternary_to_if
(
e
:
@
expr
)
->
@
expr
{
...
...
src/comp/syntax/fold.rs
浏览文件 @
24102d50
...
...
@@ -95,7 +95,6 @@ fn nf_crate_directive_dummy(&&_c: @crate_directive) -> @crate_directive {
fn
nf_variant_dummy
(
_
v
:
variant
)
->
variant
{
fail
;
}
fn
nf_ident_dummy
(
&&
_
i
:
ident
)
->
ident
{
fail
;
}
fn
nf_path_dummy
(
&&
_
p
:
@
path
)
->
@
path
{
fail
;
}
fn
nf_obj_field_dummy
(
_
o
:
obj_field
)
->
obj_field
{
fail
;
}
fn
nf_local_dummy
(
&&
_
o
:
@
local
)
->
@
local
{
fail
;
}
/* some little folds that probably aren't useful to have in ast_fold itself*/
...
...
@@ -216,14 +215,6 @@ fn noop_fold_item(&&i: @item, fld: ast_fold) -> @item {
}
fn
noop_fold_item_underscore
(
i
:
item_
,
fld
:
ast_fold
)
->
item_
{
fn
fold_obj_field_
(
of
:
obj_field
,
fld
:
ast_fold
)
->
obj_field
{
ret
{
mut
:
of
.mut
,
ty
:
fld
.fold_ty
(
of
.ty
),
ident
:
fld
.fold_ident
(
of
.ident
),
id
:
of
.id
};
}
let
fold_obj_field
=
bind
fold_obj_field_
(
_
,
fld
);
ret
alt
i
{
item_const
(
t
,
e
)
{
item_const
(
fld
.fold_ty
(
t
),
fld
.fold_expr
(
e
))
}
item_fn
(
decl
,
typms
,
body
)
{
...
...
@@ -236,11 +227,6 @@ fn fold_obj_field_(of: obj_field, fld: ast_fold) -> obj_field {
item_tag
(
variants
,
typms
)
{
item_tag
(
vec
::
map
(
variants
,
fld
.fold_variant
),
typms
)
}
item_obj
(
o
,
typms
,
d
)
{
item_obj
({
fields
:
vec
::
map
(
o
.fields
,
fold_obj_field
),
methods
:
vec
::
map
(
o
.methods
,
fld
.fold_method
)},
typms
,
d
)
}
item_impl
(
tps
,
ifce
,
ty
,
methods
)
{
item_impl
(
tps
,
option
::
map
(
ifce
,
fld
.fold_ty
),
fld
.fold_ty
(
ty
),
vec
::
map
(
methods
,
fld
.fold_method
))
...
...
@@ -327,29 +313,6 @@ fn fold_field_(field: field, fld: ast_fold) -> field {
span
:
field
.span
};
}
let
fold_field
=
bind
fold_field_
(
_
,
fld
);
fn
fold_anon_obj_
(
ao
:
anon_obj
,
fld
:
ast_fold
)
->
anon_obj
{
fn
fold_anon_obj_field_
(
aof
:
anon_obj_field
,
fld
:
ast_fold
)
->
anon_obj_field
{
ret
{
mut
:
aof
.mut
,
ty
:
fld
.fold_ty
(
aof
.ty
),
expr
:
fld
.fold_expr
(
aof
.expr
),
ident
:
fld
.fold_ident
(
aof
.ident
),
id
:
aof
.id
};
}
let
fold_anon_obj_field
=
bind
fold_anon_obj_field_
(
_
,
fld
);
ret
{
fields
:
alt
ao
.fields
{
option
::
none
.
{
ao
.fields
}
option
::
some
(
v
)
{
option
::
some
(
vec
::
map
(
v
,
fold_anon_obj_field
))
}
},
methods
:
vec
::
map
(
ao
.methods
,
fld
.fold_method
),
inner_obj
:
option
::
map
(
ao
.inner_obj
,
fld
.fold_expr
)}
}
let
fold_anon_obj
=
bind
fold_anon_obj_
(
_
,
fld
);
let
fold_mac
=
bind
fold_mac_
(
_
,
fld
);
...
...
@@ -439,7 +402,6 @@ fn fold_anon_obj_field_(aof: anon_obj_field, fld: ast_fold) ->
expr_if_check
(
fld
.fold_expr
(
cond
),
fld
.fold_block
(
tr
),
option
::
map
(
fl
,
fld
.fold_expr
))
}
expr_anon_obj
(
ao
)
{
expr_anon_obj
(
fold_anon_obj
(
ao
))
}
expr_mac
(
mac
)
{
expr_mac
(
fold_mac
(
mac
))
}
}
}
...
...
src/comp/syntax/parse/parser.rs
浏览文件 @
24102d50
...
...
@@ -139,8 +139,7 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
"cont"
,
"ret"
,
"be"
,
"fail"
,
"type"
,
"resource"
,
"check"
,
"assert"
,
"claim"
,
"native"
,
"fn"
,
"pure"
,
"unsafe"
,
"block"
,
"import"
,
"export"
,
"let"
,
"const"
,
"log"
,
"tag"
,
"obj"
,
"copy"
,
"sendfn"
,
"impl"
,
"iface"
,
"enum"
]
{
"log"
,
"copy"
,
"sendfn"
,
"impl"
,
"iface"
,
"enum"
]
{
words
.insert
(
word
,
());
}
words
...
...
@@ -260,12 +259,12 @@ fn parse_fn_input_ty(p: parser) -> ast::arg {
constraints
:
constrs
});
}
fn
parse_ty_methods
(
p
:
parser
,
allow_tps
:
bool
)
->
[
ast
::
ty_method
]
{
fn
parse_ty_methods
(
p
:
parser
)
->
[
ast
::
ty_method
]
{
parse_seq
(
token
::
LBRACE
,
token
::
RBRACE
,
seq_sep_none
(),
{|
p
|
let
flo
=
p
.span.lo
;
expect_word
(
p
,
"fn"
);
let
ident
=
parse_value_ident
(
p
);
let
tps
=
allow_tps
?
parse_ty_params
(
p
)
:
[]
;
let
tps
=
parse_ty_params
(
p
)
;
let
f
=
parse_ty_fn
(
ast
::
proto_bare
,
p
),
fhi
=
p
.last_span.hi
;
expect
(
p
,
token
::
SEMI
);
alt
f
{
...
...
@@ -490,8 +489,6 @@ fn parse_ty(p: parser, colons_before_params: bool) -> @ast::ty {
}
else
if
eat_word
(
p
,
"sendfn"
)
{
//(breaks prettyprinting!) p.warn("sendfn is deprecated, use fn~");
t
=
parse_ty_fn
(
ast
::
proto_uniq
,
p
);
}
else
if
eat_word
(
p
,
"obj"
)
{
t
=
ast
::
ty_obj
(
parse_ty_methods
(
p
,
false
));
}
else
if
p
.token
==
token
::
MOD_SEP
||
is_ident
(
p
.token
)
{
let
path
=
parse_path
(
p
);
t
=
ast
::
ty_path
(
path
,
p
.get_id
());
...
...
@@ -825,35 +822,6 @@ fn parse_bottom_expr(p: parser) -> pexpr {
}
else
if
p
.token
==
token
::
ELLIPSIS
{
p
.bump
();
ret
pexpr
(
mk_mac_expr
(
p
,
lo
,
p
.span.hi
,
ast
::
mac_ellipsis
));
}
else
if
eat_word
(
p
,
"obj"
)
{
// Anonymous object
// Only make people type () if they're actually adding new fields
let
fields
:
option
::
t
<
[
ast
::
anon_obj_field
]
>
=
none
;
if
p
.token
==
token
::
LPAREN
{
p
.bump
();
fields
=
some
(
parse_seq_to_end
(
token
::
RPAREN
,
seq_sep
(
token
::
COMMA
),
parse_anon_obj_field
,
p
));
}
let
meths
:
[
@
ast
::
method
]
=
[];
let
inner_obj
:
option
::
t
<@
ast
::
expr
>
=
none
;
expect
(
p
,
token
::
LBRACE
);
while
p
.token
!=
token
::
RBRACE
{
if
eat_word
(
p
,
"with"
)
{
inner_obj
=
some
(
parse_expr
(
p
));
}
else
{
meths
+=
[
parse_method
(
p
,
false
)];
}
}
hi
=
p
.span.hi
;
expect
(
p
,
token
::
RBRACE
);
// fields and methods may be *additional* or *overriding* fields
// and methods if there's a inner_obj, or they may be the *only*
// fields and methods if there's no inner_obj.
// We don't need to pull ".node" out of fields because it's not a
// "spanned".
let
ob
=
{
fields
:
fields
,
methods
:
meths
,
inner_obj
:
inner_obj
};
ex
=
ast
::
expr_anon_obj
(
ob
);
}
else
if
eat_word
(
p
,
"bind"
)
{
let
e
=
parse_expr_res
(
p
,
RESTRICT_NO_CALL_EXPRS
);
fn
parse_expr_opt
(
p
:
parser
)
->
option
::
t
<@
ast
::
expr
>
{
...
...
@@ -1781,55 +1749,20 @@ fn parse_item_fn(p: parser, purity: ast::purity,
ast
::
item_fn
(
decl
,
t
.tps
,
body
),
attrs
);
}
fn
parse_obj_field
(
p
:
parser
)
->
ast
::
obj_field
{
let
mut
=
parse_mutability
(
p
);
let
ident
=
parse_value_ident
(
p
);
expect
(
p
,
token
::
COLON
);
let
ty
=
parse_ty
(
p
,
false
);
ret
{
mut
:
mut
,
ty
:
ty
,
ident
:
ident
,
id
:
p
.get_id
()};
}
fn
parse_anon_obj_field
(
p
:
parser
)
->
ast
::
anon_obj_field
{
let
mut
=
parse_mutability
(
p
);
let
ident
=
parse_value_ident
(
p
);
expect
(
p
,
token
::
COLON
);
let
ty
=
parse_ty
(
p
,
false
);
expect
(
p
,
token
::
EQ
);
let
expr
=
parse_expr
(
p
);
ret
{
mut
:
mut
,
ty
:
ty
,
expr
:
expr
,
ident
:
ident
,
id
:
p
.get_id
()};
}
fn
parse_method
(
p
:
parser
,
allow_tps
:
bool
)
->
@
ast
::
method
{
fn
parse_method
(
p
:
parser
)
->
@
ast
::
method
{
let
lo
=
p
.span.lo
;
expect_word
(
p
,
"fn"
);
let
ident
=
parse_value_ident
(
p
);
let
tps
=
allow_tps
?
parse_ty_params
(
p
)
:
[]
;
let
tps
=
parse_ty_params
(
p
)
;
let
decl
=
parse_fn_decl
(
p
,
ast
::
impure_fn
);
let
body
=
parse_block
(
p
);
@
{
ident
:
ident
,
tps
:
tps
,
decl
:
decl
,
body
:
body
,
id
:
p
.get_id
(),
span
:
ast_util
::
mk_sp
(
lo
,
body
.span.hi
)}
}
fn
parse_item_obj
(
p
:
parser
,
attrs
:
[
ast
::
attribute
])
->
@
ast
::
item
{
let
lo
=
p
.last_span.lo
;
let
ident
=
parse_value_ident
(
p
);
let
ty_params
=
parse_ty_params
(
p
);
let
fields
:
ast
::
spanned
<
[
ast
::
obj_field
]
>
=
parse_seq
(
token
::
LPAREN
,
token
::
RPAREN
,
seq_sep
(
token
::
COMMA
),
parse_obj_field
,
p
);
let
meths
:
[
@
ast
::
method
]
=
[];
expect
(
p
,
token
::
LBRACE
);
while
p
.token
!=
token
::
RBRACE
{
meths
+=
[
parse_method
(
p
,
false
)];
}
let
hi
=
p
.span.hi
;
expect
(
p
,
token
::
RBRACE
);
let
ob
:
ast
::
_
obj
=
{
fields
:
fields
.node
,
methods
:
meths
};
ret
mk_item
(
p
,
lo
,
hi
,
ident
,
ast
::
item_obj
(
ob
,
ty_params
,
p
.get_id
()),
attrs
);
}
fn
parse_item_iface
(
p
:
parser
,
attrs
:
[
ast
::
attribute
])
->
@
ast
::
item
{
let
lo
=
p
.last_span.lo
,
ident
=
parse_ident
(
p
),
tps
=
parse_ty_params
(
p
),
meths
=
parse_ty_methods
(
p
,
true
);
tps
=
parse_ty_params
(
p
),
meths
=
parse_ty_methods
(
p
);
ret
mk_item
(
p
,
lo
,
p
.last_span.hi
,
ident
,
ast
::
item_iface
(
tps
,
meths
),
attrs
);
}
...
...
@@ -1861,7 +1794,7 @@ fn wrap_path(p: parser, pt: @ast::path) -> @ast::ty {
expect_word
(
p
,
"for"
);
let
ty
=
parse_ty
(
p
,
false
),
meths
=
[];
expect
(
p
,
token
::
LBRACE
);
while
!
eat
(
p
,
token
::
RBRACE
)
{
meths
+=
[
parse_method
(
p
,
true
)];
}
while
!
eat
(
p
,
token
::
RBRACE
)
{
meths
+=
[
parse_method
(
p
)];
}
ret
mk_item
(
p
,
lo
,
p
.last_span.hi
,
ident
,
ast
::
item_impl
(
tps
,
ifce
,
ty
,
meths
),
attrs
);
}
...
...
@@ -2169,9 +2102,6 @@ fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> {
ret
some
(
parse_item_type
(
p
,
attrs
));
}
else
if
eat_word
(
p
,
"tag"
)
||
eat_word
(
p
,
"enum"
)
{
ret
some
(
parse_item_tag
(
p
,
attrs
));
}
else
if
is_word
(
p
,
"obj"
)
&&
p
.look_ahead
(
1u
)
!=
token
::
LPAREN
{
p
.bump
();
ret
some
(
parse_item_obj
(
p
,
attrs
));
}
else
if
eat_word
(
p
,
"iface"
)
{
ret
some
(
parse_item_iface
(
p
,
attrs
));
}
else
if
eat_word
(
p
,
"impl"
)
{
...
...
src/comp/syntax/print/pprust.rs
浏览文件 @
24102d50
...
...
@@ -306,12 +306,6 @@ fn print_field(s: ps, f: ast::ty_field) {
ast
::
ty_fn
(
proto
,
d
)
{
print_ty_fn
(
s
,
proto
,
d
,
none
,
none
);
}
ast
::
ty_obj
(
methods
)
{
head
(
s
,
"obj"
);
bopen
(
s
);
for
m
in
methods
{
print_ty_method
(
s
,
m
);
}
bclose
(
s
,
ty
.span
);
}
ast
::
ty_path
(
path
,
_
)
{
print_path
(
s
,
path
,
false
);
}
ast
::
ty_type
.
{
word
(
s
.s
,
"type"
);
}
ast
::
ty_constr
(
t
,
cs
)
{
...
...
@@ -438,32 +432,6 @@ fn print_variant_arg(s: ps, arg: ast::variant_arg) {
bclose
(
s
,
item
.span
);
}
}
ast
::
item_obj
(
_
obj
,
params
,
_
)
{
head
(
s
,
"obj"
);
word
(
s
.s
,
item
.ident
);
print_type_params
(
s
,
params
);
popen
(
s
);
fn
print_field
(
s
:
ps
,
field
:
ast
::
obj_field
)
{
ibox
(
s
,
indent_unit
);
print_mutability
(
s
,
field
.mut
);
word_space
(
s
,
field
.ident
+
":"
);
print_type
(
s
,
field
.ty
);
end
(
s
);
}
fn
get_span
(
f
:
ast
::
obj_field
)
->
codemap
::
span
{
ret
f
.ty.span
;
}
commasep_cmnt
(
s
,
consistent
,
_
obj
.fields
,
print_field
,
get_span
);
pclose
(
s
);
space
(
s
.s
);
bopen
(
s
);
for
meth
:
@
ast
::
method
in
_
obj
.methods
{
hardbreak_if_not_bol
(
s
);
maybe_print_comment
(
s
,
meth
.span.lo
);
print_fn
(
s
,
meth
.decl
,
meth
.ident
,
meth
.tps
);
word
(
s
.s
,
" "
);
print_block
(
s
,
meth
.body
);
}
bclose
(
s
,
item
.span
);
}
ast
::
item_impl
(
tps
,
ifce
,
ty
,
methods
)
{
head
(
s
,
"impl"
);
word
(
s
.s
,
item
.ident
);
...
...
@@ -972,50 +940,6 @@ fn print_opt(s: ps, expr: option::t<@ast::expr>) {
pclose
(
s
);
}
ast
::
expr_mac
(
m
)
{
print_mac
(
s
,
m
);
}
ast
::
expr_anon_obj
(
anon_obj
)
{
head
(
s
,
"obj"
);
// Fields
popen
(
s
);
fn
print_field
(
s
:
ps
,
field
:
ast
::
anon_obj_field
)
{
ibox
(
s
,
indent_unit
);
print_mutability
(
s
,
field
.mut
);
word_space
(
s
,
field
.ident
+
":"
);
print_type
(
s
,
field
.ty
);
space
(
s
.s
);
word_space
(
s
,
"="
);
print_expr
(
s
,
field
.expr
);
end
(
s
);
}
fn
get_span
(
f
:
ast
::
anon_obj_field
)
->
codemap
::
span
{
ret
f
.ty.span
;
}
alt
anon_obj
.fields
{
none
.
{
}
some
(
fields
)
{
commasep_cmnt
(
s
,
consistent
,
fields
,
print_field
,
get_span
);
}
}
pclose
(
s
);
space
(
s
.s
);
bopen
(
s
);
// Methods
for
meth
:
@
ast
::
method
in
anon_obj
.methods
{
hardbreak_if_not_bol
(
s
);
maybe_print_comment
(
s
,
meth
.span.lo
);
print_fn
(
s
,
meth
.decl
,
meth
.ident
,
meth
.tps
);
word
(
s
.s
,
" "
);
print_block
(
s
,
meth
.body
);
}
// With object
alt
anon_obj
.inner_obj
{
none
.
{
}
some
(
e
)
{
space
(
s
.s
);
word_space
(
s
,
"with"
);
print_expr
(
s
,
e
);
}
}
bclose
(
s
,
expr
.span
);
}
}
s
.ann
.post
(
ann_node
);
end
(
s
);
...
...
src/comp/syntax/visit.rs
浏览文件 @
24102d50
...
...
@@ -126,14 +126,6 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
for
va
:
variant_arg
in
vr
.node.args
{
v
.visit_ty
(
va
.ty
,
e
,
v
);
}
}
}
item_obj
(
ob
,
tps
,
_
)
{
v
.visit_ty_params
(
tps
,
e
,
v
);
for
f
:
obj_field
in
ob
.fields
{
v
.visit_ty
(
f
.ty
,
e
,
v
);
}
for
m
:
@
method
in
ob
.methods
{
v
.visit_fn
(
fk_method
(
m
.ident
,
m
.tps
),
m
.decl
,
m
.body
,
m
.span
,
m
.id
,
e
,
v
);
}
}
item_impl
(
tps
,
ifce
,
ty
,
methods
)
{
v
.visit_ty_params
(
tps
,
e
,
v
);
alt
ifce
{
some
(
ty
)
{
v
.visit_ty
(
ty
,
e
,
v
);
}
_
{}
}
...
...
@@ -172,12 +164,6 @@ fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
}
v
.visit_ty
(
decl
.output
,
e
,
v
);
}
ty_obj
(
tmeths
)
{
for
m
:
ty_method
in
tmeths
{
for
a
in
m
.decl.inputs
{
v
.visit_ty
(
a
.ty
,
e
,
v
);
}
v
.visit_ty
(
m
.decl.output
,
e
,
v
);
}
}
ty_path
(
p
,
_
)
{
visit_path
(
p
,
e
,
v
);
}
ty_type
.
{
/* no-op */
}
ty_constr
(
t
,
cs
)
{
...
...
@@ -370,25 +356,6 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
}
expr_check
(
_
,
x
)
{
v
.visit_expr
(
x
,
e
,
v
);
}
expr_assert
(
x
)
{
v
.visit_expr
(
x
,
e
,
v
);
}
expr_anon_obj
(
anon_obj
)
{
alt
anon_obj
.fields
{
none
.
{
}
some
(
fields
)
{
for
f
:
anon_obj_field
in
fields
{
v
.visit_ty
(
f
.ty
,
e
,
v
);
v
.visit_expr
(
f
.expr
,
e
,
v
);
}
}
}
alt
anon_obj
.inner_obj
{
none
.
{
}
some
(
ex
)
{
v
.visit_expr
(
ex
,
e
,
v
);
}
}
for
m
:
@
method
in
anon_obj
.methods
{
v
.visit_fn
(
fk_method
(
m
.ident
,
m
.tps
),
m
.decl
,
m
.body
,
m
.span
,
m
.id
,
e
,
v
);
}
}
expr_mac
(
mac
)
{
visit_mac
(
mac
,
e
,
v
);
}
}
}
...
...
src/comp/util/ppaux.rs
浏览文件 @
24102d50
...
...
@@ -112,11 +112,6 @@ fn mt_to_str(cx: ctxt, m: mt) -> str {
fn_to_str
(
cx
,
ast
::
proto_bare
,
none
,
inputs
,
output
,
ast
::
return_val
,
[])
}
ty_obj
(
meths
)
{
let
strs
=
[];
for
m
:
method
in
meths
{
strs
+=
[
method_to_str
(
cx
,
m
)];
}
"obj {
\n\t
"
+
str
::
connect
(
strs
,
"
\n\t
"
)
+
"
\n
}"
}
ty_var
(
v
)
{
"<T"
+
int
::
str
(
v
)
+
">"
}
ty_param
(
id
,
_
)
{
"'"
+
str
::
unsafe_from_bytes
([(
'a'
as
u8
)
+
(
id
as
u8
)])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录