Skip to content

Parse native moules names #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,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 \
Expand Down
4 changes: 2 additions & 2 deletions src/comp/front/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ type item = spanned[item_];
tag item_ {
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_mod(ident, _mod, str, 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);
Expand All @@ -264,7 +264,7 @@ fn index_item(mod_index index, @item it) {
case (ast.item_fn(?id, _, _, _, _)) {
index.insert(id, ast.mie_item(it));
}
case (ast.item_mod(?id, _, _)) {
case (ast.item_mod(?id, _, _, _)) {
index.insert(id, ast.mie_item(it));
}
case (ast.item_ty(?id, _, _, _, _)) {
Expand Down
21 changes: 15 additions & 6 deletions src/comp/front/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ fn index_block(vec[@ast.stmt] stmts, option.t[@ast.expr] expr) -> ast.block_ {
case (ast.item_fn(?i, _, _, _, _)) {
index.insert(i, u-1u);
}
case (ast.item_mod(?i, _, _)) {
case (ast.item_mod(?i, _, _, _)) {
index.insert(i, u-1u);
}
case (ast.item_ty(?i, _, _, _, _)) {
Expand Down Expand Up @@ -1543,15 +1543,15 @@ impure fn parse_item_const(parser p) -> @ast.item {
ret @spanned(lo, hi, item);
}

impure fn parse_item_mod(parser p) -> @ast.item {
impure fn parse_item_mod(parser p, str native_name) -> @ast.item {
auto lo = p.get_span();
expect(p, token.MOD);
auto id = parse_ident(p);
expect(p, token.LBRACE);
auto m = parse_mod_items(p, token.RBRACE);
auto hi = p.get_span();
expect(p, token.RBRACE);
auto item = ast.item_mod(id, m, p.next_def_id());
auto item = ast.item_mod(id, m, native_name, p.next_def_id());
ret @spanned(lo, hi, item);
}

Expand Down Expand Up @@ -1693,7 +1693,14 @@ impure fn parse_item(parser p) -> @ast.item {
case (token.MOD) {
check (eff == ast.eff_pure);
check (lyr == ast.layer_value);
ret parse_item_mod(p);
ret parse_item_mod(p, "");
}
case (token.NATIVE) {
check (eff == ast.eff_pure);
check (lyr == ast.layer_value);
p.bump();
auto native_name = parse_str_lit(p);
ret parse_item_mod(p, native_name);
}
case (token.TYPE) {
check (eff == ast.eff_pure);
Expand Down Expand Up @@ -1912,7 +1919,8 @@ impure fn parse_crate_directive(str prefix, parser p,
}
auto p0 = new_parser(p.get_session(), 0, full_path);
auto m0 = parse_mod_items(p0, token.EOF);
auto im = ast.item_mod(id, m0, p.next_def_id());
// FIXME: are these modules never native?
auto im = ast.item_mod(id, m0, "", p.next_def_id());
auto i = @spanned(lo, hi, im);
ast.index_item(index, i);
append[@ast.item](items, i);
Expand All @@ -1926,7 +1934,8 @@ impure fn parse_crate_directive(str prefix, parser p,
token.RBRACE);
hi = p.get_span();
expect(p, token.RBRACE);
auto im = ast.item_mod(id, m0, p.next_def_id());
// FIXME: are these modules never native?
auto im = ast.item_mod(id, m0, "", p.next_def_id());
auto i = @spanned(lo, hi, im);
ast.index_item(index, i);
append[@ast.item](items, i);
Expand Down
14 changes: 8 additions & 6 deletions src/comp/middle/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ type ast_fold[ENV] =
def_id id, ann a) -> @item) fold_item_fn,

(fn(&ENV e, &span sp, ident ident,
&ast._mod m, def_id id) -> @item) fold_item_mod,
&ast._mod m, str native_name,
def_id id) -> @item) fold_item_mod,

(fn(&ENV e, &span sp, ident ident,
@ty t, vec[ast.ty_param] ty_params,
Expand Down Expand Up @@ -763,9 +764,9 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
ret fld.fold_item_fn(env_, i.span, ident, ff_, tps, id, ann);
}

case (ast.item_mod(?ident, ?mm, ?id)) {
case (ast.item_mod(?ident, ?mm, ?n, ?id)) {
let ast._mod mm_ = fold_mod[ENV](env_, fld, mm);
ret fld.fold_item_mod(env_, i.span, ident, mm_, id);
ret fld.fold_item_mod(env_, i.span, ident, mm_, n, id);
}

case (ast.item_ty(?ident, ?ty, ?params, ?id, ?ann)) {
Expand Down Expand Up @@ -1088,8 +1089,9 @@ fn identity_fold_item_fn[ENV](&ENV e, &span sp, ident i,
}

fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i,
&ast._mod m, def_id id) -> @item {
ret @respan(sp, ast.item_mod(i, m, id));
&ast._mod m, str native_name,
def_id id) -> @item {
ret @respan(sp, ast.item_mod(i, m, native_name, id));
}

fn identity_fold_item_ty[ENV](&ENV e, &span sp, ident i,
Expand Down Expand Up @@ -1267,7 +1269,7 @@ 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_mod = bind identity_fold_item_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](_,_,_,_,_,_,_),
Expand Down
6 changes: 3 additions & 3 deletions src/comp/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn unwrap_def(def_wrap d) -> def {
}
case (def_wrap_mod(?m)) {
alt (m.node) {
case (ast.item_mod(_, _, ?id)) {
case (ast.item_mod(_, _, _, ?id)) {
ret ast.def_mod(id);
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
case (ast.item_fn(_, _, _, ?id, _)) {
ret def_wrap_other(ast.def_fn(id));
}
case (ast.item_mod(_, _, ?id)) {
case (ast.item_mod(_, _, _, ?id)) {
ret def_wrap_mod(i);
}
case (ast.item_ty(_, _, _, ?id, _)) {
Expand Down Expand Up @@ -310,7 +310,7 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
}
}
}
case (ast.item_mod(_, ?m, _)) {
case (ast.item_mod(_, ?m, _, _)) {
ret check_mod(i, m);
}
case (ast.item_ty(_, _, ?ty_params, _, _)) {
Expand Down
4 changes: 2 additions & 2 deletions src/comp/middle/trans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3751,7 +3751,7 @@ fn trans_item(@crate_ctxt cx, &ast.item item) {
obj_fields=ob.fields with *cx);
trans_obj(sub_cx, ob, oid, tps, ann);
}
case (ast.item_mod(?name, ?m, _)) {
case (ast.item_mod(?name, ?m, _, _)) {
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
trans_mod(sub_cx, m);
}
Expand Down Expand Up @@ -3838,7 +3838,7 @@ fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
cx.items.insert(cid, i);
}

case (ast.item_mod(?name, ?m, ?mid)) {
case (ast.item_mod(?name, ?m, _, ?mid)) {
cx.items.insert(mid, i);
}

Expand Down
2 changes: 1 addition & 1 deletion src/comp/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ fn item_ty(@ast.item it) -> ty_params_and_ty {
ty_params = tps;
result_ty = ann_to_type(ann);
}
case (ast.item_mod(_, _, _)) {
case (ast.item_mod(_, _, _, _)) {
fail; // modules are typeless
}
case (ast.item_ty(_, _, ?tps, _, ?ann)) {
Expand Down
4 changes: 2 additions & 2 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
ret t;
}

case (ast.item_mod(_, _, _)) { fail; }
case (ast.item_mod(_, _, _, _)) { fail; }
}
}

Expand Down Expand Up @@ -452,7 +452,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)

fn convert(&@env e, @ast.item i) -> @env {
alt (i.node) {
case (ast.item_mod(_, _, _)) {
case (ast.item_mod(_, _, _, _)) {
// ignore item_mod, it has no type.
}
case (_) {
Expand Down
5 changes: 5 additions & 0 deletions src/test/run-pass/native2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
native "rust" mod rustrt {
}

fn main(vec[str] args) {
}