Add spans to fields, args, methods. Improve pp of same.
This commit is contained in:
parent
8235e76a47
commit
088ab03fdb
5 changed files with 40 additions and 38 deletions
|
@ -300,11 +300,15 @@ tag lit_ {
|
|||
// type structure in middle/ty.rs as well.
|
||||
|
||||
type mt = rec(@ty ty, mutability mut);
|
||||
type ty_field = rec(ident ident, mt mt);
|
||||
type ty_arg = rec(mode mode, @ty ty);
|
||||
type ty_method = rec(proto proto, ident ident,
|
||||
type ty_field_ = rec(ident ident, mt mt);
|
||||
type ty_arg_ = rec(mode mode, @ty ty);
|
||||
type ty_method_ = rec(proto proto, ident ident,
|
||||
vec[ty_arg] inputs, @ty output,
|
||||
controlflow cf);
|
||||
type ty_field = spanned[ty_field_];
|
||||
type ty_arg = spanned[ty_arg_];
|
||||
type ty_method = spanned[ty_method_];
|
||||
|
||||
type ty = spanned[ty_];
|
||||
tag ty_ {
|
||||
ty_nil;
|
||||
|
|
|
@ -287,7 +287,6 @@ fn eat_word(&parser p, &str word) -> bool {
|
|||
p.bump();
|
||||
ret true;
|
||||
} else { ret false; }
|
||||
|
||||
}
|
||||
case (_) { ret false; }
|
||||
}
|
||||
|
@ -312,7 +311,8 @@ fn check_bad_word(&parser p) {
|
|||
|
||||
fn parse_ty_fn(ast::proto proto, &parser p, uint lo)
|
||||
-> ast::ty_ {
|
||||
fn parse_fn_input_ty(&parser p) -> rec(ast::mode mode, @ast::ty ty) {
|
||||
fn parse_fn_input_ty(&parser p) -> ast::ty_arg {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto mode;
|
||||
if (p.peek() == token::BINOP(token::AND)) {
|
||||
p.bump();
|
||||
|
@ -332,14 +332,12 @@ fn parse_ty_fn(ast::proto proto, &parser p, uint lo)
|
|||
case (_) { /* no param name present */ }
|
||||
}
|
||||
|
||||
ret rec(mode=mode, ty=t);
|
||||
ret spanned(lo, t.span.hi, rec(mode=mode, ty=t));
|
||||
}
|
||||
|
||||
auto lo = p.get_lo_pos();
|
||||
|
||||
auto f = parse_fn_input_ty; // FIXME: trans_const_lval bug
|
||||
auto inputs = parse_seq[rec(ast::mode mode, @ast::ty ty)](token::LPAREN,
|
||||
token::RPAREN, some(token::COMMA), f, p);
|
||||
auto inputs = parse_seq(token::LPAREN, token::RPAREN,
|
||||
some(token::COMMA), parse_fn_input_ty, p);
|
||||
|
||||
// FIXME: dropping constrs on the floor at the moment.
|
||||
// pick them up when they're used by typestate pass.
|
||||
|
@ -383,8 +381,9 @@ fn parse_ty_obj(&parser p, &mutable uint hi) -> ast::ty_ {
|
|||
expect(p, token::SEMI);
|
||||
alt (f) {
|
||||
case (ast::ty_fn(?proto, ?inputs, ?output, ?cf)) {
|
||||
ret rec(proto=proto, ident=ident,
|
||||
inputs=inputs, output=output, cf=cf);
|
||||
ret spanned(flo, output.span.hi,
|
||||
rec(proto=proto, ident=ident,
|
||||
inputs=inputs, output=output, cf=cf));
|
||||
}
|
||||
}
|
||||
fail;
|
||||
|
@ -405,9 +404,10 @@ fn parse_mt(&parser p) -> ast::mt {
|
|||
}
|
||||
|
||||
fn parse_ty_field(&parser p) -> ast::ty_field {
|
||||
auto lo = p.get_lo_pos();
|
||||
auto mt = parse_mt(p);
|
||||
auto id = parse_ident(p);
|
||||
ret rec(ident=id, mt=mt);
|
||||
ret spanned(lo, mt.ty.span.hi, rec(ident=id, mt=mt));
|
||||
}
|
||||
|
||||
fn parse_constr_arg(&parser p) -> @ast::constr_arg {
|
||||
|
|
|
@ -229,10 +229,10 @@ fn ast_mode_to_mode(ast::mode mode) -> ty::mode {
|
|||
fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
|
||||
fn ast_arg_to_arg(&ty::ctxt tcx,
|
||||
&ty_getter getter,
|
||||
&rec(ast::mode mode, @ast::ty ty) arg)
|
||||
&ast::ty_arg arg)
|
||||
-> rec(ty::mode mode, ty::t ty) {
|
||||
auto ty_mode = ast_mode_to_mode(arg.mode);
|
||||
ret rec(mode=ty_mode, ty=ast_ty_to_ty(tcx, getter, arg.ty));
|
||||
auto ty_mode = ast_mode_to_mode(arg.node.mode);
|
||||
ret rec(mode=ty_mode, ty=ast_ty_to_ty(tcx, getter, arg.node.ty));
|
||||
}
|
||||
|
||||
fn ast_mt_to_mt(&ty::ctxt tcx,
|
||||
|
@ -306,8 +306,8 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
|
|||
case (ast::ty_rec(?fields)) {
|
||||
let vec[field] flds = [];
|
||||
for (ast::ty_field f in fields) {
|
||||
auto tm = ast_mt_to_mt(tcx, getter, f.mt);
|
||||
vec::push[field](flds, rec(ident=f.ident, mt=tm));
|
||||
auto tm = ast_mt_to_mt(tcx, getter, f.node.mt);
|
||||
vec::push[field](flds, rec(ident=f.node.ident, mt=tm));
|
||||
}
|
||||
typ = ty::mk_rec(tcx, flds);
|
||||
}
|
||||
|
@ -342,14 +342,14 @@ fn ast_ty_to_ty(&ty::ctxt tcx, &ty_getter getter, &@ast::ty ast_ty) -> ty::t {
|
|||
let vec[ty::method] tmeths = [];
|
||||
auto f = bind ast_arg_to_arg(tcx, getter, _);
|
||||
for (ast::ty_method m in meths) {
|
||||
auto ins = vec::map[ast::ty_arg, arg](f, m.inputs);
|
||||
auto out = ast_ty_to_ty(tcx, getter, m.output);
|
||||
auto ins = vec::map[ast::ty_arg, arg](f, m.node.inputs);
|
||||
auto out = ast_ty_to_ty(tcx, getter, m.node.output);
|
||||
let ty::method new_m =
|
||||
rec(proto=m.proto,
|
||||
ident=m.ident,
|
||||
rec(proto=m.node.proto,
|
||||
ident=m.node.ident,
|
||||
inputs=ins,
|
||||
output=out,
|
||||
cf=m.cf);
|
||||
cf=m.node.cf);
|
||||
vec::push[ty::method](tmeths, new_m);
|
||||
}
|
||||
|
||||
|
|
|
@ -167,21 +167,21 @@ fn walk_ty(&ast_visitor v, @ast::ty t) {
|
|||
}
|
||||
case (ast::ty_rec(?flds)) {
|
||||
for (ast::ty_field f in flds) {
|
||||
walk_ty(v, f.mt.ty);
|
||||
walk_ty(v, f.node.mt.ty);
|
||||
}
|
||||
}
|
||||
case (ast::ty_fn(_, ?args, ?out, _)) {
|
||||
for (ast::ty_arg a in args) {
|
||||
walk_ty(v, a.ty);
|
||||
walk_ty(v, a.node.ty);
|
||||
}
|
||||
walk_ty(v, out);
|
||||
}
|
||||
case (ast::ty_obj(?tmeths)) {
|
||||
for (ast::ty_method m in tmeths) {
|
||||
for (ast::ty_arg a in m.inputs) {
|
||||
walk_ty(v, a.ty);
|
||||
for (ast::ty_arg a in m.node.inputs) {
|
||||
walk_ty(v, a.node.ty);
|
||||
}
|
||||
walk_ty(v, m.output);
|
||||
walk_ty(v, m.node.output);
|
||||
}
|
||||
}
|
||||
case (ast::ty_path(?p, _)) {
|
||||
|
|
|
@ -268,16 +268,13 @@ fn print_type(&ps s, &ast::ty ty) {
|
|||
popen(s);
|
||||
fn print_field(&ps s, &ast::ty_field f) {
|
||||
cbox(s, indent_unit);
|
||||
print_mt(s, f.mt);
|
||||
print_mt(s, f.node.mt);
|
||||
space(s.s);
|
||||
word(s.s, f.ident);
|
||||
word(s.s, f.node.ident);
|
||||
end(s);
|
||||
}
|
||||
fn get_span(&ast::ty_field f) -> common::span {
|
||||
// Try to reconstruct the span for this field
|
||||
auto sp = f.mt.ty.span;
|
||||
auto hi = sp.hi + str::char_len(f.ident) + 1u;
|
||||
ret rec(hi=hi with sp);
|
||||
ret f.span;
|
||||
}
|
||||
auto f = print_field;
|
||||
auto gs = get_span;
|
||||
|
@ -290,8 +287,9 @@ fn print_type(&ps s, &ast::ty ty) {
|
|||
for (ast::ty_method m in methods) {
|
||||
hardbreak(s.s);
|
||||
cbox(s, indent_unit);
|
||||
print_ty_fn(s, m.proto, some(m.ident),
|
||||
m.inputs, m.output, m.cf);
|
||||
maybe_print_comment(s, m.span.lo);
|
||||
print_ty_fn(s, m.node.proto, some(m.node.ident),
|
||||
m.node.inputs, m.node.output, m.node.cf);
|
||||
word(s.s, ";");
|
||||
end(s);
|
||||
}
|
||||
|
@ -1217,8 +1215,8 @@ fn print_ty_fn(&ps s, &ast::proto proto, &option::t[str] id,
|
|||
zerobreak(s.s);
|
||||
popen(s);
|
||||
fn print_arg(&ps s, &ast::ty_arg input) {
|
||||
if (input.mode == ast::alias) {word(s.s, "&");}
|
||||
print_type(s, *input.ty);
|
||||
if (input.node.mode == ast::alias) {word(s.s, "&");}
|
||||
print_type(s, *input.node.ty);
|
||||
}
|
||||
auto f = print_arg;
|
||||
commasep[ast::ty_arg](s, inconsistent, inputs, f);
|
||||
|
|
Loading…
Add table
Reference in a new issue