Skip to content

Commit 4b946ce

Browse files
committed
Modify native_item_fn to handle trailing linkage names that differ from the item name (used in win32 build of std.dll)
1 parent 0c7545c commit 4b946ce

File tree

8 files changed

+33
-18
lines changed

8 files changed

+33
-18
lines changed

src/comp/front/ast.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ tag item_ {
367367
type native_item = spanned[native_item_];
368368
tag native_item_ {
369369
native_item_ty(ident, def_id);
370-
native_item_fn(ident, fn_decl, vec[ty_param], def_id, ann);
370+
native_item_fn(ident, option.t[str],
371+
fn_decl, vec[ty_param], def_id, ann);
371372
}
372373
373374
// TODO: Actually store something here.
@@ -426,7 +427,7 @@ fn index_native_item(native_mod_index index, @native_item it) {
426427
case (ast.native_item_ty(?id, _)) {
427428
index.insert(id, ast.nmie_item(it));
428429
}
429-
case (ast.native_item_fn(?id, _, _, _, _)) {
430+
case (ast.native_item_fn(?id, _, _, _, _, _)) {
430431
index.insert(id, ast.nmie_item(it));
431432
}
432433
}

src/comp/front/parser.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,9 +1859,15 @@ impure fn parse_item_native_fn(parser p, ast.effect eff) -> @ast.native_item {
18591859
expect(p, token.FN);
18601860
auto t = parse_fn_header(p);
18611861
auto decl = parse_fn_decl(p, eff);
1862+
auto link_name = none[str];
1863+
if (p.peek() == token.EQ) {
1864+
p.bump();
1865+
link_name = some[str](parse_str_lit_or_env_ident(p));
1866+
}
18621867
auto hi = p.get_span();
18631868
expect(p, token.SEMI);
1864-
auto item = ast.native_item_fn(t._0, decl, t._1, p.next_def_id(),
1869+
auto item = ast.native_item_fn(t._0, link_name, decl,
1870+
t._1, p.next_def_id(),
18651871
ast.ann_none);
18661872
ret @spanned(lo, hi, item);
18671873
}

src/comp/middle/fold.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ type ast_fold[ENV] =
233233
def_id id, ann a) -> @item) fold_item_fn,
234234

235235
(fn(&ENV e, &span sp, ident ident,
236+
option.t[str] link_name,
236237
&ast.fn_decl decl,
237238
vec[ast.ty_param] ty_params,
238239
def_id id, ann a) -> @native_item) fold_native_item_fn,
@@ -990,9 +991,10 @@ fn fold_native_item[ENV](&ENV env, ast_fold[ENV] fld,
990991
case (ast.native_item_ty(?ident, ?id)) {
991992
ret fld.fold_native_item_ty(env_, i.span, ident, id);
992993
}
993-
case (ast.native_item_fn(?ident, ?fn_decl, ?ty_params, ?id, ?ann)) {
994+
case (ast.native_item_fn(?ident, ?lname, ?fn_decl,
995+
?ty_params, ?id, ?ann)) {
994996
auto d = fold_fn_decl[ENV](env_, fld, fn_decl);
995-
ret fld.fold_native_item_fn(env_, i.span, ident, d,
997+
ret fld.fold_native_item_fn(env_, i.span, ident, lname, d,
996998
ty_params, id, ann);
997999
}
9981000
}
@@ -1346,10 +1348,11 @@ fn identity_fold_item_fn[ENV](&ENV e, &span sp, ident i,
13461348
}
13471349

13481350
fn identity_fold_native_item_fn[ENV](&ENV e, &span sp, ident i,
1351+
option.t[str] link_name,
13491352
&ast.fn_decl decl,
13501353
vec[ast.ty_param] ty_params,
13511354
def_id id, ann a) -> @native_item {
1352-
ret @respan(sp, ast.native_item_fn(i, decl, ty_params, id, a));
1355+
ret @respan(sp, ast.native_item_fn(i, link_name, decl, ty_params, id, a));
13531356
}
13541357

13551358
fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i,
@@ -1576,7 +1579,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
15761579
fold_item_const= bind identity_fold_item_const[ENV](_,_,_,_,_,_,_),
15771580
fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_,_),
15781581
fold_native_item_fn =
1579-
bind identity_fold_native_item_fn[ENV](_,_,_,_,_,_,_),
1582+
bind identity_fold_native_item_fn[ENV](_,_,_,_,_,_,_,_),
15801583
fold_item_mod = bind identity_fold_item_mod[ENV](_,_,_,_,_),
15811584
fold_item_native_mod =
15821585
bind identity_fold_item_native_mod[ENV](_,_,_,_,_),

src/comp/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
240240
case (ast.native_item_ty(_, ?id)) {
241241
ret def_wrap_other(ast.def_native_ty(id));
242242
}
243-
case (ast.native_item_fn(_, _, _, ?id, _)) {
243+
case (ast.native_item_fn(_, _, _, _, ?id, _)) {
244244
ret def_wrap_other(ast.def_native_fn(id));
245245
}
246246
}
@@ -430,7 +430,7 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
430430

431431
case (scope_native_item(?it)) {
432432
alt (it.node) {
433-
case (ast.native_item_fn(_, ?decl, ?ty_params, _, _)) {
433+
case (ast.native_item_fn(_, _, ?decl, ?ty_params, _, _)) {
434434
ret handle_fn_decl(i, decl, ty_params);
435435
}
436436
}

src/comp/middle/trans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5409,7 +5409,7 @@ fn native_fn_ty_param_count(@crate_ctxt cx, &ast.def_id id) -> uint {
54095409
"actually a fn?!");
54105410
fail;
54115411
}
5412-
case (ast.native_item_fn(_, _, ?tps, _, _)) {
5412+
case (ast.native_item_fn(_, _, _, ?tps, _, _)) {
54135413
count = _vec.len[ast.ty_param](tps);
54145414
}
54155415
}
@@ -5499,7 +5499,7 @@ fn decl_native_fn_and_pair(@crate_ctxt cx,
54995499

55005500
fn collect_native_item(&@crate_ctxt cx, @ast.native_item i) -> @crate_ctxt {
55015501
alt (i.node) {
5502-
case (ast.native_item_fn(?name, _, _, ?fid, ?ann)) {
5502+
case (ast.native_item_fn(?name, _, _, _, ?fid, ?ann)) {
55035503
cx.native_items.insert(fid, i);
55045504
if (! cx.obj_methods.contains_key(fid)) {
55055505
decl_native_fn_and_pair(cx, name, ann, fid);

src/comp/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ fn native_item_ty(@ast.native_item it) -> ty_params_and_ty {
645645
auto ty_params;
646646
auto result_ty;
647647
alt (it.node) {
648-
case (ast.native_item_fn(_, _, ?tps, _, ?ann)) {
648+
case (ast.native_item_fn(_, _, _, ?tps, _, ?ann)) {
649649
ty_params = tps;
650650
result_ty = ann_to_type(ann);
651651
}

src/comp/middle/typeck.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ fn ty_params_of_item(@ast.item item) -> vec[ast.ty_param] {
442442

443443
fn ty_params_of_native_item(@ast.native_item item) -> vec[ast.ty_param] {
444444
alt (item.node) {
445-
case (ast.native_item_fn(_, _, ?p, _, _)) {
445+
case (ast.native_item_fn(_, _, _, ?p, _, _)) {
446446
ret p;
447447
}
448448
case (_) {
@@ -623,7 +623,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
623623
@ast.native_item it,
624624
ast.native_abi abi) -> @ty.t {
625625
alt (it.node) {
626-
case (ast.native_item_fn(?ident, ?fn_decl, ?params, ?def_id, _)) {
626+
case (ast.native_item_fn(?ident, ?lname, ?fn_decl,
627+
?params, ?def_id, _)) {
627628
auto get = bind getter(id_to_ty_item, item_to_ty, _);
628629
auto convert = bind ast_ty_to_ty(get, _);
629630
auto f = bind ty_of_arg(id_to_ty_item, item_to_ty, _);
@@ -800,14 +801,14 @@ fn collect_item_types(session.session sess, @ast.crate crate)
800801
ret @fold.respan[ast.item_](sp, item);
801802
}
802803

803-
fn fold_native_item_fn(&@env e, &span sp, ast.ident i,
804+
fn fold_native_item_fn(&@env e, &span sp, ast.ident i, option.t[str] ln,
804805
&ast.fn_decl d, vec[ast.ty_param] ty_params,
805806
ast.def_id id, ast.ann a) -> @ast.native_item {
806807
collect_ty_params(e, id, ty_params);
807808

808809
check (e.item_to_ty.contains_key(id));
809810
auto typ = e.item_to_ty.get(id);
810-
auto item = ast.native_item_fn(i, d, ty_params, id,
811+
auto item = ast.native_item_fn(i, ln, d, ty_params, id,
811812
ast.ann_type(typ, none[vec[@ty.t]]));
812813
ret @fold.respan[ast.native_item_](sp, item);
813814
}
@@ -912,7 +913,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
912913
update_env_for_native_item = bind convert_native(_,_),
913914
fold_item_const = bind fold_item_const(_,_,_,_,_,_,_),
914915
fold_item_fn = bind fold_item_fn(_,_,_,_,_,_,_),
915-
fold_native_item_fn = bind fold_native_item_fn(_,_,_,_,_,_,_),
916+
fold_native_item_fn = bind fold_native_item_fn(_,_,_,_,_,_,_,_),
916917
fold_item_obj = bind fold_item_obj(_,_,_,_,_,_,_),
917918
fold_item_ty = bind fold_item_ty(_,_,_,_,_,_,_),
918919
fold_item_tag = bind fold_item_tag(_,_,_,_,_,_)

src/comp/pretty/pprust.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,12 @@ impure fn print_item(ps s, @ast.item item) {
163163
wrd1(s, "type");
164164
wrd(s, id);
165165
}
166-
case (ast.native_item_fn(?id,?decl,?typarams,_,_)) {
166+
case (ast.native_item_fn(?id,?lname,?decl,?typarams,_,_)) {
167167
print_fn(s, decl, id, typarams);
168+
alt (lname) {
169+
case (option.none[str]) {}
170+
case (option.some[str](?ss)) {print_string(s,ss);}
171+
}
168172
}
169173
}
170174
wrd(s, ";");

0 commit comments

Comments
 (0)