diff options
| author | Rafael Ávila de Espíndola <[email protected]> | 2011-02-02 10:43:57 -0500 |
|---|---|---|
| committer | Rafael Ávila de Espíndola <[email protected]> | 2011-02-02 10:43:57 -0500 |
| commit | dd3ed6139a6fc6fda15403d0b5679535959945e5 (patch) | |
| tree | f97126df9bb855569e2b40d668d7190c033d8ce2 /src/comp/front | |
| parent | Fix buggy argument assembly for upcall_get_type_desc. Can now complete calls ... (diff) | |
| download | rust-dd3ed6139a6fc6fda15403d0b5679535959945e5.tar.xz rust-dd3ed6139a6fc6fda15403d0b5679535959945e5.zip | |
Add most of the plumbing for native items and add support for parsing native type declarations.
Diffstat (limited to 'src/comp/front')
| -rw-r--r-- | src/comp/front/ast.rs | 19 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 35 |
2 files changed, 51 insertions, 3 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 5f527f2d..7b22e700 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -215,7 +215,6 @@ type obj_field = rec(@ty ty, ident ident, def_id id, ann ann); type _obj = rec(vec[obj_field] fields, vec[@method] methods); - tag mod_index_entry { mie_view_item(@view_item); mie_item(@item); @@ -227,7 +226,10 @@ type _mod = rec(vec[@view_item] view_items, vec[@item] items, mod_index index); -type native_mod = rec(str native_name); +type native_mod = rec(str native_name, + vec[@native_item] items, + native_mod_index index); +type native_mod_index = hashmap[ident,@native_item]; type variant_arg = rec(@ty ty, def_id id); type variant = rec(str name, vec[variant_arg] args, def_id id, ann ann); @@ -249,6 +251,11 @@ tag item_ { item_obj(ident, _obj, vec[ty_param], def_id, ann); } +type native_item = spanned[native_item_]; +tag native_item_ { + native_item_ty(ident, def_id); +} + fn index_view_item(mod_index index, @view_item it) { alt (it.node) { case(ast.view_item_use(?id, _, _)) { @@ -292,6 +299,14 @@ fn index_item(mod_index index, @item it) { } } +fn index_native_item(native_mod_index index, @native_item it) { + alt (it.node) { + case (ast.native_item_ty(?id, _)) { + index.insert(id, it); + } + } +} + // // Local Variables: // mode: rust diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 16adfedb..c088e68d 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1577,6 +1577,39 @@ impure fn parse_item_mod(parser p) -> @ast.item { ret @spanned(lo, hi, item); } + +impure fn parse_item_native_type(parser p) -> @ast.native_item { + auto lo = p.get_span(); + expect(p, token.TYPE); + auto id = parse_ident(p); + auto hi = p.get_span(); + expect(p, token.SEMI); + auto item = ast.native_item_ty(id, p.next_def_id()); + ret @spanned(lo, hi, item); +} + +impure fn parse_native_item(parser p) -> @ast.native_item { + alt (p.peek()) { + case (token.TYPE) { + ret parse_item_native_type(p); + } + } +} + +impure fn parse_native_mod_items(parser p, + str native_name) -> ast.native_mod { + auto index = new_str_hash[@ast.native_item](); + let vec[@ast.native_item] items = vec(); + while (p.peek() != token.RBRACE) { + auto item = parse_native_item(p); + items += vec(item); + + // Index the item. + ast.index_native_item(index, item); + } + ret rec(native_name=native_name, items=items, index=index); +} + impure fn parse_item_native_mod(parser p) -> @ast.item { auto lo = p.get_span(); expect(p, token.NATIVE); @@ -1584,7 +1617,7 @@ impure fn parse_item_native_mod(parser p) -> @ast.item { expect(p, token.MOD); auto id = parse_ident(p); expect(p, token.LBRACE); - auto m = rec(native_name = native_name); + auto m = parse_native_mod_items(p, native_name); auto hi = p.get_span(); expect(p, token.RBRACE); auto item = ast.item_native_mod(id, m, p.next_def_id()); |