aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarijn Haverbeke <[email protected]>2011-03-28 20:46:31 +0200
committerGraydon Hoare <[email protected]>2011-03-31 14:41:40 +0000
commitf8393cc572db5a18b9412324a7501fadb48f9944 (patch)
tree9ed9d5ce650bc6685b26b7ecec0be14589fd3515 /src
parentPreserve comments when pretty-printing. (diff)
downloadrust-f8393cc572db5a18b9412324a7501fadb48f9944.tar.xz
rust-f8393cc572db5a18b9412324a7501fadb48f9944.zip
Add effect field to ast.ty_fn.
Still not used, except by the pretty-printer.
Diffstat (limited to 'src')
-rw-r--r--src/comp/front/ast.rs5
-rw-r--r--src/comp/front/parser.rs23
-rw-r--r--src/comp/middle/fold.rs23
-rw-r--r--src/comp/middle/typeck.rs2
-rw-r--r--src/comp/pretty/pprust.rs13
5 files changed, 35 insertions, 31 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index 95a5cceb..450cc933 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -305,8 +305,7 @@ tag lit_ {
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 @@ tag ty_ {
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;
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index 82f7712f..3ee73576 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -184,7 +184,7 @@ impure fn parse_str_lit_or_env_ident(parser p) -> ast.ident {
}
-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 @@ impure fn parse_ty_fn(ast.proto proto, parser p,
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 @@ impure fn parse_ty_obj(parser p, &mutable ast.span hi) -> ast.ty_ {
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 @@ impure fn parse_ty(parser p) -> @ast.ty {
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 @@ impure fn parse_ty(parser p) -> @ast.ty {
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 @@ impure fn parse_ty(parser p) -> @ast.ty {
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;
}
}
diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs
index d805c3cb..66176d79 100644
--- a/src/comp/middle/fold.rs
+++ b/src/comp/middle/fold.rs
@@ -60,6 +60,7 @@ type ast_fold[ENV] =
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](_,_,_),
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index bf1b6c39..ff13ad93 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -337,7 +337,7 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
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));
diff --git a/src/comp/pretty/pprust.rs b/src/comp/pretty/pprust.rs
index ac5cec31..e7e2746c 100644
--- a/src/comp/pretty/pprust.rs
+++ b/src/comp/pretty/pprust.rs
@@ -127,7 +127,7 @@ impure fn print_type(ps s, &@ast.ty ty) {
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 @@ impure fn print_type(ps s, &@ast.ty ty) {
}
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 @@ impure fn print_string(ps s, str st) {
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) {