Skip to content

Commit fba0df7

Browse files
committed
Use attributes for native module ABI and link name [temp]
This patch adds support of using attributes to specify native mode ABI and link name. The old optional syntax like: native "cdecl" mod llvm = "rustllvm" { ... } is still supported. This is a transitional commit to avoid making a stage1 (backward imcompatible) snapshot.
1 parent 3b683f5 commit fba0df7

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/comp/syntax/parse/parser.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import token::can_begin_expr;
77
import codemap::span;
88
import util::interner;
99
import ast::{node_id, spanned};
10+
import front::attr;
1011

1112
tag restriction { UNRESTRICTED; RESTRICT_NO_CALL_EXPRS; }
1213

@@ -2012,14 +2013,37 @@ fn parse_item_native_mod(p: parser, attrs: [ast::attribute]) -> @ast::item {
20122013
} else {
20132014
p.fatal("unsupported abi: " + t);
20142015
}
2016+
} else {
2017+
abi =
2018+
alt attr::get_meta_item_value_str_by_name(attrs, "abi") {
2019+
none. { ast::native_abi_cdecl }
2020+
some("rust-intrinsic") {
2021+
ast::native_abi_rust_intrinsic
2022+
}
2023+
some("cdecl") {
2024+
ast::native_abi_cdecl
2025+
}
2026+
some("stdcall") {
2027+
ast::native_abi_stdcall
2028+
}
2029+
some(t) {
2030+
p.fatal("unsupported abi: " + t);
2031+
}
2032+
};
20152033
}
20162034
expect_word(p, "mod");
20172035
let id = parse_ident(p);
20182036
let native_name;
20192037
if p.peek() == token::EQ {
20202038
expect(p, token::EQ);
20212039
native_name = parse_str(p);
2022-
} else { native_name = id; }
2040+
} else {
2041+
native_name =
2042+
alt attr::get_meta_item_value_str_by_name(attrs, "link_name") {
2043+
none. { id }
2044+
some(nn) { nn }
2045+
};
2046+
}
20232047
expect(p, token::LBRACE);
20242048
let more_attrs = parse_inner_attrs_and_next(p);
20252049
let inner_attrs = more_attrs.inner;

0 commit comments

Comments
 (0)