diff options
| author | Haitao Li <lihaitao@gmail.com> | 2011-11-16 22:49:38 -0600 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-11-16 11:35:13 -0800 |
| commit | 88f29aab27bf56bda4cf7062cb53af0be4b5c251 (patch) | |
| tree | 2699aca1781258a889f68d553935150d665d9e50 /src/comp/syntax | |
| parent | 7a9b66db631478b7f42cdbfae52f96d5e7bb0a1f (diff) | |
Use attributes for native module ABI and link name
This patch changes how to specify ABI and link name of a native module.
Before:
native "cdecl" mod llvm = "rustllvm" {...}
After:
#[abi = "cdecl"]
#[link_name = "rustllvm"]
native mod llvm {...}
The old optional syntax for ABI and link name is no longer supported.
Fixes issue #547
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/ast.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/fold.rs | 3 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 66 | ||||
| -rw-r--r-- | src/comp/syntax/print/pprust.rs | 16 |
4 files changed, 22 insertions, 65 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index 16d0d0d53c8..b2117810c6d 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -432,7 +432,7 @@ tag native_abi { } type native_mod = - {native_name: str, + {// FIXME: Removing abi from AST. Depends on Issue #1179. abi: native_abi, view_items: [@view_item], items: [@native_item]}; diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs index 56e6aecbab1..f9b6d5739c8 100644 --- a/src/comp/syntax/fold.rs +++ b/src/comp/syntax/fold.rs @@ -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 {native_name: nm.native_name, - abi: nm.abi, + ret {abi: nm.abi, view_items: vec::map(fld.fold_view_item, nm.view_items), items: vec::map(fld.fold_native_item, nm.items)} } diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 580822d9f1d..05f508edfd0 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -1978,7 +1978,7 @@ fn parse_native_item(p: parser, attrs: [ast::attribute]) -> } else { unexpected(p, p.peek()); } } -fn parse_native_mod_items(p: parser, native_name: str, abi: ast::native_abi, +fn parse_native_mod_items(p: parser, abi: ast::native_abi, first_item_attrs: [ast::attribute]) -> ast::native_mod { // Shouldn't be any view items since we've already parsed an item attr @@ -1993,63 +1993,37 @@ fn parse_native_mod_items(p: parser, native_name: str, abi: ast::native_abi, initial_attrs = []; items += [parse_native_item(p, attrs)]; } - ret {native_name: native_name, - abi: abi, + ret {abi: abi, view_items: view_items, items: items}; } fn parse_item_native_mod(p: parser, attrs: [ast::attribute]) -> @ast::item { let lo = p.get_last_lo_pos(); - let abi = ast::native_abi_cdecl; - if !is_word(p, "mod") { - let t = parse_str(p); - if str::eq(t, "rust-intrinsic") { - abi = ast::native_abi_rust_intrinsic; - } else if str::eq(t, "cdecl") { - abi = ast::native_abi_cdecl; - } else if str::eq(t, "stdcall") { - abi = ast::native_abi_stdcall; - } 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); - let native_name; - if p.peek() == token::EQ { - expect(p, token::EQ); - native_name = parse_str(p); - } 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; let first_item_outer_attrs = more_attrs.next; - let m = - parse_native_mod_items(p, native_name, abi, first_item_outer_attrs); + 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 hi = p.get_hi_pos(); expect(p, token::RBRACE); ret mk_item(p, lo, hi, id, ast::item_native_mod(m), attrs + inner_attrs); diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 21cfaa9e072..93a4293a5d1 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -395,24 +395,8 @@ fn print_item(s: ps, &&item: @ast::item) { } ast::item_native_mod(nmod) { head(s, "native"); - alt nmod.abi { - ast::native_abi_rust_intrinsic. { - word_nbsp(s, "\"rust-intrinsic\""); - } - ast::native_abi_cdecl. { - word_nbsp(s, "\"cdecl\""); - } - ast::native_abi_stdcall. { - word_nbsp(s, "\"stdcall\""); - } - } word_nbsp(s, "mod"); word_nbsp(s, item.ident); - if !str::eq(nmod.native_name, item.ident) { - word_space(s, "="); - print_string(s, nmod.native_name); - nbsp(s); - } bopen(s); print_native_mod(s, nmod, item.attrs); bclose(s, item.span); |
