1
Fork 0

rustc: Remove abi from ast::native_mod

This commit is contained in:
Haitao Li 2011-11-21 02:15:40 +08:00 committed by Marijn Haverbeke
parent 7a7f0604f4
commit 5ca83553bc
16 changed files with 126 additions and 128 deletions

View file

@ -1,6 +1,6 @@
// Functions dealing with attributes and meta_items
import std::{vec, map, option};
import std::{either, vec, map, option};
import syntax::{ast, ast_util};
import driver::session;
@ -24,6 +24,7 @@ export mk_name_value_item;
export mk_list_item;
export mk_word_item;
export mk_attr;
export native_abi;
// From a list of crate attributes get only the meta_items that impact crate
// linkage
@ -199,6 +200,26 @@ fn require_unique_names(sess: session::session, metas: [@ast::meta_item]) {
}
}
fn native_abi(attrs: [ast::attribute]) -> either::t<str, ast::native_abi> {
ret alt attr::get_meta_item_value_str_by_name(attrs, "abi") {
option::none. {
either::right(ast::native_abi_cdecl)
}
option::some("rust-intrinsic") {
either::right(ast::native_abi_rust_intrinsic)
}
option::some("cdecl") {
either::right(ast::native_abi_cdecl)
}
option::some("stdcall") {
either::right(ast::native_abi_stdcall)
}
option::some(t) {
either::left("unsupported abi: " + t)
}
};
}
fn span<copy T>(item: T) -> ast::spanned<T> {
ret {node: item, span: ast_util::dummy_sp()};
}

View file

@ -45,8 +45,7 @@ fn fold_native_mod(cfg: ast::crate_cfg, nm: ast::native_mod,
fld: fold::ast_fold) -> ast::native_mod {
let filter = bind filter_native_item(cfg, _);
let filtered_items = vec::filter_map(filter, nm.items);
ret {abi: nm.abi,
view_items: vec::map(fld.fold_view_item, nm.view_items),
ret {view_items: vec::map(fld.fold_view_item, nm.view_items),
items: filtered_items};
}

View file

@ -7,7 +7,7 @@ import front::attr;
import syntax::visit;
import syntax::codemap::span;
import util::{filesearch};
import std::{vec, str, fs, io, option};
import std::{either, vec, str, fs, io, option};
import std::option::{none, some};
import std::map::{hashmap, new_int_hash};
import syntax::print::pprust;
@ -49,9 +49,12 @@ fn visit_view_item(e: env, i: @ast::view_item) {
fn visit_item(e: env, i: @ast::item) {
alt i.node {
ast::item_native_mod(m) {
if m.abi != ast::native_abi_cdecl &&
m.abi != ast::native_abi_stdcall {
ret;
alt attr::native_abi(i.attrs) {
either::right(abi) {
if abi != ast::native_abi_cdecl &&
abi != ast::native_abi_stdcall { ret; }
}
either::left(msg) { e.sess.span_fatal(i.span, msg); }
}
let cstore = e.sess.get_cstore();
let native_name = i.ident;

View file

@ -257,14 +257,8 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
func.cs);
}
'N' {
let abi;
alt next(st) as char {
'i' { abi = ast::native_abi_rust_intrinsic; }
'C' { abi = ast::native_abi_cdecl; }
'S' { abi = ast::native_abi_stdcall; }
}
let func = parse_ty_fn(st, sd);
ret ty::mk_native_fn(st.tcx, abi, func.args, func.ty);
ret ty::mk_native_fn(st.tcx, func.args, func.ty);
}
'O' {
assert (next(st) as char == '[');

View file

@ -138,13 +138,8 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
enc_proto(w, proto);
enc_ty_fn(w, cx, args, out, cf, constrs);
}
ty::ty_native_fn(abi, args, out) {
ty::ty_native_fn(args, out) {
w.write_char('N');
alt abi {
native_abi_rust_intrinsic. { w.write_char('i'); }
native_abi_cdecl. { w.write_char('C'); }
native_abi_stdcall. { w.write_char('S'); }
}
enc_ty_fn(w, cx, args, out, return_val, []);
}
ty::ty_obj(methods) {

View file

@ -651,7 +651,7 @@ fn copy_is_expensive(tcx: ty::ctxt, ty: ty::t) -> bool {
ty::ty_ptr(_) { 1u }
ty::ty_box(_) { 3u }
ty::ty_constr(t, _) | ty::ty_res(_, t, _) { score_ty(tcx, t) }
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) |
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _) |
ty::ty_obj(_) { 4u }
ty::ty_str. | ty::ty_vec(_) | ty::ty_param(_, _) { 50u }
ty::ty_uniq(mt) { 1u + score_ty(tcx, mt.ty) }

View file

@ -151,7 +151,7 @@ fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_fn(_, _, _, _, _) |
ty::ty_native_fn(_, _, _) | ty::ty_obj(_) | ty::ty_param(_, _) |
ty::ty_native_fn(_, _) | ty::ty_obj(_) | ty::ty_param(_, _) |
ty::ty_res(_, _, _) {
ret true;
}

View file

@ -419,7 +419,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
ty::ty_fn(_, _, _, _, _) {
s += [shape_fn];
}
ty::ty_native_fn(_, _, _) { s += [shape_u32]; }
ty::ty_native_fn(_, _) { s += [shape_u32]; }
ty::ty_obj(_) { s += [shape_obj]; }

View file

@ -12,7 +12,7 @@
// pcwalton). You can, instead, find out its TypeRef by calling val_ty,
// but many TypeRefs correspond to one ty::t; for instance, tup(int, int,
// int) and rec(x=int, y=int, z=int) will have the same TypeRef.
import std::{str, uint, map, option, time, vec};
import std::{either, str, uint, map, option, time, vec};
import std::map::hashmap;
import std::map::{new_int_hash, new_str_hash};
import std::option::{some, none};
@ -182,7 +182,7 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
check returns_non_ty_var(cx, t);
T_fn_pair(cx, type_of_fn_from_ty(cx, sp, t, 0u))
}
ty::ty_native_fn(abi, args, out) {
ty::ty_native_fn(args, out) {
let nft = native_fn_wrapper_type(cx, sp, 0u, t);
T_fn_pair(cx, nft)
}
@ -235,7 +235,7 @@ fn type_of_ty_param_kinds_and_ty(lcx: @local_ctxt, sp: span,
let cx = lcx.ccx;
let t = tpt.ty;
alt ty::struct(cx.tcx, t) {
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) {
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _) {
check returns_non_ty_var(cx, t);
ret type_of_fn_from_ty(cx, sp, t, std::vec::len(tpt.kinds));
}
@ -1727,7 +1727,7 @@ fn iter_structural_ty(cx: @block_ctxt, av: ValueRef, t: ty::t,
}
ret next_cx;
}
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _, _) {
ty::ty_fn(_, _, _, _, _) | ty::ty_native_fn(_, _) {
let box_cell_a = GEPi(cx, av, [0, abi::fn_field_box]);
ret iter_boxpp(cx, box_cell_a, f);
}
@ -5305,7 +5305,7 @@ fn c_stack_tys(ccx: @crate_ctxt,
sp: span,
id: ast::node_id) -> @c_stack_tys {
alt ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, id)) {
ty::ty_native_fn(_, arg_tys, ret_ty) {
ty::ty_native_fn(arg_tys, ret_ty) {
let tcx = ccx.tcx;
let llargtys = type_of_explicit_args(ccx, sp, arg_tys);
check non_ty_var(ccx, ret_ty); // NDM does this truly hold?
@ -5365,7 +5365,8 @@ fn c_stack_tys(ccx: @crate_ctxt,
// stack pointer appropriately to avoid a round of copies. (In fact, the shim
// function itself is unnecessary). We used to do this, in fact, and will
// perhaps do so in the future.
fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod) {
fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod,
abi: ast::native_abi) {
fn build_shim_fn(lcx: @local_ctxt,
native_item: @ast::native_item,
tys: @c_stack_tys,
@ -5448,7 +5449,7 @@ fn trans_native_mod(lcx: @local_ctxt, native_mod: ast::native_mod) {
let ccx = lcx_ccx(lcx);
let cc: uint = lib::llvm::LLVMCCallConv;
alt native_mod.abi {
alt abi {
ast::native_abi_rust_intrinsic. { ret; }
ast::native_abi_cdecl. { cc = lib::llvm::LLVMCCallConv; }
ast::native_abi_stdcall. { cc = lib::llvm::LLVMX86StdcallCallConv; }
@ -5529,13 +5530,16 @@ fn trans_item(cx: @local_ctxt, item: ast::item) {
}
ast::item_const(_, expr) { trans_const(cx.ccx, expr, item.id); }
ast::item_native_mod(native_mod) {
trans_native_mod(cx, native_mod);
let abi = alt attr::native_abi(item.attrs) {
either::right(abi_) { abi_ }
either::left(msg) { cx.ccx.sess.span_fatal(item.span, msg) }
};
trans_native_mod(cx, native_mod, abi);
}
_ {/* fall through */ }
}
}
// Translate a module. Doing this amounts to translating the items in the
// module; there ends up being no artifact (aside from linkage names) of
// separate modules in the compiled program. That's because modules exist
@ -5697,7 +5701,7 @@ fn native_fn_ty_param_count(cx: @crate_ctxt, id: ast::node_id) -> uint {
fn native_fn_wrapper_type(cx: @crate_ctxt, sp: span, ty_param_count: uint,
x: ty::t) -> TypeRef {
alt ty::struct(cx.tcx, x) {
ty::ty_native_fn(abi, args, out) {
ty::ty_native_fn(args, out) {
check non_ty_var(cx, out);
ret type_of_fn(cx, sp, false, false, args, out, ty_param_count);
}
@ -5719,7 +5723,10 @@ fn link_name(i: @ast::native_item) -> str {
}
}
fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, &&pt: [str],
fn collect_native_item(ccx: @crate_ctxt,
abi: @mutable option::t<ast::native_abi>,
i: @ast::native_item,
&&pt: [str],
_v: vt<[str]>) {
alt i.node {
ast::native_item_fn(_, tps) {
@ -5727,10 +5734,21 @@ fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, &&pt: [str],
let sp = i.span;
let id = i.id;
let node_type = node_id_type(ccx, id);
// FIXME NDM abi should come from attr
let abi = ty::ty_fn_abi(ccx.tcx, node_type);
alt abi {
let fn_abi =
alt attr::get_meta_item_value_str_by_name(i.attrs, "abi") {
option::none. {
// if abi isn't specified for this function, inherit from
// its enclosing native module
option::get(*abi)
}
_ {
alt attr::native_abi(i.attrs) {
either::right(abi_) { abi_ }
either::left(msg) { ccx.sess.span_fatal(i.span, msg) }
}
}
};
alt fn_abi {
ast::native_abi_rust_intrinsic. {
// For intrinsics: link the function directly to the intrinsic
// function itself.
@ -5760,9 +5778,8 @@ fn collect_native_item(ccx: @crate_ctxt, i: @ast::native_item, &&pt: [str],
}
}
fn collect_item_1(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
v: vt<[str]>) {
visit::visit_item(i, pt + item_path(i), v);
fn collect_item_1(ccx: @crate_ctxt, abi: @mutable option::t<ast::native_abi>,
i: @ast::item, &&pt: [str], v: vt<[str]>) {
alt i.node {
ast::item_const(_, _) {
let typ = node_id_type(ccx, i.id);
@ -5778,8 +5795,18 @@ fn collect_item_1(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
ccx.item_symbols.insert(i.id, s);
ccx.consts.insert(i.id, g);
}
ast::item_native_mod(native_mod) {
// Propagate the native ABI down to collect_native_item(),
alt attr::native_abi(i.attrs) {
either::left(msg) { ccx.sess.span_fatal(i.span, msg); }
either::right(abi_) {
*abi = option::some(abi_);
}
}
}
_ { }
}
visit::visit_item(i, pt + item_path(i), v);
}
fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
@ -5814,10 +5841,11 @@ fn collect_item_2(ccx: @crate_ctxt, i: @ast::item, &&pt: [str],
}
fn collect_items(ccx: @crate_ctxt, crate: @ast::crate) {
let abi = @mutable none::<ast::native_abi>;
let visitor0 = visit::default_visitor();
let visitor1 =
@{visit_native_item: bind collect_native_item(ccx, _, _, _),
visit_item: bind collect_item_1(ccx, _, _, _) with *visitor0};
@{visit_native_item: bind collect_native_item(ccx, abi, _, _, _),
visit_item: bind collect_item_1(ccx, abi, _, _, _) with *visitor0};
let visitor2 =
@{visit_item: bind collect_item_2(ccx, _, _, _) with *visitor0};
visit::visit_crate(*crate, [], visit::mk_vt(visitor1));

View file

@ -1070,7 +1070,7 @@ fn callee_modes(fcx: fn_ctxt, callee: node_id) -> [ty::mode] {
ty::type_autoderef(fcx.ccx.tcx,
ty::node_id_to_type(fcx.ccx.tcx, callee));
alt ty::struct(fcx.ccx.tcx, ty) {
ty::ty_fn(_, args, _, _, _) | ty::ty_native_fn(_, args, _) {
ty::ty_fn(_, args, _, _, _) | ty::ty_native_fn(args, _) {
let modes = [];
for arg: ty::arg in args { modes += [arg.mode]; }
ret modes;

View file

@ -113,7 +113,6 @@ export ty_constr;
export ty_constr_arg;
export ty_float;
export ty_fn;
export ty_fn_abi;
export ty_fn_proto;
export ty_fn_ret;
export ty_fn_ret_style;
@ -259,7 +258,7 @@ tag sty {
ty_ptr(mt);
ty_rec([field]);
ty_fn(ast::proto, [arg], t, ret_style, [@constr]);
ty_native_fn(ast::native_abi, [arg], t);
ty_native_fn([arg], t);
ty_obj([method]);
ty_res(def_id, t, [t]);
ty_tup([t]);
@ -465,7 +464,7 @@ fn mk_raw_ty(cx: ctxt, st: sty, _in_cname: option::t<str>) -> @raw_t {
ty_fn(_, args, tt, _, _) {
derive_flags_sig(cx, has_params, has_vars, args, tt);
}
ty_native_fn(_, args, tt) {
ty_native_fn(args, tt) {
derive_flags_sig(cx, has_params, has_vars, args, tt);
}
ty_obj(meths) {
@ -568,8 +567,8 @@ fn mk_fn(cx: ctxt, proto: ast::proto, args: [arg], ty: t, cf: ret_style,
ret gen_ty(cx, ty_fn(proto, args, ty, cf, constrs));
}
fn mk_native_fn(cx: ctxt, abi: ast::native_abi, args: [arg], ty: t) -> t {
ret gen_ty(cx, ty_native_fn(abi, args, ty));
fn mk_native_fn(cx: ctxt, args: [arg], ty: t) -> t {
ret gen_ty(cx, ty_native_fn(args, ty));
}
fn mk_obj(cx: ctxt, meths: [method]) -> t { ret gen_ty(cx, ty_obj(meths)); }
@ -628,7 +627,7 @@ fn walk_ty(cx: ctxt, walker: ty_walk, ty: t) {
for a: arg in args { walk_ty(cx, walker, a.ty); }
walk_ty(cx, walker, ret_ty);
}
ty_native_fn(abi, args, ret_ty) {
ty_native_fn(args, ret_ty) {
for a: arg in args { walk_ty(cx, walker, a.ty); }
walk_ty(cx, walker, ret_ty);
}
@ -719,7 +718,7 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
mk_fn(cx, proto, new_args, fold_ty(cx, fld, ret_ty),
cf, constrs), ty);
}
ty_native_fn(abi, args, ret_ty) {
ty_native_fn(args, ret_ty) {
let new_args: [arg] = [];
for a: arg in args {
let new_ty = fold_ty(cx, fld, a.ty);
@ -727,7 +726,7 @@ fn fold_ty(cx: ctxt, fld: fold_mode, ty_0: t) -> t {
}
ty =
copy_cname(cx,
mk_native_fn(cx, abi, new_args,
mk_native_fn(cx, new_args,
fold_ty(cx, fld, ret_ty)), ty);
}
ty_obj(methods) {
@ -802,7 +801,7 @@ fn type_is_structural(cx: ctxt, ty: t) -> bool {
ty_tup(_) { ret true; }
ty_tag(_, _) { ret true; }
ty_fn(_, _, _, _, _) { ret true; }
ty_native_fn(_, _, _) { ret true; }
ty_native_fn(_, _) { ret true; }
ty_obj(_) { ret true; }
ty_res(_, _, _) { ret true; }
_ { ret false; }
@ -1008,7 +1007,7 @@ fn type_kind(cx: ctxt, ty: t) -> ast::kind {
// Scalar and unique types are sendable
ty_nil. | ty_bot. | ty_bool. | ty_int. | ty_uint. | ty_float. |
ty_machine(_) | ty_char. | ty_native(_) |
ty_type. | ty_str. | ty_native_fn(_, _, _) { ast::kind_sendable }
ty_type. | ty_str. | ty_native_fn(_, _) { ast::kind_sendable }
// FIXME: obj is broken for now, since we aren't asserting
// anything about its fields.
ty_obj(_) { kind_copyable }
@ -1221,7 +1220,7 @@ fn type_is_pod(cx: ctxt, ty: t) -> bool {
}
// Boxed types
ty_str. | ty_box(_) | ty_uniq(_) | ty_vec(_) | ty_fn(_, _, _, _, _) |
ty_native_fn(_, _, _) | ty_obj(_) {
ty_native_fn(_, _) | ty_obj(_) {
result = false;
}
// Structural types
@ -1390,7 +1389,7 @@ fn hash_type_structure(st: sty) -> uint {
ty_fn(_, args, rty, _, _) {
ret hash_fn(27u, args, rty);
}
ty_native_fn(_, args, rty) { ret hash_fn(28u, args, rty); }
ty_native_fn(args, rty) { ret hash_fn(28u, args, rty); }
ty_obj(methods) {
let h = 29u;
for m: method in methods { h += h << 5u + str::hash(m.ident); }
@ -1584,7 +1583,7 @@ fn type_contains_params(cx: ctxt, typ: t) -> bool {
fn ty_fn_args(cx: ctxt, fty: t) -> [arg] {
alt struct(cx, fty) {
ty::ty_fn(_, a, _, _, _) { ret a; }
ty::ty_native_fn(_, a, _) { ret a; }
ty::ty_native_fn(a, _) { ret a; }
_ { cx.sess.bug("ty_fn_args() called on non-fn type"); }
}
}
@ -1592,7 +1591,7 @@ fn ty_fn_args(cx: ctxt, fty: t) -> [arg] {
fn ty_fn_proto(cx: ctxt, fty: t) -> ast::proto {
alt struct(cx, fty) {
ty::ty_fn(p, _, _, _, _) { ret p; }
ty::ty_native_fn(_, _, _) {
ty::ty_native_fn(_, _) {
// FIXME: This should probably be proto_bare
ret ast::proto_shared(ast::sugar_normal);
}
@ -1600,18 +1599,11 @@ fn ty_fn_proto(cx: ctxt, fty: t) -> ast::proto {
}
}
fn ty_fn_abi(cx: ctxt, fty: t) -> ast::native_abi {
alt struct(cx, fty) {
ty::ty_native_fn(a, _, _) { ret a; }
_ { cx.sess.bug("ty_fn_abi() called on non-native-fn type"); }
}
}
pure fn ty_fn_ret(cx: ctxt, fty: t) -> t {
let sty = struct(cx, fty);
alt sty {
ty::ty_fn(_, _, r, _, _) { ret r; }
ty::ty_native_fn(_, _, r) { ret r; }
ty::ty_native_fn(_, r) { ret r; }
_ {
// Unchecked is ok since we diverge here
// (might want to change the typechecker to allow
@ -1626,7 +1618,7 @@ pure fn ty_fn_ret(cx: ctxt, fty: t) -> t {
fn ty_fn_ret_style(cx: ctxt, fty: t) -> ast::ret_style {
alt struct(cx, fty) {
ty::ty_fn(_, _, _, rs, _) { rs }
ty::ty_native_fn(_, _, _) { ast::return_val }
ty::ty_native_fn(_, _) { ast::return_val }
_ { cx.sess.bug("ty_fn_ret_style() called on non-fn type"); }
}
}
@ -1634,7 +1626,7 @@ fn ty_fn_ret_style(cx: ctxt, fty: t) -> ast::ret_style {
fn is_fn_ty(cx: ctxt, fty: t) -> bool {
alt struct(cx, fty) {
ty::ty_fn(_, _, _, _, _) { ret true; }
ty::ty_native_fn(_, _, _) { ret true; }
ty::ty_native_fn(_, _) { ret true; }
_ { ret false; }
}
}
@ -2097,12 +2089,10 @@ mod unify {
}
}
}
fn unify_native_fn(cx: @ctxt, e_abi: ast::native_abi,
a_abi: ast::native_abi, expected: t, actual: t,
fn unify_native_fn(cx: @ctxt, expected: t, actual: t,
expected_inputs: [arg], expected_output: t,
actual_inputs: [arg], actual_output: t,
variance: variance) -> result {
if e_abi != a_abi { ret ures_err(terr_mismatch); }
let t =
unify_fn_common(cx, expected, actual, expected_inputs,
expected_output, actual_inputs, actual_output,
@ -2110,7 +2100,7 @@ mod unify {
alt t {
fn_common_res_err(r) { ret r; }
fn_common_res_ok(result_ins, result_out) {
let t2 = mk_native_fn(cx.tcx, e_abi, result_ins, result_out);
let t2 = mk_native_fn(cx.tcx, result_ins, result_out);
ret ures_ok(t2);
}
}
@ -2521,10 +2511,10 @@ mod unify {
_ { ret ures_err(terr_mismatch); }
}
}
ty::ty_native_fn(e_abi, expected_inputs, expected_output) {
ty::ty_native_fn(expected_inputs, expected_output) {
alt struct(cx.tcx, actual) {
ty::ty_native_fn(a_abi, actual_inputs, actual_output) {
ret unify_native_fn(cx, e_abi, a_abi, expected, actual,
ty::ty_native_fn(actual_inputs, actual_output) {
ret unify_native_fn(cx, expected, actual,
expected_inputs, expected_output,
actual_inputs, actual_output, variance);
}

View file

@ -524,14 +524,14 @@ mod collect {
}
fn ty_of_native_fn_decl(cx: @ctxt, convert: fn@(&&@ast::ty) -> ty::t,
ty_of_arg: fn@(ast::arg) -> arg,
decl: ast::fn_decl, abi: ast::native_abi,
decl: ast::fn_decl,
ty_params: [ast::ty_param], def_id: ast::def_id)
-> ty::ty_param_kinds_and_ty {
let input_tys = [];
for a: ast::arg in decl.inputs { input_tys += [ty_of_arg(a)]; }
let output_ty = convert(decl.output);
let t_fn = ty::mk_native_fn(cx.tcx, abi, input_tys, output_ty);
let t_fn = ty::mk_native_fn(cx.tcx, input_tys, output_ty);
let tpt = {kinds: ty_param_kinds(ty_params), ty: t_fn};
cx.tcx.tcache.insert(def_id, tpt);
ret tpt;
@ -546,8 +546,7 @@ mod collect {
alt it {
some(ast_map::node_item(item)) { tpt = ty_of_item(cx, item); }
some(ast_map::node_native_item(native_item)) {
tpt = ty_of_native_item(cx, native_item,
ast::native_abi_cdecl);
tpt = ty_of_native_item(cx, native_item);
}
_ { cx.tcx.sess.fatal("internal error " + std::int::str(id.node)); }
}
@ -661,15 +660,15 @@ mod collect {
ast::item_native_mod(_) { fail; }
}
}
fn ty_of_native_item(cx: @ctxt, it: @ast::native_item,
abi: ast::native_abi) -> ty::ty_param_kinds_and_ty {
fn ty_of_native_item(cx: @ctxt, it: @ast::native_item)
-> ty::ty_param_kinds_and_ty {
let no_kinds: [ast::kind] = [];
alt it.node {
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, _);
ret ty_of_native_fn_decl(cx, convert, f, fn_decl, abi, params,
ret ty_of_native_fn_decl(cx, convert, f, fn_decl, params,
ast_util::local_def(it.id));
}
ast::native_item_ty. {
@ -726,16 +725,13 @@ mod collect {
}
ret meths;
}
fn convert(cx: @ctxt, abi: @mutable option::t<ast::native_abi>,
it: @ast::item) {
fn convert(cx: @ctxt, it: @ast::item) {
alt it.node {
ast::item_mod(_) {
// ignore item_mod, it has no type.
}
ast::item_native_mod(native_mod) {
// Propagate the native ABI down to convert_native() below,
// but otherwise do nothing, as native modules have no types.
*abi = some::<ast::native_abi>(native_mod.abi);
// do nothing, as native modules have no types.
}
ast::item_tag(variants, ty_params) {
let tpt = ty_of_item(cx, it);
@ -804,14 +800,11 @@ mod collect {
}
}
}
fn convert_native(cx: @ctxt, abi: @mutable option::t<ast::native_abi>,
i: @ast::native_item) {
fn convert_native(cx: @ctxt, i: @ast::native_item) {
// As above, this call populates the type table with the converted
// type of the native item. We simply write it into the node type
// table.
let tpt =
ty_of_native_item(cx, i,
option::get::<ast::native_abi>({ *abi }));
let tpt = ty_of_native_item(cx, i);
alt i.node {
ast::native_item_ty. {
// FIXME: Native types have no annotation. Should they? --pcw
@ -822,14 +815,11 @@ mod collect {
}
}
fn collect_item_types(tcx: ty::ctxt, crate: @ast::crate) {
// We have to propagate the surrounding ABI to the native items
// contained within the native module.
let abi = @mutable none::<ast::native_abi>;
let cx = @{tcx: tcx};
let visit =
visit::mk_simple_visitor(@{visit_item: bind convert(cx, abi, _),
visit::mk_simple_visitor(@{visit_item: bind convert(cx, _),
visit_native_item:
bind convert_native(cx, abi, _)
bind convert_native(cx, _)
with
*visit::default_simple_visitor()});
visit::visit_crate(*crate, (), visit);
@ -1567,7 +1557,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
// Grab the argument types
let arg_tys =
alt sty {
ty::ty_fn(_, arg_tys, _, _, _) | ty::ty_native_fn(_, arg_tys, _)
ty::ty_fn(_, arg_tys, _, _, _) | ty::ty_native_fn(arg_tys, _)
{
arg_tys
}
@ -1676,7 +1666,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
bot |= cf == ast::noreturn;
rt_1 = rt;
}
ty::ty_native_fn(_, _, rt) { rt_1 = rt; }
ty::ty_native_fn(_, rt) { rt_1 = rt; }
_ { fcx.ccx.tcx.sess.span_fatal(sp, "calling non-function"); }
}
write::ty_only_fixup(fcx, id, rt_1);
@ -2031,7 +2021,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
cf = cf_;
constrs = constrs_;
}
ty::ty_native_fn(_, arg_tys_, rt_) {
ty::ty_native_fn(arg_tys_, rt_) {
proto = ast::proto_bare;
arg_tys = arg_tys_;
rt = rt_;

View file

@ -431,9 +431,7 @@ tag native_abi {
}
type native_mod =
{// FIXME: Removing abi from AST. Depends on Issue #1179.
abi: native_abi,
view_items: [@view_item],
{view_items: [@view_item],
items: [@native_item]};
type variant_arg = {ty: @ty, id: node_id};

View file

@ -452,8 +452,7 @@ fn noop_fold_mod(m: _mod, fld: ast_fold) -> _mod {
}
fn noop_fold_native_mod(nm: native_mod, fld: ast_fold) -> native_mod {
ret {abi: nm.abi,
view_items: vec::map(fld.fold_view_item, nm.view_items),
ret {view_items: vec::map(fld.fold_view_item, nm.view_items),
items: vec::map(fld.fold_native_item, nm.items)}
}

View file

@ -1981,8 +1981,7 @@ fn parse_native_item(p: parser, attrs: [ast::attribute]) ->
} else { unexpected(p, p.peek()); }
}
fn parse_native_mod_items(p: parser, abi: ast::native_abi,
first_item_attrs: [ast::attribute]) ->
fn parse_native_mod_items(p: parser, first_item_attrs: [ast::attribute]) ->
ast::native_mod {
// Shouldn't be any view items since we've already parsed an item attr
let view_items =
@ -1996,8 +1995,7 @@ fn parse_native_mod_items(p: parser, abi: ast::native_abi,
initial_attrs = [];
items += [parse_native_item(p, attrs)];
}
ret {abi: abi,
view_items: view_items,
ret {view_items: view_items,
items: items};
}
@ -2009,24 +2007,7 @@ fn parse_item_native_mod(p: parser, attrs: [ast::attribute]) -> @ast::item {
let more_attrs = parse_inner_attrs_and_next(p);
let inner_attrs = more_attrs.inner;
let first_item_outer_attrs = more_attrs.next;
let abi =
alt attr::get_meta_item_value_str_by_name(
attrs + inner_attrs, "abi") {
none. { ast::native_abi_cdecl }
some("rust-intrinsic") {
ast::native_abi_rust_intrinsic
}
some("cdecl") {
ast::native_abi_cdecl
}
some("stdcall") {
ast::native_abi_stdcall
}
some(t) {
p.fatal("unsupported abi: " + t);
}
};
let m = parse_native_mod_items(p, abi, first_item_outer_attrs);
let m = parse_native_mod_items(p, first_item_outer_attrs);
let hi = p.get_hi_pos();
expect(p, token::RBRACE);
ret mk_item(p, lo, hi, id, ast::item_native_mod(m), attrs + inner_attrs);

View file

@ -127,7 +127,7 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
ty_fn(proto, inputs, output, cf, constrs) {
fn_to_str(cx, proto, none, inputs, output, cf, constrs)
}
ty_native_fn(_, inputs, output) {
ty_native_fn(inputs, output) {
fn_to_str(cx, ast::proto_bare, none, inputs, output,
ast::return_val, [])
}