Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2fe299d1
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,发现更多精彩内容 >>
提交
2fe299d1
编写于
8月 02, 2012
作者:
M
Michael Sullivan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extend ast_map to know about method declarations in traits.
上级
97452c0c
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
48 addition
and
11 deletion
+48
-11
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+1
-1
src/libsyntax/ast_map.rs
src/libsyntax/ast_map.rs
+20
-8
src/libsyntax/ast_util.rs
src/libsyntax/ast_util.rs
+13
-0
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+1
-1
src/rustc/middle/trans/base.rs
src/rustc/middle/trans/base.rs
+7
-1
src/rustc/middle/trans/impl.rs
src/rustc/middle/trans/impl.rs
+2
-0
src/rustc/middle/ty.rs
src/rustc/middle/ty.rs
+4
-0
未找到文件。
src/libsyntax/ast.rs
浏览文件 @
2fe299d1
...
@@ -511,7 +511,7 @@ enum lit_ {
...
@@ -511,7 +511,7 @@ enum lit_ {
#[auto_serialize]
#[auto_serialize]
type
ty_method
=
{
ident
:
ident
,
attrs
:
~
[
attribute
],
type
ty_method
=
{
ident
:
ident
,
attrs
:
~
[
attribute
],
decl
:
fn_decl
,
tps
:
~
[
ty_param
],
self_ty
:
self_ty
,
decl
:
fn_decl
,
tps
:
~
[
ty_param
],
self_ty
:
self_ty
,
span
:
span
};
id
:
node_id
,
span
:
span
};
#[auto_serialize]
#[auto_serialize]
// A trait method is either required (meaning it doesn't have an
// A trait method is either required (meaning it doesn't have an
...
...
src/libsyntax/ast_map.rs
浏览文件 @
2fe299d1
...
@@ -35,6 +35,8 @@ fn path_to_str(p: path) -> ~str {
...
@@ -35,6 +35,8 @@ fn path_to_str(p: path) -> ~str {
enum
ast_node
{
enum
ast_node
{
node_item
(
@
item
,
@
path
),
node_item
(
@
item
,
@
path
),
node_foreign_item
(
@
foreign_item
,
foreign_abi
,
@
path
),
node_foreign_item
(
@
foreign_item
,
foreign_abi
,
@
path
),
node_trait_method
(
@
trait_method
,
def_id
/* trait did */
,
@
path
/* path to the trait */
),
node_method
(
@
method
,
def_id
/* impl did */
,
@
path
/* path to the impl */
),
node_method
(
@
method
,
def_id
/* impl did */
,
@
path
/* path to the impl */
),
node_variant
(
variant
,
@
item
,
@
path
),
node_variant
(
variant
,
@
item
,
@
path
),
node_expr
(
@
expr
),
node_expr
(
@
expr
),
...
@@ -218,19 +220,24 @@ fn map_item(i: @item, cx: ctx, v: vt) {
...
@@ -218,19 +220,24 @@ fn map_item(i: @item, cx: ctx, v: vt) {
let
(
_
,
ms
)
=
ast_util
::
split_class_items
(
items
);
let
(
_
,
ms
)
=
ast_util
::
split_class_items
(
items
);
// Map trait refs to their parent classes. This is
// Map trait refs to their parent classes. This is
// so we can find the self_ty
// so we can find the self_ty
do
vec
::
iter
(
traits
)
|
p
|
{
cx
.map
.insert
(
p
.ref_id
,
for
traits
.each
|
p
|
{
node_item
(
i
,
item_path
));
cx
.map
.insert
(
p
.ref_id
,
node_item
(
i
,
item_path
));
// This is so we can look up the right things when
// This is so we can look up the right things when
// encoding/decoding
// encoding/decoding
cx
.map
.insert
(
p
.impl_id
,
cx
.map
.insert
(
p
.impl_id
,
node_item
(
i
,
item_path
));
node_item
(
i
,
item_path
));
}
};
let
d_id
=
ast_util
::
local_def
(
i
.id
);
let
d_id
=
ast_util
::
local_def
(
i
.id
);
let
p
=
extend
(
cx
,
i
.ident
);
let
p
=
extend
(
cx
,
i
.ident
);
// only need to handle methods
// only need to handle methods
do
vec
::
iter
(
ms
)
|
m
|
{
map_method
(
d_id
,
p
,
m
,
cx
);
}
do
vec
::
iter
(
ms
)
|
m
|
{
map_method
(
d_id
,
p
,
m
,
cx
);
}
}
}
item_trait
(
tps
,
methods
)
{
for
methods
.each
|
tm
|
{
let
id
=
ast_util
::
trait_method_to_ty_method
(
tm
)
.id
;
let
d_id
=
ast_util
::
local_def
(
i
.id
);
cx
.map
.insert
(
id
,
node_trait_method
(
@
tm
,
d_id
,
item_path
));
}
}
_
{
}
_
{
}
}
}
alt
i
.node
{
alt
i
.node
{
...
@@ -283,6 +290,11 @@ fn node_id_to_str(map: map, id: node_id) -> ~str {
...
@@ -283,6 +290,11 @@ fn node_id_to_str(map: map, id: node_id) -> ~str {
fmt!
{
"method %s in %s (id=%?)"
,
fmt!
{
"method %s in %s (id=%?)"
,
*
m
.ident
,
path_to_str
(
*
path
),
id
}
*
m
.ident
,
path_to_str
(
*
path
),
id
}
}
}
some
(
node_trait_method
(
tm
,
impl_did
,
path
))
{
let
m
=
ast_util
::
trait_method_to_ty_method
(
*
tm
);
fmt!
{
"method %s in %s (id=%?)"
,
*
m
.ident
,
path_to_str
(
*
path
),
id
}
}
some
(
node_variant
(
variant
,
def_id
,
path
))
{
some
(
node_variant
(
variant
,
def_id
,
path
))
{
fmt!
{
"variant %s in %s (id=%?)"
,
fmt!
{
"variant %s in %s (id=%?)"
,
*
variant
.node.name
,
path_to_str
(
*
path
),
id
}
*
variant
.node.name
,
path_to_str
(
*
path
),
id
}
...
...
src/libsyntax/ast_util.rs
浏览文件 @
2fe299d1
...
@@ -316,6 +316,19 @@ fn split_class_items(cs: ~[@class_member]) -> (~[ivar], ~[@method]) {
...
@@ -316,6 +316,19 @@ fn split_class_items(cs: ~[@class_member]) -> (~[ivar], ~[@method]) {
(
vs
,
ms
)
(
vs
,
ms
)
}
}
// extract a ty_method from a trait_method. if the trait_method is
// a default, pull out the useful fields to make a ty_method
fn
trait_method_to_ty_method
(
method
:
trait_method
)
->
ty_method
{
alt
method
{
required
(
m
)
{
m
}
provided
(
m
)
{
{
ident
:
m
.ident
,
attrs
:
m
.attrs
,
decl
:
m
.decl
,
tps
:
m
.tps
,
self_ty
:
m
.self_ty
,
id
:
m
.id
,
span
:
m
.span
}
}
}
}
pure
fn
class_member_visibility
(
ci
:
@
class_member
)
->
visibility
{
pure
fn
class_member_visibility
(
ci
:
@
class_member
)
->
visibility
{
alt
ci
.node
{
alt
ci
.node
{
instance_var
(
_
,
_
,
_
,
_
,
vis
)
{
vis
}
instance_var
(
_
,
_
,
_
,
_
,
vis
)
{
vis
}
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
2fe299d1
...
@@ -291,7 +291,7 @@ fn parse_trait_methods() -> ~[trait_method] {
...
@@ -291,7 +291,7 @@ fn parse_trait_methods() -> ~[trait_method] {
required
({
ident
:
ident
,
attrs
:
attrs
,
required
({
ident
:
ident
,
attrs
:
attrs
,
decl
:
{
purity
:
pur
with
d
},
tps
:
tps
,
decl
:
{
purity
:
pur
with
d
},
tps
:
tps
,
self_ty
:
self_ty
,
self_ty
:
self_ty
,
span
:
mk_sp
(
lo
,
hi
)})
id
:
p
.get_id
(),
span
:
mk_sp
(
lo
,
hi
)})
}
}
token
::
LBRACE
{
token
::
LBRACE
{
debug!
{
"parse_trait_methods(): parsing provided method"
};
debug!
{
"parse_trait_methods(): parsing provided method"
};
...
...
src/rustc/middle/trans/base.rs
浏览文件 @
2fe299d1
...
@@ -2111,6 +2111,9 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id,
...
@@ -2111,6 +2111,9 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id,
}
}
ast_map
::
node_ctor
(
nm
,
_
,
ct
,
_
,
pt
)
{
(
pt
,
nm
,
ct
.span
)
}
ast_map
::
node_ctor
(
nm
,
_
,
ct
,
_
,
pt
)
{
(
pt
,
nm
,
ct
.span
)
}
ast_map
::
node_dtor
(
_
,
dtor
,
_
,
pt
)
{(
pt
,
@~
"drop"
,
dtor
.span
)}
ast_map
::
node_dtor
(
_
,
dtor
,
_
,
pt
)
{(
pt
,
@~
"drop"
,
dtor
.span
)}
ast_map
::
node_trait_method
(
*
)
{
ccx
.tcx.sess
.bug
(
~
"Can't monomorphize a trait method"
)
}
ast_map
::
node_expr
(
*
)
{
ast_map
::
node_expr
(
*
)
{
ccx
.tcx.sess
.bug
(
~
"Can't monomorphize an expr"
)
ccx
.tcx.sess
.bug
(
~
"Can't monomorphize an expr"
)
}
}
...
@@ -2207,6 +2210,9 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id,
...
@@ -2207,6 +2210,9 @@ fn monomorphic_fn(ccx: @crate_ctxt, fn_id: ast::def_id,
ast_map
::
node_expr
(
*
)
{
ast_map
::
node_expr
(
*
)
{
ccx
.tcx.sess
.bug
(
~
"Can't monomorphize an expr"
)
ccx
.tcx.sess
.bug
(
~
"Can't monomorphize an expr"
)
}
}
ast_map
::
node_trait_method
(
*
)
{
ccx
.tcx.sess
.bug
(
~
"Can't monomorphize a trait method"
)
}
ast_map
::
node_export
(
*
)
{
ast_map
::
node_export
(
*
)
{
ccx
.tcx.sess
.bug
(
~
"Can't monomorphize an export"
)
ccx
.tcx.sess
.bug
(
~
"Can't monomorphize an export"
)
}
}
...
@@ -2418,7 +2424,7 @@ fn take_local(table: hashmap<ast::node_id, local_val>,
...
@@ -2418,7 +2424,7 @@ fn take_local(table: hashmap<ast::node_id, local_val>,
return
{
val
:
slf
,
kind
:
lv_owned
};
return
{
val
:
slf
,
kind
:
lv_owned
};
}
}
_
{
_
{
cx
.sess
()
.unimpl
(
fmt!
{
"unsupported def type in trans_local_
def
: %?"
,
cx
.sess
()
.unimpl
(
fmt!
{
"unsupported def type in trans_local_
var
: %?"
,
def
});
def
});
}
}
}
}
...
...
src/rustc/middle/trans/impl.rs
浏览文件 @
2fe299d1
...
@@ -185,6 +185,8 @@ fn resolve_vtables_in_fn_ctxt(fcx: fn_ctxt, vts: typeck::vtable_res)
...
@@ -185,6 +185,8 @@ fn resolve_vtables_in_fn_ctxt(fcx: fn_ctxt, vts: typeck::vtable_res)
@
vec
::
map
(
*
vts
,
|
d
|
resolve_vtable_in_fn_ctxt
(
fcx
,
d
))
@
vec
::
map
(
*
vts
,
|
d
|
resolve_vtable_in_fn_ctxt
(
fcx
,
d
))
}
}
// Apply the typaram substitutions in the fn_ctxt to a vtable. This should
// eliminate any vtable_params.
fn
resolve_vtable_in_fn_ctxt
(
fcx
:
fn_ctxt
,
vt
:
typeck
::
vtable_origin
)
fn
resolve_vtable_in_fn_ctxt
(
fcx
:
fn_ctxt
,
vt
:
typeck
::
vtable_origin
)
->
typeck
::
vtable_origin
{
->
typeck
::
vtable_origin
{
alt
vt
{
alt
vt
{
...
...
src/rustc/middle/ty.rs
浏览文件 @
2fe299d1
...
@@ -2759,6 +2759,10 @@ fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path {
...
@@ -2759,6 +2759,10 @@ fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path {
ast_map
::
node_method
(
method
,
_
,
path
)
{
ast_map
::
node_method
(
method
,
_
,
path
)
{
vec
::
append_one
(
*
path
,
ast_map
::
path_name
(
method
.ident
))
vec
::
append_one
(
*
path
,
ast_map
::
path_name
(
method
.ident
))
}
}
ast_map
::
node_trait_method
(
trait_method
,
_
,
path
)
{
let
method
=
ast_util
::
trait_method_to_ty_method
(
*
trait_method
);
vec
::
append_one
(
*
path
,
ast_map
::
path_name
(
method
.ident
))
}
ast_map
::
node_variant
(
variant
,
_
,
path
)
{
ast_map
::
node_variant
(
variant
,
_
,
path
)
{
vec
::
append_one
(
vec
::
init
(
*
path
),
vec
::
append_one
(
vec
::
init
(
*
path
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录