提交 f8393cc5 编写于 作者: M Marijn Haverbeke 提交者: Graydon Hoare

Add effect field to ast.ty_fn.

Still not used, except by the pretty-printer.
上级 e7e6f396
......@@ -305,8 +305,7 @@ fn unop_to_str(unop op) -> str {
type mt = rec(@ty ty, mutability mut);
type ty_field = rec(ident ident, mt mt);
type ty_arg = rec(mode mode, @ty ty);
// TODO: effect
type ty_method = rec(proto proto, ident ident,
type ty_method = rec(effect effect, proto proto, ident ident,
vec[ty_arg] inputs, @ty output);
type ty = spanned[ty_];
tag ty_ {
......@@ -324,7 +323,7 @@ fn unop_to_str(unop op) -> str {
ty_chan(@ty);
ty_tup(vec[mt]);
ty_rec(vec[ty_field]);
ty_fn(proto, vec[ty_arg], @ty); // TODO: effect
ty_fn(effect, proto, vec[ty_arg], @ty);
ty_obj(vec[ty_method]);
ty_path(path, option.t[def]);
ty_type;
......
......@@ -184,7 +184,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
}
impure fn parse_ty_fn(ast.proto proto, parser p,
impure fn parse_ty_fn(ast.effect eff, ast.proto proto, parser p,
ast.span lo) -> ast.ty_ {
impure fn parse_fn_input_ty(parser p) -> rec(ast.mode mode, @ast.ty ty) {
auto mode;
......@@ -228,7 +228,7 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
output = @spanned(lo, inputs.span, ast.ty_nil);
}
ret ast.ty_fn(proto, inputs.node, output);
ret ast.ty_fn(eff, proto, inputs.node, output);
}
impure fn parse_proto(parser p) -> ast.proto {
......@@ -245,15 +245,14 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
impure fn parse_method_sig(parser p) -> ast.ty_method {
auto flo = p.get_span();
// FIXME: do something with this, currently it's dropped on the floor.
let ast.effect eff = parse_effect(p);
let ast.proto proto = parse_proto(p);
auto ident = parse_ident(p);
auto f = parse_ty_fn(proto, p, flo);
auto f = parse_ty_fn(eff, proto, p, flo);
expect(p, token.SEMI);
alt (f) {
case (ast.ty_fn(?proto, ?inputs, ?output)) {
ret rec(proto=proto, ident=ident,
case (ast.ty_fn(?eff, ?proto, ?inputs, ?output)) {
ret rec(effect=eff, proto=proto, ident=ident,
inputs=inputs, output=output);
}
}
......@@ -342,9 +341,9 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
auto hi = lo;
let ast.ty_ t;
// FIXME: do something with these; currently they're
// dropped on the floor.
// FIXME: make sure these are only used when valid
let ast.effect eff = parse_effect(p);
// FIXME: do something with this
let ast.layer lyr = parse_layer(p);
alt (p.peek()) {
......@@ -412,9 +411,9 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
case (token.FN) {
auto flo = p.get_span();
p.bump();
t = parse_ty_fn(ast.proto_fn, p, flo);
t = parse_ty_fn(eff, ast.proto_fn, p, flo);
alt (t) {
case (ast.ty_fn(_, _, ?out)) {
case (ast.ty_fn(_, _, _, ?out)) {
hi = out.span;
}
}
......@@ -423,9 +422,9 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
case (token.ITER) {
auto flo = p.get_span();
p.bump();
t = parse_ty_fn(ast.proto_iter, p, flo);
t = parse_ty_fn(eff, ast.proto_iter, p, flo);
alt (t) {
case (ast.ty_fn(_, _, ?out)) {
case (ast.ty_fn(_, _, _, ?out)) {
hi = out.span;
}
}
......
......@@ -60,6 +60,7 @@
vec[ast.ty_method] meths) -> @ty) fold_ty_obj,
(fn(&ENV e, &span sp,
ast.effect eff,
ast.proto proto,
vec[rec(ast.mode mode, @ty ty)] inputs,
@ty output) -> @ty) fold_ty_fn,
......@@ -388,13 +389,13 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
case (ast.ty_obj(?meths)) {
let vec[ast.ty_method] meths_ = vec();
for (ast.ty_method m in meths) {
auto tfn = fold_ty_fn(env_, fld, t.span, m.proto,
auto tfn = fold_ty_fn(env_, fld, t.span, m.effect, m.proto,
m.inputs, m.output);
alt (tfn.node) {
case (ast.ty_fn(?p, ?ins, ?out)) {
case (ast.ty_fn(?eff, ?p, ?ins, ?out)) {
_vec.push[ast.ty_method]
(meths_, rec(proto=p, inputs=ins, output=out
with m));
(meths_, rec(effect=eff, proto=p, inputs=ins,
output=out with m));
}
}
}
......@@ -406,8 +407,8 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
ret fld.fold_ty_path(env_, t.span, pth_, ref_opt);
}
case (ast.ty_fn(?proto, ?inputs, ?output)) {
ret fold_ty_fn(env_, fld, t.span, proto, inputs, output);
case (ast.ty_fn(?eff, ?proto, ?inputs, ?output)) {
ret fold_ty_fn(env_, fld, t.span, eff, proto, inputs, output);
}
case (ast.ty_chan(?ty)) {
......@@ -423,7 +424,7 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
}
fn fold_ty_fn[ENV](&ENV env, ast_fold[ENV] fld, &span sp,
ast.proto proto,
ast.effect eff, ast.proto proto,
vec[rec(ast.mode mode, @ty ty)] inputs,
@ty output) -> @ty {
auto output_ = fold_ty(env, fld, output);
......@@ -433,7 +434,7 @@ fn fold_ty_fn[ENV](&ENV env, ast_fold[ENV] fld, &span sp,
auto input_ = rec(ty=ty_ with input);
inputs_ += vec(input_);
}
ret fld.fold_ty_fn(env, sp, proto, inputs_, output_);
ret fld.fold_ty_fn(env, sp, eff, proto, inputs_, output_);
}
fn fold_decl[ENV](&ENV env, ast_fold[ENV] fld, @decl d) -> @decl {
......@@ -1131,10 +1132,10 @@ fn identity_fold_ty_obj[ENV](&ENV env, &span sp,
}
fn identity_fold_ty_fn[ENV](&ENV env, &span sp,
ast.proto proto,
ast.effect eff, ast.proto proto,
vec[rec(ast.mode mode, @ty ty)] inputs,
@ty output) -> @ty {
ret @respan(sp, ast.ty_fn(proto, inputs, output));
ret @respan(sp, ast.ty_fn(eff, proto, inputs, output));
}
fn identity_fold_ty_path[ENV](&ENV env, &span sp, ast.path p,
......@@ -1569,7 +1570,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
fold_ty_tup = bind identity_fold_ty_tup[ENV](_,_,_),
fold_ty_rec = bind identity_fold_ty_rec[ENV](_,_,_),
fold_ty_obj = bind identity_fold_ty_obj[ENV](_,_,_),
fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_,_),
fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_,_,_),
fold_ty_path = bind identity_fold_ty_path[ENV](_,_,_,_),
fold_ty_chan = bind identity_fold_ty_chan[ENV](_,_,_),
fold_ty_port = bind identity_fold_ty_port[ENV](_,_,_),
......
......@@ -337,7 +337,7 @@ fn instantiate(ty_getter getter, ast.def_id id,
sty = ty.ty_rec(flds);
}
case (ast.ty_fn(?proto, ?inputs, ?output)) {
case (ast.ty_fn(_, ?proto, ?inputs, ?output)) {
auto f = bind ast_arg_to_arg(getter, _);
auto i = _vec.map[ast.ty_arg, arg](f, inputs);
sty = ty.ty_fn(proto, i, ast_ty_to_ty(getter, output));
......
......@@ -127,7 +127,7 @@ fn ty_to_str(&@ast.ty ty) -> str {
bopen(s);
for (ast.ty_method m in methods) {
hbox(s);
print_ty_fn(s, m.proto, option.some[str](m.ident),
print_ty_fn(s, m.effect, m.proto, option.some[str](m.ident),
m.inputs, m.output);
wrd(s.s, ";");
end(s.s);
......@@ -135,8 +135,8 @@ fn ty_to_str(&@ast.ty ty) -> str {
}
bclose_c(s, ty.span);
}
case (ast.ty_fn(?proto,?inputs,?output)) {
print_ty_fn(s, proto, option.none[str], inputs, output);
case (ast.ty_fn(?eff, ?proto,?inputs,?output)) {
print_ty_fn(s, eff, proto, option.none[str], inputs, output);
}
case (ast.ty_path(?path,_)) {
print_path(s, path);
......@@ -843,8 +843,13 @@ fn escape_str(str st, char to_escape) -> str {
wrd(s.s, "\""); wrd(s.s, escape_str(st, '"')); wrd(s.s, "\"");
}
impure fn print_ty_fn(ps s, ast.proto proto, option.t[str] id,
impure fn print_ty_fn(ps s, ast.effect eff, ast.proto proto, option.t[str] id,
vec[ast.ty_arg] inputs, @ast.ty output) {
alt (eff) {
case (ast.eff_impure) {wrd1(s, "impure");}
case (ast.eff_unsafe) {wrd1(s, "unsafe");}
case (_) {}
}
if (proto == ast.proto_fn) {wrd(s.s, "fn");}
else {wrd(s.s, "iter");}
alt (id) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册