about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2011-06-14 18:53:12 -0700
committerBrian Anderson <banderson@mozilla.com>2011-06-15 09:48:59 -0700
commitdf6ec4f8ea4bc9d56ec87a2410779dcd47221f79 (patch)
treeb9c58557ced5b599ebe6cd3bff5d4715bfa5b8ec /src/comp
parent6c6d7c3916fade4549caf4dd9380d23fc3d3d040 (diff)
downloadrust-df6ec4f8ea4bc9d56ec87a2410779dcd47221f79.tar.gz
rust-df6ec4f8ea4bc9d56ec87a2410779dcd47221f79.zip
rustc: Pretty-print outer attributes of items
Issue #487
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/pretty/pprust.rs62
1 files changed, 47 insertions, 15 deletions
diff --git a/src/comp/pretty/pprust.rs b/src/comp/pretty/pprust.rs
index 5f2b6458998..e8c960fc634 100644
--- a/src/comp/pretty/pprust.rs
+++ b/src/comp/pretty/pprust.rs
@@ -257,7 +257,8 @@ fn print_item(&ps s, &@ast::item item) {
     hardbreak(s.s);
     maybe_print_comment(s, item.span.lo);
     alt (item.node) {
-        case (ast::item_const(?id, ?ty, ?expr, _, _, _)) {
+        case (ast::item_const(?id, ?ty, ?expr, ?attrs, _, _)) {
+            print_outer_attributes(s, attrs);
             head(s, "const");
             print_type(s, *ty);
             space(s.s);
@@ -268,19 +269,22 @@ fn print_item(&ps s, &@ast::item item) {
             word(s.s, ";");
             end(s); // end the outer cbox
         }
-        case (ast::item_fn(?name,?_fn,?typarams,_,_,_)) {
+        case (ast::item_fn(?name,?_fn,?typarams,?attrs,_,_)) {
+            print_outer_attributes(s, attrs);
             print_fn(s, _fn.decl, _fn.proto, name, typarams);
             word(s.s, " ");
             print_block(s, _fn.body);
         }
-        case (ast::item_mod(?id,?_mod,_,_)) {
+        case (ast::item_mod(?id,?_mod,?attrs,_)) {
+            print_outer_attributes(s, attrs);
             head(s, "mod");
             word_nbsp(s, id);
             bopen(s);
             for (@ast::item itm in _mod.items) {print_item(s, itm);}
             bclose(s, item.span);
         }
-        case (ast::item_native_mod(?id,?nmod,_,_)) {
+        case (ast::item_native_mod(?id,?nmod,?attrs,_)) {
+            print_outer_attributes(s, attrs);
             head(s, "native");
             alt (nmod.abi) {
                 case (ast::native_abi_rust) {word_nbsp(s, "\"rust\"");}
@@ -317,7 +321,8 @@ fn print_item(&ps s, &@ast::item item) {
             }
             bclose(s, item.span);
         }
-        case (ast::item_ty(?id,?ty,?params,_,_,_)) {
+        case (ast::item_ty(?id,?ty,?params,?attrs,_,_)) {
+            print_outer_attributes(s, attrs);
             ibox(s, indent_unit);
             ibox(s, 0u);
             word_nbsp(s, "type");
@@ -331,7 +336,8 @@ fn print_item(&ps s, &@ast::item item) {
             end(s); // end the outer ibox
             break_offset(s.s, 0u, 0);
         }
-        case (ast::item_tag(?id,?variants,?params,_,_,_)) {
+        case (ast::item_tag(?id,?variants,?params,?attrs,_,_)) {
+            print_outer_attributes(s, attrs);
             head(s, "tag");
             word(s.s, id);
             print_type_params(s, params);
@@ -354,7 +360,8 @@ fn print_item(&ps s, &@ast::item item) {
             }
             bclose(s, item.span);
         }
-        case (ast::item_obj(?id,?_obj,?params,_,_,_)) {
+        case (ast::item_obj(?id,?_obj,?params,?attrs,_,_)) {
+            print_outer_attributes(s, attrs);
             head(s, "obj");
             word(s.s, id);
             print_type_params(s, params);
@@ -401,6 +408,30 @@ fn print_item(&ps s, &@ast::item item) {
     }
 }
 
+fn print_outer_attributes(&ps s, vec[ast::attribute] attrs) {
+    auto count = 0;
+    for (ast::attribute attr in attrs) {
+        alt (attr.node.style) {
+            case (ast::attr_outer) {
+                print_attribute(s, attr);
+                count += 1;
+            }
+            case (_) { /* fallthrough */ }
+        }
+    }
+    if (count > 0) {
+        hardbreak(s.s);
+    }
+}
+
+fn print_attribute(&ps s, &ast::attribute attr) {
+    hardbreak(s.s);
+    maybe_print_comment(s, attr.span.lo);
+    word(s.s, "#[");
+    print_meta_item(s, @attr.node.value);
+    word(s.s, "]");
+}
+
 fn print_stmt(&ps s, &ast::stmt st) {
     maybe_print_comment(s, st.span.lo);
     alt (st.node) {
@@ -987,6 +1018,14 @@ fn print_type_params(&ps s, &vec[ast::ty_param] params) {
     }
 }
 
+fn print_meta_item(&ps s, &@ast::meta_item item) {
+    ibox(s, indent_unit);
+    word_space(s, item.node.key);
+    word_space(s, "=");
+    print_string(s, item.node.value);
+    end(s);
+}
+
 fn print_view_item(&ps s, &@ast::view_item item) {
     hardbreak(s.s);
     maybe_print_comment(s, item.span.lo);
@@ -996,14 +1035,7 @@ fn print_view_item(&ps s, &@ast::view_item item) {
             word(s.s, id);
             if (vec::len(mta) > 0u) {
                 popen(s);
-                fn print_meta(&ps s, &@ast::meta_item item) {
-                    ibox(s, indent_unit);
-                    word_space(s, item.node.key);
-                    word_space(s, "=");
-                    print_string(s, item.node.value);
-                    end(s);
-                }
-                commasep(s, consistent, mta, print_meta);
+                commasep(s, consistent, mta, print_meta_item);
                 pclose(s);
             }
         }