Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
dd3ed613
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,发现更多精彩内容 >>
提交
dd3ed613
编写于
2月 02, 2011
作者:
R
Rafael Ávila de Espíndola
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add most of the plumbing for native items and add support for parsing native type declarations.
上级
f22dc4d5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
96 addition
and
4 deletion
+96
-4
src/comp/front/ast.rs
src/comp/front/ast.rs
+17
-2
src/comp/front/parser.rs
src/comp/front/parser.rs
+34
-1
src/comp/middle/fold.rs
src/comp/middle/fold.rs
+44
-1
src/test/run-pass/native2.rs
src/test/run-pass/native2.rs
+1
-0
未找到文件。
src/comp/front/ast.rs
浏览文件 @
dd3ed613
...
...
@@ -215,7 +215,6 @@
type
_
obj
=
rec
(
vec
[
obj_field
]
fields
,
vec
[
@
method
]
methods
);
tag
mod_index_entry
{
mie_view_item
(
@
view_item
);
mie_item
(
@
item
);
...
...
@@ -227,7 +226,10 @@
vec
[
@
item
]
items
,
mod_index
index
);
type
native_mod
=
rec
(
str
native_name
);
type
native_mod
=
rec
(
str
native_name
,
vec
[
@
native_item
]
items
,
native_mod_index
index
);
type
native_mod_index
=
hashmap
[
ident
,
@
native_item
];
type
variant_arg
=
rec
(
@
ty
ty
,
def_id
id
);
type
variant
=
rec
(
str
name
,
vec
[
variant_arg
]
args
,
def_id
id
,
ann
ann
);
...
...
@@ -249,6 +251,11 @@
item_obj
(
ident
,
_
obj
,
vec
[
ty_param
],
def_id
,
ann
);
}
type
native_item
=
spanned
[
native_item_
];
tag
native_item_
{
native_item_ty
(
ident
,
def_id
);
}
fn
index_view_item
(
mod_index
index
,
@
view_item
it
)
{
alt
(
it
.node
)
{
case
(
ast
.view_item_use
(
?
id
,
_
,
_
))
{
...
...
@@ -292,6 +299,14 @@ fn index_item(mod_index index, @item it) {
}
}
fn
index_native_item
(
native_mod_index
index
,
@
native_item
it
)
{
alt
(
it
.node
)
{
case
(
ast
.native_item_ty
(
?
id
,
_
))
{
index
.insert
(
id
,
it
);
}
}
}
//
// Local Variables:
// mode: rust
...
...
src/comp/front/parser.rs
浏览文件 @
dd3ed613
...
...
@@ -1577,6 +1577,39 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
ret
@
spanned
(
lo
,
hi
,
item
);
}
impure
fn
parse_item_native_type
(
parser
p
)
->
@
ast
.native_item
{
auto
lo
=
p
.get_span
();
expect
(
p
,
token
.TYPE
);
auto
id
=
parse_ident
(
p
);
auto
hi
=
p
.get_span
();
expect
(
p
,
token
.SEMI
);
auto
item
=
ast
.native_item_ty
(
id
,
p
.next_def_id
());
ret
@
spanned
(
lo
,
hi
,
item
);
}
impure
fn
parse_native_item
(
parser
p
)
->
@
ast
.native_item
{
alt
(
p
.peek
())
{
case
(
token
.TYPE
)
{
ret
parse_item_native_type
(
p
);
}
}
}
impure
fn
parse_native_mod_items
(
parser
p
,
str
native_name
)
->
ast
.native_mod
{
auto
index
=
new_str_hash
[
@
ast
.native_item
]();
let
vec
[
@
ast
.native_item
]
items
=
vec
();
while
(
p
.peek
()
!=
token
.RBRACE
)
{
auto
item
=
parse_native_item
(
p
);
items
+=
vec
(
item
);
// Index the item.
ast
.index_native_item
(
index
,
item
);
}
ret
rec
(
native_name
=
native_name
,
items
=
items
,
index
=
index
);
}
impure
fn
parse_item_native_mod
(
parser
p
)
->
@
ast
.item
{
auto
lo
=
p
.get_span
();
expect
(
p
,
token
.NATIVE
);
...
...
@@ -1584,7 +1617,7 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
expect
(
p
,
token
.MOD
);
auto
id
=
parse_ident
(
p
);
expect
(
p
,
token
.LBRACE
);
auto
m
=
rec
(
native_name
=
native_name
);
auto
m
=
parse_native_mod_items
(
p
,
native_name
);
auto
hi
=
p
.get_span
();
expect
(
p
,
token
.RBRACE
);
auto
item
=
ast
.item_native_mod
(
id
,
m
,
p
.next_def_id
());
...
...
src/comp/middle/fold.rs
浏览文件 @
dd3ed613
...
...
@@ -20,6 +20,7 @@
import
front
.ast.item
;
import
front
.ast.view_item
;
import
front
.ast.meta_item
;
import
front
.ast.native_item
;
import
front
.ast.arg
;
import
front
.ast.pat
;
import
front
.ast.decl
;
...
...
@@ -203,6 +204,9 @@
@
ty
t
,
vec
[
ast
.ty_param
]
ty_params
,
def_id
id
,
ann
a
)
->
@
item
)
fold_item_ty
,
(
fn
(
&
ENV
e
,
&
span
sp
,
ident
ident
,
def_id
id
)
->
@
native_item
)
fold_native_item_ty
,
(
fn
(
&
ENV
e
,
&
span
sp
,
ident
ident
,
vec
[
ast
.variant
]
variants
,
vec
[
ast
.ty_param
]
ty_params
,
...
...
@@ -244,6 +248,7 @@
// Env updates.
(
fn
(
&
ENV
e
,
@
ast
.crate
c
)
->
ENV
)
update_env_for_crate
,
(
fn
(
&
ENV
e
,
@
item
i
)
->
ENV
)
update_env_for_item
,
(
fn
(
&
ENV
e
,
@
native_item
i
)
->
ENV
)
update_env_for_native_item
,
(
fn
(
&
ENV
e
,
@
view_item
i
)
->
ENV
)
update_env_for_view_item
,
(
fn
(
&
ENV
e
,
&
block
b
)
->
ENV
)
update_env_for_block
,
(
fn
(
&
ENV
e
,
@
stmt
s
)
->
ENV
)
update_env_for_stmt
,
...
...
@@ -841,9 +846,34 @@ fn fold_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast._mod m) -> ast._mod {
ret
fld
.fold_mod
(
e
,
rec
(
view_items
=
view_items
,
items
=
items
,
index
=
index
));
}
fn
fold_native_item
[
ENV
](
&
ENV
env
,
ast_fold
[
ENV
]
fld
,
@
native_item
i
)
->
@
native_item
{
let
ENV
env_
=
fld
.update_env_for_native_item
(
env
,
i
);
if
(
!
fld
.keep_going
(
env_
))
{
ret
i
;
}
alt
(
i
.node
)
{
case
(
ast
.native_item_ty
(
?
ident
,
?
id
))
{
ret
fld
.fold_native_item_ty
(
env_
,
i
.span
,
ident
,
id
);
}
}
}
fn
fold_native_mod
[
ENV
](
&
ENV
e
,
ast_fold
[
ENV
]
fld
,
&
ast
.native_mod
m
)
->
ast
.native_mod
{
ret
fld
.fold_native_mod
(
e
,
rec
(
native_name
=
m
.native_name
));
let
vec
[
@
native_item
]
items
=
vec
();
auto
index
=
new_str_hash
[
@
ast
.native_item
]();
for
(
@
native_item
i
in
m
.items
)
{
auto
new_item
=
fold_native_item
[
ENV
](
e
,
fld
,
i
);
append
[
@
native_item
](
items
,
new_item
);
ast
.index_native_item
(
index
,
new_item
);
}
ret
fld
.fold_native_mod
(
e
,
rec
(
native_name
=
m
.native_name
,
items
=
items
,
index
=
index
));
}
fn
fold_crate
[
ENV
](
&
ENV
env
,
ast_fold
[
ENV
]
fld
,
@
ast
.crate
c
)
->
@
ast
.crate
{
...
...
@@ -1130,6 +1160,11 @@ fn identity_fold_item_ty[ENV](&ENV e, &span sp, ident i,
ret
@
respan
(
sp
,
ast
.item_ty
(
i
,
t
,
ty_params
,
id
,
a
));
}
fn
identity_fold_native_item_ty
[
ENV
](
&
ENV
e
,
&
span
sp
,
ident
i
,
def_id
id
)
->
@
native_item
{
ret
@
respan
(
sp
,
ast
.native_item_ty
(
i
,
id
));
}
fn
identity_fold_item_tag
[
ENV
](
&
ENV
e
,
&
span
sp
,
ident
i
,
vec
[
ast
.variant
]
variants
,
vec
[
ast
.ty_param
]
ty_params
,
...
...
@@ -1204,6 +1239,10 @@ fn identity_update_env_for_item[ENV](&ENV e, @item i) -> ENV {
ret
e
;
}
fn
identity_update_env_for_native_item
[
ENV
](
&
ENV
e
,
@
native_item
i
)
->
ENV
{
ret
e
;
}
fn
identity_update_env_for_view_item
[
ENV
](
&
ENV
e
,
@
view_item
i
)
->
ENV
{
ret
e
;
}
...
...
@@ -1308,6 +1347,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
fold_item_native_mod
=
bind
identity_fold_item_native_mod
[
ENV
](
_
,
_
,
_
,
_
,
_
),
fold_item_ty
=
bind
identity_fold_item_ty
[
ENV
](
_
,
_
,
_
,
_
,
_
,
_
,
_
),
fold_native_item_ty
=
bind
identity_fold_native_item_ty
[
ENV
](
_
,
_
,
_
,
_
),
fold_item_tag
=
bind
identity_fold_item_tag
[
ENV
](
_
,
_
,
_
,
_
,
_
,
_
),
fold_item_obj
=
bind
identity_fold_item_obj
[
ENV
](
_
,
_
,
_
,
_
,
_
,
_
,
_
),
...
...
@@ -1325,6 +1366,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
update_env_for_crate
=
bind
identity_update_env_for_crate
[
ENV
](
_
,
_
),
update_env_for_item
=
bind
identity_update_env_for_item
[
ENV
](
_
,
_
),
update_env_for_native_item
=
bind
identity_update_env_for_native_item
[
ENV
](
_
,
_
),
update_env_for_view_item
=
bind
identity_update_env_for_view_item
[
ENV
](
_
,
_
),
update_env_for_block
=
bind
identity_update_env_for_block
[
ENV
](
_
,
_
),
...
...
src/test/run-pass/native2.rs
浏览文件 @
dd3ed613
native
"rust"
mod
rustrt
{
type
vbuf
;
}
fn
main
(
vec
[
str
]
args
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录