Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
8499c77c
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,发现更多精彩内容 >>
提交
8499c77c
编写于
7月 05, 2011
作者:
B
Brian Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Parse attributes for native items. Closes #609
上级
10a4737d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
48 addition
and
10 deletion
+48
-10
src/comp/syntax/ast.rs
src/comp/syntax/ast.rs
+1
-0
src/comp/syntax/fold.rs
src/comp/syntax/fold.rs
+3
-0
src/comp/syntax/parse/parser.rs
src/comp/syntax/parse/parser.rs
+30
-10
src/comp/syntax/print/pprust.rs
src/comp/syntax/print/pprust.rs
+2
-0
src/test/run-pass/item-attributes.rs
src/test/run-pass/item-attributes.rs
+12
-0
未找到文件。
src/comp/syntax/ast.rs
浏览文件 @
8499c77c
...
...
@@ -542,6 +542,7 @@ fn ty_mach_to_str(ty_mach tm) -> str {
}
type
native_item
=
rec
(
ident
ident
,
vec
[
attribute
]
attrs
,
native_item_
node
,
node_id
id
,
span
span
);
...
...
src/comp/syntax/fold.rs
浏览文件 @
8499c77c
...
...
@@ -161,8 +161,11 @@ fn noop_fold_view_item(&view_item_ vi, ast_fold fld) -> view_item_ {
fn
noop_fold_native_item
(
&@
native_item
ni
,
ast_fold
fld
)
->
@
native_item
{
auto
fold_arg
=
bind
fold_arg_
(
_
,
fld
);
auto
fold_meta_item
=
bind
fold_meta_item_
(
_
,
fld
);
auto
fold_attribute
=
bind
fold_attribute_
(
_
,
fold_meta_item
);
ret
@
rec
(
ident
=
fld
.fold_ident
(
ni
.ident
),
attrs
=
map
(
fold_attribute
,
ni
.attrs
),
node
=
alt
(
ni
.node
)
{
case
(
native_item_ty
)
{
native_item_ty
}
case
(
native_item_fn
(
?
st
,
?
fdec
,
?
typms
))
{
...
...
src/comp/syntax/parse/parser.rs
浏览文件 @
8499c77c
...
...
@@ -1870,17 +1870,20 @@ fn parse_item_mod(&parser p, vec[ast::attribute] attrs) -> @ast::item {
ret
mk_item
(
p
,
lo
,
hi
,
id
,
ast
::
item_mod
(
m
),
attrs
+
inner_attrs
._0
);
}
fn
parse_item_native_type
(
&
parser
p
)
->
@
ast
::
native_item
{
fn
parse_item_native_type
(
&
parser
p
,
&
vec
[
ast
::
attribute
]
attrs
)
->
@
ast
::
native_item
{
auto
t
=
parse_type_decl
(
p
);
auto
hi
=
p
.get_hi_pos
();
expect
(
p
,
token
::
SEMI
);
ret
@
rec
(
ident
=
t
._1
,
attrs
=
attrs
,
node
=
ast
::
native_item_ty
,
id
=
p
.get_id
(),
span
=
rec
(
lo
=
t
._0
,
hi
=
hi
));
}
fn
parse_item_native_fn
(
&
parser
p
)
->
@
ast
::
native_item
{
fn
parse_item_native_fn
(
&
parser
p
,
&
vec
[
ast
::
attribute
]
attrs
)
->
@
ast
::
native_item
{
auto
lo
=
p
.get_last_lo_pos
();
auto
t
=
parse_fn_header
(
p
);
auto
decl
=
parse_fn_decl
(
p
,
ast
::
impure_fn
);
...
...
@@ -1892,25 +1895,38 @@ fn parse_item_native_fn(&parser p) -> @ast::native_item {
auto
hi
=
p
.get_hi_pos
();
expect
(
p
,
token
::
SEMI
);
ret
@
rec
(
ident
=
t
._0
,
attrs
=
attrs
,
node
=
ast
::
native_item_fn
(
link_name
,
decl
,
t
._1
),
id
=
p
.get_id
(),
span
=
rec
(
lo
=
lo
,
hi
=
hi
));
}
fn
parse_native_item
(
&
parser
p
)
->
@
ast
::
native_item
{
fn
parse_native_item
(
&
parser
p
,
&
vec
[
ast
::
attribute
]
attrs
)
->
@
ast
::
native_item
{
parse_layer
(
p
);
if
(
eat_word
(
p
,
"type"
))
{
ret
parse_item_native_type
(
p
);
ret
parse_item_native_type
(
p
,
attrs
);
}
else
if
(
eat_word
(
p
,
"fn"
))
{
ret
parse_item_native_fn
(
p
);
ret
parse_item_native_fn
(
p
,
attrs
);
}
else
{
unexpected
(
p
,
p
.peek
());
fail
;
}
}
fn
parse_native_mod_items
(
&
parser
p
,
&
str
native_name
,
ast
::
native_abi
abi
)
->
fn
parse_native_mod_items
(
&
parser
p
,
&
str
native_name
,
ast
::
native_abi
abi
,
&
vec
[
ast
::
attribute
]
first_item_attrs
)
->
ast
::
native_mod
{
auto
view_items
=
if
(
vec
::
len
(
first_item_attrs
)
==
0u
)
{
parse_native_view
(
p
)
}
else
{
// Shouldn't be any view items since we've already parsed an item attr
[]
};
let
vec
[
@
ast
::
native_item
]
items
=
[];
auto
view_items
=
parse_native_view
(
p
);
while
(
p
.peek
()
!=
token
::
RBRACE
)
{
items
+=
[
parse_native_item
(
p
)];
}
auto
initial_attrs
=
first_item_attrs
;
while
(
p
.peek
()
!=
token
::
RBRACE
)
{
auto
attrs
=
initial_attrs
+
parse_outer_attributes
(
p
);
initial_attrs
=
[];
items
+=
[
parse_native_item
(
p
,
attrs
)];
}
ret
rec
(
native_name
=
native_name
,
abi
=
abi
,
view_items
=
view_items
,
...
...
@@ -1941,10 +1957,14 @@ fn parse_item_native_mod(&parser p, vec[ast::attribute] attrs) -> @ast::item {
native_name
=
id
;
}
expect
(
p
,
token
::
LBRACE
);
auto
m
=
parse_native_mod_items
(
p
,
native_name
,
abi
);
auto
more_attrs
=
parse_inner_attrs_and_next
(
p
);
auto
inner_attrs
=
more_attrs
._0
;
auto
first_item_outer_attrs
=
more_attrs
._1
;
auto
m
=
parse_native_mod_items
(
p
,
native_name
,
abi
,
first_item_outer_attrs
);
auto
hi
=
p
.get_hi_pos
();
expect
(
p
,
token
::
RBRACE
);
ret
mk_item
(
p
,
lo
,
hi
,
id
,
ast
::
item_native_mod
(
m
),
attrs
);
ret
mk_item
(
p
,
lo
,
hi
,
id
,
ast
::
item_native_mod
(
m
),
attrs
+
inner_attrs
);
}
fn
parse_type_decl
(
&
parser
p
)
->
tup
(
uint
,
ast
::
ident
)
{
...
...
src/comp/syntax/print/pprust.rs
浏览文件 @
8499c77c
...
...
@@ -383,8 +383,10 @@ fn print_item(&ps s, &@ast::item item) {
word_nbsp
(
s
,
"mod"
);
word_nbsp
(
s
,
item
.ident
);
bopen
(
s
);
print_inner_attributes
(
s
,
item
.attrs
);
for
(
@
ast
::
native_item
item
in
nmod
.items
)
{
hardbreak_if_not_bol
(
s
);
print_outer_attributes
(
s
,
item
.attrs
);
ibox
(
s
,
indent_unit
);
maybe_print_comment
(
s
,
item
.span.lo
);
alt
(
item
.node
)
{
...
...
src/test/run-pass/item-attributes.rs
浏览文件 @
8499c77c
...
...
@@ -192,6 +192,18 @@ fn f() {
}
}
mod
test_native_items
{
native
"rust"
mod
rustrt
{
#[attr]
;
#[attr]
type
vbuf
;
#[attr]
fn
vec_len
[
T
](
vec
[
T
]
v
)
->
uint
;
}
}
fn
main
()
{
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录