rustc: Add an annotation to function and type items so that the typechecker can store types with them
This commit is contained in:
parent
d1e7f0b414
commit
c3bc88a325
@ -149,9 +149,9 @@ type _mod = rec(vec[@item] items,
|
||||
|
||||
type item = spanned[item_];
|
||||
tag item_ {
|
||||
item_fn(ident, _fn, def_id);
|
||||
item_fn(ident, _fn, def_id, ann);
|
||||
item_mod(ident, _mod, def_id);
|
||||
item_ty(ident, @ty, def_id);
|
||||
item_ty(ident, @ty, def_id, ann);
|
||||
}
|
||||
|
||||
|
||||
|
@ -868,13 +868,13 @@ impure fn parse_block(parser p) -> ast.block {
|
||||
}
|
||||
case (ast.decl_item(?it)) {
|
||||
alt (it.node) {
|
||||
case (ast.item_fn(?i, _, _)) {
|
||||
case (ast.item_fn(?i, _, _, _)) {
|
||||
index.insert(i, u-1u);
|
||||
}
|
||||
case (ast.item_mod(?i, _, _)) {
|
||||
index.insert(i, u-1u);
|
||||
}
|
||||
case (ast.item_ty(?i, _, _)) {
|
||||
case (ast.item_ty(?i, _, _, _)) {
|
||||
index.insert(i, u-1u);
|
||||
}
|
||||
}
|
||||
@ -915,7 +915,7 @@ impure fn parse_fn(parser p) -> tup(ast.ident, @ast.item) {
|
||||
output = output,
|
||||
body = body);
|
||||
|
||||
auto item = ast.item_fn(id, f, p.next_def_id());
|
||||
auto item = ast.item_fn(id, f, p.next_def_id(), ast.ann_none);
|
||||
ret tup(id, @spanned(lo, body.span, item));
|
||||
}
|
||||
|
||||
|
@ -140,13 +140,13 @@ type ast_fold[ENV] =
|
||||
|
||||
// Item folds.
|
||||
(fn(&ENV e, &span sp, ident ident,
|
||||
&ast._fn f, def_id id) -> @item) fold_item_fn,
|
||||
&ast._fn f, 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,
|
||||
|
||||
(fn(&ENV e, &span sp, ident ident,
|
||||
@ty t, def_id id) -> @item) fold_item_ty,
|
||||
@ty t, def_id id, ann a) -> @item) fold_item_ty,
|
||||
|
||||
// Additional nodes.
|
||||
(fn(&ENV e, &span sp,
|
||||
@ -481,9 +481,9 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
|
||||
|
||||
alt (i.node) {
|
||||
|
||||
case (ast.item_fn(?ident, ?ff, ?id)) {
|
||||
case (ast.item_fn(?ident, ?ff, ?id, ?ann)) {
|
||||
let ast._fn ff_ = fold_fn[ENV](env_, fld, ff);
|
||||
ret fld.fold_item_fn(env_, i.span, ident, ff_, id);
|
||||
ret fld.fold_item_fn(env_, i.span, ident, ff_, id, ann);
|
||||
}
|
||||
|
||||
case (ast.item_mod(?ident, ?mm, ?id)) {
|
||||
@ -491,9 +491,9 @@ 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_ty(?ident, ?ty, ?id)) {
|
||||
case (ast.item_ty(?ident, ?ty, ?id, ?ann)) {
|
||||
let @ast.ty ty_ = fold_ty[ENV](env_, fld, ty);
|
||||
ret fld.fold_item_ty(env_, i.span, ident, ty_, id);
|
||||
ret fld.fold_item_ty(env_, i.span, ident, ty_, id, ann);
|
||||
}
|
||||
}
|
||||
|
||||
@ -709,8 +709,8 @@ fn identity_fold_stmt_expr[ENV](&ENV e, &span sp, @expr x) -> @stmt {
|
||||
// Item identities.
|
||||
|
||||
fn identity_fold_item_fn[ENV](&ENV e, &span sp, ident i,
|
||||
&ast._fn f, def_id id) -> @item {
|
||||
ret @respan(sp, ast.item_fn(i, f, id));
|
||||
&ast._fn f, def_id id, ann a) -> @item {
|
||||
ret @respan(sp, ast.item_fn(i, f, id, a));
|
||||
}
|
||||
|
||||
fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i,
|
||||
@ -719,8 +719,8 @@ fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i,
|
||||
}
|
||||
|
||||
fn identity_fold_item_ty[ENV](&ENV e, &span sp, ident i,
|
||||
@ty t, def_id id) -> @item {
|
||||
ret @respan(sp, ast.item_ty(i, t, id));
|
||||
@ty t, def_id id, ann a) -> @item {
|
||||
ret @respan(sp, ast.item_ty(i, t, id, a));
|
||||
}
|
||||
|
||||
|
||||
@ -829,9 +829,9 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
|
||||
= bind identity_fold_stmt_check_expr[ENV](_,_,_),
|
||||
fold_stmt_expr = bind identity_fold_stmt_expr[ENV](_,_,_),
|
||||
|
||||
fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_),
|
||||
fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_),
|
||||
fold_item_mod = bind identity_fold_item_mod[ENV](_,_,_,_,_),
|
||||
fold_item_ty = bind identity_fold_item_ty[ENV](_,_,_,_,_),
|
||||
fold_item_ty = bind identity_fold_item_ty[ENV](_,_,_,_,_,_),
|
||||
|
||||
fold_block = bind identity_fold_block[ENV](_,_,_),
|
||||
fold_fn = bind identity_fold_fn[ENV](_,_,_,_),
|
||||
|
@ -28,13 +28,13 @@ fn lookup_name(&env e, ast.ident i) -> option.t[def] {
|
||||
|
||||
fn found_def_item(@ast.item i) -> option.t[def] {
|
||||
alt (i.node) {
|
||||
case (ast.item_fn(_, _, ?id)) {
|
||||
case (ast.item_fn(_, _, ?id, _)) {
|
||||
ret some[def](ast.def_fn(id));
|
||||
}
|
||||
case (ast.item_mod(_, _, ?id)) {
|
||||
ret some[def](ast.def_mod(id));
|
||||
}
|
||||
case (ast.item_ty(_, _, ?id)) {
|
||||
case (ast.item_ty(_, _, ?id, _)) {
|
||||
ret some[def](ast.def_ty(id));
|
||||
}
|
||||
}
|
||||
@ -75,7 +75,7 @@ fn lookup_name(&env e, ast.ident i) -> option.t[def] {
|
||||
|
||||
case (scope_item(?it)) {
|
||||
alt (it.node) {
|
||||
case (ast.item_fn(_, ?f, _)) {
|
||||
case (ast.item_fn(_, ?f, _, _)) {
|
||||
for (ast.arg a in f.inputs) {
|
||||
if (_str.eq(a.ident, i)) {
|
||||
ret some[def](ast.def_arg(a.id));
|
||||
|
@ -914,7 +914,7 @@ impure fn trans_expr(@block_ctxt cx, &ast.expr e) -> result {
|
||||
// perhaps to pick a more tasteful one.
|
||||
auto outptr = cx.fcx.lloutptr;
|
||||
alt (cx.fcx.tcx.items.get(f_res._2).node) {
|
||||
case (ast.item_fn(_, ?ff, _)) {
|
||||
case (ast.item_fn(_, ?ff, _, _)) {
|
||||
outptr = cx.build.Alloca(type_of(cx.fcx.tcx, ff.output));
|
||||
}
|
||||
}
|
||||
@ -1182,7 +1182,7 @@ impure fn trans_fn(@trans_ctxt cx, &ast._fn f, ast.def_id fid) {
|
||||
|
||||
impure fn trans_item(@trans_ctxt cx, &ast.item item) {
|
||||
alt (item.node) {
|
||||
case (ast.item_fn(?name, ?f, ?fid)) {
|
||||
case (ast.item_fn(?name, ?f, ?fid, _)) {
|
||||
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
|
||||
trans_fn(sub_cx, f, fid);
|
||||
}
|
||||
@ -1202,7 +1202,7 @@ impure fn trans_mod(@trans_ctxt cx, &ast._mod m) {
|
||||
|
||||
fn collect_item(&@trans_ctxt cx, @ast.item i) -> @trans_ctxt {
|
||||
alt (i.node) {
|
||||
case (ast.item_fn(?name, ?f, ?fid)) {
|
||||
case (ast.item_fn(?name, ?f, ?fid, _)) {
|
||||
cx.items.insert(fid, i);
|
||||
let vec[TypeRef] args =
|
||||
vec(T_ptr(type_of(cx, f.output)), // outptr.
|
||||
|
Loading…
Reference in New Issue
Block a user