aboutsummaryrefslogtreecommitdiff
path: root/src/comp/front/parser.rs
diff options
context:
space:
mode:
authorRafael Ávila de Espíndola <[email protected]>2011-02-23 14:06:37 -0500
committerRafael Ávila de Espíndola <[email protected]>2011-02-23 14:06:37 -0500
commitffcb4613700c968041f891985927b77f70a51c0c (patch)
treeed5a0566378482e48723d106edab384c1bbfac25 /src/comp/front/parser.rs
parentHandle the new ty_native_fn in type check. (diff)
downloadrust-ffcb4613700c968041f891985927b77f70a51c0c.tar.xz
rust-ffcb4613700c968041f891985927b77f70a51c0c.zip
Parse the abi in native modules.
Diffstat (limited to 'src/comp/front/parser.rs')
-rw-r--r--src/comp/front/parser.rs44
1 files changed, 33 insertions, 11 deletions
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index bbac78d3..03b24e4e 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -1723,7 +1723,8 @@ impure fn parse_native_item(parser p) -> @ast.native_item {
}
impure fn parse_native_mod_items(parser p,
- str native_name) -> ast.native_mod {
+ str native_name,
+ ast.native_abi abi) -> ast.native_mod {
auto index = new_str_hash[@ast.native_item]();
let vec[@ast.native_item] items = vec();
while (p.peek() != token.RBRACE) {
@@ -1733,28 +1734,49 @@ impure fn parse_native_mod_items(parser p,
// Index the item.
ast.index_native_item(index, item);
}
- ret rec(native_name=native_name, items=items, index=index);
+ ret rec(native_name=native_name, abi=abi,
+ items=items, index=index);
+}
+
+fn default_native_name(session.session sess, str id) -> str {
+ alt (sess.get_targ_cfg().os) {
+ case (session.os_win32) {
+ ret id + ".dll";
+ }
+ case (session.os_macos) {
+ ret "lib" + id + ".dylib";
+ }
+ case (session.os_linux) {
+ ret "lib" + id + ".so";
+ }
+ }
}
impure fn parse_item_native_mod(parser p) -> @ast.item {
auto lo = p.get_span();
expect(p, token.NATIVE);
- auto has_eq;
- auto native_name = "";
- if (p.peek() == token.MOD) {
- has_eq = true;
- } else {
- native_name = parse_str_lit(p);
- has_eq = false;
+ auto abi = ast.native_abi_cdecl;
+ if (p.peek() != token.MOD) {
+ auto t = parse_str_lit(p);
+ if (t == "cdecl") {
+ } else if (t == "rust") {
+ abi = ast.native_abi_rust;
+ } else {
+ p.err("unsupported abi: " + t);
+ fail;
+ }
}
expect(p, token.MOD);
auto id = parse_ident(p);
- if (has_eq) {
+ auto native_name;
+ if (p.peek() == token.EQ) {
expect(p, token.EQ);
native_name = parse_str_lit(p);
+ } else {
+ native_name = default_native_name(p.get_session(), id);
}
expect(p, token.LBRACE);
- auto m = parse_native_mod_items(p, native_name);
+ auto m = parse_native_mod_items(p, native_name, ast.native_abi_cdecl);
auto hi = p.get_span();
expect(p, token.RBRACE);
auto item = ast.item_native_mod(id, m, p.next_def_id());