提交 4b06dc57 编写于 作者: R Rafael Ávila de Espíndola 提交者: Graydon Hoare

Add very minimal support for native modules. For now they must be empty.

上级 b3689e7c
......@@ -476,6 +476,7 @@ TEST_XFAILS_RUSTC := $(filter-out \
linear-for-loop.rs \
multiline-comment.rs \
mutual-recursion-group.rs \
native2.rs \
obj-drop.rs \
obj-recursion.rs \
obj-with-vec.rs \
......
......@@ -227,6 +227,8 @@
vec[@item] items,
mod_index index);
type native_mod = rec(str native_name);
type variant_arg = rec(@ty ty, def_id id);
type variant = rec(str name, vec[variant_arg] args, def_id id, ann ann);
......@@ -241,6 +243,7 @@
item_const(ident, @ty, @expr, def_id, ann);
item_fn(ident, _fn, vec[ty_param], def_id, ann);
item_mod(ident, _mod, def_id);
item_native_mod(ident, native_mod, def_id);
item_ty(ident, @ty, vec[ty_param], def_id, ann);
item_tag(ident, vec[variant], vec[ty_param], def_id);
item_obj(ident, _obj, vec[ty_param], def_id, ann);
......@@ -268,6 +271,9 @@ fn index_item(mod_index index, @item it) {
case (ast.item_mod(?id, _, _)) {
index.insert(id, ast.mie_item(it));
}
case (ast.item_native_mod(?id, _, _)) {
index.insert(id, ast.mie_item(it));
}
case (ast.item_ty(?id, _, _, _, _)) {
index.insert(id, ast.mie_item(it));
}
......
......@@ -1577,6 +1577,20 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
ret @spanned(lo, hi, item);
}
impure fn parse_item_native_mod(parser p) -> @ast.item {
auto lo = p.get_span();
expect(p, token.NATIVE);
auto native_name = parse_str_lit(p);
expect(p, token.MOD);
auto id = parse_ident(p);
expect(p, token.LBRACE);
auto m = rec(native_name = native_name);
auto hi = p.get_span();
expect(p, token.RBRACE);
auto item = ast.item_native_mod(id, m, p.next_def_id());
ret @spanned(lo, hi, item);
}
impure fn parse_item_type(parser p) -> @ast.item {
auto lo = p.get_span();
expect(p, token.TYPE);
......@@ -1717,6 +1731,11 @@ fn peeking_at_item(parser p) -> bool {
check (lyr == ast.layer_value);
ret parse_item_mod(p);
}
case (token.NATIVE) {
check (eff == ast.eff_pure);
check (lyr == ast.layer_value);
ret parse_item_native_mod(p);
}
case (token.TYPE) {
check (eff == ast.eff_pure);
ret parse_item_type(p);
......
......@@ -196,6 +196,9 @@
(fn(&ENV e, &span sp, ident ident,
&ast._mod m, def_id id) -> @item) fold_item_mod,
(fn(&ENV e, &span sp, ident ident,
&ast.native_mod m, def_id id) -> @item) fold_item_native_mod,
(fn(&ENV e, &span sp, ident ident,
@ty t, vec[ast.ty_param] ty_params,
def_id id, ann a) -> @item) fold_item_ty,
......@@ -229,6 +232,8 @@
(fn(&ENV e, &ast._mod m) -> ast._mod) fold_mod,
(fn(&ENV e, &ast.native_mod m) -> ast.native_mod) fold_native_mod,
(fn(&ENV e, &span sp,
&ast._mod m) -> @ast.crate) fold_crate,
......@@ -780,6 +785,11 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
ret fld.fold_item_mod(env_, i.span, ident, mm_, id);
}
case (ast.item_native_mod(?ident, ?mm, ?id)) {
let ast.native_mod mm_ = fold_native_mod[ENV](env_, fld, mm);
ret fld.fold_item_native_mod(env_, i.span, ident, mm_, id);
}
case (ast.item_ty(?ident, ?ty, ?params, ?id, ?ann)) {
let @ast.ty ty_ = fold_ty[ENV](env_, fld, ty);
ret fld.fold_item_ty(env_, i.span, ident, ty_, params, id, ann);
......@@ -810,7 +820,6 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
fail;
}
fn fold_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast._mod m) -> ast._mod {
let vec[@view_item] view_items = vec();
......@@ -830,7 +839,12 @@ fn fold_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast._mod m) -> ast._mod {
}
ret fld.fold_mod(e, rec(view_items=view_items, items=items, index=index));
}
}
fn fold_native_mod[ENV](&ENV e, ast_fold[ENV] fld,
&ast.native_mod m) -> ast.native_mod {
ret fld.fold_native_mod(e, rec(native_name = m.native_name));
}
fn fold_crate[ENV](&ENV env, ast_fold[ENV] fld, @ast.crate c) -> @ast.crate {
let ENV env_ = fld.update_env_for_crate(env, c);
......@@ -1105,6 +1119,11 @@ fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i,
ret @respan(sp, ast.item_mod(i, m, id));
}
fn identity_fold_item_native_mod[ENV](&ENV e, &span sp, ident i,
&ast.native_mod m, def_id id) -> @item {
ret @respan(sp, ast.item_native_mod(i, m, id));
}
fn identity_fold_item_ty[ENV](&ENV e, &span sp, ident i,
@ty t, vec[ast.ty_param] ty_params,
def_id id, ann a) -> @item {
......@@ -1159,6 +1178,11 @@ fn identity_fold_mod[ENV](&ENV e, &ast._mod m) -> ast._mod {
ret m;
}
fn identity_fold_native_mod[ENV](&ENV e,
&ast.native_mod m) -> ast.native_mod {
ret m;
}
fn identity_fold_crate[ENV](&ENV e, &span sp, &ast._mod m) -> @ast.crate {
ret @respan(sp, rec(module=m));
}
......@@ -1281,6 +1305,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
fold_item_const= bind identity_fold_item_const[ENV](_,_,_,_,_,_,_),
fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_,_),
fold_item_mod = bind identity_fold_item_mod[ENV](_,_,_,_,_),
fold_item_native_mod =
bind identity_fold_item_native_mod[ENV](_,_,_,_,_),
fold_item_ty = bind identity_fold_item_ty[ENV](_,_,_,_,_,_,_),
fold_item_tag = bind identity_fold_item_tag[ENV](_,_,_,_,_,_),
fold_item_obj = bind identity_fold_item_obj[ENV](_,_,_,_,_,_,_),
......@@ -1293,6 +1319,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
fold_block = bind identity_fold_block[ENV](_,_,_),
fold_fn = bind identity_fold_fn[ENV](_,_,_,_,_,_),
fold_mod = bind identity_fold_mod[ENV](_,_),
fold_native_mod = bind identity_fold_native_mod[ENV](_,_),
fold_crate = bind identity_fold_crate[ENV](_,_,_),
fold_obj = bind identity_fold_obj[ENV](_,_,_),
......
......@@ -376,6 +376,7 @@ fn ty_of_item(@ty_item_table id_to_ty_item,
}
case (ast.item_mod(_, _, _)) { fail; }
case (ast.item_native_mod(_, _, _)) { fail; }
}
}
......@@ -455,6 +456,9 @@ fn convert(&@env e, @ast.item i) -> @env {
case (ast.item_mod(_, _, _)) {
// ignore item_mod, it has no type.
}
case (ast.item_native_mod(_, _, _)) {
// ignore item_native_mod, it has no type.
}
case (_) {
// This call populates the ty_table with the converted type of
// the item in passing; we don't need to do anything else.
......
native "rust" mod rustrt {
}
fn main(vec[str] args) {
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册