about summary refs log tree commit diff
path: root/src/comp/syntax
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2012-01-30 11:43:45 -0800
committerBrian Anderson <banderson@mozilla.com>2012-01-30 11:43:45 -0800
commit0e498da47e265b5bb7a4f59bbed53bc843bd83cc (patch)
treefaa59e85a242835d965df27778221b19aa4db5ad /src/comp/syntax
parent6ba3d2435556ae4ea72eeb6095e95b5c14a3c1f7 (diff)
downloadrust-0e498da47e265b5bb7a4f59bbed53bc843bd83cc.tar.gz
rust-0e498da47e265b5bb7a4f59bbed53bc843bd83cc.zip
rustc: Allow attributes on methods. Closes #1709
Diffstat (limited to 'src/comp/syntax')
-rw-r--r--src/comp/syntax/ast.rs6
-rw-r--r--src/comp/syntax/parse/parser.rs9
-rw-r--r--src/comp/syntax/print/pprust.rs7
3 files changed, 14 insertions, 8 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs
index ee93a3e0e29..1436f9b08f4 100644
--- a/src/comp/syntax/ast.rs
+++ b/src/comp/syntax/ast.rs
@@ -299,7 +299,8 @@ type ty_field_ = {ident: ident, mt: mt};
 
 type ty_field = spanned<ty_field_>;
 
-type ty_method = {ident: ident, decl: fn_decl, tps: [ty_param], span: span};
+type ty_method = {ident: ident, attrs: [attribute],
+                  decl: fn_decl, tps: [ty_param], span: span};
 
 enum int_ty { ty_i, ty_char, ty_i8, ty_i16, ty_i32, ty_i64, }
 
@@ -399,7 +400,8 @@ enum ret_style {
     return_val, // everything else
 }
 
-type method = {ident: ident, tps: [ty_param], decl: fn_decl, body: blk,
+type method = {ident: ident, attrs: [attribute],
+               tps: [ty_param], decl: fn_decl, body: blk,
                id: node_id, span: span};
 
 type _mod = {view_items: [@view_item], items: [@item]};
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 272d65707dd..1c81eda7df5 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -282,6 +282,7 @@ fn parse_ty_fn(proto: ast::proto, p: parser) -> ast::ty_ {
 
 fn parse_ty_methods(p: parser) -> [ast::ty_method] {
     parse_seq(token::LBRACE, token::RBRACE, seq_sep_none(), {|p|
+        let attrs = parse_outer_attributes(p);
         let flo = p.span.lo;
         expect_word(p, "fn");
         let ident = parse_method_name(p);
@@ -290,7 +291,7 @@ fn parse_ty_methods(p: parser) -> [ast::ty_method] {
         expect(p, token::SEMI);
         alt f {
           ast::ty_fn(_, d) {
-            {ident: ident, decl: d, tps: tps,
+            {ident: ident, attrs: attrs, decl: d, tps: tps,
              span: ast_util::mk_sp(flo, fhi)}
           }
         }
@@ -1849,13 +1850,15 @@ fn parse_method_name(p: parser) -> ast::ident {
 }
 
 fn parse_method(p: parser) -> @ast::method {
+    let attrs = parse_outer_attributes(p);
     let lo = p.span.lo;
     expect_word(p, "fn");
     let ident = parse_method_name(p);
     let tps = parse_ty_params(p);
     let decl = parse_fn_decl(p, ast::impure_fn);
-    let body = parse_block(p);
-    @{ident: ident, tps: tps, decl: decl, body: body,
+    let (inner_attrs, body) = parse_inner_attrs_and_block(p, true);
+    let attrs = attrs + inner_attrs;
+    @{ident: ident, attrs: attrs, tps: tps, decl: decl, body: body,
       id: p.get_id(), span: ast_util::mk_sp(lo, body.span.hi)}
 }
 
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index 94095b6ab40..c361beb21ce 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -510,9 +510,10 @@ fn print_item(s: ps, &&item: @ast::item) {
         for meth in methods {
             hardbreak_if_not_bol(s);
             maybe_print_comment(s, meth.span.lo);
+            print_outer_attributes(s, meth.attrs);
             print_fn(s, meth.decl, meth.ident, meth.tps);
             word(s.s, " ");
-            print_block(s, meth.body);
+            print_block_with_attrs(s, meth.body, meth.attrs);
         }
         bclose(s, item.span);
       }
@@ -520,6 +521,7 @@ fn print_item(s: ps, &&item: @ast::item) {
         head(s, "iface");
         word(s.s, item.ident);
         print_type_params(s, tps);
+        word(s.s, " ");
         bopen(s);
         for meth in methods { print_ty_method(s, meth); }
         bclose(s, item.span);
@@ -566,11 +568,10 @@ fn print_variant(s: ps, v: ast::variant) {
 
 fn print_ty_method(s: ps, m: ast::ty_method) {
     hardbreak_if_not_bol(s);
-    cbox(s, indent_unit);
     maybe_print_comment(s, m.span.lo);
+    print_outer_attributes(s, m.attrs);
     print_ty_fn(s, none, m.decl, some(m.ident), some(m.tps));
     word(s.s, ";");
-    end(s);
 }
 
 fn print_outer_attributes(s: ps, attrs: [ast::attribute]) {