about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorHaitao Li <lihaitao@gmail.com>2011-11-16 21:50:50 -0600
committerHaitao Li <lihaitao@gmail.com>2011-11-16 23:45:07 +0800
commitfba0df72d320a5b2e19678c9490825568de6f9a4 (patch)
tree6f3cba64ec10eea6321badcd5d6242e3799cefa8 /src
parent3b683f52052b0cbf514c89a4da08df2b8e017fd4 (diff)
downloadrust-fba0df72d320a5b2e19678c9490825568de6f9a4.tar.gz
rust-fba0df72d320a5b2e19678c9490825568de6f9a4.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/comp/syntax/parse/parser.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index bb5bf4f7faa..580822d9f1d 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -7,6 +7,7 @@ import token::can_begin_expr;
 import codemap::span;
 import util::interner;
 import ast::{node_id, spanned};
+import front::attr;
 
 tag restriction { UNRESTRICTED; RESTRICT_NO_CALL_EXPRS; }
 
@@ -2012,6 +2013,23 @@ fn parse_item_native_mod(p: parser, attrs: [ast::attribute]) -> @ast::item {
         } else {
             p.fatal("unsupported abi: " + t);
         }
+    } else {
+        abi =
+            alt attr::get_meta_item_value_str_by_name(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);
+              }
+            };
     }
     expect_word(p, "mod");
     let id = parse_ident(p);
@@ -2019,7 +2037,13 @@ fn parse_item_native_mod(p: parser, attrs: [ast::attribute]) -> @ast::item {
     if p.peek() == token::EQ {
         expect(p, token::EQ);
         native_name = parse_str(p);
-    } else { native_name = id; }
+    } else {
+        native_name =
+            alt attr::get_meta_item_value_str_by_name(attrs, "link_name") {
+              none. { id }
+              some(nn) { nn }
+            };
+    }
     expect(p, token::LBRACE);
     let more_attrs = parse_inner_attrs_and_next(p);
     let inner_attrs = more_attrs.inner;