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;
}
}
+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) }
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' }
}
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);
}
}
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),
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};
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);
}
}
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);
}
}
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, _);
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);
}
}
tag native_item_ {
native_item_ty;
- native_item_fn(option::t<str>, fn_decl, [ty_param]);
+ native_item_fn(fn_decl, [ty_param]);
}
//
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,
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)};
}
- 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
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. { }
}
}
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;
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 {