about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2011-06-03 15:26:03 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-06-03 15:42:42 -0700
commit088ab03fdbdd2fad29b678f5eeaadde4e15cb205 (patch)
tree00a3a6b77754b9788cffe0bff534f2d6530f6dc2
parent8235e76a473f6c650ad6a96dca0b5ef84ebdac4a (diff)
downloadrust-088ab03fdbdd2fad29b678f5eeaadde4e15cb205.tar.gz
rust-088ab03fdbdd2fad29b678f5eeaadde4e15cb205.zip
Add spans to fields, args, methods. Improve pp of same.
-rw-r--r--src/comp/front/ast.rs10
-rw-r--r--src/comp/front/parser.rs20
-rw-r--r--src/comp/middle/typeck.rs20
-rw-r--r--src/comp/middle/walk.rs10
-rw-r--r--src/comp/pretty/pprust.rs18
5 files changed, 40 insertions, 38 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index 85e525e8823..92f12c3dc1b 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -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;
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index d7fecee6ca4..dbfdea89c21 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -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 {
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index e952908a6ba..b93e0765d0d 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -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);
             }
 
diff --git a/src/comp/middle/walk.rs b/src/comp/middle/walk.rs
index 76b027fd8f9..426f72d9bed 100644
--- a/src/comp/middle/walk.rs
+++ b/src/comp/middle/walk.rs
@@ -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, _)) {
diff --git a/src/comp/pretty/pprust.rs b/src/comp/pretty/pprust.rs
index f58c9fd45e4..dad990fe443 100644
--- a/src/comp/pretty/pprust.rs
+++ b/src/comp/pretty/pprust.rs
@@ -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);