Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3b683f52
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,发现更多精彩内容 >>
提交
3b683f52
编写于
11月 14, 2011
作者:
H
Haitao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc: Use link_name attribute for native function
Fixes issue #906
上级
73cd032d
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
35 addition
and
29 deletion
+35
-29
src/comp/front/attr.rs
src/comp/front/attr.rs
+10
-0
src/comp/metadata/encoder.rs
src/comp/metadata/encoder.rs
+1
-1
src/comp/middle/resolve.rs
src/comp/middle/resolve.rs
+2
-2
src/comp/middle/trans.rs
src/comp/middle/trans.rs
+8
-8
src/comp/middle/typeck.rs
src/comp/middle/typeck.rs
+2
-2
src/comp/syntax/ast.rs
src/comp/syntax/ast.rs
+1
-1
src/comp/syntax/fold.rs
src/comp/syntax/fold.rs
+2
-3
src/comp/syntax/parse/parser.rs
src/comp/syntax/parse/parser.rs
+1
-3
src/comp/syntax/print/pprust.rs
src/comp/syntax/print/pprust.rs
+1
-5
src/comp/syntax/visit.rs
src/comp/syntax/visit.rs
+1
-1
src/lib/win32_os.rs
src/lib/win32_os.rs
+4
-2
src/test/run-pass/native-fn-linkname.rs
src/test/run-pass/native-fn-linkname.rs
+2
-1
未找到文件。
src/comp/front/attr.rs
浏览文件 @
3b683f52
...
...
@@ -17,6 +17,7 @@
export
get_attr_name
;
export
get_meta_item_name
;
export
get_meta_item_value_str
;
export
get_meta_item_value_str_by_name
;
export
get_meta_item_list
;
export
mk_name_value_item_str
;
export
mk_name_value_item
;
...
...
@@ -85,6 +86,15 @@ fn get_meta_item_value_str(meta: @ast::meta_item) -> option::t<str> {
}
}
fn
get_meta_item_value_str_by_name
(
attrs
:
[
ast
::
attribute
],
name
:
ast
::
ident
)
->
option
::
t
<
str
>
{
let
mattrs
=
find_attrs_by_name
(
attrs
,
name
);
if
vec
::
len
(
mattrs
)
>
0u
{
ret
get_meta_item_value_str
(
attr_meta
(
mattrs
[
0
]));
}
ret
option
::
none
;
}
fn
get_meta_item_list
(
meta
:
@
ast
::
meta_item
)
->
option
::
t
<
[
@
ast
::
meta_item
]
>
{
alt
meta
.node
{
ast
::
meta_list
(
_
,
l
)
{
option
::
some
(
l
)
}
...
...
src/comp/metadata/encoder.rs
浏览文件 @
3b683f52
...
...
@@ -348,7 +348,7 @@ fn encode_info_for_native_item(ecx: @encode_ctxt, ebml_w: ebml::writer,
encode_type
(
ecx
,
ebml_w
,
ty
::
mk_native
(
ecx
.ccx.tcx
,
local_def
(
nitem
.id
)));
}
native_item_fn
(
_
,
fn_decl
,
tps
)
{
native_item_fn
(
fn_decl
,
tps
)
{
let
letter
=
alt
fn_decl
.purity
{
unsafe_fn
.
{
'U'
}
...
...
src/comp/middle/resolve.rs
浏览文件 @
3b683f52
...
...
@@ -656,7 +656,7 @@ fn in_scope(e: env, sp: span, name: ident, s: scope, ns: namespace) ->
}
scope_native_item
(
it
)
{
alt
it
.node
{
ast
::
native_item_fn
(
_
,
decl
,
ty_params
)
{
ast
::
native_item_fn
(
decl
,
ty_params
)
{
ret
lookup_in_fn
(
name
,
decl
,
ty_params
,
ns
);
}
}
...
...
@@ -1077,7 +1077,7 @@ fn lookup_in_mie(e: env, mie: mod_index_entry, ns: namespace) ->
ret
some
(
ast
::
def_native_ty
(
local_def
(
native_item
.id
)));
}
}
ast
::
native_item_fn
(
_
,
decl
,
_
)
{
ast
::
native_item_fn
(
decl
,
_
)
{
if
ns
==
ns_value
{
ret
some
(
ast
::
def_native_fn
(
local_def
(
native_item
.id
),
...
...
src/comp/middle/trans.rs
浏览文件 @
3b683f52
...
...
@@ -17,6 +17,7 @@
import
std
::
map
::{
new_int_hash
,
new_str_hash
};
import
std
::
option
::{
some
,
none
};
import
driver
::
session
;
import
front
::
attr
;
import
middle
::{
ty
,
gc
};
import
middle
::
freevars
::
*
;
import
back
::{
link
,
abi
,
upcall
};
...
...
@@ -5585,7 +5586,7 @@ fn native_fn_ty_param_count(cx: @crate_ctxt, id: ast::node_id) -> uint {
cx
.sess
.bug
(
"register_native_fn(): native fn isn't
\
actually a fn"
);
}
ast
::
native_item_fn
(
_
,
_
,
tps
)
{
ast
::
native_item_fn
(
_
,
tps
)
{
count
=
std
::
vec
::
len
::
<
ast
::
ty_param
>
(
tps
);
}
}
...
...
@@ -5805,14 +5806,13 @@ fn trans_simple_native_abi(bcx: @block_ctxt, name: str,
fn
collect_native_item
(
ccx
:
@
crate_ctxt
,
i
:
@
ast
::
native_item
,
&&
pt
:
[
str
],
_
v
:
vt
<
[
str
]
>
)
{
alt
i
.node
{
ast
::
native_item_fn
(
link_name
,
_
,
_
)
{
ast
::
native_item_fn
(
_
,
_
)
{
if
!
ccx
.obj_methods
.contains_key
(
i
.id
)
{
let
name
=
if
option
::
is_some
(
link_name
)
{
option
::
get
(
link_name
)
}
else
{
i
.ident
};
let
name
=
i
.ident
;
alt
attr
::
get_meta_item_value_str_by_name
(
i
.attrs
,
"link_name"
)
{
none
.
{
}
option
::
some
(
ln
)
{
name
=
ln
;
}
}
register_native_fn
(
ccx
,
i
.span
,
pt
,
name
,
i
.id
);
}
}
...
...
src/comp/middle/typeck.rs
浏览文件 @
3b683f52
...
...
@@ -668,7 +668,7 @@ fn ty_of_native_item(cx: @ctxt, it: @ast::native_item,
abi
:
ast
::
native_abi
)
->
ty
::
ty_param_kinds_and_ty
{
let
no_kinds
:
[
ast
::
kind
]
=
[];
alt
it
.node
{
ast
::
native_item_fn
(
_
,
fn_decl
,
params
)
{
ast
::
native_item_fn
(
fn_decl
,
params
)
{
let
get
=
bind
getter
(
cx
,
_
);
let
convert
=
bind
ast_ty_to_ty
(
cx
.tcx
,
get
,
_
);
let
f
=
bind
ty_of_arg
(
cx
,
_
);
...
...
@@ -819,7 +819,7 @@ fn convert_native(cx: @ctxt, abi: @mutable option::t<ast::native_abi>,
ast
::
native_item_ty
.
{
// FIXME: Native types have no annotation. Should they? --pcw
}
ast
::
native_item_fn
(
_
,
_
,
_
)
{
ast
::
native_item_fn
(
_
,
_
)
{
write
::
ty_only
(
cx
.tcx
,
i
.id
,
tpt
.ty
);
}
}
...
...
src/comp/syntax/ast.rs
浏览文件 @
3b683f52
...
...
@@ -501,7 +501,7 @@
tag
native_item_
{
native_item_ty
;
native_item_fn
(
option
::
t
<
str
>
,
fn_decl
,
[
ty_param
]);
native_item_fn
(
fn_decl
,
[
ty_param
]);
}
//
...
...
src/comp/syntax/fold.rs
浏览文件 @
3b683f52
...
...
@@ -187,9 +187,8 @@ fn noop_fold_native_item(&&ni: @native_item, fld: ast_fold) -> @native_item {
node
:
alt
ni
.node
{
native_item_ty
.
{
native_item_ty
}
native_item_fn
(
st
,
fdec
,
typms
)
{
native_item_fn
(
st
,
{
inputs
:
vec
::
map
(
fold_arg
,
fdec
.inputs
),
native_item_fn
(
fdec
,
typms
)
{
native_item_fn
({
inputs
:
vec
::
map
(
fold_arg
,
fdec
.inputs
),
output
:
fld
.fold_ty
(
fdec
.output
),
purity
:
fdec
.purity
,
il
:
fdec
.il
,
...
...
src/comp/syntax/parse/parser.rs
浏览文件 @
3b683f52
...
...
@@ -1956,13 +1956,11 @@ fn parse_item_native_fn(p: parser, attrs: [ast::attribute],
let
lo
=
p
.get_last_lo_pos
();
let
t
=
parse_fn_header
(
p
);
let
decl
=
parse_fn_decl
(
p
,
purity
,
ast
::
il_normal
);
let
link_name
=
none
;
if
p
.peek
()
==
token
::
EQ
{
p
.bump
();
link_name
=
some
(
parse_str
(
p
));
}
let
hi
=
p
.get_hi_pos
();
expect
(
p
,
token
::
SEMI
);
ret
@
{
ident
:
t
.ident
,
attrs
:
attrs
,
node
:
ast
::
native_item_fn
(
link_name
,
decl
,
t
.tps
),
node
:
ast
::
native_item_fn
(
decl
,
t
.tps
),
id
:
p
.get_id
(),
span
:
ast_util
::
mk_sp
(
lo
,
hi
)};
}
...
...
src/comp/syntax/print/pprust.rs
浏览文件 @
3b683f52
...
...
@@ -350,13 +350,9 @@ fn print_native_item(s: ps, item: @ast::native_item) {
ast
::
native_item_fn
(
lname
,
decl
,
typarams
)
{
ast
::
native_item_fn
(
decl
,
typarams
)
{
print_fn
(
s
,
decl
,
ast
::
proto_bare
,
item
.ident
,
typarams
,
decl
.constraints
);
alt
lname
{
none
.
{
}
some
(
ss
)
{
space
(
s
.s
);
word_space
(
s
,
"="
);
print_string
(
s
,
ss
);
}
}
end
(
s
);
// end head-ibox
word
(
s
.s
,
";"
);
end
(
s
);
// end the outer fn box
...
...
src/comp/syntax/visit.rs
浏览文件 @
3b683f52
...
...
@@ -179,7 +179,7 @@ fn visit_pat<E>(p: @pat, e: E, v: vt<E>) {
fn
visit_native_item
<
E
>
(
ni
:
@
native_item
,
e
:
E
,
v
:
vt
<
E
>
)
{
alt
ni
.node
{
native_item_fn
(
_
,
fd
,
_
)
{
visit_fn_decl
(
fd
,
e
,
v
);
}
native_item_fn
(
fd
,
_
)
{
visit_fn_decl
(
fd
,
e
,
v
);
}
native_item_ty
.
{
}
}
}
...
...
src/lib/win32_os.rs
浏览文件 @
3b683f52
...
...
@@ -4,8 +4,10 @@
fn
write
(
fd
:
int
,
buf
:
*
u8
,
count
:
uint
)
->
int
;
fn
fread
(
buf
:
*
u8
,
size
:
uint
,
n
:
uint
,
f
:
libc
::
FILE
)
->
uint
;
fn
fwrite
(
buf
:
*
u8
,
size
:
uint
,
n
:
uint
,
f
:
libc
::
FILE
)
->
uint
;
fn
open
(
s
:
str
::
sbuf
,
flags
:
int
,
mode
:
uint
)
->
int
=
"_open"
;
fn
close
(
fd
:
int
)
->
int
=
"_close"
;
#[link_name
=
"_open"
]
fn
open
(
s
:
str
::
sbuf
,
flags
:
int
,
mode
:
uint
)
->
int
;
#[link_name
=
"_close"
]
fn
close
(
fd
:
int
)
->
int
;
type
FILE
;
fn
fopen
(
path
:
str
::
sbuf
,
mode
:
str
::
sbuf
)
->
FILE
;
fn
_
fdopen
(
fd
:
int
,
mode
:
str
::
sbuf
)
->
FILE
;
...
...
src/test/run-pass/native-fn-linkname.rs
浏览文件 @
3b683f52
...
...
@@ -4,7 +4,8 @@
import
std
::
str
;
native
"cdecl"
mod
libc
=
""
{
fn
my_strlen
(
str
:
*
u8
)
->
uint
=
"strlen"
;
#[link_name
=
"strlen"
]
fn
my_strlen
(
str
:
*
u8
)
->
uint
;
}
fn
strlen
(
str
:
str
)
->
uint
unsafe
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录